use of com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath in project jib by GoogleContainerTools.
the class StandardExplodedProcessorTest method testCreateLayers_withoutClassPathInManifest_containsOnlyClasses.
@Test
public void testCreateLayers_withoutClassPathInManifest_containsOnlyClasses() throws IOException, URISyntaxException {
Path standardJar = Paths.get(Resources.getResource(STANDARD_JAR_WITH_ONLY_CLASSES).toURI());
Path destDir = temporaryFolder.newFolder().toPath();
StandardExplodedProcessor standardExplodedModeProcessor = new StandardExplodedProcessor(standardJar, destDir, JAR_JAVA_VERSION);
List<FileEntriesLayer> layers = standardExplodedModeProcessor.createLayers();
assertThat(layers.size()).isEqualTo(2);
FileEntriesLayer resourcesLayer = layers.get(0);
FileEntriesLayer classesLayer = layers.get(1);
// Validate resources layer.
assertThat(resourcesLayer.getEntries().size()).isEqualTo(1);
assertThat(resourcesLayer.getEntries().get(0).getExtractionPath()).isEqualTo(AbsoluteUnixPath.get("/app/explodedJar/META-INF/MANIFEST.MF"));
// Validate classes layer.
List<AbsoluteUnixPath> actualClassesPath = classesLayer.getEntries().stream().map(FileEntry::getExtractionPath).collect(Collectors.toList());
assertThat(actualClassesPath).containsExactly(AbsoluteUnixPath.get("/app/explodedJar/class1.class"), AbsoluteUnixPath.get("/app/explodedJar/class2.class"));
}
use of com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath in project jib by GoogleContainerTools.
the class JavaContainerBuilderTest method testToJibContainerBuilder_setAppRootLate.
@Test
public void testToJibContainerBuilder_setAppRootLate() throws URISyntaxException, IOException, InvalidImageReferenceException, CacheDirectoryCreationException {
BuildContext buildContext = JavaContainerBuilder.from("scratch").addClasses(getResource("core/application/classes")).addResources(getResource("core/application/resources")).addDependencies(getResource("core/application/dependencies/libraryA.jar")).addToClasspath(getResource("core/fileA")).setAppRoot("/different").setMainClass("HelloWorld").toContainerBuilder().toBuildContext(Containerizer.to(RegistryImage.named("hello")));
// Check entrypoint
Assert.assertEquals(ImmutableList.of("java", "-cp", "/different/classes:/different/resources:/different/libs/*:/different/classpath", "HelloWorld"), buildContext.getContainerConfiguration().getEntrypoint());
// Check classes
List<AbsoluteUnixPath> expectedClasses = ImmutableList.of(AbsoluteUnixPath.get("/different/classes/HelloWorld.class"), AbsoluteUnixPath.get("/different/classes/some.class"));
Assert.assertEquals(expectedClasses, getExtractionPaths(buildContext, "classes"));
// Check resources
List<AbsoluteUnixPath> expectedResources = ImmutableList.of(AbsoluteUnixPath.get("/different/resources/resourceA"), AbsoluteUnixPath.get("/different/resources/resourceB"), AbsoluteUnixPath.get("/different/resources/world"));
Assert.assertEquals(expectedResources, getExtractionPaths(buildContext, "resources"));
// Check dependencies
List<AbsoluteUnixPath> expectedDependencies = ImmutableList.of(AbsoluteUnixPath.get("/different/libs/libraryA.jar"));
Assert.assertEquals(expectedDependencies, getExtractionPaths(buildContext, "dependencies"));
Assert.assertEquals(expectedClasses, getExtractionPaths(buildContext, "classes"));
// Check additional classpath files
List<AbsoluteUnixPath> expectedOthers = ImmutableList.of(AbsoluteUnixPath.get("/different/classpath/fileA"));
Assert.assertEquals(expectedOthers, getExtractionPaths(buildContext, "extra files"));
}
use of com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath in project jib by GoogleContainerTools.
the class JavaContainerBuilderTest method testToJibContainerBuilder_all.
@Test
public void testToJibContainerBuilder_all() throws InvalidImageReferenceException, URISyntaxException, IOException, CacheDirectoryCreationException {
BuildContext buildContext = JavaContainerBuilder.from("scratch").setAppRoot("/hello").addResources(getResource("core/application/resources")).addClasses(getResource("core/application/classes")).addDependencies(getResource("core/application/dependencies/dependency-1.0.0.jar"), getResource("core/application/dependencies/more/dependency-1.0.0.jar")).addSnapshotDependencies(getResource("core/application/snapshot-dependencies/dependency-1.0.0-SNAPSHOT.jar")).addProjectDependencies(getResource("core/application/dependencies/libraryA.jar"), getResource("core/application/dependencies/libraryB.jar")).addToClasspath(getResource("core/fileA"), getResource("core/fileB")).setClassesDestination(RelativeUnixPath.get("different-classes")).setResourcesDestination(RelativeUnixPath.get("different-resources")).setDependenciesDestination(RelativeUnixPath.get("different-libs")).setOthersDestination(RelativeUnixPath.get("different-classpath")).addJvmFlags("-xflag1", "-xflag2").setMainClass("HelloWorld").toContainerBuilder().toBuildContext(Containerizer.to(RegistryImage.named("hello")));
// Check entrypoint
Assert.assertEquals(ImmutableList.of("java", "-xflag1", "-xflag2", "-cp", "/hello/different-resources:/hello/different-classes:/hello/different-libs/*:/hello/different-classpath", "HelloWorld"), buildContext.getContainerConfiguration().getEntrypoint());
// Check dependencies
List<AbsoluteUnixPath> expectedDependencies = ImmutableList.of(AbsoluteUnixPath.get("/hello/different-libs/dependency-1.0.0-770.jar"), AbsoluteUnixPath.get("/hello/different-libs/dependency-1.0.0-200.jar"));
Assert.assertEquals(expectedDependencies, getExtractionPaths(buildContext, "dependencies"));
// Check snapshots
List<AbsoluteUnixPath> expectedSnapshotDependencies = ImmutableList.of(AbsoluteUnixPath.get("/hello/different-libs/dependency-1.0.0-SNAPSHOT.jar"));
Assert.assertEquals(expectedSnapshotDependencies, getExtractionPaths(buildContext, "snapshot dependencies"));
List<AbsoluteUnixPath> expectedProjectDependencies = ImmutableList.of(AbsoluteUnixPath.get("/hello/different-libs/libraryA.jar"), AbsoluteUnixPath.get("/hello/different-libs/libraryB.jar"));
Assert.assertEquals(expectedProjectDependencies, getExtractionPaths(buildContext, "project dependencies"));
// Check resources
List<AbsoluteUnixPath> expectedResources = ImmutableList.of(AbsoluteUnixPath.get("/hello/different-resources/resourceA"), AbsoluteUnixPath.get("/hello/different-resources/resourceB"), AbsoluteUnixPath.get("/hello/different-resources/world"));
Assert.assertEquals(expectedResources, getExtractionPaths(buildContext, "resources"));
// Check classes
List<AbsoluteUnixPath> expectedClasses = ImmutableList.of(AbsoluteUnixPath.get("/hello/different-classes/HelloWorld.class"), AbsoluteUnixPath.get("/hello/different-classes/some.class"));
Assert.assertEquals(expectedClasses, getExtractionPaths(buildContext, "classes"));
// Check additional classpath files
List<AbsoluteUnixPath> expectedOthers = ImmutableList.of(AbsoluteUnixPath.get("/hello/different-classpath/fileA"), AbsoluteUnixPath.get("/hello/different-classpath/fileB"));
Assert.assertEquals(expectedOthers, getExtractionPaths(buildContext, "extra files"));
}
use of com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath in project jib by GoogleContainerTools.
the class JavaContainerBuilderTest method testToJibContainerBuilder_missingAndMultipleAdds.
@Test
public void testToJibContainerBuilder_missingAndMultipleAdds() throws InvalidImageReferenceException, URISyntaxException, IOException, CacheDirectoryCreationException {
BuildContext buildContext = JavaContainerBuilder.from("scratch").addDependencies(getResource("core/application/dependencies/libraryA.jar")).addDependencies(getResource("core/application/dependencies/libraryB.jar")).addSnapshotDependencies(getResource("core/application/snapshot-dependencies/dependency-1.0.0-SNAPSHOT.jar")).addClasses(getResource("core/application/classes/")).addClasses(getResource("core/class-finder-tests/extension")).setMainClass("HelloWorld").toContainerBuilder().toBuildContext(Containerizer.to(RegistryImage.named("hello")));
// Check entrypoint
Assert.assertEquals(ImmutableList.of("java", "-cp", "/app/libs/*:/app/classes", "HelloWorld"), buildContext.getContainerConfiguration().getEntrypoint());
// Check dependencies
List<AbsoluteUnixPath> expectedDependencies = ImmutableList.of(AbsoluteUnixPath.get("/app/libs/libraryA.jar"), AbsoluteUnixPath.get("/app/libs/libraryB.jar"));
Assert.assertEquals(expectedDependencies, getExtractionPaths(buildContext, "dependencies"));
// Check snapshots
List<AbsoluteUnixPath> expectedSnapshotDependencies = ImmutableList.of(AbsoluteUnixPath.get("/app/libs/dependency-1.0.0-SNAPSHOT.jar"));
Assert.assertEquals(expectedSnapshotDependencies, getExtractionPaths(buildContext, "snapshot dependencies"));
// Check classes
List<AbsoluteUnixPath> expectedClasses = ImmutableList.of(AbsoluteUnixPath.get("/app/classes/HelloWorld.class"), AbsoluteUnixPath.get("/app/classes/some.class"), AbsoluteUnixPath.get("/app/classes/main/"), AbsoluteUnixPath.get("/app/classes/main/MainClass.class"), AbsoluteUnixPath.get("/app/classes/pack/"), AbsoluteUnixPath.get("/app/classes/pack/Apple.class"), AbsoluteUnixPath.get("/app/classes/pack/Orange.class"));
Assert.assertEquals(expectedClasses, getExtractionPaths(buildContext, "classes"));
// Check empty layers
Assert.assertEquals(ImmutableList.of(), getExtractionPaths(buildContext, "resources"));
Assert.assertEquals(ImmutableList.of(), getExtractionPaths(buildContext, "extra files"));
}
use of com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath in project jib by GoogleContainerTools.
the class JavaContainerBuilder method addDirectoryContentsToLayer.
private void addDirectoryContentsToLayer(Map<LayerType, FileEntriesLayer.Builder> layerBuilders, LayerType layerType, Path sourceRoot, Predicate<Path> pathFilter, AbsoluteUnixPath basePathInContainer) throws IOException {
if (!layerBuilders.containsKey(layerType)) {
layerBuilders.put(layerType, FileEntriesLayer.builder());
}
FileEntriesLayer.Builder builder = layerBuilders.get(layerType);
new DirectoryWalker(sourceRoot).filterRoot().filter(path -> Files.isDirectory(path) || pathFilter.test(path)).walk(path -> {
AbsoluteUnixPath pathOnContainer = basePathInContainer.resolve(sourceRoot.relativize(path));
Instant modificationTime = modificationTimeProvider.get(path, pathOnContainer);
builder.addEntry(path, pathOnContainer, modificationTime);
});
}
Aggregations