Profile tests. Fixes for negation activation.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@749717 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Britton Isbell 2009-03-03 19:57:01 +00:00
parent e417b541e0
commit c151f2925f
4 changed files with 86 additions and 7 deletions

View File

@ -10,21 +10,36 @@ import java.util.List;
public class JdkMatcher implements ActiveProfileMatcher { public class JdkMatcher implements ActiveProfileMatcher {
//TODO: Ranges //TODO: Ranges
public boolean isMatch(ModelContainer modelContainer, List<InterpolatorProperty> properties) { public boolean isMatch(ModelContainer modelContainer, List<InterpolatorProperty> properties) {
if(modelContainer == null ) { if(modelContainer == null )
{
throw new IllegalArgumentException("modelContainer: null"); throw new IllegalArgumentException("modelContainer: null");
} }
if(properties == null) { if(properties == null)
{
return false; return false;
} }
for(InterpolatorProperty property : properties) { for(InterpolatorProperty property : properties)
if(property.getKey().equals("${java.specification.version}")) { {
if(property.getKey().equals("${java.specification.version}"))
{
String version = property.getValue(); String version = property.getValue();
for(ModelProperty modelProperty : modelContainer.getProperties()) { for(ModelProperty modelProperty : modelContainer.getProperties())
if(modelProperty.getUri().equals(ProjectUri.Profiles.Profile.Activation.jdk)) { {
if(modelProperty.getUri().equals(ProjectUri.Profiles.Profile.Activation.jdk))
{
if(modelProperty.getValue().startsWith("!"))
{
return !version.equals(modelProperty.getValue().replaceFirst("!", ""));
}
else
{
return version.equals(modelProperty.getValue()); return version.equals(modelProperty.getValue());
} }
}
} }
return false; return false;
} }

View File

@ -35,6 +35,39 @@ public class JdkMatcherTest {
assertTrue(matcher.isMatch(modelContainer, props)); assertTrue(matcher.isMatch(modelContainer, props));
} }
@org.junit.Test
public void jdkVersionDoesNotMatchWithNotSymbol() {
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null));
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null));
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.jdk , "!1.5"));
ModelContainer modelContainer = new DefaultModelContainer(modelProperties);
List<InterpolatorProperty> props = new ArrayList<InterpolatorProperty>();
props.add(new InterpolatorProperty("${java.specification.version}" , "1.5"));
JdkMatcher matcher = new JdkMatcher();
assertTrue(!matcher.isMatch(modelContainer, props));
}
@org.junit.Test
public void jdkVersionDoesMatchWithNotSymbol() {
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null));
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null));
modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.jdk , "!1.5"));
ModelContainer modelContainer = new DefaultModelContainer(modelProperties);
List<InterpolatorProperty> props = new ArrayList<InterpolatorProperty>();
props.add(new InterpolatorProperty("${java.specification.version}" , "1.6"));
JdkMatcher matcher = new JdkMatcher();
assertTrue(matcher.isMatch(modelContainer, props));
}
@org.junit.Test @org.junit.Test
public void jdkVersionNotMatches() { public void jdkVersionNotMatches() {
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>(); List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();

View File

@ -78,6 +78,19 @@ public class PomConstructionTest
} }
*/ */
/**
* Tests that modules is not overriden by profile
*
* @throws Exception
*/
public void testProfileModules()
throws Exception
{
PomTestWrapper pom = buildPomFromMavenProject( "profile-module", "a" );
assertEquals( "test-prop", pom.getValue( "properties[1]/b" ) );//verifies profile applied
assertEquals( "test-module", pom.getValue( "modules[1]" ) );
}
/** /**
* Will throw exception if doesn't find parent(s) in build * Will throw exception if doesn't find parent(s) in build
* *

View File

@ -0,0 +1,18 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>gid</groupId>
<artifactId>aid</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
<module>test-module</module>
</modules>
<profiles>
<profile>
<id>a</id>
<properties>
<b>test-prop</b>
</properties>
</profile>
</profiles>
</project>