mirror of https://github.com/apache/maven.git
Add solution to http://jira.codehaus.org/browse/MNG-4565
Signed-off-by: Jason van Zyl <jason@tesla.io>
This commit is contained in:
parent
faccffe269
commit
c6529932f9
|
@ -104,13 +104,19 @@ public class DefaultProfileSelector
|
|||
|
||||
private boolean isActive( Profile profile, ProfileActivationContext context, ModelProblemCollector problems )
|
||||
{
|
||||
boolean isActive = false;
|
||||
for ( ProfileActivator activator : activators ) {
|
||||
if ( activator.presentInConfig( profile, context, problems ) ) {
|
||||
isActive = true;
|
||||
}
|
||||
}
|
||||
for ( ProfileActivator activator : activators )
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( activator.isActive( profile, context, problems ) )
|
||||
if ( activator.presentInConfig( profile, context, problems ) )
|
||||
{
|
||||
return true;
|
||||
isActive &= activator.isActive( profile, context, problems );
|
||||
}
|
||||
}
|
||||
catch ( RuntimeException e )
|
||||
|
@ -122,7 +128,7 @@ public class DefaultProfileSelector
|
|||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return isActive;
|
||||
}
|
||||
|
||||
private boolean isActiveByDefault( Profile profile )
|
||||
|
|
|
@ -167,4 +167,23 @@ public class FileProfileActivator
|
|||
return missing ? !fileExists : fileExists;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean presentInConfig( Profile profile, ProfileActivationContext context, ModelProblemCollector problems )
|
||||
{
|
||||
Activation activation = profile.getActivation();
|
||||
|
||||
if ( activation == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ActivationFile file = activation.getFile();
|
||||
|
||||
if ( file == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -83,6 +83,25 @@ public class JdkVersionProfileActivator
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean presentInConfig( Profile profile, ProfileActivationContext context, ModelProblemCollector problems )
|
||||
{
|
||||
Activation activation = profile.getActivation();
|
||||
|
||||
if ( activation == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
String jdk = activation.getJdk();
|
||||
|
||||
if ( jdk == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean isInRange( String value, List<RangeValue> range )
|
||||
{
|
||||
int leftRelation = getRelationOrder( value, range.get( 0 ), true );
|
||||
|
|
|
@ -76,6 +76,25 @@ public class OperatingSystemProfileActivator
|
|||
return active;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean presentInConfig( Profile profile, ProfileActivationContext context, ModelProblemCollector problems )
|
||||
{
|
||||
Activation activation = profile.getActivation();
|
||||
|
||||
if ( activation == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ActivationOS os = activation.getOs();
|
||||
|
||||
if ( os == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean ensureAtLeastOneNonNull( ActivationOS os )
|
||||
{
|
||||
return os.getArch() != null || os.getFamily() != null || os.getName() != null || os.getVersion() != null;
|
||||
|
|
|
@ -43,4 +43,17 @@ public interface ProfileActivator
|
|||
*/
|
||||
boolean isActive( Profile profile, ProfileActivationContext context, ModelProblemCollector problems );
|
||||
|
||||
/**
|
||||
* Determines whether specified activation method is present in configuration or not. It should help to have AND between
|
||||
* activation conditions
|
||||
* Need for solving http://jira.codehaus.org/browse/MNG-4565
|
||||
* @param profile The profile whose activation status should be determined, must not be {@code null}.
|
||||
* @param context The environmental context used to determine the activation status of the profile, must not be
|
||||
* {@code null}.
|
||||
* @param problems The container used to collect problems (e.g. bad syntax) that were encountered, must not be
|
||||
* {@code null}.
|
||||
* @return {@code true} if the profile is active, {@code false} otherwise.
|
||||
*/
|
||||
boolean presentInConfig( Profile profile, ProfileActivationContext context, ModelProblemCollector problems );
|
||||
|
||||
}
|
||||
|
|
|
@ -103,4 +103,23 @@ public class PropertyProfileActivator
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean presentInConfig( Profile profile, ProfileActivationContext context, ModelProblemCollector problems )
|
||||
{
|
||||
Activation activation = profile.getActivation();
|
||||
|
||||
if ( activation == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ActivationProperty property = activation.getProperty();
|
||||
|
||||
if ( property == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
package org.apache.maven.model.building;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author Konstantin Perikov
|
||||
*/
|
||||
public class ComplexActivationTest
|
||||
extends TestCase
|
||||
{
|
||||
|
||||
private File getPom( String name )
|
||||
{
|
||||
return new File( "src/test/resources/poms/factory/" + name + ".xml" ).getAbsoluteFile();
|
||||
}
|
||||
|
||||
public void testAndConditionInActivation()
|
||||
throws Exception
|
||||
{
|
||||
Properties sysProperties = new Properties();
|
||||
sysProperties.setProperty( "myproperty", "test" );
|
||||
|
||||
ModelBuilder builder = new DefaultModelBuilderFactory().newInstance();
|
||||
assertNotNull( builder );
|
||||
|
||||
DefaultModelBuildingRequest request = new DefaultModelBuildingRequest();
|
||||
request.setProcessPlugins( true );
|
||||
request.setPomFile( getPom( "complex" ) );
|
||||
request.setSystemProperties( sysProperties );
|
||||
|
||||
ModelBuildingResult result = builder.build( request );
|
||||
assertNotNull( result );
|
||||
assertNotNull( result.getEffectiveModel() );
|
||||
assertEquals( "activated-1", result.getEffectiveModel().getProperties().get( "profile.file" ) );
|
||||
assertNull( result.getEffectiveModel().getProperties().get( "profile.miss" ) );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>test</groupId>
|
||||
<artifactId>test</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<properties>
|
||||
<my.filter.value>hello</my.filter.value>
|
||||
</properties>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>two-conditions</id>
|
||||
<activation>
|
||||
<file>
|
||||
<exists>simple.xml</exists>
|
||||
</file>
|
||||
<property>
|
||||
<name>myproperty</name>
|
||||
<value>test</value>
|
||||
</property>
|
||||
</activation>
|
||||
<properties>
|
||||
<profile.file>activated-1</profile.file>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>another-two-conditions</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>myproperty</name>
|
||||
<value>test</value>
|
||||
</property>
|
||||
<file>
|
||||
<missing>simple.xml</missing>
|
||||
</file>
|
||||
</activation>
|
||||
<properties>
|
||||
<profile.miss>activated-2</profile.miss>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
Loading…
Reference in New Issue