Author: brianf Date: Wed Nov 14 02:49:02 2007 New Revision: 594831 URL: http://svn.apache.org/viewvc?rev=594831&view=rev Log: add banning of plugin snapshots
Modified: maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java Modified: maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java?rev=594831&r1=594830&r2=594831&view=diff ============================================================================== --- maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java (original) +++ maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java Wed Nov 14 02:49:02 2007 @@ -30,6 +30,7 @@ import java.util.Map; import java.util.Set; import java.util.Map.Entry; +import java.util.regex.Matcher; import org.apache.maven.BuildFailureException; import org.apache.maven.artifact.Artifact; @@ -89,17 +90,12 @@ public String message; /** - * The message to be printed in case the condition - * returns <b>true</b> - * - * @required - * @parameter + * Don't allow the LATEST identifier */ public boolean banLatest = true; /** - * The message to be printed in case the condition - * returns <b>true</b> + * Don't allow the RELEASE identifier * * @required * @parameter @@ -107,6 +103,11 @@ public boolean banRelease = true; /** + * Don't allow snapshot plugins. + */ + public boolean banSnapshots = true; + + /** * The comma separated list of phases that should be * used to find lifecycle plugin bindings. The default * value is "clean,deploy,site". @@ -114,15 +115,16 @@ * @parameter */ public String phases = "clean,deploy,site"; - + /** - * Additional plugins to enforce have versions. These are plugins that may not be - * in the poms but are used anyway, like help, eclipse etc. - * <br> - * The plugins should be specified in the form: group:artifactId. + * Additional plugins to enforce have versions. These + * are plugins that may not be in the poms but are used + * anyway, like help, eclipse etc. <br> + * The plugins should be specified in the form: + * group:artifactId. */ public List additionalPlugins; - + private PluginManager pluginManager; private Map phaseToLifecycleMap; @@ -169,9 +171,10 @@ // specified lifecycles Set allPlugins = getBoundPlugins( life, project, phases ); - //insert any additional Plugins specified by the user. + // insert any additional Plugins specified by + // the user. allPlugins = addAdditionalPlugins( allPlugins ); - + // there's nothing to do here if ( allPlugins.isEmpty() ) { @@ -214,7 +217,7 @@ newMsg.append( plugin.getGroupId() ); newMsg.append( ":" ); newMsg.append( plugin.getArtifactId() ); - + try { newMsg.append( ". \tThe version currently in use is " ); @@ -232,9 +235,11 @@ } catch ( Exception e ) { - //lots can go wrong here. Don't allow any issues trying to determine the issue - //stop me - log.debug( "Exception while determining plugin Version.",e ); + // lots can go wrong here. Don't + // allow any issues trying to + // determine the issue + // stop me + log.debug( "Exception while determining plugin Version.", e ); newMsg.append( ". Unable to determine the plugin version." ); } newMsg.append( "\n" ); @@ -291,39 +296,42 @@ /** * Add the additional plugins if they don't exist yet - * @throws MojoExecutionException + * + * @throws MojoExecutionException */ - public Set addAdditionalPlugins(Set existing) throws MojoExecutionException + public Set addAdditionalPlugins ( Set existing ) + throws MojoExecutionException { - if (additionalPlugins != null) + if ( additionalPlugins != null ) { Iterator iter = additionalPlugins.iterator(); - while(iter.hasNext()) + while ( iter.hasNext() ) { - String pluginString = (String)iter.next(); + String pluginString = (String) iter.next(); String[] pluginStrings = pluginString.split( ":" ); - if (pluginStrings.length == 2) + if ( pluginStrings.length == 2 ) { Plugin plugin = new Plugin(); plugin.setGroupId( pluginStrings[0] ); plugin.setArtifactId( pluginStrings[1] ); - - //only add this if it's not already there. - if (!existing.contains( plugin )) + + // only add this if it's not already + // there. + if ( !existing.contains( plugin ) ) { existing.add( plugin ); - } + } } else { - throw new MojoExecutionException("Invalid AdditionalPlugin string: "+ pluginString); + throw new MojoExecutionException( "Invalid AdditionalPlugin string: " + pluginString ); } } - + } return existing; } - + /** * Given a plugin, this will retrieve the matching * plugin artifact from the model. @@ -448,12 +456,17 @@ { return false; } + + if ( banSnapshots && isSnapshot( plugin.getVersion() ) ) + { + return false; + } // the version was specified and not // banned. It's ok. status = true; - if ( !banRelease && !banLatest ) + if ( !banRelease && !banLatest && !banSnapshots ) { // no need to keep looking break; @@ -462,6 +475,11 @@ } } return status; + } + + protected boolean isSnapshot ( String baseVersion ) + { + return Artifact.VERSION_FILE_PATTERN.matcher( baseVersion ).matches(); } /*