You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by si...@apache.org on 2009/03/04 20:08:29 UTC
svn commit: r750104 - in /maven/components/trunk:
maven-project-builder/src/main/java/org/apache/maven/project/builder/profile/
maven-project/src/main/java/org/apache/maven/profiles/
maven-project/src/main/java/org/apache/maven/project/
Author: sisbell
Date: Wed Mar 4 19:08:28 2009
New Revision: 750104
URL: http://svn.apache.org/viewvc?rev=750104&view=rev
Log:
Cleaned up code - generics
Modified:
maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/builder/profile/JdkMatcher.java
maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java
maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileManager.java
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
Modified: maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/builder/profile/JdkMatcher.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/builder/profile/JdkMatcher.java?rev=750104&r1=750103&r2=750104&view=diff
==============================================================================
--- maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/builder/profile/JdkMatcher.java (original)
+++ maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/builder/profile/JdkMatcher.java Wed Mar 4 19:08:28 2009
@@ -12,7 +12,6 @@
public class JdkMatcher
implements ActiveProfileMatcher
{
- // TODO: Ranges
public boolean isMatch( ModelContainer modelContainer, List<InterpolatorProperty> properties )
{
if ( modelContainer == null )
@@ -39,9 +38,9 @@
{
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,62 +57,63 @@
private static boolean isInRange( String value, List<RangeValue> range )
{
- int leftRelation = getRelationOrder(value, range.get( 0 ), true);
-
- if( leftRelation == 0)
- {
- return true;
- }
-
- if(leftRelation < 0)
- {
- return false;
- }
-
- return getRelationOrder(value, range.get( 1 ), false) <= 0;
+ int leftRelation = getRelationOrder( value, range.get( 0 ), true );
+
+ if ( leftRelation == 0 )
+ {
+ return true;
+ }
+
+ if ( leftRelation < 0 )
+ {
+ return false;
+ }
+
+ 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);
-
- if(value.equals( rangeValue.value ) )
+ addZeroTokens( valueTokens, max );
+ addZeroTokens( rangeValueTokens, max );
+
+ 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;
}
}
- return 0;
+ 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( "," );
}
@@ -139,12 +139,12 @@
else if ( token.endsWith( ")" ) )
{
ranges.add( new RangeValue( token.replace( ")", "" ), false ) );
- }
-
+ }
+
}
- if(ranges.size() < 2)
+ if ( ranges.size() < 2 )
{
- ranges.add( new RangeValue("99999999", false));
+ ranges.add( new RangeValue( "99999999", false ) );
}
return ranges;
}
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java?rev=750104&r1=750103&r2=750104&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java Wed Mar 4 19:08:28 2009
@@ -52,7 +52,7 @@
{
private MutablePlexusContainer container;
- private Map profilesById = new LinkedHashMap();
+ private Map<String, Profile> profilesById = new LinkedHashMap<String, Profile>();
private ProfileActivationContext profileActivationContext;
@@ -100,7 +100,7 @@
this.profileActivationContext = profileActivationContext;
}
- public Map getProfilesById()
+ public Map<String, Profile> getProfilesById()
{
return profilesById;
}
@@ -130,80 +130,71 @@
}
// 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
{
+ List<Profile> activeFromPom = new ArrayList<Profile>();
+ List<Profile> activeExternal = new ArrayList<Profile>();
- try
+ for ( Iterator it = profilesById.entrySet().iterator(); it.hasNext(); )
{
- List activeFromPom = new ArrayList();
- List activeExternal = new ArrayList();
+ Map.Entry entry = (Entry) it.next();
- for ( Iterator it = profilesById.entrySet().iterator(); it.hasNext(); )
- {
- Map.Entry entry = (Entry) it.next();
+ String profileId = (String) entry.getKey();
+ Profile profile = (Profile) entry.getValue();
- String profileId = (String) entry.getKey();
- Profile profile = (Profile) entry.getValue();
+ boolean shouldAdd = false;
+ if ( profileActivationContext.isExplicitlyActive( profileId ) )
+ {
+ shouldAdd = true;
+ }
+ else if ( isActive( profile, profileActivationContext ) )
+ {
+ shouldAdd = true;
+ }
- boolean shouldAdd = false;
- if ( profileActivationContext.isExplicitlyActive( profileId ) )
- {
- shouldAdd = true;
- }
- else if ( isActive( profile, profileActivationContext ) )
+ if ( !profileActivationContext.isExplicitlyInactive( profileId ) && shouldAdd )
+ {
+ if ( "pom".equals( profile.getSource() ) )
{
- shouldAdd = true;
+ activeFromPom.add( profile );
}
-
- if ( !profileActivationContext.isExplicitlyInactive( profileId ) && shouldAdd )
+ else
{
- if ( "pom".equals( profile.getSource() ) )
- {
- activeFromPom.add( profile );
- }
- else
- {
- activeExternal.add( profile );
- }
+ activeExternal.add( profile );
}
}
+ }
- if ( activeFromPom.isEmpty() )
- {
- List defaultIds = profileActivationContext.getActiveByDefaultProfileIds();
+ if ( activeFromPom.isEmpty() )
+ {
+ 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 )
+ {
+ // If this profile was excluded, don't add it back in
+ // Fixes MNG-3545
+ if ( deactivatedIds.contains( profileId ) )
{
- String profileId = (String) it.next();
+ continue;
+ }
+ Profile profile = (Profile) profilesById.get( profileId );
- // If this profile was excluded, don't add it back in
- // Fixes MNG-3545
- if ( deactivatedIds.contains( profileId ) )
- {
- continue;
- }
- Profile profile = (Profile) profilesById.get( profileId );
-
- if ( profile != null )
- {
- activeFromPom.add( profile );
- }
+ if ( profile != null )
+ {
+ activeFromPom.add( profile );
}
}
+ }
- List allActive = new ArrayList( activeFromPom.size() + activeExternal.size() );
+ List<Profile> allActive = new ArrayList<Profile>( activeFromPom.size() + activeExternal.size() );
- allActive.addAll( activeExternal );
- allActive.addAll( activeFromPom );
+ allActive.addAll( activeExternal );
+ allActive.addAll( activeFromPom );
- return allActive;
- }
- finally
- {
- }
+ return allActive;
}
private static List<ActiveProfileMatcher> matchers = Arrays.asList(new FileMatcher(),
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileManager.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileManager.java?rev=750104&r1=750103&r2=750104&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileManager.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileManager.java Wed Mar 4 19:08:28 2009
@@ -33,8 +33,8 @@
void addProfiles( List<Profile> profiles );
- Map getProfilesById();
+ Map<String, Profile> getProfilesById();
- List getActiveProfiles( Model model )
+ List<Profile> getActiveProfiles( Model model )
throws ProfileActivationException;
}
\ No newline at end of file
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/MavenProject.java?rev=750104&r1=750103&r2=750104&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/MavenProject.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/MavenProject.java Wed Mar 4 19:08:28 2009
@@ -510,10 +510,8 @@
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 @@
{
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 @@
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 @@
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 @@
{
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 @@
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 @@
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 @@
{
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 @@
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 @@
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 @@
{
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 @@
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 @@
}
}
+ //TODO: remove ModelUtils
public void injectPluginManagementInfo( Plugin plugin )
{
PluginManagement pm = getModelBuild().getPluginManagement();
@@ -1409,7 +1386,6 @@
public List<Repository> getPluginRepositories()
{
- // return model.getPluginRepositories();
return getModel().getRepositories();
}