Skip to content

Commit

Permalink
Fix to match relative path (#3181)
Browse files Browse the repository at this point in the history
  • Loading branch information
chanseokoh committed Apr 2, 2021
1 parent ff8c5b2 commit 053a1d7
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,11 @@ public void testDockerDaemon_simple_extraDirectoriesFiltering()
new Command("docker", "run", "--rm", "--entrypoint=ls", targetImage, "-1R", "/extras")
.run();

// No "bar" or "*.txt" files. Only copies the following:
// /extras/cat.json
// /extras/cat.txt
// /extras/foo
// /extras/sub/
// /extras/sub/a.json
assertThat(output).isEqualTo("/extras:\ncat.json\nfoo\nsub\n\n/extras/sub:\na.json\n");
assertThat(output).isEqualTo("/extras:\ncat.txt\nfoo\nsub\n\n/extras/sub:\na.json\n");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ jib {
path {
from = 'src/main/custom-extra-dir3'
into = '/extras'
includes = ['**/*a*']
includes = ['**/*a*', '*.txt']
excludes = ['**/*.txt']
}
path {
from = 'src/main/custom-extra-dir4'
into = '/extras'
includes = ['**/foo']
includes = ['foo']
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,11 @@ public void testExecute_simple_extraDirectoriesFiltering()
new Command("docker", "run", "--rm", "--entrypoint=ls", targetImage, "-1R", "/extras")
.run();

// No "bar" or "*.txt" files. Only copies the following:
// /extras/cat.json
// /extras/cat.txt
// /extras/foo
// /extras/sub/
// /extras/sub/a.json
assertThat(output).isEqualTo("/extras:\ncat.json\nfoo\nsub\n\n/extras/sub:\na.json\n");
assertThat(output).isEqualTo("/extras:\ncat.txt\nfoo\nsub\n\n/extras/sub:\na.json\n");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@
<path>
<from>${project.basedir}/src/main/jib-custom-3</from>
<into>/extras</into>
<includes>**/*a*</includes>
<includes>**/*a*,*.txt</includes>
<excludes>**/*.txt</excludes>
</path>
<path>
<from>src/main/jib-custom-4</from>
<into>/extras</into>
<includes>
<include>**/foo</include>
<include>foo</include>
</includes>
</path>
</paths>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,16 @@ public static FileEntriesLayer extraDirectoryLayerConfiguration(
excludes
.stream()
.map(pattern -> FileSystems.getDefault().getPathMatcher("glob:" + pattern))
.forEach(pathMatcher -> walker.filter(path -> !pathMatcher.matches(path)));
.forEach(
pathMatcher ->
walker.filter(path -> !pathMatcher.matches(sourceDirectory.relativize(path))));
// add an inclusion filter
includes
.stream()
.map(pattern -> FileSystems.getDefault().getPathMatcher("glob:" + pattern))
.map(pathMatcher -> (Predicate<Path>) path -> pathMatcher.matches(path))
.map(
pathMatcher ->
(Predicate<Path>) path -> pathMatcher.matches(sourceDirectory.relativize(path)))
.reduce((matches1, matches2) -> matches1.or(matches2))
.ifPresent(walker::filter);
// walk the source tree and add layer entries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ public void testExtraDirectoryLayerConfiguration_includes()
assertThat(layerConfiguration.getEntries())
.comparingElementsUsing(SOURCE_FILE_OF)
.containsExactly(
extraFilesDirectory.resolve("a"),
extraFilesDirectory.resolve("a/b/bar"),
extraFilesDirectory.resolve("c/cat"));
extraFilesDirectory.resolve("a/b/bar"), extraFilesDirectory.resolve("c/cat"));
}

@Test
Expand All @@ -130,6 +128,7 @@ public void testExtraDirectoryLayerConfiguration_excludes()
assertThat(layerConfiguration.getEntries())
.comparingElementsUsing(SOURCE_FILE_OF)
.containsExactly(
extraFilesDirectory.resolve("a"),
extraFilesDirectory.resolve("a/b"),
extraFilesDirectory.resolve("c"),
extraFilesDirectory.resolve("foo"));
Expand Down Expand Up @@ -158,7 +157,7 @@ public void testExtraDirectoryLayerConfiguration_includesAndExcludes()
JavaContainerBuilderHelper.extraDirectoryLayerConfiguration(
extraFilesDirectory,
AbsoluteUnixPath.get("/"),
Arrays.asList("**/*a*"),
Arrays.asList("**/*a*", "a"),
Arrays.asList("**/*c*"),
Collections.emptyMap(),
(ignored1, ignored2) -> Instant.EPOCH);
Expand Down

0 comments on commit 053a1d7

Please sign in to comment.