From 0d53029a72b454c0b513ca5ff9392a3f78cd102b Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Wed, 23 Dec 2020 19:27:11 +0100 Subject: [PATCH 1/5] [MNG-4660] Increase usefulness of logging --- .../java/org/apache/maven/ReactorReader.java | 73 +++++++++++-------- 1 file changed, 44 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 7799667face0..97712bc7cb33 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 @@ private File find( MavenProject project, Artifact artifact ) } // 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 @@ else if ( !hasBeenPackagedDuringThisSession( project ) ) { // 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 determineLooseDirectoryForArtifact( 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 determineLooseDirectoryForArtifact( 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 @@ private boolean hasArtifactFileFromPackagePhase( Artifact projectArtifact ) 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() ) @@ -266,12 +274,19 @@ private boolean isPackagedArtifactUpToDate( MavenProject project, File packagedA 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 = determineLooseDirectoryForArtifact( project, artifact ); + if ( alternative != null ) + { + LOGGER.warn( "The file {} is more recent than the packaged artifact for {}; using {} instead", + relativizeOutputFile( outputFile ), project.getArtifactId(), + relativizeOutputFile( alternative.toPath() ) ); + } + else + { + LOGGER.warn( "The file {} is more recent than the packaged artifact for {}; " + + "cannot use a loose directory for this type of artifact", + relativizeOutputFile( outputFile ), project.getArtifactId() ); + } return false; } } From 2147b2acb452ca7e4ae203fe39e12cbdb062525e Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Wed, 23 Dec 2020 21:28:17 +0100 Subject: [PATCH 2/5] [MNG-4660] Not intereted in directories --- .../src/main/java/org/apache/maven/ReactorReader.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 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 97712bc7cb33..ab0be28d4e7f 100644 --- a/maven-core/src/main/java/org/apache/maven/ReactorReader.java +++ b/maven-core/src/main/java/org/apache/maven/ReactorReader.java @@ -271,19 +271,25 @@ private boolean isPackagedArtifactUpToDate( MavenProject project, File packagedA while ( iterator.hasNext() ) { Path outputFile = iterator.next(); + + if ( Files.isDirectory( outputFile ) ) + { + continue; + } + long outputFileLastModified = Files.getLastModifiedTime( outputFile ).toMillis(); if ( outputFileLastModified > artifactLastModified ) { File alternative = determineLooseDirectoryForArtifact( project, artifact ); if ( alternative != null ) { - LOGGER.warn( "The file {} is more recent than the packaged artifact for {}; using {} instead", + LOGGER.warn( "File {} is more recent than the packaged artifact for {}; using {} instead", relativizeOutputFile( outputFile ), project.getArtifactId(), relativizeOutputFile( alternative.toPath() ) ); } else { - LOGGER.warn( "The file {} is more recent than the packaged artifact for {}; " + LOGGER.warn( "File {} is more recent than the packaged artifact for {}; " + "cannot use a loose directory for this type of artifact", relativizeOutputFile( outputFile ), project.getArtifactId() ); } From 39548fdbd2eb05f99b270fee49ba7cd5a20562cf Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Thu, 24 Dec 2020 20:22:41 +0100 Subject: [PATCH 3/5] [MNG-4660] Logging args in single quotes --- maven-core/src/main/java/org/apache/maven/ReactorReader.java | 4 ++-- 1 file changed, 2 insertions(+), 2 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 ab0be28d4e7f..90e55285c73b 100644 --- a/maven-core/src/main/java/org/apache/maven/ReactorReader.java +++ b/maven-core/src/main/java/org/apache/maven/ReactorReader.java @@ -283,13 +283,13 @@ private boolean isPackagedArtifactUpToDate( MavenProject project, File packagedA File alternative = determineLooseDirectoryForArtifact( project, artifact ); if ( alternative != null ) { - LOGGER.warn( "File {} is more recent than the packaged artifact for {}; using {} instead", + 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 {}; " + LOGGER.warn( "File '{}' is more recent than the packaged artifact for '{}'; " + "cannot use a loose directory for this type of artifact", relativizeOutputFile( outputFile ), project.getArtifactId() ); } From bf2a29d908163be370d2d984914f07481d2f5028 Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Thu, 24 Dec 2020 20:25:47 +0100 Subject: [PATCH 4/5] [MNG-4660] Do not use term 'loose directory' --- maven-core/src/main/java/org/apache/maven/ReactorReader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 90e55285c73b..29badd95d912 100644 --- a/maven-core/src/main/java/org/apache/maven/ReactorReader.java +++ b/maven-core/src/main/java/org/apache/maven/ReactorReader.java @@ -290,7 +290,7 @@ private boolean isPackagedArtifactUpToDate( MavenProject project, File packagedA else { LOGGER.warn( "File '{}' is more recent than the packaged artifact for '{}'; " - + "cannot use a loose directory for this type of artifact", + + "cannot use the build output directory for this type of artifact", relativizeOutputFile( outputFile ), project.getArtifactId() ); } return false; From 898c38520ef390b463b92fda30ab6346842a93c5 Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Thu, 24 Dec 2020 20:32:46 +0100 Subject: [PATCH 5/5] [MNG-4660] Rename method --- .../src/main/java/org/apache/maven/ReactorReader.java | 6 +++--- 1 file changed, 3 insertions(+), 3 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 29badd95d912..42c41aca5883 100644 --- a/maven-core/src/main/java/org/apache/maven/ReactorReader.java +++ b/maven-core/src/main/java/org/apache/maven/ReactorReader.java @@ -186,7 +186,7 @@ else if ( !hasBeenPackagedDuringThisSession( project ) ) { // 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 determineLooseDirectoryForArtifact( project, artifact ); + return determineBuildOutputDirectoryForArtifact( project, artifact ); } // The fall-through indicates that the artifact cannot be found; @@ -194,7 +194,7 @@ else if ( !hasBeenPackagedDuringThisSession( project ) ) return null; } - private File determineLooseDirectoryForArtifact( final MavenProject project, final Artifact artifact ) + private File determineBuildOutputDirectoryForArtifact( final MavenProject project, final Artifact artifact ) { if ( isTestArtifact( artifact ) ) { @@ -280,7 +280,7 @@ private boolean isPackagedArtifactUpToDate( MavenProject project, File packagedA long outputFileLastModified = Files.getLastModifiedTime( outputFile ).toMillis(); if ( outputFileLastModified > artifactLastModified ) { - File alternative = determineLooseDirectoryForArtifact( project, artifact ); + File alternative = determineBuildOutputDirectoryForArtifact( project, artifact ); if ( alternative != null ) { LOGGER.warn( "File '{}' is more recent than the packaged artifact for '{}'; using '{}' instead",