|
37 | 37 | import org.apache.commons.io.FilenameUtils; |
38 | 38 | import org.apache.commons.io.IOUtils; |
39 | 39 | import org.apache.maven.model.Resource; |
| 40 | +import org.codehaus.plexus.util.DirectoryScanner; |
40 | 41 | import org.codehaus.plexus.util.Scanner; |
41 | 42 | import org.slf4j.Logger; |
42 | 43 | import org.slf4j.LoggerFactory; |
@@ -189,20 +190,44 @@ public void filterResources(MavenResourcesExecution mavenResourcesExecution) thr |
189 | 190 | // as destination |
190 | 191 | // see MNG-1345 |
191 | 192 | File outputDirectory = mavenResourcesExecution.getOutputDirectory(); |
192 | | - boolean outputExists = outputDirectory.exists(); |
193 | | - if (!outputExists && !outputDirectory.mkdirs()) { |
| 193 | + if (!outputDirectory.mkdirs() && !outputDirectory.exists()) { |
194 | 194 | throw new MavenFilteringException("Cannot create resource output directory: " + outputDirectory); |
195 | 195 | } |
196 | 196 |
|
197 | 197 | if (resource.isFiltering()) { |
198 | 198 | isFilteringUsed = true; |
199 | 199 | } |
200 | 200 |
|
201 | | - boolean ignoreDelta = !outputExists |
202 | | - || buildContext.hasDelta(mavenResourcesExecution.getFileFilters()) |
203 | | - || buildContext.hasDelta(getRelativeOutputDirectory(mavenResourcesExecution)); |
204 | | - LOGGER.debug("ignoreDelta " + ignoreDelta); |
205 | | - Scanner scanner = buildContext.newScanner(resourceDirectory, ignoreDelta); |
| 201 | + boolean filtersFileChanged = buildContext.hasDelta(mavenResourcesExecution.getFileFilters()); |
| 202 | + Path resourcePath = resourceDirectory.toPath(); |
| 203 | + DirectoryScanner scanner = new DirectoryScanner() { |
| 204 | + @Override |
| 205 | + protected boolean isSelected(String name, File file) { |
| 206 | + if (filtersFileChanged) { |
| 207 | + // if the file filters file has a change we must assume everything is out of |
| 208 | + // date |
| 209 | + return true; |
| 210 | + } |
| 211 | + if (file.isFile()) { |
| 212 | + try { |
| 213 | + File targetFile = getTargetFile(file); |
| 214 | + if (targetFile.isFile() && buildContext.isUptodate(targetFile, file)) { |
| 215 | + return false; |
| 216 | + } |
| 217 | + } catch (MavenFilteringException e) { |
| 218 | + // can't really do anything than to assume we must copy the file... |
| 219 | + } |
| 220 | + } |
| 221 | + return true; |
| 222 | + } |
| 223 | + |
| 224 | + private File getTargetFile(File file) throws MavenFilteringException { |
| 225 | + Path relativize = resourcePath.relativize(file.toPath()); |
| 226 | + return getDestinationFile( |
| 227 | + outputDirectory, targetPath, relativize.toString(), mavenResourcesExecution); |
| 228 | + } |
| 229 | + }; |
| 230 | + scanner.setBasedir(resourceDirectory); |
206 | 231 |
|
207 | 232 | setupScanner(resource, scanner, mavenResourcesExecution.isAddDefaultExcludes()); |
208 | 233 |
|
@@ -276,13 +301,13 @@ public void filterResources(MavenResourcesExecution mavenResourcesExecution) thr |
276 | 301 |
|
277 | 302 | // deal with deleted source files |
278 | 303 |
|
279 | | - scanner = buildContext.newDeleteScanner(resourceDirectory); |
| 304 | + Scanner deleteScanner = buildContext.newDeleteScanner(resourceDirectory); |
280 | 305 |
|
281 | | - setupScanner(resource, scanner, mavenResourcesExecution.isAddDefaultExcludes()); |
| 306 | + setupScanner(resource, deleteScanner, mavenResourcesExecution.isAddDefaultExcludes()); |
282 | 307 |
|
283 | | - scanner.scan(); |
| 308 | + deleteScanner.scan(); |
284 | 309 |
|
285 | | - for (String name : scanner.getIncludedFiles()) { |
| 310 | + for (String name : deleteScanner.getIncludedFiles()) { |
286 | 311 | File destinationFile = getDestinationFile(outputDirectory, targetPath, name, mavenResourcesExecution); |
287 | 312 |
|
288 | 313 | destinationFile.delete(); |
|