Cleaned up code - generics

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@750104 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Britton Isbell 2009-03-04 19:08:28 +00:00
parent 023a96155b
commit a2b9aa8bf3
4 changed files with 111 additions and 144 deletions

View File

@ -12,7 +12,6 @@ import java.util.List;
public class JdkMatcher
implements ActiveProfileMatcher
{
// TODO: Ranges
public boolean isMatch( ModelContainer modelContainer, List<InterpolatorProperty> properties )
{
if ( modelContainer == null )
@ -39,9 +38,9 @@ public class JdkMatcher
{
return !version.equals( modelProperty.getResolvedValue().replaceFirst( "!", "" ) );
}
else if ( isRange( modelProperty.getResolvedValue()) )
else if ( isRange( modelProperty.getResolvedValue() ) )
{
return isInRange( version, getRange( modelProperty.getResolvedValue()));
return isInRange( version, getRange( modelProperty.getResolvedValue() ) );
}
else
{
@ -58,44 +57,44 @@ public class JdkMatcher
private static boolean isInRange( String value, List<RangeValue> range )
{
int leftRelation = getRelationOrder(value, range.get( 0 ), true);
int leftRelation = getRelationOrder( value, range.get( 0 ), true );
if( leftRelation == 0)
if ( leftRelation == 0 )
{
return true;
}
if(leftRelation < 0)
if ( leftRelation < 0 )
{
return false;
}
return getRelationOrder(value, range.get( 1 ), false) <= 0;
return getRelationOrder( value, range.get( 1 ), false ) <= 0;
}
private static int getRelationOrder(String value, RangeValue rangeValue, boolean isLeft)
private static int getRelationOrder( String value, RangeValue rangeValue, boolean isLeft )
{
List<String> valueTokens = Arrays.asList(value.split( "." ));
List<String> rangeValueTokens = Arrays.asList(rangeValue.value.split( "." ));
List<String> valueTokens = Arrays.asList( value.split( "." ) );
List<String> rangeValueTokens = Arrays.asList( rangeValue.value.split( "." ) );
int max = Math.max( valueTokens.size(), rangeValueTokens.size() );
addZeroTokens(valueTokens, max);
addZeroTokens(rangeValueTokens, max);
addZeroTokens( valueTokens, max );
addZeroTokens( rangeValueTokens, max );
if(value.equals( rangeValue.value ) )
if ( value.equals( rangeValue.value ) )
{
return (rangeValue.isClosed()) ? 0 : -1;
return ( rangeValue.isClosed() ) ? 0 : -1;
}
for( int i = 0; i < valueTokens.size() ; i++)
for ( int i = 0; i < valueTokens.size(); i++ )
{
int x = Integer.getInteger( valueTokens.get( i ) );
int y = Integer.getInteger( rangeValueTokens.get( i ) );
if( x < y)
if ( x < y )
{
return -1;
}
else if( x > y)
else if ( x > y )
{
return 1;
}
@ -103,17 +102,18 @@ public class JdkMatcher
return 0;
}
private static void addZeroTokens(List<String> tokens, int max)
private static void addZeroTokens( List<String> tokens, int max )
{
if(tokens.size() < max)
if ( tokens.size() < max )
{
for ( int i = 0; i < ( max - tokens.size() ); i++ )
{
for(int i = 0; i < (max - tokens.size()) ; i++){
tokens.add( "0" );
}
}
}
private static boolean isRange(String value)
private static boolean isRange( String value )
{
return value.contains( "," );
}
@ -142,9 +142,9 @@ public class JdkMatcher
}
}
if(ranges.size() < 2)
if ( ranges.size() < 2 )
{
ranges.add( new RangeValue("99999999", false));
ranges.add( new RangeValue( "99999999", false ) );
}
return ranges;
}

View File

@ -52,7 +52,7 @@ public class DefaultProfileManager
{
private MutablePlexusContainer container;
private Map profilesById = new LinkedHashMap();
private Map<String, Profile> profilesById = new LinkedHashMap<String, Profile>();
private ProfileActivationContext profileActivationContext;
@ -100,7 +100,7 @@ public class DefaultProfileManager
this.profileActivationContext = profileActivationContext;
}
public Map getProfilesById()
public Map<String, Profile> getProfilesById()
{
return profilesById;
}
@ -130,14 +130,11 @@ public class DefaultProfileManager
}
// TODO: Portions of this logic are duplicated in o.a.m.p.b.p.ProfileContext, something is wrong here
public List getActiveProfiles( Model model )
public List<Profile> getActiveProfiles( Model model )
throws ProfileActivationException
{
try
{
List activeFromPom = new ArrayList();
List activeExternal = new ArrayList();
List<Profile> activeFromPom = new ArrayList<Profile>();
List<Profile> activeExternal = new ArrayList<Profile>();
for ( Iterator it = profilesById.entrySet().iterator(); it.hasNext(); )
{
@ -171,14 +168,12 @@ public class DefaultProfileManager
if ( activeFromPom.isEmpty() )
{
List defaultIds = profileActivationContext.getActiveByDefaultProfileIds();
List<String> defaultIds = profileActivationContext.getActiveByDefaultProfileIds();
List deactivatedIds = profileActivationContext.getExplicitlyInactiveProfileIds();
List<String> deactivatedIds = profileActivationContext.getExplicitlyInactiveProfileIds();
for ( Iterator it = defaultIds.iterator(); it.hasNext(); )
for ( String profileId : defaultIds )
{
String profileId = (String) it.next();
// If this profile was excluded, don't add it back in
// Fixes MNG-3545
if ( deactivatedIds.contains( profileId ) )
@ -194,17 +189,13 @@ public class DefaultProfileManager
}
}
List allActive = new ArrayList( activeFromPom.size() + activeExternal.size() );
List<Profile> allActive = new ArrayList<Profile>( activeFromPom.size() + activeExternal.size() );
allActive.addAll( activeExternal );
allActive.addAll( activeFromPom );
return allActive;
}
finally
{
}
}
private static List<ActiveProfileMatcher> matchers = Arrays.asList(new FileMatcher(),
new JdkMatcher(), new OperatingSystemMatcher(), new PropertyMatcher());

View File

@ -33,8 +33,8 @@ public interface ProfileManager
void addProfiles( List<Profile> profiles );
Map getProfilesById();
Map<String, Profile> getProfilesById();
List getActiveProfiles( Model model )
List<Profile> getActiveProfiles( Model model )
throws ProfileActivationException;
}

View File

@ -510,10 +510,8 @@ public class MavenProject
list.add( getBuild().getOutputDirectory() );
for ( Iterator<Artifact> i = getArtifacts().iterator(); i.hasNext(); )
for ( Artifact a : getArtifacts() )
{
Artifact a = (Artifact) i.next();
if ( a.getArtifactHandler().isAddedToClasspath() )
{
// TODO: let the scope handler deal with this
@ -530,10 +528,8 @@ public class MavenProject
{
List<Artifact> list = new ArrayList<Artifact>( getArtifacts().size() );
for ( Iterator<Artifact> i = getArtifacts().iterator(); i.hasNext(); )
for ( Artifact a : getArtifacts() )
{
Artifact a = (Artifact) i.next();
// TODO: classpath check doesn't belong here - that's the other method
if ( a.getArtifactHandler().isAddedToClasspath() )
{
@ -558,10 +554,8 @@ public class MavenProject
List<Dependency> list = new ArrayList<Dependency>( artifacts.size() );
for ( Iterator<Artifact> i = getArtifacts().iterator(); i.hasNext(); )
for ( Artifact a : getArtifacts() )
{
Artifact a = (Artifact) i.next();
// TODO: let the scope handler deal with this
if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() ) || Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
{
@ -589,10 +583,8 @@ public class MavenProject
list.add( getBuild().getOutputDirectory() );
for ( Iterator<Artifact> i = getArtifacts().iterator(); i.hasNext(); )
for ( Artifact a : getArtifacts() )
{
Artifact a = (Artifact) i.next();
if ( a.getArtifactHandler().isAddedToClasspath() )
{
File file = a.getFile();
@ -610,10 +602,8 @@ public class MavenProject
{
List<Artifact> list = new ArrayList<Artifact>( getArtifacts().size() );
for ( Iterator<Artifact> i = getArtifacts().iterator(); i.hasNext(); )
for ( Artifact a : getArtifacts() )
{
Artifact a = (Artifact) i.next();
// TODO: classpath check doesn't belong here - that's the other method
if ( a.getArtifactHandler().isAddedToClasspath() )
{
@ -634,10 +624,8 @@ public class MavenProject
List<Dependency> list = new ArrayList<Dependency>( artifacts.size() );
for ( Iterator<Artifact> i = getArtifacts().iterator(); i.hasNext(); )
for ( Artifact a : getArtifacts() )
{
Artifact a = (Artifact) i.next();
Dependency dependency = new Dependency();
dependency.setArtifactId( a.getArtifactId() );
@ -659,10 +647,8 @@ public class MavenProject
list.add( getBuild().getOutputDirectory() );
for ( Iterator<Artifact> i = getArtifacts().iterator(); i.hasNext(); )
for ( Artifact a : getArtifacts() )
{
Artifact a = (Artifact) i.next();
if ( a.getArtifactHandler().isAddedToClasspath() )
{
// TODO: let the scope handler deal with this
@ -684,10 +670,8 @@ public class MavenProject
{
List<Artifact> list = new ArrayList<Artifact>( getArtifacts().size() );
for ( Iterator<Artifact> i = getArtifacts().iterator(); i.hasNext(); )
for ( Artifact a : getArtifacts() )
{
Artifact a = (Artifact) i.next();
// TODO: classpath check doesn't belong here - that's the other method
if ( a.getArtifactHandler().isAddedToClasspath() )
{
@ -712,10 +696,8 @@ public class MavenProject
List<Dependency> list = new ArrayList<Dependency>( artifacts.size() );
for ( Iterator<Artifact> i = artifacts.iterator(); i.hasNext(); )
for ( Artifact a : getArtifacts() )
{
Artifact a = (Artifact) i.next();
// TODO: let the scope handler deal with this
if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_RUNTIME.equals( a.getScope() ) )
{
@ -741,10 +723,8 @@ public class MavenProject
list.add( getBuild().getOutputDirectory() );
for ( Iterator<Artifact> i = getArtifacts().iterator(); i.hasNext(); )
for ( Artifact a : getArtifacts() )
{
Artifact a = (Artifact) i.next();
if ( a.getArtifactHandler().isAddedToClasspath() )
{
// TODO: let the scope handler deal with this
@ -761,10 +741,8 @@ public class MavenProject
{
List<Artifact> list = new ArrayList<Artifact>( getArtifacts().size() );
for ( Iterator<Artifact> i = getArtifacts().iterator(); i.hasNext(); )
for ( Artifact a : getArtifacts() )
{
Artifact a = (Artifact) i.next();
// TODO: classpath check doesn't belong here - that's the other method
if ( a.getArtifactHandler().isAddedToClasspath() )
{
@ -789,10 +767,8 @@ public class MavenProject
List<Dependency> list = new ArrayList<Dependency>( artifacts.size() );
for ( Iterator<Artifact> i = getArtifacts().iterator(); i.hasNext(); )
for ( Artifact a : getArtifacts() )
{
Artifact a = (Artifact) i.next();
// TODO: let the scope handler deal with this
if ( Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
{
@ -1359,6 +1335,7 @@ public class MavenProject
}
}
//TODO: remove ModelUtils
public void injectPluginManagementInfo( Plugin plugin )
{
PluginManagement pm = getModelBuild().getPluginManagement();
@ -1409,7 +1386,6 @@ public class MavenProject
public List<Repository> getPluginRepositories()
{
// return model.getPluginRepositories();
return getModel().getRepositories();
}