1 package org.apache.maven.plugin.descriptor; 2 3 18 19 import org.apache.maven.plugin.Mojo; 20 import org.codehaus.plexus.component.repository.ComponentDescriptor; 21 import org.codehaus.plexus.configuration.PlexusConfiguration; 22 import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; 23 24 import java.util.HashMap ; 25 import java.util.Iterator ; 26 import java.util.LinkedList ; 27 import java.util.List ; 28 import java.util.Map ; 29 30 35 public class MojoDescriptor 36 extends ComponentDescriptor 37 implements Cloneable 38 { 39 public static String MAVEN_PLUGIN = "maven-plugin"; 40 41 public static final String SINGLE_PASS_EXEC_STRATEGY = "once-per-session"; 42 43 public static final String MULTI_PASS_EXEC_STRATEGY = "always"; 44 45 private static final String DEFAULT_INSTANTIATION_STRATEGY = "per-lookup"; 46 47 private static final String DEFAULT_LANGUAGE = "java"; 48 49 private List parameters; 50 51 private Map parameterMap; 52 53 private String executionStrategy = SINGLE_PASS_EXEC_STRATEGY; 54 55 private String goal; 56 57 private String phase; 58 59 private String executePhase; 60 61 private String executeGoal; 62 63 private String executeLifecycle; 64 65 private String deprecated; 66 67 private boolean aggregator = false; 68 69 73 private String dependencyResolutionRequired = null; 74 75 private boolean projectRequired = true; 76 77 private boolean onlineRequired = false; 78 79 private PlexusConfiguration mojoConfiguration; 80 81 private PluginDescriptor pluginDescriptor; 82 83 private boolean inheritedByDefault = true; 84 85 private boolean directInvocationOnly = false; 86 87 private boolean requiresReports = false; 88 89 public MojoDescriptor() 90 { 91 setInstantiationStrategy( DEFAULT_INSTANTIATION_STRATEGY ); 92 setComponentFactory( DEFAULT_LANGUAGE ); 93 } 94 95 99 public String getLanguage() 100 { 101 return getComponentFactory(); 102 } 103 104 public void setLanguage( String language ) 105 { 106 setComponentFactory( language ); 107 } 108 109 public String getDeprecated() 110 { 111 return deprecated; 112 } 113 114 public void setDeprecated( String deprecated ) 115 { 116 this.deprecated = deprecated; 117 } 118 119 public List getParameters() 120 { 121 return parameters; 122 } 123 124 public void setParameters( List parameters ) 125 throws DuplicateParameterException 126 { 127 for ( Iterator it = parameters.iterator(); it.hasNext(); ) 128 { 129 Parameter parameter = (Parameter) it.next(); 130 addParameter( parameter ); 131 } 132 } 133 134 public void addParameter( Parameter parameter ) 135 throws DuplicateParameterException 136 { 137 if ( parameters != null && parameters.contains( parameter ) ) 138 { 139 throw new DuplicateParameterException( parameter.getName() + 140 " has been declared multiple times in mojo with goal: " + getGoal() + " (implementation: " + 141 getImplementation() + ")" ); 142 } 143 else 144 { 145 if ( parameters == null ) 146 { 147 parameters = new LinkedList (); 148 } 149 150 parameters.add( parameter ); 151 } 152 } 153 154 public Map getParameterMap() 155 { 156 if ( parameterMap == null ) 157 { 158 parameterMap = new HashMap (); 159 160 if ( parameters != null ) 161 { 162 for ( Iterator iterator = parameters.iterator(); iterator.hasNext(); ) 163 { 164 Parameter pd = (Parameter) iterator.next(); 165 166 parameterMap.put( pd.getName(), pd ); 167 } 168 } 169 } 170 171 return parameterMap; 172 } 173 174 178 public void setDependencyResolutionRequired( String requiresDependencyResolution ) 179 { 180 this.dependencyResolutionRequired = requiresDependencyResolution; 181 } 182 183 public String isDependencyResolutionRequired() 184 { 185 return dependencyResolutionRequired; 186 } 187 188 192 public void setProjectRequired( boolean requiresProject ) 193 { 194 this.projectRequired = requiresProject; 195 } 196 197 public boolean isProjectRequired() 198 { 199 return projectRequired; 200 } 201 202 206 public void setOnlineRequired( boolean requiresOnline ) 207 { 208 this.onlineRequired = requiresOnline; 209 } 210 211 public boolean isOnlineRequired() 214 { 215 return onlineRequired; 216 } 217 218 public boolean requiresOnline() 220 { 221 return onlineRequired; 222 } 223 224 public String getPhase() 225 { 226 return phase; 227 } 228 229 public void setPhase( String phase ) 230 { 231 this.phase = phase; 232 } 233 234 public String getGoal() 235 { 236 return goal; 237 } 238 239 public void setGoal( String goal ) 240 { 241 this.goal = goal; 242 } 243 244 public String getExecutePhase() 245 { 246 return executePhase; 247 } 248 249 public void setExecutePhase( String executePhase ) 250 { 251 this.executePhase = executePhase; 252 } 253 254 public boolean alwaysExecute() 255 { 256 return MULTI_PASS_EXEC_STRATEGY.equals( executionStrategy ); 257 } 258 259 public String getExecutionStrategy() 260 { 261 return executionStrategy; 262 } 263 264 public void setExecutionStrategy( String executionStrategy ) 265 { 266 this.executionStrategy = executionStrategy; 267 } 268 269 public PlexusConfiguration getMojoConfiguration() 270 { 271 if ( mojoConfiguration == null ) 272 { 273 mojoConfiguration = new XmlPlexusConfiguration( "configuration" ); 274 } 275 return mojoConfiguration; 276 } 277 278 public void setMojoConfiguration( PlexusConfiguration mojoConfiguration ) 279 { 280 this.mojoConfiguration = mojoConfiguration; 281 } 282 283 public String getRole() 284 { 285 return Mojo.ROLE; 286 } 287 288 public String getRoleHint() 289 { 290 return getId(); 291 } 292 293 public String getId() 294 { 295 return getPluginDescriptor().getId() + ":" + getGoal(); 296 } 297 298 public String getFullGoalName() 299 { 300 return getPluginDescriptor().getGoalPrefix() + ":" + getGoal(); 301 } 302 303 public String getComponentType() 304 { 305 return MAVEN_PLUGIN; 306 } 307 308 public PluginDescriptor getPluginDescriptor() 309 { 310 return pluginDescriptor; 311 } 312 313 public void setPluginDescriptor( PluginDescriptor pluginDescriptor ) 314 { 315 this.pluginDescriptor = pluginDescriptor; 316 } 317 318 public boolean isInheritedByDefault() 319 { 320 return inheritedByDefault; 321 } 322 323 public void setInheritedByDefault( boolean inheritedByDefault ) 324 { 325 this.inheritedByDefault = inheritedByDefault; 326 } 327 328 public boolean equals( Object object ) 329 { 330 if ( this == object ) 331 { 332 return true; 333 } 334 335 if ( object instanceof MojoDescriptor ) 336 { 337 MojoDescriptor other = (MojoDescriptor) object; 338 339 if ( !compareObjects( getPluginDescriptor(), other.getPluginDescriptor() ) ) 340 { 341 return false; 342 } 343 344 if ( !compareObjects( getGoal(), other.getGoal() ) ) 345 { 346 return false; 347 } 348 349 return true; 350 } 351 352 return false; 353 } 354 355 private boolean compareObjects( Object first, Object second ) 356 { 357 if ( ( first == null && second != null ) || ( first != null && second == null ) ) 358 { 359 return false; 360 } 361 362 if ( !first.equals( second ) ) 363 { 364 return false; 365 } 366 367 return true; 368 } 369 370 public int hashCode() 371 { 372 int result = 1; 373 374 String goal = getGoal(); 375 376 if ( goal != null ) 377 { 378 result += goal.hashCode(); 379 } 380 381 PluginDescriptor pd = getPluginDescriptor(); 382 383 if ( pd != null ) 384 { 385 result -= pd.hashCode(); 386 } 387 388 return result; 389 } 390 391 public String getExecuteLifecycle() 392 { 393 return executeLifecycle; 394 } 395 396 public void setExecuteLifecycle( String executeLifecycle ) 397 { 398 this.executeLifecycle = executeLifecycle; 399 } 400 401 public void setAggregator( boolean aggregator ) 402 { 403 this.aggregator = aggregator; 404 } 405 406 public boolean isAggregator() 407 { 408 return aggregator; 409 } 410 411 public boolean isDirectInvocationOnly() 412 { 413 return directInvocationOnly; 414 } 415 416 public void setDirectInvocationOnly( boolean directInvocationOnly ) 417 { 418 this.directInvocationOnly = directInvocationOnly; 419 } 420 421 public boolean isRequiresReports() 422 { 423 return requiresReports; 424 } 425 426 public void setRequiresReports( boolean requiresReports ) 427 { 428 this.requiresReports = requiresReports; 429 } 430 431 public void setExecuteGoal( String executeGoal ) 432 { 433 this.executeGoal = executeGoal; 434 } 435 436 public String getExecuteGoal() 437 { 438 return executeGoal; 439 } 440 } 441 | Popular Tags |