use of com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath in project jib by google.
the class StandardExplodedProcessorTest method testCreateLayers_withClassPathInManifest.
@Test
public void testCreateLayers_withClassPathInManifest() throws IOException, URISyntaxException {
Path standardJar = Paths.get(Resources.getResource(STANDARD_JAR_WITH_CLASS_PATH_MANIFEST).toURI());
Path destDir = temporaryFolder.newFolder().toPath();
StandardExplodedProcessor standardExplodedModeProcessor = new StandardExplodedProcessor(standardJar, destDir, JAR_JAVA_VERSION);
List<FileEntriesLayer> layers = standardExplodedModeProcessor.createLayers();
assertThat(layers.size()).isEqualTo(4);
FileEntriesLayer nonSnapshotLayer = layers.get(0);
FileEntriesLayer snapshotLayer = layers.get(1);
FileEntriesLayer resourcesLayer = layers.get(2);
FileEntriesLayer classesLayer = layers.get(3);
// Validate dependencies layers.
assertThat(nonSnapshotLayer.getName()).isEqualTo("dependencies");
assertThat(nonSnapshotLayer.getEntries().stream().map(FileEntry::getExtractionPath).collect(Collectors.toList())).isEqualTo(ImmutableList.of(AbsoluteUnixPath.get("/app/dependencies/dependency1"), AbsoluteUnixPath.get("/app/dependencies/dependency2"), AbsoluteUnixPath.get("/app/dependencies/dependency4")));
assertThat(snapshotLayer.getName()).isEqualTo("snapshot dependencies");
assertThat(snapshotLayer.getEntries().size()).isEqualTo(1);
assertThat(snapshotLayer.getEntries().get(0).getExtractionPath()).isEqualTo(AbsoluteUnixPath.get("/app/dependencies/dependency3-SNAPSHOT-1.jar"));
// Validate resources layer.
assertThat(resourcesLayer.getName()).isEqualTo("resources");
List<AbsoluteUnixPath> actualResourcesPaths = resourcesLayer.getEntries().stream().map(FileEntry::getExtractionPath).collect(Collectors.toList());
assertThat(actualResourcesPaths).containsExactly(AbsoluteUnixPath.get("/app/explodedJar/META-INF/MANIFEST.MF"), AbsoluteUnixPath.get("/app/explodedJar/directory1/resource1.txt"), AbsoluteUnixPath.get("/app/explodedJar/directory2/directory3/resource2.sql"), AbsoluteUnixPath.get("/app/explodedJar/directory4/resource3.txt"), AbsoluteUnixPath.get("/app/explodedJar/resource4.sql"));
// Validate classes layer.
assertThat(classesLayer.getName()).isEqualTo("classes");
List<AbsoluteUnixPath> actualClassesPaths = classesLayer.getEntries().stream().map(FileEntry::getExtractionPath).collect(Collectors.toList());
assertThat(actualClassesPaths).containsExactly(AbsoluteUnixPath.get("/app/explodedJar/class5.class"), AbsoluteUnixPath.get("/app/explodedJar/directory1/class1.class"), AbsoluteUnixPath.get("/app/explodedJar/directory1/class2.class"), AbsoluteUnixPath.get("/app/explodedJar/directory2/class4.class"), AbsoluteUnixPath.get("/app/explodedJar/directory2/directory3/class3.class"));
}
use of com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath in project jib by google.
the class StandardExplodedProcessorTest method testCreateLayers_withoutClassPathInManifest.
@Test
public void testCreateLayers_withoutClassPathInManifest() throws IOException, URISyntaxException {
Path standardJar = Paths.get(Resources.getResource(STANDARD_JAR_WITHOUT_CLASS_PATH_MANIFEST).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.getName()).isEqualTo("resources");
List<AbsoluteUnixPath> actualResourcesPaths = resourcesLayer.getEntries().stream().map(FileEntry::getExtractionPath).collect(Collectors.toList());
assertThat(actualResourcesPaths).containsExactly(AbsoluteUnixPath.get("/app/explodedJar/META-INF/MANIFEST.MF"), AbsoluteUnixPath.get("/app/explodedJar/directory1/resource1.txt"), AbsoluteUnixPath.get("/app/explodedJar/directory2/directory3/resource2.sql"), AbsoluteUnixPath.get("/app/explodedJar/directory4/resource3.txt"), AbsoluteUnixPath.get("/app/explodedJar/resource4.sql"));
// Validate classes layer.
assertThat(classesLayer.getName()).isEqualTo("classes");
List<AbsoluteUnixPath> actualClassesPaths = classesLayer.getEntries().stream().map(FileEntry::getExtractionPath).collect(Collectors.toList());
assertThat(actualClassesPaths).containsExactly(AbsoluteUnixPath.get("/app/explodedJar/class5.class"), AbsoluteUnixPath.get("/app/explodedJar/directory1/class1.class"), AbsoluteUnixPath.get("/app/explodedJar/directory1/class2.class"), AbsoluteUnixPath.get("/app/explodedJar/directory2/class4.class"), AbsoluteUnixPath.get("/app/explodedJar/directory2/directory3/class3.class"));
}
use of com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath in project jib by google.
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 google.
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 component-runtime by Talend.
the class ConnectorLoader method createConnectorLayer.
public ConnectorLayer createConnectorLayer(final AbsoluteUnixPath rootContainerPath, final Path workDir, final Path car) {
String gav = null;
final Map<String, Path> toCopy = new HashMap<>();
try (final JarInputStream jarInputStream = new JarInputStream(Files.newInputStream(car))) {
JarEntry entry;
while ((entry = jarInputStream.getNextJarEntry()) != null) {
if ("TALEND-INF/metadata.properties".equals(entry.getName())) {
// don't close, it is the jar!
gav = IO.loadProperties(new BufferedReader(new InputStreamReader(jarInputStream)).lines().collect(joining("\n"))).getProperty("component_coordinates");
continue;
}
if (!entry.getName().startsWith("MAVEN-INF/repository/")) {
continue;
}
final String relativeName = entry.getName().substring("MAVEN-INF/repository/".length());
final Path local = workDir.resolve(relativeName);
if (entry.isDirectory()) {
if (!Files.exists(local)) {
Files.createDirectories(local);
}
} else {
if (local.getParent() != null && !Files.exists(local.getParent())) {
Files.createDirectories(local.getParent());
}
Files.copy(jarInputStream, local);
if (entry.getLastModifiedTime() != null) {
Files.setLastModifiedTime(local, entry.getLastModifiedTime());
}
toCopy.put(relativeName, local);
}
}
} catch (final IOException e) {
throw new IllegalStateException(e);
}
return new ConnectorLayer(toCopy.entrySet().stream().collect(Collector.of(LayerConfiguration::builder, (builder, entry) -> {
try {
builder.addEntry(new LayerEntry(entry.getValue(), rootContainerPath.resolve(entry.getKey()), FilePermissions.DEFAULT_FILE_PERMISSIONS, Instant.ofEpochMilli(Files.getLastModifiedTime(entry.getValue()).toMillis())));
} catch (final IOException e) {
throw new IllegalStateException(e);
}
}, (builder1, builder2) -> {
builder2.build().getLayerEntries().forEach(builder1::addEntry);
return builder1;
})).build(), toCopy, requireNonNull(gav, "GAV was not found in '" + car + "', ensure it is a valid component archive."));
}
Aggregations