55import com .github .dockerjava .core .util .FilePathUtil ;
66import com .github .dockerjava .core .GoLangFileMatch ;
77import com .github .dockerjava .core .exception .GoLangFileMatchException ;
8- import com .github .dockerjava .core .GoLangMatchFileFilter ;
98import com .google .common .base .Function ;
109import com .google .common .base .Objects ;
1110import com .google .common .base .Optional ;
2120import java .io .InputStream ;
2221import java .util .ArrayList ;
2322import java .util .Collection ;
24- import java .util .HashMap ;
2523import java .util .List ;
26- import java .util .Map ;
2724import java .util .UUID ;
2825
2926/**
@@ -115,8 +112,6 @@ public class ScannedResult {
115112
116113 final List <String > ignores ;
117114
118- final Map <String , String > environmentMap = new HashMap <String , String >();
119-
120115 final List <File > filesToAdd = new ArrayList <File >();
121116
122117 public InputStream buildDockerFolderTar () {
@@ -162,7 +157,8 @@ public void close() throws IOException {
162157
163158 @ Override
164159 public String toString () {
165- return Objects .toStringHelper (this ).add ("ignores" , ignores ).add ("environmentMap" , environmentMap )
160+ return Objects .toStringHelper (this )
161+ .add ("ignores" , ignores )
166162 .add ("filesToAdd" , filesToAdd ).toString ();
167163 }
168164
@@ -172,18 +168,17 @@ public ScannedResult() throws IOException {
172168
173169 String matchingIgnorePattern = effectiveMatchingIgnorePattern (dockerFile );
174170
175- if (matchingIgnorePattern == null ) {
176- filesToAdd .add (dockerFile );
177- } else {
171+ if (matchingIgnorePattern != null ) {
178172 throw new DockerClientException (String .format (
179173 "Dockerfile is excluded by pattern '%s' in .dockerignore file" , matchingIgnorePattern ));
180174 }
181175
182- for (DockerfileStatement statement : getStatements ()) {
183- if (statement instanceof DockerfileStatement .Env ) {
184- processEnvStatement ((DockerfileStatement .Env ) statement );
185- } else if (statement instanceof DockerfileStatement .Add ) {
186- processAddStatement ((DockerfileStatement .Add ) statement );
176+ Collection <File > filesInBuildContext = FileUtils .listFiles (getDockerFolder (), TrueFileFilter .INSTANCE ,
177+ TrueFileFilter .INSTANCE );
178+
179+ for (File f : filesInBuildContext ) {
180+ if (effectiveMatchingIgnorePattern (f ) == null ) {
181+ filesToAdd .add (f );
187182 }
188183 }
189184 }
@@ -238,62 +233,5 @@ private String effectiveMatchingIgnorePattern(File file) {
238233
239234 return lastMatchingPattern ;
240235 }
241-
242- private void processAddStatement (DockerfileStatement .Add add ) throws IOException {
243-
244- add = add .transform (environmentMap );
245-
246- for (String resource : add .getFileResources ()) {
247-
248- File dockerFolder = getDockerFolder ();
249-
250- File src = new File (resource );
251- if (!src .isAbsolute ()) {
252- src = new File (dockerFolder , resource );
253- } else {
254- throw new DockerClientException (String .format ("Source file %s must be relative to %s" , src ,
255- dockerFolder ));
256- }
257-
258- if (src .exists ()) {
259- src = src .getCanonicalFile ();
260- if (src .isDirectory ()) {
261- Collection <File > files = FileUtils .listFiles (src , new GoLangMatchFileFilter (src , ignores ),
262- TrueFileFilter .INSTANCE );
263- filesToAdd .addAll (files );
264- } else if (effectiveMatchingIgnorePattern (src ) == null ) {
265- filesToAdd .add (src );
266- } else {
267- throw new DockerClientException (String .format (
268- "Source file %s is excluded by .dockerignore file" , src ));
269- }
270- } else {
271- filesToAdd .addAll (resolveWildcards (src , ignores ));
272- }
273- }
274- }
275-
276- private Collection <File > resolveWildcards (File file , List <String > ignores ) {
277- List <File > filesToAdd = new ArrayList <File >();
278-
279- File parent = file .getParentFile ();
280- if (parent != null ) {
281- if (parent .isDirectory ()) {
282- Collection <File > files = FileUtils .listFiles (parent , new GoLangMatchFileFilter (parent , ignores ),
283- TrueFileFilter .INSTANCE );
284- filesToAdd .addAll (files );
285- } else {
286- filesToAdd .addAll (resolveWildcards (parent , ignores ));
287- }
288- } else {
289- throw new DockerClientException (String .format ("Source file %s doesn't exist" , file ));
290- }
291-
292- return filesToAdd ;
293- }
294-
295- private void processEnvStatement (DockerfileStatement .Env env ) {
296- environmentMap .put (env .variable , env .value );
297- }
298236 }
299237}
0 commit comments