Author: brianf
Date: Mon Nov 26 17:24:40 2007
New Revision: 598486
URL: http://svn.apache.org/viewvc?rev=598486&view=rev
Log:
site updates
Added:
maven/enforcer/trunk/enforcer-api/src/custom-rule-sample/src/main/java/org/apache/maven/enforcer/
maven/enforcer/trunk/enforcer-api/src/custom-rule-sample/src/main/java/org/apache/maven/enforcer/rule/
maven/enforcer/trunk/enforcer-api/src/custom-rule-sample/src/main/java/org/apache/maven/enforcer/rule/MyCustomRule.java
maven/enforcer/trunk/enforcer-rules/src/main/site/
maven/enforcer/trunk/enforcer-rules/src/main/site/apt/
maven/enforcer/trunk/enforcer-rules/src/main/site/apt/rules/
- copied from r598112,
maven/enforcer/trunk/maven-enforcer-plugin/src/site/apt/rules/
maven/enforcer/trunk/enforcer-rules/src/main/site/apt/rules/requireNoRepositories.apt
maven/enforcer/trunk/enforcer-rules/src/main/site/site.xml
- copied, changed from r598112,
maven/enforcer/trunk/maven-enforcer-plugin/src/site/site.xml
Removed:
maven/enforcer/trunk/enforcer-api/src/custom-rule-sample/src/main/java/org/apache/maven/shared/
maven/enforcer/trunk/maven-enforcer-plugin/src/site/apt/examples/
maven/enforcer/trunk/maven-enforcer-plugin/src/site/apt/rules/
Modified:
maven/enforcer/trunk/enforcer-api/src/custom-rule-sample/pom.xml
maven/enforcer/trunk/enforcer-api/src/custom-rule-sample/src/usage-pom.xml
maven/enforcer/trunk/enforcer-api/src/custom-rule-sample/usage-pom.xml
maven/enforcer/trunk/enforcer-api/src/site/apt/writing-a-custom-rule.apt
maven/enforcer/trunk/enforcer-api/src/site/resources/custom-rule.zip
maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java
maven/enforcer/trunk/enforcer-rules/src/main/site/apt/rules/noSnapshots.apt
maven/enforcer/trunk/enforcer-rules/src/main/site/apt/rules/requirePluginVersions.apt
maven/enforcer/trunk/maven-enforcer-plugin/src/it/pom.xml
Modified: maven/enforcer/trunk/enforcer-api/src/custom-rule-sample/pom.xml
URL:
http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-api/src/custom-rule-sample/pom.xml?rev=598486&r1=598485&r2=598486&view=diff
==============================================================================
--- maven/enforcer/trunk/enforcer-api/src/custom-rule-sample/pom.xml (original)
+++ maven/enforcer/trunk/enforcer-api/src/custom-rule-sample/pom.xml Mon Nov 26
17:24:40 2007
@@ -1,39 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
- <groupId>your.group</groupId>
- <artifactId>custom-rule</artifactId>
+ <groupId>custom-rule</groupId>
+ <artifactId>custom-rule-sample</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>My Custom Rule</name>
<description>This is my custom rule.</description>
+ <properties>
+ <api.version>1.0-SNAPSHOT</api.version>
+ <maven.version>2.0.6</maven.version>
+ </properties>
<build>
</build>
<dependencies>
<dependency>
<groupId>org.apache.maven.enforcer</groupId>
<artifactId>enforcer-api</artifactId>
- <version>1.0-alpha-3</version>
+ <version>${api.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
- <version>2.0.5</version>
+ <version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
- <version>2.0.5</version>
+ <version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
- <version>2.0.5</version>
+ <version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
- <version>2.0.5</version>
+ <version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
Added:
maven/enforcer/trunk/enforcer-api/src/custom-rule-sample/src/main/java/org/apache/maven/enforcer/rule/MyCustomRule.java
URL:
http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-api/src/custom-rule-sample/src/main/java/org/apache/maven/enforcer/rule/MyCustomRule.java?rev=598486&view=auto
==============================================================================
---
maven/enforcer/trunk/enforcer-api/src/custom-rule-sample/src/main/java/org/apache/maven/enforcer/rule/MyCustomRule.java
(added)
+++
maven/enforcer/trunk/enforcer-api/src/custom-rule-sample/src/main/java/org/apache/maven/enforcer/rule/MyCustomRule.java
Mon Nov 26 17:24:40 2007
@@ -0,0 +1,101 @@
+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 <a href="mailto:[EMAIL PROTECTED]">Brian Fox</a>
+ */
+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;
+ }
+}
Modified:
maven/enforcer/trunk/enforcer-api/src/custom-rule-sample/src/usage-pom.xml
URL:
http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-api/src/custom-rule-sample/src/usage-pom.xml?rev=598486&r1=598485&r2=598486&view=diff
==============================================================================
--- maven/enforcer/trunk/enforcer-api/src/custom-rule-sample/src/usage-pom.xml
(original)
+++ maven/enforcer/trunk/enforcer-api/src/custom-rule-sample/src/usage-pom.xml
Mon Nov 26 17:24:40 2007
@@ -9,10 +9,11 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
+ <version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
- <groupId>your.group</groupId>
-
<artifactId>custom-rule</artifactId>
+ <groupId>custom-rule</groupId>
+
<artifactId>custom-rule-sample</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
@@ -27,8 +28,8 @@
<requireMavenVersion>
<version>2.0.6</version>
</requireMavenVersion>
- <myCustomRule
implementation="org.apache.maven.enforcer.rule.myCustomRule">
-
<shouldIfail>false</shouldIfail>
+ <myCustomRule
implementation="org.apache.maven.enforcer.rule.MyCustomRule">
+
<shouldIfail>true</shouldIfail>
</myCustomRule>
</rules>
</configuration>
Modified: maven/enforcer/trunk/enforcer-api/src/custom-rule-sample/usage-pom.xml
URL:
http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-api/src/custom-rule-sample/usage-pom.xml?rev=598486&r1=598485&r2=598486&view=diff
==============================================================================
--- maven/enforcer/trunk/enforcer-api/src/custom-rule-sample/usage-pom.xml
(original)
+++ maven/enforcer/trunk/enforcer-api/src/custom-rule-sample/usage-pom.xml Mon
Nov 26 17:24:40 2007
@@ -1,43 +1,39 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-enforcer-plugin-it1</artifactId>
- <version>1</version>
- <packaging>pom</packaging>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-enforcer-plugin</artifactId>
- <dependencies>
- <dependency>
- <groupId>your.group</groupId>
-
<artifactId>custom-rule</artifactId>
- <version>1.0</version>
- </dependency>
- </dependencies>
- <executions>
- <execution>
- <id>enforce</id>
- <configuration>
- <rules>
-
<requireJavaVersion>
-
<version>[1.3,1.6]</version>
-
</requireJavaVersion>
-
<requireMavenVersion>
-
<version>2.0.6</version>
-
</requireMavenVersion>
- <myCustomRule
implementation="org.apache.maven.shared.rule.myCustomRule">
-
<shouldIfail>false</shouldIfail>
- </myCustomRule>
- </rules>
- </configuration>
- <goals>
- <goal>enforce</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-enforcer-plugin-sample-usage</artifactId>
+ <version>1</version>
+ <packaging>jar</packaging>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-enforcer-plugin</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <dependencies>
+ <dependency>
+ <groupId>custom-rule</groupId>
+ <artifactId>custom-rule-sample</artifactId>
+ <version>1.0</version>
+ </dependency>
+ </dependencies>
+ <executions>
+ <execution>
+ <id>enforce</id>
+ <configuration>
+ <rules>
+ <myCustomRule
implementation="org.apache.maven.enforcer.rule.MyCustomRule">
+ <shouldIfail>false</shouldIfail>
+ </myCustomRule>
+ </rules>
+ </configuration>
+ <goals>
+ <goal>enforce</goal>
+ </goals>
+
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
</project>
Modified:
maven/enforcer/trunk/enforcer-api/src/site/apt/writing-a-custom-rule.apt
URL:
http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-api/src/site/apt/writing-a-custom-rule.apt?rev=598486&r1=598485&r2=598486&view=diff
==============================================================================
--- maven/enforcer/trunk/enforcer-api/src/site/apt/writing-a-custom-rule.apt
(original)
+++ maven/enforcer/trunk/enforcer-api/src/site/apt/writing-a-custom-rule.apt
Mon Nov 26 17:24:40 2007
@@ -20,7 +20,7 @@
------
Brian Fox
------
- Mar 2007
+ Nov 2007
------
Writing a custom rule
@@ -34,55 +34,58 @@
+---+
<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>your.group</groupId>
- <artifactId>custom-rule</artifactId>
- <packaging>jar</packaging>
- <version>1.0</version>
- <name>My Custom Rule</name>
- <description>This is my custom rule.</description>
- <build>
- </build>
- <dependencies>
- <dependency>
- <groupId>org.apache.maven.shared</groupId>
- <artifactId>maven-enforcer-rule-api</artifactId>
- <version>1.0-alpha-1</version>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-project</artifactId>
- <version>2.0.5</version>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-core</artifactId>
- <version>2.0.5</version>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-artifact</artifactId>
- <version>2.0.5</version>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-plugin-api</artifactId>
- <version>2.0.5</version>
- </dependency>
- <dependency>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-container-default</artifactId>
- <version>1.0-alpha-9</version>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>custom-rule</groupId>
+ <artifactId>custom-rule-sample</artifactId>
+ <packaging>jar</packaging>
+ <version>1.0</version>
+ <name>My Custom Rule</name>
+ <description>This is my custom rule.</description>
+ <properties>
+ <api.version>1.0-SNAPSHOT</api.version>
+ <maven.version>2.0.6</maven.version>
+ </properties>
+ <build>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.enforcer</groupId>
+ <artifactId>enforcer-api</artifactId>
+ <version>${api.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project</artifactId>
+ <version>${maven.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>${maven.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact</artifactId>
+ <version>${maven.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>${maven.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-container-default</artifactId>
+ <version>1.0-alpha-9</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
</project>
+---+
@@ -90,32 +93,35 @@
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
retreive components by class name from the helper:
+---+
-package org.apache.maven.shared.rule;
+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.apache.maven.shared.enforcer.rule.api.EnforcerRule;
-import org.apache.maven.shared.enforcer.rule.api.EnforcerRuleException;
-import org.apache.maven.shared.enforcer.rule.api.EnforcerRuleHelper;
+import
org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
import
org.codehaus.plexus.component.repository.exception.ComponentLookupException;
/**
- * @author <a href="mailto:[EMAIL PROTECTED]">Brian Fox</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Brian Fox</a>
*/
public class MyCustomRule
implements EnforcerRule
{
/**
- * Simple param. This rule will fail if the value is true.
+ * Simple param. This rule will fail if the value is true.
*/
private boolean shouldIfail = false;
-
+
public void execute( EnforcerRuleHelper helper )
throws EnforcerRuleException
{
@@ -123,7 +129,7 @@
try
{
- // get the various expressions out of the helper.
+ // 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}" );
@@ -139,17 +145,59 @@
log.info( "Retrieved RuntimeInfo: " + rti );
log.info( "Retrieved Session: " + session );
log.info( "Retrieved Resolver: " + resolver );
-
- if (this.shouldIfail)
+
+ if ( this.shouldIfail )
{
- throw new EnforcerRuleException("Failing because my param said
so.");
+ throw new EnforcerRuleException( "Failing because my param
said so." );
}
}
catch ( ComponentLookupException e )
{
- throw new EnforcerRuleException("Unable to lookup a component",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;
+ }
}
+---+
@@ -167,8 +215,8 @@
<artifactId>maven-enforcer-plugin</artifactId>
<dependencies>
<dependency>
- <groupId>your.group</groupId>
- <artifactId>custom-rule</artifactId>
+ <groupId>custom-rule</groupId>
+ <artifactId>custom-rule-sample</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
@@ -186,7 +234,7 @@
+---+
<configuration>
<rules>
- <myCustomRule implementation="org.apache.maven.shared.rule.myCustomRule">
+ <myCustomRule implementation="org.apache.maven.enforcer.rule.MyCustomRule">
<shouldIfail>true</shouldIfail>
</myCustomRule>
</rules>
@@ -196,36 +244,33 @@
[[6]] That's it. The full plugin config may look like this:
+---+
-<plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-enforcer-plugin</artifactId>
- <dependencies>
- <dependency>
- <groupId>your.group</groupId>
- <artifactId>custom-rule</artifactId>
- <version>1.0</version>
- </dependency>
- </dependencies>
- <executions>
- <execution>
- <id>enforce</id>
- <configuration>
- <rules>
- <requireJavaVersion>
- <version>[1.3,1.6]</version>
- </requireJavaVersion>
- <requireMavenVersion>
- <version>2.0.6</version>
- </requireMavenVersion>
- <myCustomRule
implementation="org.apache.maven.shared.rule.myCustomRule">
- <shouldIfail>true</shouldIfail>
- </myCustomRule>
- </rules>
- </configuration>
- <goals>
- <goal>enforce-once</goal>
- </goals>
- </execution>
- </executions>
-</plugin>
+<plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-enforcer-plugin</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <dependencies>
+ <dependency>
+ <groupId>custom-rule</groupId>
+ <artifactId>custom-rule-sample</artifactId>
+ <version>1.0</version>
+ </dependency>
+ </dependencies>
+ <executions>
+ <execution>
+ <id>enforce</id>
+ <configuration>
+ <rules>
+ <myCustomRule
implementation="org.apache.maven.enforcer.rule.MyCustomRule">
+ <shouldIfail>false</shouldIfail>
+ </myCustomRule>
+ </rules>
+ </configuration>
+ <goals>
+ <goal>enforce</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+</plugins>
+---+
Modified: maven/enforcer/trunk/enforcer-api/src/site/resources/custom-rule.zip
URL:
http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-api/src/site/resources/custom-rule.zip?rev=598486&r1=598485&r2=598486&view=diff
==============================================================================
Binary files - no diff available.
Modified:
maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java
URL:
http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java?rev=598486&r1=598485&r2=598486&view=diff
==============================================================================
---
maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java
(original)
+++
maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java
Mon Nov 26 17:24:40 2007
@@ -30,7 +30,6 @@
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
-import java.util.regex.Matcher;
import org.apache.maven.BuildFailureException;
import org.apache.maven.artifact.Artifact;
@@ -173,7 +172,7 @@
// insert any additional Plugins specified by
// the user.
- allPlugins = addAdditionalPlugins( allPlugins );
+ allPlugins = addAdditionalPlugins( allPlugins, additionalPlugins );
// there's nothing to do here
if ( allPlugins.isEmpty() )
@@ -316,12 +315,12 @@
*
* @throws MojoExecutionException
*/
- public Set addAdditionalPlugins ( Set existing )
+ public Set addAdditionalPlugins ( Set existing, List additional )
throws MojoExecutionException
{
- if ( additionalPlugins != null )
+ if ( additional != null )
{
- Iterator iter = additionalPlugins.iterator();
+ Iterator iter = additional.iterator();
while ( iter.hasNext() )
{
String pluginString = (String) iter.next();
@@ -334,7 +333,12 @@
// only add this if it's not already
// there.
- if ( !existing.contains( plugin ) )
+ if (existing == null)
+ {
+ existing = new HashSet();
+ existing.add( plugin );
+ }
+ else if ( !existing.contains( plugin ) )
{
existing.add( plugin );
}
@@ -896,5 +900,21 @@
public boolean isResultValid ( EnforcerRule theCachedRule )
{
return false;
+ }
+
+ /**
+ * @return the banSnapshots
+ */
+ public boolean isBanSnapshots ()
+ {
+ return this.banSnapshots;
+ }
+
+ /**
+ * @param theBanSnapshots the banSnapshots to set
+ */
+ public void setBanSnapshots ( boolean theBanSnapshots )
+ {
+ this.banSnapshots = theBanSnapshots;
}
}
Modified:
maven/enforcer/trunk/enforcer-rules/src/main/site/apt/rules/noSnapshots.apt
URL:
http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/main/site/apt/rules/noSnapshots.apt?rev=598486&r1=598112&r2=598486&view=diff
==============================================================================
--- maven/enforcer/trunk/enforcer-rules/src/main/site/apt/rules/noSnapshots.apt
(original)
+++ maven/enforcer/trunk/enforcer-rules/src/main/site/apt/rules/noSnapshots.apt
Mon Nov 26 17:24:40 2007
@@ -16,14 +16,14 @@
~~ under the License.
------
- No Snapshots
+ Require Release Dependencies
------
Brian Fox
------
- July 2007
+ November 2007
------
-No Snapshots
+Require Release Dependencies
This rule checks the dependencies and fails if any snapshots are found.
@@ -55,9 +55,9 @@
</goals>
<configuration>
<rules>
- <noSnapshots>
+ <requireReleaseDeps>
<message>No Snapshots Allowed!</message>
- </noSnapshots>
+ </requireReleaseDeps>
</rules>
<fail>true</fail>
</configuration>
Added:
maven/enforcer/trunk/enforcer-rules/src/main/site/apt/rules/requireNoRepositories.apt
URL:
http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/main/site/apt/rules/requireNoRepositories.apt?rev=598486&view=auto
==============================================================================
---
maven/enforcer/trunk/enforcer-rules/src/main/site/apt/rules/requireNoRepositories.apt
(added)
+++
maven/enforcer/trunk/enforcer-rules/src/main/site/apt/rules/requireNoRepositories.apt
Mon Nov 26 17:24:40 2007
@@ -0,0 +1,88 @@
+~~ 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):
+
++---+
+<project>
+ [...]
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-enforcer-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>enforce-plugin-versions</id>
+ <goals>
+ <goal>enforce</goal>
+ </goals>
+ <configuration>
+ <rules>
+ <requirePluginVersions>
+ <message>Best Practice is to always define plugin
versions!</message>
+ <banLatest>true</banLatest>
+ <banRelease>true</banRelease>
+ <banSnapshots>true</banSnapshots>
+ <phases>clean,deploy,site</phases>
+ <additionalPlugins>
+
<additionalPlugin>org.apache.maven.plugins:maven-eclipse-plugin</additionalPlugin>
+
<additionalPlugin>org.apache.maven.plugins:maven-ide-plugin</additionalPlugin>
+ </additionalPlugins>
+ </requirePluginVersions>
+ </rules>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ [...]
+</project>
++---+
\ No newline at end of file
Modified:
maven/enforcer/trunk/enforcer-rules/src/main/site/apt/rules/requirePluginVersions.apt
URL:
http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/main/site/apt/rules/requirePluginVersions.apt?rev=598486&r1=598112&r2=598486&view=diff
==============================================================================
---
maven/enforcer/trunk/enforcer-rules/src/main/site/apt/rules/requirePluginVersions.apt
(original)
+++
maven/enforcer/trunk/enforcer-rules/src/main/site/apt/rules/requirePluginVersions.apt
Mon Nov 26 17:24:40 2007
@@ -20,7 +20,7 @@
------
Brian Fox
------
- August 2007
+ Novemer 2007
------
Require Plugin Versions
@@ -31,13 +31,23 @@
* 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
+ * 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
+ * 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:
+ Sample Plugin Configuration (showing some defaults, defaults can be
skipped):
+---+
<project>
@@ -59,6 +69,12 @@
<message>Best Practice is to always define plugin
versions!</message>
<banLatest>true</banLatest>
<banRelease>true</banRelease>
+ <banSnapshots>true</banSnapshots>
+ <phases>clean,deploy,site</phases>
+ <additionalPlugins>
+
<additionalPlugin>org.apache.maven.plugins:maven-eclipse-plugin</additionalPlugin>
+
<additionalPlugin>org.apache.maven.plugins:maven-ide-plugin</additionalPlugin>
+ </additionalPlugins>
</requirePluginVersions>
</rules>
</configuration>
Copied: maven/enforcer/trunk/enforcer-rules/src/main/site/site.xml (from
r598112, maven/enforcer/trunk/maven-enforcer-plugin/src/site/site.xml)
URL:
http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/main/site/site.xml?p2=maven/enforcer/trunk/enforcer-rules/src/main/site/site.xml&p1=maven/enforcer/trunk/maven-enforcer-plugin/src/site/site.xml&r1=598112&r2=598486&rev=598486&view=diff
==============================================================================
--- maven/enforcer/trunk/maven-enforcer-plugin/src/site/site.xml (original)
+++ maven/enforcer/trunk/enforcer-rules/src/main/site/site.xml Mon Nov 26
17:24:40 2007
@@ -23,16 +23,12 @@
<body>
<menu name="Overview">
<item name="Introduction" href="index.html"/>
- <item name="Goals" href="plugin-info.html"/>
- <item name="Usage" href="usage.html"/>
- <item name="FAQ" href="faq.html"/>
<item name="Standard Rules" href="rules/index.html"/>
+ <item name="Rule API"
href="http://maven.apache.org/enforcer/enforcer-api/"/>
+ <item name="Enforcer Plugin"
href="http://maven.apache.org/plugins/maven-enforcer-plugin/"/>
</menu>
<menu name="Custom Rules">
<item name="Writing a custom rule"
href="http://maven.apache.org/enforcer/enforcer-api/writing-a-custom-rule.html"/>
- </menu>
- <menu name="Resources">
- <item name="Maven 2.0.x Version Range Syntax"
href="http://docs.codehaus.org/display/MAVEN/Dependency+Mediation+and+Conflict+Resolution#DependencyMediationandConflictResolution-DependencyVersionRanges"
/>
</menu>
</body>
</project>
Modified: maven/enforcer/trunk/maven-enforcer-plugin/src/it/pom.xml
URL:
http://svn.apache.org/viewvc/maven/enforcer/trunk/maven-enforcer-plugin/src/it/pom.xml?rev=598486&r1=598485&r2=598486&view=diff
==============================================================================
--- maven/enforcer/trunk/maven-enforcer-plugin/src/it/pom.xml (original)
+++ maven/enforcer/trunk/maven-enforcer-plugin/src/it/pom.xml Mon Nov 26
17:24:40 2007
@@ -39,26 +39,27 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
+ <version>1.0-SNAPSHOT</version>
<dependencies>
- <!-- <dependency>
- <groupId>your.group</groupId>
-
<artifactId>custom-rule</artifactId>
+ <dependency>
+ <groupId>custom-rule</groupId>
+
<artifactId>custom-rule-sample</artifactId>
<version>1.0</version>
- </dependency>-->
+ </dependency>
</dependencies>
<executions>
<execution>
<id>enforce</id>
<configuration>
<rules>
-
<!--<requireJavaVersion>
+
<requireJavaVersion>
<version>[1.3,1.6]</version>
</requireJavaVersion>
<requireMavenVersion>
<version>2.0.8</version>
<message>You need 2.0.8!</message>
</requireMavenVersion>
- <myCustomRule
implementation="org.apache.maven.shared.rule.myCustomRule">
+ <myCustomRule
implementation="org.apache.maven.enforcer.rule.MyCustomRule">
<shouldIfail>true</shouldIfail>
</myCustomRule>
<requireOS>
@@ -72,12 +73,12 @@
<excludes>
<exclude>org.apache.maven</exclude>
</excludes>
-
</bannedDependencies>-->
+
</bannedDependencies>
<requirePluginVersions/>
</rules>
</configuration>
<goals>
-
<goal>enforce-once</goal>
+ <goal>enforce</goal>
</goals>
<phase>validate</phase>