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 org.apache.maven.enforcer.rule.api.EnforcerRuleException; 023import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; 024import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; 025 026/** 027 * This rule checks that certain properties are set. 028 * 029 * @author Paul Gier 030 */ 031public class RequireProperty 032 extends AbstractPropertyEnforcerRule 033{ 034 035 /** 036 * Specify the required property. 037 * 038 * @see {@link #setProperty(String)} 039 * @see {@link #getPropertyName()} 040 */ 041 private String property = null; 042 043 public final void setProperty( String property ) 044 { 045 this.property = property; 046 } 047 048 @Override 049 public Object resolveValue( EnforcerRuleHelper helper ) 050 throws EnforcerRuleException 051 { 052 Object propValue = null; 053 try 054 { 055 propValue = helper.evaluate( "${" + property + "}" ); 056 } 057 catch ( ExpressionEvaluationException eee ) 058 { 059 throw new EnforcerRuleException( "Unable to evaluate property: " + property, eee ); 060 } 061 return propValue; 062 } 063 064 protected String resolveValue() 065 { 066 return null; 067 } 068 069 @Override 070 public String getPropertyName() 071 { 072 return property; 073 } 074 075 @Override 076 public String getName() 077 { 078 return "Property"; 079 } 080}