You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2020/07/27 14:26:17 UTC

[maven-enforcer] branch master updated (8224c4c -> 0124c62)

This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/maven-enforcer.git.


    from 8224c4c  enable GitHub Actions CI
     new c7c00a9  MENFORCER-245 Improve documentation about writing own Enforcer Rule
     new 0124c62  Changed those lines reviewed in the PR.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 enforcer-api/src/custom-rule-sample/pom.xml        | 133 +++++------
 .../apache/maven/enforcer/rule/MyCustomRule.java   | 251 +++++++++++----------
 .../src/custom-rule-sample/src/usage-pom.xml       |  64 ------
 enforcer-api/src/custom-rule-sample/usage-pom.xml  |   2 +-
 .../src/main/assembly/custom-rule-sample.xml       |  13 ++
 .../src/site/apt/writing-a-custom-rule.apt.vm      |  58 ++---
 6 files changed, 229 insertions(+), 292 deletions(-)
 delete mode 100644 enforcer-api/src/custom-rule-sample/src/usage-pom.xml


[maven-enforcer] 02/02: Changed those lines reviewed in the PR.

Posted by sl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-enforcer.git

commit 0124c6227829e1661a455f65b3ad474cef182933
Author: Gabriel Belingueres <be...@gmail.com>
AuthorDate: Mon May 25 16:18:56 2020 -0300

    Changed those lines reviewed in the PR.
    
    - pom.xml indentation to 2 spaces.
    - 'will fail' to 'fails'.
    - parameter name from 'arg0' to 'rule'.
    - rewrite paragraph about parameter in pom.xml.
---
 enforcer-api/src/custom-rule-sample/pom.xml        | 76 +++++++++++----------
 .../apache/maven/enforcer/rule/MyCustomRule.java   |  4 +-
 .../src/site/apt/writing-a-custom-rule.apt.vm      | 78 +++++++++++-----------
 3 files changed, 80 insertions(+), 78 deletions(-)

diff --git a/enforcer-api/src/custom-rule-sample/pom.xml b/enforcer-api/src/custom-rule-sample/pom.xml
index 577dac0..2b13b0a 100644
--- a/enforcer-api/src/custom-rule-sample/pom.xml
+++ b/enforcer-api/src/custom-rule-sample/pom.xml
@@ -18,41 +18,43 @@
   * under the License. 
   *
 -->
