| 1 | |
package org.apache.maven.execution; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
import org.apache.maven.artifact.ArtifactUtils; |
| 24 | |
import org.apache.maven.plugin.descriptor.PluginDescriptor; |
| 25 | |
import org.apache.maven.project.DuplicateProjectException; |
| 26 | |
import org.apache.maven.project.MavenProject; |
| 27 | |
import org.apache.maven.project.ProjectSorter; |
| 28 | |
import org.codehaus.plexus.util.dag.CycleDetectedException; |
| 29 | |
|
| 30 | |
import java.util.ArrayList; |
| 31 | |
import java.util.HashMap; |
| 32 | |
import java.util.Iterator; |
| 33 | |
import java.util.List; |
| 34 | |
import java.util.Map; |
| 35 | |
|
| 36 | |
public class ReactorManager |
| 37 | |
{ |
| 38 | |
public static final String FAIL_FAST = "fail-fast"; |
| 39 | |
|
| 40 | |
public static final String FAIL_AT_END = "fail-at-end"; |
| 41 | |
|
| 42 | |
public static final String FAIL_NEVER = "fail-never"; |
| 43 | |
|
| 44 | 0 | private List blackList = new ArrayList(); |
| 45 | |
|
| 46 | 0 | private Map buildFailuresByProject = new HashMap(); |
| 47 | |
|
| 48 | 0 | private Map pluginContextsByProjectAndPluginKey = new HashMap(); |
| 49 | |
|
| 50 | 0 | private String failureBehavior = FAIL_FAST; |
| 51 | |
|
| 52 | |
private final ProjectSorter sorter; |
| 53 | |
|
| 54 | 0 | private Map buildSuccessesByProject = new HashMap(); |
| 55 | |
|
| 56 | |
public ReactorManager( List projects ) |
| 57 | |
throws CycleDetectedException, DuplicateProjectException |
| 58 | 0 | { |
| 59 | 0 | this.sorter = new ProjectSorter( projects ); |
| 60 | 0 | } |
| 61 | |
|
| 62 | |
public Map getPluginContext( PluginDescriptor plugin, MavenProject project ) |
| 63 | |
{ |
| 64 | 0 | Map pluginContextsByKey = (Map) pluginContextsByProjectAndPluginKey.get( project.getId() ); |
| 65 | |
|
| 66 | 0 | if ( pluginContextsByKey == null ) |
| 67 | |
{ |
| 68 | 0 | pluginContextsByKey = new HashMap(); |
| 69 | 0 | pluginContextsByProjectAndPluginKey.put( project.getId(), pluginContextsByKey ); |
| 70 | |
} |
| 71 | |
|
| 72 | 0 | Map pluginContext = (Map) pluginContextsByKey.get( plugin.getPluginLookupKey() ); |
| 73 | |
|
| 74 | 0 | if ( pluginContext == null ) |
| 75 | |
{ |
| 76 | 0 | pluginContext = new HashMap(); |
| 77 | 0 | pluginContextsByKey.put( plugin.getPluginLookupKey(), pluginContext ); |
| 78 | |
} |
| 79 | |
|
| 80 | 0 | return pluginContext; |
| 81 | |
} |
| 82 | |
|
| 83 | |
public void setFailureBehavior( String failureBehavior ) |
| 84 | |
{ |
| 85 | 0 | if ( FAIL_FAST.equals( failureBehavior ) || FAIL_AT_END.equals( failureBehavior ) || |
| 86 | |
FAIL_NEVER.equals( failureBehavior ) ) |
| 87 | |
{ |
| 88 | 0 | this.failureBehavior = failureBehavior; |
| 89 | |
} |
| 90 | |
else |
| 91 | |
{ |
| 92 | 0 | throw new IllegalArgumentException( "Invalid failure behavior (must be one of: \'" + FAIL_FAST + "\', \'" + |
| 93 | |
FAIL_AT_END + "\', \'" + FAIL_NEVER + "\')." ); |
| 94 | |
} |
| 95 | 0 | } |
| 96 | |
|
| 97 | |
public String getFailureBehavior() |
| 98 | |
{ |
| 99 | 0 | return failureBehavior; |
| 100 | |
} |
| 101 | |
|
| 102 | |
public void blackList( MavenProject project ) |
| 103 | |
{ |
| 104 | 0 | blackList( getProjectKey( project ) ); |
| 105 | 0 | } |
| 106 | |
|
| 107 | |
private void blackList( String id ) |
| 108 | |
{ |
| 109 | 0 | if ( !blackList.contains( id ) ) |
| 110 | |
{ |
| 111 | 0 | blackList.add( id ); |
| 112 | |
|
| 113 | 0 | List dependents = sorter.getDependents( id ); |
| 114 | |
|
| 115 | 0 | if ( dependents != null && !dependents.isEmpty() ) |
| 116 | |
{ |
| 117 | 0 | for ( Iterator it = dependents.iterator(); it.hasNext(); ) |
| 118 | |
{ |
| 119 | 0 | String dependentId = (String) it.next(); |
| 120 | |
|
| 121 | 0 | if ( !buildSuccessesByProject.containsKey( dependentId ) && |
| 122 | |
!buildFailuresByProject.containsKey( dependentId ) ) |
| 123 | |
{ |
| 124 | 0 | blackList( dependentId ); |
| 125 | |
} |
| 126 | 0 | } |
| 127 | |
} |
| 128 | |
} |
| 129 | 0 | } |
| 130 | |
|
| 131 | |
public boolean isBlackListed( MavenProject project ) |
| 132 | |
{ |
| 133 | 0 | return blackList.contains( getProjectKey( project ) ); |
| 134 | |
} |
| 135 | |
|
| 136 | |
private static String getProjectKey( MavenProject project ) |
| 137 | |
{ |
| 138 | 0 | return ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() ); |
| 139 | |
} |
| 140 | |
|
| 141 | |
public void registerBuildFailure( MavenProject project, Exception error, String task, long time ) |
| 142 | |
{ |
| 143 | 0 | buildFailuresByProject.put( getProjectKey( project ), new BuildFailure( error, task, time ) ); |
| 144 | 0 | } |
| 145 | |
|
| 146 | |
public boolean hasBuildFailures() |
| 147 | |
{ |
| 148 | 0 | return !buildFailuresByProject.isEmpty(); |
| 149 | |
} |
| 150 | |
|
| 151 | |
public boolean hasBuildFailure( MavenProject project ) |
| 152 | |
{ |
| 153 | 0 | return buildFailuresByProject.containsKey( getProjectKey( project ) ); |
| 154 | |
} |
| 155 | |
|
| 156 | |
public boolean hasMultipleProjects() |
| 157 | |
{ |
| 158 | 0 | return sorter.hasMultipleProjects(); |
| 159 | |
} |
| 160 | |
|
| 161 | |
public List getSortedProjects() |
| 162 | |
{ |
| 163 | 0 | return sorter.getSortedProjects(); |
| 164 | |
} |
| 165 | |
|
| 166 | |
public MavenProject getTopLevelProject() |
| 167 | |
{ |
| 168 | 0 | return sorter.getTopLevelProject(); |
| 169 | |
} |
| 170 | |
|
| 171 | |
public boolean hasBuildSuccess( MavenProject project ) |
| 172 | |
{ |
| 173 | 0 | return buildSuccessesByProject.containsKey( getProjectKey( project ) ); |
| 174 | |
} |
| 175 | |
|
| 176 | |
public void registerBuildSuccess( MavenProject project, long time ) |
| 177 | |
{ |
| 178 | 0 | buildSuccessesByProject.put( getProjectKey( project ), new BuildSuccess( project, time ) ); |
| 179 | 0 | } |
| 180 | |
|
| 181 | |
public BuildFailure getBuildFailure( MavenProject project ) |
| 182 | |
{ |
| 183 | 0 | return (BuildFailure) buildFailuresByProject.get( getProjectKey( project ) ); |
| 184 | |
} |
| 185 | |
|
| 186 | |
public BuildSuccess getBuildSuccess( MavenProject project ) |
| 187 | |
{ |
| 188 | 0 | return (BuildSuccess) buildSuccessesByProject.get( getProjectKey( project ) ); |
| 189 | |
} |
| 190 | |
|
| 191 | |
public boolean executedMultipleProjects() |
| 192 | |
{ |
| 193 | 0 | return buildFailuresByProject.size() + buildSuccessesByProject.size() > 1; |
| 194 | |
} |
| 195 | |
} |