use of com.google.common.io.InsecureRecursiveDeleteException in project jib by google.
the class DockerContextMojo method createDockerContext.
// TODO: Move most of this to jib-core.
/**
* Creates the Docker context in {@link #targetDir}.
*/
private void createDockerContext(ProjectProperties projectProperties) throws MojoExecutionException, MojoFailureException {
SourceFilesConfiguration sourceFilesConfiguration = projectProperties.getSourceFilesConfiguration();
try {
Path targetDirPath = Paths.get(targetDir);
// Deletes the targetDir if it exists.
if (Files.exists(targetDirPath)) {
MoreFiles.deleteDirectoryContents(targetDirPath);
}
Files.createDirectory(targetDirPath);
// Creates the directories.
Path dependenciesDir = targetDirPath.resolve("libs");
Path resourcesDIr = targetDirPath.resolve("resources");
Path classesDir = targetDirPath.resolve("classes");
Files.createDirectory(dependenciesDir);
Files.createDirectory(resourcesDIr);
Files.createDirectory(classesDir);
// Copies dependencies.
copyFiles(sourceFilesConfiguration.getDependenciesFiles(), dependenciesDir);
copyFiles(sourceFilesConfiguration.getResourcesFiles(), resourcesDIr);
copyFiles(sourceFilesConfiguration.getClassesFiles(), classesDir);
// Creates the Dockerfile.
Files.write(targetDirPath.resolve("Dockerfile"), makeDockerfile(sourceFilesConfiguration).getBytes(StandardCharsets.UTF_8));
projectProperties.getLog().info("Created Docker context at " + targetDir);
} catch (InsecureRecursiveDeleteException ex) {
throwMojoExecutionExceptionWithHelpMessage(ex, "cannot clear directory '" + targetDir + "' safely - clear it manually before creating the Docker context");
} catch (IOException ex) {
throwMojoExecutionExceptionWithHelpMessage(ex, "check if `targetDir` is set correctly");
}
}
Aggregations