Skip to content

Commit a097fac

Browse files
joerwinKostyaSha
authored andcommitted
Ignore all but specified files (docker-java#1105)
* Implement fix for ignore all files except specified, with a test * Fix Typo
1 parent cb7a56d commit a097fac

File tree

7 files changed

+22
-6
lines changed

7 files changed

+22
-6
lines changed

src/main/java/com/github/dockerjava/core/dockerfile/Dockerfile.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,10 @@ private void addFilesInDirectory(File directory) {
205205

206206
if (files.length != 0) {
207207
for (File f : files) {
208-
if (effectiveMatchingIgnorePattern(f) == null) {
209-
if (f.isDirectory()) {
210-
addFilesInDirectory(f);
211-
} else {
212-
filesToAdd.add(f);
213-
}
208+
if (f.isDirectory()) {
209+
addFilesInDirectory(f);
210+
} else if (effectiveMatchingIgnorePattern(f) == null) {
211+
filesToAdd.add(f);
214212
}
215213
}
216214
// base directory should at least contains Dockerfile, but better check

src/test/java/com/github/dockerjava/core/dockerfile/DockerfileAddMultipleFilesTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ public String apply(File file) {
2424
}
2525
};
2626

27+
@Test
28+
public void ignoreAllBut() throws Exception {
29+
File baseDir = fileFromBuildTestResource("dockerignore/IgnoreAllBut");
30+
Dockerfile dockerfile = new Dockerfile(new File(baseDir, "Dockerfile"), baseDir);
31+
Dockerfile.ScannedResult result = dockerfile.parse();
32+
Collection<String> filesToAdd = transform(result.filesToAdd, TO_FILE_NAMES);
33+
34+
assertThat(filesToAdd,
35+
containsInAnyOrder("Dockerfile", "foo.jar"));
36+
}
37+
2738
@Test
2839
public void nestedDirsPatterns() throws Exception {
2940
File baseDir = fileFromBuildTestResource("dockerignore/NestedDirsDockerignore");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*
2+
!Dockerfile
3+
!build/libs/foo.jar
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM ubuntu:18.04
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DO NOT WANT THIS IN THE DOCKER
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo.jar
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FILE

0 commit comments

Comments
 (0)