Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 50 additions & 29 deletions maven-core/src/main/java/org/apache/maven/ReactorReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,41 +178,49 @@ 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;
}
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 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;
}
}

Expand All @@ -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() )
Expand All @@ -263,15 +271,28 @@ 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 )
{
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;
}
}
Expand Down