GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — MSHARED-1285 use an up-to-date scanner instead the newscanner · apache/maven-filtering@74a967d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src/main/java/org/apache/maven/shared/filtering
    • DefaultMavenResourcesFiltering.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java‎

Copy file name to clipboardExpand all lines: src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
+36-11Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.apache.commons.io.FilenameUtils;
3838
import org.apache.commons.io.IOUtils;
3939
import org.apache.maven.model.Resource;
40+
import org.codehaus.plexus.util.DirectoryScanner;
4041
import org.codehaus.plexus.util.Scanner;
4142
import org.slf4j.Logger;
4243
import org.slf4j.LoggerFactory;
@@ -189,20 +190,44 @@ public void filterResources(MavenResourcesExecution mavenResourcesExecution) thr
189190
// as destination
190191
// see MNG-1345
191192
File outputDirectory = mavenResourcesExecution.getOutputDirectory();
192-
boolean outputExists = outputDirectory.exists();
193-
if (!outputExists && !outputDirectory.mkdirs()) {
193+
if (!outputDirectory.mkdirs() && !outputDirectory.exists()) {
194194
throw new MavenFilteringException("Cannot create resource output directory: " + outputDirectory);
195195
}
196196

197197
if (resource.isFiltering()) {
198198
isFilteringUsed = true;
199199
}
200200

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);
206231

207232
setupScanner(resource, scanner, mavenResourcesExecution.isAddDefaultExcludes());
208233

@@ -276,13 +301,13 @@ public void filterResources(MavenResourcesExecution mavenResourcesExecution) thr
276301

277302
// deal with deleted source files
278303

279-
scanner = buildContext.newDeleteScanner(resourceDirectory);
304+
Scanner deleteScanner = buildContext.newDeleteScanner(resourceDirectory);
280305

281-
setupScanner(resource, scanner, mavenResourcesExecution.isAddDefaultExcludes());
306+
setupScanner(resource, deleteScanner, mavenResourcesExecution.isAddDefaultExcludes());
282307

283-
scanner.scan();
308+
deleteScanner.scan();
284309

285-
for (String name : scanner.getIncludedFiles()) {
310+
for (String name : deleteScanner.getIncludedFiles()) {
286311
File destinationFile = getDestinationFile(outputDirectory, targetPath, name, mavenResourcesExecution);
287312

288313
destinationFile.delete();

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.