View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.buildcache.checksum;
20  
21  import java.io.IOException;
22  import java.nio.file.Files;
23  import java.nio.file.Path;
24  import java.util.ArrayList;
25  import java.util.Arrays;
26  import java.util.Properties;
27  
28  import org.apache.maven.buildcache.checksum.exclude.Exclusion.EntryType;
29  import org.apache.maven.buildcache.checksum.exclude.Exclusion.MatcherType;
30  import org.apache.maven.buildcache.checksum.exclude.ExclusionResolver;
31  import org.apache.maven.buildcache.xml.CacheConfig;
32  import org.apache.maven.buildcache.xml.config.Exclude;
33  import org.apache.maven.model.Build;
34  import org.apache.maven.project.MavenProject;
35  import org.junit.jupiter.api.Assertions;
36  import org.junit.jupiter.api.Test;
37  import org.junit.jupiter.api.io.TempDir;
38  import org.mockito.Mockito;
39  
40  public class InputExclusionTest {
41  
42      @TempDir
43      private Path testFolder;
44  
45      /**
46       * Basic folder content exclusion
47       * @throws IOException
48       */
49      @Test
50      public void exclusionByFolder() throws IOException {
51          FsTree fsTree = createFsTree();
52  
53          // Exclude folder 1 + everything inside based on the starting path
54          ExclusionResolver exclusionResolver =
55                  createExclusionResolver("folder1", "**", EntryType.ALL, MatcherType.FILENAME);
56          Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.txtFileRootFolder));
57          Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.folder1));
58          Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.javaFileFolder1));
59          Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.subFolder1));
60          Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.txtFileSubFolder1));
61          Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.folder2));
62          Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.txtFileFolder2));
63  
64          // Exclude everything inside folder 1 based on the glob
65          exclusionResolver = createExclusionResolver("", "folder1/**", EntryType.ALL, MatcherType.PATH);
66          Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.txtFileRootFolder));
67          Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.folder1));
68          Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.javaFileFolder1));
69          Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.subFolder1));
70          Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.txtFileSubFolder1));
71          Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.folder2));
72          Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.txtFileFolder2));
73  
74          // Exclusion on folder
75          exclusionResolver = createExclusionResolver("", "folder1", EntryType.DIRECTORY, MatcherType.PATH);
76          Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.folder1));
77          exclusionResolver = createExclusionResolver("", "folder1", EntryType.DIRECTORY, MatcherType.FILENAME);
78          Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.folder1));
79          exclusionResolver = createExclusionResolver("", "folder1", EntryType.FILE, MatcherType.FILENAME);
80          Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.folder1));
81      }
82  
83      /**
84       * Files excluded by extension
85       * @throws IOException
86       */
87      @Test
88      public void exclusionByFileExtension() throws IOException {
89          FsTree fsTree = createFsTree();
90  
91          // Excludes all json files
92          ExclusionResolver exclusionResolver =
93                  createExclusionResolver("", "*.json", EntryType.FILE, MatcherType.FILENAME);
94          Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileRootFolder));
95          Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.jsonFileRootFolder));
96          Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileFolder1));
97          Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.jsonFileFolder1));
98          Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileSubFolder1));
99          Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.jsonFileSubFolder1));
100         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileFolder2));
101         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.jsonFileFolder2));
102 
103         // Excludes all json files under folder 1
104         exclusionResolver = createExclusionResolver("folder1", "*.json", EntryType.FILE, MatcherType.FILENAME);
105         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileRootFolder));
106         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileRootFolder));
107         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileFolder1));
108         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.jsonFileFolder1));
109         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileSubFolder1));
110         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.jsonFileSubFolder1));
111         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileFolder2));
112         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileFolder2));
113     }
114 
115     /**
116      * One file exclusion
117      * @throws IOException
118      */
119     @Test
120     public void exclusionOfOneSpecificFile() throws IOException {
121         FsTree fsTree = createFsTree();
122 
123         // Exclude the json file in subfolder 1
124         ExclusionResolver exclusionResolver = createExclusionResolver(
125                 "folder1/subfolder1/other-file.json", "**", EntryType.ALL, MatcherType.FILENAME);
126         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileRootFolder));
127         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.txtFileRootFolder));
128         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileRootFolder));
129         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileFolder1));
130         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.txtFileFolder1));
131         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileFolder1));
132         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileSubFolder1));
133         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.txtFileSubFolder1));
134         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.jsonFileSubFolder1));
135         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileFolder2));
136         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.txtFileFolder2));
137         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileFolder2));
138 
139         // Exclude the json file in subfolder 1 by glob v1
140         exclusionResolver =
141                 createExclusionResolver("folder1/subfolder1", "other-file.json", EntryType.ALL, MatcherType.FILENAME);
142         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileRootFolder));
143         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.txtFileRootFolder));
144         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileRootFolder));
145         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileFolder1));
146         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.txtFileFolder1));
147         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileFolder1));
148         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileSubFolder1));
149         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.txtFileSubFolder1));
150         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.jsonFileSubFolder1));
151         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileFolder2));
152         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.txtFileFolder2));
153         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileFolder2));
154 
155         // Exclude the json file in subfolder 1 by glob v2
156         exclusionResolver =
157                 createExclusionResolver("", "folder1/subfolder1/other-file.json", EntryType.ALL, MatcherType.PATH);
158         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileRootFolder));
159         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.txtFileRootFolder));
160         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileRootFolder));
161         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileFolder1));
162         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.txtFileFolder1));
163         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileFolder1));
164         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileSubFolder1));
165         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.txtFileSubFolder1));
166         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.jsonFileSubFolder1));
167         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileFolder2));
168         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.txtFileFolder2));
169         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileFolder2));
170     }
171 
172     /**
173      * One file exclusion with the windows (DOS) path and glob syntax
174      * @throws IOException
175      */
176     @Test
177     public void exclusionOfOneSpecificFileWindowsStyle() throws IOException {
178         FsTree fsTree = createFsTree();
179 
180         // Exclude the json file in subfolder 1
181         ExclusionResolver exclusionResolver = createExclusionResolver(
182                 "folder1\\subfolder1\\other-file.json", "**", EntryType.ALL, MatcherType.FILENAME);
183         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileRootFolder));
184         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.txtFileRootFolder));
185         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileRootFolder));
186         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileFolder1));
187         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.txtFileFolder1));
188         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileFolder1));
189         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileSubFolder1));
190         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.txtFileSubFolder1));
191         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.jsonFileSubFolder1));
192         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileFolder2));
193         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.txtFileFolder2));
194         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileFolder2));
195 
196         // Exclude the json file in subfolder 1 by glob v1
197         exclusionResolver =
198                 createExclusionResolver("folder1\\subfolder1", "other-file.json", EntryType.ALL, MatcherType.FILENAME);
199         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileRootFolder));
200         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.txtFileRootFolder));
201         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileRootFolder));
202         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileFolder1));
203         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.txtFileFolder1));
204         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileFolder1));
205         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileSubFolder1));
206         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.txtFileSubFolder1));
207         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.jsonFileSubFolder1));
208         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileFolder2));
209         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.txtFileFolder2));
210         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileFolder2));
211 
212         // Exclude the json file in subfolder 1 by glob v2 (\ is a meta character in glob syntax + in java syntax, so we
213         // need to double escape it)
214         exclusionResolver = createExclusionResolver(
215                 "", "folder1\\\\subfolder1\\\\other-file.json", EntryType.ALL, MatcherType.PATH);
216         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileRootFolder));
217         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.txtFileRootFolder));
218         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileRootFolder));
219         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileFolder1));
220         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.txtFileFolder1));
221         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileFolder1));
222         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileSubFolder1));
223         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.txtFileSubFolder1));
224         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.jsonFileSubFolder1));
225         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileFolder2));
226         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.txtFileFolder2));
227         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileFolder2));
228     }
229 
230     /**
231      * Exclusion by a pattern in the filename
232      * @throws IOException
233      */
234     @Test
235     public void exclusionByPatternInFilename() throws IOException {
236         FsTree fsTree = createFsTree();
237 
238         // Excludes all files containing the string "my-f" in their filename
239         ExclusionResolver exclusionResolver =
240                 createExclusionResolver("", "*my-f*", EntryType.ALL, MatcherType.FILENAME);
241         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.javaFileRootFolder));
242         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.txtFileRootFolder));
243         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileRootFolder));
244         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.javaFileFolder1));
245         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.txtFileFolder1));
246         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileFolder1));
247         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.javaFileSubFolder1));
248         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.txtFileSubFolder1));
249         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileSubFolder1));
250         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.javaFileFolder2));
251         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.txtFileFolder2));
252         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileFolder2));
253 
254         // Excludes all files containing the string "my-f" in their path
255         exclusionResolver = createExclusionResolver("", "**my-f*", EntryType.ALL, MatcherType.PATH);
256         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.javaFileRootFolder));
257         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.txtFileRootFolder));
258         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileRootFolder));
259         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.javaFileFolder1));
260         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.txtFileFolder1));
261         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileFolder1));
262         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.javaFileSubFolder1));
263         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.txtFileSubFolder1));
264         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileSubFolder1));
265         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.javaFileFolder2));
266         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.txtFileFolder2));
267         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileFolder2));
268     }
269 
270     /**
271      * Via project properties, excludes :
272      * - all files in folder 1
273      * - the json file in subfolder 1
274      * - txt files everywhere
275      * @throws IOException
276      */
277     @Test
278     public void exclusionViaProjectProperties() throws IOException {
279         FsTree fsTree = createFsTree();
280 
281         MavenProject mavenProject = Mockito.mock(MavenProject.class);
282         Mockito.when(mavenProject.getBasedir()).thenReturn(testFolder.toFile());
283         Build build = Mockito.mock(Build.class);
284         Mockito.when(build.getDirectory())
285                 .thenReturn(testFolder.resolve("target").toString());
286         Mockito.when(build.getOutputDirectory())
287                 .thenReturn(testFolder.resolve("target/classes").toString());
288         Mockito.when(build.getTestOutputDirectory())
289                 .thenReturn(testFolder.resolve("target/test-classes").toString());
290         Mockito.when(mavenProject.getBuild()).thenReturn(build);
291 
292         Properties properties = new Properties();
293         // all files in the folder 1
294         properties.setProperty(ExclusionResolver.PROJECT_PROPERTY_EXCLUDE_VALUE + ".1", "");
295         properties.setProperty(ExclusionResolver.PROJECT_PROPERTY_EXCLUDE_GLOB + ".1", "folder1/*");
296         properties.setProperty(ExclusionResolver.PROJECT_PROPERTY_EXCLUDE_ENTRY_TYPE + ".1", EntryType.FILE.toString());
297         properties.setProperty(
298                 ExclusionResolver.PROJECT_PROPERTY_EXCLUDE_MATCHER_TYPE + ".1", MatcherType.PATH.toString());
299         // json file in subfolder 1
300         properties.setProperty(ExclusionResolver.PROJECT_PROPERTY_EXCLUDE_VALUE + ".2", "folder1/subfolder1");
301         properties.setProperty(ExclusionResolver.PROJECT_PROPERTY_EXCLUDE_GLOB + ".2", "other-file.json");
302         properties.setProperty(ExclusionResolver.PROJECT_PROPERTY_EXCLUDE_ENTRY_TYPE + ".2", EntryType.FILE.toString());
303         properties.setProperty(
304                 ExclusionResolver.PROJECT_PROPERTY_EXCLUDE_MATCHER_TYPE + ".2", MatcherType.FILENAME.toString());
305         // txt files everywhere
306         properties.setProperty(ExclusionResolver.PROJECT_PROPERTY_EXCLUDE_GLOB + ".3", "*.txt");
307         Mockito.when(mavenProject.getProperties()).thenReturn(properties);
308 
309         ExclusionResolver exclusionResolver = createExclusionResolver(mavenProject);
310         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileRootFolder));
311         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.txtFileRootFolder));
312         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileRootFolder));
313         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.javaFileFolder1));
314         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.txtFileFolder1));
315         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.jsonFileFolder1));
316         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileSubFolder1));
317         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.txtFileSubFolder1));
318         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.jsonFileSubFolder1));
319         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.javaFileFolder2));
320         Assertions.assertTrue(exclusionResolver.excludesPath(fsTree.txtFileFolder2));
321         Assertions.assertFalse(exclusionResolver.excludesPath(fsTree.jsonFileFolder2));
322     }
323 
324     private FsTree createFsTree() throws IOException {
325         FsTree fsTree = new FsTree();
326         fsTree.txtFileRootFolder = Files.createFile(testFolder.resolve("my-file.txt"));
327         fsTree.javaFileRootFolder = Files.createFile(testFolder.resolve("my-file.java"));
328         fsTree.jsonFileRootFolder = Files.createFile(testFolder.resolve("other-file.json"));
329 
330         fsTree.folder1 = Files.createDirectories(testFolder.resolve("folder1"));
331         fsTree.txtFileFolder1 = Files.createFile(fsTree.folder1.resolve("my-file.txt"));
332         fsTree.javaFileFolder1 = Files.createFile(fsTree.folder1.resolve("my-file.java"));
333         fsTree.jsonFileFolder1 = Files.createFile(fsTree.folder1.resolve("other-file.json"));
334 
335         fsTree.subFolder1 = Files.createDirectories(fsTree.folder1.resolve("subfolder1"));
336         fsTree.txtFileSubFolder1 = Files.createFile(fsTree.subFolder1.resolve("my-file.txt"));
337         fsTree.javaFileSubFolder1 = Files.createFile(fsTree.subFolder1.resolve("my-file.java"));
338         fsTree.jsonFileSubFolder1 = Files.createFile(fsTree.subFolder1.resolve("other-file.json"));
339 
340         fsTree.folder2 = Files.createDirectories(testFolder.resolve("folder2"));
341         fsTree.txtFileFolder2 = Files.createFile(fsTree.folder2.resolve("my-file.txt"));
342         fsTree.javaFileFolder2 = Files.createFile(fsTree.folder2.resolve("my-file.java"));
343         fsTree.jsonFileFolder2 = Files.createFile(fsTree.folder2.resolve("other-file.json"));
344         return fsTree;
345     }
346 
347     private ExclusionResolver createExclusionResolver(MavenProject mavenProject) {
348 
349         CacheConfig cacheConfig = Mockito.mock(CacheConfig.class);
350         Mockito.when(cacheConfig.getGlobalExcludePaths()).thenReturn(new ArrayList<>());
351         ExclusionResolver resolver = new ExclusionResolver(mavenProject, cacheConfig);
352         return resolver;
353     }
354 
355     private ExclusionResolver createExclusionResolver(
356             String value, String glob, EntryType entryType, MatcherType matcherType) {
357         MavenProject mavenProject = Mockito.mock(MavenProject.class);
358         Mockito.when(mavenProject.getBasedir()).thenReturn(testFolder.toFile());
359         Mockito.when(mavenProject.getProperties()).thenReturn(new Properties());
360 
361         Build build = Mockito.mock(Build.class);
362         Mockito.when(build.getDirectory())
363                 .thenReturn(testFolder.resolve("target").toString());
364         Mockito.when(build.getOutputDirectory())
365                 .thenReturn(testFolder.resolve("target/classes").toString());
366         Mockito.when(build.getTestOutputDirectory())
367                 .thenReturn(testFolder.resolve("target/test-classes").toString());
368         Mockito.when(mavenProject.getBuild()).thenReturn(build);
369 
370         Exclude exclude = new Exclude();
371         exclude.setValue(value);
372         exclude.setGlob(glob);
373         exclude.setEntryType(entryType.toString());
374         exclude.setMatcherType(matcherType.toString());
375 
376         CacheConfig cacheConfig = Mockito.mock(CacheConfig.class);
377         Mockito.when(cacheConfig.getGlobalExcludePaths()).thenReturn(Arrays.asList(exclude));
378         ExclusionResolver resolver = new ExclusionResolver(mavenProject, cacheConfig);
379         return resolver;
380     }
381 
382     /**
383      * Folders and files with the following hierarchy
384      *
385      * root
386      * - my-file.txt
387      * - my-file.java
388      * - other-file.json
389      * \-- folder 1
390      *     - my-file.txt
391      *     - my-file.java
392      *     - other-file.json
393      *     \-- subfolder1
394      *         - my-file.txt
395      *         - my-file.java
396      *         - other-file.json
397      * \-- folder 2
398      *     - my-file.txt
399      *     - my-file.java
400      *     - other-file.json
401      */
402     private class FsTree {
403         public Path txtFileRootFolder;
404         public Path javaFileRootFolder;
405         public Path jsonFileRootFolder;
406         public Path folder1;
407         public Path txtFileFolder1;
408         public Path javaFileFolder1;
409         public Path jsonFileFolder1;
410         public Path subFolder1;
411         public Path txtFileSubFolder1;
412         public Path javaFileSubFolder1;
413         public Path jsonFileSubFolder1;
414         public Path folder2;
415         public Path txtFileFolder2;
416         public Path javaFileFolder2;
417         public Path jsonFileFolder2;
418     }
419 }