PR: MNG-1509

Submitted By: Bernd Bohmann
Reviewed By: John Casey

Applied patches. These patches added the OS activator to the component descriptor, fixed the activation implementation for it, and finally added a unit test for OS activation.


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@355387 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-12-09 05:57:05 +00:00
parent 2e89dadbce
commit 4e955c058a
3 changed files with 59 additions and 12 deletions

View File

@ -35,17 +35,28 @@ public class OperatingSystemProfileActivator
{ {
Activation activation = profile.getActivation(); Activation activation = profile.getActivation();
ActivationOS os = activation.getOs(); ActivationOS os = activation.getOs();
boolean hasNonNull = ensureAtLeastOneNonNull( os ); boolean result = ensureAtLeastOneNonNull( os );
boolean isFamily = determineFamilyMatch( os.getFamily() ); if ( result && os.getFamily() != null )
boolean isName = determineNameMatch( os.getName() ); {
boolean isArch = determineArchMatch( os.getArch() ); result = determineFamilyMatch( os.getFamily() );
boolean isVersion = determineVersionMatch( os.getVersion() ); }
if ( result && os.getName() != null )
return hasNonNull && isFamily && isName && isArch && isVersion; {
result = determineNameMatch( os.getName() );
}
if ( result && os.getArch() != null )
{
result = determineArchMatch( os.getArch() );
}
if ( result && os.getVersion() != null )
{
result = determineVersionMatch( os.getVersion() );
}
return result;
} }
private boolean ensureAtLeastOneNonNull( ActivationOS os ) private boolean ensureAtLeastOneNonNull( ActivationOS os )
{ {
return os.getArch() != null || os.getFamily() != null || os.getName() != null || os.getVersion() != null; return os.getArch() != null || os.getFamily() != null || os.getName() != null || os.getVersion() != null;
@ -107,9 +118,9 @@ public class OperatingSystemProfileActivator
reverse = true; reverse = true;
test = test.substring( 1 ); test = test.substring( 1 );
} }
boolean result = Os.isName( test ); boolean result = Os.isName( test );
if ( reverse ) if ( reverse )
{ {
return !result; return !result;

View File

@ -115,6 +115,16 @@
<role-hint>system-property</role-hint> <role-hint>system-property</role-hint>
<implementation>org.apache.maven.profiles.activation.SystemPropertyProfileActivator</implementation> <implementation>org.apache.maven.profiles.activation.SystemPropertyProfileActivator</implementation>
</component> </component>
<!--
|
|
|
-->
<component>
<role>org.apache.maven.profiles.activation.ProfileActivator</role>
<role-hint>os</role-hint>
<implementation>org.apache.maven.profiles.activation.OperatingSystemProfileActivator</implementation>
</component>
<!-- <!--
| |
| |

View File

@ -3,6 +3,7 @@ package org.apache.maven.profiles;
import org.apache.maven.model.Activation; import org.apache.maven.model.Activation;
import org.apache.maven.model.ActivationProperty; import org.apache.maven.model.ActivationProperty;
import org.apache.maven.model.Profile; import org.apache.maven.model.Profile;
import org.apache.maven.model.ActivationOS;
import org.apache.maven.profiles.activation.ProfileActivationException; import org.apache.maven.profiles.activation.ProfileActivationException;
import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.PlexusTestCase;
@ -156,4 +157,29 @@ public class DefaultProfileManagerTest
assertEquals( 0, active.size() ); assertEquals( 0, active.size() );
} }
public void testOsActivationProfile() throws ProfileActivationException
{
Profile osActivated = new Profile();
osActivated.setId("os-profile");
Activation osActivation = new Activation();
ActivationOS activationOS = new ActivationOS();
activationOS.setName("!dddd");
osActivation.setOs(activationOS);
osActivated.setActivation(osActivation);
ProfileManager profileManager = new DefaultProfileManager(getContainer());
profileManager.addProfile(osActivated);
List active = profileManager.getActiveProfiles();
assertNotNull( active );
assertEquals( 1, active.size() );
}
} }