[ 
https://issues.apache.org/jira/browse/MBUILDCACHE-64?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17760679#comment-17760679
 ] 

ASF GitHub Bot commented on MBUILDCACHE-64:
-------------------------------------------

AlexanderAshitkin commented on code in PR #91:
URL: 
https://github.com/apache/maven-build-cache-extension/pull/91#discussion_r1311031579


##########
src/main/java/org/apache/maven/buildcache/checksum/MavenProjectInput.java:
##########
@@ -165,45 +185,101 @@ public MavenProjectInput(
         this.repoSystem = repoSystem;
         this.remoteCache = remoteCache;
         Properties properties = project.getProperties();
-        this.dirGlob = properties.getProperty(CACHE_INPUT_GLOB_NAME, 
config.getDefaultGlob());
+        this.projectGlob = properties.getProperty(CACHE_INPUT_GLOB_NAME, 
config.getDefaultGlob());
         this.processPlugins =
                 
Boolean.parseBoolean(properties.getProperty(CACHE_PROCESS_PLUGINS, 
config.isProcessPlugins()));
         this.tmpDir = System.getProperty("java.io.tmpdir");
 
-        org.apache.maven.model.Build build = project.getBuild();
-        filteredOutPaths = new ArrayList<>(Arrays.asList(
-                normalizedPath(build.getDirectory()), // target by default
-                normalizedPath(build.getOutputDirectory()),
-                normalizedPath(build.getTestOutputDirectory())));
+        this.baseDirectoryGlobPrefix = baseDirPath.toString().replace("\\", 
"/") + "/";
+
+        addDefaultExcludeSection(project);
 
         List<Exclude> excludes = config.getGlobalExcludePaths();
         for (Exclude excludePath : excludes) {
-            filteredOutPaths.add(Paths.get(excludePath.getValue()));
+            addToExcludedSection(excludePath.getValue(), true);
         }
 
         for (String propertyName : properties.stringPropertyNames()) {
             if (propertyName.startsWith(CACHE_EXCLUDE_NAME)) {
                 String propertyValue = properties.getProperty(propertyName);
-                Path path = Paths.get(propertyValue);
-                filteredOutPaths.add(path);
+                addToExcludedSection(propertyValue, true);
+
                 if (LOGGER.isDebugEnabled()) {
                     LOGGER.debug(
-                            "Adding an excludePath from property '{}', values 
is '{}', path is '{}' ",
-                            propertyName,
-                            propertyValue,
-                            path);
+                            "Adding an excludePath from property '{}', value 
is '{}'", propertyName, propertyValue);
                 }
             }
         }
         CacheUtils.debugPrintCollection(
-                LOGGER,
-                filteredOutPaths,
-                "List of excluded paths (checked either by fileName or by 
startsWith prefix)",
-                "Path entry");
+                LOGGER, inputExcludePathMatcherString, "List of excluded glob 
patterns", "Pattern");
 
         this.fileComparator = new PathIgnoringCaseComparator();
     }
 
+    private void addDefaultExcludeSection(MavenProject project) {
+
+        Build build = project.getBuild();
+        Path buildDirectoryPath = normalizedPath(build.getDirectory());
+        Path outputDirectoryPath = normalizedPath(build.getOutputDirectory());
+        Path testOutputDirectoryPath = 
normalizedPath(build.getTestOutputDirectory());
+        addToExcludedSection(
+                
convertToPathMatcherFileSeperator(buildDirectoryPath.toString()) + 
GLOB_SX_FULL_SUB_TREE,
+                false); // target by default
+
+        if (!outputDirectoryPath.startsWith(buildDirectoryPath)) {
+            addToExcludedSection(
+                    
convertToPathMatcherFileSeperator(outputDirectoryPath.toString()) + 
GLOB_SX_FULL_SUB_TREE,
+                    false); // target/classes by default
+        }
+        if (!testOutputDirectoryPath.startsWith(buildDirectoryPath)) {
+            addToExcludedSection(
+                    
convertToPathMatcherFileSeperator(testOutputDirectoryPath.toString()) + 
GLOB_SX_FULL_SUB_TREE,
+                    false); // target/test-classes by default
+        }
+    }
+
+    private String convertToPathMatcherFileSeperator(String path) {
+        return path.replace("\\", "/");
+    }
+
+    /**
+     * Add a value from the excluded section list to the directories and/or 
the filenames ban list.
+     * @param excludedValue a value from the exclude list
+     */
+    private void addToExcludedSection(String excludedValue, boolean 
addProjectBaseDir) {

Review Comment:
   Why need the `addProjectBaseDir` parameter? Intuitively, the project dir 
should always be prepended. Otherwise, the `exclude` could be applied to an 
unexpected subtree (calculated not from the root but to a nested one)





> Apply global exclusions to folder names
> ---------------------------------------
>
>                 Key: MBUILDCACHE-64
>                 URL: https://issues.apache.org/jira/browse/MBUILDCACHE-64
>             Project: Maven Build Cache Extension
>          Issue Type: Bug
>    Affects Versions: 1.0.1
>            Reporter: Frank Wagner
>            Assignee: Olivier Lamy
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.1.0
>
>
> It is currently not possible to exclude folders by their name, like 
> {quote}<input>
> <global>
> <excludes>
> <exclude>node_modules</exclude>
> <exclude>dist</exclude>
> <exclude>build</exclude>
> </excludes>
> </global>
> ...
> {quote}
> That's because isFilteredOutSubpath(), 
> [https://github.com/apache/maven-build-cache-extension/blob/master/src/main/java/org/apache/maven/buildcache/checksum/MavenProjectInput.java#L638,]
>  uses startWith on normalized absolute paths.
> That function could be enhanced with an additional criterion like in 
> [https://github.com/apache/maven-build-cache-extension/blob/master/src/main/java/org/apache/maven/buildcache/checksum/MavenProjectInput.java#L510]
> {{filteredOutPaths.stream().anyMatch(it -> 
> it.getFileName().equals(entry.getFileName()))}}
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to