diff --git a/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/SingleProjectIntegrationTest.java b/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/SingleProjectIntegrationTest.java
index 0abd8d9c5f..6d76a42743 100644
--- a/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/SingleProjectIntegrationTest.java
+++ b/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/SingleProjectIntegrationTest.java
@@ -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
diff --git a/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-extra-dirs-filtering.gradle b/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-extra-dirs-filtering.gradle
index fad3d437e6..4e04624dac 100644
--- a/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-extra-dirs-filtering.gradle
+++ b/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-extra-dirs-filtering.gradle
@@ -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']
}
}
}
diff --git a/jib-maven-plugin/src/integration-test/java/com/google/cloud/tools/jib/maven/BuildDockerMojoIntegrationTest.java b/jib-maven-plugin/src/integration-test/java/com/google/cloud/tools/jib/maven/BuildDockerMojoIntegrationTest.java
index c0f8a97776..422c7e6f5d 100644
--- a/jib-maven-plugin/src/integration-test/java/com/google/cloud/tools/jib/maven/BuildDockerMojoIntegrationTest.java
+++ b/jib-maven-plugin/src/integration-test/java/com/google/cloud/tools/jib/maven/BuildDockerMojoIntegrationTest.java
@@ -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
diff --git a/jib-maven-plugin/src/test/resources/maven/projects/simple/pom-extra-dirs-filtering.xml b/jib-maven-plugin/src/test/resources/maven/projects/simple/pom-extra-dirs-filtering.xml
index 812d6d1af9..1a5da943fc 100644
--- a/jib-maven-plugin/src/test/resources/maven/projects/simple/pom-extra-dirs-filtering.xml
+++ b/jib-maven-plugin/src/test/resources/maven/projects/simple/pom-extra-dirs-filtering.xml
@@ -48,14 +48,14 @@
${project.basedir}/src/main/jib-custom-3
/extras
- **/*a*
+ **/*a*,*.txt
**/*.txt
src/main/jib-custom-4
/extras
- **/foo
+ foo
diff --git a/jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/JavaContainerBuilderHelper.java b/jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/JavaContainerBuilderHelper.java
index 30eb90a504..2b06d6aed7 100644
--- a/jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/JavaContainerBuilderHelper.java
+++ b/jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/JavaContainerBuilderHelper.java
@@ -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 -> pathMatcher.matches(path))
+ .map(
+ pathMatcher ->
+ (Predicate) path -> pathMatcher.matches(sourceDirectory.relativize(path)))
.reduce((matches1, matches2) -> matches1.or(matches2))
.ifPresent(walker::filter);
// walk the source tree and add layer entries
diff --git a/jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/JavaContainerBuilderHelperTest.java b/jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/JavaContainerBuilderHelperTest.java
index 5df61ac0a4..5b45ec72c3 100644
--- a/jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/JavaContainerBuilderHelperTest.java
+++ b/jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/JavaContainerBuilderHelperTest.java
@@ -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
@@ -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"));
@@ -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);