use of com.google.cloud.tools.jib.filesystem.DirectoryWalker in project jib by google.
the class JavaContainerBuilderHelper method fromExplodedWar.
/**
* Constructs a new {@link JibContainerBuilder} for a WAR project.
*
* @param javaContainerBuilder Java container builder to start with
* @param explodedWar the exploded WAR directory
* @param projectArtifactFilename the file names of project artifacts for project dependencies
* @return {@link JibContainerBuilder} containing the layers for the exploded WAR
* @throws IOException if adding layer contents fails
*/
public static JibContainerBuilder fromExplodedWar(JavaContainerBuilder javaContainerBuilder, Path explodedWar, Set<String> projectArtifactFilename) throws IOException {
Path webInfLib = explodedWar.resolve("WEB-INF/lib");
Path webInfClasses = explodedWar.resolve("WEB-INF/classes");
Predicate<Path> isDependency = path -> path.startsWith(webInfLib);
Predicate<Path> isClassFile = // Don't use Path.endsWith(), since Path works on path elements.
path -> path.startsWith(webInfClasses) && path.getFileName().toString().endsWith(".class");
Predicate<Path> isResource = isDependency.or(isClassFile).negate();
Predicate<Path> isSnapshot = path -> path.getFileName().toString().contains("SNAPSHOT");
Predicate<Path> isProjectDependency = path -> projectArtifactFilename.contains(path.getFileName().toString());
javaContainerBuilder.setResourcesDestination(RelativeUnixPath.get("")).setClassesDestination(RelativeUnixPath.get("WEB-INF/classes")).setDependenciesDestination(RelativeUnixPath.get("WEB-INF/lib"));
if (Files.exists(explodedWar)) {
javaContainerBuilder.addResources(explodedWar, isResource);
}
if (Files.exists(webInfClasses)) {
javaContainerBuilder.addClasses(webInfClasses, isClassFile);
}
if (Files.exists(webInfLib)) {
javaContainerBuilder.addDependencies(new DirectoryWalker(webInfLib).filterRoot().filter(isSnapshot.negate()).filter(isProjectDependency.negate()).walk());
javaContainerBuilder.addSnapshotDependencies(new DirectoryWalker(webInfLib).filterRoot().filter(isSnapshot).walk());
javaContainerBuilder.addProjectDependencies(new DirectoryWalker(webInfLib).filterRoot().filter(isProjectDependency).walk());
}
return javaContainerBuilder.toContainerBuilder();
}
use of com.google.cloud.tools.jib.filesystem.DirectoryWalker in project jib by google.
the class StandardWarExplodedProcessorTest method zipUpDirectory.
private static Path zipUpDirectory(Path sourceRoot, Path targetZip) throws IOException {
try (ZipOutputStream zipOut = new ZipOutputStream(Files.newOutputStream(targetZip))) {
for (Path source : new DirectoryWalker(sourceRoot).filterRoot().walk()) {
StringJoiner pathJoiner = new StringJoiner("/", "", "");
sourceRoot.relativize(source).forEach(element -> pathJoiner.add(element.toString()));
String zipEntryPath = Files.isDirectory(source) ? pathJoiner.toString() + '/' : pathJoiner.toString();
ZipEntry entry = new ZipEntry(zipEntryPath);
zipOut.putNextEntry(entry);
if (!Files.isDirectory(source)) {
try (InputStream in = Files.newInputStream(source)) {
ByteStreams.copy(in, zipOut);
}
}
zipOut.closeEntry();
}
}
return targetZip;
}
use of com.google.cloud.tools.jib.filesystem.DirectoryWalker in project jib by google.
the class MainClassFinderTest method testFindMainClass_importedMethods.
@Test
public void testFindMainClass_importedMethods() throws URISyntaxException, IOException {
Path rootDirectory = Paths.get(Resources.getResource("core/class-finder-tests/imported-methods").toURI());
MainClassFinder.Result mainClassFinderResult = MainClassFinder.find(new DirectoryWalker(rootDirectory).walk(), logEventConsumer);
Assert.assertSame(Result.Type.MAIN_CLASS_FOUND, mainClassFinderResult.getType());
MatcherAssert.assertThat(mainClassFinderResult.getFoundMainClass(), CoreMatchers.containsString("main.MainClass"));
}
use of com.google.cloud.tools.jib.filesystem.DirectoryWalker in project jib by google.
the class MainClassFinderTest method testFindMainClass_externalClasses.
@Test
public void testFindMainClass_externalClasses() throws URISyntaxException, IOException {
Path rootDirectory = Paths.get(Resources.getResource("core/class-finder-tests/external-classes").toURI());
MainClassFinder.Result mainClassFinderResult = MainClassFinder.find(new DirectoryWalker(rootDirectory).walk(), logEventConsumer);
Assert.assertSame(Result.Type.MAIN_CLASS_FOUND, mainClassFinderResult.getType());
MatcherAssert.assertThat(mainClassFinderResult.getFoundMainClass(), CoreMatchers.containsString("main.MainClass"));
}
use of com.google.cloud.tools.jib.filesystem.DirectoryWalker in project jib by google.
the class MainClassFinderTest method testMainClass_varargs.
@Test
public void testMainClass_varargs() throws URISyntaxException, IOException {
Path rootDirectory = Paths.get(Resources.getResource("core/class-finder-tests/varargs").toURI());
MainClassFinder.Result mainClassFinderResult = MainClassFinder.find(new DirectoryWalker(rootDirectory).walk(), logEventConsumer);
Assert.assertSame(Result.Type.MAIN_CLASS_FOUND, mainClassFinderResult.getType());
MatcherAssert.assertThat(mainClassFinderResult.getFoundMainClass(), CoreMatchers.containsString("HelloWorld"));
}
Aggregations