package org.apache.maven.plugins.enforcer;

import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;

/**
 * Abstract enforcer rule that give a foundation to validate properties from multiple sources.
 *
 * @author Paul Gier
 * @author <a href='mailto:marvin[at]marvinformatics[dot]com'>Marvin Froeder</a>
 * @version $Id: AbstractPropertyEnforcerRule.java $
 */
public abstract class AbstractPropertyEnforcerRule
    extends AbstractNonCacheableEnforcerRule
{

    /**
     * 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;

    public AbstractPropertyEnforcerRule()
    {
        super();
    }

    /**
     * Execute the rule.
     *
     * @param helper the helper
     * @throws EnforcerRuleException the enforcer rule exception
     */
    public void execute( EnforcerRuleHelper helper )
        throws EnforcerRuleException
    {
        Object propValue = resolveValue( helper );

        // Check that the property is not null or empty string
        if ( propValue == null )
        {
            if ( message == null )
            {
                message = getName() + " \"" + getPropertyName() + "\" 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 = getName() + " \"" + getPropertyName() + "\" evaluates to \"" + propValue + "\".  "
                    + "This does not match the regular expression \"" + regex + "\"";
            }
            throw new EnforcerRuleException( regexMessage );
        }
    }

    /**
     * How the property that is being evaluated is called
     */
    public abstract String getName();

    /**
     * The name of the property currently being evaluated, this is used for default message pourpouses only
     */
    public abstract String getPropertyName();

    /**
     * Resolves the property value
     *
     * @param helper
     * @throws EnforcerRuleException
     */
    public abstract Object resolveValue( EnforcerRuleHelper helper )
        throws EnforcerRuleException;

}
@@ -39,16 +39,843 @@
 cer;%0D%0A%0D%0A
+/*%0D%0A * Licensed to the Apache Software Foundation (ASF) under one%0D%0A * or more contributor license agreements.  See the NOTICE file%0D%0A * distributed with this work for additional information%0D%0A * regarding copyright ownership.  The ASF licenses this file%0D%0A * to you under the Apache License, Version 2.0 (the%0D%0A * %22License%22); you may not use this file except in compliance%0D%0A * with the License.  You may obtain a copy of the License at%0D%0A *%0D%0A *  http://www.apache.org/licenses/LICENSE-2.0%0D%0A *%0D%0A * Unless required by applicable law or agreed to in writing,%0D%0A * software distributed under the License is distributed on an%0D%0A * %22AS IS%22 BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY%0D%0A * KIND, either express or implied.  See the License for the%0D%0A * specific language governing permissions and limitations%0D%0A * under the License.%0D%0A */%0D%0A%0D%0A
 import o

add missing license header