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 public class JdkMatcher
implements ActiveProfileMatcher implements ActiveProfileMatcher
{ {
// TODO: Ranges
public boolean isMatch( ModelContainer modelContainer, List<InterpolatorProperty> properties ) public boolean isMatch( ModelContainer modelContainer, List<InterpolatorProperty> properties )
{ {
if ( modelContainer == null ) if ( modelContainer == null )
@ -107,7 +106,8 @@ public class JdkMatcher
{ {
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" ); tokens.add( "0" );
} }
} }

View File

@ -52,7 +52,7 @@ public class DefaultProfileManager
{ {
private MutablePlexusContainer container; private MutablePlexusContainer container;
private Map profilesById = new LinkedHashMap(); private Map<String, Profile> profilesById = new LinkedHashMap<String, Profile>();
private ProfileActivationContext profileActivationContext; private ProfileActivationContext profileActivationContext;
@ -100,7 +100,7 @@ public class DefaultProfileManager
this.profileActivationContext = profileActivationContext; this.profileActivationContext = profileActivationContext;
} }
public Map getProfilesById() public Map<String, Profile> getProfilesById()
{ {
return profilesById; 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 // 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 throws ProfileActivationException
{ {
List<Profile> activeFromPom = new ArrayList<Profile>();
try List<Profile> activeExternal = new ArrayList<Profile>();
{
List activeFromPom = new ArrayList();
List activeExternal = new ArrayList();
for ( Iterator it = profilesById.entrySet().iterator(); it.hasNext(); ) for ( Iterator it = profilesById.entrySet().iterator(); it.hasNext(); )
{ {
@ -171,14 +168,12 @@ public class DefaultProfileManager
if ( activeFromPom.isEmpty() ) 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 // If this profile was excluded, don't add it back in
// Fixes MNG-3545 // Fixes MNG-3545
if ( deactivatedIds.contains( profileId ) ) 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( activeExternal );
allActive.addAll( activeFromPom ); allActive.addAll( activeFromPom );
return allActive; return allActive;
} }
finally
{
}
}
private static List<ActiveProfileMatcher> matchers = Arrays.asList(new FileMatcher(), private static List<ActiveProfileMatcher> matchers = Arrays.asList(new FileMatcher(),
new JdkMatcher(), new OperatingSystemMatcher(), new PropertyMatcher()); new JdkMatcher(), new OperatingSystemMatcher(), new PropertyMatcher());

View File

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

View File

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