PR: MNG-864

Fail build if the model contains an expression that doesn't evaluate

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@307311 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-10-08 16:48:21 +00:00
parent 84d1a85baf
commit 3171417299
3 changed files with 32 additions and 13 deletions

View File

@ -25,8 +25,14 @@ public class ModelInterpolationException
extends Exception extends Exception
{ {
private String expression; private String expression;
private String originalMessage; private String originalMessage;
public ModelInterpolationException( String message )
{
super( message );
}
public ModelInterpolationException( String message, Throwable cause ) public ModelInterpolationException( String message, Throwable cause )
{ {
super( message, cause ); super( message, cause );

View File

@ -28,9 +28,9 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.Map;
/** /**
* Use a regular expression search to find and resolve expressions within the POM. * Use a regular expression search to find and resolve expressions within the POM.
@ -142,6 +142,11 @@ public class RegexBasedModelInterpolator
// but this could result in multiple lookups of stringValue, and replaceAll is not correct behaviour // but this could result in multiple lookups of stringValue, and replaceAll is not correct behaviour
matcher.reset( result ); matcher.reset( result );
} }
else
{
throw new ModelInterpolationException(
"Expression '" + wholeExpr + "' did not evaluate to anything in the model" );
}
} }
return result; return result;

View File

@ -68,9 +68,17 @@ public class RegexBasedModelInterpolatorTest
model.addDependency( dep ); model.addDependency( dep );
try
{
Model out = new RegexBasedModelInterpolator().interpolate( model, context ); Model out = new RegexBasedModelInterpolator().interpolate( model, context );
fail( "Should have failed to interpolate with invalid reference" );
}
catch ( ModelInterpolationException expected )
{
assertTrue( true );
}
assertEquals( "${something}", ( (Dependency) out.getDependencies().get( 0 ) ).getVersion() ); // assertEquals( "${something}", ( (Dependency) out.getDependencies().get( 0 ) ).getVersion() );
} }
public void testTwoReferences() public void testTwoReferences()