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,16 +44,20 @@ public class JdkVersionProfileActivator
public boolean isActive( Profile profile, ProfileActivationContext context, ModelProblemCollector problems ) public boolean isActive( Profile profile, ProfileActivationContext context, ModelProblemCollector problems )
{ {
boolean active = false;
Activation activation = profile.getActivation(); Activation activation = profile.getActivation();
if ( activation != null ) if ( activation == null )
{ {
return false;
}
String jdk = activation.getJdk(); String jdk = activation.getJdk();
if ( jdk != null ) if ( jdk == null )
{ {
return false;
}
String version = context.getSystemProperties().get( "java.version" ); String version = context.getSystemProperties().get( "java.version" );
if ( version == null || version.length() <= 0 ) if ( version == null || version.length() <= 0 )
@ -66,21 +70,17 @@ public class JdkVersionProfileActivator
if ( jdk.startsWith( "!" ) ) if ( jdk.startsWith( "!" ) )
{ {
active = !version.startsWith( jdk.substring( 1 ) ); return !version.startsWith( jdk.substring( 1 ) );
} }
else if ( isRange( jdk ) ) else if ( isRange( jdk ) )
{ {
active = isInRange( version, getRange( jdk ) ); return isInRange( version, getRange( jdk ) );
} }
else else
{ {
active = version.startsWith( jdk ); return version.startsWith( jdk );
} }
} }
}
return active;
}
private static boolean isInRange( String value, List<RangeValue> range ) private static boolean isInRange( String value, List<RangeValue> range )
{ {

View File

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

View File

@ -42,16 +42,20 @@ public class PropertyProfileActivator
public boolean isActive( Profile profile, ProfileActivationContext context, ModelProblemCollector problems ) public boolean isActive( Profile profile, ProfileActivationContext context, ModelProblemCollector problems )
{ {
boolean active = false;
Activation activation = profile.getActivation(); Activation activation = profile.getActivation();
if ( activation != null ) if ( activation == null )
{ {
return false;
}
ActivationProperty property = activation.getProperty(); ActivationProperty property = activation.getProperty();
if ( property != null ) if ( property == null )
{ {
return false;
}
String name = property.getName(); String name = property.getName();
boolean reverseName = false; boolean reverseName = false;
@ -88,32 +92,14 @@ public class PropertyProfileActivator
// we have a value, so it has to match the system value... // we have a value, so it has to match the system value...
boolean result = propValue.equals( sysValue ); boolean result = propValue.equals( sysValue );
if ( reverseValue ) return reverseValue ? !result : result;
{
active = !result;
}
else
{
active = result;
}
} }
else else
{ {
boolean result = StringUtils.isNotEmpty( sysValue ); boolean result = StringUtils.isNotEmpty( sysValue );
if ( reverseName ) return reverseName ? !result : result;
{
active = !result;
}
else
{
active = result;
}
}
} }
} }
return active;
}
} }