code simplification

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1403786 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Herve Boutemy 2012-10-30 17:20:14 +00:00
parent 0312cb0ff8
commit 622b08ef6a
3 changed files with 114 additions and 154 deletions

View File

@ -44,42 +44,42 @@ public class JdkVersionProfileActivator
public boolean isActive( Profile profile, ProfileActivationContext context, ModelProblemCollector problems )
{
boolean active = false;
Activation activation = profile.getActivation();
if ( activation != null )
if ( activation == null )
{
String jdk = activation.getJdk();
if ( jdk != null )
{
String version = context.getSystemProperties().get( "java.version" );
if ( version == null || version.length() <= 0 )
{
problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE )
.setMessage( "Failed to determine Java version for profile " + profile.getId() )
.setLocation(activation.getLocation( "jdk" ) ) );
return false;
}
if ( jdk.startsWith( "!" ) )
{
active = !version.startsWith( jdk.substring( 1 ) );
}
else if ( isRange( jdk ) )
{
active = isInRange( version, getRange( jdk ) );
}
else
{
active = version.startsWith( jdk );
}
}
return false;
}
return active;
String jdk = activation.getJdk();
if ( jdk == null )
{
return false;
}
String version = context.getSystemProperties().get( "java.version" );
if ( version == null || version.length() <= 0 )
{
problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE )
.setMessage( "Failed to determine Java version for profile " + profile.getId() )
.setLocation(activation.getLocation( "jdk" ) ) );
return false;
}
if ( jdk.startsWith( "!" ) )
{
return !version.startsWith( jdk.substring( 1 ) );
}
else if ( isRange( jdk ) )
{
return isInRange( version, getRange( jdk ) );
}
else
{
return version.startsWith( jdk );
}
}
private static boolean isInRange( String value, List<RangeValue> range )

View File

@ -39,35 +39,37 @@ public class OperatingSystemProfileActivator
public boolean isActive( Profile profile, ProfileActivationContext context, ModelProblemCollector problems )
{
boolean active = false;
Activation activation = profile.getActivation();
if ( activation != null )
if ( activation == null )
{
ActivationOS os = activation.getOs();
return false;
}
if ( os != null )
{
active = ensureAtLeastOneNonNull( os );
ActivationOS os = activation.getOs();
if ( active && os.getFamily() != null )
{
active = determineFamilyMatch( os.getFamily() );
}
if ( active && os.getName() != null )
{
active = determineNameMatch( os.getName() );
}
if ( active && os.getArch() != null )
{
active = determineArchMatch( os.getArch() );
}
if ( active && os.getVersion() != null )
{
active = determineVersionMatch( os.getVersion() );
}
}
if ( os == null )
{
return false;
}
boolean active = ensureAtLeastOneNonNull( os );
if ( active && os.getFamily() != null )
{
active = determineFamilyMatch( os.getFamily() );
}
if ( active && os.getName() != null )
{
active = determineNameMatch( os.getName() );
}
if ( active && os.getArch() != null )
{
active = determineArchMatch( os.getArch() );
}
if ( active && os.getVersion() != null )
{
active = determineVersionMatch( os.getVersion() );
}
return active;
@ -91,14 +93,7 @@ public class OperatingSystemProfileActivator
boolean result = Os.isVersion( test );
if ( reverse )
{
return !result;
}
else
{
return result;
}
return reverse ? !result : result;
}
private boolean determineArchMatch( String arch )
@ -114,14 +109,7 @@ public class OperatingSystemProfileActivator
boolean result = Os.isArch( test );
if ( reverse )
{
return !result;
}
else
{
return result;
}
return reverse ? !result : result;
}
private boolean determineNameMatch( String name )
@ -137,14 +125,7 @@ public class OperatingSystemProfileActivator
boolean result = Os.isName( test );
if ( reverse )
{
return !result;
}
else
{
return result;
}
return reverse ? !result : result;
}
private boolean determineFamilyMatch( String family )
@ -160,14 +141,7 @@ public class OperatingSystemProfileActivator
boolean result = Os.isFamily( test );
if ( reverse )
{
return !result;
}
else
{
return result;
}
return reverse ? !result : result;
}
}

View File

@ -42,78 +42,64 @@ public class PropertyProfileActivator
public boolean isActive( Profile profile, ProfileActivationContext context, ModelProblemCollector problems )
{
boolean active = false;
Activation activation = profile.getActivation();
if ( activation != null )
if ( activation == null )
{
ActivationProperty property = activation.getProperty();
if ( property != null )
{
String name = property.getName();
boolean reverseName = false;
if ( name != null && name.startsWith( "!" ) )
{
reverseName = true;
name = name.substring( 1 );
}
if ( name == null || name.length() <= 0 )
{
problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE )
.setMessage( "The property name is required to activate the profile " + profile.getId() )
.setLocation( property.getLocation( "" ) ) );
return false;
}
String sysValue = context.getUserProperties().get( name );
if ( sysValue == null )
{
sysValue = context.getSystemProperties().get( name );
}
String propValue = property.getValue();
if ( StringUtils.isNotEmpty( propValue ) )
{
boolean reverseValue = false;
if ( propValue.startsWith( "!" ) )
{
reverseValue = true;
propValue = propValue.substring( 1 );
}
// we have a value, so it has to match the system value...
boolean result = propValue.equals( sysValue );
if ( reverseValue )
{
active = !result;
}
else
{
active = result;
}
}
else
{
boolean result = StringUtils.isNotEmpty( sysValue );
if ( reverseName )
{
active = !result;
}
else
{
active = result;
}
}
}
return false;
}
return active;
ActivationProperty property = activation.getProperty();
if ( property == null )
{
return false;
}
String name = property.getName();
boolean reverseName = false;
if ( name != null && name.startsWith( "!" ) )
{
reverseName = true;
name = name.substring( 1 );
}
if ( name == null || name.length() <= 0 )
{
problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE )
.setMessage( "The property name is required to activate the profile " + profile.getId() )
.setLocation( property.getLocation( "" ) ) );
return false;
}
String sysValue = context.getUserProperties().get( name );
if ( sysValue == null )
{
sysValue = context.getSystemProperties().get( name );
}
String propValue = property.getValue();
if ( StringUtils.isNotEmpty( propValue ) )
{
boolean reverseValue = false;
if ( propValue.startsWith( "!" ) )
{
reverseValue = true;
propValue = propValue.substring( 1 );
}
// we have a value, so it has to match the system value...
boolean result = propValue.equals( sysValue );
return reverseValue ? !result : result;
}
else
{
boolean result = StringUtils.isNotEmpty( sysValue );
return reverseName ? !result : result;
}
}
}