Skip to content
Closed
Show file tree
Hide file tree
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
41 changes: 22 additions & 19 deletions src/main/java/org/apache/maven/plugins/install/InstallMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@
*/

import java.io.IOException;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;

import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecutionException;
Expand All @@ -50,9 +47,7 @@
public class InstallMojo
extends AbstractInstallMojo
{
private static final String INSTALL_REQUESTS_KEY = InstallMojo.class.getName() + ".installRequests";

private static final MavenProject SENTINEL = new MavenProject();
private static final String INSTALL_PROCESSED_MARKER = InstallMojo.class.getName() + ".processed";

@Parameter( defaultValue = "${project}", readonly = true, required = true )
private MavenProject project;
Expand Down Expand Up @@ -93,17 +88,10 @@ public void execute()
{

final String projectKey = project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion();
final ConcurrentMap<String, Object> pluginContext =
(ConcurrentMap<String, Object>) session.getPluginContext( pluginDescriptor, reactorProjects.get( 0 ) );
final Map<String, MavenProject> installRequests = (Map<String, MavenProject>) pluginContext.computeIfAbsent(
INSTALL_REQUESTS_KEY,
k -> Collections.synchronizedMap( new LinkedHashMap<String, MavenProject>() )
);

boolean addedInstallRequest = false;
if ( skip )
{
installRequests.put( projectKey, SENTINEL );
getPluginContext().put( INSTALL_PROCESSED_MARKER, Boolean.FALSE );
getLog().info( "Skipping artifact installation" );
}
else
Expand All @@ -114,22 +102,24 @@ public void execute()
}
else
{
installRequests.put( projectKey, project );
getPluginContext().put( INSTALL_PROCESSED_MARKER, Boolean.TRUE );
addedInstallRequest = true;
}
}

if ( installRequests.size() == reactorProjects.size() )
if ( allProjectsMarked() )
{
for ( Map.Entry<String, MavenProject> projectEntry : installRequests.entrySet() )
for ( MavenProject reactorProject : reactorProjects )
{
if ( projectEntry.getValue() == SENTINEL )
Map<String, Object> pluginContext = session.getPluginContext( pluginDescriptor, reactorProject );
Boolean install = (Boolean) pluginContext.get( INSTALL_PROCESSED_MARKER );
if ( !install )
{
getLog().info( "Project " + projectKey + " skipped install" );
}
else
{
installProject( projectEntry.getValue() );
installProject( reactorProject );
}
}
}
Expand All @@ -139,6 +129,19 @@ else if ( addedInstallRequest )
}
}

private boolean allProjectsMarked()
{
for ( MavenProject reactorProject : reactorProjects )
{
Map<String, Object> pluginContext = session.getPluginContext( pluginDescriptor, reactorProject );
if ( !pluginContext.containsKey( INSTALL_PROCESSED_MARKER ) )
{
return false;
}
}
return true;
}

private void installProject( MavenProject pir )
throws MojoFailureException, MojoExecutionException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ public void testSkip()
MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
updateMavenProject( project );

setVariableValueToObject( mojo, "pluginContext", new ConcurrentHashMap<>() );
setVariableValueToObject( mojo, "pluginDescriptor", new PluginDescriptor() );
setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
setVariableValueToObject( mojo, "session", createMavenSession() );
Expand Down