mirror of https://github.com/apache/maven.git
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:
parent
023a96155b
commit
a2b9aa8bf3
|
@ -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,62 +57,63 @@ public class JdkMatcher
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
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( "." ));
|
||||
|
||||
int max = Math.max( valueTokens.size(), rangeValueTokens.size() );
|
||||
addZeroTokens(valueTokens, max);
|
||||
addZeroTokens(rangeValueTokens, max);
|
||||
|
||||
if(value.equals( rangeValue.value ) )
|
||||
int leftRelation = getRelationOrder( value, range.get( 0 ), true );
|
||||
|
||||
if ( leftRelation == 0 )
|
||||
{
|
||||
return (rangeValue.isClosed()) ? 0 : -1;
|
||||
return true;
|
||||
}
|
||||
|
||||
for( int i = 0; i < valueTokens.size() ; i++)
|
||||
if ( leftRelation < 0 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return getRelationOrder( value, range.get( 1 ), false ) <= 0;
|
||||
}
|
||||
|
||||
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( "." ) );
|
||||
|
||||
int max = Math.max( valueTokens.size(), rangeValueTokens.size() );
|
||||
addZeroTokens( valueTokens, max );
|
||||
addZeroTokens( rangeValueTokens, max );
|
||||
|
||||
if ( value.equals( rangeValue.value ) )
|
||||
{
|
||||
return ( rangeValue.isClosed() ) ? 0 : -1;
|
||||
}
|
||||
|
||||
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 @@ public class JdkMatcher
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -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,80 +130,71 @@ 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
|
||||
{
|
||||
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(); )
|
||||
String profileId = (String) entry.getKey();
|
||||
Profile profile = (Profile) entry.getValue();
|
||||
|
||||
boolean shouldAdd = false;
|
||||
if ( profileActivationContext.isExplicitlyActive( profileId ) )
|
||||
{
|
||||
Map.Entry entry = (Entry) it.next();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if ( !profileActivationContext.isExplicitlyInactive( profileId ) && shouldAdd )
|
||||
{
|
||||
if ( "pom".equals( profile.getSource() ) )
|
||||
{
|
||||
activeFromPom.add( profile );
|
||||
}
|
||||
else
|
||||
{
|
||||
activeExternal.add( profile );
|
||||
}
|
||||
}
|
||||
shouldAdd = true;
|
||||
}
|
||||
else if ( isActive( profile, profileActivationContext ) )
|
||||
{
|
||||
shouldAdd = true;
|
||||
}
|
||||
|
||||
if ( activeFromPom.isEmpty() )
|
||||
if ( !profileActivationContext.isExplicitlyInactive( profileId ) && shouldAdd )
|
||||
{
|
||||
List defaultIds = profileActivationContext.getActiveByDefaultProfileIds();
|
||||
|
||||
List deactivatedIds = profileActivationContext.getExplicitlyInactiveProfileIds();
|
||||
|
||||
for ( Iterator it = defaultIds.iterator(); it.hasNext(); )
|
||||
if ( "pom".equals( profile.getSource() ) )
|
||||
{
|
||||
String profileId = (String) it.next();
|
||||
|
||||
// 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 );
|
||||
}
|
||||
activeFromPom.add( profile );
|
||||
}
|
||||
else
|
||||
{
|
||||
activeExternal.add( profile );
|
||||
}
|
||||
}
|
||||
|
||||
List allActive = new ArrayList( activeFromPom.size() + activeExternal.size() );
|
||||
|
||||
allActive.addAll( activeExternal );
|
||||
allActive.addAll( activeFromPom );
|
||||
|
||||
return allActive;
|
||||
}
|
||||
finally
|
||||
|
||||
if ( activeFromPom.isEmpty() )
|
||||
{
|
||||
List<String> defaultIds = profileActivationContext.getActiveByDefaultProfileIds();
|
||||
|
||||
List<String> deactivatedIds = profileActivationContext.getExplicitlyInactiveProfileIds();
|
||||
|
||||
for ( String profileId : defaultIds )
|
||||
{
|
||||
// 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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<Profile> allActive = new ArrayList<Profile>( activeFromPom.size() + activeExternal.size() );
|
||||
|
||||
allActive.addAll( activeExternal );
|
||||
allActive.addAll( activeFromPom );
|
||||
|
||||
return allActive;
|
||||
}
|
||||
|
||||
private static List<ActiveProfileMatcher> matchers = Arrays.asList(new FileMatcher(),
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue