You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2022/05/17 21:11:09 UTC

[maven-build-cache-extension] 02/02: [MBUILDCACHE-21] Improve default exclusions when testing directories

This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-build-cache-extension.git

commit 056b27efc6b2abe5491f6fa6ba34b35bb4aa6c9d
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Tue May 17 10:25:04 2022 +0200

    [MBUILDCACHE-21] Improve default exclusions when testing directories
---
 .../buildcache/checksum/MavenProjectInput.java     | 30 +++++++++++++---
 .../apache/maven/buildcache/its/Issue21Test.java   | 40 ++++++++++++++++++++++
 .../.mvn/maven-build-cache-config.xml              | 24 +++++++++++++
 src/test/projects/mbuildcache-21/pom.xml           | 39 +++++++++++++++++++++
 4 files changed, 128 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/maven/buildcache/checksum/MavenProjectInput.java b/src/main/java/org/apache/maven/buildcache/checksum/MavenProjectInput.java
index 0c99a78..2ca6f9f 100644
--- a/src/main/java/org/apache/maven/buildcache/checksum/MavenProjectInput.java
+++ b/src/main/java/org/apache/maven/buildcache/checksum/MavenProjectInput.java
@@ -139,6 +139,7 @@ public class MavenProjectInput
     private final Path baseDirPath;
     private final String dirGlob;
     private final boolean processPlugins;
+    private final String tmpDir;
 
     @SuppressWarnings( "checkstyle:parameternumber" )
     public MavenProjectInput( MavenProject project,
@@ -163,6 +164,7 @@ public class MavenProjectInput
         this.dirGlob = 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
@@ -558,6 +560,14 @@ public class MavenProjectInput
                 LOGGER.debug( "Visiting subtree: {}", path );
                 return FileVisitResult.CONTINUE;
             }
+
+            @Override
+            public FileVisitResult visitFileFailed( Path path, IOException exc )
+                    throws IOException
+            {
+                LOGGER.debug( "Skipping subtree (exception: {}): {}", exc, path );
+                return FileVisitResult.SKIP_SUBTREE;
+            }
         } );
     }
 
@@ -613,15 +623,25 @@ public class MavenProjectInput
     private Path getPathOrNull( String text )
     {
         // small optimization to not probe not-paths
-        boolean blacklisted = isBlank( text )
-                || equalsAnyIgnoreCase( text, "true", "false", "utf-8", "null", "\\" ) // common values
+        if ( isBlank( text ) )
+        {
+            // do not even bother logging about blank/null values
+        }
+        else if ( equalsAnyIgnoreCase( text, "true", "false", "utf-8", "null", "\\" ) // common values
                 || contains( text, "*" ) // tag value is a glob or regex - unclear how to process
                 || ( contains( text, ":" ) && !contains( text, ":\\" ) )// artifactId
                 || startsWithAny( text, "com.", "org.", "io.", "java.", "javax." ) // java packages
                 || startsWithAny( text, "${env." ) // env variables in maven notation
                 || startsWithAny( text, "http:", "https:", "scm:", "ssh:", "git:", "svn:", "cp:",
-                        "classpath:" ); // urls identified by common protocols
-        if ( !blacklisted )
+                        "classpath:" ) ) // urls identified by common protocols
+        {
+            LOGGER.debug( "Skipping directory (blacklisted literal): {}", text );
+        }
+        else if ( startsWithAny( text, tmpDir ) ) // tmp dir
+        {
+            LOGGER.debug( "Skipping directory (temp dir): {}", text );
+        }
+        else
         {
             try
             {
@@ -629,9 +649,9 @@ public class MavenProjectInput
             }
             catch ( Exception ignore )
             {
+                LOGGER.debug( "Skipping directory (invalid path): {}", text );
             }
         }
-        LOGGER.debug( "{}: {}", text, blacklisted ? "skipped(blacklisted literal)" : "invalid path" );
         return null;
     }
 
diff --git a/src/test/java/org/apache/maven/buildcache/its/Issue21Test.java b/src/test/java/org/apache/maven/buildcache/its/Issue21Test.java
new file mode 100644
index 0000000..f77d667
--- /dev/null
+++ b/src/test/java/org/apache/maven/buildcache/its/Issue21Test.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.buildcache.its;
+
+import org.apache.maven.buildcache.its.junit.IntegrationTest;
+import org.apache.maven.buildcache.its.junit.Test;
+import org.apache.maven.it.VerificationException;
+import org.apache.maven.it.Verifier;
+
+@IntegrationTest( "src/test/projects/mbuildcache-21" )
+public class Issue21Test
+{
+
+    @Test
+    void simple( Verifier verifier ) throws VerificationException
+    {
+        verifier.setAutoclean( false );
+
+        verifier.setLogFileName( "../log.txt" );
+        verifier.executeGoal( "verify" );
+        verifier.verifyErrorFreeLog();
+    }
+
+}
diff --git a/src/test/projects/mbuildcache-21/.mvn/maven-build-cache-config.xml b/src/test/projects/mbuildcache-21/.mvn/maven-build-cache-config.xml
new file mode 100644
index 0000000..f23c467
--- /dev/null
+++ b/src/test/projects/mbuildcache-21/.mvn/maven-build-cache-config.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<cache xmlns="http://maven.apache.org/CACHE-CONFIG/1.0.0">
+
+</cache>
diff --git a/src/test/projects/mbuildcache-21/pom.xml b/src/test/projects/mbuildcache-21/pom.xml
new file mode 100644
index 0000000..63e440c
--- /dev/null
+++ b/src/test/projects/mbuildcache-21/pom.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>org.example</groupId>
+    <artifactId>build_cache_test</artifactId>
+    <version>1.0-SNAPSHOT</version>
+
+    <properties>
+        <maven.compiler.source>1.8</maven.compiler.source>
+        <maven.compiler.target>1.8</maven.compiler.target>
+    </properties>
+
+
+    <build>
+        <extensions>
+            <extension>
+                <groupId>org.apache.maven.extensions</groupId>
+                <artifactId>maven-build-cache-extension</artifactId>
+                <version>1.0.0-SNAPSHOT</version>
+            </extension>
+        </extensions>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <version>3.0.0-M5</version>
+                <configuration>
+                    <systemPropertyVariables>
+                        <java.awt.headless>true</java.awt.headless>
+                        <java.io.tmpdir>${java.io.tmpdir}</java.io.tmpdir>
+                    </systemPropertyVariables>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>