[MNG-4660] Increase usefulness of logging

Closes #416
This commit is contained in:
Maarten Mulders 2020-12-23 19:27:11 +01:00
parent c79682bca9
commit 2caed6218a
1 changed files with 52 additions and 31 deletions

View File

@ -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,7 +186,16 @@ 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;
}
private File determineBuildOutputDirectoryForArtifact( final MavenProject project, final Artifact artifact )
{
if ( isTestArtifact( artifact ) )
{
if ( project.hasLifecyclePhase( "test-compile" ) )
@ -214,7 +223,6 @@ class ReactorReader
return outputDirectory;
}
}
}
// The fall-through indicates that the artifact cannot be found;
// for instance if package produced nothing or classifier problems.
@ -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;
}
}