Search in sources :

Example 26 with InvalidPathException

use of java.nio.file.InvalidPathException in project google-cloud-intellij by GoogleCloudPlatform.

the class AppEngineFlexibleStage method stage.

/**
 * Stages the application in the given staging directory, in preparation for deployment to the App
 * Engine flexible environment.
 *
 * @param stagingDirectory the directory to stage the application to
 * @return {@code true} if the application was staged successfully, {@code false} otherwise
 * @throws IOException if there was a filesystem error during copying
 */
public boolean stage(@NotNull Path stagingDirectory) throws IOException {
    try {
        String moduleName = deploymentConfiguration.getModuleName();
        if (StringUtils.isEmpty(moduleName)) {
            loggingHandler.print(getMessage("appengine.deployment.error.staging.yaml.notspecified"));
            return false;
        }
        AppEngineFlexibleFacet flexibleFacet = AppEngineFlexibleFacet.getFacetByModuleName(moduleName, project);
        if (flexibleFacet == null || StringUtils.isEmpty(flexibleFacet.getConfiguration().getAppYamlPath())) {
            loggingHandler.print(getMessage("appengine.deployment.error.staging.yaml.notspecified"));
            return false;
        }
        AppEngineFlexibleFacetConfiguration facetConfiguration = flexibleFacet.getConfiguration();
        String appYaml = facetConfiguration.getAppYamlPath();
        // Checks if the app.yaml exists before staging.
        if (!Files.exists(Paths.get(appYaml))) {
            loggingHandler.print(getMessage("appengine.deployment.error.staging.yaml.notfound"));
            return false;
        }
        boolean isCustomRuntime = AppEngineProjectService.getInstance().getFlexibleRuntimeFromAppYaml(appYaml).filter(FlexibleRuntime::isCustom).isPresent();
        // Checks if the Dockerfile exists before staging.
        String dockerDirectory = facetConfiguration.getDockerDirectory();
        if (isCustomRuntime) {
            if (Strings.isNullOrEmpty(dockerDirectory)) {
                loggingHandler.print(getMessage("appengine.deployment.error.staging.dockerfile.notspecified"));
                return false;
            }
            if (!Files.isRegularFile(Paths.get(dockerDirectory, DOCKERFILE_NAME))) {
                loggingHandler.print(getMessage("appengine.deployment.error.staging.dockerfile.notfound"));
                return false;
            }
        }
        String stagedArtifactName = deploymentConfiguration.getStagedArtifactName();
        if (Strings.isNullOrEmpty(stagedArtifactName)) {
            if (deploymentConfiguration.isStagedArtifactNameLegacy()) {
                // Uses "target.jar" or "target.war" for legacy configs.
                AppEngineFlexibleDeploymentArtifactType artifactType = AppEngineFlexibleDeploymentArtifactType.typeForPath(deploymentArtifactPath);
                stagedArtifactName = StagedArtifactNameLegacySupport.getTargetName(artifactType);
            } else {
                // Defaults to the name of the artifact.
                stagedArtifactName = deploymentArtifactPath.getFileName().toString();
            }
        }
        loggingHandler.print(getMessage("appengine.deployment.staging.artifact.as", stagedArtifactName));
        Path stagedArtifactPath = stagingDirectory.resolve(stagedArtifactName);
        // Creates parent directories first, if necessary.
        Files.createDirectories(stagedArtifactPath.getParent());
        Files.copy(deploymentArtifactPath, stagedArtifactPath);
        Path appYamlPath = Paths.get(appYaml);
        Files.copy(appYamlPath, stagingDirectory.resolve(appYamlPath.getFileName()));
        if (isCustomRuntime) {
            FileUtils.copyDirectory(Paths.get(dockerDirectory).toFile(), stagingDirectory.toFile());
        }
    } catch (InvalidPathException | MalformedYamlFileException e) {
        loggingHandler.print(e.getMessage() + "\n");
    }
    return true;
}
Also used : Path(java.nio.file.Path) MalformedYamlFileException(com.google.cloud.tools.intellij.appengine.project.MalformedYamlFileException) AppEngineFlexibleFacet(com.google.cloud.tools.intellij.appengine.facet.flexible.AppEngineFlexibleFacet) AppEngineFlexibleFacetConfiguration(com.google.cloud.tools.intellij.appengine.facet.flexible.AppEngineFlexibleFacetConfiguration) InvalidPathException(java.nio.file.InvalidPathException)

Example 27 with InvalidPathException

use of java.nio.file.InvalidPathException in project google-cloud-intellij by GoogleCloudPlatform.

the class DefaultAppEngineProjectService method getValueFromAppYaml.

/**
 * Returns the value of a key-value pair for a given {@code key}, on the file located at {@code
 * appYamlPathString}.
 *
 * @return a String with the value, or an empty Optional if app.yaml isn't a regular file, or if
 *     there is any error getting the value
 * @throws MalformedYamlFileException when an app.yaml isn't syntactically well formed
 */
