You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2012/09/05 23:00:35 UTC

svn commit: r1381367 - /maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireProperty.java

Author: olamy
Date: Wed Sep  5 21:00:34 2012
New Revision: 1381367

URL: http://svn.apache.org/viewvc?rev=1381367&view=rev
Log:
[MENFORCER-136] New enforcer for environment variables.
Submitted by Marvin Froeder.

Modified:
    maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireProperty.java

Modified: maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireProperty.java
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireProperty.java?rev=1381367&r1=1381366&r2=1381367&view=diff
==============================================================================
--- maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireProperty.java (original)
+++ maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireProperty.java Wed Sep  5 21:00:34 2012
@@ -25,29 +25,18 @@ import org.codehaus.plexus.component.con
 
 /**
  * This rule checks that certain properties are set.
- *
+ * 
  * @author Paul Gier
  */
 public class RequireProperty
-    extends AbstractNonCacheableEnforcerRule
+    extends AbstractPropertyEnforcerRule
 {
 
     /** Specify the required property. */
     public String property = null;
 
-    /** Match the property value to a given regular expression. Defaults to <code>null</code> (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 )
+    @Override
+    public Object resolveValue( EnforcerRuleHelper helper )
         throws EnforcerRuleException
     {
         Object propValue = null;
@@ -59,26 +48,23 @@ public class RequireProperty
         {
             throw new EnforcerRuleException( "Unable to evaluate property: " + property, eee );
         }
+        return propValue;
+    }
 
-        // 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 );
-        }
+    protected String resolveValue()
+    {
+        return null;
+    }
+
+    @Override
+    public String getPropertyName()
+    {
+        return property;
+    }
+
+    @Override
+    public String getName()
+    {
+        return "Property";
     }
 }