use of com.google.cloud.tools.jib.api.JavaContainerBuilder.LayerType in project jib by google.
the class MavenProjectProperties method classifyDependencies.
@VisibleForTesting
Map<LayerType, List<Path>> classifyDependencies(Set<Artifact> dependencies, Set<Artifact> projectArtifacts) {
Map<LayerType, List<Path>> classifiedDependencies = new HashMap<>();
classifiedDependencies.put(LayerType.DEPENDENCIES, new ArrayList<>());
classifiedDependencies.put(LayerType.SNAPSHOT_DEPENDENCIES, new ArrayList<>());
classifiedDependencies.put(LayerType.PROJECT_DEPENDENCIES, new ArrayList<>());
for (Artifact artifact : dependencies) {
if (projectArtifacts.contains(artifact)) {
classifiedDependencies.get(LayerType.PROJECT_DEPENDENCIES).add(artifact.getFile().toPath());
} else if (artifact.isSnapshot()) {
classifiedDependencies.get(LayerType.SNAPSHOT_DEPENDENCIES).add(artifact.getFile().toPath());
} else {
classifiedDependencies.get(LayerType.DEPENDENCIES).add(artifact.getFile().toPath());
}
}
return classifiedDependencies;
}
use of com.google.cloud.tools.jib.api.JavaContainerBuilder.LayerType in project jib by google.
the class MavenProjectProperties method createJibContainerBuilder.
@Override
public JibContainerBuilder createJibContainerBuilder(JavaContainerBuilder javaContainerBuilder, ContainerizingMode containerizingMode) throws IOException {
try {
if (isWarProject()) {
Path war = getWarArtifact();
Path explodedWarPath = tempDirectoryProvider.newDirectory();
ZipUtil.unzip(war, explodedWarPath);
return JavaContainerBuilderHelper.fromExplodedWar(javaContainerBuilder, explodedWarPath, getProjectDependencies().stream().map(Artifact::getFile).map(File::getName).collect(Collectors.toSet()));
}
switch(containerizingMode) {
case EXPLODED:
// Add resources, and classes
Path classesOutputDirectory = Paths.get(project.getBuild().getOutputDirectory());
// Don't use Path.endsWith(), since Path works on path elements.
Predicate<Path> isClassFile = path -> path.getFileName().toString().endsWith(".class");
javaContainerBuilder.addResources(classesOutputDirectory, isClassFile.negate()).addClasses(classesOutputDirectory, isClassFile);
break;
case PACKAGED:
// Add a JAR
javaContainerBuilder.addToClasspath(getJarArtifact());
break;
default:
throw new IllegalStateException("unknown containerizing mode: " + containerizingMode);
}
// Classify and add dependencies
Map<LayerType, List<Path>> classifiedDependencies = classifyDependencies(project.getArtifacts(), getProjectDependencies());
javaContainerBuilder.addDependencies(Preconditions.checkNotNull(classifiedDependencies.get(LayerType.DEPENDENCIES)));
javaContainerBuilder.addSnapshotDependencies(Preconditions.checkNotNull(classifiedDependencies.get(LayerType.SNAPSHOT_DEPENDENCIES)));
javaContainerBuilder.addProjectDependencies(Preconditions.checkNotNull(classifiedDependencies.get(LayerType.PROJECT_DEPENDENCIES)));
return javaContainerBuilder.toContainerBuilder();
} catch (IOException ex) {
throw new IOException("Obtaining project build output files failed; make sure you have " + (isPackageErrorMessage(containerizingMode) ? "packaged" : "compiled") + " your project " + "before trying to build the image. (Did you accidentally run \"mvn clean " + "jib:build\" instead of \"mvn clean " + (isPackageErrorMessage(containerizingMode) ? "package" : "compile") + " jib:build\"?)", ex);
}
}
use of com.google.cloud.tools.jib.api.JavaContainerBuilder.LayerType in project jib by GoogleContainerTools.
the class MavenProjectProperties method classifyDependencies.
@VisibleForTesting
Map<LayerType, List<Path>> classifyDependencies(Set<Artifact> dependencies, Set<Artifact> projectArtifacts) {
Map<LayerType, List<Path>> classifiedDependencies = new HashMap<>();
classifiedDependencies.put(LayerType.DEPENDENCIES, new ArrayList<>());
classifiedDependencies.put(LayerType.SNAPSHOT_DEPENDENCIES, new ArrayList<>());
classifiedDependencies.put(LayerType.PROJECT_DEPENDENCIES, new ArrayList<>());
for (Artifact artifact : dependencies) {
if (projectArtifacts.contains(artifact)) {
classifiedDependencies.get(LayerType.PROJECT_DEPENDENCIES).add(artifact.getFile().toPath());
} else if (artifact.isSnapshot()) {
classifiedDependencies.get(LayerType.SNAPSHOT_DEPENDENCIES).add(artifact.getFile().toPath());
} else {
classifiedDependencies.get(LayerType.DEPENDENCIES).add(artifact.getFile().toPath());
}
}
return classifiedDependencies;
}
use of com.google.cloud.tools.jib.api.JavaContainerBuilder.LayerType in project jib by GoogleContainerTools.
the class MavenProjectProperties method createJibContainerBuilder.
@Override
public JibContainerBuilder createJibContainerBuilder(JavaContainerBuilder javaContainerBuilder, ContainerizingMode containerizingMode) throws IOException {
try {
if (isWarProject()) {
Path war = getWarArtifact();
Path explodedWarPath = tempDirectoryProvider.newDirectory();
ZipUtil.unzip(war, explodedWarPath);
return JavaContainerBuilderHelper.fromExplodedWar(javaContainerBuilder, explodedWarPath, getProjectDependencies().stream().map(Artifact::getFile).map(File::getName).collect(Collectors.toSet()));
}
switch(containerizingMode) {
case EXPLODED:
// Add resources, and classes
Path classesOutputDirectory = Paths.get(project.getBuild().getOutputDirectory());
// Don't use Path.endsWith(), since Path works on path elements.
Predicate<Path> isClassFile = path -> path.getFileName().toString().endsWith(".class");
javaContainerBuilder.addResources(classesOutputDirectory, isClassFile.negate()).addClasses(classesOutputDirectory, isClassFile);
break;
case PACKAGED:
// Add a JAR
javaContainerBuilder.addToClasspath(getJarArtifact());
break;
default:
throw new IllegalStateException("unknown containerizing mode: " + containerizingMode);
}
// Classify and add dependencies
Map<LayerType, List<Path>> classifiedDependencies = classifyDependencies(project.getArtifacts(), getProjectDependencies());
javaContainerBuilder.addDependencies(Preconditions.checkNotNull(classifiedDependencies.get(LayerType.DEPENDENCIES)));
javaContainerBuilder.addSnapshotDependencies(Preconditions.checkNotNull(classifiedDependencies.get(LayerType.SNAPSHOT_DEPENDENCIES)));
javaContainerBuilder.addProjectDependencies(Preconditions.checkNotNull(classifiedDependencies.get(LayerType.PROJECT_DEPENDENCIES)));
return javaContainerBuilder.toContainerBuilder();
} catch (IOException ex) {
throw new IOException("Obtaining project build output files failed; make sure you have " + (isPackageErrorMessage(containerizingMode) ? "packaged" : "compiled") + " your project " + "before trying to build the image. (Did you accidentally run \"mvn clean " + "jib:build\" instead of \"mvn clean " + (isPackageErrorMessage(containerizingMode) ? "package" : "compile") + " jib:build\"?)", ex);
}
}
Aggregations