private Optional<String> getValueFromAppYaml(@NotNull String appYamlPathString, @NotNull String key) throws MalformedYamlFileException {
    Yaml yamlParser = new Yaml();
    Path appYamlPath = Paths.get(appYamlPathString);
    if (!Files.isRegularFile(appYamlPath)) {
        return Optional.empty();
    }
    try (BufferedReader reader = Files.newBufferedReader(appYamlPath, Charset.defaultCharset())) {
        Object parseResult = yamlParser.load(reader);
        if (!(parseResult instanceof Map)) {
            return Optional.empty();
        }
        // It's possible to get rid of this unchecked cast using a loadAs(file,
        // AppEngineYamlWebApp.class) sort of approach.
        Map<String, String> yamlMap = (Map<String, String>) parseResult;
        return yamlMap.containsKey(key) ? Optional.of(yamlMap.get(key)) : Optional.empty();
    } catch (ScannerException se) {
        throw new MalformedYamlFileException(se);
    } catch (InvalidPathException | IOException ioe) {
        return Optional.empty();
    }
}
Also used : Path(java.nio.file.Path) ScannerException(org.yaml.snakeyaml.scanner.ScannerException) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) Map(java.util.Map) Yaml(org.yaml.snakeyaml.Yaml) InvalidPathException(java.nio.file.InvalidPathException)

Example 28 with InvalidPathException

use of java.nio.file.InvalidPathException in project chatty by chatty.

the class UsericonFactory method createCustomIcon.

/**
 * Creates an icon based on a filename, which is resolved with the image
 * directory (if necessary). It also takes a restriction parameter and
 * stuff and sets the other values to appropriate values for custom icons.
 *
 * @param type
 * @param idVersion
 * @param restriction
 * @param fileName
 * @param channel
 * @return
 */
public static Usericon createCustomIcon(Usericon.Type type, String idVersion, String restriction, String fileName, String channel) {
    try {
        URL url = null;
        if (fileName != null) {
            if (fileName.startsWith("http")) {
                url = new URL(fileName);
            } else if (!fileName.trim().isEmpty()) {
                Path path = Paths.get(Chatty.getImageDirectory()).resolve(Paths.get(fileName));
                url = path.toUri().toURL();
            }
        }
        Usericon.Builder b = new Usericon.Builder(type, SOURCE_CUSTOM);
        b.setChannel(channel);
        b.setUrl(url);
        b.setRestriction(restriction);
        b.setFileName(fileName);
        b.setBadgeType(BadgeType.parse(idVersion));
        return b.build();
    } catch (MalformedURLException | InvalidPathException ex) {
        LOGGER.warning("Invalid icon file: " + fileName);
    }
    return null;
}
Also used : Path(java.nio.file.Path) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) InvalidPathException(java.nio.file.InvalidPathException)

Example 29 with InvalidPathException

use of java.nio.file.InvalidPathException in project embulk by embulk.

the class JRubyInitializer method buildEmbulkHome.

private Path buildEmbulkHome() throws ProvisionException {
    final String userHomeProperty = System.getProperty("user.home");
    if (userHomeProperty == null) {
        throw new ProvisionException("User home directory is not set in Java properties.");
    }
    final Path userHome;
    try {
        userHome = Paths.get(userHomeProperty);
    } catch (InvalidPathException ex) {
        throw new ProvisionException("User home directory is invalid: \"" + userHomeProperty + "\"", ex);
    }
    return userHome.toAbsolutePath().resolve(".embulk");
}
Also used : Path(java.nio.file.Path) ProvisionException(com.google.inject.ProvisionException) InvalidPathException(java.nio.file.InvalidPathException)

Example 30 with InvalidPathException

use of java.nio.file.InvalidPathException in project catena-java by alinush.

the class ServerApp method genClientConfigFileHandler.

private static void genClientConfigFileHandler() throws IOException {
    Path path;
    while (true) {
        try {
            System.out.print("Please enter the directory where you'd like the config.ini file to be saved (leave blank for 'catena-client/'): ");
            String dirStr = scanner.nextLine();
            if (dirStr.trim().isEmpty()) {
                dirStr = "catena-client";
            }
            Path dir = Paths.get(dirStr);
            path = Paths.get(dir.toString(), "config.ini");
            if (path.toFile().exists() == false) {
                if (dir.toFile().isFile()) {
                    System.out.printf("The %s directory you entered is actually a file, not a directory. Try again.\n", dir);
                    continue;
                }
                if (dir.toFile().exists() == false)
                    Files.createDirectory(dir);
                break;
            } else {
                System.out.printf("ERROR: We won't overwrite the already existing file at %s. Please pick a " + "different directory where the config.ini file doesn't exist.\n", path);
            }
        } catch (InvalidPathException e) {
            System.out.println("\nERROR: You must enter a valid path! Try again...");
        }
    }
    genClientConfigFile(path);
}
Also used : Path(java.nio.file.Path) InvalidPathException(java.nio.file.InvalidPathException)

Aggregations

InvalidPathException (java.nio.file.InvalidPathException)97 Path (java.nio.file.Path)53 IOException (java.io.IOException)26 URL (java.net.URL)14 File (java.io.File)13 MalformedURLException (java.net.MalformedURLException)12 Test (org.junit.Test)11 AlluxioURI (alluxio.AlluxioURI)7 Resource (org.springframework.core.io.Resource)7 Nullable (org.springframework.lang.Nullable)7 URI (java.net.URI)6 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)5 URISyntaxException (java.net.URISyntaxException)5 ArrayList (java.util.ArrayList)5 URIStatus (alluxio.client.file.URIStatus)4 ViewResolve (com.nvlad.yii2support.views.entities.ViewResolve)4 InputStream (java.io.InputStream)4 FileOutStream (alluxio.client.file.FileOutStream)3 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)3 SetAttributePOptions (alluxio.grpc.SetAttributePOptions)2