| 1 | |
package org.apache.maven.plugins.enforcer; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
import org.apache.maven.artifact.Artifact; |
| 23 | |
import org.apache.maven.enforcer.rule.api.EnforcerRuleException; |
| 24 | |
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; |
| 25 | |
import org.apache.maven.project.MavenProject; |
| 26 | |
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; |
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | 2 | public class RequireReleaseVersion |
| 34 | |
extends AbstractNonCacheableEnforcerRule |
| 35 | |
{ |
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | 2 | public boolean failWhenParentIsSnapshot = true; |
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
public void execute( EnforcerRuleHelper theHelper ) |
| 50 | |
throws EnforcerRuleException |
| 51 | |
{ |
| 52 | |
|
| 53 | 4 | MavenProject project = getProject( theHelper ); |
| 54 | |
|
| 55 | 4 | if ( project.getArtifact().isSnapshot() ) |
| 56 | |
{ |
| 57 | 1 | StringBuffer buf = new StringBuffer(); |
| 58 | 1 | if ( message != null ) |
| 59 | |
{ |
| 60 | 0 | buf.append( message + "\n" ); |
| 61 | |
} |
| 62 | 1 | buf.append( "This project cannot be a snapshot:" + project.getArtifact().getId() ); |
| 63 | 1 | throw new EnforcerRuleException( buf.toString() ); |
| 64 | |
} |
| 65 | 3 | if ( failWhenParentIsSnapshot ) |
| 66 | |
{ |
| 67 | 2 | Artifact parentArtifact = project.getParentArtifact(); |
| 68 | 2 | if ( parentArtifact != null && parentArtifact.isSnapshot() ) |
| 69 | |
{ |
| 70 | 1 | throw new EnforcerRuleException( "Parent Cannot be a snapshot: " + parentArtifact.getId() ); |
| 71 | |
} |
| 72 | |
} |
| 73 | |
|
| 74 | 2 | } |
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
private MavenProject getProject( EnforcerRuleHelper helper ) |
| 82 | |
throws EnforcerRuleException |
| 83 | |
{ |
| 84 | |
try |
| 85 | |
{ |
| 86 | 4 | return (MavenProject) helper.evaluate( "${project}" ); |
| 87 | |
} |
| 88 | 0 | catch ( ExpressionEvaluationException eee ) |
| 89 | |
{ |
| 90 | 0 | throw new EnforcerRuleException( "Unable to retrieve the MavenProject: ", eee ); |
| 91 | |
} |
| 92 | |
} |
| 93 | |
|
| 94 | |
public boolean isFailWhenParentIsSnapshot() |
| 95 | |
{ |
| 96 | 0 | return failWhenParentIsSnapshot; |
| 97 | |
} |
| 98 | |
|
| 99 | |
public void setFailWhenParentIsSnapshot( boolean failWhenParentIsSnapshot ) |
| 100 | |
{ |
| 101 | 2 | this.failWhenParentIsSnapshot = failWhenParentIsSnapshot; |
| 102 | 2 | } |
| 103 | |
} |