-<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/xsd/maven-4.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>${project.version}</api.version>
-        <maven.version>3.0</maven.version>
-    </properties>
-    <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-core</artifactId>
-            <version>${maven.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.maven</groupId>
-            <artifactId>maven-plugin-api</artifactId>
-            <version>${maven.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <version>3.8.1</version>
-            <scope>test</scope>
-        </dependency>
-    </dependencies>
-    <build>
-    </build>
+<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/xsd/maven-4.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>${project.version}</api.version>
+    <maven.version>3.0</maven.version>
+  </properties>
+  <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-core</artifactId>
+      <version>${maven.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+      <version>${maven.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  <build>
+  </build>
 </project>
\ No newline at end of file
diff --git a/enforcer-api/src/custom-rule-sample/src/main/java/org/apache/maven/enforcer/rule/MyCustomRule.java b/enforcer-api/src/custom-rule-sample/src/main/java/org/apache/maven/enforcer/rule/MyCustomRule.java
index 30b4db6..9b8f2fc 100644
--- a/enforcer-api/src/custom-rule-sample/src/main/java/org/apache/maven/enforcer/rule/MyCustomRule.java
+++ b/enforcer-api/src/custom-rule-sample/src/main/java/org/apache/maven/enforcer/rule/MyCustomRule.java
@@ -37,7 +37,7 @@ public class MyCustomRule
     implements EnforcerRule
 {
     /**
-     * Simple param. This rule will fail if the value is true.
+     * Simple param. This rule fails if the value is true.
      */
     private boolean shouldIfail = false;
 
@@ -113,7 +113,7 @@ public class MyCustomRule
      * 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 )
+    public boolean isResultValid( EnforcerRule rule )
     {
         return false;
     }
diff --git a/enforcer-api/src/site/apt/writing-a-custom-rule.apt.vm b/enforcer-api/src/site/apt/writing-a-custom-rule.apt.vm
index 23b5f67..e4e79d0 100644
--- a/enforcer-api/src/site/apt/writing-a-custom-rule.apt.vm
+++ b/enforcer-api/src/site/apt/writing-a-custom-rule.apt.vm
@@ -34,48 +34,48 @@ Writing a custom rule
   
 +---+
 <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/xsd/maven-4.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>${project.version}</api.version>
-        <maven.version>3.0</maven.version>
-    </properties>
-    <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-core</artifactId>
-            <version>${maven.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.maven</groupId>
-            <artifactId>maven-plugin-api</artifactId>
-            <version>${maven.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <version>3.8.1</version>
-            <scope>test</scope>
-        </dependency>
-    </dependencies>
-    <build>
-    </build>
+  <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>${project.version}</api.version>
+    <maven.version>3.0</maven.version>
+  </properties>
+  <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-core</artifactId>
+      <version>${maven.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+      <version>${maven.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  <build>
+  </build>
 </project>
 +---+
 
   [[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.
-   In addition, the rule must provide a setter method for each parameter allowed to be configured in the pom.xml file (like the shown in point 5).
+   In addition, the rule must provide a setter method for each parameter allowed to be configured in the pom.xml file (like the parameter <<<shouldIfail>>> shown in point 5).
    
    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.
    
@@ -104,7 +104,7 @@ public class MyCustomRule
     implements EnforcerRule
 {
     /**
-     * Simple param. This rule will fail if the value is true.
+     * Simple param. This rule fails if the value is true.
      */
     private boolean shouldIfail = false;
 
@@ -180,7 +180,7 @@ public class MyCustomRule
      * 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 )
+    public boolean isResultValid( EnforcerRule rule )
     {
         return false;
     }


[maven-enforcer] 01/02: MENFORCER-245 Improve documentation about writing own Enforcer Rule

Posted by sl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-enforcer.git

commit c7c00a9d74a54e5ea00c276373552f919c87e78f
Author: Gabriel Belingueres <be...@gmail.com>
AuthorDate: Wed Dec 19 16:43:37 2018 -0300

    MENFORCER-245 Improve documentation about writing own Enforcer Rule
    
    Updated sample custom rule project to Maven 3.0. Updated documentation.
    Deleted confusing src/custom-rule-sample/src/usage-pom.xml file.
---
 enforcer-api/src/custom-rule-sample/pom.xml        | 131 +++++------
 .../apache/maven/enforcer/rule/MyCustomRule.java   | 251 +++++++++++----------
 .../src/custom-rule-sample/src/usage-pom.xml       |  64 ------
 enforcer-api/src/custom-rule-sample/usage-pom.xml  |   2 +-
 .../src/main/assembly/custom-rule-sample.xml       |  13 ++
 .../src/site/apt/writing-a-custom-rule.apt.vm      | 122 +++++-----
 6 files changed, 259 insertions(+), 324 deletions(-)

diff --git a/enforcer-api/src/custom-rule-sample/pom.xml b/enforcer-api/src/custom-rule-sample/pom.xml
index 5ae0f9e..577dac0 100644
--- a/enforcer-api/src/custom-rule-sample/pom.xml
+++ b/enforcer-api/src/custom-rule-sample/pom.xml
@@ -1,73 +1,58 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-  * 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. 
-  *
--->
-<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/xsd/maven-4.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-beta-1</api.version>
-	  <maven.version>2.0.9</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>
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  * 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. 
+  *
+-->
+<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/xsd/maven-4.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>${project.version}</api.version>
+        <maven.version>3.0</maven.version>
+    </properties>
+    <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-core</artifactId>
+            <version>${maven.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-plugin-api</artifactId>
+            <version>${maven.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>3.8.1</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+    <build>
+    </build>
+</project>
\ No newline at end of file
diff --git a/enforcer-api/src/custom-rule-sample/src/main/java/org/apache/maven/enforcer/rule/MyCustomRule.java b/enforcer-api/src/custom-rule-sample/src/main/java/org/apache/maven/enforcer/rule/MyCustomRule.java
index b9792d1..30b4db6 100644
--- a/enforcer-api/src/custom-rule-sample/src/main/java/org/apache/maven/enforcer/rule/MyCustomRule.java
+++ b/enforcer-api/src/custom-rule-sample/src/main/java/org/apache/maven/enforcer/rule/MyCustomRule.java
@@ -1,120 +1,131 @@
-package org.apache.maven.enforcer.rule;
-
-/*
- * 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.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:brianf@apache.org">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;
-    }
-}
+package org.apache.maven.enforcer.rule;
+
+/*
+ * 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.ProjectDependenciesResolver;
+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.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:brianf@apache.org">Brian Fox</a>
+ * @author <a href="mailto:belingueres@gmail.com">Gabriel Belingueres</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}" );
+            String mavenVersion = (String) helper.evaluate( "${maven.version}" );
+
+            // retrieve any component out of the session directly
+            ProjectDependenciesResolver resolver = helper.getComponent( ProjectDependenciesResolver.class );
+
+            log.info( "Retrieved Target Folder: " + target );
+            log.info( "Retrieved ArtifactId: " +artifactId );
+            log.info( "Retrieved Project: " + project );
+            log.info( "Retrieved Maven version: " + mavenVersion );
+            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 Boolean.toString( 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;
+    }
+
+    /**
+     * Injects the value of the shouldIfail parameter into the custom rule.
+     * 
+     * @param shouldIfail set to true if you want the rule to fail. false to succeed.
+     */
+    public void setShouldIfail( boolean shouldIfail )
+    {
+        this.shouldIfail = shouldIfail;
+    }
+
+}
diff --git a/enforcer-api/src/custom-rule-sample/src/usage-pom.xml b/enforcer-api/src/custom-rule-sample/src/usage-pom.xml
deleted file mode 100644
index 713b269..0000000
--- a/enforcer-api/src/custom-rule-sample/src/usage-pom.xml
+++ /dev/null
@@ -1,64 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-  * 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. 
-  *
--->
-<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/xsd/maven-4.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>
-                <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>
-								<requireJavaVersion>
-									<version>[1.3,1.6]</version>
-								</requireJavaVersion>
-								<requireMavenVersion>
-									<version>2.0.6</version>
-								</requireMavenVersion>
-								<myCustomRule implementation="org.apache.maven.enforcer.rule.MyCustomRule">
-									<shouldIfail>true</shouldIfail>
-								</myCustomRule>
-							</rules>
-						</configuration>
-						<goals>
-							<goal>enforce</goal>
-						</goals>
-					</execution>
-				</executions>
-			</plugin>
-		</plugins>
-	</build>
-</project>
diff --git a/enforcer-api/src/custom-rule-sample/usage-pom.xml b/enforcer-api/src/custom-rule-sample/usage-pom.xml
index 0a4efb4..7af9b80 100644
--- a/enforcer-api/src/custom-rule-sample/usage-pom.xml
+++ b/enforcer-api/src/custom-rule-sample/usage-pom.xml
@@ -29,7 +29,7 @@
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-enforcer-plugin</artifactId>
-                <version>1.0-beta-1</version>
+                <version>${project.version}</version>
                 <dependencies>
                     <dependency>
                         <groupId>custom-rule</groupId>
diff --git a/enforcer-api/src/main/assembly/custom-rule-sample.xml b/enforcer-api/src/main/assembly/custom-rule-sample.xml
index 1abdf30..5b72b90 100644
--- a/enforcer-api/src/main/assembly/custom-rule-sample.xml
+++ b/enforcer-api/src/main/assembly/custom-rule-sample.xml
@@ -32,4 +32,17 @@
       <outputDirectory>/custom-rule-sample</outputDirectory>
     </fileSet>
   </fileSets>
+  <files>
+    <!-- filters custom-rule's pom.xml to replace 'api.version' property with the current project version -->
+    <file>
+      <source>src/custom-rule-sample/pom.xml</source>
+      <outputDirectory>/custom-rule-sample</outputDirectory>
+      <filtered>true</filtered>
+    </file>
+    <file>
+      <source>src/custom-rule-sample/usage-pom.xml</source>
+      <outputDirectory>/custom-rule-sample</outputDirectory>
+      <filtered>true</filtered>
+    </file>
+  </files>
 </assembly>
\ No newline at end of file
diff --git a/enforcer-api/src/site/apt/writing-a-custom-rule.apt.vm b/enforcer-api/src/site/apt/writing-a-custom-rule.apt.vm
index feeb30a..23b5f67 100644
--- a/enforcer-api/src/site/apt/writing-a-custom-rule.apt.vm
+++ b/enforcer-api/src/site/apt/writing-a-custom-rule.apt.vm
@@ -33,71 +33,50 @@ Writing a custom rule
   [[1]] First make a new jar project starting with the sample pom below:
   
 +---+
-<?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/xsd/maven-4.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>${project.version}</api.version>
-    <maven.version>2.0.9</maven.version>
-  </properties>
-
-  <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.2</version>
-      <scope>test</scope>
-    </dependency>
-  </dependencies>
-
-  <build>
-  </build>
+<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/xsd/maven-4.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>${project.version}</api.version>
+        <maven.version>3.0</maven.version>
+    </properties>
+    <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-core</artifactId>
+            <version>${maven.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-plugin-api</artifactId>
+            <version>${maven.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>3.8.1</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+    <build>
+    </build>
 </project>
 +---+
 
   [[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.
+   In addition, the rule must provide a setter method for each parameter allowed to be configured in the pom.xml file (like the shown in point 5).
+   
    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.
@@ -107,12 +86,11 @@ Writing a custom rule
 +---+
 package org.apache.maven.enforcer.rule;
 
-import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.ProjectDependenciesResolver;
 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;
@@ -120,6 +98,7 @@ import org.codehaus.plexus.component.repository.exception.ComponentLookupExcepti
 
 /**
  * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
+ * @author <a href="mailto:belingueres@gmail.com">Gabriel Belingueres</a>
  */
 public class MyCustomRule
     implements EnforcerRule
@@ -141,15 +120,15 @@ public class MyCustomRule
             MavenSession session = (MavenSession) helper.evaluate( "${session}" );
             String target = (String) helper.evaluate( "\${project.build.directory}" );
             String artifactId = (String) helper.evaluate( "\${project.artifactId}" );
+            String mavenVersion = (String) helper.evaluate( "${maven.version}" );
 
             // retrieve any component out of the session directly
-            ArtifactResolver resolver = (ArtifactResolver) helper.getComponent( ArtifactResolver.class );
-            RuntimeInformation rti = (RuntimeInformation) helper.getComponent( RuntimeInformation.class );
+            ProjectDependenciesResolver resolver = helper.getComponent( ProjectDependenciesResolver.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 Maven version: " + mavenVersion );
             log.info( "Retrieved Session: " + session );
             log.info( "Retrieved Resolver: " + resolver );
 
@@ -180,7 +159,7 @@ public class MyCustomRule
     public String getCacheId()
     {
         //no hash on boolean...only parameter so no hash is needed.
-        return ""+this.shouldIfail;
+        return Boolean.toString( this.shouldIfail );
     }
 
     /**
@@ -205,6 +184,17 @@ public class MyCustomRule
     {
         return false;
     }
+
+    /**
+     * Injects the value of the shouldIfail parameter into the custom rule.
+     * 
+     * @param shouldIfail set to true if you want the rule to fail. false to succeed.
+     */
+    public void setShouldIfail( boolean shouldIfail )
+    {
+        this.shouldIfail = shouldIfail;
+    }
+
 }
 +---+