pax_global_header00006660000000000000000000000064120571126340014513gustar00rootroot0000000000000052 comment=e1ae3c8c691e8dfddf4458fd5d5dbd8f352420be maven-enforcer-1.0.1/000077500000000000000000000000001205711263400144215ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-api/000077500000000000000000000000001205711263400167735ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-api/pom.xml000066400000000000000000000061621205711263400203150ustar00rootroot00000000000000 4.0.0 org.apache.maven.enforcer enforcer 1.0.1 enforcer-api 1.0.1 jar Enforcer API This component provides the generic interfaces needed to implement custom rules for the maven-enforcer-plugin. org.apache.maven maven-plugin-api org.codehaus.plexus plexus-container-default 1.0-alpha-9 maven-compiler-plugin 1.4 1.4 org.codehaus.plexus plexus-maven-plugin descriptor org.apache.maven.plugins maven-assembly-plugin 2.2-beta-2 custom-rule pre-site single custom-rule target/site src/main/assembly/custom-rule-sample.xml false maven-enforcer-1.0.1/enforcer-api/src/000077500000000000000000000000001205711263400175625ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-api/src/custom-rule-sample/000077500000000000000000000000001205711263400233205ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-api/src/custom-rule-sample/pom.xml000066400000000000000000000033031205711263400246340ustar00rootroot00000000000000 4.0.0 custom-rule custom-rule-sample jar 1.0 My Custom Rule This is my custom rule. 1.0-beta-1 2.0.9 org.apache.maven.enforcer enforcer-api ${api.version} org.apache.maven maven-project ${maven.version} org.apache.maven maven-core ${maven.version} org.apache.maven maven-artifact ${maven.version} org.apache.maven maven-plugin-api ${maven.version} org.codehaus.plexus plexus-container-default 1.0-alpha-9 junit junit 3.8.1 test maven-enforcer-1.0.1/enforcer-api/src/custom-rule-sample/src/000077500000000000000000000000001205711263400241075ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-api/src/custom-rule-sample/src/main/000077500000000000000000000000001205711263400250335ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-api/src/custom-rule-sample/src/main/java/000077500000000000000000000000001205711263400257545ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-api/src/custom-rule-sample/src/main/java/org/000077500000000000000000000000001205711263400265435ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-api/src/custom-rule-sample/src/main/java/org/apache/000077500000000000000000000000001205711263400277645ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-api/src/custom-rule-sample/src/main/java/org/apache/maven/000077500000000000000000000000001205711263400310725ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-api/src/custom-rule-sample/src/main/java/org/apache/maven/enforcer/000077500000000000000000000000001205711263400326755ustar00rootroot00000000000000rule/000077500000000000000000000000001205711263400335655ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-api/src/custom-rule-sample/src/main/java/org/apache/maven/enforcerMyCustomRule.java000066400000000000000000000100331205711263400370350ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-api/src/custom-rule-sample/src/main/java/org/apache/maven/enforcer/rulepackage org.apache.maven.enforcer.rule; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.enforcer.rule.api.EnforcerRule; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.RuntimeInformation; import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; /** * @author Brian Fox */ public class MyCustomRule implements EnforcerRule { /** * Simple param. This rule will fail if the value is true. */ private boolean shouldIfail = false; public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException { Log log = helper.getLog(); try { // get the various expressions out of the helper. MavenProject project = (MavenProject) helper.evaluate( "${project}" ); MavenSession session = (MavenSession) helper.evaluate( "${session}" ); String target = (String) helper.evaluate( "${project.build.directory}" ); String artifactId = (String) helper.evaluate( "${project.artifactId}" ); // retreive any component out of the session directly ArtifactResolver resolver = (ArtifactResolver) helper.getComponent( ArtifactResolver.class ); RuntimeInformation rti = (RuntimeInformation) helper.getComponent( RuntimeInformation.class ); log.info( "Retrieved Target Folder: " + target ); log.info( "Retrieved ArtifactId: " +artifactId ); log.info( "Retrieved Project: " + project ); log.info( "Retrieved RuntimeInfo: " + rti ); log.info( "Retrieved Session: " + session ); log.info( "Retrieved Resolver: " + resolver ); if ( this.shouldIfail ) { throw new EnforcerRuleException( "Failing because my param said so." ); } } catch ( ComponentLookupException e ) { throw new EnforcerRuleException( "Unable to lookup a component " + e.getLocalizedMessage(), e ); } catch ( ExpressionEvaluationException e ) { throw new EnforcerRuleException( "Unable to lookup an expression " + e.getLocalizedMessage(), e ); } } /** * If your rule is cacheable, you must return a unique id when parameters or conditions * change that would cause the result to be different. Multiple cached results are stored * based on their id. * * The easiest way to do this is to return a hash computed from the values of your parameters. * * If your rule is not cacheable, then the result here is not important, you may return anything. */ public String getCacheId() { //no hash on boolean...only parameter so no hash is needed. return ""+this.shouldIfail; } /** * This tells the system if the results are cacheable at all. Keep in mind that during * forked builds and other things, a given rule may be executed more than once for the same * project. This means that even things that change from project to project may still * be cacheable in certain instances. */ public boolean isCacheable() { return false; } /** * If the rule is cacheable and the same id is found in the cache, the stored results * are passed to this method to allow double checking of the results. Most of the time * this can be done by generating unique ids, but sometimes the results of objects returned * by the helper need to be queried. You may for example, store certain objects in your rule * and then query them later. */ public boolean isResultValid( EnforcerRule arg0 ) { return false; } } maven-enforcer-1.0.1/enforcer-api/src/custom-rule-sample/src/usage-pom.xml000066400000000000000000000025361205711263400265340ustar00rootroot00000000000000 4.0.0 org.apache.maven.plugins maven-enforcer-plugin-it1 1 pom org.apache.maven.plugins maven-enforcer-plugin 1.0-SNAPSHOT custom-rule custom-rule-sample 1.0 enforce [1.3,1.6] 2.0.6 true enforce maven-enforcer-1.0.1/enforcer-api/src/custom-rule-sample/usage-pom.xml000066400000000000000000000031701205711263400257400ustar00rootroot00000000000000 4.0.0 org.apache.maven.plugins maven-enforcer-plugin-sample-usage 1 jar org.apache.maven.plugins maven-enforcer-plugin 1.0-beta-1 custom-rule custom-rule-sample 1.0 enforce false enforce maven-enforcer-1.0.1/enforcer-api/src/main/000077500000000000000000000000001205711263400205065ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-api/src/main/assembly/000077500000000000000000000000001205711263400223255ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-api/src/main/assembly/custom-rule-sample.xml000066400000000000000000000004701205711263400266060ustar00rootroot00000000000000 sample false zip src/custom-rule-sample /custom-rule-sample maven-enforcer-1.0.1/enforcer-api/src/main/java/000077500000000000000000000000001205711263400214275ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-api/src/main/java/org/000077500000000000000000000000001205711263400222165ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-api/src/main/java/org/apache/000077500000000000000000000000001205711263400234375ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-api/src/main/java/org/apache/maven/000077500000000000000000000000001205711263400245455ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-api/src/main/java/org/apache/maven/enforcer/000077500000000000000000000000001205711263400263505ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/000077500000000000000000000000001205711263400273175ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/000077500000000000000000000000001205711263400300705ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRule.java000066400000000000000000000057331205711263400333360ustar00rootroot00000000000000package org.apache.maven.enforcer.rule.api; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /** * Interface to be implemented by any rules executed by the enforcer. * * @author Brian Fox * @version $Id: EnforcerRule.java 987781 2010-08-21 16:23:40Z dennisl $ */ public interface EnforcerRule { /** * This is the interface into the rule. This method should throw an exception * containing a reason message if the rule fails the check. The plugin will * then decide based on the fail flag if it should stop or just log the * message as a warning. * * @param helper The helper provides access to the log, MavenSession and has * helpers to get common components. It is also able to lookup components * by class name. * * @throws EnforcerRuleException the enforcer rule exception */ void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException; /** * This method tells the enforcer if the rule results may be cached. If the result is true, * the results will be remembered for future executions in the same build (ie children). Subsequent * iterations of the rule will be queried to see if they are also cacheable. This will allow the rule to be * uncached further down the tree if needed. * * @return true if rule is cacheable */ boolean isCacheable(); /** * Checks if cached result is valid. * * @param cachedRule the last cached instance of the rule. This is to be used by the rule to * potentially determine if the results are still valid (ie if the configuration has been overridden) * * @return true if the stored results are valid for the same id. */ boolean isResultValid( EnforcerRule cachedRule ); /** * If the rule is to be cached, this id is used as part of the key. This can allow rules to take parameters * that allow multiple results of the same rule to be cached. * * @return id to be used by the enforcer to determine uniqueness of cache results. The ids only need to be unique * within a given rule implementation as the full key will be [classname]-[id] */ String getCacheId(); } EnforcerRuleException.java000066400000000000000000000061651205711263400351360ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/apipackage org.apache.maven.enforcer.rule.api; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /** * An exception occurring during the execution of a rule. Based off of * EnforcerRuleException, but separated to keep the rule dependencies to a * minimum. * * @author Brian Fox * @version $Id: EnforcerRuleException.java 805162 2009-08-17 21:48:52Z hboutemy $ */ public class EnforcerRuleException extends Exception { /** serialVersionUID. */ private static final long serialVersionUID = 1L; /** The source. */ protected Object source; /** The long message. */ protected String longMessage; /** * Gets the long message. * * @return the long message */ public String getLongMessage() { return longMessage; } /** * Gets the source. * * @return the source */ public Object getSource() { return source; } /** * Construct a new EnforcerRuleException exception providing * the source and a short and long message. * * @param source the source * @param shortMessage the short message * @param longMessage the long message */ public EnforcerRuleException( Object source, String shortMessage, String longMessage ) { super( shortMessage ); this.source = source; this.longMessage = longMessage; } /** * Construct a new EnforcerRuleException exception wrapping * an underlying Exception and providing a * message. * * @param message the message * @param cause the cause */ public EnforcerRuleException( String message, Exception cause ) { super( message, cause ); } /** * Construct a new EnforcerRuleException exception wrapping * an underlying Throwable and providing a * message. * * @param message the message * @param cause the cause */ public EnforcerRuleException( String message, Throwable cause ) { super( message, cause ); } /** * Construct a new EnforcerRuleException exception providing * a message. * * @param message the message */ public EnforcerRuleException( String message ) { super( message ); } }EnforcerRuleHelper.java000066400000000000000000000063701205711263400344150ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/apipackage org.apache.maven.enforcer.rule.api; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.List; import java.util.Map; import org.apache.maven.plugin.logging.Log; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; /** * This is the interface that all helpers will use. This * provides access to the log, session and components to the * rules. * * @author Brian Fox * @version $Id: EnforcerRuleHelper.java 805162 2009-08-17 21:48:52Z hboutemy $ */ public interface EnforcerRuleHelper extends ExpressionEvaluator { /** * Gets the log. * * @return the log */ Log getLog (); /* * (non-Javadoc) * * @see org.apache.maven.shared.enforcer.rule.api.EnforcerRuleHelper#getRuntimeInformation() */ /** * Gets the component. * * @param clazz the clazz * * @return the component * * @throws ComponentLookupException the component lookup exception */ Object getComponent ( Class clazz ) throws ComponentLookupException; /** * Gets the component. * * @param componentKey the component key * * @return the component * * @throws ComponentLookupException the component lookup exception */ Object getComponent ( String componentKey ) throws ComponentLookupException; /** * Gets the component. * * @param role the role * @param roleHint the role hint * * @return the component * * @throws ComponentLookupException the component lookup exception */ Object getComponent ( String role, String roleHint ) throws ComponentLookupException; /** * Gets the component map. * * @param role the role * * @return the component map * * @throws ComponentLookupException the component lookup exception */ Map getComponentMap ( String role ) throws ComponentLookupException; /** * Gets the component list. * * @param role the role * * @return the component list * * @throws ComponentLookupException the component lookup exception */ List getComponentList ( String role ) throws ComponentLookupException; /** * Gets the container. * * @return the container */ PlexusContainer getContainer(); } maven-enforcer-1.0.1/enforcer-api/src/site/000077500000000000000000000000001205711263400205265ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-api/src/site/apt/000077500000000000000000000000001205711263400213125ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-api/src/site/apt/index.apt000066400000000000000000000023361205711263400231330ustar00rootroot00000000000000~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ------ Introduction ------ Brian Fox ------ Mar 2007 ------ Maven Enforcer Rule API - Extending The Loving Iron Fist of Maven\x99 Custom rules are easy to make with the <<>>. These rules can then be invoked with the {{{../../plugins/maven-enforcer-plugin/}maven-enforcer-plugin}}. See {{{./writing-a-custom-rule.html}Writing a Custom Rule}} for instructions on how to make your own rule. maven-enforcer-1.0.1/enforcer-api/src/site/apt/writing-a-custom-rule.apt.vm000066400000000000000000000237121205711263400266240ustar00rootroot00000000000000~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ------ Writing a custom rule ------ Brian Fox ------ Nov 2007 ------ Writing a custom rule Custom rules are easy to make with the <<>>. These rules can then be invoked with the {{{http://maven.apache.org/plugins/maven-enforcer-plugin/}maven-enforcer-plugin}}. Note: The files shown below may be downloaded here: {{{./custom-rule.zip}custom-rule.zip}} [[1]] First make a new jar project starting with the sample pom below: +---+ 4.0.0 custom-rule custom-rule-sample jar 1.0 My Custom Rule This is my custom rule. ${project.version} 2.0.9 org.apache.maven.enforcer enforcer-api ${api.version} org.apache.maven maven-project ${maven.version} org.apache.maven maven-core ${maven.version} org.apache.maven maven-artifact ${maven.version} org.apache.maven maven-plugin-api ${maven.version} org.codehaus.plexus plexus-container-default 1.0-alpha-9 junit junit 3.8.2 test +---+ [[2]] Create your rule class. The rule must implement the {{{./apidocs/index.html}EnforcerRule}} interface. The rule can get access to components and the log via the {{{./apidocs/index.html}EnforcerRuleHelper}} interface. If the rule succeeds, it should just simply return. If the rule fails, it should throw an {{{./apidocs/index.html}EnforcerRuleException}} with a descriptive message telling the user why the rule failed. There are several methods that must be implemented related to caching. Here's a sample class that shows how to access the helper methods and retrieve components by class name from the helper: +---+ package org.apache.maven.enforcer.rule; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.enforcer.rule.api.EnforcerRule; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.RuntimeInformation; import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; /** * @author Brian Fox */ public class MyCustomRule implements EnforcerRule { /** * Simple param. This rule will fail if the value is true. */ private boolean shouldIfail = false; public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException { Log log = helper.getLog(); try { // get the various expressions out of the helper. MavenProject project = (MavenProject) helper.evaluate( "\${project}" ); MavenSession session = (MavenSession) helper.evaluate( "${session}" ); String target = (String) helper.evaluate( "\${project.build.directory}" ); String artifactId = (String) helper.evaluate( "\${project.artifactId}" ); // retrieve any component out of the session directly ArtifactResolver resolver = (ArtifactResolver) helper.getComponent( ArtifactResolver.class ); RuntimeInformation rti = (RuntimeInformation) helper.getComponent( RuntimeInformation.class ); log.info( "Retrieved Target Folder: " + target ); log.info( "Retrieved ArtifactId: " +artifactId ); log.info( "Retrieved Project: " + project ); log.info( "Retrieved RuntimeInfo: " + rti ); log.info( "Retrieved Session: " + session ); log.info( "Retrieved Resolver: " + resolver ); if ( this.shouldIfail ) { throw new EnforcerRuleException( "Failing because my param said so." ); } } catch ( ComponentLookupException e ) { throw new EnforcerRuleException( "Unable to lookup a component " + e.getLocalizedMessage(), e ); } catch ( ExpressionEvaluationException e ) { throw new EnforcerRuleException( "Unable to lookup an expression " + e.getLocalizedMessage(), e ); } } /** * If your rule is cacheable, you must return a unique id when parameters or conditions * change that would cause the result to be different. Multiple cached results are stored * based on their id. * * The easiest way to do this is to return a hash computed from the values of your parameters. * * If your rule is not cacheable, then the result here is not important, you may return anything. */ public String getCacheId() { //no hash on boolean...only parameter so no hash is needed. return ""+this.shouldIfail; } /** * This tells the system if the results are cacheable at all. Keep in mind that during * forked builds and other things, a given rule may be executed more than once for the same * project. This means that even things that change from project to project may still * be cacheable in certain instances. */ public boolean isCacheable() { return false; } /** * If the rule is cacheable and the same id is found in the cache, the stored results * are passed to this method to allow double checking of the results. Most of the time * this can be done by generating unique ids, but sometimes the results of objects returned * by the helper need to be queried. You may for example, store certain objects in your rule * and then query them later. */ public boolean isResultValid( EnforcerRule arg0 ) { return false; } } +---+ [[3]] Build and Install or Deploy your custom rule. [[4]] Add your custom-rule artifact as a dependency of the <<>> in your build: +---+ ... org.apache.maven.plugins maven-enforcer-plugin 1.0-beta-1 custom-rule custom-rule-sample 1.0 ... ... +---+ [[5]] Add your rule to the configuration section of the <<>>. The name of your class will be the name of the rule, and you must add an <<>> hint that contains the fully qualified class name: +---+ ... true ... +---+ [[6]] That's it. The full plugin config may look like this: +---+ ... org.apache.maven.plugins maven-enforcer-plugin 1.0-beta-1 custom-rule custom-rule-sample 1.0 enforce false enforce ... +---+maven-enforcer-1.0.1/enforcer-api/src/site/site.xml000066400000000000000000000022021205711263400222100ustar00rootroot00000000000000 maven-enforcer-1.0.1/enforcer-rules/000077500000000000000000000000001205711263400173545ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/pom.xml000066400000000000000000000076531205711263400207040ustar00rootroot00000000000000 4.0.0 org.apache.maven.enforcer enforcer 1.0.1 enforcer-rules 1.0.1 jar Enforcer Rules This component contains the standard Enforcer Rules org.apache.maven maven-artifact org.apache.maven maven-plugin-api org.apache.maven maven-project org.apache.maven maven-core org.apache.maven.shared maven-common-artifact-filters org.codehaus.plexus plexus-utils org.apache.maven.shared maven-plugin-testing-harness test commons-lang commons-lang org.apache.maven.enforcer enforcer-api org.beanshell bsh 2.0b4 junit junit easymock easymock org.apache.maven.shared maven-dependency-tree 1.2 org.codehaus.plexus plexus-i18n 1.0-beta-6 org.codehaus.plexus plexus-maven-plugin descriptor org.apache.maven.plugins maven-jar-plugin test-jar maven-enforcer-1.0.1/enforcer-rules/src/000077500000000000000000000000001205711263400201435ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/000077500000000000000000000000001205711263400210675ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/000077500000000000000000000000001205711263400220105ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/000077500000000000000000000000001205711263400225775ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/000077500000000000000000000000001205711263400240205ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/000077500000000000000000000000001205711263400251265ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/000077500000000000000000000000001205711263400266075ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/000077500000000000000000000000001205711263400304125ustar00rootroot00000000000000AbstractBanDependencies.java000066400000000000000000000114061205711263400356730ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.Iterator; import java.util.Set; import org.apache.maven.artifact.Artifact; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; /** * Abstract Rule for banning dependencies. * * @author Brian Fox * @version $Id: AbstractBanDependencies.java 885125 2009-11-28 18:51:23Z brianf $ */ public abstract class AbstractBanDependencies extends AbstractNonCacheableEnforcerRule { /** Specify if transitive dependencies should be searched (default) or only look at direct dependencies. */ private boolean searchTransitive = true; /** * Execute the rule. * * @param helper the helper * @throws EnforcerRuleException the enforcer rule exception */ public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException { // get the project MavenProject project = null; try { project = (MavenProject) helper.evaluate( "${project}" ); } catch ( ExpressionEvaluationException eee ) { throw new EnforcerRuleException( "Unable to retrieve the MavenProject: ", eee ); } // get the correct list of dependencies Set dependencies = getDependenciesToCheck( project ); // look for banned dependencies Set foundExcludes = checkDependencies( dependencies, helper.getLog() ); // if any are found, fail the check but list all of them if ( foundExcludes != null && !foundExcludes.isEmpty() ) { StringBuffer buf = new StringBuffer(); if ( message != null ) { buf.append( message + "\n" ); } Iterator iter = foundExcludes.iterator(); while ( iter.hasNext() ) { Artifact artifact = (Artifact) iter.next(); buf.append( getErrorMessage( artifact ) ); } message = buf.toString()+ "Use 'mvn dependency:tree' to locate the source of the banned dependencies."; throw new EnforcerRuleException( message ); } } protected CharSequence getErrorMessage( Artifact artifact ) { return "Found Banned Dependency: " + artifact.getId() + "\n"; } protected Set getDependenciesToCheck( MavenProject project ) { Set dependencies = null; if ( searchTransitive ) { dependencies = project.getArtifacts(); } else { dependencies = project.getDependencyArtifacts(); } return dependencies; } /** * Checks the set of dependencies against the list of excludes. * * @param dependencies the dependencies * @param log the log * @return the sets the * @throws EnforcerRuleException the enforcer rule exception */ abstract protected Set checkDependencies( Set dependencies, Log log ) throws EnforcerRuleException; /** * Gets the message. * * @return the message */ public String getMessage() { return this.message; } /** * Sets the message. * * @param theMessage the message to set */ public void setMessage( String theMessage ) { this.message = theMessage; } /** * Checks if is search transitive. * * @return the searchTransitive */ public boolean isSearchTransitive() { return this.searchTransitive; } /** * Sets the search transitive. * * @param theSearchTransitive the searchTransitive to set */ public void setSearchTransitive( boolean theSearchTransitive ) { this.searchTransitive = theSearchTransitive; } } AbstractNonCacheableEnforcerRule.java000066400000000000000000000036341205711263400375060ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.enforcer.rule.api.EnforcerRule; /** * The Class AbstractNonCacheableEnforcerRule. This is to be used by rules * that don't need caching... it saves implementing a bunch of methods. * * @author Brian Fox * @version $Id: AbstractNonCacheableEnforcerRule.java 805190 2009-08-17 22:30:49Z hboutemy $ */ public abstract class AbstractNonCacheableEnforcerRule extends AbstractStandardEnforcerRule { /* * (non-Javadoc) * * @see org.apache.maven.enforcer.rule.api.EnforcerRule#getCacheId() */ public String getCacheId() { return "0"; } /* * (non-Javadoc) * * @see org.apache.maven.enforcer.rule.api.EnforcerRule#isCacheable() */ public boolean isCacheable() { return false; } /* * (non-Javadoc) * * @see org.apache.maven.enforcer.rule.api.EnforcerRule#isResultValid(org.apache.maven.enforcer.rule.api.EnforcerRule) */ public boolean isResultValid( EnforcerRule cachedRule ) { return false; } } AbstractRequireFiles.java000066400000000000000000000134111205711263400352610ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.File; import java.util.ArrayList; import java.util.Iterator; import org.apache.maven.enforcer.rule.api.EnforcerRule; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; /** * Contains the common code to compare an array of files against a requirement. * * @author Brian Fox */ public abstract class AbstractRequireFiles extends AbstractStandardEnforcerRule { /** Array of files to check. */ File[] files; /** if null file handles should be allowed. If they are allowed, it means treat it as a success. */ boolean allowNulls = false; // check the file for the specific condition /** * Check one file. * * @param file the file * @return true if successful */ abstract boolean checkFile( File file ); // return standard error message /** * Gets the error msg. * * @return the error msg */ abstract String getErrorMsg(); /* * (non-Javadoc) * * @see org.apache.maven.enforcer.rule.api.EnforcerRule#execute(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper) */ public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException { if ( !allowNulls && files.length == 0 ) { throw new EnforcerRuleException( "The file list is empty and Null files are disabled." ); } ArrayList failures = new ArrayList(); for ( int i = 0; i < files.length; i++ ) { if ( !allowNulls && files[i] == null ) { failures.add( files[i] ); } else if ( !checkFile( files[i] ) ) { failures.add( files[i] ); } } // if anything was found, log it with the optional message. if ( !failures.isEmpty() ) { StringBuffer buf = new StringBuffer(); if ( message != null ) { buf.append( message + "\n" ); } buf.append( getErrorMsg() ); Iterator iter = failures.iterator(); while ( iter.hasNext() ) { File file = (File) iter.next(); if ( file != null ) { buf.append( file.getAbsolutePath() + "\n" ); } else { buf.append( "(an empty filename was given and allowNulls is false)\n" ); } } throw new EnforcerRuleException( buf.toString() ); } } /** * If your rule is cacheable, you must return a unique id when parameters or conditions change that would cause the * result to be different. Multiple cached results are stored based on their id. The easiest way to do this is to * return a hash computed from the values of your parameters. If your rule is not cacheable, then the result here is * not important, you may return anything. * * @return the cache id */ public String getCacheId() { return Integer.toString( hashCode( files ) ); } /** * Calculates a hash code for the specified array as Arrays.hashCode() would do. Unfortunately, the * mentioned method is only available for Java 1.5 and later. * * @param items The array for which to compute the hash code, may be null. * @return The hash code for the array. */ private static int hashCode( Object[] items ) { int hash = 0; if ( items != null ) { hash = 1; for ( int i = 0; i < items.length; i++ ) { Object item = items[i]; hash = 31 * hash + ( item == null ? 0 : item.hashCode() ); } } return hash; } /** * This tells the system if the results are cacheable at all. Keep in mind that during forked builds and other * things, a given rule may be executed more than once for the same project. This means that even things that change * from project to project may still be cacheable in certain instances. * * @return true if rule is cacheable */ public boolean isCacheable() { return true; } /** * If the rule is cacheable and the same id is found in the cache, the stored results are passed to this method to * allow double checking of the results. Most of the time this can be done by generating unique ids, but sometimes * the results of objects returned by the helper need to be queried. You may for example, store certain objects in * your rule and then query them later. * * @param cachedRule the cached rule * @return true if the stored results are valid for the same id. */ public boolean isResultValid( EnforcerRule cachedRule ) { return true; } } AbstractStandardEnforcerRule.java000066400000000000000000000021601205711263400367350ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.enforcer.rule.api.EnforcerRule; /** * The Class AbstractStandardEnforcerRule. */ public abstract class AbstractStandardEnforcerRule implements EnforcerRule { /** Specify a friendly message if the rule fails. */ public String message = null; } AbstractVersionEnforcer.java000066400000000000000000000161651205711263400360040ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.Iterator; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; import org.apache.maven.artifact.versioning.Restriction; import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.enforcer.rule.api.EnforcerRule; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.logging.Log; import org.codehaus.plexus.util.StringUtils; /** * Contains the common code to compare a version against a version range. * * @author Brian Fox * @version $Id: AbstractVersionEnforcer.java 805190 2009-08-17 22:30:49Z hboutemy $ */ public abstract class AbstractVersionEnforcer extends AbstractStandardEnforcerRule { /** * Specify the required version. Some examples are: *
    *
  • 2.0.4 Version 2.0.4 and higher (different from Maven meaning)
  • *
  • [2.0,2.1) Versions 2.0 (included) to 2.1 (not included)
  • *
  • [2.0,2.1] Versions 2.0 to 2.1 (both included)
  • *
  • [2.0.5,) Versions 2.0.5 and higher
  • *
  • (,2.0.5],[2.1.1,) Versions up to 2.0.5 (included) and 2.1.1 or higher
  • *
*/ public String version = null; /** * Compares the specified version to see if it is allowed by the defined version range. * * @param log the log * @param variableName name of variable to use in messages (Example: "Maven" or "Java" etc). * @param requiredVersionRange range of allowed versions. * @param actualVersion the version to be checked. * @throws MojoExecutionException if the version is not allowed. * @throws EnforcerRuleException the enforcer rule exception */ public void enforceVersion( Log log, String variableName, String requiredVersionRange, ArtifactVersion actualVersion ) throws EnforcerRuleException { if ( StringUtils.isEmpty( requiredVersionRange ) ) { throw new EnforcerRuleException( variableName + " version can't be empty." ); } else { VersionRange vr; String msg = "Detected " + variableName + " Version: " + actualVersion; // short circuit check if the strings are exactly equal if ( actualVersion.toString().equals( requiredVersionRange ) ) { log.debug( msg + " is allowed in the range " + requiredVersionRange + "." ); } else { try { vr = VersionRange.createFromVersionSpec( requiredVersionRange ); if ( containsVersion( vr, actualVersion ) ) { log.debug( msg + " is allowed in the range " + requiredVersionRange + "." ); } else { if ( StringUtils.isEmpty( message ) ) { message = msg + " is not in the allowed range " + vr + "."; } throw new EnforcerRuleException( message ); } } catch ( InvalidVersionSpecificationException e ) { throw new EnforcerRuleException( "The requested " + variableName + " version " + requiredVersionRange + " is invalid.", e ); } } } } /** * Copied from Artifact.VersionRange. This is tweaked to handle singular ranges properly. Currently the default * containsVersion method assumes a singular version means allow everything. This method assumes that "2.0.4" == * "[2.0.4,)" * * @param allowedRange range of allowed versions. * @param theVersion the version to be checked. * @return true if the version is contained by the range. */ public static boolean containsVersion( VersionRange allowedRange, ArtifactVersion theVersion ) { boolean matched = false; ArtifactVersion recommendedVersion = allowedRange.getRecommendedVersion(); if ( recommendedVersion == null ) { for ( Iterator i = allowedRange.getRestrictions().iterator(); i.hasNext() && !matched; ) { Restriction restriction = (Restriction) i.next(); if ( restriction.containsVersion( theVersion ) ) { matched = true; } } } else { // only singular versions ever have a recommendedVersion int compareTo = recommendedVersion.compareTo( theVersion ); matched = ( compareTo <= 0 ); } return matched; } /* * (non-Javadoc) * * @see org.apache.maven.enforcer.rule.api.EnforcerRule#getCacheId() */ public String getCacheId() { if ( StringUtils.isNotEmpty( version ) ) { // return the hashcodes of the parameter that matters return "" + version.hashCode(); } else { return "0"; } } /* * (non-Javadoc) * * @see org.apache.maven.enforcer.rule.api.EnforcerRule#isCacheable() */ public boolean isCacheable() { // the maven version is not going to change between projects in the same build. return true; } /* * (non-Javadoc) * * @see org.apache.maven.enforcer.rule.api.EnforcerRule#isResultValid(org.apache.maven.enforcer.rule.api.EnforcerRule) */ public boolean isResultValid( EnforcerRule theCachedRule ) { // i will always return the hash of the parameters as my id. If my parameters are the same, this // rule must always have the same result. return true; } /** * Gets the required version. * * @return the required version */ public String getVersion() { return this.version; } /** * Sets the required version. * * @param theVersion the required version to set */ public void setVersion( String theVersion ) { this.version = theVersion; } } maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AlwaysFail.java000066400000000000000000000031041205711263400333070ustar00rootroot00000000000000package org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; /** * Always fail. This rule is useful for testing the Enforcer configuration, or to always fail the build if a particular * profile is enabled. * @author Ben Lidgey */ public class AlwaysFail extends AbstractNonCacheableEnforcerRule { /** * {@inheritDoc} */ public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException { StringBuffer buf = new StringBuffer(); if ( message != null ) { buf.append( message + "\n" ); } buf.append( "Always fails!" ); throw new EnforcerRuleException( buf.toString() ); } } maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AlwaysPass.java000066400000000000000000000030771205711263400333530ustar00rootroot00000000000000package org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.apache.maven.plugin.logging.Log; /** * Always pass. This rule is useful for testing the Enforcer configuration. * @author Ben Lidgey */ public class AlwaysPass extends AbstractNonCacheableEnforcerRule { /** * {@inheritDoc} */ public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException { final Log log = helper.getLog(); StringBuffer buf = new StringBuffer(); if ( message != null ) { buf.append( message + "\n" ); } buf.append( "Always pass!" ); log.info( buf.toString() ); } } BannedDependencies.java000066400000000000000000000171031205711263400346760ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.plugin.logging.Log; import org.codehaus.plexus.util.StringUtils; /** * This rule checks that lists of dependencies are not included. * * @author Brian Fox * @version $Id: BannedDependencies.java 1028164 2010-10-28 01:40:06Z brianf $ */ public class BannedDependencies extends AbstractBanDependencies { /** * Specify the banned dependencies. This can be a list of artifacts in the format groupId[:artifactId][:version]. * Any of the sections can be a wildcard by using '*' (ie group:*:1.0)
* The rule will fail if any dependency matches any exclude, unless it also matches an include rule. */ public List excludes = null; /** * Specify the allowed dependencies. This can be a list of artifacts in the format groupId[:artifactId][:version]. * Any of the sections can be a wildcard by using '*' (ie group:*:1.0)
* Includes override the exclude rules. It is meant to allow wide exclusion rules with wildcards and still allow a * smaller set of includes.
* For example, to ban all xerces except xerces-api -> exclude "xerces", include "xerces:xerces-api" */ public List includes = null; /* * (non-Javadoc) * * @see org.apache.maven.plugin.enforcer.AbstractBanDependencies#checkDependencies(java.util.Set) */ protected Set checkDependencies( Set theDependencies, Log log ) throws EnforcerRuleException { Set excluded = checkDependencies( theDependencies, excludes ); // anything specifically included should be removed // from the ban list. if ( excluded != null ) { Set included = checkDependencies( theDependencies, includes ); if ( included != null ) { excluded.removeAll( included ); } } return excluded; } /** * Checks the set of dependencies against the list of patterns. * * @param thePatterns the patterns * @param dependencies the dependencies * @return a set containing artifacts matching one of the patterns or null * @throws EnforcerRuleException the enforcer rule exception */ private Set checkDependencies( Set dependencies, List thePatterns ) throws EnforcerRuleException { Set foundMatches = null; if ( thePatterns != null && thePatterns.size() > 0 ) { Iterator iter = thePatterns.iterator(); while ( iter.hasNext() ) { String pattern = (String) iter.next(); String[] subStrings = pattern.split( ":" ); subStrings = StringUtils.stripAll( subStrings ); Iterator dependencyIter = dependencies.iterator(); while ( dependencyIter.hasNext() ) { Artifact artifact = (Artifact) dependencyIter.next(); if ( compareDependency( subStrings, artifact ) ) { // only create if needed if ( foundMatches == null ) { foundMatches = new HashSet(); } foundMatches.add( artifact ); } } } } return foundMatches; } /** * Compares the parsed array of substrings against the artifact. * The pattern should follow the format "groupId:artifactId:version:type:scope" * * @param pattern the array of patterns * @param artifact the artifact * @return true if the artifact matches one of the patterns * @throws EnforcerRuleException the enforcer rule exception */ protected boolean compareDependency( String[] pattern, Artifact artifact ) throws EnforcerRuleException { boolean result = false; if ( pattern.length > 0 ) { result = pattern[0].equals( "*" ) || artifact.getGroupId().equals( pattern[0] ); } if ( result && pattern.length > 1 ) { result = pattern[1].equals( "*" ) || artifact.getArtifactId().equals( pattern[1] ); } if ( result && pattern.length > 2 ) { // short circuit if the versions are exactly the same if ( pattern[2].equals( "*" ) || artifact.getVersion().equals( pattern[2] ) ) { result = true; } else { try { result = AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( pattern[2] ), new DefaultArtifactVersion( artifact.getBaseVersion() ) ); } catch ( InvalidVersionSpecificationException e ) { throw new EnforcerRuleException( "Invalid Version Range: ", e ); } } } if ( result && pattern.length > 3 ) { String type = artifact.getType(); if ( type == null || type.equals( "" ) ) { type = "jar"; } result = pattern[3].equals( "*" ) || type.equals( pattern[3] ); } if ( result && pattern.length > 4 ) { String scope = artifact.getScope(); if ( scope == null || scope.equals( "" ) ) { scope = "compile"; } result = pattern[4].equals( "*" ) || scope.equals( pattern[4] ); } return result; } /** * Gets the excludes. * * @return the excludes */ public List getExcludes() { return this.excludes; } /** * Sets the excludes. * * @param theExcludes the excludes to set */ public void setExcludes( List theExcludes ) { this.excludes = theExcludes; } /** * Gets the includes. * * @return the includes */ public List getIncludes() { return this.includes; } /** * Sets the includes. * * @param theIncludes the includes to set */ public void setIncludes( List theIncludes ) { this.includes = theIncludes; } } BannedPlugins.java000066400000000000000000000027041205711263400337320ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.Set; import org.apache.maven.artifact.Artifact; import org.apache.maven.project.MavenProject; /** * This rule checks that lists of plugins are not included. * * @author Marvin Froeder */ public class BannedPlugins extends BannedDependencies { protected Set getDependenciesToCheck( MavenProject project ) { return project.getPluginArtifacts(); } protected CharSequence getErrorMessage( Artifact artifact ) { return "Found Banned Plugin: " + artifact.getId() + "\n"; } } DefaultEnforcementRuleHelper.java000066400000000000000000000120251205711263400367400ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.File; import java.util.List; import java.util.Map; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.logging.Log; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; /** * Default implementation of the EnforcementRuleHelper interface. This is used to help retrieve information from the * session and provide useful elements like the log. * * @author Brian Fox * @version $Id: DefaultEnforcementRuleHelper.java 805190 2009-08-17 22:30:49Z hboutemy $ */ public class DefaultEnforcementRuleHelper implements EnforcerRuleHelper { /** The log. */ Log log; /** The evaluator. */ ExpressionEvaluator evaluator; /** The session. */ MavenSession session; /** The container. */ PlexusContainer container; /** * Instantiates a new default enforcement rule helper. * * @param session the session * @param evaluator the evaluator * @param log the log * @param container the container */ public DefaultEnforcementRuleHelper( MavenSession session, ExpressionEvaluator evaluator, Log log, PlexusContainer container ) { this.evaluator = evaluator; this.log = log; this.session = session; if ( container != null ) { this.container = container; } else { this.container = session.getContainer(); } } /* * (non-Javadoc) * * @see org.apache.maven.enforcer.rule.api.EnforcerRuleHelper#getLog() */ public Log getLog() { return log; } /* * (non-Javadoc) * * @see org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator#alignToBaseDirectory(java.io.File) */ public File alignToBaseDirectory( File theFile ) { return evaluator.alignToBaseDirectory( theFile ); } /* * (non-Javadoc) * * @see org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator#evaluate(java.lang.String) */ public Object evaluate( String theExpression ) throws ExpressionEvaluationException { return evaluator.evaluate( theExpression ); } /* * (non-Javadoc) * * @see org.apache.maven.shared.enforcer.rule.api.EnforcerRuleHelper#getRuntimeInformation() */ public Object getComponent( Class clazz ) throws ComponentLookupException { return getComponent( clazz.getName() ); } /* * (non-Javadoc) * * @see org.apache.maven.enforcer.rule.api.EnforcerRuleHelper#lookup(java.lang.String) */ public Object getComponent( String theComponentKey ) throws ComponentLookupException { return container.lookup( theComponentKey ); } /* * (non-Javadoc) * * @see org.apache.maven.enforcer.rule.api.EnforcerRuleHelper#lookup(java.lang.String, java.lang.String) */ public Object getComponent( String theRole, String theRoleHint ) throws ComponentLookupException { return container.lookup( theRole, theRoleHint ); } /* * (non-Javadoc) * * @see org.apache.maven.enforcer.rule.api.EnforcerRuleHelper#lookupList(java.lang.String) */ public List getComponentList( String theRole ) throws ComponentLookupException { return container.lookupList( theRole ); } /* * (non-Javadoc) * * @see org.apache.maven.enforcer.rule.api.EnforcerRuleHelper#lookupMap(java.lang.String) */ public Map getComponentMap( String theRole ) throws ComponentLookupException { return container.lookupMap( theRole ); } /* * (non-Javadoc) * * @see org.apache.maven.enforcer.rule.api.EnforcerRuleHelper#getContainer() */ public PlexusContainer getContainer() { return container; } } DependencyConvergence.java000066400000000000000000000204111205711263400354310ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ArtifactCollector; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.enforcer.rule.api.EnforcerRule; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugins.enforcer.utils.DependencyVersionMap; import org.apache.maven.project.MavenProject; import org.apache.maven.shared.dependency.tree.DependencyNode; import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder; import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.i18n.I18N; /** * @author Rex Hoffman */ public class DependencyConvergence implements EnforcerRule { private static Log log; private static I18N i18n; /** * Uses the {@link EnforcerRuleHelper} to populate the values of the {@link DependencyTreeBuilder#buildDependencyTree(MavenProject, ArtifactRepository, ArtifactFactory, ArtifactMetadataSource, ArtifactFilter, ArtifactCollector)} * factory method.
* * This method simply exists to hide all the ugly lookup that the {@link EnforcerRuleHelper} has to do. * * @param helper * @return a Dependency Node which is the root of the project's dependency tree * @throws EnforcerRuleException */ private DependencyNode getNode(EnforcerRuleHelper helper) throws EnforcerRuleException { try { MavenProject project = (MavenProject) helper.evaluate("${project}"); DependencyTreeBuilder dependencyTreeBuilder = (DependencyTreeBuilder) helper.getComponent(DependencyTreeBuilder.class); ArtifactRepository repository = (ArtifactRepository)helper.evaluate("${localRepository}"); ArtifactFactory factory = (ArtifactFactory)helper.getComponent(ArtifactFactory.class); ArtifactMetadataSource metadataSource = (ArtifactMetadataSource)helper.getComponent(ArtifactMetadataSource.class); ArtifactCollector collector = (ArtifactCollector)helper.getComponent(ArtifactCollector.class); ArtifactFilter filter = null; //we need to evaluate all scopes DependencyNode node = dependencyTreeBuilder.buildDependencyTree(project, repository, factory, metadataSource, filter, collector); return node; } catch (ExpressionEvaluationException e) { throw new EnforcerRuleException("Unable to lookup an expression " + e.getLocalizedMessage(), e); } catch (ComponentLookupException e){ throw new EnforcerRuleException("Unable to lookup a component " + e.getLocalizedMessage(), e); } catch (DependencyTreeBuilderException e){ throw new EnforcerRuleException("Could not build dependency tree " + e.getLocalizedMessage(), e); } } public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException { if (log == null){ log = helper.getLog(); } try { if (i18n == null){ i18n = (I18N) helper.getComponent(I18N.class); } DependencyNode node = getNode(helper); MavenProject project = (MavenProject) helper.evaluate("${project}"); DependencyVersionMap visitor = new DependencyVersionMap(project.getArtifact().isRelease(), log); node.accept(visitor); List errorMsgs = new ArrayList(); errorMsgs.addAll(getConvergenceErrorMsgs(visitor.getConflictedVersionNumbers())); for (CharSequence errorMsg : errorMsgs) { log.error(errorMsg); } if (errorMsgs.size() > 0) { throw new EnforcerRuleException("Failed while enforcing releasability the error(s) are " + errorMsgs); } } catch (ExpressionEvaluationException e) { throw new EnforcerRuleException("Unable to lookup an expression " + e.getLocalizedMessage(), e); } catch (ComponentLookupException e){ throw new EnforcerRuleException("Unable to lookup a component " + e.getLocalizedMessage(), e); } catch (Exception e){ throw new EnforcerRuleException(e.getLocalizedMessage(), e); } } private String getFullArtifactName(Artifact artifact){ return artifact.getGroupId() + ":" + artifact.getArtifactId() +":"+ artifact.getVersion(); } private StringBuilder buildTreeString(DependencyNode node) { List loc = new ArrayList(); DependencyNode currentNode = node; while (currentNode != null) { loc.add(getFullArtifactName(currentNode.getArtifact())); currentNode = currentNode.getParent(); } Collections.reverse(loc); StringBuilder builder = new StringBuilder(); for (int i = 0; i < loc.size(); i++) { for (int j = 0; j < i; j++){ builder.append(" "); } builder.append("+-"+loc.get(i)); builder.append("\n"); } return builder; } private List getConvergenceErrorMsgs(List> errors) { List errorMsgs = new ArrayList(); for (List nodeList : errors){ errorMsgs.add(buildConvergenceErrorMsg(nodeList)); } return errorMsgs; } private String buildConvergenceErrorMsg(List nodeList){ StringBuilder builder = new StringBuilder(); builder.append("\nDependency convergence error for "+getFullArtifactName(nodeList.get(0).getArtifact())+" paths to dependency are:\n"); if (nodeList.size() > 0){ builder.append(buildTreeString(nodeList.get(0))); } for (DependencyNode node: nodeList.subList(1,nodeList.size())){ builder.append("and\n"); builder.append(buildTreeString(node)); } return builder.toString(); } /** * If your rule is cacheable, you must return a unique id when parameters or * conditions change that would cause the result to be different. Multiple * cached results are stored based on their id. * * The easiest way to do this is to return a hash computed from the values of * your parameters. * * If your rule is not cacheable, then the result here is not important, you * may return anything. */ public String getCacheId() { return ""; } /** * This tells the system if the results are cacheable at all. Keep in mind * that during forked builds and other things, a given rule may be executed * more than once for the same project. This means that even things that * change from project to project may still be cacheable in certain instances. */ public boolean isCacheable() { return false; } /** * If the rule is cacheable and the same id is found in the cache, the stored * results are passed to this method to allow double checking of the results. * Most of the time this can be done by generating unique ids, but sometimes * the results of objects returned by the helper need to be queried. You may * for example, store certain objects in your rule and then query them later. */ public boolean isResultValid(EnforcerRule arg0) { return false; } } EnforcerExpressionEvaluator.java000066400000000000000000000037641205711263400367160ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.MojoExecution; import org.apache.maven.plugin.PluginParameterExpressionEvaluator; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.project.MavenProject; import org.apache.maven.project.path.PathTranslator; /** * The Class EnforcerExpressionEvaluator. This class wraps the PluginParameterExpressionEvaluator * because it can't be accessed directly in 2.0.x so we must create a new one. * * @author Brian Fox */ public class EnforcerExpressionEvaluator extends PluginParameterExpressionEvaluator { /** * The Constructor. * * @param theContext the the context * @param thePathTranslator the the path translator * @param theProject the the project */ public EnforcerExpressionEvaluator( MavenSession theContext, PathTranslator thePathTranslator, MavenProject theProject ) { super( theContext, new MojoExecution( new MojoDescriptor() ), thePathTranslator, null, theProject, theContext.getExecutionProperties() ); } } EvaluateBeanshell.java000066400000000000000000000065311205711263400345670ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.apache.maven.plugin.logging.Log; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; import org.codehaus.plexus.util.StringUtils; import bsh.EvalError; import bsh.Interpreter; /** * Rule for Maven Enforcer using Beanshell to evaluate a conditional expression. * * @author hugonnem */ public class EvaluateBeanshell extends AbstractNonCacheableEnforcerRule { /** Beanshell interpreter. */ private static final Interpreter bsh = new Interpreter(); /** The condition to be evaluated. */ public String condition; /* * (non-Javadoc) * * @see org.apache.maven.enforcer.rule.api.EnforcerRule#execute(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper) */ public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException { Log log = helper.getLog(); try { log.debug( "Echo condition : " + this.condition ); // Evaluate condition within Plexus Container String script = (String) helper.evaluate( this.condition ); log.debug( "Echo script : " + script ); if ( !evaluateCondition( script, log ) ) { if ( StringUtils.isEmpty( message ) ) { message = "The expression \"" + condition + "\" is not true."; } throw new EnforcerRuleException( this.message ); } } catch ( ExpressionEvaluationException e ) { throw new EnforcerRuleException( "Unable to evaluate an expression '" + condition + "'", e ); } } /** * Evaluate expression using Beanshell. * * @param script the expression to be evaluated * @param log the logger * @return boolean the evaluation of the expression * @throws EnforcerRuleException if the script could not be evaluated */ protected boolean evaluateCondition( String script, Log log ) throws EnforcerRuleException { Boolean evaluation = Boolean.FALSE; try { evaluation = (Boolean) bsh.eval( script ); log.debug( "Echo evaluating : " + evaluation ); } catch ( EvalError ex ) { throw new EnforcerRuleException( "Couldn't evaluate condition: " + script, ex ); } return evaluation.booleanValue(); } } maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/NoSnapshots.java000066400000000000000000000035521205711263400335410ustar00rootroot00000000000000package org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.Set; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.plugin.logging.Log; /** * This rule is deprecated. Use requireReleaseVersions. * * @author Brian Fox * @version $Id: NoSnapshots.java 987781 2010-08-21 16:23:40Z dennisl $ * @deprecated replaced by {@link RequireReleaseDeps} */ public class NoSnapshots extends AbstractBanDependencies { /** * Checks the set of dependencies to see if any snapshots are included. * * @param dependencies the dependencies * @param log the log * @return the sets the * @throws EnforcerRuleException the enforcer rule exception */ protected Set checkDependencies( Set dependencies, Log log ) throws EnforcerRuleException { log.warn( "The \"NoSnapshots\" rule is deprecated. Use \"requireReleaseDeps\" instead" ); RequireReleaseDeps rule = new RequireReleaseDeps(); return rule.checkDependencies( dependencies, log ); } } RequireActiveProfile.java000066400000000000000000000107411205711263400352720ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.apache.maven.model.Profile; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; import org.codehaus.plexus.util.StringUtils; /** * This rule checks that some profiles are active. * * @author Brian Fox */ public class RequireActiveProfile extends AbstractNonCacheableEnforcerRule { /** Comma separated list of profiles to check. */ public String profiles = null; /** If all profiles must be active. If false, only one must be active */ public boolean all = true; /* * (non-Javadoc) * * @see org.apache.maven.enforcer.rule.api.EnforcerRule#execute(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper) */ public void execute( EnforcerRuleHelper theHelper ) throws EnforcerRuleException { List missingProfiles = new ArrayList(); try { MavenProject project = (MavenProject) theHelper.evaluate( "${project}" ); if ( StringUtils.isNotEmpty( profiles ) ) { String[] profs = profiles.split( "," ); for ( int i = 0; i < profs.length; i++ ) { if ( !isProfileActive( project, profs[i] ) ) { missingProfiles.add( profs[i] ); } } boolean fail = false; if ( !missingProfiles.isEmpty() ) { fail = true; // if (all && missingProfiles.size() != profs.length) // { // fail = true; // } // else // { // if (!all && missingProfiles.size() >= (profs.length -1)) // { // fail = true; // } // } } if ( fail ) { StringBuffer buf = new StringBuffer(); if ( message != null ) { buf.append( message + "\n" ); } Iterator iter = missingProfiles.iterator(); while ( iter.hasNext() ) { buf.append( "Profile \"" + iter.next().toString() + "\" is not activated.\n" ); } throw new EnforcerRuleException( buf.toString() ); } } } catch ( ExpressionEvaluationException e ) { throw new EnforcerRuleException( "Unable to retrieve the project.", e ); } } /** * Checks if profile is active. * * @param project the project * @param profileName the profile name * @return true if profile is active */ protected boolean isProfileActive( MavenProject project, String profileName ) { List activeProfiles = project.getActiveProfiles(); if ( activeProfiles != null && !activeProfiles.isEmpty() ) { for ( Iterator it = activeProfiles.iterator(); it.hasNext(); ) { Profile profile = (Profile) it.next(); if ( profile.getId().equals( profileName ) ) { return true; } } } return false; } } RequireFilesDontExist.java000066400000000000000000000027411205711263400354430ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.File; /** * The Class RequireFilesDontExist. */ public class RequireFilesDontExist extends AbstractRequireFiles { /* * (non-Javadoc) * * @see org.apache.maven.plugins.enforcer.AbstractRequireFiles#checkFile(java.io.File) */ boolean checkFile( File file ) { //if we get here and the handle is null, treat it as a success return file == null ? true : !file.exists(); } /* * (non-Javadoc) * * @see org.apache.maven.plugins.enforcer.AbstractRequireFiles#getErrorMsg() */ String getErrorMsg() { return "Some files should not exist:\n"; } } RequireFilesExist.java000066400000000000000000000027361205711263400346220ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.File; /** * The Class RequireFilesExist. */ public class RequireFilesExist extends AbstractRequireFiles { /* * (non-Javadoc) * * @see org.apache.maven.plugins.enforcer.AbstractRequireFiles#checkFile(java.io.File) */ boolean checkFile( File file ) { //if we get here and the handle is null, treat it as a success return file == null ? true : file.exists(); } /* * (non-Javadoc) * * @see org.apache.maven.plugins.enforcer.AbstractRequireFiles#getErrorMsg() */ String getErrorMsg() { return "Some required files are missing:\n"; } } RequireFilesSize.java000066400000000000000000000107131205711263400344320ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.File; import org.apache.maven.enforcer.rule.api.EnforcerRule; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; /** * Rule to validate the main artifact is within certain size constraints. * * @author brianf * @author Roman Stumm */ public class RequireFilesSize extends AbstractRequireFiles { /** the max size allowed. */ long maxsize = 10000; /** the min size allowed. */ long minsize = 0; /** The error msg. */ private String errorMsg; /** The log. */ private Log log; /* * (non-Javadoc) * * @see org.apache.maven.enforcer.rule.api.EnforcerRule#execute(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper) */ public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException { this.log = helper.getLog(); // if the file is already defined, use that. Otherwise get the main artifact. if ( files.length == 0 ) { try { MavenProject project = (MavenProject) helper.evaluate( "${project}" ); files = new File[1]; files[0] = project.getArtifact().getFile(); super.execute( helper ); } catch ( ExpressionEvaluationException e ) { throw new EnforcerRuleException( "Unable to retrieve the project.", e ); } } else { super.execute( helper ); } } /* * (non-Javadoc) * * @see org.apache.maven.enforcer.rule.api.EnforcerRule#isCacheable() */ public boolean isCacheable() { return false; } /* * (non-Javadoc) * * @see org.apache.maven.enforcer.rule.api.EnforcerRule#isResultValid(org.apache.maven.enforcer.rule.api.EnforcerRule) */ public boolean isResultValid( EnforcerRule cachedRule ) { return false; } /* (non-Javadoc) * @see org.apache.maven.plugins.enforcer.AbstractRequireFiles#checkFile(java.io.File) */ boolean checkFile( File file ) { if (file == null) { //if we get here and it's null, treat it as a success. return true; } // check the file now if ( file.exists() ) { long length = file.length(); if ( length < minsize ) { this.errorMsg = ( file + " size (" + length + ") too small. Min. is " + minsize ); return false; } else if ( length > maxsize ) { this.errorMsg = ( file + " size (" + length + ") too large. Max. is " + maxsize ); return false; } else { this.log.debug( file + " size (" + length + ") is OK (" + ( minsize == maxsize || minsize == 0 ? ( "max. " + maxsize ) : ( "between " + minsize + " and " + maxsize ) ) + " byte)." ); return true; } } else { this.errorMsg = ( file + " does not exist!" ); return false; } } /* (non-Javadoc) * @see org.apache.maven.plugins.enforcer.AbstractRequireFiles#getErrorMsg() */ String getErrorMsg() { return this.errorMsg; } } RequireJavaVersion.java000066400000000000000000000075261205711263400347740ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.Arrays; import java.util.Iterator; import java.util.List; import org.apache.commons.lang.SystemUtils; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.apache.maven.plugin.logging.Log; import org.codehaus.plexus.util.StringUtils; /** * This rule checks that the Java version is allowed. * * @author Brian Fox * @version $Id: RequireJavaVersion.java 805190 2009-08-17 22:30:49Z hboutemy $ */ public class RequireJavaVersion extends AbstractVersionEnforcer { /* * (non-Javadoc) * * @see org.apache.maven.enforcer.rule.api.EnforcerRule#execute(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper) */ public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException { String java_version = SystemUtils.JAVA_VERSION_TRIMMED; Log log = helper.getLog(); log.debug( "Detected Java String: " + java_version ); java_version = normalizeJDKVersion( java_version ); log.debug( "Normalized Java String: " + java_version ); ArtifactVersion detectedJdkVersion = new DefaultArtifactVersion( java_version ); log.debug( "Parsed Version: Major: " + detectedJdkVersion.getMajorVersion() + " Minor: " + detectedJdkVersion.getMinorVersion() + " Incremental: " + detectedJdkVersion.getIncrementalVersion() + " Build: " + detectedJdkVersion.getBuildNumber() + " Qualifier: " + detectedJdkVersion.getQualifier() ); enforceVersion( helper.getLog(), "JDK", version, detectedJdkVersion ); } /** * Converts a jdk string from 1.5.0-11b12 to a single 3 digit version like 1.5.0-11 * * @param theJdkVersion to be converted. * @return the converted string. */ public static String normalizeJDKVersion( String theJdkVersion ) { theJdkVersion = theJdkVersion.replaceAll( "_|-", "." ); String tokenArray[] = StringUtils.split( theJdkVersion, "." ); List tokens = Arrays.asList( tokenArray ); StringBuffer buffer = new StringBuffer( theJdkVersion.length() ); Iterator iter = tokens.iterator(); for ( int i = 0; i < tokens.size() && i < 4; i++ ) { String section = (String) iter.next(); section = section.replaceAll( "[^0-9]", "" ); if ( StringUtils.isNotEmpty( section ) ) { buffer.append( Integer.parseInt( section ) ); if ( i != 2 ) { buffer.append( '.' ); } else { buffer.append( '-' ); } } } String version = buffer.toString(); version = StringUtils.stripEnd( version, "-" ); return StringUtils.stripEnd( version, "." ); } } RequireMavenVersion.java000066400000000000000000000043421205711263400351520ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.apache.maven.execution.RuntimeInformation; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; /** * This rule checks that the Maven version is allowed. * * @author Brian Fox * @version $Id: RequireMavenVersion.java 805190 2009-08-17 22:30:49Z hboutemy $ */ public class RequireMavenVersion extends AbstractVersionEnforcer { /* * (non-Javadoc) * * @see org.apache.maven.enforcer.rule.api.EnforcerRule#execute(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper) */ public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException { try { RuntimeInformation rti = (RuntimeInformation) helper.getComponent( RuntimeInformation.class ); ArtifactVersion detectedMavenVersion = rti.getApplicationVersion(); helper.getLog().debug( "Detected Maven Version: " + detectedMavenVersion ); enforceVersion( helper.getLog(), "Maven", this.version, detectedMavenVersion ); } catch ( ComponentLookupException e ) { // TODO Auto-generated catch block e.printStackTrace(); } } } RequireNoRepositories.java000066400000000000000000000163551205711263400355310ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.apache.maven.model.Model; import org.apache.maven.model.Repository; import org.apache.maven.plugins.enforcer.utils.EnforcerRuleUtils; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; /** * This rule checks that this pom or its parents don't define a repository. * * @author Brian Fox */ public class RequireNoRepositories extends AbstractNonCacheableEnforcerRule { /** * Whether to ban non-plugin repositories. By default they are banned. */ public boolean banRepositories = true; /** * Whether to ban plugin repositories. By default they are banned. */ public boolean banPluginRepositories = true; /** * Specify explicitly allowed non-plugin repositories. This is a list of ids. */ public List allowedRepositories = Collections.EMPTY_LIST; /** * Specify explicitly allowed plugin repositories. This is a list of ids. */ public List allowedPluginRepositories = Collections.EMPTY_LIST; /** * Whether to allow repositories which only resolve snapshots. By default they are banned. */ public boolean allowSnapshotRepositories = false; /** * Whether to allow plugin repositories which only resolve snapshots. By default they are banned. */ public boolean allowSnapshotPluginRepositories = false; /* * (non-Javadoc) * @see * org.apache.maven.enforcer.rule.api.EnforcerRule#execute(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper) */ public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException { EnforcerRuleUtils utils = new EnforcerRuleUtils( helper ); MavenProject project; try { project = (MavenProject) helper.evaluate( "${project}" ); List models = utils.getModelsRecursively( project.getGroupId(), project.getArtifactId(), project.getVersion(), new File( project.getBasedir(), "pom.xml" ) ); List badModels = new ArrayList(); StringBuffer newMsg = new StringBuffer(); newMsg.append( "Some poms have repositories defined:\n" ); for ( Iterator i = models.iterator(); i.hasNext(); ) { Model model = (Model) i.next(); if ( banRepositories ) { List repos = model.getRepositories(); if ( repos != null && !repos.isEmpty() ) { List bannedRepos = findBannedRepositories( repos, allowedRepositories, allowSnapshotRepositories ); if ( !bannedRepos.isEmpty() ) { badModels.add( model ); newMsg.append( model.getGroupId() + ":" + model.getArtifactId() + " version:" + model.getVersion() + " has repositories " + bannedRepos ); } } } if ( banPluginRepositories ) { List repos = model.getPluginRepositories(); if ( repos != null && !repos.isEmpty() ) { List bannedRepos = findBannedRepositories( repos, allowedPluginRepositories, allowSnapshotPluginRepositories ); if ( !bannedRepos.isEmpty() ) { badModels.add( model ); newMsg.append( model.getGroupId() + ":" + model.getArtifactId() + " version:" + model.getVersion() + " has plugin repositories " + bannedRepos ); } } } } // if anything was found, log it then append the // optional message. if ( !badModels.isEmpty() ) { if ( StringUtils.isNotEmpty( message ) ) { newMsg.append( message ); } throw new EnforcerRuleException( newMsg.toString() ); } } catch ( ExpressionEvaluationException e ) { throw new EnforcerRuleException( e.getLocalizedMessage() ); } catch ( ArtifactResolutionException e ) { throw new EnforcerRuleException( e.getLocalizedMessage() ); } catch ( ArtifactNotFoundException e ) { throw new EnforcerRuleException( e.getLocalizedMessage() ); } catch ( IOException e ) { throw new EnforcerRuleException( e.getLocalizedMessage() ); } catch ( XmlPullParserException e ) { throw new EnforcerRuleException( e.getLocalizedMessage() ); } } private static List findBannedRepositories( List repos, List allowedRepos, boolean allowSnapshots ) { List bannedRepos = new ArrayList( allowedRepos.size() ); for ( Iterator i = repos.iterator(); i.hasNext(); ) { Repository r = (Repository) i.next(); if ( !allowedRepos.contains( r.getId() ) ) { if ( !allowSnapshots || r.getReleases().isEnabled() ) { // if we are not allowing snapshots and this repo is enabled for releases // it is banned. We don't care whether it is enabled for snapshots // if you define a repo and don't enable it for anything, then we have nothing // to worry about bannedRepos.add( r.getId() ); } } } return bannedRepos; } } maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireOS.java000066400000000000000000000241011205711263400331310ustar00rootroot00000000000000package org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.Iterator; import org.apache.maven.enforcer.rule.api.EnforcerRule; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.apache.maven.model.Activation; import org.apache.maven.model.ActivationOS; import org.apache.maven.model.Profile; import org.apache.maven.plugin.logging.Log; import org.apache.maven.profiles.activation.OperatingSystemProfileActivator; import org.codehaus.plexus.util.Os; import org.codehaus.plexus.util.StringUtils; /** * This rule checks that the OS is allowed by combinations of family, name, version and cpu architecture. The behavior * is exactly the same as the Maven Os profile activation so the same values are allowed here. * * @author Brian Fox * @version $Id: RequireOS.java 805190 2009-08-17 22:30:49Z hboutemy $ */ public class RequireOS extends AbstractStandardEnforcerRule { /** * The OS family type desired
* Possible values: *
    *
  • dos
  • *
  • mac
  • *
  • netware
  • *
  • os/2
  • *
  • tandem
  • *
  • unix
  • *
  • windows
  • *
  • win9x
  • *
  • z/os
  • *
  • os/400
  • *
*/ public String family = null; /** The OS name desired. */ public String name = null; /** The OS version desired. */ public String version = null; /** The OS architecture desired. */ public String arch = null; /** Specify an optional message to the user if the rule fails. */ public String message = ""; /** Display detected OS information. */ public boolean display = false; /** * Instantiates a new RequireOS. */ public RequireOS() { } /* * (non-Javadoc) * * @see org.apache.maven.enforcer.rule.api.EnforcerRule#execute(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper) */ public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException { displayOSInfo( helper.getLog(), display ); if ( allParamsEmpty() ) { throw new EnforcerRuleException( "All parameters can not be empty. You must pick at least one of (family, name, version, arch) or use -Denforcer.os.display=true to see the current OS information." ); } if ( isValidFamily( this.family ) ) { if ( !isAllowed() ) { if ( StringUtils.isEmpty( message ) ) { message = ( "OS Arch: " + Os.OS_ARCH + " Family: " + Os.OS_FAMILY + " Name: " + Os.OS_NAME + " Version: " + Os.OS_VERSION + " is not allowed by" + ( arch != null ? " Arch=" + arch : "" ) + ( family != null ? " Family=" + family : "" ) + ( name != null ? " Name=" + name : "" ) + ( version != null ? " Version=" + version : "" ) ); } throw new EnforcerRuleException( message ); } } else { StringBuffer buffer = new StringBuffer( 50 ); Iterator iter = Os.getValidFamilies().iterator(); while ( iter.hasNext() ) { buffer.append( iter.next() ); buffer.append( ", " ); } String help = StringUtils.stripEnd( buffer.toString().trim(), "." ); throw new EnforcerRuleException( "Invalid Family type used. Valid family types are: " + help ); } } /** * Log the current OS information. * * @param log the log * @param info the info */ public void displayOSInfo( Log log, boolean info ) { String string = "OS Info: Arch: " + Os.OS_ARCH + " Family: " + Os.OS_FAMILY + " Name: " + Os.OS_NAME + " Version: " + Os.OS_VERSION; if ( !info ) { log.debug( string ); } else { log.info( string ); } } /** * Helper method to determine if the current OS is allowed based on the injected values for family, name, version * and arch. * * @return true if the version is allowed. */ public boolean isAllowed() { OperatingSystemProfileActivator activator = new OperatingSystemProfileActivator(); return activator.isActive( createProfile() ); } /** * Helper method to check that at least one of family, name, version or arch is set. * * @return true if all parameters are empty. */ public boolean allParamsEmpty() { return ( StringUtils.isEmpty( family ) && StringUtils.isEmpty( arch ) && StringUtils.isEmpty( name ) && StringUtils.isEmpty( version ) ); } /** * Creates a Profile object that contains the activation information. * * @return a properly populated profile to be used for OS validation. */ private Profile createProfile() { Profile profile = new Profile(); profile.setActivation( createActivation() ); return profile; } /** * Creates an Activation object that contains the ActivationOS information. * * @return a properly populated Activation object. */ private Activation createActivation() { Activation activation = new Activation(); activation.setActiveByDefault( false ); activation.setOs( createOsBean() ); return activation; } /** * Creates an ActivationOS object containing family, name, version and arch. * * @return a properly populated ActivationOS object. */ private ActivationOS createOsBean() { ActivationOS os = new ActivationOS(); os.setArch( arch ); os.setFamily( family ); os.setName( name ); os.setVersion( version ); return os; } /** * Helper method to check if the given family is in the following list: *
    *
  • dos
  • *
  • mac
  • *
  • netware
  • *
  • os/2
  • *
  • tandem
  • *
  • unix
  • *
  • windows
  • *
  • win9x
  • *
  • z/os
  • *
  • os/400
  • *
* Note: '!' is allowed at the beginning of the string and still considered valid. * * @param theFamily the family to check. * @return true if one of the valid families. */ public boolean isValidFamily( String theFamily ) { // in case they are checking !family theFamily = StringUtils.stripStart( theFamily, "!" ); return ( StringUtils.isEmpty( theFamily ) || Os.getValidFamilies().contains( theFamily ) ); } /** * Gets the arch. * * @return the arch */ public String getArch() { return this.arch; } /** * Sets the arch. * * @param theArch the arch to set */ public void setArch( String theArch ) { this.arch = theArch; } /** * Gets the family. * * @return the family */ public String getFamily() { return this.family; } /** * Sets the family. * * @param theFamily the family to set */ public void setFamily( String theFamily ) { this.family = theFamily; } /** * Gets the name. * * @return the name */ public String getName() { return this.name; } /** * Sets the name. * * @param theName the name to set */ public void setName( String theName ) { this.name = theName; } /** * Gets the version. * * @return the version */ public String getVersion() { return this.version; } /** * Sets the version. * * @param theVersion the version to set */ public void setVersion( String theVersion ) { this.version = theVersion; } /* * (non-Javadoc) * * @see org.apache.maven.enforcer.rule.api.EnforcerRule#getCacheId() */ public String getCacheId() { // return the hashcodes of all the parameters StringBuffer b = new StringBuffer(); if ( StringUtils.isNotEmpty( version ) ) { b.append( version.hashCode() ); } if ( StringUtils.isNotEmpty( name ) ) { b.append( name.hashCode() ); } if ( StringUtils.isNotEmpty( arch ) ) { b.append( arch.hashCode() ); } if ( StringUtils.isNotEmpty( family ) ) { b.append( family.hashCode() ); } return b.toString(); } /* * (non-Javadoc) * * @see org.apache.maven.enforcer.rule.api.EnforcerRule#isCacheable() */ public boolean isCacheable() { // the os is not going to change between projects in the same build. return true; } /* * (non-Javadoc) * * @see org.apache.maven.enforcer.rule.api.EnforcerRule#isResultValid(org.apache.maven.enforcer.rule.api.EnforcerRule) */ public boolean isResultValid( EnforcerRule theCachedRule ) { // i will always return the hash of the parameters as my id. If my parameters are the same, this // rule must always have the same result. return true; } } RequirePluginVersions.java000066400000000000000000001205711205711263400355300ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.Map.Entry; import org.apache.maven.BuildFailureException; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.apache.maven.execution.MavenSession; import org.apache.maven.lifecycle.Lifecycle; import org.apache.maven.lifecycle.LifecycleExecutionException; import org.apache.maven.lifecycle.LifecycleExecutor; import org.apache.maven.lifecycle.mapping.LifecycleMapping; import org.apache.maven.model.BuildBase; import org.apache.maven.model.Model; import org.apache.maven.model.Plugin; import org.apache.maven.model.Profile; import org.apache.maven.plugin.InvalidPluginException; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.PluginManager; import org.apache.maven.plugin.PluginManagerException; import org.apache.maven.plugin.PluginNotFoundException; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugin.version.PluginVersionNotFoundException; import org.apache.maven.plugin.version.PluginVersionResolutionException; import org.apache.maven.plugins.enforcer.utils.EnforcerRuleUtils; import org.apache.maven.plugins.enforcer.utils.PluginWrapper; import org.apache.maven.project.MavenProject; import org.apache.maven.settings.Settings; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.util.ReflectionUtils; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; /** * This rule will enforce that all plugins specified in the poms have a version declared. * * @author Brian Fox * @version $Id: RequirePluginVersions.java 1028144 2010-10-28 00:10:58Z brianf $ */ public class RequirePluginVersions extends AbstractNonCacheableEnforcerRule { /** Don't allow the LATEST identifier. */ public boolean banLatest = true; /** Don't allow the RELEASE identifier. */ public boolean banRelease = true; /** Don't allow snapshot plugins. */ public boolean banSnapshots = true; /** Don't allow timestamp snapshot plugins. */ public boolean banTimestamps = true; /** * The comma separated list of phases that should be used to find lifecycle plugin bindings. The default value is * "clean,deploy,site". */ 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.
* The plugins should be specified in the form: group:artifactId. */ public List additionalPlugins; /** * Plugins to skip for version enforcement. The plugins should be specified in the form: * group:artifactId. NOTE: This is deprecated, use unCheckedPluginList instead. * @deprecated */ public List unCheckedPlugins; /** * Same as unCheckedPlugins but as a comma list to better support properties. Sample form: * group:artifactId,group2:artifactId2 * @since 1.0-beta-1 */ public String unCheckedPluginList; /** The plugin manager. */ private PluginManager pluginManager; /** The phase to lifecycle map. */ private Map phaseToLifecycleMap; /** The lifecycles. */ private List lifecycles; /** The factory. */ ArtifactFactory factory; /** The resolver. */ ArtifactResolver resolver; /** The local. */ ArtifactRepository local; /** The remote repositories. */ List remoteRepositories; /** The log. */ Log log; /** The session. */ MavenSession session; /** The utils. */ EnforcerRuleUtils utils; /* * (non-Javadoc) * * @see org.apache.maven.enforcer.rule.api.EnforcerRule#execute(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper) */ public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException { log = helper.getLog(); MavenProject project; try { // get the various expressions out of the helper. project = (MavenProject) helper.evaluate( "${project}" ); LifecycleExecutor life; life = (LifecycleExecutor) helper.getComponent( LifecycleExecutor.class ); try { lifecycles = (List) ReflectionUtils.getValueIncludingSuperclasses( "lifecycles", life ); } catch (Exception e) { log.info( "The requirePluginVersions rule is currently not compatible with Maven3."); /* * * NOTE: If this happens, we're bailing out right away. * * */ return; } session = (MavenSession) helper.evaluate( "${session}" ); pluginManager = (PluginManager) helper.getComponent( PluginManager.class ); factory = (ArtifactFactory) helper.getComponent( ArtifactFactory.class ); resolver = (ArtifactResolver) helper.getComponent( ArtifactResolver.class ); local = (ArtifactRepository) helper.evaluate( "${localRepository}" ); remoteRepositories = project.getRemoteArtifactRepositories(); utils = new EnforcerRuleUtils( helper ); // get all the plugins that are bound to the specified lifecycles Set allPlugins = getBoundPlugins( life, project, phases ); // insert any additional plugins specified by the user. allPlugins = addAdditionalPlugins( allPlugins, additionalPlugins ); allPlugins.addAll( getProfilePlugins( project ) ); // pull out any we should skip allPlugins = (Set) removeUncheckedPlugins( combineUncheckedPlugins( unCheckedPlugins, unCheckedPluginList ), allPlugins ); // there's nothing to do here if ( allPlugins.isEmpty() ) { log.info( "No plugin bindings found." ); return; } else { log.debug( "All Plugins in use: " + allPlugins ); } // get all the plugins that are mentioned in the pom (and parents) List pluginWrappers = getAllPluginEntries( project ); // now look for the versions that aren't valid and add to a list. ArrayList failures = new ArrayList(); Iterator iter = allPlugins.iterator(); while ( iter.hasNext() ) { Plugin plugin = (Plugin) iter.next(); if ( !hasValidVersionSpecified( helper, plugin, pluginWrappers ) ) { failures.add( plugin ); } } // if anything was found, log it then append the optional message. if ( !failures.isEmpty() ) { StringBuffer newMsg = new StringBuffer(); newMsg.append( "Some plugins are missing valid versions:" ); if ( banLatest || banRelease || banSnapshots || banTimestamps ) { newMsg.append( "(" ); if ( banLatest ) { newMsg.append( "LATEST " ); } if ( banRelease ) { newMsg.append( "RELEASE " ); } if ( banSnapshots || banTimestamps ) { newMsg.append( "SNAPSHOT " ); } newMsg.append( "are not allowed )\n" ); } iter = failures.iterator(); while ( iter.hasNext() ) { Plugin plugin = (Plugin) iter.next(); newMsg.append( plugin.getGroupId() ); newMsg.append( ":" ); newMsg.append( plugin.getArtifactId() ); try { newMsg.append( ". \tThe version currently in use is " ); Plugin currentPlugin = findCurrentPlugin( plugin, project ); if ( currentPlugin != null ) { newMsg.append( currentPlugin.getVersion() ); } else { newMsg.append( "unknown" ); } } 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 ); newMsg.append( ". Unable to determine the plugin version." ); } newMsg.append( "\n" ); } if ( StringUtils.isNotEmpty( message ) ) { newMsg.append( message ); } throw new EnforcerRuleException( newMsg.toString() ); } } catch ( ExpressionEvaluationException e ) { throw new EnforcerRuleException( "Unable to Evaluate an Expression:" + e.getLocalizedMessage() ); } catch ( ComponentLookupException e ) { throw new EnforcerRuleException( "Unable to lookup a component:" + e.getLocalizedMessage() ); } catch ( IllegalAccessException e ) { throw new EnforcerRuleException( e.getLocalizedMessage() ); } catch ( LifecycleExecutionException e ) { throw new EnforcerRuleException( e.getLocalizedMessage() ); } catch ( PluginNotFoundException e ) { throw new EnforcerRuleException( e.getLocalizedMessage() ); } catch ( ArtifactResolutionException e ) { throw new EnforcerRuleException( e.getLocalizedMessage() ); } catch ( ArtifactNotFoundException e ) { throw new EnforcerRuleException( e.getLocalizedMessage() ); } catch ( IOException e ) { throw new EnforcerRuleException( e.getLocalizedMessage() ); } catch ( XmlPullParserException e ) { throw new EnforcerRuleException( e.getLocalizedMessage() ); } catch ( MojoExecutionException e ) { throw new EnforcerRuleException( e.getLocalizedMessage() ); } } /** * Remove the plugins that the user doesn't want to check. * * @param uncheckedPlugins * @param plugins * @return * @throws MojoExecutionException */ public Collection removeUncheckedPlugins( Collection uncheckedPlugins, Collection plugins ) throws MojoExecutionException { if ( uncheckedPlugins != null && !uncheckedPlugins.isEmpty() ) { Iterator iter = uncheckedPlugins.iterator(); while ( iter.hasNext() ) { Plugin plugin = parsePluginString( (String) iter.next(), "UncheckedPlugins" ); plugins.remove( plugin ); } } return plugins; } /** * Combines the old Collection with the new comma separated list. * @param uncheckedPlugins * @param uncheckedPluginsList * @return */ public Collection combineUncheckedPlugins( Collection uncheckedPlugins, String uncheckedPluginsList ) { //if the comma list is empty, then there's nothing to do here. if ( StringUtils.isNotEmpty( uncheckedPluginsList ) ) { //make sure there is a collection to add to. if ( uncheckedPlugins == null ) { uncheckedPlugins = new HashSet(); } else if (!uncheckedPlugins.isEmpty() && log != null) { log.warn( "The parameter 'unCheckedPlugins' is deprecated. Use 'unCheckedPluginList' instead" ); } uncheckedPlugins.addAll( Arrays.asList( uncheckedPluginsList.split( "," ) ) ); } return uncheckedPlugins; } /** * Add the additional plugins if they don't exist yet. * * @param existing the existing * @param additional the additional * @return the sets the * @throws MojoExecutionException the mojo execution exception */ public Set addAdditionalPlugins( Set existing, List additional ) throws MojoExecutionException { if ( additional != null ) { Iterator iter = additional.iterator(); while ( iter.hasNext() ) { String pluginString = (String) iter.next(); Plugin plugin = parsePluginString( pluginString, "AdditionalPlugins" ); if ( existing == null ) { existing = new HashSet(); existing.add( plugin ); } else if ( !existing.contains( plugin ) ) { existing.add( plugin ); } } } return existing; } /** * Helper method to parse and inject a Plugin. * * @param pluginString * @return * @throws MojoExecutionException */ protected Plugin parsePluginString( String pluginString, String field ) throws MojoExecutionException { if ( pluginString != null ) { String[] pluginStrings = pluginString.split( ":" ); if ( pluginStrings.length == 2 ) { Plugin plugin = new Plugin(); plugin.setGroupId( StringUtils.strip( pluginStrings[0] ) ); plugin.setArtifactId( StringUtils.strip( pluginStrings[1] ) ); return plugin; } else { throw new MojoExecutionException( "Invalid " + field + " string: " + pluginString ); } } else { throw new MojoExecutionException( "Invalid " + field + " string: " + pluginString ); } } /** * Finds the plugins that are listed in active profiles. * * @param project the project * @return the profile plugins */ public Set getProfilePlugins( MavenProject project ) { Set result = new HashSet(); List profiles = project.getActiveProfiles(); if ( profiles != null && !profiles.isEmpty() ) { Iterator iter = profiles.iterator(); while ( iter.hasNext() ) { Profile p = (Profile) iter.next(); BuildBase b = p.getBuild(); if ( b != null ) { List plugins = b.getPlugins(); if ( plugins != null ) { result.addAll( plugins ); } } } } return result; } /** * Given a plugin, this will retrieve the matching plugin artifact from the model. * * @param plugin plugin to lookup * @param project project to search * @return matching plugin, null if not found. */ protected Plugin findCurrentPlugin( Plugin plugin, MavenProject project ) { Plugin found = null; try { Model model = project.getModel(); Map plugins = model.getBuild().getPluginsAsMap(); found = (Plugin) plugins.get( plugin.getKey() ); } catch ( NullPointerException e ) { // nothing to do here } if ( found == null ) { found = resolvePlugin( plugin, project ); } return found; } /** * Resolve plugin. * * @param plugin the plugin * @param project the project * @return the plugin */ protected Plugin resolvePlugin( Plugin plugin, MavenProject project ) { List pluginRepositories = project.getPluginArtifactRepositories(); Artifact artifact = factory.createPluginArtifact( plugin.getGroupId(), plugin.getArtifactId(), VersionRange.createFromVersion( "LATEST" ) ); try { this.resolver.resolve( artifact, pluginRepositories, this.local ); plugin.setVersion( artifact.getVersion() ); } catch ( ArtifactResolutionException e ) { } catch ( ArtifactNotFoundException e ) { } return plugin; } /** * Gets the plugins that are bound to the defined phases. This does not find plugins bound in the pom to a phase * later than the plugin is executing. * * @param life the life * @param project the project * @param thePhases the the phases * @return the bound plugins * @throws PluginNotFoundException the plugin not found exception * @throws LifecycleExecutionException the lifecycle execution exception * @throws IllegalAccessException the illegal access exception */ protected Set getBoundPlugins( LifecycleExecutor life, MavenProject project, String thePhases ) throws PluginNotFoundException, LifecycleExecutionException, IllegalAccessException { Set allPlugins = new HashSet(); // lookup the bindings for all the passed in phases String[] lifecyclePhases = thePhases.split( "," ); for ( int i = 0; i < lifecyclePhases.length; i++ ) { String lifecyclePhase = lifecyclePhases[i]; if ( StringUtils.isNotEmpty( lifecyclePhase ) ) { try { Lifecycle lifecycle = getLifecycleForPhase( lifecyclePhase ); allPlugins.addAll( getAllPlugins( project, lifecycle ) ); } catch ( BuildFailureException e ) { // i'm going to swallow this because the // user may have declared a phase that // doesn't exist for every module. } } } return allPlugins; } /* * Checks to see if the version is specified for the plugin. Can optionally ban "RELEASE" or "LATEST" even if * specified. */ /** * Checks for valid version specified. * * @param helper the helper * @param source the source * @param pluginWrappers the plugins * @return true, if successful */ protected boolean hasValidVersionSpecified( EnforcerRuleHelper helper, Plugin source, List pluginWrappers ) { boolean found = false; boolean status = false; Iterator iter = pluginWrappers.iterator(); while ( iter.hasNext() ) { // find the matching plugin entry PluginWrapper plugin = (PluginWrapper) iter.next(); if ( source.getArtifactId().equals( plugin.getArtifactId() ) && source.getGroupId().equals( plugin.getGroupId() ) ) { found = true; // found the entry. now see if the version is specified String version = plugin.getVersion(); try { version = (String) helper.evaluate( version ); } catch ( ExpressionEvaluationException e ) { return false; } if ( StringUtils.isNotEmpty( version ) && !StringUtils.isWhitespace( version ) ) { if ( banRelease && version.equals( "RELEASE" ) ) { return false; } if ( banLatest && version.equals( "LATEST" ) ) { return false; } if ( banSnapshots && isSnapshot( version ) ) { return false; } // the version was specified and not // banned. It's ok. Keep looking through the list to make // sure it's not using a banned version somewhere else. status = true; if ( !banRelease && !banLatest && !banSnapshots ) { // no need to keep looking break; } } } } if ( !found ) { log.debug( "plugin " + source.getGroupId() + ":" + source.getArtifactId() + " not found" ); } return status; } /** * Checks if is snapshot. * * @param baseVersion the base version * @return true, if is snapshot */ protected boolean isSnapshot( String baseVersion ) { if ( banTimestamps ) { return Artifact.VERSION_FILE_PATTERN.matcher( baseVersion ).matches() || baseVersion.endsWith( Artifact.SNAPSHOT_VERSION ); } else { return baseVersion.endsWith( Artifact.SNAPSHOT_VERSION ); } } /* * Uses borrowed lifecycle code to get a list of all plugins bound to the lifecycle. */ /** * Gets the all plugins. * * @param project the project * @param lifecycle the lifecycle * @return the all plugins * @throws PluginNotFoundException the plugin not found exception * @throws LifecycleExecutionException the lifecycle execution exception */ private Set getAllPlugins( MavenProject project, Lifecycle lifecycle ) throws PluginNotFoundException, LifecycleExecutionException { HashSet plugins = new HashSet(); // first, bind those associated with the packaging Map mappings = findMappingsForLifecycle( project, lifecycle ); Iterator iter = mappings.entrySet().iterator(); while ( iter.hasNext() ) { Entry entry = (Entry) iter.next(); String value = (String) entry.getValue(); String tokens[] = value.split( ":" ); Plugin plugin = new Plugin(); plugin.setGroupId( tokens[0] ); plugin.setArtifactId( tokens[1] ); plugins.add( plugin ); } List mojos = findOptionalMojosForLifecycle( project, lifecycle ); iter = mojos.iterator(); while ( iter.hasNext() ) { String value = (String) iter.next(); String tokens[] = value.split( ":" ); Plugin plugin = new Plugin(); plugin.setGroupId( tokens[0] ); plugin.setArtifactId( tokens[1] ); plugins.add( plugin ); } for ( Iterator i = project.getBuildPlugins().iterator(); i.hasNext(); ) { plugins.add( i.next() ); } return plugins; } /* * NOTE: All the code following this point was scooped from the DefaultLifecycleExecutor. There must be a better way * but for now it should work. */ /** * Gets the phase to lifecycle map. * * @return the phase to lifecycle map * @throws LifecycleExecutionException the lifecycle execution exception */ public Map getPhaseToLifecycleMap() throws LifecycleExecutionException { if ( phaseToLifecycleMap == null ) { phaseToLifecycleMap = new HashMap(); for ( Iterator i = lifecycles.iterator(); i.hasNext(); ) { Lifecycle lifecycle = (Lifecycle) i.next(); for ( Iterator p = lifecycle.getPhases().iterator(); p.hasNext(); ) { String phase = (String) p.next(); if ( phaseToLifecycleMap.containsKey( phase ) ) { Lifecycle prevLifecycle = (Lifecycle) phaseToLifecycleMap.get( phase ); throw new LifecycleExecutionException( "Phase '" + phase + "' is defined in more than one lifecycle: '" + lifecycle.getId() + "' and '" + prevLifecycle.getId() + "'" ); } else { phaseToLifecycleMap.put( phase, lifecycle ); } } } } return phaseToLifecycleMap; } /** * Gets the lifecycle for phase. * * @param phase the phase * @return the lifecycle for phase * @throws BuildFailureException the build failure exception * @throws LifecycleExecutionException the lifecycle execution exception */ private Lifecycle getLifecycleForPhase( String phase ) throws BuildFailureException, LifecycleExecutionException { Lifecycle lifecycle = (Lifecycle) getPhaseToLifecycleMap().get( phase ); if ( lifecycle == null ) { throw new BuildFailureException( "Unable to find lifecycle for phase '" + phase + "'" ); } return lifecycle; } /** * Find mappings for lifecycle. * * @param project the project * @param lifecycle the lifecycle * @return the map * @throws LifecycleExecutionException the lifecycle execution exception * @throws PluginNotFoundException the plugin not found exception */ private Map findMappingsForLifecycle( MavenProject project, Lifecycle lifecycle ) throws LifecycleExecutionException, PluginNotFoundException { String packaging = project.getPackaging(); Map mappings = null; LifecycleMapping m = (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging, session.getSettings(), session.getLocalRepository() ); if ( m != null ) { mappings = m.getPhases( lifecycle.getId() ); } Map defaultMappings = lifecycle.getDefaultPhases(); if ( mappings == null ) { try { m = (LifecycleMapping) session.lookup( LifecycleMapping.ROLE, packaging ); mappings = m.getPhases( lifecycle.getId() ); } catch ( ComponentLookupException e ) { if ( defaultMappings == null ) { throw new LifecycleExecutionException( "Cannot find lifecycle mapping for packaging: \'" + packaging + "\'.", e ); } } } if ( mappings == null ) { if ( defaultMappings == null ) { throw new LifecycleExecutionException( "Cannot find lifecycle mapping for packaging: \'" + packaging + "\', and there is no default" ); } else { mappings = defaultMappings; } } return mappings; } /** * Find optional mojos for lifecycle. * * @param project the project * @param lifecycle the lifecycle * @return the list * @throws LifecycleExecutionException the lifecycle execution exception * @throws PluginNotFoundException the plugin not found exception */ private List findOptionalMojosForLifecycle( MavenProject project, Lifecycle lifecycle ) throws LifecycleExecutionException, PluginNotFoundException { String packaging = project.getPackaging(); List optionalMojos = null; LifecycleMapping m = (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging, session.getSettings(), session.getLocalRepository() ); if ( m != null ) { optionalMojos = m.getOptionalMojos( lifecycle.getId() ); } if ( optionalMojos == null ) { try { m = (LifecycleMapping) session.lookup( LifecycleMapping.ROLE, packaging ); optionalMojos = m.getOptionalMojos( lifecycle.getId() ); } catch ( ComponentLookupException e ) { log.debug( "Error looking up lifecycle mapping to retrieve optional mojos. Lifecycle ID: " + lifecycle.getId() + ". Error: " + e.getMessage(), e ); } } if ( optionalMojos == null ) { optionalMojos = Collections.EMPTY_LIST; } return optionalMojos; } /** * Find extension. * * @param project the project * @param role the role * @param roleHint the role hint * @param settings the settings * @param localRepository the local repository * @return the object * @throws LifecycleExecutionException the lifecycle execution exception * @throws PluginNotFoundException the plugin not found exception */ private Object findExtension( MavenProject project, String role, String roleHint, Settings settings, ArtifactRepository localRepository ) throws LifecycleExecutionException, PluginNotFoundException { Object pluginComponent = null; for ( Iterator i = project.getBuildPlugins().iterator(); i.hasNext() && pluginComponent == null; ) { Plugin plugin = (Plugin) i.next(); if ( plugin.isExtensions() ) { verifyPlugin( plugin, project, settings, localRepository ); // TODO: if moved to the plugin manager we // already have the descriptor from above // and so do can lookup the container // directly try { pluginComponent = pluginManager.getPluginComponent( plugin, role, roleHint ); } catch ( ComponentLookupException e ) { log.debug( "Unable to find the lifecycle component in the extension", e ); } catch ( PluginManagerException e ) { throw new LifecycleExecutionException( "Error getting extensions from the plugin '" + plugin.getKey() + "': " + e.getMessage(), e ); } } } return pluginComponent; } /** * Verify plugin. * * @param plugin the plugin * @param project the project * @param settings the settings * @param localRepository the local repository * @return the plugin descriptor * @throws LifecycleExecutionException the lifecycle execution exception * @throws PluginNotFoundException the plugin not found exception */ private PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings, ArtifactRepository localRepository ) throws LifecycleExecutionException, PluginNotFoundException { PluginDescriptor pluginDescriptor; try { pluginDescriptor = pluginManager.verifyPlugin( plugin, project, settings, localRepository ); } catch ( PluginManagerException e ) { throw new LifecycleExecutionException( "Internal error in the plugin manager getting plugin '" + plugin.getKey() + "': " + e.getMessage(), e ); } catch ( PluginVersionResolutionException e ) { throw new LifecycleExecutionException( e.getMessage(), e ); } catch ( InvalidVersionSpecificationException e ) { throw new LifecycleExecutionException( e.getMessage(), e ); } catch ( InvalidPluginException e ) { throw new LifecycleExecutionException( e.getMessage(), e ); } catch ( ArtifactNotFoundException e ) { throw new LifecycleExecutionException( e.getMessage(), e ); } catch ( ArtifactResolutionException e ) { throw new LifecycleExecutionException( e.getMessage(), e ); } catch ( PluginVersionNotFoundException e ) { throw new LifecycleExecutionException( e.getMessage(), e ); } return pluginDescriptor; } /** * Gets all plugin entries in build.plugins, build.pluginManagement.plugins, profile.build.plugins, reporting and * profile.reporting in this project and all parents * * @param project the project * @return the all plugin entries wrapped in a PluginWrapper Object * @throws ArtifactResolutionException the artifact resolution exception * @throws ArtifactNotFoundException the artifact not found exception * @throws IOException Signals that an I/O exception has occurred. * @throws XmlPullParserException the xml pull parser exception */ protected List getAllPluginEntries( MavenProject project ) throws ArtifactResolutionException, ArtifactNotFoundException, IOException, XmlPullParserException { List plugins = new ArrayList(); // get all the pom models String pomName = null; try { pomName = project.getFile().getName(); } catch (Exception e) { pomName = "pom.xml"; } List models = utils.getModelsRecursively( project.getGroupId(), project.getArtifactId(), project.getVersion(), new File( project.getBasedir(), pomName ) ); // now find all the plugin entries, either in // build.plugins or build.pluginManagement.plugins, profiles.plugins and reporting Iterator iter = models.iterator(); while ( iter.hasNext() ) { Model model = (Model) iter.next(); try { plugins.addAll( PluginWrapper.addAll( model.getBuild().getPlugins(), model.getId() + ".build.plugins" ) ); } catch ( NullPointerException e ) { // guess there are no plugins here. } try { // add the reporting plugins plugins.addAll( PluginWrapper.addAll( model.getReporting().getPlugins(), model.getId() + ".reporting" ) ); } catch ( NullPointerException e ) { // guess there are no plugins here. } try { plugins.addAll( PluginWrapper.addAll( model.getBuild().getPluginManagement().getPlugins(), model.getId() + ".build.pluginManagement.plugins" ) ); } catch ( NullPointerException e ) { // guess there are no plugins here. } // Add plugins in profiles Iterator it = model.getProfiles().iterator(); while ( it.hasNext() ) { Profile profile = (Profile) it.next(); try { plugins.addAll( PluginWrapper.addAll( profile.getBuild().getPlugins(), model.getId() + ".profiles.profile[" + profile.getId() + "].build.plugins" ) ); } catch ( NullPointerException e ) { // guess there are no plugins here. } try { // add the reporting plugins plugins.addAll( PluginWrapper.addAll( profile.getReporting().getPlugins(), model.getId() + "profile[" + profile.getId() + "].reporting.plugins" ) ); } catch ( NullPointerException e ) { // guess there are no plugins here. } try { // add the reporting plugins plugins.addAll( PluginWrapper.addAll( profile.getBuild().getPluginManagement().getPlugins(), model.getId() + "profile[" + profile.getId() + "].build.pluginManagement.plugins" ) ); } catch ( NullPointerException e ) { // guess there are no plugins here. } } } return plugins; } /** * Checks if is ban latest. * * @return the banLatest */ protected boolean isBanLatest() { return this.banLatest; } /** * Sets the ban latest. * * @param theBanLatest the banLatest to set */ protected void setBanLatest( boolean theBanLatest ) { this.banLatest = theBanLatest; } /** * Checks if is ban release. * * @return the banRelease */ protected boolean isBanRelease() { return this.banRelease; } /** * Sets the ban release. * * @param theBanRelease the banRelease to set */ protected void setBanRelease( boolean theBanRelease ) { this.banRelease = theBanRelease; } /** * Gets the message. * * @return the message */ protected String getMessage() { return this.message; } /** * Sets the message. * * @param theMessage the message to set */ protected void setMessage( String theMessage ) { this.message = theMessage; } /** * Gets the utils. * * @return the utils */ protected EnforcerRuleUtils getUtils() { return this.utils; } /** * Sets the utils. * * @param theUtils the utils to set */ protected void setUtils( EnforcerRuleUtils theUtils ) { this.utils = theUtils; } /** * Checks if is ban snapshots. * * @return the banSnapshots */ public boolean isBanSnapshots() { return this.banSnapshots; } /** * Sets the ban snapshots. * * @param theBanSnapshots the banSnapshots to set */ public void setBanSnapshots( boolean theBanSnapshots ) { this.banSnapshots = theBanSnapshots; } /** * Checks if is ban timestamps. * * @return the banTimestamps */ public boolean isBanTimestamps() { return this.banTimestamps; } /** * Sets the ban timestamps. * * @param theBanTimestamps the banTimestamps to set */ public void setBanTimestamps( boolean theBanTimestamps ) { this.banTimestamps = theBanTimestamps; } public List getUnCheckedPlugins() { return unCheckedPlugins; } public void setUnCheckedPlugins( List unCheckedPlugins ) { this.unCheckedPlugins = unCheckedPlugins; } }RequireProperty.java000066400000000000000000000056051205711263400343650ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; /** * This rule checks that certain properties are set. * * @author Paul Gier */ public class RequireProperty extends AbstractNonCacheableEnforcerRule { /** Specify the required property. */ public String property = null; /** Match the property value to a given regular expression. Defaults to null (any value is ok). */ public String regex = null; /** Specify a warning message if the regular expression is not matched. */ public String regexMessage = null; /** * Execute the rule. * * @param helper the helper * @throws EnforcerRuleException the enforcer rule exception */ public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException { Object propValue = null; try { propValue = helper.evaluate( "${" + property + "}" ); } catch ( ExpressionEvaluationException eee ) { throw new EnforcerRuleException( "Unable to evaluate property: " + property, eee ); } // Check that the property is not null or empty string if ( propValue == null ) { if ( message == null ) { message = "Property \"" + property + "\" is required for this build."; } throw new EnforcerRuleException( message ); } // If there is a regex, check that the property matches it if ( regex != null && !propValue.toString().matches( regex ) ) { if ( regexMessage == null ) { regexMessage = "Property \"" + property + "\" evaluates to \"" + propValue + "\". " + "This does not match the regular expression \"" + regex + "\""; } throw new EnforcerRuleException( regexMessage ); } } } RequireReleaseDeps.java000066400000000000000000000147631205711263400347420ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.resolver.filter.AndArtifactFilter; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; import org.apache.maven.shared.artifact.filter.StrictPatternExcludesArtifactFilter; import org.apache.maven.shared.artifact.filter.StrictPatternIncludesArtifactFilter; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; /** * This rule checks that no snapshots are included. * * @author Brian Fox * @version $Id: RequireReleaseDeps.java 989820 2010-08-26 16:52:46Z pgier $ */ public class RequireReleaseDeps extends AbstractBanDependencies { /** * Allows this rule to execute only when this project is a release. * * @parameter */ public boolean onlyWhenRelease = false; /** * Allows this rule to fail when the parent is defined as a snapshot. * * @parameter */ public boolean failWhenParentIsSnapshot = true; /** * Dependencies to ignore when checking for release versions. For example, inter-module dependencies * can be excluded from the check and therefore allowed to contain snapshot versions. */ public List excludes = null; /** * Dependencies to include when checking for release versions. If any of the included dependencies * have snapshot versions, the rule will fail. */ public List includes = null; /** * Override parent to allow optional ignore of this rule. */ public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException { boolean callSuper; MavenProject project = null; if ( onlyWhenRelease ) { // get the project project = getProject( helper ); // only call super if this project is a release callSuper = !project.getArtifact().isSnapshot(); } else { callSuper = true; } if ( callSuper ) { super.execute( helper ); if ( failWhenParentIsSnapshot ) { if ( project == null ) { project = getProject( helper ); } Artifact parentArtifact = project.getParentArtifact(); if ( parentArtifact != null && parentArtifact.isSnapshot() ) { throw new EnforcerRuleException( "Parent Cannot be a snapshot: " + parentArtifact.getId() ); } } } } /** * @param helper * @return * @throws EnforcerRuleException */ private MavenProject getProject( EnforcerRuleHelper helper ) throws EnforcerRuleException { try { return (MavenProject) helper.evaluate( "${project}" ); } catch ( ExpressionEvaluationException eee ) { throw new EnforcerRuleException( "Unable to retrieve the MavenProject: ", eee ); } } /** * Checks the set of dependencies to see if any snapshots are included * * @param dependencies the dependencies * @param log the log * @return the sets the * @throws EnforcerRuleException the enforcer rule exception */ protected Set checkDependencies( Set dependencies, Log log ) throws EnforcerRuleException { Set foundSnapshots = new HashSet(); Set filteredDependencies = this.filterArtifacts( dependencies ); Iterator DependencyIter = filteredDependencies.iterator(); while ( DependencyIter.hasNext() ) { Artifact artifact = (Artifact) DependencyIter.next(); if ( artifact.isSnapshot() ) { foundSnapshots.add( artifact ); } } return foundSnapshots; } /* * Filter the dependency artifacts according to the includes and excludes * If includes and excludes are both null, the original set is returned. * * @param dependencies the list of dependencies to filter * @return the resulting set of dependencies */ public Set filterArtifacts( Set dependencies ) { if ( includes == null && excludes == null ) { return dependencies; } AndArtifactFilter filter = new AndArtifactFilter( ); if ( includes != null ) { filter.add( new StrictPatternIncludesArtifactFilter( includes ) ); } if ( excludes != null ) { filter.add( new StrictPatternExcludesArtifactFilter( excludes ) ); } Set result = new HashSet(); Iterator iter = dependencies.iterator(); while ( iter.hasNext() ) { Artifact artifact = (Artifact) iter.next(); if ( filter.include( artifact ) ) { result.add( artifact ); } } return result; } public boolean isOnlyWhenRelease() { return onlyWhenRelease; } public void setOnlyWhenRelease( boolean onlyWhenRelease ) { this.onlyWhenRelease = onlyWhenRelease; } public boolean isFailWhenParentIsSnapshot() { return failWhenParentIsSnapshot; } public void setFailWhenParentIsSnapshot( boolean failWhenParentIsSnapshot ) { this.failWhenParentIsSnapshot = failWhenParentIsSnapshot; } } RequireReleaseVersion.java000066400000000000000000000064061205711263400354670ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.artifact.Artifact; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; /** * This rule checks that the current project is not a snapshot. * * @author Brian Fox */ public class RequireReleaseVersion extends AbstractNonCacheableEnforcerRule { /** * Allows this rule to fail when the parent is defined as a snapshot. * * @parameter */ public boolean failWhenParentIsSnapshot = true; /* * (non-Javadoc) * * @see org.apache.maven.enforcer.rule.api.EnforcerRule#execute(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper) */ public void execute( EnforcerRuleHelper theHelper ) throws EnforcerRuleException { MavenProject project = getProject( theHelper ); if ( project.getArtifact().isSnapshot() ) { StringBuffer buf = new StringBuffer(); if ( message != null ) { buf.append( message + "\n" ); } buf.append( "This project cannot be a snapshot:" + project.getArtifact().getId() ); throw new EnforcerRuleException( buf.toString() ); } if ( failWhenParentIsSnapshot ) { Artifact parentArtifact = project.getParentArtifact(); if ( parentArtifact != null && parentArtifact.isSnapshot() ) { throw new EnforcerRuleException( "Parent Cannot be a snapshot: " + parentArtifact.getId() ); } } } /** * @param helper * @return * @throws EnforcerRuleException */ private MavenProject getProject( EnforcerRuleHelper helper ) throws EnforcerRuleException { try { return (MavenProject) helper.evaluate( "${project}" ); } catch ( ExpressionEvaluationException eee ) { throw new EnforcerRuleException( "Unable to retrieve the MavenProject: ", eee ); } } public boolean isFailWhenParentIsSnapshot() { return failWhenParentIsSnapshot; } public void setFailWhenParentIsSnapshot( boolean failWhenParentIsSnapshot ) { this.failWhenParentIsSnapshot = failWhenParentIsSnapshot; } } maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/000077500000000000000000000000001205711263400315525ustar00rootroot00000000000000DependencyVersionMap.java000066400000000000000000000071231205711263400364230ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utilspackage org.apache.maven.plugins.enforcer.utils; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.logging.Log; import org.apache.maven.shared.dependency.tree.DependencyNode; import org.apache.maven.shared.dependency.tree.traversal.DependencyNodeVisitor; public class DependencyVersionMap implements DependencyNodeVisitor { private boolean demandReleasedVersions = false; private Map> idsToNode; private List snapshots; public DependencyVersionMap(Log log){ idsToNode = new HashMap>(); snapshots = new ArrayList(); } public DependencyVersionMap(boolean demandReleasedVersions, Log log){ this(log); this.demandReleasedVersions = demandReleasedVersions; } public boolean visit(DependencyNode node) { addDependency(node); if (containsConflicts(node)){ return false; } if (demandReleasedVersions){ if (node.getArtifact().isSnapshot()){ snapshots.add(node); return false; } } return true; } public boolean endVisit(DependencyNode node) { return true; } private String constructKey(DependencyNode node){ return constructKey(node.getArtifact()); } private String constructKey(Artifact artifact){ return artifact.getGroupId()+":"+artifact.getArtifactId(); } public void addDependency(DependencyNode node) { String key = constructKey(node); if (node.getArtifact().isSnapshot()){ snapshots.add(node); } List nodes = idsToNode.get(key); if (nodes == null){ nodes = new ArrayList(); idsToNode.put(key,nodes); } nodes.add(node); } public List getSnapshots(){ return snapshots; } private boolean containsConflicts(DependencyNode node){ return containsConflicts(node.getArtifact()); } private boolean containsConflicts(Artifact artifact){ return containsConflicts(idsToNode.get(constructKey(artifact))); } private boolean containsConflicts(List nodes){ String version = null; for (DependencyNode node : nodes){ if (version == null){ version = node.getArtifact().getVersion(); } else { if (version.compareTo(node.getArtifact().getVersion()) != 0){ return true; } } } return false; } public List> getConflictedVersionNumbers(){ List> output = new ArrayList>(); for (List nodes : idsToNode.values()) { if(containsConflicts(nodes)){ output.add(nodes); } } return output; } } EnforcerRuleUtils.java000066400000000000000000000251311205711263400357540ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utilspackage org.apache.maven.plugins.enforcer.utils; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.File; import java.io.IOException; import java.io.Reader; import java.util.ArrayList; import java.util.List; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.apache.maven.model.Model; import org.apache.maven.model.Parent; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; // TODO: Auto-generated Javadoc /** * The Class EnforcerRuleUtils. * * @author Brian Fox */ public class EnforcerRuleUtils { /** The factory. */ ArtifactFactory factory; /** The resolver. */ ArtifactResolver resolver; /** The local. */ ArtifactRepository local; /** The remote repositories. */ List remoteRepositories; /** The log. */ Log log; /** The project. */ MavenProject project; private EnforcerRuleHelper helper; /** * Instantiates a new enforcer rule utils. * * @param theFactory the the factory * @param theResolver the the resolver * @param theLocal the the local * @param theRemoteRepositories the the remote repositories * @param project the project * @param theLog the the log */ public EnforcerRuleUtils( ArtifactFactory theFactory, ArtifactResolver theResolver, ArtifactRepository theLocal, List theRemoteRepositories, MavenProject project, Log theLog ) { super(); this.factory = theFactory; this.resolver = theResolver; this.local = theLocal; this.remoteRepositories = theRemoteRepositories; this.log = theLog; this.project = project; } /** * Instantiates a new enforcer rule utils. * * @param helper the helper */ public EnforcerRuleUtils( EnforcerRuleHelper helper ) { this.helper = helper; // get the various expressions out of the // helper. try { factory = (ArtifactFactory) helper.getComponent( ArtifactFactory.class ); resolver = (ArtifactResolver) helper.getComponent( ArtifactResolver.class ); local = (ArtifactRepository) helper.evaluate( "${localRepository}" ); project = (MavenProject) helper.evaluate( "${project}" ); remoteRepositories = project.getRemoteArtifactRepositories(); } catch ( ComponentLookupException e ) { // TODO Auto-generated catch block e.printStackTrace(); } catch ( ExpressionEvaluationException e ) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * Gets the pom model for this file. * * @param pom the pom * * @return the model * * @throws IOException Signals that an I/O exception has occurred. * @throws XmlPullParserException the xml pull parser exception */ private Model readModel ( File pom ) throws IOException, XmlPullParserException { Reader reader = ReaderFactory.newXmlReader( pom ); MavenXpp3Reader xpp3 = new MavenXpp3Reader(); Model model = null; try { model = xpp3.read( reader ); } finally { reader.close(); reader = null; } return model; } /** * This method gets the model for the defined artifact. * Looks first in the filesystem, then tries to get it * from the repo. * * @param groupId the group id * @param artifactId the artifact id * @param version the version * @param pom the pom * * @return the pom model * * @throws ArtifactResolutionException the artifact resolution exception * @throws ArtifactNotFoundException the artifact not found exception * @throws XmlPullParserException the xml pull parser exception * @throws IOException Signals that an I/O exception has occurred. */ private Model getPomModel ( String groupId, String artifactId, String version, File pom ) throws ArtifactResolutionException, ArtifactNotFoundException, IOException, XmlPullParserException { Model model = null; // do we want to look in the reactor like the // project builder? Would require @aggregator goal // which causes problems in maven core right now // because we also need dependency resolution in // other // rules. (MNG-2277) // look in the location specified by pom first. boolean found = false; try { model = readModel( pom ); // i found a model, lets make sure it's the one // I want found = checkIfModelMatches( groupId, artifactId, version, model ); } catch ( IOException e ) { // nothing here, but lets look in the repo // before giving up. } catch ( XmlPullParserException e ) { // nothing here, but lets look in the repo // before giving up. } // i didn't find it in the local file system, go // look in the repo if ( !found ) { Artifact pomArtifact = factory.createArtifact( groupId, artifactId, version, null, "pom" ); resolver.resolve( pomArtifact, remoteRepositories, local ); model = readModel( pomArtifact.getFile() ); } return model; } /** * This method loops through all the parents, getting * each pom model and then its parent. * * @param groupId the group id * @param artifactId the artifact id * @param version the version * @param pom the pom * * @return the models recursively * * @throws ArtifactResolutionException the artifact resolution exception * @throws ArtifactNotFoundException the artifact not found exception * @throws IOException Signals that an I/O exception has occurred. * @throws XmlPullParserException the xml pull parser exception */ public List getModelsRecursively ( String groupId, String artifactId, String version, File pom ) throws ArtifactResolutionException, ArtifactNotFoundException, IOException, XmlPullParserException { List models = null; Model model = getPomModel( groupId, artifactId, version, pom ); Parent parent = model.getParent(); // recurse into the parent if ( parent != null ) { // get the relative path String relativePath = parent.getRelativePath(); if ( StringUtils.isEmpty( relativePath ) ) { relativePath = "../pom.xml"; } // calculate the recursive path File parentPom = new File( pom.getParent(), relativePath ); // if relative path is a directory, append pom.xml if ( parentPom.isDirectory() ) { parentPom = new File( parentPom, "pom.xml" ); } models = getModelsRecursively( parent.getGroupId(), parent.getArtifactId(), parent.getVersion(), parentPom ); } else { // only create it here since I'm not at the top models = new ArrayList(); } models.add( model ); return models; } /** * Make sure the model is the one I'm expecting. * * @param groupId the group id * @param artifactId the artifact id * @param version the version * @param model Model being checked. * * @return true, if check if model matches */ protected boolean checkIfModelMatches ( String groupId, String artifactId, String version, Model model ) { // try these first. String modelGroup = model.getGroupId(); String modelVersion = model.getVersion(); try { if ( StringUtils.isEmpty( modelGroup ) ) { modelGroup = model.getParent().getGroupId(); } else { //MENFORCER-30, handle cases where the value is a property like ${project.parent.groupId} modelGroup = (String) helper.evaluate( modelGroup ); } if ( StringUtils.isEmpty( modelVersion ) ) { modelVersion = model.getParent().getVersion(); } else { //MENFORCER-30, handle cases where the value is a property like ${project.parent.version} modelVersion = (String) helper.evaluate( modelVersion ); } } catch ( NullPointerException e ) { // this is probably bad. I don't have a valid // group or version and I can't find a // parent???? // lets see if it's what we're looking for // anyway. } catch ( ExpressionEvaluationException e ) { // as above } return ( StringUtils.equals( groupId, modelGroup ) && StringUtils.equals( version, modelVersion ) && StringUtils .equals( artifactId, model.getArtifactId() ) ); } } PluginWrapper.java000066400000000000000000000060031205711263400351340ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utilspackage org.apache.maven.plugins.enforcer.utils; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.apache.maven.model.Plugin; import org.apache.maven.model.ReportPlugin; public class PluginWrapper { private String groupId; private String artifactId; private String version; private String source; public static List addAll( List plugins, String source ) { List results = null; if ( !plugins.isEmpty() ) { results = new ArrayList( plugins.size() ); Iterator iter = plugins.iterator(); while ( iter.hasNext() ) { Object o = iter.next(); if ( o instanceof Plugin ) { results.add( new PluginWrapper( (Plugin) o, source ) ); } else { if ( o instanceof ReportPlugin ) { results.add( new PluginWrapper( (ReportPlugin) o, source ) ); } } } } return results; } public PluginWrapper( Plugin plugin, String source ) { setGroupId( plugin.getGroupId() ); setArtifactId( plugin.getArtifactId() ); setVersion( plugin.getVersion() ); setSource( source ); } public PluginWrapper( ReportPlugin plugin, String source ) { setGroupId( plugin.getGroupId() ); setArtifactId( plugin.getArtifactId() ); setVersion( plugin.getVersion() ); setSource( source ); } public String getGroupId() { return groupId; } public void setGroupId( String groupId ) { this.groupId = groupId; } public String getArtifactId() { return artifactId; } public void setArtifactId( String artifactId ) { this.artifactId = artifactId; } public String getVersion() { return version; } public void setVersion( String version ) { this.version = version; } public String getSource() { return source; } public void setSource( String source ) { this.source = source; } } maven-enforcer-1.0.1/enforcer-rules/src/site/000077500000000000000000000000001205711263400211075ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/site/apt/000077500000000000000000000000001205711263400216735ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/site/apt/alwaysFail.apt.vm000066400000000000000000000031721205711263400251210ustar00rootroot00000000000000~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ------ Always Fail ------ Brian Fox ------ August 2008 ------ Always Fail This rule will always fail. It is useful for testing proper plugin configuration. Sample Plugin Configuration: +---+ [...] org.apache.maven.plugins maven-enforcer-plugin ${project.version} enforce enforce true [...] +---+ maven-enforcer-1.0.1/enforcer-rules/src/site/apt/alwaysPass.apt.vm000066400000000000000000000031741205711263400251560ustar00rootroot00000000000000~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ------ AlwaysPass ------ Brian Fox ------ August 2008 ------ Always Pass This rule will always succeed. It is useful for testing proper plugin configuration. Sample Plugin Configuration: +---+ [...] org.apache.maven.plugins maven-enforcer-plugin ${project.version} enforce enforce true [...] +---+ maven-enforcer-1.0.1/enforcer-rules/src/site/apt/bannedDependencies.apt.vm000066400000000000000000000063661205711263400265730ustar00rootroot00000000000000~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ------ Banned Dependencies ------ Brian Fox ------ November 2007 ------ Banned Dependencies This rule checks the dependencies and fails if any of the matching excludes are found. The following parameters are supported by this rule: * searchTransitive - if transitive dependencies should be checked. * excludes - a list of artifacts to ban. The format is groupId[:artifactId][:version][:type][:scope] where artifactId, version, type, and scope are optional. Wildcards may be used to replace an entire section. Examples: * org.apache.maven * org.apache.maven:badArtifact * org.apache.maven:artifact:badVersion * org.apache.maven:*:1.2 * org.apache.maven:*:*:jar:test [] * includes - a list of artifacts to include. These are exceptions to the excludes. It is meant to allow wide exclusion rules with wildcards and fine tune using includes. If nothing has been excluded, then the includes have no effect. In otherwords, includes only subtract from artifacts that matched an exclude rule. For example, to ban all xerces except xerces-api you would exclude "xerces" (groupId) and include "xerces:xerces-api" * message - an optional message to the user if the rule fails. [] Sample Plugin Configuration: +---+ [...] org.apache.maven.plugins maven-enforcer-plugin ${project.version} enforce-banned-dependencies enforce org.apache.maven org.apache.maven:badArtifact *:badArtifact org.apache.maven:badArtifact:1.0 true [...] +---+maven-enforcer-1.0.1/enforcer-rules/src/site/apt/dependencyConvergence.apt.vm000066400000000000000000000073471205711263400273320ustar00rootroot00000000000000 ~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ----- Comparing against a specific artifact ----- ----- 2008-09-13 ----- This rule requires that dependency version numbers converge. If a project has two dependencies, A and B, both depending on the same artifact, C, this rule will fail the build if A depends on a different version of C then the version of C depended on by B. Here is a concrete example. This will cause a build to fail. ----------------------------------------------------------------------------------- org.slf4j slf4j-jdk14 1.6.1 org.slf4j slf4j-nop 1.6.0 ----------------------------------------------------------------------------------- With this being logged during compilation ----------------------------------------------------------------------------------- Dependency convergence error for org.slf4j:slf4j-api1.6.1 paths to dependency are: [ERROR] Dependency convergence error for org.slf4j:slf4j-api:1.6.1 paths to dependency are: +-org.myorg:my-project:1.0.0-SNAPSHOT +-org.slf4j:slf4j-jdk14:1.6.1 +-org.slf4j:slf4j-api:1.6.1 and +-org.myorg:my-project:1.0.0-SNAPSHOT +-org.slf4j:slf4j-nop:1.6.0 +-org.slf4j:slf4j-api:1.6.0 ----------------------------------------------------------------------------------- And this will succeed. ----------------------------------------------------------------------------------- org.slf4j slf4j-jdk14 1.6.1 org.slf4j slf4j-nop 1.6.0 org.slf4j slf4j-api ----------------------------------------------------------------------------------- Here is how a project should be setup to use this rule ----------------------------------------------------------------------------------- ... ... org.apache.maven.plugins maven-enforcer-plugin ${project.version} enforce enforce ... ... ----------------------------------------------------------------------------------- maven-enforcer-1.0.1/enforcer-rules/src/site/apt/evaluateBeanshell.apt.vm000066400000000000000000000043671205711263400264600ustar00rootroot00000000000000~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ------ Beanshell ------ Brian Fox ------ June 2007 ------ Beanshell This rule can execute a beanshell script and evaluate the result. The following parameters are supported by this rule: * condition - the beanshell statement to evaluate. * message - an optional message to the user if the rule fails. [] Sample Plugin Configuration: +---+ [...] org.apache.maven.plugins maven-enforcer-plugin ${project.version} enforce-beanshell enforce \${project.artifactId} == foo true [...] +---+ The condition can be a complex script or a simple expression. As long as it results in True, the rule will succeed. This means code can be executed as long as the last line results in true. +---+ for (int i = 0;i!=10;i++){print ("Hello World "+i);};1==1 +---+maven-enforcer-1.0.1/enforcer-rules/src/site/apt/index.apt000066400000000000000000000053051205711263400235130ustar00rootroot00000000000000~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ------ Standard Rules ------ Brian Fox ------ August 2008 ------ Standard Rules The following standard rules ship along with the enforcer plugin: * {{{./alwaysPass.html}alwaysPass}} - Always passes... used to test plugin configuration. * {{{./alwaysFail.html}alwaysFail}} - Always fail... used to test plugin configuration. * {{{./bannedDependencies.html}bannedDependencies}} - enforces that excluded dependencies aren't included. * bannedPlugins - enforces that excluded plugins aren't included. * {{{./dependencyConvergence.html}dependencyConvergence}} - ensure all dependencies converge to the same version. * {{{./evaluateBeanshell.html}evaluateBeanshell}} - evaluates a beanshell script. * {{{./requireReleaseDeps.html}requireReleaseDeps}} - enforces that no snapshots are included as dependencies. * {{{./requireReleaseVersion.html}requireReleaseVersion}} - enforces that the artifact is not a snapshot. * {{{./requireMavenVersion.html}requireMavenVersion}} - enforces the Maven version. * {{{./requireJavaVersion.html}requireJavaVersion}} - enforces the JDK version. * {{{./requireOS.html}requireOS}} - enforces the OS / CPU Archictecture. * {{{./requirePluginVersions.html}requirePluginVersions}} - enforces that all plugins have a specified version. * {{{./requireProperty.html}requireProperty}} - enforces the existence and values of properties. * {{{./requireFilesDontExist.html}requireFilesDontExist}} - enforces that the list of files do not exist. * {{{./requireFilesExist.html}requireFilesExist}} - enforces that the list of files do exist. * {{{./requireFilesSize.html}requireFilesSize}} - enforces that the list of files exist and are within a certain size range. [] You may also create and inject your own custom rules by following the {{{http://maven.apache.org/enforcer/enforcer-api/writing-a-custom-rule.html}maven-enforcer-rule-api}} instructions. maven-enforcer-1.0.1/enforcer-rules/src/site/apt/noSnapshots.apt.vm000066400000000000000000000037341205711263400253500ustar00rootroot00000000000000~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ------ Require Release Dependencies ------ Brian Fox ------ November 2007 ------ Require Release Dependencies This rule checks the dependencies and fails if any snapshots are found. The following parameters are supported by this rule: * searchTransitive - if transitive dependencies should be checked. * message - an optional message to the user if the rule fails. [] Sample Plugin Configuration: +---+ [...] org.apache.maven.plugins maven-enforcer-plugin ${project.version} enforce-no-snapshots enforce No Snapshots Allowed! true [...] +---+maven-enforcer-1.0.1/enforcer-rules/src/site/apt/requireFilesDontExist.apt.vm000066400000000000000000000043031205711263400273230ustar00rootroot00000000000000~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ------ Require Files Dont Exist ------ Brian Fox ------ August 2008 ------ Require Files Don't Exist This rule checks that the specified list of files do not exist. The following parameters are supported by this rule: * message - an optional message to the user if the rule fails. * files - A list of files to check. * allowNulls - If null files should be allowed. If allowed, they will be treated as if they do not exist. Default is false. [] Sample Plugin Configuration: +---+ [...] org.apache.maven.plugins maven-enforcer-plugin ${project.version} enforce-dont-exist enforce \${project.build.outputDirectory}/foo.txt \${project.build.outputDirectory}/foo2.txt true [...] +---+ maven-enforcer-1.0.1/enforcer-rules/src/site/apt/requireFilesExist.apt.vm000066400000000000000000000042461205711263400265040ustar00rootroot00000000000000~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ------ Require Files Exist ------ Brian Fox ------ August 2008 ------ Require Files Exist This rule checks that the specified list of files exist. The following parameters are supported by this rule: * message - an optional message to the user if the rule fails. * files - A list of files to check. * allowNulls - If null files should be allowed. If allowed, they will be treated as if they do exist. Default is false. [] Sample Plugin Configuration: +---+ [...] org.apache.maven.plugins maven-enforcer-plugin ${project.version} enforce-files-exist enforce \${project.build.outputDirectory}/foo.txt \${project.build.outputDirectory}/foo2.txt true [...] +---+ maven-enforcer-1.0.1/enforcer-rules/src/site/apt/requireFilesSize.apt.vm000066400000000000000000000047111205711263400263170ustar00rootroot00000000000000~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ------ Require File Size ------ Brian Fox ------ August 2008 ------ Require File Size This rule checks that the specified list of files exist and are within the specified size range. The following parameters are supported by this rule: * message - an optional message to the user if the rule fails. * files - A list of files to check. If this list is empty, the main project artifact will be checked. * maxsize - maximum size in bytes for this file * minsize - minimum size in bytes for this file * allowNulls - If null files should be allowed. If allowed, they will be treated as if they do exist. Default is false. [] Sample Plugin Configuration: +---+ [...] org.apache.maven.plugins maven-enforcer-plugin ${project.version} enforce-file-size enforce 10000 90 \${project.build.outputDirectory}/foo.txt \${project.build.outputDirectory}/foo2.txt true [...] +---+ maven-enforcer-1.0.1/enforcer-rules/src/site/apt/requireJavaVersion.apt.vm000066400000000000000000000064161205711263400266550ustar00rootroot00000000000000~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ------ Require Java Version ------ Brian Fox ------ June 2007 ------ Require Java Version This rule enforces certain Java JDK versions. The rule uses the {{{./versionRanges.html}Enforcer version range syntax}} to define allowed versions. The following parameters are supported by this rule: * message - an optional message to the user if the rule fails. * {{{../apidocs/org/apache/maven/plugin/enforcer/AbstractVersionEnforcer.html#version}version}} - {{{./versionRanges.html}range}} of allowed JDKs. [] The JDK version is retrieved and the following processing occurs before being checked: [[1]] Drop all non-numeric characters preceeding the first number. (build 1.5.0_07-b03 becomes 1.5.0_07-b03) [[2]] Replace all '_' and '-' with '.' (1.5.0_07-b03 becomes 1.5.0.07.b03) [[3]] Remove all non digit characters "[^0-9] and convert each section using Integer.parseInt() (1.5.0_07-b03 becomes 1.5.0.7.3) [[3]] Split the string on '.' and take the first 3 sections, separated by '.' and add '-' followed by the forth section (1.5.0.7.3 becomes 1.5.0-7) [] This preprocessing normalizes various JDK version strings into a standard x.y.z-b version number. Your required range should therefore use the x.y.z-b format for comparison. There is an easy way to see how your current JDK string will be normalized: +---+ mvn enforcer:display-info ... [enforcer:display-info] Maven Version: 2.0.8 JDK Version: 1.5.0_11 normalized as: 1.5.0-11 OS Info: Arch: x86 Family: windows Name: windows xp Version: 5.1 +---+ Sample Plugin Configuration: +---+ [...] org.apache.maven.plugins maven-enforcer-plugin ${project.version} enforce-java enforce 1.5.0 [...] +---+ If you would like to enforce a certain vendor string for the JDK, you would use the {{{./requireProperty.html}RequireProperty}} rule, and check the java.vendor property with a regular expression.maven-enforcer-1.0.1/enforcer-rules/src/site/apt/requireMavenVersion.apt.vm000066400000000000000000000040741205711263400270400ustar00rootroot00000000000000~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ------ Require Maven Version ------ Brian Fox ------ June 2007 ------ Require Maven Version This rule enforces certain Maven versions. The rule uses the {{{./versionRanges.html}Enforcer version range syntax}} to define allowed versions. The following parameters are supported by this rule: * message - an optional message to the user if the rule fails. * {{{../apidocs/org/apache/maven/plugin/enforcer/AbstractVersionEnforcer.html#version}version}} - {{{./versionRanges.html}range}} of allowed Maven versions. [] Sample Plugin Configuration: +---+ [...] org.apache.maven.plugins maven-enforcer-plugin ${project.version} enforce-maven enforce 2.0.6 [...] +---+ maven-enforcer-1.0.1/enforcer-rules/src/site/apt/requireNoRepositories.apt.vm000066400000000000000000000062041205711263400274050ustar00rootroot00000000000000~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ------ Require No Repositories ------ Brian Fox ------ Novemer 2007 ------ Require No Repositories This rule enforces that all plugins have a version defined, either in the plugin or pluginManagement section of the pom or a parent pom. The following parameters are supported by this rule: * message - an optional message to the user if the rule fails. * banLatest - disallow any use of "LATEST" as a version for any plugin. Default = true. * banRelease - disallow any use of "RELEASE" as a version for any plugin. Default = true. * banSnapshots - disallow any use of SNAPSHOT plugins. Default = true. * phases - The comma separated list of phases that should be used to find lifecycle plugin bindings. The default value is "clean,deploy,site". * additionalPlugins - A list of additional plugins to enforce have versions. These are plugins that may not be in the poms but are used anyway, like help, eclipse etc. The plugins should be specified in the form: group:artifactId. [] Sample Plugin Configuration (showing some defaults, defaults can be skipped): +---+ [...] org.apache.maven.plugins maven-enforcer-plugin ${project.version} enforce-no-repos enforce Best Practice is to always define plugin versions! true true true clean,deploy,site org.apache.maven.plugins:maven-eclipse-plugin org.apache.maven.plugins:maven-ide-plugin [...] +---+ maven-enforcer-1.0.1/enforcer-rules/src/site/apt/requireOS.apt.vm000066400000000000000000000104071205711263400247420ustar00rootroot00000000000000~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ------ Require OS Version ------ Brian Fox ------ June 2007 ------ Require OS Version This rule can enforce certain values about the Operating System and processor architecture. The values and code used to determine if an OS is allowed are exactly the same as the OS Profile activation in Maven. The following parameters are supported by this rule: * message - an optional message to the user if the rule fails. * {{{../apidocs/org/apache/maven/plugin/enforcer/RequireOS.html#arch}arch}} - the cpu architecture. * {{{../apidocs/org/apache/maven/plugin/enforcer/RequireOS.html#family}family}} - the family of OS. Possible families are: * dos * mac * netware * os/2 * tandem * unix * windows * win9x * z/os * os/400 [] * {{{../apidocs/org/apache/maven/plugin/enforcer/RequireOS.html#name}name}} - the name of the OS. * {{{../apidocs/org/apache/maven/plugin/enforcer/RequireOS.html#version}version}} - the version of the OS. * {{{../apidocs/org/apache/maven/plugin/enforcer/RequireOS.html#display}display}} - flag to display the detected OS informatin. [] Family is calculated based on testing against the name string retreived from the JDK. The name, arch and version values are retreived from the JDK using the following code: +---+ public static final String OS_NAME = System.getProperty( "os.name" ).toLowerCase( Locale.US ); public static final String OS_ARCH = System.getProperty( "os.arch" ).toLowerCase( Locale.US ); public static final String OS_VERSION = System.getProperty( "os.version" ).toLowerCase( Locale.US ); +---+ Possible arch, name, and version values can be found here: * {{{http://lopica.sourceforge.net/os.html}lopica.sourceforge.net}} * {{{http://tolstoy.com/samizdat/sysprops.html}Sysprops}} [] The various options are considered to be "and'd" together but any number can be specified. (ie family = windows means windows, but family = windows and arch = x86 means only windows on x86 processors) Any parameter may also be used in the negative by prepending a "!" in front of it. For example !dos means everything but dos. (who uses dos anyway?) Since the various names, versions and architecture values cannot be listed exhaustively, there is an easy way to display the information for the current system: +---+ mvn enforcer:display-info ... [enforcer:display-info] Maven Version: 2.0.6 JDK Version: 1.5.0_11 normalized as: 1.5.0 OS Info: Arch: x86 Family: windows Name: windows xp Version: 5.1 +---+ Sample Plugin Configuration: +---+ [...] org.apache.maven.plugins maven-enforcer-plugin ${project.version} enforce-os enforce Windows XP windows x86 5.1.2600 true [...] +---+ maven-enforcer-1.0.1/enforcer-rules/src/site/apt/requirePluginVersions.apt.vm000066400000000000000000000071251205711263400274130ustar00rootroot00000000000000~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ------ Require Plugin Versions ------ Brian Fox ------ November 2009 ------ Require Plugin Versions This rule enforces that all plugins have a version defined, either in the plugin or pluginManagement section of the pom or a parent pom. The following parameters are supported by this rule: * message - an optional message to the user if the rule fails. * banLatest - disallow any use of "LATEST" as a version for any plugin. Default = true. * banRelease - disallow any use of "RELEASE" as a version for any plugin. Default = true. * banSnapshots - disallow any use of SNAPSHOT plugins. Default = true. * banTimestamps - disallow any use of snapshot plugins with timestamp version (only enabled when banSnapshots is true). Default = true. * phases - The comma separated list of phases that should be used to find lifecycle plugin bindings. The default value is "clean,deploy,site". * additionalPlugins - A list of additional plugins to enforce have versions. These are plugins that may not be in the poms but are used anyway, like help, eclipse etc. The plugins should be specified in the form: group:artifactId. * unCheckedPluginsList - A comma separated list of plugins to skip version checking. Ie allow no version, or snapshots, etc. The plugins should be specified in the form: group:artifactId. [] Sample Plugin Configuration (showing some defaults, defaults can be skipped): +---+ [...] org.apache.maven.plugins maven-enforcer-plugin ${project.version} enforce-plugin-versions enforce Best Practice is to always define plugin versions! true true true clean,deploy,site org.apache.maven.plugins:maven-eclipse-plugin org.apache.maven.plugins:maven-reactor-plugin org.apache.maven.plugins:maven-enforcer-plugin,org.apache.maven.plugins:maven-idea-plugin [...] +---+maven-enforcer-1.0.1/enforcer-rules/src/site/apt/requireProperty.apt.vm000066400000000000000000000052431205711263400262470ustar00rootroot00000000000000~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ------ Require Property ------ Brian Fox ------ June 2007 ------ Require Property This rule can enforce that a declared property is set and optionally evaluate it against a regular expression. The following parameters are supported by this rule: * property - the property to evaluate. * message - an optional message to the user if the rule fails. Default is: "Property 'xxx' is required for this build". * regex - a regular expression used to check the value of the property. * regexMessage - an optional message to the user if the regex check fails. [] Sample Plugin Configuration: +---+ [...] org.apache.maven.plugins maven-enforcer-plugin ${project.version} enforce-property enforce basedir You must have a basedir! \d You must have a digit in your baseDir! project.version "Project version must be specified." (\d|-SNAPSHOT)$ "Project version must end in a number or -SNAPSHOT." true [...] +---+ maven-enforcer-1.0.1/enforcer-rules/src/site/apt/requireReleaseDeps.apt.vm000066400000000000000000000065301205711263400266170ustar00rootroot00000000000000~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ------ Require Release Dependencies ------ Brian Fox ------ Auguest 2008 ------ Require Release Dependencies This rule checks the dependencies and fails if any snapshots are found. The following parameters are supported by this rule: * searchTransitive - if transitive dependencies should be checked. Default: true * message - an optional message to the user if the rule fails. * onlyWhenRelease - if this rule should only be executed when the version is a non-SNAPSHOT version. Default: false * failWhenParentIsSnapshot - if the parent should be checked. Default: true * includes - List of dependency patterns to include when checking for snapshot versions * excludes - List of dependency patterns to exclude when checking for snapshot versions [] Sample Plugin Configuration: +---+ [...] org.apache.maven.plugins maven-enforcer-plugin ${project.version} enforce-no-snapshots enforce No Snapshots Allowed! true [...] +---+ Includes/Excludes Plugin Configuration: +---+ [...] org.apache.maven.plugins maven-enforcer-plugin ${project.version} enforce-no-snapshots enforce No Snapshots Allowed! org.apache.maven:maven-core org.apache.maven.plugins:* true [...] +---+ maven-enforcer-1.0.1/enforcer-rules/src/site/apt/requireReleaseVersion.apt.vm000066400000000000000000000037241205711263400273530ustar00rootroot00000000000000~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ------ Require Release Version ------ Brian Fox ------ August 2008 ------ Require Release Version This rule checks that the current project is not a snapshot. The following parameters are supported by this rule: * message - an optional message to the user if the rule fails. * failWhenParentIsSnapshot - if the parent should be checked. Default: true [] Sample Plugin Configuration: +---+ [...] org.apache.maven.plugins maven-enforcer-plugin ${project.version} enforce-no-snapshots enforce No Snapshots Allowed! true [...] +---+ maven-enforcer-1.0.1/enforcer-rules/src/site/apt/versionRanges.apt000066400000000000000000000042461205711263400252340ustar00rootroot00000000000000~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ------ Version Range Specification ------ Brian Fox ------ May 2007 ------ Version Range Specification The {{{./requireMavenVersion.html}RequireMavenVersion}} and {{{./requireJavaVersion.html}RequireJavaVersion}} rules use the {{{http://docs.codehaus.org/display/MAVEN/Dependency+Mediation+and+Conflict+Resolution#DependencyMediationandConflictResolution-DependencyVersionRanges}standard Maven version range syntax}} with one minor change for ease of use (denoted with *): *----------*--------------+ | Range | Meaning | *----------*--------------+ | 1.0 | x \>\= 1.0 \* The default Maven meaning for 1.0 is everything (,) but with 1.0 recommended. Obviously this doesn't work for enforcing versions here, so it has been redefined as a minimum version. | *----------*--------------+ | (,1.0] | x \<\= 1.0 | *----------*--------------+ | (,1.0) | x \< 1.0 | *----------*--------------+ | [1.0] | x \=\= 1.0 | *----------*--------------+ | [1.0,) | x \>\= 1.0 | *----------*--------------+ | (1.0,) | x \> 1.0 | *----------*--------------+ | (1.0,2.0)| 1.0 \< x \< 2.0 | *----------*--------------+ | [1.0,2.0]| 1.0 \<\= x \<\= 2.0 | *----------*--------------+ | (,1.0],[1.2,) |x \<\= 1.0 or x \>\= 1.2. Multiple sets are comma-separated | *----------*--------------+ | (,1.1),(1.1,) |x !\= 1.1 | *----------*--------------+ maven-enforcer-1.0.1/enforcer-rules/src/site/site.xml000066400000000000000000000023001205711263400225700ustar00rootroot00000000000000 maven-enforcer-1.0.1/enforcer-rules/src/test/000077500000000000000000000000001205711263400211225ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/000077500000000000000000000000001205711263400220435ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/000077500000000000000000000000001205711263400226325ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/000077500000000000000000000000001205711263400240535ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/maven/000077500000000000000000000000001205711263400251615ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/maven/plugins/000077500000000000000000000000001205711263400266425ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/000077500000000000000000000000001205711263400304455ustar00rootroot00000000000000EnforcerTestUtils.java000066400000000000000000000100011205711263400346450ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.Date; import java.util.Properties; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Plugin; import org.apache.maven.plugin.logging.SystemStreamLog; import org.apache.maven.plugins.enforcer.utils.MockEnforcerExpressionEvaluator; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; // TODO: Auto-generated Javadoc /** * The Class EnforcerTestUtils. * * @author Brian Fox */ public final class EnforcerTestUtils { /** * Gets the maven session. * * @return the maven session */ public static MavenSession getMavenSession() { return new MavenSession( new MockPlexusContainer(), null, null, null, null, null, null, new Properties(), new Date() ); } /** * Gets the helper. * * @return the helper */ public static EnforcerRuleHelper getHelper() { return getHelper( new MockProject(), false ); } /** * Gets the helper. * * @param mockExpression the mock expression * @return the helper */ public static EnforcerRuleHelper getHelper( boolean mockExpression ) { return getHelper( new MockProject(), mockExpression ); } /** * Gets the helper. * * @param project the project * @return the helper */ public static EnforcerRuleHelper getHelper( MavenProject project ) { return getHelper( project, false ); } /** * Gets the helper. * * @param project the project * @param mockExpression the mock expression * @return the helper */ public static EnforcerRuleHelper getHelper( MavenProject project, boolean mockExpression ) { MavenSession session = getMavenSession(); ExpressionEvaluator eval; if ( mockExpression ) { eval = new MockEnforcerExpressionEvaluator( session, new MockPathTranslator(), project ); } else { eval = new EnforcerExpressionEvaluator( session, new MockPathTranslator(), project ); } return new DefaultEnforcementRuleHelper( session, eval, new SystemStreamLog(), null ); } /** * Gets the helper. * * @param project the project * @param eval the expression evaluator to use * @return the helper */ public static EnforcerRuleHelper getHelper( MavenProject project, ExpressionEvaluator eval ) { MavenSession session = getMavenSession(); return new DefaultEnforcementRuleHelper( session, eval, new SystemStreamLog(), null ); } /** * New plugin. * * @param groupId the group id * @param artifactId the artifact id * @param version the version * @return the plugin */ public static Plugin newPlugin( String groupId, String artifactId, String version ) { Plugin plugin = new Plugin(); plugin.setArtifactId( artifactId ); plugin.setGroupId( groupId ); plugin.setVersion( version ); return plugin; } } MockPathTranslator.java000066400000000000000000000043531205711263400350160ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.File; import org.apache.maven.model.Model; import org.apache.maven.project.path.PathTranslator; // TODO: Auto-generated Javadoc /** * The Class MockPathTranslator. * * @author Brian Fox */ public class MockPathTranslator implements PathTranslator { /* * (non-Javadoc) * * @see org.apache.maven.project.path.PathTranslator#alignToBaseDirectory(org.apache.maven.model.Model, * java.io.File) */ public void alignToBaseDirectory( Model theModel, File theBasedir ) { } /* * (non-Javadoc) * * @see org.apache.maven.project.path.PathTranslator#alignToBaseDirectory(java.lang.String, java.io.File) */ public String alignToBaseDirectory( String thePath, File theBasedir ) { return theBasedir.getAbsolutePath(); } /* * (non-Javadoc) * * @see org.apache.maven.project.path.PathTranslator#unalignFromBaseDirectory(org.apache.maven.model.Model, * java.io.File) */ public void unalignFromBaseDirectory( Model theModel, File theBasedir ) { } /* * (non-Javadoc) * * @see org.apache.maven.project.path.PathTranslator#unalignFromBaseDirectory(java.lang.String, java.io.File) */ public String unalignFromBaseDirectory( String theDirectory, File theBasedir ) { return theBasedir.getAbsolutePath(); } } MockPlexusContainer.java000066400000000000000000000332341205711263400351730ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.File; import java.io.Reader; import java.util.Date; import java.util.List; import java.util.Map; import org.apache.maven.execution.RuntimeInformation; import org.apache.maven.project.MavenProject; import org.codehaus.classworlds.ClassRealm; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.PlexusContainerException; import org.codehaus.plexus.component.composition.CompositionException; import org.codehaus.plexus.component.composition.UndefinedComponentComposerException; import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener; import org.codehaus.plexus.component.factory.ComponentInstantiationException; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.component.repository.exception.ComponentRepositoryException; import org.codehaus.plexus.configuration.PlexusConfigurationResourceException; import org.codehaus.plexus.context.Context; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.LoggerManager; // TODO: Auto-generated Javadoc /** * The Class MockPlexusContainer. * * @author Brian Fox */ public class MockPlexusContainer implements PlexusContainer { /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#lookup(java.lang.String) */ public Object lookup( String theComponentKey ) throws ComponentLookupException { if ( theComponentKey.equals( MavenProject.class.getName() ) ) { return new MavenProject(); } else if ( theComponentKey.equals( RuntimeInformation.class.getName() ) ) { return new MockRuntimeInformation(); } return null; } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#addComponentDescriptor(org.codehaus.plexus.component.repository.ComponentDescriptor) */ public void addComponentDescriptor( ComponentDescriptor theComponentDescriptor ) throws ComponentRepositoryException { // TODO Auto-generated method stub } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#addContextValue(java.lang.Object, java.lang.Object) */ public void addContextValue( Object theKey, Object theValue ) { // TODO Auto-generated method stub } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#addJarRepository(java.io.File) */ public void addJarRepository( File theRepository ) { // TODO Auto-generated method stub } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#addJarResource(java.io.File) */ public void addJarResource( File theResource ) throws PlexusContainerException { // TODO Auto-generated method stub } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#composeComponent(java.lang.Object, * org.codehaus.plexus.component.repository.ComponentDescriptor) */ public void composeComponent( Object theComponent, ComponentDescriptor theComponentDescriptor ) throws CompositionException, UndefinedComponentComposerException { // TODO Auto-generated method stub } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#createChildContainer(java.lang.String, java.util.List, java.util.Map) */ public PlexusContainer createChildContainer( String theName, List theClasspathJars, Map theContext ) throws PlexusContainerException { // TODO Auto-generated method stub return null; } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#createChildContainer(java.lang.String, java.util.List, java.util.Map, * java.util.List) */ public PlexusContainer createChildContainer( String theName, List theClasspathJars, Map theContext, List theDiscoveryListeners ) throws PlexusContainerException { // TODO Auto-generated method stub return null; } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#createComponentInstance(org.codehaus.plexus.component.repository.ComponentDescriptor) */ public Object createComponentInstance( ComponentDescriptor theComponentDescriptor ) throws ComponentInstantiationException, ComponentLifecycleException { // TODO Auto-generated method stub return null; } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#dispose() */ public void dispose() { // TODO Auto-generated method stub } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#getChildContainer(java.lang.String) */ public PlexusContainer getChildContainer( String theName ) { // TODO Auto-generated method stub return null; } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#getComponentDescriptor(java.lang.String) */ public ComponentDescriptor getComponentDescriptor( String theComponentKey ) { // TODO Auto-generated method stub return null; } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#getComponentDescriptorList(java.lang.String) */ public List getComponentDescriptorList( String theRole ) { // TODO Auto-generated method stub return null; } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#getComponentDescriptorMap(java.lang.String) */ public Map getComponentDescriptorMap( String theRole ) { // TODO Auto-generated method stub return null; } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#getComponentRealm(java.lang.String) */ public ClassRealm getComponentRealm( String theComponentKey ) { // TODO Auto-generated method stub return null; } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#getContainerRealm() */ public ClassRealm getContainerRealm() { // TODO Auto-generated method stub return null; } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#getContext() */ public Context getContext() { // TODO Auto-generated method stub return null; } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#getCreationDate() */ public Date getCreationDate() { // TODO Auto-generated method stub return null; } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#getLogger() */ public Logger getLogger() { // TODO Auto-generated method stub return null; } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#getLoggerManager() */ public LoggerManager getLoggerManager() { // TODO Auto-generated method stub return null; } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#hasChildContainer(java.lang.String) */ public boolean hasChildContainer( String theName ) { // TODO Auto-generated method stub return false; } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#hasComponent(java.lang.String) */ public boolean hasComponent( String theComponentKey ) { // TODO Auto-generated method stub return false; } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#hasComponent(java.lang.String, java.lang.String) */ public boolean hasComponent( String theRole, String theRoleHint ) { // TODO Auto-generated method stub return false; } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#initialize() */ public void initialize() throws PlexusContainerException { // TODO Auto-generated method stub } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#isInitialized() */ public boolean isInitialized() { // TODO Auto-generated method stub return false; } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#isStarted() */ public boolean isStarted() { // TODO Auto-generated method stub return false; } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#lookup(java.lang.String, java.lang.String) */ public Object lookup( String theRole, String theRoleHint ) throws ComponentLookupException { // TODO Auto-generated method stub return null; } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#lookupList(java.lang.String) */ public List lookupList( String theRole ) throws ComponentLookupException { // TODO Auto-generated method stub return null; } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#lookupMap(java.lang.String) */ public Map lookupMap( String theRole ) throws ComponentLookupException { // TODO Auto-generated method stub return null; } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#registerComponentDiscoveryListener(org.codehaus.plexus.component.discovery.ComponentDiscoveryListener) */ public void registerComponentDiscoveryListener( ComponentDiscoveryListener theListener ) { // TODO Auto-generated method stub } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#release(java.lang.Object) */ public void release( Object theComponent ) throws ComponentLifecycleException { // TODO Auto-generated method stub } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#releaseAll(java.util.Map) */ public void releaseAll( Map theComponents ) throws ComponentLifecycleException { // TODO Auto-generated method stub } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#releaseAll(java.util.List) */ public void releaseAll( List theComponents ) throws ComponentLifecycleException { // TODO Auto-generated method stub } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#removeChildContainer(java.lang.String) */ public void removeChildContainer( String theName ) { // TODO Auto-generated method stub } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#removeComponentDiscoveryListener(org.codehaus.plexus.component.discovery.ComponentDiscoveryListener) */ public void removeComponentDiscoveryListener( ComponentDiscoveryListener theListener ) { // TODO Auto-generated method stub } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#resume(java.lang.Object) */ public void resume( Object theComponent ) throws ComponentLifecycleException { // TODO Auto-generated method stub } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#setConfigurationResource(java.io.Reader) */ public void setConfigurationResource( Reader theConfiguration ) throws PlexusConfigurationResourceException { // TODO Auto-generated method stub } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#setLoggerManager(org.codehaus.plexus.logging.LoggerManager) */ public void setLoggerManager( LoggerManager theLoggerManager ) { // TODO Auto-generated method stub } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#setParentPlexusContainer(org.codehaus.plexus.PlexusContainer) */ public void setParentPlexusContainer( PlexusContainer theParentContainer ) { // TODO Auto-generated method stub } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#start() */ public void start() throws PlexusContainerException { // TODO Auto-generated method stub } /* * (non-Javadoc) * * @see org.codehaus.plexus.PlexusContainer#suspend(java.lang.Object) */ public void suspend( Object theComponent ) throws ComponentLifecycleException { // TODO Auto-generated method stub } } maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/MockProject.java000066400000000000000000001233601205711263400335350ustar00rootroot00000000000000package org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.File; import java.io.IOException; import java.io.Writer; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.model.Build; import org.apache.maven.model.CiManagement; import org.apache.maven.model.Contributor; import org.apache.maven.model.DependencyManagement; import org.apache.maven.model.Developer; import org.apache.maven.model.DistributionManagement; import org.apache.maven.model.IssueManagement; import org.apache.maven.model.License; import org.apache.maven.model.MailingList; import org.apache.maven.model.Model; import org.apache.maven.model.Organization; import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginManagement; import org.apache.maven.model.Prerequisites; import org.apache.maven.model.Reporting; import org.apache.maven.model.Resource; import org.apache.maven.model.Scm; import org.apache.maven.project.MavenProject; import org.apache.maven.project.artifact.InvalidDependencyVersionException; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.util.xml.Xpp3Dom; /** * very simple stub of maven project, going to take a lot of work to make it useful as a stub though. */ public class MockProject extends MavenProject { /** The group id. */ private String groupId; /** The artifact id. */ private String artifactId; /** The name. */ private String name; /** The model. */ private Model model; /** The parent. */ private MavenProject parent; /** The dependencies. */ private List dependencies; /** The file. */ private File file; /** The collected projects. */ private List collectedProjects; /** The attached artifacts. */ private List attachedArtifacts; /** The compile source roots. */ private List compileSourceRoots; /** The test compile source roots. */ private List testCompileSourceRoots; /** The script source roots. */ private List scriptSourceRoots; /** The plugin artifact repositories. */ private List pluginArtifactRepositories; // private ArtifactRepository releaseArtifactRepository; // private ArtifactRepository snapshotArtifactRepository; /** The active profiles. */ private List activeProfiles; /** The dependency artifacts. */ private Set dependencyArtifacts; /** The dependency management. */ private DependencyManagement dependencyManagement; /** The artifact. */ private Artifact artifact; // private Map artifactMap; /** The original model. */ private Model originalModel; // private Map pluginArtifactMap; // private Map reportArtifactMap; // private Map extensionArtifactMap; // private Map projectReferences; // private Build buildOverlay; /** The execution root. */ private boolean executionRoot; /** The compile artifacts. */ private List compileArtifacts; /** The compile dependencies. */ private List compileDependencies; /** The system dependencies. */ private List systemDependencies; /** The test classpath elements. */ private List testClasspathElements; /** The test dependencies. */ private List testDependencies; /** The system classpath elements. */ private List systemClasspathElements; /** The system artifacts. */ private List systemArtifacts; /** The test artifacts. */ private List testArtifacts; /** The runtime artifacts. */ private List runtimeArtifacts; /** The runtime dependencies. */ private List runtimeDependencies; /** The runtime classpath elements. */ private List runtimeClasspathElements; /** The model version. */ private String modelVersion; /** The packaging. */ private String packaging; /** The inception year. */ private String inceptionYear; /** The url. */ private String url; /** The description. */ private String description; /** The version. */ private String version; /** The default goal. */ private String defaultGoal; /** The artifacts. */ private Set artifacts; /** The properties. */ private Properties properties = new Properties(); /** The base dir. */ private File baseDir = null; /** * Instantiates a new mock project. */ public MockProject() { super( (Model) null ); } // kinda dangerous... /** * Instantiates a new mock project. * * @param model the model */ public MockProject( Model model ) { // super(model); super( (Model) null ); } // kinda dangerous... /** * Instantiates a new mock project. * * @param project the project */ public MockProject( MavenProject project ) { // super(project); super( (Model) null ); } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getModulePathAdjustment(org.apache.maven.project.MavenProject) */ public String getModulePathAdjustment( MavenProject mavenProject ) throws IOException { return ""; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getArtifact() */ public Artifact getArtifact() { return artifact; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setArtifact(org.apache.maven.artifact.Artifact) */ public void setArtifact( Artifact artifact ) { this.artifact = artifact; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getModel() */ public Model getModel() { return model; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getParent() */ public MavenProject getParent() { return parent; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setParent(org.apache.maven.project.MavenProject) */ public void setParent( MavenProject mavenProject ) { this.parent = mavenProject; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setRemoteArtifactRepositories(java.util.List) */ public void setRemoteArtifactRepositories( List list ) { } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getRemoteArtifactRepositories() */ public List getRemoteArtifactRepositories() { return Collections.singletonList( "" ); } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#hasParent() */ public boolean hasParent() { if ( parent != null ) { return true; } else { return false; } } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getFile() */ public File getFile() { return file; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setFile(java.io.File) */ public void setFile( File file ) { this.file = file; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getBasedir() */ public File getBasedir() { if ( baseDir == null ) { baseDir = new File( PlexusTestCase.getBasedir() ); } return baseDir; } /** * Sets the base dir. * * @param base the new base dir */ public void setBaseDir( File base ) { baseDir = base; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setDependencies(java.util.List) */ public void setDependencies( List list ) { dependencies = list; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getDependencies() */ public List getDependencies() { if ( dependencies == null ) { dependencies = Collections.EMPTY_LIST; } return dependencies; } /** * Sets the dependency management. * * @param depMgt the new dependency management */ public void setDependencyManagement( DependencyManagement depMgt ) { this.dependencyManagement = depMgt; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getDependencyManagement() */ public DependencyManagement getDependencyManagement() { if ( dependencyManagement == null ) { dependencyManagement = new DependencyManagement(); } return dependencyManagement; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#addCompileSourceRoot(java.lang.String) */ public void addCompileSourceRoot( String string ) { if ( compileSourceRoots == null ) { compileSourceRoots = Collections.singletonList( string ); } else { compileSourceRoots.add( string ); } } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#addScriptSourceRoot(java.lang.String) */ public void addScriptSourceRoot( String string ) { if ( scriptSourceRoots == null ) { scriptSourceRoots = Collections.singletonList( string ); } else { scriptSourceRoots.add( string ); } } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#addTestCompileSourceRoot(java.lang.String) */ public void addTestCompileSourceRoot( String string ) { if ( testCompileSourceRoots == null ) { testCompileSourceRoots = Collections.singletonList( string ); } else { testCompileSourceRoots.add( string ); } } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getCompileSourceRoots() */ public List getCompileSourceRoots() { return compileSourceRoots; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getScriptSourceRoots() */ public List getScriptSourceRoots() { return scriptSourceRoots; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getTestCompileSourceRoots() */ public List getTestCompileSourceRoots() { return testCompileSourceRoots; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getCompileClasspathElements() */ public List getCompileClasspathElements() throws DependencyResolutionRequiredException { return compileSourceRoots; } /** * Sets the compile artifacts. * * @param compileArtifacts the new compile artifacts */ public void setCompileArtifacts( List compileArtifacts ) { this.compileArtifacts = compileArtifacts; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getCompileArtifacts() */ public List getCompileArtifacts() { return compileArtifacts; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getCompileDependencies() */ public List getCompileDependencies() { return compileDependencies; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getTestClasspathElements() */ public List getTestClasspathElements() throws DependencyResolutionRequiredException { return testClasspathElements; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getTestArtifacts() */ public List getTestArtifacts() { return testArtifacts; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getTestDependencies() */ public List getTestDependencies() { return testDependencies; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getRuntimeClasspathElements() */ public List getRuntimeClasspathElements() throws DependencyResolutionRequiredException { return runtimeClasspathElements; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getRuntimeArtifacts() */ public List getRuntimeArtifacts() { return runtimeArtifacts; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getRuntimeDependencies() */ public List getRuntimeDependencies() { return runtimeDependencies; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getSystemClasspathElements() */ public List getSystemClasspathElements() throws DependencyResolutionRequiredException { return systemClasspathElements; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getSystemArtifacts() */ public List getSystemArtifacts() { return systemArtifacts; } /** * Sets the runtime classpath elements. * * @param runtimeClasspathElements the new runtime classpath elements */ public void setRuntimeClasspathElements( List runtimeClasspathElements ) { this.runtimeClasspathElements = runtimeClasspathElements; } /** * Sets the attached artifacts. * * @param attachedArtifacts the new attached artifacts */ public void setAttachedArtifacts( List attachedArtifacts ) { this.attachedArtifacts = attachedArtifacts; } /** * Sets the compile source roots. * * @param compileSourceRoots the new compile source roots */ public void setCompileSourceRoots( List compileSourceRoots ) { this.compileSourceRoots = compileSourceRoots; } /** * Sets the test compile source roots. * * @param testCompileSourceRoots the new test compile source roots */ public void setTestCompileSourceRoots( List testCompileSourceRoots ) { this.testCompileSourceRoots = testCompileSourceRoots; } /** * Sets the script source roots. * * @param scriptSourceRoots the new script source roots */ public void setScriptSourceRoots( List scriptSourceRoots ) { this.scriptSourceRoots = scriptSourceRoots; } /** * Sets the artifact map. * * @param artifactMap the new artifact map */ public void setArtifactMap( Map artifactMap ) { // this.artifactMap = artifactMap; } /** * Sets the plugin artifact map. * * @param pluginArtifactMap the new plugin artifact map */ public void setPluginArtifactMap( Map pluginArtifactMap ) { // this.pluginArtifactMap = pluginArtifactMap; } /** * Sets the report artifact map. * * @param reportArtifactMap the new report artifact map */ public void setReportArtifactMap( Map reportArtifactMap ) { // this.reportArtifactMap = reportArtifactMap; } /** * Sets the extension artifact map. * * @param extensionArtifactMap the new extension artifact map */ public void setExtensionArtifactMap( Map extensionArtifactMap ) { // this.extensionArtifactMap = extensionArtifactMap; } /** * Sets the project references. * * @param projectReferences the new project references */ public void setProjectReferences( Map projectReferences ) { // this.projectReferences = projectReferences; } /** * Sets the builds the overlay. * * @param buildOverlay the new builds the overlay */ public void setBuildOverlay( Build buildOverlay ) { // this.buildOverlay = buildOverlay; } /** * Sets the compile dependencies. * * @param compileDependencies the new compile dependencies */ public void setCompileDependencies( List compileDependencies ) { this.compileDependencies = compileDependencies; } /** * Sets the system dependencies. * * @param systemDependencies the new system dependencies */ public void setSystemDependencies( List systemDependencies ) { this.systemDependencies = systemDependencies; } /** * Sets the test classpath elements. * * @param testClasspathElements the new test classpath elements */ public void setTestClasspathElements( List testClasspathElements ) { this.testClasspathElements = testClasspathElements; } /** * Sets the test dependencies. * * @param testDependencies the new test dependencies */ public void setTestDependencies( List testDependencies ) { this.testDependencies = testDependencies; } /** * Sets the system classpath elements. * * @param systemClasspathElements the new system classpath elements */ public void setSystemClasspathElements( List systemClasspathElements ) { this.systemClasspathElements = systemClasspathElements; } /** * Sets the system artifacts. * * @param systemArtifacts the new system artifacts */ public void setSystemArtifacts( List systemArtifacts ) { this.systemArtifacts = systemArtifacts; } /** * Sets the test artifacts. * * @param testArtifacts the new test artifacts */ public void setTestArtifacts( List testArtifacts ) { this.testArtifacts = testArtifacts; } /** * Sets the runtime artifacts. * * @param runtimeArtifacts the new runtime artifacts */ public void setRuntimeArtifacts( List runtimeArtifacts ) { this.runtimeArtifacts = runtimeArtifacts; } /** * Sets the runtime dependencies. * * @param runtimeDependencies the new runtime dependencies */ public void setRuntimeDependencies( List runtimeDependencies ) { this.runtimeDependencies = runtimeDependencies; } /** * Sets the model. * * @param model the new model */ public void setModel( Model model ) { this.model = model; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getSystemDependencies() */ public List getSystemDependencies() { return systemDependencies; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setModelVersion(java.lang.String) */ public void setModelVersion( String string ) { this.modelVersion = string; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getModelVersion() */ public String getModelVersion() { return modelVersion; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getId() */ public String getId() { return ""; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setGroupId(java.lang.String) */ public void setGroupId( String string ) { this.groupId = string; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getGroupId() */ public String getGroupId() { return groupId; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setArtifactId(java.lang.String) */ public void setArtifactId( String string ) { this.artifactId = string; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getArtifactId() */ public String getArtifactId() { return artifactId; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setName(java.lang.String) */ public void setName( String string ) { this.name = string; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getName() */ public String getName() { return name; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setVersion(java.lang.String) */ public void setVersion( String string ) { this.version = string; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getVersion() */ public String getVersion() { return version; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getPackaging() */ public String getPackaging() { return packaging; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setPackaging(java.lang.String) */ public void setPackaging( String string ) { this.packaging = string; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setInceptionYear(java.lang.String) */ public void setInceptionYear( String string ) { this.inceptionYear = string; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getInceptionYear() */ public String getInceptionYear() { return inceptionYear; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setUrl(java.lang.String) */ public void setUrl( String string ) { this.url = string; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getUrl() */ public String getUrl() { return url; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getPrerequisites() */ public Prerequisites getPrerequisites() { return null; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setIssueManagement(org.apache.maven.model.IssueManagement) */ public void setIssueManagement( IssueManagement issueManagement ) { } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getCiManagement() */ public CiManagement getCiManagement() { return null; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setCiManagement(org.apache.maven.model.CiManagement) */ public void setCiManagement( CiManagement ciManagement ) { } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getIssueManagement() */ public IssueManagement getIssueManagement() { return null; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setDistributionManagement(org.apache.maven.model.DistributionManagement) */ public void setDistributionManagement( DistributionManagement distributionManagement ) { } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getDistributionManagement() */ public DistributionManagement getDistributionManagement() { return null; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setDescription(java.lang.String) */ public void setDescription( String string ) { this.description = string; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getDescription() */ public String getDescription() { return description; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setOrganization(org.apache.maven.model.Organization) */ public void setOrganization( Organization organization ) { } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getOrganization() */ public Organization getOrganization() { return null; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setScm(org.apache.maven.model.Scm) */ public void setScm( Scm scm ) { } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getScm() */ public Scm getScm() { return null; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setMailingLists(java.util.List) */ public void setMailingLists( List list ) { } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getMailingLists() */ public List getMailingLists() { return Collections.singletonList( "" ); } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#addMailingList(org.apache.maven.model.MailingList) */ public void addMailingList( MailingList mailingList ) { } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setDevelopers(java.util.List) */ public void setDevelopers( List list ) { } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getDevelopers() */ public List getDevelopers() { return Collections.singletonList( "" ); } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#addDeveloper(org.apache.maven.model.Developer) */ public void addDeveloper( Developer developer ) { } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setContributors(java.util.List) */ public void setContributors( List list ) { } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getContributors() */ public List getContributors() { return Collections.singletonList( "" ); } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#addContributor(org.apache.maven.model.Contributor) */ public void addContributor( Contributor contributor ) { } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setBuild(org.apache.maven.model.Build) */ public void setBuild( Build build ) { } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getBuild() */ public Build getBuild() { return null; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getResources() */ public List getResources() { return Collections.singletonList( "" ); } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getTestResources() */ public List getTestResources() { return Collections.singletonList( "" ); } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#addResource(org.apache.maven.model.Resource) */ public void addResource( Resource resource ) { } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#addTestResource(org.apache.maven.model.Resource) */ public void addTestResource( Resource resource ) { } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setReporting(org.apache.maven.model.Reporting) */ public void setReporting( Reporting reporting ) { } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getReporting() */ public Reporting getReporting() { return null; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setLicenses(java.util.List) */ public void setLicenses( List list ) { } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getLicenses() */ public List getLicenses() { return Collections.singletonList( "" ); } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#addLicense(org.apache.maven.model.License) */ public void addLicense( License license ) { } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setArtifacts(java.util.Set) */ public void setArtifacts( Set set ) { this.artifacts = set; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getArtifacts() */ public Set getArtifacts() { if ( artifacts == null ) { return Collections.EMPTY_SET; } else { return artifacts; } } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getArtifactMap() */ public Map getArtifactMap() { return Collections.singletonMap( "", "" ); } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setPluginArtifacts(java.util.Set) */ public void setPluginArtifacts( Set set ) { } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getPluginArtifacts() */ public Set getPluginArtifacts() { return Collections.singleton( "" ); } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getPluginArtifactMap() */ public Map getPluginArtifactMap() { return Collections.singletonMap( "", "" ); } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setReportArtifacts(java.util.Set) */ public void setReportArtifacts( Set set ) { } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getReportArtifacts() */ public Set getReportArtifacts() { return Collections.singleton( "" ); } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getReportArtifactMap() */ public Map getReportArtifactMap() { return Collections.singletonMap( "", "" ); } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setExtensionArtifacts(java.util.Set) */ public void setExtensionArtifacts( Set set ) { } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getExtensionArtifacts() */ public Set getExtensionArtifacts() { return Collections.singleton( "" ); } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getExtensionArtifactMap() */ public Map getExtensionArtifactMap() { return Collections.singletonMap( "", "" ); } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setParentArtifact(org.apache.maven.artifact.Artifact) */ public void setParentArtifact( Artifact artifact ) { } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getParentArtifact() */ public Artifact getParentArtifact() { if (parent !=null) { return parent.getArtifact(); } else return null; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getRepositories() */ public List getRepositories() { return Collections.singletonList( "" ); } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getReportPlugins() */ public List getReportPlugins() { return Collections.singletonList( "" ); } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getBuildPlugins() */ public List getBuildPlugins() { return Collections.singletonList( "" ); } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getModules() */ public List getModules() { return Collections.singletonList( "" ); } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getPluginManagement() */ public PluginManagement getPluginManagement() { return null; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#addPlugin(org.apache.maven.model.Plugin) */ public void addPlugin( Plugin plugin ) { } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#injectPluginManagementInfo(org.apache.maven.model.Plugin) */ public void injectPluginManagementInfo( Plugin plugin ) { } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getCollectedProjects() */ public List getCollectedProjects() { return collectedProjects; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setCollectedProjects(java.util.List) */ public void setCollectedProjects( List list ) { this.collectedProjects = list; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setPluginArtifactRepositories(java.util.List) */ public void setPluginArtifactRepositories( List list ) { this.pluginArtifactRepositories = list; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getPluginArtifactRepositories() */ public List getPluginArtifactRepositories() { return pluginArtifactRepositories; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getDistributionManagementArtifactRepository() */ public ArtifactRepository getDistributionManagementArtifactRepository() { return null; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getPluginRepositories() */ public List getPluginRepositories() { return Collections.singletonList( "" ); } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setActiveProfiles(java.util.List) */ public void setActiveProfiles( List list ) { activeProfiles = list; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getActiveProfiles() */ public List getActiveProfiles() { return activeProfiles; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#addAttachedArtifact(org.apache.maven.artifact.Artifact) */ public void addAttachedArtifact( Artifact theArtifact ) { if ( attachedArtifacts == null ) { this.attachedArtifacts = Collections.singletonList( theArtifact ); } else { attachedArtifacts.add( theArtifact ); } } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getAttachedArtifacts() */ public List getAttachedArtifacts() { return attachedArtifacts; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getGoalConfiguration(java.lang.String, java.lang.String, * java.lang.String, java.lang.String) */ public Xpp3Dom getGoalConfiguration( String string, String string1, String string2, String string3 ) { return null; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getReportConfiguration(java.lang.String, java.lang.String, * java.lang.String) */ public Xpp3Dom getReportConfiguration( String string, String string1, String string2 ) { return null; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getExecutionProject() */ public MavenProject getExecutionProject() { return null; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setExecutionProject(org.apache.maven.project.MavenProject) */ public void setExecutionProject( MavenProject mavenProject ) { } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#writeModel(java.io.Writer) */ public void writeModel( Writer writer ) throws IOException { } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#writeOriginalModel(java.io.Writer) */ public void writeOriginalModel( Writer writer ) throws IOException { } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getDependencyArtifacts() */ public Set getDependencyArtifacts() { return dependencyArtifacts; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setDependencyArtifacts(java.util.Set) */ public void setDependencyArtifacts( Set set ) { this.dependencyArtifacts = set; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setReleaseArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) */ public void setReleaseArtifactRepository( ArtifactRepository artifactRepository ) { // this.releaseArtifactRepository = artifactRepository; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setSnapshotArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) */ public void setSnapshotArtifactRepository( ArtifactRepository artifactRepository ) { // this.snapshotArtifactRepository = artifactRepository; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setOriginalModel(org.apache.maven.model.Model) */ public void setOriginalModel( Model model ) { this.originalModel = model; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getOriginalModel() */ public Model getOriginalModel() { return originalModel; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getBuildExtensions() */ public List getBuildExtensions() { return Collections.singletonList( "" ); } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#createArtifacts(org.apache.maven.artifact.factory.ArtifactFactory, * java.lang.String, org.apache.maven.artifact.resolver.filter.ArtifactFilter) */ public Set createArtifacts( ArtifactFactory artifactFactory, String string, ArtifactFilter artifactFilter ) throws InvalidDependencyVersionException { return Collections.EMPTY_SET; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#addProjectReference(org.apache.maven.project.MavenProject) */ public void addProjectReference( MavenProject mavenProject ) { } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#attachArtifact(java.lang.String, java.lang.String, java.io.File) */ public void attachArtifact( String string, String string1, File theFile ) { } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getProperties() */ public Properties getProperties() { return this.properties; } /** * Sets the property. * * @param key the key * @param value the value */ public void setProperty( String key, String value ) { properties.setProperty( key, value ); } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getFilters() */ public List getFilters() { return Collections.singletonList( "" ); } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getProjectReferences() */ public Map getProjectReferences() { return Collections.singletonMap( "", "" ); } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#isExecutionRoot() */ public boolean isExecutionRoot() { return executionRoot; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#setExecutionRoot(boolean) */ public void setExecutionRoot( boolean b ) { this.executionRoot = b; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#getDefaultGoal() */ public String getDefaultGoal() { return defaultGoal; } /* * (non-Javadoc) * * @see org.apache.maven.project.MavenProject#replaceWithActiveArtifact(org.apache.maven.artifact.Artifact) */ public Artifact replaceWithActiveArtifact( Artifact theArtifact ) { return null; } } MockRuntimeInformation.java000066400000000000000000000027121205711263400356760ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.execution.RuntimeInformation; /** * Just a mock object hard coded to return version 2.0.5 * * @author Brian Fox */ public class MockRuntimeInformation implements RuntimeInformation { /* * (non-Javadoc) * * @see org.apache.maven.execution.RuntimeInformation#getApplicationVersion() */ public ArtifactVersion getApplicationVersion() { return new DefaultArtifactVersion( "2.0.5" ); } } TestAbstractVersionEnforcer.java000066400000000000000000000166271205711263400367020ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import junit.framework.TestCase; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugin.logging.SystemStreamLog; // TODO: Auto-generated Javadoc /** * The Class TestAbstractVersionEnforcer. * * @author Brian Fox */ public class TestAbstractVersionEnforcer extends TestCase { /** * Test contains version. * * @throws InvalidVersionSpecificationException the invalid version specification exception */ public void testContainsVersion() throws InvalidVersionSpecificationException { ArtifactVersion version = new DefaultArtifactVersion( "2.0.5" ); // test ranges assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[2.0.5,)" ), version ) ); assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[2.0.4,)" ), version ) ); assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[2.0.4,2.0.5]" ), version ) ); assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[2.0.4,2.0.6]" ), version ) ); assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[2.0.4,2.0.6)" ), version ) ); assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[2.0,)" ), version ) ); assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[2.0.0,)" ), version ) ); // not matching versions assertFalse( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[2.0.4,2.0.5)" ), version ) ); assertFalse( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[2.0.6,)" ), version ) ); assertFalse( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "(2.0.5,)" ), version ) ); // test singular versions -> 2.0.5 == [2.0.5,) or x >= 2.0.5 assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "2.0" ), version ) ); assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "2.0.4" ), version ) ); assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "2.0.5" ), version ) ); assertFalse( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "2.0.6" ), version ) ); version = new DefaultArtifactVersion( "1.5.0-7" ); assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[1.5.0,)" ), version ) ); assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[1.5,1.6)" ), version ) ); version = new DefaultArtifactVersion( RequireJavaVersion.normalizeJDKVersion( "1.5.0-07" ) ); assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[1.5.0,)" ), version ) ); assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[1.5,1.6)" ), version ) ); //MENFORCER-50 version = new DefaultArtifactVersion ("2.1.0-M1-RC12"); assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[2.1.0-M1-RC12,)" ), version ) ); assertFalse( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[2.1.0-M1,)" ), version ) ); } /** * Enforce false. * * @param rule the rule * @param log the log * @param var the var * @param range the range * @param version the version */ private void enforceFalse( AbstractVersionEnforcer rule, Log log, String var, String range, ArtifactVersion version ) { try { rule.enforceVersion( log, var, range, version ); fail( "Expected to receive EnforcerRuleException because:" + version + " is not contained by " + range ); } catch ( Exception e ) { if ( e instanceof EnforcerRuleException ) { // log.info( "Caught Expected Exception: " + // e.getLocalizedMessage() ); } else { fail( "Received wrong exception. Expected EnforcerRuleExeption. Received:" + e.toString() ); } } } /** * Test enforce version. */ public void testEnforceVersion() { RequireMavenVersion rule = new RequireMavenVersion(); ArtifactVersion version = new DefaultArtifactVersion( "2.0.5" ); SystemStreamLog log = new SystemStreamLog(); // test ranges // not matching versions try { rule.enforceVersion( log, "test", "[2.0.5,)", version ); rule.enforceVersion( log, "test", "[2.0.4,)", version ); rule.enforceVersion( log, "test", "[2.0.4,2.0.5]", version ); rule.enforceVersion( log, "test", "[2.0.4,2.0.6]", version ); rule.enforceVersion( log, "test", "[2.0.4,2.0.6)", version ); rule.enforceVersion( log, "test", "[2.0,)", version ); rule.enforceVersion( log, "test", "[2.0.0,)", version ); // test singular versions -> 2.0.5 == [2.0.5,) or x >= 2.0.5 rule.enforceVersion( log, "test", "2.0", version ); rule.enforceVersion( log, "test", "2.0.4", version ); rule.enforceVersion( log, "test", "2.0.5", version ); } catch ( Exception e ) { fail( "No Exception expected. Caught:" + e.getLocalizedMessage() ); } enforceFalse( rule, log, "test", "[2.0.6,)", version ); enforceFalse( rule, log, "test", "(2.0.5,)", version ); enforceFalse( rule, log, "test", "2.0.6", version ); enforceFalse( rule, log, "test", "[2.0.4,2.0.5)", version ); // make sure to handle the invalid range specification enforceFalse( rule, log, "test", "[[2.0.4,2.0.5)", version ); } } TestAlwaysFail.java000066400000000000000000000027061205711263400341320ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import junit.framework.TestCase; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; /** * Test AlwaysFail rule. * @author Ben Lidgey * @see AlwaysFail */ public class TestAlwaysFail extends TestCase { public void testExecute() { final AlwaysFail rule = new AlwaysFail(); try { // execute rule -- should throw EnforcerRuleException rule.execute( EnforcerTestUtils.getHelper() ); fail( "Should throw EnforcerRuleException" ); } catch ( EnforcerRuleException e ) { assertTrue( true ); } } } TestAlwaysPass.java000066400000000000000000000027161205711263400341660ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import junit.framework.TestCase; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; /** * Test AlwaysPass rule. * @author Ben Lidgey * @see AlwaysPass */ public class TestAlwaysPass extends TestCase { public void testExecute() { final AlwaysPass rule = new AlwaysPass(); try { // execute rule -- should NOT throw EnforcerRuleException rule.execute( EnforcerTestUtils.getHelper() ); assertTrue( true ); } catch ( EnforcerRuleException e ) { fail( "Should NOT throw EnforcerRuleException" ); } } } TestBannedDependencies.java000066400000000000000000000135141205711263400355730ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.IOException; import java.util.ArrayList; import junit.framework.TestCase; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.apache.maven.plugin.testing.ArtifactStubFactory; // TODO: Auto-generated Javadoc /** * The Class TestBannedDependencies. * * @author Brian Fox */ public class TestBannedDependencies extends TestCase { /** * Test rule. * * @throws IOException Signals that an I/O exception has occurred. */ public void testRule() throws IOException { ArtifactStubFactory factory = new ArtifactStubFactory(); MockProject project = new MockProject(); EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project ); project.setArtifacts( factory.getMixedArtifacts() ); project.setDependencyArtifacts( factory.getScopedArtifacts() ); BannedDependencies rule = new BannedDependencies(); ArrayList excludes = new ArrayList(); rule.setSearchTransitive( false ); // test whole name excludes.add( "testGroupId:release:1.0" ); rule.setExcludes( excludes ); execute( rule, helper, false ); // test group:artifact excludes.clear(); excludes.add( "testGroupId:release" ); execute( rule, helper, false ); // test group excludes.clear(); excludes.add( "testGroupId" ); execute( rule, helper, false ); // now check one that should be found in direct // dependencies excludes.clear(); excludes.add( "g:compile:1.0" ); execute( rule, helper, true ); rule.setSearchTransitive( true ); // whole name excludes.clear(); excludes.add( "testGroupId:release:1.0" ); execute( rule, helper, true ); // group:artifact excludes.clear(); excludes.add( "testGroupId:release" ); execute( rule, helper, true ); // group excludes.clear(); excludes.add( "testGroupId" ); execute( rule, helper, true ); // now check wildcards excludes.clear(); excludes.add( "*:release" ); execute( rule, helper, true ); // now check wildcards excludes.clear(); excludes.add( "*:*:1.0" ); execute( rule, helper, true ); // now check wildcards excludes.clear(); excludes.add( "*:release:*" ); execute( rule, helper, true ); // now check wildcards excludes.clear(); excludes.add( "*:release:1.2" ); execute( rule, helper, false ); // now check multiple excludes excludes.add( "*:release:*" ); execute( rule, helper, true ); // now check space trimming excludes.clear(); excludes.add( " testGroupId : release : 1.0 " ); execute( rule, helper, true ); // now check weirdness excludes.clear(); excludes.add( ":::" ); // null entry, won't match anything execute( rule, helper, false ); } /** * Test includes. * * @throws IOException Signals that an I/O exception has occurred. */ public void testIncludes() throws IOException { ArtifactStubFactory factory = new ArtifactStubFactory(); MockProject project = new MockProject(); EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project ); project.setArtifacts( factory.getMixedArtifacts() ); project.setDependencyArtifacts( factory.getScopedArtifacts() ); BannedDependencies rule = new BannedDependencies(); ArrayList excludes = new ArrayList(); ArrayList includes = new ArrayList(); rule.setSearchTransitive( false ); excludes.add( "*" ); includes.add( "*" ); rule.setExcludes( excludes ); rule.setIncludes( includes ); execute( rule, helper, false ); excludes.clear(); excludes.add( "*:runtime" ); rule.setExcludes( excludes ); execute( rule, helper, false ); includes.clear(); includes.add( "*:test" ); rule.setIncludes( includes ); execute( rule, helper, true ); } /** * Simpler wrapper to execute and deal with the expected result. * * @param rule the rule * @param helper the helper * @param shouldFail the should fail */ private void execute( BannedDependencies rule, EnforcerRuleHelper helper, boolean shouldFail ) { try { rule.message = null; rule.execute( helper ); if ( shouldFail ) { fail( "Exception expected." ); } } catch ( EnforcerRuleException e ) { if ( !shouldFail ) { fail( "No Exception expected:" + e.getLocalizedMessage() ); } // helper.getLog().debug(e.getMessage()); } } } TestEvaluateBeanshell.java000066400000000000000000000115451205711263400354630ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import junit.framework.TestCase; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.easymock.MockControl; /** * The Class TestEvaluateBeanshell. * * @author hugonnem */ public class TestEvaluateBeanshell extends TestCase { private MockProject project; public void setUp() { project = new MockProject(); project.setProperty( "env", "\"This is a test.\"" ); } /** * Test rule. */ public void testRulePass() throws EnforcerRuleException, ExpressionEvaluationException { EvaluateBeanshell rule = new EvaluateBeanshell(); // this property should not be set rule.condition = "${env} == \"This is a test.\""; rule.message = "We have a variable : ${env}"; EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project ); rule.execute( helper ); } public void testRuleFail() throws EnforcerRuleException, ExpressionEvaluationException { EvaluateBeanshell rule = new EvaluateBeanshell(); // this property should be set by the surefire // plugin rule.condition = "${env} == null"; rule.message = "We have a variable : ${env}"; try { EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project ); rule.execute( helper ); fail( "Expected an exception." ); } catch ( EnforcerRuleException e ) { assertEquals( e.getLocalizedMessage(), rule.message ); } } public void testRuleFailNoMessage() throws EnforcerRuleException, ExpressionEvaluationException { EvaluateBeanshell rule = new EvaluateBeanshell(); // this property should be set by the surefire // plugin rule.condition = "${env} == null"; try { EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project ); rule.execute( helper ); fail( "Expected an exception." ); } catch ( EnforcerRuleException e ) { assertEquals( e.getLocalizedMessage(), rule.message ); assertTrue( e.getLocalizedMessage().length() > 0 ); } } public void testRuleInvalidExpression() throws EnforcerRuleException, ExpressionEvaluationException { EvaluateBeanshell rule = new EvaluateBeanshell(); rule.condition = "${env} == null"; rule.message = "We have a variable : ${env}"; MockControl evalControl = MockControl.createControl( ExpressionEvaluator.class ); try { ExpressionEvaluator eval = (ExpressionEvaluator) evalControl.getMock(); eval.evaluate( rule.condition ); evalControl.expectAndDefaultThrow( null, new ExpressionEvaluationException( "expected error" ) ); evalControl.replay(); EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project, eval ); rule.execute( helper ); fail( "Expected an exception." ); } catch ( EnforcerRuleException e ) { assertFalse( e.getLocalizedMessage().equals( rule.message ) ); } evalControl.verify(); } public void testRuleInvalidBeanshell() throws EnforcerRuleException, ExpressionEvaluationException { EvaluateBeanshell rule = new EvaluateBeanshell(); rule.condition = "this is not valid beanshell"; rule.message = "We have a variable : ${env}"; try { EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project ); rule.execute( helper ); fail( "Expected an exception." ); } catch ( EnforcerRuleException e ) { assertFalse( e.getLocalizedMessage().equals( rule.message ) ); } } } TestMavenVersion.java000066400000000000000000000042771205711263400345170ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import junit.framework.TestCase; import org.apache.commons.lang.SystemUtils; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; // TODO: Auto-generated Javadoc /** * The Class TestMavenVersion. * * @author Brian Fox */ public class TestMavenVersion extends TestCase { /** * Test rule. * * @throws EnforcerRuleException the enforcer rule exception */ public void testRule() throws EnforcerRuleException { RequireMavenVersion rule = new RequireMavenVersion(); rule.setVersion( "2.0.5" ); EnforcerRuleHelper helper = EnforcerTestUtils.getHelper(); // test the singular version rule.execute( helper ); // exclude this version rule.setVersion( "(2.0.5" ); try { rule.execute( helper ); fail( "Expected an exception." ); } catch ( EnforcerRuleException e ) { // expected to catch this. } // this shouldn't crash rule.setVersion( SystemUtils.JAVA_VERSION_TRIMMED ); rule.execute( helper ); } /** * Test id. */ public void testId() { RequireMavenVersion rule = new RequireMavenVersion(); rule.getCacheId(); } } TestNoSnapshots.java000066400000000000000000000043631205711263400343560ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.IOException; import junit.framework.TestCase; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.apache.maven.plugin.testing.ArtifactStubFactory; import org.apache.maven.plugins.enforcer.utils.TestEnforcerRuleUtils; /** * The Class TestNoSnapshots. * * @author Brian Fox */ public class TestNoSnapshots extends TestCase { /** * Test rule. * * @throws IOException Signals that an I/O exception has occurred. */ public void testRule() throws IOException { ArtifactStubFactory factory = new ArtifactStubFactory(); MockProject project = new MockProject(); EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project ); project.setArtifacts( factory.getMixedArtifacts() ); project.setDependencyArtifacts( factory.getScopedArtifacts() ); NoSnapshots rule = new NoSnapshots(); rule.setSearchTransitive( false ); TestEnforcerRuleUtils.execute( rule, helper, false ); rule.setSearchTransitive( true ); TestEnforcerRuleUtils.execute( rule, helper, true ); project.setArtifact( factory.getSnapshotArtifact() ); TestEnforcerRuleUtils.execute( rule, helper, true ); } /** * Test id. */ public void testId() { NoSnapshots rule = new NoSnapshots(); rule.getCacheId(); } } TestRequireFilesDontExist.java000066400000000000000000000074611205711263400363420ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.File; import java.io.IOException; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import junit.framework.TestCase; /** * Test the "require files don't exist" rule. * * @author Brian Fox */ public class TestRequireFilesDontExist extends TestCase { RequireFilesDontExist rule = new RequireFilesDontExist(); public void testFileExists() throws EnforcerRuleException, IOException { File f = File.createTempFile( "enforcer", "tmp" ); f.deleteOnExit(); rule.files = new File[] { f }; try { rule.execute( EnforcerTestUtils.getHelper() ); fail( "Expected an Exception." ); } catch ( EnforcerRuleException e ) { assertTrue( true ); } f.delete(); } public void testEmptyFile() throws EnforcerRuleException, IOException { rule.files = new File[] { null }; try { rule.execute( EnforcerTestUtils.getHelper() ); fail( "Should get exception" ); } catch ( EnforcerRuleException e ) { assertTrue( true ); } } public void testEmptyFileAllowNull() throws EnforcerRuleException, IOException { rule.files = new File[] { null }; rule.allowNulls = true; try { rule.execute( EnforcerTestUtils.getHelper() ); } catch ( EnforcerRuleException e ) { fail( "Unexpected Exception:" + e.getLocalizedMessage() ); } } public void testEmptyFileList() throws EnforcerRuleException, IOException { rule.files = new File[] {}; assertEquals( 0, rule.files.length ); try { rule.execute( EnforcerTestUtils.getHelper() ); fail( "Should get exception" ); } catch ( EnforcerRuleException e ) { assertTrue( true ); } } public void testEmptyFileListAllowNull() throws EnforcerRuleException, IOException { rule.files = new File[] {}; assertEquals( 0, rule.files.length ); rule.allowNulls = true; try { rule.execute( EnforcerTestUtils.getHelper() ); } catch ( EnforcerRuleException e ) { fail( "Unexpected Exception:" + e.getLocalizedMessage() ); } } public void testFileDoesNotExist() throws EnforcerRuleException, IOException { File f = File.createTempFile( "enforcer", "tmp" ); f.delete(); assertTrue( !f.exists() ); rule.files = new File[] { f }; rule.execute( EnforcerTestUtils.getHelper() ); } /** * Test id. */ public void testId() { rule.getCacheId(); } } TestRequireFilesExist.java000066400000000000000000000072101205711263400355050ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.File; import java.io.IOException; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import junit.framework.TestCase; /** * Test the "require files exist" rule. * * @author Brett Porter */ public class TestRequireFilesExist extends TestCase { RequireFilesExist rule = new RequireFilesExist(); public void testFileExists() throws EnforcerRuleException, IOException { File f = File.createTempFile( "enforcer", "tmp" ); f.deleteOnExit(); rule.files = new File[] { f }; rule.execute( EnforcerTestUtils.getHelper() ); f.delete(); } public void testEmptyFile() throws EnforcerRuleException, IOException { rule.files = new File[] { null }; try { rule.execute( EnforcerTestUtils.getHelper() ); fail( "Should get exception" ); } catch ( EnforcerRuleException e ) { assertTrue( true ); } } public void testEmptyFileAllowNull() throws EnforcerRuleException, IOException { rule.files = new File[] { null }; rule.allowNulls = true; try { rule.execute( EnforcerTestUtils.getHelper() ); } catch ( EnforcerRuleException e ) { fail( "Unexpected Exception:" + e.getLocalizedMessage() ); } } public void testEmptyFileList() throws EnforcerRuleException, IOException { rule.files = new File[] {}; assertEquals(0,rule.files.length); try { rule.execute( EnforcerTestUtils.getHelper() ); fail( "Should get exception" ); } catch ( EnforcerRuleException e ) { assertTrue( true ); } } public void testEmptyFileListAllowNull() throws EnforcerRuleException, IOException { rule.files = new File[] {}; assertEquals(0,rule.files.length); rule.allowNulls = true; try { rule.execute( EnforcerTestUtils.getHelper() ); } catch ( EnforcerRuleException e ) { fail( "Unexpected Exception:" + e.getLocalizedMessage() ); } } public void testFileDoesNotExist() throws EnforcerRuleException, IOException { File f = File.createTempFile( "enforcer", "tmp" ); f.delete(); assertTrue(!f.exists()); rule.files = new File[] { f }; try { rule.execute( EnforcerTestUtils.getHelper() ); fail( "Should get exception" ); } catch ( EnforcerRuleException e ) { assertTrue( true ); } } /** * Test id. */ public void testId() { rule.getCacheId(); } } TestRequireFilesSize.java000066400000000000000000000123071205711263400353260ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import org.apache.maven.artifact.Artifact; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.plugin.testing.ArtifactStubFactory; import junit.framework.TestCase; /** * Test the "require files exist" rule. * * @author Brian Fox */ public class TestRequireFilesSize extends TestCase { RequireFilesSize rule = new RequireFilesSize(); public void testFileExists() throws EnforcerRuleException, IOException { File f = File.createTempFile( "enforcer", "tmp" ); f.deleteOnExit(); rule.files = new File[] { f }; rule.execute( EnforcerTestUtils.getHelper() ); f.delete(); } public void testEmptyFile() throws EnforcerRuleException, IOException { rule.files = new File[] { null }; try { rule.execute( EnforcerTestUtils.getHelper() ); fail( "Should get exception" ); } catch ( EnforcerRuleException e ) { assertTrue( true ); } } public void testEmptyFileAllowNull() throws EnforcerRuleException, IOException { rule.files = new File[] { null }; rule.allowNulls = true; try { rule.execute( EnforcerTestUtils.getHelper() ); } catch ( EnforcerRuleException e ) { fail( "Unexpected Exception:" + e.getLocalizedMessage() ); } } public void testEmptyFileList() throws EnforcerRuleException, IOException { rule.files = new File[] {}; assertEquals( 0, rule.files.length ); MockProject project = new MockProject(); File f = File.createTempFile( "enforcer", "tmp" ); f.deleteOnExit(); ArtifactStubFactory factory = new ArtifactStubFactory(); Artifact a = factory.getReleaseArtifact(); a.setFile( f ); project.setArtifact(a); // sanity check the mockProject assertSame( f, project.getArtifact().getFile() ); rule.execute( EnforcerTestUtils.getHelper(project) ); } public void testFileDoesNotExist() throws EnforcerRuleException, IOException { File f = File.createTempFile( "enforcer", "tmp" ); f.delete(); assertTrue( !f.exists() ); rule.files = new File[] { f }; try { rule.execute( EnforcerTestUtils.getHelper() ); fail( "Should get exception" ); } catch ( EnforcerRuleException e ) { assertTrue( true ); } } public void testFileTooSmall() throws EnforcerRuleException, IOException { File f = File.createTempFile( "enforcer", "tmp" ); f.deleteOnExit(); rule.files = new File[] { f }; rule.minsize = 10; try { rule.execute( EnforcerTestUtils.getHelper() ); fail( "Should get exception" ); } catch ( EnforcerRuleException e ) { assertTrue( true ); } } public void testFileTooBig() throws EnforcerRuleException, IOException { File f = File.createTempFile( "enforcer", "tmp" ); f.deleteOnExit(); try { // Create file FileWriter fstream = new FileWriter( f ); BufferedWriter out = new BufferedWriter( fstream ); out.write( "123456789101112131415" ); // Close the output stream out.close(); fstream.close(); } catch ( Exception e ) {// Catch exception if any System.err.println( "Error: " + e.getMessage() ); } rule.files = new File[] { f }; rule.maxsize = 10; assertTrue( f.length() > 10 ); try { rule.execute( EnforcerTestUtils.getHelper() ); fail( "Should get exception" ); } catch ( EnforcerRuleException e ) { assertTrue( true ); } } /** * Test id. */ public void testId() { rule.getCacheId(); } } TestRequireJavaVersion.java000066400000000000000000000074011205711263400356570ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import junit.framework.TestCase; import org.apache.commons.lang.SystemUtils; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; // TODO: Auto-generated Javadoc /** * The Class TestRequireJavaVersion. * * @author Brian Fox */ public class TestRequireJavaVersion extends TestCase { /** * Test fix jdk version. */ public void testFixJDKVersion() { // test that we only take the first 3 versions for // comparision assertEquals( "1.5.0-11", RequireJavaVersion.normalizeJDKVersion( "1.5.0_11" ) ); assertEquals( "1.5.1", RequireJavaVersion.normalizeJDKVersion( "1.5.1" ) ); assertEquals( "1.5.2-1", RequireJavaVersion.normalizeJDKVersion( "1.5.2-1.b11" ) ); assertEquals( "1.5.3-11", RequireJavaVersion.normalizeJDKVersion( "1.5.3_11" ) ); assertEquals( "1.5.4-5", RequireJavaVersion.normalizeJDKVersion( "1.5.4.5_11" ) ); assertEquals( "1.5.5-6", RequireJavaVersion.normalizeJDKVersion( "1.5.5.6_11.2" ) ); // test for non-standard versions assertEquals( "1.5.0-11", RequireJavaVersion.normalizeJDKVersion( "1-5-0-11" ) ); assertEquals( "1.5.0-11", RequireJavaVersion.normalizeJDKVersion( "1-_5-_0-_11" ) ); assertEquals( "1.5.0-11", RequireJavaVersion.normalizeJDKVersion( "1_5_0_11" ) ); assertEquals( "1.5.0-7", RequireJavaVersion.normalizeJDKVersion( "1.5.0-07" ) ); assertEquals( "1.5.0-7", RequireJavaVersion.normalizeJDKVersion( "1.5.0-b7" ) ); assertEquals( "1.5.0-7", RequireJavaVersion.normalizeJDKVersion( "1.5.0-;7" ) ); assertEquals( "1.6.0", RequireJavaVersion.normalizeJDKVersion( "1.6.0-dp" ) ); assertEquals( "1.6.0-2", RequireJavaVersion.normalizeJDKVersion( "1.6.0-dp2" ) ); } /** * Test rule. * * @throws EnforcerRuleException the enforcer rule exception */ public void testRule() throws EnforcerRuleException { String thisVersion = RequireJavaVersion.normalizeJDKVersion( SystemUtils.JAVA_VERSION_TRIMMED ); RequireJavaVersion rule = new RequireJavaVersion(); rule.setVersion( thisVersion ); EnforcerRuleHelper helper = EnforcerTestUtils.getHelper(); // test the singular version rule.execute( helper ); // exclude this version rule.setVersion( "(" + thisVersion ); try { rule.execute( helper ); fail( "Expected an exception." ); } catch ( EnforcerRuleException e ) { // expected to catch this. } // this shouldn't crash rule.setVersion( SystemUtils.JAVA_VERSION_TRIMMED ); rule.execute( helper ); } /** * Test id. */ public void testId() { RequireJavaVersion rule = new RequireJavaVersion(); rule.getCacheId(); } } TestRequireNoRepositories.java000066400000000000000000000173151205711263400364210ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.Collections; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.codehaus.plexus.PlexusTestCase; /** * Test the "require no repositories" rule. * * @author Brett Porter */ public class TestRequireNoRepositories extends PlexusTestCase { private EnforcerRuleHelper helper; private RequireNoRepositories rule; private MockProject project; public void setUp() throws Exception { super.setUp(); rule = new RequireNoRepositories(); rule.message = "my message"; project = new MockProject(); project.setGroupId( "org.apache.maven.plugins.enforcer.test" ); project.setVersion( "1.0-SNAPSHOT" ); helper = EnforcerTestUtils.getHelper( project ); } public void testAllBannedNoRepositories() throws EnforcerRuleException { project.setArtifactId( "no-repositories-child" ); project.setBaseDir( getTestFile( "target/test-classes/requireNoRepositories/no-repositories/child" ) ); rule.execute( helper ); } public void testAllBannedWithRepositories() throws EnforcerRuleException { project.setArtifactId( "with-repositories-child" ); project.setBaseDir( getTestFile( "target/test-classes/requireNoRepositories/with-repositories/child" ) ); try { rule.execute( helper ); fail( "Should have exception" ); } catch ( EnforcerRuleException e ) { assertTrue( true ); } } public void testAllBannedWithAllowedRepositories() throws EnforcerRuleException { rule.allowedRepositories = Collections.singletonList( "repo" ); project.setArtifactId( "with-repositories-child" ); project.setBaseDir( getTestFile( "target/test-classes/requireNoRepositories/with-repositories/child" ) ); rule.execute( helper ); } public void testAllBannedWithAllowedPluginRepositories() throws EnforcerRuleException { rule.allowedPluginRepositories = Collections.singletonList( "repo" ); project.setArtifactId( "with-plugin-repositories-child" ); project.setBaseDir( getTestFile( "target/test-classes/requireNoRepositories/with-plugin-repositories/child" ) ); rule.execute( helper ); } public void testReposNotBannedNoRepositories() throws EnforcerRuleException { rule.banRepositories = false; project.setArtifactId( "no-repositories-child" ); project.setBaseDir( getTestFile( "target/test-classes/requireNoRepositories/no-repositories/child" ) ); rule.execute( helper ); } public void testReposNotBannedWithRepositories() throws EnforcerRuleException { rule.banRepositories = false; project.setArtifactId( "with-repositories-child" ); project.setBaseDir( getTestFile( "target/test-classes/requireNoRepositories/with-repositories/child" ) ); rule.execute( helper ); } public void testReposNotBannedWithPluginRepositories() throws EnforcerRuleException { rule.banRepositories = false; project.setArtifactId( "with-plugin-repositories-child" ); project.setBaseDir( getTestFile( "target/test-classes/requireNoRepositories/with-plugin-repositories/child" ) ); try { rule.execute( helper ); fail( "Should have exception" ); } catch ( EnforcerRuleException e ) { assertTrue( true ); } } public void testPluginReposNotBannedNoRepositories() throws EnforcerRuleException { rule.banPluginRepositories = false; project.setArtifactId( "no-repositories-child" ); project.setBaseDir( getTestFile( "target/test-classes/requireNoRepositories/no-repositories/child" ) ); rule.execute( helper ); } public void testPluginReposNotBannedWithRepositories() throws EnforcerRuleException { rule.banPluginRepositories = false; project.setArtifactId( "with-repositories-child" ); project.setBaseDir( getTestFile( "target/test-classes/requireNoRepositories/with-repositories/child" ) ); try { rule.execute( helper ); fail( "Should have exception" ); } catch ( EnforcerRuleException e ) { assertTrue( true ); } } public void testPluginReposNotBannedWithPluginRepositories() throws EnforcerRuleException { rule.banPluginRepositories = false; project.setArtifactId( "with-plugin-repositories-child" ); project.setBaseDir( getTestFile( "target/test-classes/requireNoRepositories/with-plugin-repositories/child" ) ); rule.execute( helper ); } public void testReposNotAllowedWithSnapshotRepositories() throws EnforcerRuleException { rule.allowSnapshotRepositories = true; project.setArtifactId( "snapshot-plugin-repositories-child" ); project.setBaseDir( getTestFile( "target/test-classes/requireNoRepositories/snapshot-plugin-repositories/child" ) ); try { rule.execute( helper ); fail( "Should have exception" ); } catch ( EnforcerRuleException e ) { assertTrue( true ); } } public void testReposAllowedWithSnapshotRepositories() throws EnforcerRuleException { rule.allowSnapshotRepositories = true; project.setArtifactId( "snapshot-repositories-child" ); project.setBaseDir( getTestFile( "target/test-classes/requireNoRepositories/snapshot-repositories/child" ) ); rule.execute( helper ); } public void testPluginReposNotAllowedWithSnapshotRepositories() throws EnforcerRuleException { rule.allowSnapshotPluginRepositories = true; project.setArtifactId( "snapshot-repositories-child" ); project.setBaseDir( getTestFile( "target/test-classes/requireNoRepositories/snapshot-repositories/child" ) ); try { rule.execute( helper ); fail( "Should have exception" ); } catch ( EnforcerRuleException e ) { assertTrue( true ); } } public void testPluginReposAllowedWithSnapshotPluginRepositories() throws EnforcerRuleException { rule.allowSnapshotPluginRepositories = true; project.setArtifactId( "snapshot-plugin-repositories-child" ); project.setBaseDir( getTestFile( "target/test-classes/requireNoRepositories/snapshot-plugin-repositories/child" ) ); rule.execute( helper ); } /** * Test id. */ public void testId() { RequireNoRepositories rule = new RequireNoRepositories(); rule.getCacheId(); } } TestRequireOS.java000066400000000000000000000070111205711263400337460ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.Iterator; import junit.framework.TestCase; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugin.logging.SystemStreamLog; import org.codehaus.plexus.util.Os; // TODO: Auto-generated Javadoc /** * Exhaustively check the OS mojo. * * @author Brian Fox */ public class TestRequireOS extends TestCase { /** * Test os. */ public void testOS() { Log log = new SystemStreamLog(); RequireOS rule = new RequireOS(); rule.displayOSInfo( log, true ); Iterator iter = Os.getValidFamilies().iterator(); String validFamily = null; String invalidFamily = null; while ( iter.hasNext() ) { String fam = (String) iter.next(); if ( !Os.isFamily( fam ) ) { invalidFamily = fam; break; } } validFamily = Os.OS_FAMILY; log.info( "Testing Mojo Using Valid Family: " + validFamily + " Invalid Family: " + invalidFamily ); rule.setFamily( validFamily ); assertTrue( rule.isAllowed() ); rule.setFamily( invalidFamily ); assertFalse( rule.isAllowed() ); rule.setFamily( "!" + invalidFamily ); assertTrue( rule.isAllowed() ); rule.setFamily( "junk" ); try { rule.execute( EnforcerTestUtils.getHelper() ); fail( "Expected MojoExecution Exception becuase of invalid family type" ); } catch ( EnforcerRuleException e ) { log.info( "Caught Expected Exception:" + e.getLocalizedMessage() ); } rule.setFamily( null ); rule.setArch( Os.OS_ARCH ); assertTrue( rule.isAllowed() ); rule.setArch( "somecrazyarch" ); assertFalse( rule.isAllowed() ); rule.setArch( "!somecrazyarch" ); assertTrue( rule.isAllowed() ); rule.setArch( null ); rule.setName( Os.OS_NAME ); assertTrue( rule.isAllowed() ); rule.setName( "somecrazyname" ); assertFalse( rule.isAllowed() ); rule.setName( "!somecrazyname" ); assertTrue( rule.isAllowed() ); rule.setName( null ); rule.setVersion( Os.OS_VERSION ); assertTrue( rule.isAllowed() ); rule.setVersion( "somecrazyversion" ); assertFalse( rule.isAllowed() ); rule.setVersion( "!somecrazyversion" ); assertTrue( rule.isAllowed() ); } /** * Test id. */ public void testId() { RequireOS rule = new RequireOS(); rule.getCacheId(); } } TestRequirePluginVersions.java000066400000000000000000000445111205711263400364220ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Set; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.apache.maven.model.Plugin; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.apache.maven.plugins.enforcer.utils.EnforcerRuleUtils; import org.apache.maven.plugins.enforcer.utils.PluginWrapper; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; // TODO: Auto-generated Javadoc /** * The Class TestRequirePluginVersions. * * @author Brian Fox */ public class TestRequirePluginVersions extends AbstractMojoTestCase { /** * Test has version specified. */ public void testHasVersionSpecified() { Plugin source = new Plugin(); source.setArtifactId( "foo" ); source.setGroupId( "group" ); // setup the plugins. I'm setting up the foo group // with a few bogus entries and then a real one. // this is to test that the list is exhaustively // searched for versions before giving up. // banLatest/Release will fail if it is found // anywhere in the list List plugins = new ArrayList(); plugins.add( EnforcerTestUtils.newPlugin( "group", "a-artifact", "1.0" ) ); plugins.add( EnforcerTestUtils.newPlugin( "group", "foo", null ) ); plugins.add( EnforcerTestUtils.newPlugin( "group", "foo", "" ) ); plugins.add( EnforcerTestUtils.newPlugin( "group", "b-artifact", "1.0" ) ); plugins.add( EnforcerTestUtils.newPlugin( "group", "foo", "1.0" ) ); plugins.add( EnforcerTestUtils.newPlugin( "group", "c-artifact", "LATEST" ) ); plugins.add( EnforcerTestUtils.newPlugin( "group", "c-artifact", "1.0" ) ); plugins.add( EnforcerTestUtils.newPlugin( "group", "d-artifact", "RELEASE" ) ); plugins.add( EnforcerTestUtils.newPlugin( "group", "d-artifact", "1.0" ) ); plugins.add( EnforcerTestUtils.newPlugin( "group", "e-artifact", "1.0" ) ); plugins.add( EnforcerTestUtils.newPlugin( "group", "e-artifact", "RELEASE" ) ); plugins.add( EnforcerTestUtils.newPlugin( "group", "f-artifact", "1.0" ) ); plugins.add( EnforcerTestUtils.newPlugin( "group", "f-artifact", "LATEST" ) ); plugins.add( EnforcerTestUtils.newPlugin( "group", "f-artifact", "1.0-SNAPSHOT" ) ); plugins.add( EnforcerTestUtils.newPlugin( "group", "g-artifact", "1.0-12345678.123456-1" ) ); plugins = PluginWrapper.addAll( plugins, "unit" ); RequirePluginVersions rule = new RequirePluginVersions(); rule.setBanLatest( false ); rule.setBanRelease( false ); rule.setBanSnapshots( false ); EnforcerRuleHelper helper = EnforcerTestUtils.getHelper(); assertTrue( rule.hasValidVersionSpecified( helper, source, plugins ) ); // check that LATEST is allowed source.setArtifactId( "c-artifact" ); assertTrue( rule.hasValidVersionSpecified( helper, source, plugins ) ); // check that LATEST is banned rule.setBanLatest( true ); assertFalse( rule.hasValidVersionSpecified( helper, source, plugins ) ); // check that LATEST is exhausively checked rule.setBanSnapshots( false ); source.setArtifactId( "f-artifact" ); assertFalse( rule.hasValidVersionSpecified( helper, source, plugins ) ); rule.setBanLatest( false ); rule.setBanSnapshots( true ); assertFalse( rule.hasValidVersionSpecified( helper, source, plugins ) ); // check that TIMESTAMP is allowed rule.setBanTimestamps( false ); source.setArtifactId( "g-artifact" ); assertTrue( rule.hasValidVersionSpecified( helper, source, plugins ) ); // check that RELEASE is allowed source.setArtifactId( "d-artifact" ); assertTrue( rule.hasValidVersionSpecified( helper, source, plugins ) ); // check that RELEASE is banned rule.setBanRelease( true ); assertFalse( rule.hasValidVersionSpecified( helper, source, plugins ) ); // check that RELEASE is exhaustively checked source.setArtifactId( "e-artifact" ); assertFalse( rule.hasValidVersionSpecified( helper, source, plugins ) ); } /** * Test has version specified with properties. */ public void testHasVersionSpecifiedWithProperties() { Plugin source = new Plugin(); source.setGroupId( "group" ); // setup the plugins. List plugins = new ArrayList(); plugins.add( EnforcerTestUtils.newPlugin( "group", "a-artifact", "1.0-${SNAPSHOT}" ) ); plugins.add( EnforcerTestUtils.newPlugin( "group", "b-artifact", "${1.0}" ) ); plugins.add( EnforcerTestUtils.newPlugin( "group", "c-artifact", "${LATEST}" ) ); plugins.add( EnforcerTestUtils.newPlugin( "group", "d-artifact", "${RELEASE}" ) ); plugins.add( EnforcerTestUtils.newPlugin( "group", "e-artifact", "${}" ) ); plugins.add( EnforcerTestUtils.newPlugin( "group", "f-artifact", "${ }" ) ); plugins = PluginWrapper.addAll( plugins, "unit" ); RequirePluginVersions rule = new RequirePluginVersions(); rule.setBanLatest( false ); rule.setBanRelease( false ); rule.setBanSnapshots( false ); EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( true ); source.setArtifactId( "a-artifact" ); assertTrue( rule.hasValidVersionSpecified( helper, source, plugins ) ); source.setArtifactId( "b-artifact" ); assertTrue( rule.hasValidVersionSpecified( helper, source, plugins ) ); source.setArtifactId( "c-artifact" ); assertTrue( rule.hasValidVersionSpecified( helper, source, plugins ) ); source.setArtifactId( "d-artifact" ); assertTrue( rule.hasValidVersionSpecified( helper, source, plugins ) ); // this one checks empty property values source.setArtifactId( "e-artifact" ); assertFalse( rule.hasValidVersionSpecified( helper, source, plugins ) ); // this one checks empty property values source.setArtifactId( "f-artifact" ); assertFalse( rule.hasValidVersionSpecified( helper, source, plugins ) ); rule.setBanLatest( true ); source.setArtifactId( "c-artifact" ); assertFalse( rule.hasValidVersionSpecified( helper, source, plugins ) ); rule.setBanRelease( true ); source.setArtifactId( "d-artifact" ); assertFalse( rule.hasValidVersionSpecified( helper, source, plugins ) ); rule.setBanSnapshots( true ); source.setArtifactId( "a-artifact" ); assertFalse( rule.hasValidVersionSpecified( helper, source, plugins ) ); // release versions should pass everything source.setArtifactId( "b-artifact" ); assertTrue( rule.hasValidVersionSpecified( helper, source, plugins ) ); } /** * Test get all plugins. * * @throws ArtifactResolutionException the artifact resolution exception * @throws ArtifactNotFoundException the artifact not found exception * @throws IOException Signals that an I/O exception has occurred. * @throws XmlPullParserException the xml pull parser exception */ public void testGetAllPlugins() throws ArtifactResolutionException, ArtifactNotFoundException, IOException, XmlPullParserException { RequirePluginVersions rule = new RequirePluginVersions(); String path = "target/test-classes/requirePluginVersions/getPomRecursively/b/c"; StringUtils.replace( path, "/", File.separator ); File projectDir = new File( getBasedir(), path ); MockProject project = new MockProject(); project.setArtifactId( "c" ); project.setGroupId( "group" ); project.setVersion( "1.0" ); project.setBaseDir( projectDir ); rule.setUtils( new EnforcerRuleUtils( EnforcerTestUtils.getHelper( project ) ) ); List plugins = rule.getAllPluginEntries( project ); // there should be 3 assertEquals( 3, plugins.size() ); } /** * Test get additional plugins null. * * @throws MojoExecutionException the mojo execution exception */ public void testGetAdditionalPluginsNull() throws MojoExecutionException { RequirePluginVersions rule = new RequirePluginVersions(); rule.addAdditionalPlugins( null, null ); } /** * Test get additional plugins invalid format. */ public void testGetAdditionalPluginsInvalidFormat() { RequirePluginVersions rule = new RequirePluginVersions(); List additional = new ArrayList(); // invalid format (not enough sections) additional.add( "group" ); Set plugins = new HashSet(); try { rule.addAdditionalPlugins( plugins, additional ); fail( "Expected Exception because the format is invalid" ); } catch ( MojoExecutionException e ) { } // invalid format (too many sections) additional.clear(); additional.add( "group:i:i" ); try { rule.addAdditionalPlugins( plugins, additional ); fail( "Expected Exception because the format is invalid" ); } catch ( MojoExecutionException e ) { } } /** * Test get additional plugins empty set. * * @throws MojoExecutionException the mojo execution exception */ public void testGetAdditionalPluginsEmptySet() throws MojoExecutionException { RequirePluginVersions rule = new RequirePluginVersions(); Set plugins = new HashSet(); plugins.add( EnforcerTestUtils.newPlugin( "group", "a-artifact", "1.0" ) ); plugins.add( EnforcerTestUtils.newPlugin( "group", "foo", null ) ); plugins.add( EnforcerTestUtils.newPlugin( "group", "foo2", "" ) ); List additional = new ArrayList(); additional.add( "group:a-artifact" ); additional.add( "group:another-artifact" ); // make sure a null set can be handled Set results = rule.addAdditionalPlugins( null, additional ); assertNotNull( results ); assertContainsPlugin( "group", "a-artifact", results ); assertContainsPlugin( "group", "another-artifact", results ); } /** * Test get additional plugins. * * @throws MojoExecutionException the mojo execution exception */ public void testGetAdditionalPlugins() throws MojoExecutionException { RequirePluginVersions rule = new RequirePluginVersions(); Set plugins = new HashSet(); plugins.add( EnforcerTestUtils.newPlugin( "group", "a-artifact", "1.0" ) ); plugins.add( EnforcerTestUtils.newPlugin( "group", "foo", null ) ); plugins.add( EnforcerTestUtils.newPlugin( "group", "foo2", "" ) ); List additional = new ArrayList(); additional.add( "group:a-artifact" ); additional.add( "group:another-artifact" ); Set results = rule.addAdditionalPlugins( plugins, additional ); // make sure only one new plugin has been added assertNotNull( results ); assertEquals( 4, results.size() ); assertContainsPlugin( "group", "a-artifact", results ); assertContainsPlugin( "group", "another-artifact", results ); } /** * Test remove Unchecked plugins. * * @throws MojoExecutionException the mojo execution exception */ public void testGetUncheckedPlugins() throws MojoExecutionException { RequirePluginVersions rule = new RequirePluginVersions(); Set plugins = new HashSet(); plugins.add( EnforcerTestUtils.newPlugin( "group", "a-artifact", "1.0" ) ); plugins.add( EnforcerTestUtils.newPlugin( "group", "foo", null ) ); plugins.add( EnforcerTestUtils.newPlugin( "group", "foo2", "" ) ); List unchecked = new ArrayList(); //intentionally inserting spaces to make sure they are handled correctly. unchecked.add( "group : a-artifact" ); Collection results = rule.removeUncheckedPlugins( unchecked, plugins ); // make sure only one new plugin has been added assertNotNull( results ); assertEquals( 2, results.size() ); assertContainsPlugin( "group", "foo", results ); assertContainsPlugin( "group", "foo2", results ); assertNotContainPlugin( "group", "a-artifact", results ); } /** * Test combining values from both lists */ public void testCombinePlugins() { RequirePluginVersions rule = new RequirePluginVersions(); Set plugins = new HashSet(); plugins.add( "group:a-artifact" ); plugins.add( "group:foo" ); plugins.add( "group:foo2" ); Collection results = rule.combineUncheckedPlugins( plugins, "group2:a,group3:b" ); // make sure only one new plugin has been added assertNotNull( results ); assertEquals( 5, results.size() ); assertTrue( results.contains( "group:foo") ); assertTrue( results.contains( "group:foo2") ); assertTrue( results.contains( "group:a-artifact") ); assertTrue( results.contains( "group2:a") ); assertTrue( results.contains( "group3:b") ); } /** * Test combining with an empty list */ public void testCombinePlugins1() { RequirePluginVersions rule = new RequirePluginVersions(); Set plugins = new HashSet(); Collection results = rule.combineUncheckedPlugins( plugins, "group2:a,group3:b" ); // make sure only one new plugin has been added assertNotNull( results ); assertEquals( 2, results.size() ); assertTrue( results.contains( "group2:a") ); assertTrue( results.contains( "group3:b") ); } /** * Test combining with a null list */ public void testCombinePlugins2() { RequirePluginVersions rule = new RequirePluginVersions(); Collection results = rule.combineUncheckedPlugins( null, "group2:a,group3:b" ); // make sure only one new plugin has been added assertNotNull( results ); assertEquals( 2, results.size() ); assertTrue( results.contains( "group2:a") ); assertTrue( results.contains( "group3:b") ); } /** * Test combining with an empty string */ public void testCombinePlugins3() { RequirePluginVersions rule = new RequirePluginVersions(); Set plugins = new HashSet(); plugins.add( "group:a-artifact" ); plugins.add( "group:foo" ); plugins.add( "group:foo2" ); Collection results = rule.combineUncheckedPlugins( plugins, "" ); assertNotNull( results ); assertEquals( 3, results.size() ); assertTrue( results.contains( "group:foo") ); assertTrue( results.contains( "group:foo2") ); assertTrue( results.contains( "group:a-artifact") ); } /** * Test combining with a null string */ public void testCombinePlugins4() { RequirePluginVersions rule = new RequirePluginVersions(); Set plugins = new HashSet(); plugins.add( "group:a-artifact" ); plugins.add( "group:foo" ); plugins.add( "group:foo2" ); Collection results = rule.combineUncheckedPlugins( plugins, null ); assertNotNull( results ); assertEquals( 3, results.size() ); assertTrue( results.contains( "group:foo") ); assertTrue( results.contains( "group:foo2") ); assertTrue( results.contains( "group:a-artifact") ); } /** * Test combining with an invalid plugin string */ public void testCombinePlugins5() { RequirePluginVersions rule = new RequirePluginVersions(); Set plugins = new HashSet(); plugins.add( "group:a-artifact" ); plugins.add( "group:foo" ); plugins.add( "group:foo2" ); Collection results = rule.combineUncheckedPlugins( plugins, "a" ); assertNotNull( results ); assertEquals( 4, results.size() ); assertTrue( results.contains( "group:foo") ); assertTrue( results.contains( "group:foo2") ); //this should be here, the checking of a valid plugin string happens in another method. assertTrue( results.contains( "a") ); } /** * Assert contains plugin. * * @param group the group * @param artifact the artifact * @param theSet the the set */ private void assertContainsPlugin( String group, String artifact, Collection theSet ) { Plugin p = new Plugin(); p.setGroupId( group ); p.setArtifactId( artifact ); assertTrue( theSet.contains( p ) ); } /** * Assert doesn't contain plugin. * * @param group the group * @param artifact the artifact * @param theSet the the set */ private void assertNotContainPlugin( String group, String artifact, Collection theSet ) { Plugin p = new Plugin(); p.setGroupId( group ); p.setArtifactId( artifact ); assertFalse( theSet.contains( p ) ); } /** * Test id. */ public void testId() { RequirePluginVersions rule = new RequirePluginVersions(); rule.getCacheId(); } } TestRequireProperty.java000066400000000000000000000065311205711263400352570ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import junit.framework.TestCase; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; // TODO: Auto-generated Javadoc /** * The Class TestRequireProperty. * * @author Paul Gier */ public class TestRequireProperty extends TestCase { /** * Test rule. * * @throws EnforcerRuleException the enforcer rule exception */ public void testRule() throws EnforcerRuleException { MockProject project = new MockProject(); project.setProperty( "testProp", "This is a test." ); EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project ); RequireProperty rule = new RequireProperty(); // this property should not be set rule.property = "testPropJunk"; try { rule.execute( helper ); fail( "Expected an exception." ); } catch ( EnforcerRuleException e ) { // expected to catch this. } // this property should be set by the surefire // plugin rule.property = "testProp"; try { rule.execute( helper ); } catch ( EnforcerRuleException e ) { fail( "This should not throw an exception" ); } } /** * Test rule with regex. * * @throws EnforcerRuleException the enforcer rule exception */ public void testRuleWithRegex() throws EnforcerRuleException { MockProject project = new MockProject(); project.setProperty( "testProp", "This is a test." ); EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project ); RequireProperty rule = new RequireProperty(); rule.property = "testProp"; // This expression should not match the property // value rule.regex = "[^abc]"; try { rule.execute( helper ); fail( "Expected an exception." ); } catch ( EnforcerRuleException e ) { // expected to catch this. } // this expr should match the property rule.regex = "[This].*[.]"; try { rule.execute( helper ); } catch ( EnforcerRuleException e ) { fail( "This should not throw an exception" ); } } /** * Test id. */ public void testId() { RequireProperty rule = new RequireProperty(); rule.getCacheId(); } } TestRequireReleaseDeps.java000066400000000000000000000061111205711263400356210ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.IOException; import junit.framework.TestCase; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.apache.maven.plugin.testing.ArtifactStubFactory; import org.apache.maven.plugins.enforcer.utils.TestEnforcerRuleUtils; // TODO: Auto-generated Javadoc /** * The Class TestNoSnapshots. * * @author Brian Fox */ public class TestRequireReleaseDeps extends TestCase { /** * Test rule. * * @throws IOException Signals that an I/O exception has occurred. */ public void testRule() throws IOException { ArtifactStubFactory factory = new ArtifactStubFactory(); MockProject project = new MockProject(); EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project ); project.setArtifacts( factory.getMixedArtifacts() ); project.setDependencyArtifacts( factory.getScopedArtifacts() ); RequireReleaseDeps rule = new RequireReleaseDeps(); rule.setSearchTransitive( false ); TestEnforcerRuleUtils.execute( rule, helper, false ); rule.setSearchTransitive( true ); TestEnforcerRuleUtils.execute( rule, helper, true ); // test onlyWhenRelease in each case project.setArtifact( factory.getSnapshotArtifact() ); TestEnforcerRuleUtils.execute( rule, helper, true ); rule.onlyWhenRelease = true; TestEnforcerRuleUtils.execute( rule, helper, false ); project.setArtifact( factory.getReleaseArtifact() ); TestEnforcerRuleUtils.execute( rule, helper, true ); MockProject parent = new MockProject(); parent.setArtifact( factory.getSnapshotArtifact() ); project.setParent( parent ); project.setArtifacts( null ); project.setDependencyArtifacts( null ); helper = EnforcerTestUtils.getHelper(project); rule.setFailWhenParentIsSnapshot( true ); TestEnforcerRuleUtils.execute( rule, helper, true ); rule.setFailWhenParentIsSnapshot( false ); TestEnforcerRuleUtils.execute( rule, helper, false ); } /** * Test id. */ public void testId() { RequireReleaseDeps rule = new RequireReleaseDeps(); rule.getCacheId(); } } TestRequireReleaseVersion.java000066400000000000000000000054671205711263400363700ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.IOException; import junit.framework.TestCase; import org.apache.maven.enforcer.rule.api.EnforcerRule; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.apache.maven.plugin.testing.ArtifactStubFactory; import org.apache.maven.plugins.enforcer.utils.TestEnforcerRuleUtils; // TODO: Auto-generated Javadoc /** * The Class TestRequireReleaseVersion. * * @author Brian Fox */ public class TestRequireReleaseVersion extends TestCase { /** * Test mojo. * * @throws IOException Signals that an I/O exception has occurred. */ public void testMojo() throws IOException { ArtifactStubFactory factory = new ArtifactStubFactory(); MockProject project = new MockProject(); EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project ); project.setArtifact( factory.getReleaseArtifact() ); EnforcerRule rule = new RequireReleaseVersion(); TestEnforcerRuleUtils.execute( rule, helper, false ); project.setArtifact( factory.getSnapshotArtifact() ); TestEnforcerRuleUtils.execute( rule, helper, true ); project.setArtifact( factory.getReleaseArtifact() ); MockProject parent = new MockProject(); parent.setArtifact( factory.getSnapshotArtifact() ); project.setParent( parent ); helper = EnforcerTestUtils.getHelper(project); ( (RequireReleaseVersion) rule ).setFailWhenParentIsSnapshot( true ); TestEnforcerRuleUtils.execute( rule, helper, true ); ( (RequireReleaseVersion) rule ).setFailWhenParentIsSnapshot( false ); TestEnforcerRuleUtils.execute( rule, helper, false ); } /** * Test cache. */ public void testCache() { EnforcerRule rule = new RequireReleaseVersion(); assertFalse( rule.isCacheable() ); assertFalse( rule.isResultValid( null ) ); assertEquals( "0", rule.getCacheId() ); } } maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/utils/000077500000000000000000000000001205711263400316055ustar00rootroot00000000000000MockEnforcerExpressionEvaluator.java000066400000000000000000000044331205711263400407150ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/utilspackage org.apache.maven.plugins.enforcer.utils; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.execution.MavenSession; import org.apache.maven.plugins.enforcer.EnforcerExpressionEvaluator; import org.apache.maven.project.MavenProject; import org.apache.maven.project.path.PathTranslator; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; // TODO: Auto-generated Javadoc /** * The Class MockEnforcerExpressionEvaluator. */ public class MockEnforcerExpressionEvaluator extends EnforcerExpressionEvaluator { /** * Instantiates a new mock enforcer expression evaluator. * * @param theContext the the context * @param thePathTranslator the the path translator * @param theProject the the project */ public MockEnforcerExpressionEvaluator( MavenSession theContext, PathTranslator thePathTranslator, MavenProject theProject ) { super( theContext, thePathTranslator, theProject ); // TODO Auto-generated constructor stub } /* * (non-Javadoc) * * @see org.apache.maven.plugin.PluginParameterExpressionEvaluator#evaluate(java.lang.String) */ public Object evaluate( String expr ) throws ExpressionEvaluationException { if ( expr != null ) { // just remove the ${ } and return the name as the value return expr.replaceAll( "\\$\\{|}", "" ); } else { return expr; } } } TestEnforcerRuleUtils.java000066400000000000000000000227641205711263400366600ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/utilspackage org.apache.maven.plugins.enforcer.utils; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.File; import java.io.IOException; import java.util.List; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.enforcer.rule.api.EnforcerRule; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.apache.maven.model.Model; import org.apache.maven.model.Parent; import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.apache.maven.plugins.enforcer.EnforcerTestUtils; import org.apache.maven.plugins.enforcer.MockProject; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; // TODO: Auto-generated Javadoc /** * The Class TestEnforcerRuleUtils. * * @author Brian Fox */ public class TestEnforcerRuleUtils extends AbstractMojoTestCase { /** * Test check if model matches. */ public void testCheckIfModelMatches() { EnforcerRuleUtils utils = new EnforcerRuleUtils( EnforcerTestUtils.getHelper() ); Model model = new Model(); model.setArtifactId( "" ); model.setGroupId( "" ); model.setVersion( "" ); // should generate internal NPE on the parent, but // will still // compare the raw values assertTrue( utils.checkIfModelMatches( "", "", "", model ) ); assertFalse( utils.checkIfModelMatches( "", "", "1.0", model ) ); // now setup a parent Parent parent = new Parent(); parent.setArtifactId( "foo" ); parent.setGroupId( "foo-group" ); parent.setVersion( "1.0" ); model.setParent( parent ); // should NOT pickup the parent artifact assertFalse( utils.checkIfModelMatches( "foo-group", "foo", "1.0", model ) ); // check that the version and group are inherited // from the parent. assertTrue( utils.checkIfModelMatches( "foo-group", "", "1.0", model ) ); // check handling of nulls assertFalse( utils.checkIfModelMatches( "foo-group", null, "1.0", model ) ); } /** * Test get models recursively bottom. * * @throws ArtifactResolutionException the artifact resolution exception * @throws ArtifactNotFoundException the artifact not found exception * @throws IOException Signals that an I/O exception has occurred. * @throws XmlPullParserException the xml pull parser exception */ public void testGetModelsRecursivelyBottom() throws ArtifactResolutionException, ArtifactNotFoundException, IOException, XmlPullParserException { String path = "target/test-classes/requirePluginVersions/getPomRecursively/b/c"; StringUtils.replace( path, "/", File.separator ); File pom = new File( getBasedir() + File.separator + path, "pom.xml" ); EnforcerRuleUtils utils = new EnforcerRuleUtils( EnforcerTestUtils.getHelper() ); List models = utils.getModelsRecursively( "group", "c", "1.0", pom ); // there should be 3 assertEquals( 3, models.size() ); // now make sure they are all there Model m = new Model(); m.setGroupId( "group" ); m.setVersion( "1.0" ); m.setArtifactId( "c" ); models.contains( m ); m.setArtifactId( "b" ); models.contains( m ); m.setArtifactId( "a" ); models.contains( m ); } /** * Test get models recursively top. * * @throws ArtifactResolutionException the artifact resolution exception * @throws ArtifactNotFoundException the artifact not found exception * @throws IOException Signals that an I/O exception has occurred. * @throws XmlPullParserException the xml pull parser exception */ public void testGetModelsRecursivelyTop() throws ArtifactResolutionException, ArtifactNotFoundException, IOException, XmlPullParserException { String path = "target/test-classes/requirePluginVersions/getPomRecursively"; StringUtils.replace( path, "/", File.separator ); File pom = new File( getBasedir() + File.separator + path, "pom.xml" ); EnforcerRuleUtils utils = new EnforcerRuleUtils( EnforcerTestUtils.getHelper() ); List models = utils.getModelsRecursively( "group", "a", "1.0", pom ); // there should be 1 assertEquals( 1, models.size() ); // now make sure they are all there Model m = new Model(); m.setGroupId( "group" ); m.setVersion( "1.0" ); m.setArtifactId( "a" ); models.contains( m ); } public void testGetModelsRecursivelyParentExpression() throws ArtifactResolutionException, ArtifactNotFoundException, IOException, XmlPullParserException { String path = "target/test-classes/requirePluginVersions/parentExpression/child"; StringUtils.replace( path, "/", File.separator ); File pom = new File( getBasedir() + File.separator + path, "pom.xml" ); // bit backwards - the project here should really be the one read in the first stage of getModelsRecursively MockProject parent = new MockProject(); parent.setGroupId( "org.apache.maven.plugins.enforcer.test" ); parent.setArtifactId( "parent" ); parent.setVersion( "1.0-SNAPSHOT" ); MockProject project = new MockProject(); project.setParent( parent ); EnforcerRuleUtils utils = new EnforcerRuleUtils( EnforcerTestUtils.getHelper( project ) ); List models = utils.getModelsRecursively( "org.apache.maven.plugins.enforcer.test", "child", "1.0-SNAPSHOT", pom ); // there should be 2 assertEquals( 2, models.size() ); } public void testGetModelsRecursivelyParentRelativePath() throws ArtifactResolutionException, ArtifactNotFoundException, IOException, XmlPullParserException { String path = "target/test-classes/requirePluginVersions/parentRelativePath"; StringUtils.replace( path, "/", File.separator ); File pom = new File( getBasedir() + File.separator + path, "pom.xml" ); // bit backwards - the project here should really be the one read in the first stage of getModelsRecursively MockProject parent = new MockProject(); parent.setGroupId( "org.apache.maven.plugins.enforcer.test" ); parent.setArtifactId( "parent" ); parent.setVersion( "1.0-SNAPSHOT" ); MockProject project = new MockProject(); project.setParent( parent ); EnforcerRuleUtils utils = new EnforcerRuleUtils( EnforcerTestUtils.getHelper( project ) ); List models = utils.getModelsRecursively( "org.apache.maven.plugins.enforcer.test", "aggregate", "1.0-SNAPSHOT", pom ); // there should be 2 assertEquals( 2, models.size() ); } public void testGetModelsRecursivelyParentRelativePathDirectory() throws ArtifactResolutionException, ArtifactNotFoundException, IOException, XmlPullParserException { String path = "target/test-classes/requirePluginVersions/parentRelativePathDirectory"; StringUtils.replace( path, "/", File.separator ); File pom = new File( getBasedir() + File.separator + path, "pom.xml" ); // bit backwards - the project here should really be the one read in the first stage of getModelsRecursively MockProject parent = new MockProject(); parent.setGroupId( "org.apache.maven.plugins.enforcer.test" ); parent.setArtifactId( "parent" ); parent.setVersion( "1.0-SNAPSHOT" ); MockProject project = new MockProject(); project.setParent( parent ); EnforcerRuleUtils utils = new EnforcerRuleUtils( EnforcerTestUtils.getHelper( project ) ); List models = utils.getModelsRecursively( "org.apache.maven.plugins.enforcer.test", "aggregate", "1.0-SNAPSHOT", pom ); // there should be 2 assertEquals( 2, models.size() ); } /** * Simpler wrapper to execute and deal with the expected result. * * @param rule the rule * @param helper the helper * @param shouldFail the should fail */ public static void execute( EnforcerRule rule, EnforcerRuleHelper helper, boolean shouldFail ) { try { rule.execute( helper ); if ( shouldFail ) { fail( "Exception expected." ); } } catch ( EnforcerRuleException e ) { if ( !shouldFail ) { fail( "No Exception expected:" + e.getLocalizedMessage() ); } helper.getLog().debug( e.getMessage() ); } } } TestMockEnforcerExpressionEvaluator.java000066400000000000000000000045441205711263400415600ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/utilspackage org.apache.maven.plugins.enforcer.utils; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import junit.framework.TestCase; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugins.enforcer.EnforcerExpressionEvaluator; import org.apache.maven.plugins.enforcer.EnforcerTestUtils; import org.apache.maven.plugins.enforcer.MockPathTranslator; import org.apache.maven.plugins.enforcer.MockProject; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; // TODO: Auto-generated Javadoc /** * The Class TestMockEnforcerExpressionEvaluator. */ public class TestMockEnforcerExpressionEvaluator extends TestCase { /** * Test evaluate. */ public void testEvaluate() { MavenSession session = EnforcerTestUtils.getMavenSession(); EnforcerExpressionEvaluator ev = new MockEnforcerExpressionEvaluator( session, new MockPathTranslator(), new MockProject() ); assertMatch( ev, "SNAPSHOT" ); assertMatch( ev, "RELEASE" ); assertMatch( ev, "SNAPSHOT" ); assertMatch( ev, "LATEST" ); assertMatch( ev, "1.0" ); } /** * Assert match. * * @param ev the ev * @param exp the exp */ public void assertMatch( EnforcerExpressionEvaluator ev, String exp ) { // the mock enforcer should return the name of the expression as the value. try { assertEquals( exp, ev.evaluate( "${" + exp + "}" ) ); } catch ( ExpressionEvaluationException e ) { fail( e.getLocalizedMessage() ); } } } maven-enforcer-1.0.1/enforcer-rules/src/test/resources/000077500000000000000000000000001205711263400231345ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requireNoRepositories/000077500000000000000000000000001205711263400275155ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requireNoRepositories/no-repositories/000077500000000000000000000000001205711263400326565ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requireNoRepositories/no-repositories/child/000077500000000000000000000000001205711263400337415ustar00rootroot00000000000000pom.xml000066400000000000000000000003601205711263400351760ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requireNoRepositories/no-repositories/child org.apache.maven.plugins.enforcer.test no-repositories 1.0-SNAPSHOT no-repositories-child maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requireNoRepositories/no-repositories/pom.xml000066400000000000000000000002351205711263400341730ustar00rootroot00000000000000 org.apache.maven.plugins.enforcer.test no-repositories 1.0-SNAPSHOT snapshot-plugin-repositories/000077500000000000000000000000001205711263400353165ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requireNoRepositorieschild/000077500000000000000000000000001205711263400364015ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requireNoRepositories/snapshot-plugin-repositoriespom.xml000066400000000000000000000004121205711263400377130ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requireNoRepositories/snapshot-plugin-repositories/child org.apache.maven.plugins.enforcer.test snapshot-plugin-repositories 1.0-SNAPSHOT snapshot-plugin-repositories-child pom.xml000066400000000000000000000007161205711263400366370ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requireNoRepositories/snapshot-plugin-repositories org.apache.maven.plugins.enforcer.test snapshot-plugin-repositories 1.0-SNAPSHOT repo http://example.com/repo false true maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requireNoRepositories/snapshot-repositories/000077500000000000000000000000001205711263400341015ustar00rootroot00000000000000child/000077500000000000000000000000001205711263400351055ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requireNoRepositories/snapshot-repositoriespom.xml000066400000000000000000000003741205711263400364260ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requireNoRepositories/snapshot-repositories/child org.apache.maven.plugins.enforcer.test snapshot-repositories 1.0-SNAPSHOT snapshot-repositories-child pom.xml000066400000000000000000000006571205711263400353470ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requireNoRepositories/snapshot-repositories org.apache.maven.plugins.enforcer.test snapshot-repositories 1.0-SNAPSHOT repo http://example.com/repo false true with-plugin-repositories/000077500000000000000000000000001205711263400344325ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requireNoRepositorieschild/000077500000000000000000000000001205711263400355155ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requireNoRepositories/with-plugin-repositoriespom.xml000066400000000000000000000004021205711263400370260ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requireNoRepositories/with-plugin-repositories/child org.apache.maven.plugins.enforcer.test with-plugin-repositories 1.0-SNAPSHOT with-plugin-repositories-child pom.xml000066400000000000000000000005011205711263400357430ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requireNoRepositories/with-plugin-repositories org.apache.maven.plugins.enforcer.test with-plugin-repositories 1.0-SNAPSHOT repo http://example.com/repo maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requireNoRepositories/with-repositories/000077500000000000000000000000001205711263400332155ustar00rootroot00000000000000child/000077500000000000000000000000001205711263400342215ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requireNoRepositories/with-repositoriespom.xml000066400000000000000000000003641205711263400355410ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requireNoRepositories/with-repositories/child org.apache.maven.plugins.enforcer.test with-repositories 1.0-SNAPSHOT with-repositories-child pom.xml000066400000000000000000000004421205711263400344530ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requireNoRepositories/with-repositories org.apache.maven.plugins.enforcer.test with-repositories 1.0-SNAPSHOT repo http://example.com/repo maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requirePluginVersions/000077500000000000000000000000001205711263400275205ustar00rootroot00000000000000checkPluginPropertyVersion/000077500000000000000000000000001205711263400350105ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requirePluginVersionspom.xml000066400000000000000000000037161205711263400363340ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requirePluginVersions/checkPluginPropertyVersion 4.0.0 a group 1.0 2.2-SNAPSHOT RELEASE LATEST SNAPSHOT org.apache.maven.plugins maven-install-plugin ${my.latest} org.apache.maven.plugins maven-clean-plugin ${my.release} org.apache.maven.plugins maven-jar-plugin ${my.version} org.apache.maven.plugins maven-enforcer-plugin 1.0-${my.snap} enforce org.apache.maven.plugins:maven-enforcer-plugin checkPluginVersionProfile/000077500000000000000000000000001205711263400345645ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requirePluginVersionspom.xml000066400000000000000000000035261205711263400361070ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requirePluginVersions/checkPluginVersionProfile 4.0.0 a group 1.0 2.2-SNAPSHOT RELEASE LATEST SNAPSHOT org.apache.maven.plugins maven-enforcer-plugin 1.0-${my.snap} enforce none prof org.apache.maven.plugins maven-site-plugin RELEASE site validate maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requirePluginVersions/getPomRecursively/000077500000000000000000000000001205711263400332105ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requirePluginVersions/getPomRecursively/b/000077500000000000000000000000001205711263400334315ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requirePluginVersions/getPomRecursively/b/c/000077500000000000000000000000001205711263400336535ustar00rootroot00000000000000pom.xml000066400000000000000000000005551205711263400351160ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requirePluginVersions/getPomRecursively/b/c b group 1.0 c org.apache.maven.plugins maven-deploy-plugin pom.xml000066400000000000000000000004731205711263400346730ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requirePluginVersions/getPomRecursively/b a group 1.0 b org.apache.maven.plugins maven-clean-plugin pom.xml000066400000000000000000000004141205711263400344450ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requirePluginVersions/getPomRecursively a group 1.0 org.apache.maven.plugins maven-dependency-plugin maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requirePluginVersions/parentExpression/000077500000000000000000000000001205711263400330715ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requirePluginVersions/parentExpression/child/000077500000000000000000000000001205711263400341545ustar00rootroot00000000000000pom.xml000066400000000000000000000006161205711263400354150ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requirePluginVersions/parentExpression/child 4.0.0 org.apache.maven.plugins.enforcer.test parentExpression 1.0-SNAPSHOT ${project.parent.groupId} child ${project.parent.version} MENFORCER-30 pom.xml000066400000000000000000000003551205711263400343320ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requirePluginVersions/parentExpression 4.0.0 org.apache.maven.plugins.enforcer.test parentExpression 1.0-SNAPSHOT MENFORCER-30 maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requirePluginVersions/parentRelativePath/000077500000000000000000000000001205711263400333225ustar00rootroot00000000000000parent/000077500000000000000000000000001205711263400345345ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requirePluginVersions/parentRelativePathpom.xml000066400000000000000000000003311205711263400360460ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requirePluginVersions/parentRelativePath/parent 4.0.0 org.apache.maven.plugins.enforcer.test parent 1.0-SNAPSHOT pom pom.xml000066400000000000000000000006161205711263400345630ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requirePluginVersions/parentRelativePath 4.0.0 org.apache.maven.plugins.enforcer.test parent 1.0-SNAPSHOT parent/pom.xml org.apache.maven.plugins.enforcer.test aggregate 1.0-SNAPSHOT parentRelativePathDirectory/000077500000000000000000000000001205711263400351305ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requirePluginVersionsparent/000077500000000000000000000000001205711263400364215ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requirePluginVersions/parentRelativePathDirectorypom.xml000066400000000000000000000003311205711263400377330ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requirePluginVersions/parentRelativePathDirectory/parent 4.0.0 org.apache.maven.plugins.enforcer.test parent 1.0-SNAPSHOT pom pom.xml000066400000000000000000000006061205711263400364470ustar00rootroot00000000000000maven-enforcer-1.0.1/enforcer-rules/src/test/resources/requirePluginVersions/parentRelativePathDirectory 4.0.0 org.apache.maven.plugins.enforcer.test parent 1.0-SNAPSHOT parent org.apache.maven.plugins.enforcer.test aggregate 1.0-SNAPSHOT maven-enforcer-1.0.1/maven-enforcer-plugin/000077500000000000000000000000001205711263400206245ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/LICENSE000066400000000000000000000520351205711263400216360ustar00rootroot00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS maven-enforcer-1.0.1/maven-enforcer-plugin/NOTICE000066400000000000000000000005601205711263400215310ustar00rootroot00000000000000Maven Dependency Plugin Copyright 1999-2006 The Apache Software Foundation This product includes software developed at The Apache Software Foundation (http://www.apache.org/). Portions of this software utilize the Plexus Container, API, and Components. Copyright the Codehaus. The original software is available from http://plexus.codehaus.org/maven-enforcer-1.0.1/maven-enforcer-plugin/pom.xml000066400000000000000000000146031205711263400221450ustar00rootroot00000000000000 4.0.0 org.apache.maven.enforcer enforcer 1.0.1 org.apache.maven.plugins maven-enforcer-plugin 1.0.1 maven-plugin Maven Enforcer Plugin The Loving Iron Fist of Maven http://maven.apache.org/plugins/maven-enforcer-plugin/ 2007 brianf Brian Fox brianf@apache.org Lead Developer 5 2.0.6 JIRA http://jira.codehaus.org/browse/MENFORCER apache.website ${site.deploy.url}/plugins/maven-enforcer-plugin org.apache.maven maven-artifact org.apache.maven maven-plugin-api org.apache.maven maven-project org.apache.maven maven-core org.codehaus.plexus plexus-utils commons-lang commons-lang org.apache.maven.enforcer enforcer-api org.apache.maven.enforcer enforcer-rules org.apache.maven.enforcer enforcer-rules test-jar org.apache.maven.shared maven-plugin-testing-harness org.codehaus.mojo cobertura-maven-plugin 2.2 clean clean maven-site-plugin scp://people.apache.org/www/maven.apache.org/plugins/${project.artifactId}-${project.version} org.apache.maven.plugins maven-plugin-plugin generated-helpmojo helpmojo ${basedir}/src/main/resources org.apache.maven.plugins maven-plugin-plugin ${maven.plugin.plugin.version} run-its maven-invoker-plugin 1.5 true ${project.build.directory}/it setup verify ${project.build.directory}/local-repo src/it/settings.xml validate integration-test install run maven-enforcer-1.0.1/maven-enforcer-plugin/src/000077500000000000000000000000001205711263400214135ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/000077500000000000000000000000001205711263400220275ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/always-fail/000077500000000000000000000000001205711263400242405ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/always-fail/invoker.properties000066400000000000000000000000361205711263400300320ustar00rootroot00000000000000invoker.buildResult = failure maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/always-fail/pom.xml000066400000000000000000000030321205711263400255530ustar00rootroot00000000000000 4.0.0 org.apache.maven.its.enforcer test 1.0 org.apache.maven.plugins maven-enforcer-plugin @project.version@ test enforce maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/always-pass/000077500000000000000000000000001205711263400242735ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/always-pass/pom.xml000066400000000000000000000030321205711263400256060ustar00rootroot00000000000000 4.0.0 org.apache.maven.its.enforcer test 1.0 org.apache.maven.plugins maven-enforcer-plugin @project.version@ test enforce maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/banned-dependencies-wildcards/000077500000000000000000000000001205711263400276545ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/banned-dependencies-wildcards/pom.xml000066400000000000000000000042351205711263400311750ustar00rootroot00000000000000 4.0.0 org.apache.maven.its.enforcer test 1.0 org.apache.maven.plugins maven-enforcer-plugin @project.version@ test enforce *:*:*:jar junit:*:*:*:test commons-logging commons-logging 1.1.1 pom junit junit 3.8.1 test maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/banned-dependencies/000077500000000000000000000000001205711263400257025ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/banned-dependencies/pom.xml000066400000000000000000000033111205711263400272150ustar00rootroot00000000000000 4.0.0 org.apache.maven.its.enforcer test 1.0 org.apache.maven.plugins maven-enforcer-plugin @project.version@ test enforce commons-logging:commons-logging maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/banned-plugins/000077500000000000000000000000001205711263400247355ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/banned-plugins/pom.xml000066400000000000000000000030751205711263400262570ustar00rootroot00000000000000 4.0.0 org.apache.maven.its.enforcer test 1.0 org.apache.maven.plugins maven-enforcer-plugin @project.version@ test enforce maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/builds_a_pom_noop/000077500000000000000000000000001205711263400255175ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/builds_a_pom_noop/module/000077500000000000000000000000001205711263400270045ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/builds_a_pom_noop/module/pom.xml000066400000000000000000000007521205711263400303250ustar00rootroot00000000000000 4.0.0 test TestParent 1.0-SNAPSHOT TestModule 1.0-SNAPSHOT maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/builds_a_pom_noop/pom.xml000066400000000000000000000017321205711263400270370ustar00rootroot00000000000000 4.0.0 test TestParent 1.0-SNAPSHOT pom org.apache.maven.plugins maven-enforcer-plugin @project.version@ enforce enforce maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/dependencies_converge/000077500000000000000000000000001205711263400263455ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/dependencies_converge/module/000077500000000000000000000000001205711263400276325ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/dependencies_converge/module/pom.xml000066400000000000000000000007521205711263400311530ustar00rootroot00000000000000 4.0.0 test TestParent 1.0-SNAPSHOT TestModule 1.0-SNAPSHOT maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/dependencies_converge/pom.xml000066400000000000000000000026661205711263400276740ustar00rootroot00000000000000 4.0.0 test TestParent 1.0 jar org.slf4j slf4j-jdk14 1.6.1 org.slf4j slf4j-nop 1.6.0 org.slf4j slf4j-api org.apache.maven.plugins maven-enforcer-plugin @project.version@ enforce enforce maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/dependencies_not_converging/000077500000000000000000000000001205711263400275565ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/dependencies_not_converging/invoker.properties000066400000000000000000000000331205711263400333450ustar00rootroot00000000000000invoker.buildResult=failuremaven-enforcer-1.0.1/maven-enforcer-plugin/src/it/dependencies_not_converging/module/000077500000000000000000000000001205711263400310435ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/dependencies_not_converging/module/pom.xml000066400000000000000000000007521205711263400323640ustar00rootroot00000000000000 4.0.0 test TestParent 1.0-SNAPSHOT TestModule 1.1-SNAPSHOT maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/dependencies_not_converging/pom.xml000066400000000000000000000024331205711263400310750ustar00rootroot00000000000000 4.0.0 test TestParent 1.0-SNAPSHOT jar org.slf4j slf4j-jdk14 1.6.1 org.slf4j slf4j-nop 1.6.0 org.apache.maven.plugins maven-enforcer-plugin @project.version@ enforce enforce maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/dependencies_not_converging_test_scope/000077500000000000000000000000001205711263400320065ustar00rootroot00000000000000invoker.properties000066400000000000000000000000331205711263400355160ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/dependencies_not_converging_test_scopeinvoker.buildResult=failuremaven-enforcer-1.0.1/maven-enforcer-plugin/src/it/dependencies_not_converging_test_scope/module/000077500000000000000000000000001205711263400332735ustar00rootroot00000000000000pom.xml000066400000000000000000000007521205711263400345350ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/dependencies_not_converging_test_scope/module 4.0.0 test TestParent 1.0-SNAPSHOT TestModule 1.1-SNAPSHOT maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/dependencies_not_converging_test_scope/pom.xml000066400000000000000000000024741205711263400333320ustar00rootroot00000000000000 4.0.0 test TestParent 1.0-SNAPSHOT jar org.slf4j slf4j-jdk14 1.6.1 org.slf4j slf4j-nop 1.6.0 test org.apache.maven.plugins maven-enforcer-plugin @project.version@ enforce enforce maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/evaluate-beanshell/000077500000000000000000000000001205711263400255705ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/evaluate-beanshell/pom.xml000066400000000000000000000032141205711263400271050ustar00rootroot00000000000000 4.0.0 org.apache.maven.its.enforcer test 1.0 org.apache.maven.plugins maven-enforcer-plugin @project.version@ test enforce ${project.artifactId} == test maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/pom.xml000066400000000000000000000052571205711263400233550ustar00rootroot00000000000000 4.0.0 org.apache.maven.plugins maven-enforcer-plugin-it1 1 jar org.apache.maven.shared maven-invoker 2.0.7-SNAPSHOT org.apache.maven.plugins maven-compiler-plugin 2.0.2 org.apache.maven.plugins maven-dependency-plugin 2.0-alpha-4 copy copy-dependencies org.apache.maven.plugins maven-enforcer-plugin 1.0-SNAPSHOT custom-rule custom-rule-sample 1.0 enforce [1.3,1.6] 2.0.8 You need 2.0.8! true !tandem rti.getApplicationVersion().getMajorVersion() == 2; org.apache.maven com.acme enforce validate maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/require-active-profile/000077500000000000000000000000001205711263400264125ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/require-active-profile/pom.xml000066400000000000000000000034271205711263400277350ustar00rootroot00000000000000 4.0.0 org.apache.maven.its.enforcer test 1.0 org.apache.maven.plugins maven-enforcer-plugin @project.version@ test enforce it it true maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/require-files-dont-exist/000077500000000000000000000000001205711263400266775ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/require-files-dont-exist/pom.xml000066400000000000000000000032671205711263400302240ustar00rootroot00000000000000 4.0.0 org.apache.maven.its.enforcer test 1.0 org.apache.maven.plugins maven-enforcer-plugin @project.version@ test enforce target/unwanted.txt maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/require-files-exist/000077500000000000000000000000001205711263400257355ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/require-files-exist/pom.xml000066400000000000000000000032431205711263400272540ustar00rootroot00000000000000 4.0.0 org.apache.maven.its.enforcer test 1.0 org.apache.maven.plugins maven-enforcer-plugin @project.version@ test enforce pom.xml maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/require-files-size/000077500000000000000000000000001205711263400255535ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/require-files-size/pom.xml000066400000000000000000000033651205711263400270770ustar00rootroot00000000000000 4.0.0 org.apache.maven.its.enforcer test 1.0 org.apache.maven.plugins maven-enforcer-plugin @project.version@ test enforce 10240 512 pom.xml maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/require-java-version/000077500000000000000000000000001205711263400261055ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/require-java-version/pom.xml000066400000000000000000000034731205711263400274310ustar00rootroot00000000000000 4.0.0 org.apache.maven.its.enforcer test 1.0 org.apache.maven.plugins maven-enforcer-plugin @project.version@ test enforce 1.4 [1.4,) maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/require-maven-version/000077500000000000000000000000001205711263400262725ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/require-maven-version/pom.xml000066400000000000000000000034771205711263400276220ustar00rootroot00000000000000 4.0.0 org.apache.maven.its.enforcer test 1.0 org.apache.maven.plugins maven-enforcer-plugin @project.version@ test enforce 2.0 [2.0,) maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/require-no-repositories/000077500000000000000000000000001205711263400266425ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/require-no-repositories/pom.xml000066400000000000000000000031151205711263400301570ustar00rootroot00000000000000 4.0.0 org.apache.maven.its.enforcer test 1.0 org.apache.maven.plugins maven-enforcer-plugin @project.version@ test enforce maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/require-plugin-versions-custom-packaging/000077500000000000000000000000001205711263400320775ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/require-plugin-versions-custom-packaging/pom.xml000066400000000000000000000046311205711263400334200ustar00rootroot00000000000000 4.0.0 org.apache.maven.its.enforcer test 1.0 maven-one-plugin org.apache.maven.plugins maven-one-plugin 1.2 true org.apache.maven.plugins maven-enforcer-plugin @project.version@ test enforce false org.apache.maven.plugins:maven-clean-plugin, org.apache.maven.plugins:maven-install-plugin, org.apache.maven.plugins:maven-deploy-plugin, org.apache.maven.plugins:maven-site-plugin, org.apache.maven.plugins:maven-resources-plugin, org.apache.maven.plugins:maven-compiler-plugin, org.apache.maven.plugins:maven-surefire-plugin maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/require-plugin-versions/000077500000000000000000000000001205711263400266455ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/require-plugin-versions/pom.xml000066400000000000000000000036661205711263400301750ustar00rootroot00000000000000 4.0.0 org.apache.maven.its.enforcer test 1.0 pom org.apache.maven.plugins maven-enforcer-plugin @project.version@ test enforce false org.apache.maven.plugins:maven-clean-plugin,org.apache.maven.plugins:maven-install-plugin,org.apache.maven.plugins:maven-deploy-plugin,org.apache.maven.plugins:maven-site-plugin maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/require-property/000077500000000000000000000000001205711263400253655ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/require-property/pom.xml000066400000000000000000000031601205711263400267020ustar00rootroot00000000000000 4.0.0 org.apache.maven.its.enforcer test 1.0 org.apache.maven.plugins maven-enforcer-plugin @project.version@ test enforce basedir maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/require-release-dependencies-excludes/000077500000000000000000000000001205711263400313575ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/require-release-dependencies-excludes/goals.txt000066400000000000000000000000101205711263400332140ustar00rootroot00000000000000validatemaven-enforcer-1.0.1/maven-enforcer-plugin/src/it/require-release-dependencies-excludes/pom.xml000066400000000000000000000023641205711263400327010ustar00rootroot00000000000000 4.0.0 org.apache.maven.enforcer.its requireReleaseDeps jar 1.0-SNAPSHOT org.apache.maven.plugins maven-enforcer-plugin @project.version@ enforce enforce No Snapshots Allowed! org.apache.maven.enforcer:enforcer-api org.apache.maven.enforcer enforcer-api @project.version@ maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/require-release-dependencies/000077500000000000000000000000001205711263400275455ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/require-release-dependencies/pom.xml000066400000000000000000000030421205711263400310610ustar00rootroot00000000000000 4.0.0 org.apache.maven.its.enforcer test 1.0 org.apache.maven.plugins maven-enforcer-plugin @project.version@ test enforce maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/require-release-version/000077500000000000000000000000001205711263400266045ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/require-release-version/pom.xml000066400000000000000000000030451205711263400301230ustar00rootroot00000000000000 4.0.0 org.apache.maven.its.enforcer test 1.0 org.apache.maven.plugins maven-enforcer-plugin @project.version@ test enforce maven-enforcer-1.0.1/maven-enforcer-plugin/src/it/settings.xml000066400000000000000000000031741205711263400244160ustar00rootroot00000000000000 it-repo true local.central @localRepositoryUrl@ true true local.central @localRepositoryUrl@ true true maven-enforcer-1.0.1/maven-enforcer-plugin/src/main/000077500000000000000000000000001205711263400223375ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/main/java/000077500000000000000000000000001205711263400232605ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/main/java/org/000077500000000000000000000000001205711263400240475ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/main/java/org/apache/000077500000000000000000000000001205711263400252705ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/main/java/org/apache/maven/000077500000000000000000000000001205711263400263765ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/000077500000000000000000000000001205711263400300575ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/000077500000000000000000000000001205711263400316625ustar00rootroot00000000000000DisplayInfoMojo.java000066400000000000000000000073311205711263400355200ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.commons.lang.SystemUtils; import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.RuntimeInformation; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.project.MavenProject; import org.apache.maven.project.path.PathTranslator; import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.context.Context; import org.codehaus.plexus.context.ContextException; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; /** * This goal displays the current platform information. * * @goal display-info * @author Brian Fox * @version $Id: DisplayInfoMojo.java 1127643 2011-05-25 19:24:38Z krosenvold $ * @threadSafe */ public class DisplayInfoMojo extends AbstractMojo implements Contextualizable { /** * Path Translator needed by the ExpressionEvaluator * * @component role="org.apache.maven.project.path.PathTranslator" */ protected PathTranslator translator; /** * The MavenSession * * @parameter default-value="${session}" * @readonly */ protected MavenSession session; /** * POM * * @parameter default-value="${project}" * @readonly * @required */ protected MavenProject project; // set by the contextualize method. Only way to get the // plugin's container in 2.0.x protected PlexusContainer container; public void contextualize ( Context context ) throws ContextException { container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); } /** * Entry point to the mojo */ public void execute () throws MojoExecutionException { try { EnforcerExpressionEvaluator evaluator = new EnforcerExpressionEvaluator( session, translator, project ); DefaultEnforcementRuleHelper helper = new DefaultEnforcementRuleHelper( session, evaluator, getLog(), container ); RuntimeInformation rti = (RuntimeInformation) helper.getComponent( RuntimeInformation.class ); getLog().info( "Maven Version: " + rti.getApplicationVersion() ); getLog().info( "JDK Version: " + SystemUtils.JAVA_VERSION + " normalized as: " + RequireJavaVersion.normalizeJDKVersion( SystemUtils.JAVA_VERSION_TRIMMED ) ); RequireOS os = new RequireOS(); os.displayOSInfo( getLog(), true ); } catch ( ComponentLookupException e ) { getLog().warn( "Unable to Lookup component: " + e.getLocalizedMessage() ); } } } EnforceMojo.java000066400000000000000000000253431205711263400346630ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.ArrayList; import java.util.Hashtable; import java.util.Iterator; import org.apache.maven.enforcer.rule.api.EnforcerRule; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; import org.apache.maven.project.path.PathTranslator; import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.context.Context; import org.codehaus.plexus.context.ContextException; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; /** * This goal executes the defined enforcer-rules once per * module. * * @requiresDependencyResolution test * @goal enforce * @phase validate * @threadSafe * @author Brian Fox * @version $Id: EnforceMojo.java 1127643 2011-05-25 19:24:38Z krosenvold $ */ public class EnforceMojo extends AbstractMojo implements Contextualizable { /** * Path Translator needed by the ExpressionEvaluator * * @component role="org.apache.maven.project.path.PathTranslator" */ protected PathTranslator translator; /** * The MavenSession * * @parameter expression="${session}" * @readonly */ protected MavenSession session; /** * POM * * @parameter expression="${project}" * @readonly * @required */ protected MavenProject project; /** * Flag to fail the build if a version check fails. * * @parameter expression="${enforcer.fail}" * default-value="true" */ protected boolean fail = true; /** * Flag to easily skip all checks * * @parameter expression="${enforcer.skip}" * default-value="false" */ protected boolean skip = false; /** * Fail on the first rule that doesn't pass * * @parameter expression="${enforcer.failFast}" * default-value="false" */ protected boolean failFast = false; /** * Array of objects that implement the EnforcerRule * interface to execute. * * @parameter * @required */ private EnforcerRule[] rules; /** * Use this flag to disable rule result caching. This will cause * all rules to execute on each project even if the rule indicates it can * safely be cached. * @parameter expression="${enforcer.ignoreCache}" * default-value="false" */ protected boolean ignoreCache = false; /** * This is a static variable used to persist the cached results across plugin invocations. */ protected static Hashtable cache = new Hashtable(); // set by the contextualize method. Only way to get the // plugin's container in 2.0.x protected PlexusContainer container; public void contextualize ( Context context ) throws ContextException { container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); } /** * Entry point to the mojo */ public void execute () throws MojoExecutionException { Log log = this.getLog(); EnforcerExpressionEvaluator evaluator = new EnforcerExpressionEvaluator( session, translator, project ); // the entire execution can be easily skipped if ( !skip ) { // list to store exceptions ArrayList list = new ArrayList(); // make sure the rules exist if ( rules != null && rules.length > 0 ) { String currentRule = "Unknown"; // create my helper EnforcerRuleHelper helper = new DefaultEnforcementRuleHelper( session, evaluator, log, container ); // if we are only warning, then disable // failFast if ( !fail ) { failFast = false; } // go through each rule for ( int i = 0; i < rules.length; i++ ) { // prevent against empty rules EnforcerRule rule = rules[i]; if ( rule != null ) { // store the current rule for // logging purposes currentRule = rule.getClass().getName(); log.debug( "Executing rule: " + currentRule ); try { if ( ignoreCache || shouldExecute( rule ) ) { // execute the rule //noinspection SynchronizationOnLocalVariableOrMethodParameter synchronized ( rule ) { rule.execute( helper ); } } } catch ( EnforcerRuleException e ) { // i can throw an exception // because failfast will be // false if fail is false. if ( failFast ) { throw new MojoExecutionException( currentRule + " failed with message:\n" + e.getMessage(), e ); } else { list.add( "Rule " + i + ": " + currentRule + " failed with message:\n" + e.getMessage() ); log.debug( "Adding failure due to exception", e ); } } } } // if we found anything if ( !list.isEmpty() ) { Iterator iter = list.iterator(); while ( iter.hasNext() ) { String failure = (String) iter.next(); log.warn( failure ); } if ( fail ) { throw new MojoExecutionException( "Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed." ); } } } else { throw new MojoExecutionException( "No rules are configured. Use the skip flag if you want to disable execution." ); } } else { log.info( "Skipping Rule Enforcement." ); } } /** * This method determines if a rule should execute based * on the cache * * @param rule * @return */ protected boolean shouldExecute ( EnforcerRule rule ) { if ( rule.isCacheable() ) { Log log = this.getLog(); log.debug( "Rule " + rule.getClass().getName() + " is cacheable." ); String key = rule.getClass().getName() + " " + rule.getCacheId(); if ( EnforceMojo.cache.containsKey( key ) ) { log.debug( "Key " + key + " was found in the cache" ); if ( rule.isResultValid( (EnforcerRule) cache.get( key ) ) ) { log.debug( "The cached results are still valid. Skipping the rule: "+rule.getClass().getName() ); return false; } } //add it to the cache of executed rules EnforceMojo.cache.put( key, rule ); } return true; } /** * @return the fail */ public boolean isFail () { return this.fail; } /** * @param theFail the fail to set */ public void setFail ( boolean theFail ) { this.fail = theFail; } /** * @return the rules */ public EnforcerRule[] getRules () { return this.rules; } /** * @param theRules the rules to set */ public void setRules ( EnforcerRule[] theRules ) { this.rules = theRules; } /** * @return the skip */ public boolean isSkip () { return this.skip; } /** * @param theSkip the skip to set */ public void setSkip ( boolean theSkip ) { this.skip = theSkip; } /** * @return the failFast */ public boolean isFailFast () { return this.failFast; } /** * @param theFailFast the failFast to set */ public void setFailFast ( boolean theFailFast ) { this.failFast = theFailFast; } /** * @return the project */ public MavenProject getProject () { return this.project; } /** * @param theProject the project to set */ public void setProject ( MavenProject theProject ) { this.project = theProject; } /** * @return the session */ public MavenSession getSession () { return this.session; } /** * @param theSession the session to set */ public void setSession ( MavenSession theSession ) { this.session = theSession; } /** * @return the translator */ public PathTranslator getTranslator () { return this.translator; } /** * @param theTranslator the translator to set */ public void setTranslator ( PathTranslator theTranslator ) { this.translator = theTranslator; } } EnforceOnceMojo.java000066400000000000000000000027251205711263400354670ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; import org.apache.maven.plugin.MojoExecutionException; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /** * This goal has been deprecated. * * @deprecated * @goal enforce-once * @phase validate * @requiresDependencyResolution test * @author Brian Fox * @version $Id: EnforceOnceMojo.java 694549 2008-09-11 23:55:34Z brianf $ */ public class EnforceOnceMojo extends EnforceMojo { public void execute() throws MojoExecutionException { this.getLog().warn( "enforcer:enforce-once is deprecated. Use enforcer:enforce instead. See MENFORCER-11/MENFORCER-12 for more information." ); super.execute(); } } maven-enforcer-1.0.1/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/util/000077500000000000000000000000001205711263400326375ustar00rootroot00000000000000EnforcerUtils.java000066400000000000000000000002311205711263400362030ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/utilpackage org.apache.maven.plugins.enforcer.util; /** * @author Brian Fox * */ public class EnforcerUtils { } maven-enforcer-1.0.1/maven-enforcer-plugin/src/site/000077500000000000000000000000001205711263400223575ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/site/apt/000077500000000000000000000000001205711263400231435ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/site/apt/index.apt000066400000000000000000000054571205711263400247730ustar00rootroot00000000000000~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ------ Introduction ------ Brian Fox ------ Mar 2007 ------ Maven Enforcer Plugin - The Loving Iron Fist of Maven\x99 The Enforcer plugin provides goals to control certain environmental constraints such as Maven version, JDK version and OS family along with many more standard rules and user created rules. * Goals Overview The Enforcer plugin has two goals: *{{{./enforce-mojo.html}enforcer:enforce}} executes rules for each project in a multi-project build. *{{{./display-info-mojo.html}enforcer:display-info}} display the current information as detected by the standard rules. * Usage General instructions on how to use the Enforcer Plugin can be found on the {{{./usage.html}usage page}}. Last but not least, users occasionally contribute additional examples, tips or errata to the {{{http://docs.codehaus.org/display/MAVENUSER/Enforcer+Plugin}plugin's wiki page}}. In case you still have questions regarding the plugin's usage, please have a look at the {{{./faq.html}FAQ}} and feel free to contact the {{{./mail-lists.html}user mailing list}}. The posts to the mailing list are archived and could already contain the answer to your question as part of an older thread. Hence, it is also worth browsing/searching the {{{./mail-lists.html}mail archive}}. If you feel like the plugin is missing a feature or has a defect, you can fill a feature request or bug report in our {{{./issue-tracking.html}issue tracker}}. When creating a new issue, please provide a comprehensive description of your concern. Especially for fixing bugs it is crucial that the developers can reproduce your problem. For this reason, entire debug logs, POMs or most preferably little demo projects attached to the issue are very much appreciated. Of course, patches are welcome, too. Contributors can check out the project from our {{{./source-repository.html}source repository}} and will find supplementary information in the {{{http://maven.apache.org/guides/development/guide-helping.html}guide to helping with Maven}}. maven-enforcer-1.0.1/maven-enforcer-plugin/src/site/apt/usage.apt.vm000066400000000000000000000076251205711263400254100ustar00rootroot00000000000000~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ------ Usage ------ Brian Fox ------ Mar 2007 ------ Usage Brief examples on how to use the enforcer goals. * Generic Plugin configuration information See the following links for information about including and configuring plugins in your project: *{{{http://maven.apache.org/guides/mini/guide-configuring-plugins.html}Configuring Plugins}} *{{{http://maven.apache.org/guides/plugin/guide-java-plugin-development.html}Plugin Development}} *{{{http://maven.apache.org/guides/introduction/introduction-to-plugin-prefix-mapping.html}Plugin Prefix}} [] * The <<>> and <<>> mojos These goals are meant to be bound to a lifecycle phase and configured in your <<>>. The enforcers execute the configured rules to check for certain constraints. The available standard rules are described {{{rules/index.html}here}}. Besides the rules to execute, these goals support three options: * {{{enforce-mojo.html#skip}skip}} - a quick way to skip checks via a profile or using <<<-Denforcer.skip=true>>> from the command line. * {{{enforce-mojo.html#fail}fail}} - if the goal should fail the build when a rule fails. The default is <<>>. If false, the errors will be logged as warnings. * {{{enforce-mojo.html#failFast}failFast}} - if the goal should stop checking after the first failure. The default is <<>>. [] Each rule to be executed should be added to the rules element along with the specific configuration for that rule. The <<>> goal executes against each project in a multi-project build. The <<>> goal executes just once per build. This is most effective for the standard rules because the Maven, Java and OS versions will not change between projects in the same build. Sample Plugin Configuration: +---+ [...] org.apache.maven.plugins maven-enforcer-plugin ${project.version} enforce-versions enforce 2.0.6 1.5 unix [...] +---+ * The <<>> mojo This goal is used to determine the current information as detected by the standard rules: +---+ mvn enforcer:display-info ... [enforcer:display-info] Maven Version: 2.0.6 JDK Version: 1.5.0_11 normalized as: 1.5.0-11 OS Info: Arch: x86 Family: windows Name: windows xp Version: 5.1 +---+ maven-enforcer-1.0.1/maven-enforcer-plugin/src/site/fml/000077500000000000000000000000001205711263400231355ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/site/fml/faq.fml000066400000000000000000000033671205711263400244150ustar00rootroot00000000000000 Why can't I just use the prerequisites tag in the pom?

The prerequisites tag was designed to be used by tools like plugins. It will work for regular projects, but it isn't inherited to their children. If it is set in a parent reactor, then Maven will do the check. However if one of the children are built, the check is not performed. The enforcer plugin is designed to allow centralized control over the build environment from a single "super-pom", and to allow greater flexibility in version specification by supporting ranges.

maven-enforcer-1.0.1/maven-enforcer-plugin/src/site/site.xml000066400000000000000000000034211205711263400240450ustar00rootroot00000000000000 maven-enforcer-1.0.1/maven-enforcer-plugin/src/test/000077500000000000000000000000001205711263400223725ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/test/java/000077500000000000000000000000001205711263400233135ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/test/java/org/000077500000000000000000000000001205711263400241025ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/test/java/org/apache/000077500000000000000000000000001205711263400253235ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/test/java/org/apache/maven/000077500000000000000000000000001205711263400264315ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/000077500000000000000000000000001205711263400301125ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/000077500000000000000000000000001205711263400317155ustar00rootroot00000000000000MockEnforcerRule.java000066400000000000000000000067421205711263400357170ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.enforcer.rule.api.EnforcerRule; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; /** * @author Brian Fox * */ public class MockEnforcerRule implements EnforcerRule { public boolean failRule = false; public String cacheId=""; public boolean isCacheable = false; public boolean isResultValid = false; public boolean executed = false; public MockEnforcerRule( boolean fail ) { this.failRule = fail; } public MockEnforcerRule( boolean fail, String cacheId, boolean isCacheable, boolean isResultValid ) { this.failRule = fail; this.isCacheable = isCacheable; this.isResultValid= isResultValid; this.cacheId = cacheId; } public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException { executed = true; if ( isFailRule() ) { throw new EnforcerRuleException( " this condition is not allowed." ); } } /** * @return the failRule */ public boolean isFailRule() { return this.failRule; } /** * @param theFailRule * the failRule to set */ public void setFailRule( boolean theFailRule ) { this.failRule = theFailRule; } /** * @return the isResultValid */ public boolean isResultValid () { return this.isResultValid; } /** * @param theIsResultValid the isResultValid to set */ public void setResultValid ( boolean theIsResultValid ) { this.isResultValid = theIsResultValid; } /** * @param theCacheId the cacheId to set */ public void setCacheId ( String theCacheId ) { this.cacheId = theCacheId; } /** * @param theIsCacheable the isCacheable to set */ public void setCacheable ( boolean theIsCacheable ) { this.isCacheable = theIsCacheable; } /* (non-Javadoc) * @see org.apache.maven.enforcer.rule.api.EnforcerRule#getCacheId() */ public String getCacheId () { return cacheId; } /* (non-Javadoc) * @see org.apache.maven.enforcer.rule.api.EnforcerRule#isCacheable() */ public boolean isCacheable () { return isCacheable; } /* (non-Javadoc) * @see org.apache.maven.enforcer.rule.api.EnforcerRule#isResultValid(org.apache.maven.enforcer.rule.api.EnforcerRule) */ public boolean isResultValid ( EnforcerRule theCachedRule ) { return isResultValid; } } TestDefaultEnforcementRuleHelper.java000066400000000000000000000032621205711263400411060ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import junit.framework.TestCase; import org.apache.maven.execution.RuntimeInformation; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; /** * @author Brian Fox * */ public class TestDefaultEnforcementRuleHelper extends TestCase { public void testHelper() throws ComponentLookupException, ExpressionEvaluationException { DefaultEnforcementRuleHelper helper = (DefaultEnforcementRuleHelper) EnforcerTestUtils.getHelper(); assertNotNull( helper.getLog() ); assertNotNull( helper.evaluate( "${session}" ) ); assertNotNull( helper.evaluate( "${project}" ) ); assertNotNull( helper.getComponent( RuntimeInformation.class ) ); } } TestEnforceMojo.java000066400000000000000000000175711205711263400355620ustar00rootroot00000000000000maven-enforcer-1.0.1/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcerpackage org.apache.maven.plugins.enforcer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import junit.framework.TestCase; import org.apache.maven.enforcer.rule.api.EnforcerRule; import org.apache.maven.plugin.MojoExecutionException; /** * Exhaustively check the enforcer mojo. * * @author Brian Fox * */ public class TestEnforceMojo extends TestCase { public void testEnforceMojo () throws MojoExecutionException { EnforceMojo mojo = new EnforceMojo(); mojo.setFail( false ); mojo.setSession( EnforcerTestUtils.getMavenSession() ); mojo.setProject( new MockProject() ); try { mojo.execute(); fail( "Expected a Mojo Execution Exception." ); } catch ( MojoExecutionException e ) { System.out.println( "Caught Expected Exception:" + e.getLocalizedMessage() ); } EnforcerRule[] rules = new EnforcerRule[10]; rules[0] = new MockEnforcerRule( true ); rules[1] = new MockEnforcerRule( true ); mojo.setRules( rules ); mojo.execute(); try { mojo.setFailFast( false ); mojo.setFail( true ); mojo.execute(); fail( "Expected a Mojo Execution Exception." ); } catch ( MojoExecutionException e ) { System.out.println( "Caught Expected Exception:" + e.getLocalizedMessage() ); } try { mojo.setFailFast( true ); mojo.setFail( true ); mojo.execute(); fail( "Expected a Mojo Execution Exception." ); } catch ( MojoExecutionException e ) { System.out.println( "Caught Expected Exception:" + e.getLocalizedMessage() ); } ( (MockEnforcerRule) rules[0] ).setFailRule( false ); ( (MockEnforcerRule) rules[1] ).setFailRule( false ); mojo.execute(); } public void testCaching () throws MojoExecutionException { EnforceMojo mojo = new EnforceMojo(); mojo.setFail( true ); mojo.setSession( EnforcerTestUtils.getMavenSession() ); mojo.setProject( new MockProject() ); MockEnforcerRule[] rules = new MockEnforcerRule[10]; //check that basic caching works. rules[0] = new MockEnforcerRule( false, "", true, true ); rules[1] = new MockEnforcerRule( false, "", true, true ); mojo.setRules( rules ); EnforceMojo.cache.clear(); mojo.execute(); assertTrue( "Expected this rule to be executed.",rules[0].executed ); assertFalse( "Expected this rule not to be executed.",rules[1].executed); //check that skip caching works. rules[0] = new MockEnforcerRule( false, "", true, true ); rules[1] = new MockEnforcerRule( false, "", true, true ); mojo.setRules( rules ); EnforceMojo.cache.clear(); mojo.ignoreCache = true; mojo.execute(); assertTrue( "Expected this rule to be executed.",rules[0].executed ); assertTrue( "Expected this rule to be executed.",rules[1].executed ); mojo.ignoreCache = false; //check that different ids are compared. rules[0] = new MockEnforcerRule( false, "1", true, true ); rules[1] = new MockEnforcerRule( false, "2", true, true ); rules[2] = new MockEnforcerRule( false, "2", true, true ); mojo.setRules( rules ); EnforceMojo.cache.clear(); mojo.execute(); assertTrue( "Expected this rule to be executed.",rules[0].executed ); assertTrue( "Expected this rule to be executed.",rules[1].executed); assertFalse( "Expected this rule not to be executed.",rules[2].executed); //check that future overrides are working rules[0] = new MockEnforcerRule( false, "1", true, true ); rules[1] = new MockEnforcerRule( false, "1", false, true ); rules[2] = null; mojo.setRules( rules ); EnforceMojo.cache.clear(); mojo.execute(); assertTrue( "Expected this rule to be executed.",rules[0].executed ); assertTrue( "Expected this rule to be executed.",rules[1].executed); //check that future isResultValid is used rules[0] = new MockEnforcerRule( false, "1", true, true ); rules[1] = new MockEnforcerRule( false, "1", true, false ); rules[2] = null; mojo.setRules( rules ); EnforceMojo.cache.clear(); mojo.execute(); assertTrue( "Expected this rule to be executed.",rules[0].executed ); assertTrue( "Expected this rule to be executed.",rules[1].executed); } public void testCachePersistence1() throws MojoExecutionException { EnforceMojo mojo = new EnforceMojo(); mojo.setFail( true ); mojo.setSession( EnforcerTestUtils.getMavenSession() ); mojo.setProject( new MockProject() ); MockEnforcerRule[] rules = new MockEnforcerRule[10]; //check that basic caching works. rules[0] = new MockEnforcerRule( false, "", true, true ); rules[1] = new MockEnforcerRule( false, "", true, true ); mojo.setRules( rules ); EnforceMojo.cache.clear(); mojo.execute(); assertTrue( "Expected this rule to be executed.",rules[0].executed ); assertFalse( "Expected this rule not to be executed.",rules[1].executed); } public void testCachePersistence2() throws MojoExecutionException { EnforceMojo mojo = new EnforceMojo(); mojo.setFail( true ); mojo.setSession( EnforcerTestUtils.getMavenSession() ); mojo.setProject( new MockProject() ); MockEnforcerRule[] rules = new MockEnforcerRule[10]; //check that basic caching works. rules[0] = new MockEnforcerRule( false, "", true, true ); rules[1] = new MockEnforcerRule( false, "", true, true ); mojo.setRules( rules ); mojo.execute(); assertFalse( "Expected this rule not to be executed.",rules[0].executed); assertFalse( "Expected this rule not to be executed.",rules[1].executed); } public void testCachePersistence3() throws MojoExecutionException { System.gc(); try { Thread.sleep( 1000 ); } catch ( InterruptedException e ) { } EnforceMojo mojo = new EnforceMojo(); mojo.setFail( true ); mojo.setSession( EnforcerTestUtils.getMavenSession() ); mojo.setProject( new MockProject() ); MockEnforcerRule[] rules = new MockEnforcerRule[10]; //check that basic caching works. rules[0] = new MockEnforcerRule( false, "", true, true ); rules[1] = new MockEnforcerRule( false, "", true, true ); mojo.setRules( rules ); mojo.execute(); assertFalse( "Expected this rule not to be executed.",rules[0].executed); assertFalse( "Expected this rule not to be executed.",rules[1].executed); } } maven-enforcer-1.0.1/pom.xml000066400000000000000000000261061205711263400157430ustar00rootroot00000000000000 4.0.0 maven-parent org.apache.maven 19 ../pom/maven/pom.xml org.apache.maven.enforcer enforcer 1.0.1 pom Enforcer Enforcer is a build rule execution framework. http://maven.apache.org/enforcer 2007 brianf Brian Fox brianf@apache.org Lead Developer 5 Maven User List users-subscribe@maven.apache.org users-unsubscribe@maven.apache.org users@maven.apache.org http://mail-archives.apache.org/mod_mbox/maven-users http://www.mail-archive.com/users@maven.apache.org/ http://old.nabble.com/Maven---Users-f178.html http://maven.users.markmail.org/ Maven Developer List dev-subscribe@maven.apache.org dev-unsubscribe@maven.apache.org dev@maven.apache.org http://mail-archives.apache.org/mod_mbox/maven-dev http://www.mail-archive.com/dev@maven.apache.org/ http://old.nabble.com/Maven-Developers-f179.html http://maven.dev.markmail.org/ Maven Issues List issues-subscribe@maven.apache.org issues-unsubscribe@maven.apache.org http://mail-archives.apache.org/mod_mbox/maven-issues/ http://www.mail-archive.com/issues@maven.apache.org http://old.nabble.com/Maven---Issues-f15573.html http://maven.issues.markmail.org/ Maven Commits List commits-subscribe@maven.apache.org commits-unsubscribe@maven.apache.org http://mail-archives.apache.org/mod_mbox/maven-dev http://www.mail-archive.com/commits@maven.apache.org http://old.nabble.com/Maven---Commits-f15575.html http://maven.commits.markmail.org/ Maven Announcements List announce@maven.apache.org announce-subscribe@maven.apache.org announce-unsubscribe@maven.apache.org http://mail-archives.apache.org/mod_mbox/maven-announce/ http://www.mail-archive.com/announce@maven.apache.org http://old.nabble.com/Maven-Announcements-f15617.html http://maven.announce.markmail.org/ Maven Notifications List notifications-subscribe@maven.apache.org notifications-unsubscribe@maven.apache.org http://mail-archives.apache.org/mod_mbox/maven-notifications/ http://www.mail-archive.com/notifications@maven.apache.org http://old.nabble.com/Maven---Notifications-f15574.html http://maven.notifications.markmail.org/ 2.0.6 enforcer-api enforcer-rules maven-enforcer-plugin scm:svn:http://svn.apache.org/repos/asf/maven/enforcer/tags/1.0.1 scm:svn:https://svn.apache.org/repos/asf/maven/enforcer/tags/1.0.1 http://svn.apache.org/viewcvs.cgi/maven/enforcer/tags/1.0.1 jira http://jira.codehaus.org/browse/MENFORCER Jenkins https://builds.apache.org/hudson/job/maven-enforcer/ apache.website scp://people.apache.org/www/maven.apache.org/enforcer/ 2.0.9 2.7 scp://people.apache.org/www/maven.apache.org org.apache.maven.enforcer enforcer-api ${project.version} org.apache.maven.enforcer enforcer-rules ${project.version} org.apache.maven.enforcer enforcer-rules ${project.version} test-jar test org.apache.maven maven-artifact ${maven.version} org.apache.maven maven-plugin-api ${maven.version} org.apache.maven maven-project ${maven.version} org.apache.maven maven-core ${maven.version} org.apache.maven.shared maven-common-artifact-filters 1.2 org.codehaus.plexus plexus-utils 1.5.8 junit junit 3.8.2 test easymock easymock 1.2_Java1.3 test commons-lang commons-lang 2.3 org.apache.maven.shared maven-plugin-testing-harness test 1.1 ${basedir}/src/main/resources maven-compiler-plugin 1.5 1.5 maven-plugin-plugin ${maven.plugin.plugin.version} maven-release-plugin https://svn.apache.org/repos/asf/maven/enforcer/tags org.codehaus.mojo cobertura-maven-plugin 2.4 org.apache.maven.plugins maven-javadoc-plugin 2.7 org.apache.maven.plugin-tools maven-plugin-tools-javadoc 2.6 org.codehaus.plexus plexus-javadoc 1.0 maven-enforcer-1.0.1/src/000077500000000000000000000000001205711263400152105ustar00rootroot00000000000000maven-enforcer-1.0.1/src/site/000077500000000000000000000000001205711263400161545ustar00rootroot00000000000000maven-enforcer-1.0.1/src/site/site.xml000066400000000000000000000025031205711263400176420ustar00rootroot00000000000000 org.apache.maven.skins maven-stylus-skin 1.1