001package org.apache.maven.plugins.enforcer;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *  http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.util.List;
023
024import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
025import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
026import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
027
028/**
029 * This rule checks that certain properties are set.
030 * 
031 * @author Paul Gier
032 */
033public class RequireProperty
034    extends AbstractPropertyEnforcerRule
035{
036
037    /** Specify the required property. 
038     * 
039     * @deprecated the visibility will be reduced to private with the next major version
040     * @see {@link #setProperty(String)}
041     * @see {@link #getPropertyName()}
042     */
043    public String property = null;
044    
045    
046    public final void setProperty( String property )
047    {
048        this.property = property;
049    }
050
051    @Override
052    public Object resolveValue( EnforcerRuleHelper helper )
053        throws EnforcerRuleException
054    {
055        Object propValue = null;
056        try
057        {
058            propValue = helper.evaluate( "${" + property + "}" );
059        }
060        catch ( ExpressionEvaluationException eee )
061        {
062            throw new EnforcerRuleException( "Unable to evaluate property: " + property, eee );
063        }
064        return propValue;
065    }
066
067    protected String resolveValue()
068    {
069        return null;
070    }
071
072    @Override
073    public String getPropertyName()
074    {
075        return property;
076    }
077
078    @Override
079    public String getName()
080    {
081        return "Property";
082    }
083}