Search in sources :

Example 36 with DirectoryWalker

use of com.google.cloud.tools.jib.filesystem.DirectoryWalker in project jib by google.

the class MainClassFinderTest method testFindMainClass_noClass.

@Test
public void testFindMainClass_noClass() throws URISyntaxException, IOException {
    Path rootDirectory = Paths.get(Resources.getResource("core/class-finder-tests/no-main").toURI());
    MainClassFinder.Result mainClassFinderResult = MainClassFinder.find(new DirectoryWalker(rootDirectory).walk(), logEventConsumer);
    Assert.assertEquals(Result.Type.MAIN_CLASS_NOT_FOUND, mainClassFinderResult.getType());
}
Also used : Path(java.nio.file.Path) Result(com.google.cloud.tools.jib.api.MainClassFinder.Result) DirectoryWalker(com.google.cloud.tools.jib.filesystem.DirectoryWalker) Test(org.junit.Test)

Example 37 with DirectoryWalker

use of com.google.cloud.tools.jib.filesystem.DirectoryWalker in project jib by GoogleContainerTools.

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;
}
Also used : AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) Path(java.nio.file.Path) ZipOutputStream(java.util.zip.ZipOutputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) DirectoryWalker(com.google.cloud.tools.jib.filesystem.DirectoryWalker) StringJoiner(java.util.StringJoiner)

Example 38 with DirectoryWalker

use of com.google.cloud.tools.jib.filesystem.DirectoryWalker in project jib by GoogleContainerTools.

the class MainClassFinderTest method testFindMainClass_simple.

@Test
public void testFindMainClass_simple() throws URISyntaxException, IOException {
    Path rootDirectory = Paths.get(Resources.getResource("core/class-finder-tests/simple").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"));
}
Also used : Path(java.nio.file.Path) Result(com.google.cloud.tools.jib.api.MainClassFinder.Result) DirectoryWalker(com.google.cloud.tools.jib.filesystem.DirectoryWalker) Test(org.junit.Test)

Example 39 with DirectoryWalker

use of com.google.cloud.tools.jib.filesystem.DirectoryWalker in project jib by GoogleContainerTools.

the class MainClassFinderTest method testFindMainClass_noClass.

@Test
public void testFindMainClass_noClass() throws URISyntaxException, IOException {
    Path rootDirectory = Paths.get(Resources.getResource("core/class-finder-tests/no-main").toURI());
    MainClassFinder.Result mainClassFinderResult = MainClassFinder.find(new DirectoryWalker(rootDirectory).walk(), logEventConsumer);
    Assert.assertEquals(Result.Type.MAIN_CLASS_NOT_FOUND, mainClassFinderResult.getType());
}
Also used : Path(java.nio.file.Path) Result(com.google.cloud.tools.jib.api.MainClassFinder.Result) DirectoryWalker(com.google.cloud.tools.jib.filesystem.DirectoryWalker) Test(org.junit.Test)

Example 40 with DirectoryWalker

use of com.google.cloud.tools.jib.filesystem.DirectoryWalker in project jib by GoogleContainerTools.

the class MainClassFinderTest method testFindMainClass_multiple.

@Test
public void testFindMainClass_multiple() throws URISyntaxException, IOException {
    Path rootDirectory = Paths.get(Resources.getResource("core/class-finder-tests/multiple").toURI());
    MainClassFinder.Result mainClassFinderResult = MainClassFinder.find(new DirectoryWalker(rootDirectory).walk(), logEventConsumer);
    Assert.assertEquals(Result.Type.MULTIPLE_MAIN_CLASSES, mainClassFinderResult.getType());
    Assert.assertEquals(2, mainClassFinderResult.getFoundMainClasses().size());
    Assert.assertTrue(mainClassFinderResult.getFoundMainClasses().contains("multi.layered.HelloMoon"));
    Assert.assertTrue(mainClassFinderResult.getFoundMainClasses().contains("HelloWorld"));
}
Also used : Path(java.nio.file.Path) Result(com.google.cloud.tools.jib.api.MainClassFinder.Result) DirectoryWalker(com.google.cloud.tools.jib.filesystem.DirectoryWalker) Test(org.junit.Test)

Aggregations

DirectoryWalker (com.google.cloud.tools.jib.filesystem.DirectoryWalker)52 Path (java.nio.file.Path)48 Test (org.junit.Test)23 Result (com.google.cloud.tools.jib.api.MainClassFinder.Result)20 AbsoluteUnixPath (com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath)15 IOException (java.io.IOException)11 FileEntriesLayer (com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer)9 Files (java.nio.file.Files)9 FileTime (java.nio.file.attribute.FileTime)8 List (java.util.List)8 Predicate (java.util.function.Predicate)8 Instant (java.time.Instant)7 Map (java.util.Map)7 ModificationTimeProvider (com.google.cloud.tools.jib.api.buildplan.ModificationTimeProvider)6 RelativeUnixPath (com.google.cloud.tools.jib.api.buildplan.RelativeUnixPath)6 InputStream (java.io.InputStream)6 Paths (java.nio.file.Paths)6 ArrayList (java.util.ArrayList)6 StringJoiner (java.util.StringJoiner)6 FilePermissions (com.google.cloud.tools.jib.api.buildplan.FilePermissions)5