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

mthmulders pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git


The following commit(s) were added to refs/heads/master by this push:
     new 2caed62  [MNG-4660] Increase usefulness of logging
2caed62 is described below

commit 2caed6218a5ec0a0b7fce2975743331e5ec76c89
Author: Maarten Mulders <mthmuld...@apache.org>
AuthorDate: Wed Dec 23 19:27:11 2020 +0100

    [MNG-4660] Increase usefulness of logging
    
    Closes #416
---
 .../main/java/org/apache/maven/ReactorReader.java  | 79 ++++++++++++++--------
 1 file changed, 50 insertions(+), 29 deletions(-)

diff --git a/maven-core/src/main/java/org/apache/maven/ReactorReader.java 
b/maven-core/src/main/java/org/apache/maven/ReactorReader.java
index 7799667..42c41ac 100644
--- a/maven-core/src/main/java/org/apache/maven/ReactorReader.java
+++ b/maven-core/src/main/java/org/apache/maven/ReactorReader.java
@@ -178,7 +178,7 @@ class ReactorReader
         }
         // Check whether an earlier Maven run might have produced an artifact 
that is still on disk.
         else if ( packagedArtifactFile != null && packagedArtifactFile.exists()
-                && isPackagedArtifactUpToDate( project, packagedArtifactFile ) 
)
+                && isPackagedArtifactUpToDate( project, packagedArtifactFile, 
artifact ) )
         {
             return packagedArtifactFile;
         }
@@ -186,33 +186,41 @@ class ReactorReader
         {
             // fallback to loose class files only if artifacts haven't been 
packaged yet
             // and only for plain old jars. Not war files, not ear files, not 
anything else.
+            return determineBuildOutputDirectoryForArtifact( project, artifact 
);
+        }
+
+        // The fall-through indicates that the artifact cannot be found;
+        // for instance if package produced nothing or classifier problems.
+        return null;
+    }
 
-            if ( isTestArtifact( artifact ) )
+    private File determineBuildOutputDirectoryForArtifact( final MavenProject 
project, final Artifact artifact )
+    {
+        if ( isTestArtifact( artifact ) )
+        {
+            if ( project.hasLifecyclePhase( "test-compile" ) )
             {
-                if ( project.hasLifecyclePhase( "test-compile" ) )
-                {
-                    return new File( 
project.getBuild().getTestOutputDirectory() );
-                }
+                return new File( project.getBuild().getTestOutputDirectory() );
             }
-            else
-            {
-                String type = artifact.getProperty( "type", "" );
-                File outputDirectory = new File( 
project.getBuild().getOutputDirectory() );
+        }
+        else
+        {
+            String type = artifact.getProperty( "type", "" );
+            File outputDirectory = new File( 
project.getBuild().getOutputDirectory() );
 
-                // Check if the project is being built during this session, 
and if we can expect any output.
-                // There is no need to check if the build has created any 
outputs, see MNG-2222.
-                boolean projectCompiledDuringThisSession
-                        = project.hasLifecyclePhase( "compile" ) && 
COMPILE_PHASE_TYPES.contains( type );
+            // Check if the project is being built during this session, and if 
we can expect any output.
+            // There is no need to check if the build has created any outputs, 
see MNG-2222.
+            boolean projectCompiledDuringThisSession
+                    = project.hasLifecyclePhase( "compile" ) && 
COMPILE_PHASE_TYPES.contains( type );
 
-                // Check if the project is part of the session (not filtered 
by -pl, -rf, etc). If so, we check
-                // if a possible earlier Maven invocation produced some output 
for that project which we can use.
-                boolean projectHasOutputFromPreviousSession
-                        = !session.getProjects().contains( project ) && 
outputDirectory.exists();
+            // Check if the project is part of the session (not filtered by 
-pl, -rf, etc). If so, we check
+            // if a possible earlier Maven invocation produced some output for 
that project which we can use.
+            boolean projectHasOutputFromPreviousSession
+                    = !session.getProjects().contains( project ) && 
outputDirectory.exists();
 
-                if ( projectHasOutputFromPreviousSession || 
projectCompiledDuringThisSession )
-                {
-                    return outputDirectory;
-                }
+            if ( projectHasOutputFromPreviousSession || 
projectCompiledDuringThisSession )
+            {
+                return outputDirectory;
             }
         }
 
@@ -237,7 +245,7 @@ class ReactorReader
         return projectArtifact != null && projectArtifact.getFile() != null && 
projectArtifact.getFile().exists();
     }
 
-    private boolean isPackagedArtifactUpToDate( MavenProject project, File 
packagedArtifactFile )
+    private boolean isPackagedArtifactUpToDate( MavenProject project, File 
packagedArtifactFile, Artifact artifact )
     {
         Path outputDirectory = Paths.get( 
project.getBuild().getOutputDirectory() );
         if ( !outputDirectory.toFile().exists() )
@@ -263,15 +271,28 @@ class ReactorReader
             while ( iterator.hasNext() )
             {
                 Path outputFile = iterator.next();
+
+                if ( Files.isDirectory(  outputFile ) )
+                {
+                    continue;
+                }
+
                 long outputFileLastModified = Files.getLastModifiedTime( 
outputFile ).toMillis();
                 if ( outputFileLastModified > artifactLastModified )
                 {
-                    LOGGER.warn(
-                            "Packaged artifact for {} is not up-to-date 
compared to the build output directory; "
-                          + "file {} is more recent than {}.",
-                            project.getArtifactId(),
-                            relativizeOutputFile( outputFile ), 
relativizeOutputFile( packagedArtifactFile.toPath() )
-                    );
+                    File alternative = 
determineBuildOutputDirectoryForArtifact( project, artifact );
+                    if ( alternative != null )
+                    {
+                        LOGGER.warn( "File '{}' is more recent than the 
packaged artifact for '{}'; using '{}' instead",
+                                relativizeOutputFile( outputFile ), 
project.getArtifactId(),
+                                relativizeOutputFile( alternative.toPath() ) );
+                    }
+                    else
+                    {
+                        LOGGER.warn( "File '{}' is more recent than the 
packaged artifact for '{}'; "
+                                + "cannot use the build output directory for 
this type of artifact",
+                                relativizeOutputFile( outputFile ), 
project.getArtifactId() );
+                    }
                     return false;
                 }
             }

Reply via email to