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:07 UTC

[maven-build-cache-extension] branch master updated (abe934c -> 056b27e)

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

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


    from abe934c  [MBUILDCACHE-20] Use local cache before remote cache
     new 7199471  [MBUILDCACHE-21] Exclude files and directories which are not readable
     new 056b27e  [MBUILDCACHE-21] Improve default exclusions when testing directories

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../buildcache/checksum/MavenProjectInput.java     | 42 ++++++++++++++++++----
 .../{CoreExtensionTest.java => Issue21Test.java}   | 11 ++----
 .../.mvn/maven-build-cache-config.xml              |  0
 src/test/projects/mbuildcache-21/pom.xml           | 39 ++++++++++++++++++++
 4 files changed, 78 insertions(+), 14 deletions(-)
 copy src/test/java/org/apache/maven/buildcache/its/{CoreExtensionTest.java => Issue21Test.java} (78%)
 copy src/test/projects/{build-extension => mbuildcache-21}/.mvn/maven-build-cache-config.xml (100%)
 create mode 100644 src/test/projects/mbuildcache-21/pom.xml


[maven-build-cache-extension] 01/02: [MBUILDCACHE-21] Exclude files and directories which are not readable

Posted by gn...@apache.org.
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 71994712bc50f0880594d24ece2b7f46d6d96196
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Tue May 17 09:50:40 2022 +0200

    [MBUILDCACHE-21] Exclude files and directories which are not readable
---
 .../apache/maven/buildcache/checksum/MavenProjectInput.java  | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

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 a717421..0c99a78 100644
--- a/src/main/java/org/apache/maven/buildcache/checksum/MavenProjectInput.java
+++ b/src/main/java/org/apache/maven/buildcache/checksum/MavenProjectInput.java
@@ -526,6 +526,11 @@ public class MavenProjectInput
                     LOGGER.debug( "Skipping subtree (hidden): {}", path );
                     return FileVisitResult.SKIP_SUBTREE;
                 }
+                else if ( !isReadable( path ) )
+                {
+                    LOGGER.debug( "Skipping subtree (not readable): {}", path );
+                    return FileVisitResult.SKIP_SUBTREE;
+                }
                 else if ( isFilteredOutSubpath( path ) )
                 {
                     LOGGER.debug( "Skipping subtree (blacklisted): {}", path );
@@ -648,7 +653,7 @@ public class MavenProjectInput
                         continue;
                     }
                     File file = entry.toFile();
-                    if ( file.isFile() && !isHidden( entry ) )
+                    if ( file.isFile() && !isHidden( entry ) && isReadable( entry ) )
                     {
                         collectedFiles.add( entry );
                     }
@@ -666,6 +671,11 @@ public class MavenProjectInput
         return Files.isHidden( entry ) || entry.toFile().getName().startsWith( "." );
     }
 
+    private static boolean isReadable( Path entry ) throws IOException
+    {
+        return Files.isReadable( entry );
+    }
+
     private boolean isFilteredOutSubpath( Path path )
     {
         Path normalized = path.normalize();


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

Posted by gn...@apache.org.
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>