fixed errors reported by Checkstyle

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@813604 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Herve Boutemy 2009-09-10 21:49:53 +00:00
parent 4e37cb1a45
commit 388fcd100e
22 changed files with 1141 additions and 847 deletions

View File

@ -78,14 +78,14 @@ public class DefaultArtifact
private List<ArtifactVersion> availableVersions; private List<ArtifactVersion> availableVersions;
private Map<Object,ArtifactMetadata> metadataMap; private Map<Object,ArtifactMetadata> metadataMap;
private boolean optional; private boolean optional;
public DefaultArtifact( String groupId, String artifactId, String version, String scope, String type, String classifier, ArtifactHandler artifactHandler ) public DefaultArtifact( String groupId, String artifactId, String version, String scope, String type, String classifier, ArtifactHandler artifactHandler )
{ {
this( groupId, artifactId, VersionRange.createFromVersion( version ), scope, type, classifier, artifactHandler, false ); this( groupId, artifactId, VersionRange.createFromVersion( version ), scope, type, classifier, artifactHandler, false );
} }
public DefaultArtifact( String groupId, String artifactId, VersionRange versionRange, String scope, String type, String classifier, ArtifactHandler artifactHandler ) public DefaultArtifact( String groupId, String artifactId, VersionRange versionRange, String scope, String type, String classifier, ArtifactHandler artifactHandler )
{ {
this( groupId, artifactId, versionRange, scope, type, classifier, artifactHandler, false ); this( groupId, artifactId, versionRange, scope, type, classifier, artifactHandler, false );
@ -263,7 +263,8 @@ public class DefaultArtifact
public Collection<ArtifactMetadata> getMetadataList() public Collection<ArtifactMetadata> getMetadataList()
{ {
if (metadataMap == null) { if ( metadataMap == null )
{
return Collections.emptyList(); return Collections.emptyList();
} }
@ -385,7 +386,7 @@ public class DefaultArtifact
protected void setBaseVersionInternal( String baseVersion ) protected void setBaseVersionInternal( String baseVersion )
{ {
Matcher m = VERSION_FILE_PATTERN.matcher( baseVersion ); Matcher m = VERSION_FILE_PATTERN.matcher( baseVersion );
if ( m.matches() ) if ( m.matches() )
{ {
this.baseVersion = m.group( 1 ) + "-" + SNAPSHOT_VERSION; this.baseVersion = m.group( 1 ) + "-" + SNAPSHOT_VERSION;
@ -528,7 +529,8 @@ public class DefaultArtifact
public boolean isSnapshot() public boolean isSnapshot()
{ {
return getBaseVersion() != null && (getBaseVersion().endsWith(SNAPSHOT_VERSION) || getBaseVersion().equals(LATEST_VERSION)); return getBaseVersion() != null
&& ( getBaseVersion().endsWith( SNAPSHOT_VERSION ) || getBaseVersion().equals( LATEST_VERSION ) );
} }
public void setResolved( boolean resolved ) public void setResolved( boolean resolved )

View File

@ -82,16 +82,18 @@ public class ArtifactRepositoryPolicy
public void setUpdatePolicy( String updatePolicy ) public void setUpdatePolicy( String updatePolicy )
{ {
if(updatePolicy != null) { if ( updatePolicy != null )
this.updatePolicy = updatePolicy; {
this.updatePolicy = updatePolicy;
} }
} }
public void setChecksumPolicy( String checksumPolicy ) public void setChecksumPolicy( String checksumPolicy )
{ {
if(checksumPolicy != null) { if ( checksumPolicy != null )
this.checksumPolicy = checksumPolicy; {
} this.checksumPolicy = checksumPolicy;
}
} }
public boolean isEnabled() public boolean isEnabled()
@ -135,7 +137,7 @@ public class ArtifactRepositoryPolicy
else if ( updatePolicy.startsWith( UPDATE_POLICY_INTERVAL ) ) else if ( updatePolicy.startsWith( UPDATE_POLICY_INTERVAL ) )
{ {
String s = updatePolicy.substring( UPDATE_POLICY_INTERVAL.length() + 1 ); String s = updatePolicy.substring( UPDATE_POLICY_INTERVAL.length() + 1 );
int minutes = Integer.valueOf(s); int minutes = Integer.valueOf( s );
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
cal.add( Calendar.MINUTE, -minutes ); cal.add( Calendar.MINUTE, -minutes );
if ( cal.getTime().after( lastModified ) ) if ( cal.getTime().after( lastModified ) )

View File

@ -86,15 +86,15 @@ public class DebugResolutionListener
String ignoredScope ) String ignoredScope )
{ {
logger.debug( logger.debug(
indent + artifact + " (not setting artifactScope to: " + ignoredScope + "; local artifactScope " + artifact.getScope() + indent + artifact + " (not setting artifactScope to: " + ignoredScope + "; local artifactScope " + artifact.getScope()
" wins)" ); + " wins)" );
// TODO: better way than static? this might hide messages in a reactor // TODO: better way than static? this might hide messages in a reactor
if ( !ignoredArtifacts.contains( artifact ) ) if ( !ignoredArtifacts.contains( artifact ) )
{ {
logger.warn( "\n\tArtifact " + artifact + " retains local artifactScope '" + artifact.getScope() + logger.warn( "\n\tArtifact " + artifact + " retains local artifactScope '" + artifact.getScope()
"' overriding broader artifactScope '" + ignoredScope + "'\n" + + "' overriding broader artifactScope '" + ignoredScope + "'\n"
"\tgiven by a dependency. If this is not intended, modify or remove the local artifactScope.\n" ); + "\tgiven by a dependency. If this is not intended, modify or remove the local artifactScope.\n" );
ignoredArtifacts.add( artifact ); ignoredArtifacts.add( artifact );
} }
} }
@ -107,16 +107,16 @@ public class DebugResolutionListener
public void selectVersionFromRange( Artifact artifact ) public void selectVersionFromRange( Artifact artifact )
{ {
logger.debug( indent + artifact + " (setting version to: " + artifact.getVersion() + " from range: " + logger.debug( indent + artifact + " (setting version to: " + artifact.getVersion() + " from range: "
artifact.getVersionRange() + ")" ); + artifact.getVersionRange() + ")" );
} }
public void restrictRange( Artifact artifact, public void restrictRange( Artifact artifact,
Artifact replacement, Artifact replacement,
VersionRange newRange ) VersionRange newRange )
{ {
logger.debug( indent + artifact + " (range restricted from: " + artifact.getVersionRange() + " and: " + logger.debug( indent + artifact + " (range restricted from: " + artifact.getVersionRange() + " and: "
replacement.getVersionRange() + " to: " + newRange + " )" ); + replacement.getVersionRange() + " to: " + newRange + " )" );
} }
/** /**

View File

@ -90,13 +90,13 @@ public class MultipleArtifactsNotFoundException
int counter = 0; int counter = 0;
for (Artifact artifact : artifacts) { for ( Artifact artifact : artifacts )
String message = (++counter) + ") " + artifact.getId(); {
String message = ( ++counter ) + ") " + artifact.getId();
buffer.append(constructMissingArtifactMessage(message, " ", artifact.getGroupId(), artifact buffer.append( constructMissingArtifactMessage( message, " ", artifact.getGroupId(),
.getArtifactId(), artifact.getVersion(), artifact.getType(), artifact.getClassifier(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), artifact.getClassifier(),
artifact.getDownloadUrl(), artifact artifact.getDownloadUrl(), artifact.getDependencyTrail() ) );
.getDependencyTrail()));
} }
buffer.append( "----------\n" ); buffer.append( "----------\n" );

View File

@ -279,8 +279,8 @@ public class VersionRange
version = recommendedVersion; version = recommendedVersion;
found = true; found = true;
} }
else if ( version == null && restriction.getRecommendedVersion() != null && else if ( version == null && restriction.getRecommendedVersion() != null
r.containsVersion( restriction.getRecommendedVersion() ) ) && r.containsVersion( restriction.getRecommendedVersion() ) )
{ {
// use this if we can, but prefer the original if possible // use this if we can, but prefer the original if possible
version = restriction.getRecommendedVersion(); version = restriction.getRecommendedVersion();
@ -320,11 +320,11 @@ public class VersionRange
boolean done = false; boolean done = false;
while ( !done ) while ( !done )
{ {
if ( res1.getLowerBound() == null || res2.getUpperBound() == null || if ( res1.getLowerBound() == null || res2.getUpperBound() == null
res1.getLowerBound().compareTo( res2.getUpperBound() ) <= 0 ) || res1.getLowerBound().compareTo( res2.getUpperBound() ) <= 0 )
{ {
if ( res1.getUpperBound() == null || res2.getLowerBound() == null || if ( res1.getUpperBound() == null || res2.getLowerBound() == null
res1.getUpperBound().compareTo( res2.getLowerBound() ) >= 0 ) || res1.getUpperBound().compareTo( res2.getLowerBound() ) >= 0 )
{ {
ArtifactVersion lower; ArtifactVersion lower;
ArtifactVersion upper; ArtifactVersion upper;
@ -525,10 +525,13 @@ public class VersionRange
// TODO: could be more efficient by sorting the list and then moving along the restrictions in order? // TODO: could be more efficient by sorting the list and then moving along the restrictions in order?
ArtifactVersion matched = null; ArtifactVersion matched = null;
for (ArtifactVersion version : versions) { for ( ArtifactVersion version : versions )
if (containsVersion(version)) { {
if ( containsVersion( version ) )
{
// valid - check if it is greater than the currently matched version // valid - check if it is greater than the currently matched version
if (matched == null || version.compareTo(matched) > 0) { if ( matched == null || version.compareTo( matched ) > 0 )
{
matched = version; matched = version;
} }
} }
@ -538,8 +541,10 @@ public class VersionRange
public boolean containsVersion( ArtifactVersion version ) public boolean containsVersion( ArtifactVersion version )
{ {
for (Restriction restriction : restrictions) { for ( Restriction restriction : restrictions )
if (restriction.containsVersion(version)) { {
if ( restriction.containsVersion( version ) )
{
return true; return true;
} }
} }
@ -553,21 +558,22 @@ public class VersionRange
public boolean equals( Object obj ) public boolean equals( Object obj )
{ {
if (this == obj){ if ( this == obj )
{
return true; return true;
} }
if (!(obj instanceof VersionRange )) if ( !( obj instanceof VersionRange ) )
{ {
return false; return false;
} }
VersionRange other = (VersionRange) obj; VersionRange other = (VersionRange) obj;
boolean equals = boolean equals =
recommendedVersion == other.recommendedVersion || recommendedVersion == other.recommendedVersion
( ( recommendedVersion != null ) && recommendedVersion.equals( other.recommendedVersion ) ); || ( ( recommendedVersion != null ) && recommendedVersion.equals( other.recommendedVersion ) );
equals &= equals &=
restrictions == other.restrictions || restrictions == other.restrictions
( ( restrictions != null ) && restrictions.equals( other.restrictions ) ); || ( ( restrictions != null ) && restrictions.equals( other.restrictions ) );
return equals; return equals;
} }

View File

@ -28,7 +28,6 @@ import org.apache.maven.model.profile.ProfileSelector;
import org.apache.maven.profiles.activation.ProfileActivationException; import org.apache.maven.profiles.activation.ProfileActivationException;
import org.codehaus.plexus.MutablePlexusContainer; import org.codehaus.plexus.MutablePlexusContainer;
import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.Logger;
@ -44,7 +43,7 @@ import java.util.Properties;
public class DefaultProfileManager public class DefaultProfileManager
implements ProfileManager implements ProfileManager
{ {
@Requirement @Requirement
private Logger logger; private Logger logger;
@ -67,7 +66,7 @@ public class DefaultProfileManager
*/ */
public DefaultProfileManager( PlexusContainer container ) public DefaultProfileManager( PlexusContainer container )
{ {
this( container, null); this( container, null );
} }
/** /**
@ -89,7 +88,8 @@ public class DefaultProfileManager
this.requestProperties = props; this.requestProperties = props;
} }
public Properties getRequestProperties() { public Properties getRequestProperties()
{
return requestProperties; return requestProperties;
} }
@ -108,8 +108,8 @@ public class DefaultProfileManager
Profile existing = (Profile) profilesById.get( profileId ); Profile existing = (Profile) profilesById.get( profileId );
if ( existing != null ) if ( existing != null )
{ {
logger.warn( "Overriding profile: \'" + profileId + "\' (source: " + existing.getSource() + logger.warn( "Overriding profile: \'" + profileId + "\' (source: " + existing.getSource()
") with new instance from source: " + profile.getSource() ); + ") with new instance from source: " + profile.getSource() );
} }
profilesById.put( profile.getId(), profile ); profilesById.put( profile.getId(), profile );

View File

@ -97,8 +97,8 @@ public final class ModelUtils
// 1. we're not processing the plugins in an inheritance-based merge // 1. we're not processing the plugins in an inheritance-based merge
// 2. the parent's <inherited/> flag is not set // 2. the parent's <inherited/> flag is not set
// 3. the parent's <inherited/> flag is set to true // 3. the parent's <inherited/> flag is set to true
if ( !handleAsInheritance || ( parentInherited == null ) || if ( !handleAsInheritance || ( parentInherited == null )
Boolean.valueOf( parentInherited ).booleanValue() ) || Boolean.valueOf( parentInherited ).booleanValue() )
{ {
Plugin childPlugin = (Plugin) childPlugins.get( parentPlugin.getKey() ); Plugin childPlugin = (Plugin) childPlugins.get( parentPlugin.getKey() );

View File

@ -155,8 +155,8 @@ public class DefaultModelInheritanceAssembler
appendPath( parentScm.getConnection(), child.getArtifactId(), childPathAdjustment, appendPaths ) ); appendPath( parentScm.getConnection(), child.getArtifactId(), childPathAdjustment, appendPaths ) );
} }
if ( StringUtils.isEmpty( childScm.getDeveloperConnection() ) && if ( StringUtils.isEmpty( childScm.getDeveloperConnection() )
!StringUtils.isEmpty( parentScm.getDeveloperConnection() ) ) && !StringUtils.isEmpty( parentScm.getDeveloperConnection() ) )
{ {
childScm childScm
.setDeveloperConnection( appendPath( parentScm.getDeveloperConnection(), child.getArtifactId(), .setDeveloperConnection( appendPath( parentScm.getDeveloperConnection(), child.getArtifactId(),
@ -388,8 +388,8 @@ public class DefaultModelInheritanceAssembler
String parentInherited = parentPlugin.getInherited(); String parentInherited = parentPlugin.getInherited();
if ( !handleAsInheritance || ( parentInherited == null ) || if ( !handleAsInheritance || ( parentInherited == null )
Boolean.valueOf( parentInherited ).booleanValue() ) || Boolean.valueOf( parentInherited ).booleanValue() )
{ {
ReportPlugin assembledPlugin = parentPlugin; ReportPlugin assembledPlugin = parentPlugin;
@ -545,9 +545,8 @@ public class DefaultModelInheritanceAssembler
if ( deps != null ) if ( deps != null )
{ {
for ( Iterator<Dependency> it = deps.iterator(); it.hasNext(); ) for ( Dependency dependency : deps )
{ {
Dependency dependency = it.next();
depsMap.put( dependency.getManagementKey(), dependency ); depsMap.put( dependency.getManagementKey(), dependency );
} }
} }
@ -556,9 +555,8 @@ public class DefaultModelInheritanceAssembler
if ( deps != null ) if ( deps != null )
{ {
for ( Iterator<Dependency> it = deps.iterator(); it.hasNext(); ) for ( Dependency dependency : deps )
{ {
Dependency dependency = it.next();
depsMap.put( dependency.getManagementKey(), dependency ); depsMap.put( dependency.getManagementKey(), dependency );
} }
} }
@ -753,9 +751,8 @@ public class DefaultModelInheritanceAssembler
private static void mergeExtensionLists( Build childBuild, Build parentBuild ) private static void mergeExtensionLists( Build childBuild, Build parentBuild )
{ {
for ( Iterator i = parentBuild.getExtensions().iterator(); i.hasNext(); ) for ( Extension e : parentBuild.getExtensions() )
{ {
Extension e = (Extension) i.next();
if ( !childBuild.getExtensions().contains( e ) ) if ( !childBuild.getExtensions().contains( e ) )
{ {
childBuild.addExtension( e ); childBuild.addExtension( e );

View File

@ -73,7 +73,7 @@ public class DefaultUpdateCheckManager
// we can safely assume that we're calculating based on the snapshot policy here if we've made it past the // we can safely assume that we're calculating based on the snapshot policy here if we've made it past the
// release-artifact short circuit above. // release-artifact short circuit above.
ArtifactRepositoryPolicy policy = repository.getSnapshots(); ArtifactRepositoryPolicy policy = repository.getSnapshots();
return isUpdateRequired( artifact, repository, policy ); return isUpdateRequired( artifact, repository, policy );
} }
@ -194,8 +194,8 @@ public class DefaultUpdateCheckManager
{ {
if ( !touchfile.getParentFile().exists() && !touchfile.getParentFile().mkdirs() ) if ( !touchfile.getParentFile().exists() && !touchfile.getParentFile().mkdirs() )
{ {
getLogger().debug( "Failed to create directory: " + touchfile.getParent() + getLogger().debug( "Failed to create directory: " + touchfile.getParent()
" for tracking artifact metadata resolution." ); + " for tracking artifact metadata resolution." );
return; return;
} }
@ -237,8 +237,8 @@ public class DefaultUpdateCheckManager
} }
catch ( IOException e ) catch ( IOException e )
{ {
getLogger().debug( "Failed to record lastUpdated information for resolution.\nFile: " + getLogger().debug( "Failed to record lastUpdated information for resolution.\nFile: "
touchfile.toString() + "; key: " + key, e ); + touchfile.toString() + "; key: " + key, e );
} }
finally finally
{ {
@ -250,8 +250,8 @@ public class DefaultUpdateCheckManager
} }
catch ( IOException e ) catch ( IOException e )
{ {
getLogger().debug( "Error releasing exclusive lock for resolution tracking file: " + getLogger().debug( "Error releasing exclusive lock for resolution tracking file: "
touchfile, e ); + touchfile, e );
} }
} }
@ -263,8 +263,8 @@ public class DefaultUpdateCheckManager
} }
catch ( IOException e ) catch ( IOException e )
{ {
getLogger().debug( "Error closing FileChannel for resolution tracking file: " + getLogger().debug( "Error closing FileChannel for resolution tracking file: "
touchfile, e ); + touchfile, e );
} }
} }
} }
@ -314,8 +314,8 @@ public class DefaultUpdateCheckManager
} }
catch ( IOException e ) catch ( IOException e )
{ {
getLogger().debug( "Failed to read lastUpdated information.\nFile: " + getLogger().debug( "Failed to read lastUpdated information.\nFile: "
touchfile.toString() + "; key: " + key, e ); + touchfile.toString() + "; key: " + key, e );
} }
finally finally
{ {
@ -327,8 +327,8 @@ public class DefaultUpdateCheckManager
} }
catch ( IOException e ) catch ( IOException e )
{ {
getLogger().debug( "Error releasing shared lock for resolution tracking file: " + getLogger().debug( "Error releasing shared lock for resolution tracking file: "
touchfile, e ); + touchfile, e );
} }
} }
@ -340,8 +340,8 @@ public class DefaultUpdateCheckManager
} }
catch ( IOException e ) catch ( IOException e )
{ {
getLogger().debug( "Error closing FileChannel for resolution tracking file: " + getLogger().debug( "Error closing FileChannel for resolution tracking file: "
touchfile, e ); + touchfile, e );
} }
} }
} }

View File

@ -25,17 +25,18 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
public interface UpdateCheckManager { public interface UpdateCheckManager
{
String ROLE = UpdateCheckManager.class.getName(); String ROLE = UpdateCheckManager.class.getName();
boolean isUpdateRequired( Artifact artifact, ArtifactRepository repository ); boolean isUpdateRequired( Artifact artifact, ArtifactRepository repository );
void touch( Artifact artifact, ArtifactRepository repository ); void touch( Artifact artifact, ArtifactRepository repository );
boolean isUpdateRequired( RepositoryMetadata metadata, ArtifactRepository repository, File file ); boolean isUpdateRequired( RepositoryMetadata metadata, ArtifactRepository repository, File file );
void touch( RepositoryMetadata metadata, ArtifactRepository repository, File file ); void touch( RepositoryMetadata metadata, ArtifactRepository repository, File file );
boolean isPomUpdateRequired( Artifact artifact, ArtifactRepository repository ); boolean isPomUpdateRequired( Artifact artifact, ArtifactRepository repository );

View File

@ -55,7 +55,8 @@ public class DefaultArtifactTransformationManager
ArtifactRepository localRepository ) ArtifactRepository localRepository )
throws ArtifactResolutionException, ArtifactNotFoundException throws ArtifactResolutionException, ArtifactNotFoundException
{ {
for (ArtifactTransformation transform : artifactTransformations) { for ( ArtifactTransformation transform : artifactTransformations )
{
transform.transformForResolve( artifact, remoteRepositories, localRepository ); transform.transformForResolve( artifact, remoteRepositories, localRepository );
} }
} }
@ -64,7 +65,8 @@ public class DefaultArtifactTransformationManager
ArtifactRepository localRepository ) ArtifactRepository localRepository )
throws ArtifactInstallationException throws ArtifactInstallationException
{ {
for (ArtifactTransformation transform : artifactTransformations) { for ( ArtifactTransformation transform : artifactTransformations )
{
transform.transformForInstall( artifact, localRepository ); transform.transformForInstall( artifact, localRepository );
} }
} }
@ -74,7 +76,8 @@ public class DefaultArtifactTransformationManager
ArtifactRepository localRepository ) ArtifactRepository localRepository )
throws ArtifactDeploymentException throws ArtifactDeploymentException
{ {
for (ArtifactTransformation transform : artifactTransformations) { for ( ArtifactTransformation transform : artifactTransformations )
{
transform.transformForDeployment( artifact, remoteRepository, localRepository ); transform.transformForDeployment( artifact, remoteRepository, localRepository );
} }
} }

View File

@ -46,7 +46,7 @@ import org.codehaus.plexus.util.StringUtils;
* @author <a href="mailto:mmaczka@interia.pl">Michal Maczka</a> * @author <a href="mailto:mmaczka@interia.pl">Michal Maczka</a>
* @version $Id$ * @version $Id$
*/ */
@Component(role=ArtifactTransformation.class, hint="snapshot") @Component(role=ArtifactTransformation.class, hint="snapshot")
public class SnapshotTransformation public class SnapshotTransformation
extends AbstractVersionTransformation extends AbstractVersionTransformation
{ {
@ -105,7 +105,7 @@ public class SnapshotTransformation
if ( artifact.isSnapshot() ) if ( artifact.isSnapshot() )
{ {
Snapshot snapshot = new Snapshot(); Snapshot snapshot = new Snapshot();
snapshot.setTimestamp( getDeploymentTimestamp() ); snapshot.setTimestamp( getDeploymentTimestamp() );
// we update the build number anyway so that it doesn't get lost. It requires the timestamp to take effect // we update the build number anyway so that it doesn't get lost. It requires the timestamp to take effect
@ -117,8 +117,8 @@ public class SnapshotTransformation
} }
catch ( RepositoryMetadataResolutionException e ) catch ( RepositoryMetadataResolutionException e )
{ {
throw new ArtifactDeploymentException( "Error retrieving previous build number for artifact '" + throw new ArtifactDeploymentException( "Error retrieving previous build number for artifact '"
artifact.getDependencyConflictId() + "': " + e.getMessage(), e ); + artifact.getDependencyConflictId() + "': " + e.getMessage(), e );
} }
RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact, snapshot ); RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact, snapshot );

View File

@ -1,5 +1,24 @@
package org.apache.maven.repository.metadata; package org.apache.maven.repository.metadata;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -8,7 +27,7 @@ import org.apache.maven.artifact.ArtifactScopeEnum;
/** /**
* classpath container that is aware of the classpath scope * classpath container that is aware of the classpath scope
* *
* @author <a href="oleg@codehaus.org">Oleg Gusakov</a> * @author <a href="oleg@codehaus.org">Oleg Gusakov</a>
* *
*/ */
@ -16,97 +35,111 @@ public class ClasspathContainer
implements Iterable<ArtifactMetadata> implements Iterable<ArtifactMetadata>
{ {
private List<ArtifactMetadata> classpath; private List<ArtifactMetadata> classpath;
private ArtifactScopeEnum scope;
//-------------------------------------------------------------------------------------------
public ClasspathContainer(ArtifactScopeEnum scope)
{
this.scope = ArtifactScopeEnum.checkScope(scope);
}
//-------------------------------------------------------------------------------------------
public ClasspathContainer(
List<ArtifactMetadata> classpath
, ArtifactScopeEnum scope
)
{
this(scope);
this.classpath = classpath;
}
//-------------------------------------------------------------------------------------------
public Iterator<ArtifactMetadata> iterator()
{
return classpath == null ? null : classpath.iterator() ;
}
//-------------------------------------------------------------------------------------------
public ClasspathContainer add( ArtifactMetadata md )
{
if( classpath == null )
classpath = new ArrayList<ArtifactMetadata>(16);
classpath.add(md);
return this;
}
//-------------------------------------------------------------------------------------------
public List<ArtifactMetadata> getClasspath()
{
return classpath;
}
//-------------------------------------------------------------------------------------------
public MetadataTreeNode getClasspathAsTree()
throws MetadataResolutionException
{
if( classpath == null || classpath.size() < 1 )
return null;
MetadataTreeNode tree = null;
MetadataTreeNode parent = null;
MetadataTreeNode node = null;
for( ArtifactMetadata md : classpath ) { private ArtifactScopeEnum scope;
node = new MetadataTreeNode( md, parent, md.isResolved(), md.getArtifactScope() );
if( tree == null ) {
tree = node;
}
if( parent != null ) {
parent.setNChildren(1);
parent.addChild(0, node);
}
parent = node;
}
return tree;
}
public void setClasspath(List<ArtifactMetadata> classpath) // -------------------------------------------------------------------------------------------
{ public ClasspathContainer( ArtifactScopeEnum scope )
this.classpath = classpath; {
} this.scope = ArtifactScopeEnum.checkScope( scope );
}
public ArtifactScopeEnum getScope() // -------------------------------------------------------------------------------------------
{ public ClasspathContainer( List<ArtifactMetadata> classpath, ArtifactScopeEnum scope )
return scope; {
} this( scope );
this.classpath = classpath;
}
public void setScope(ArtifactScopeEnum scope) // -------------------------------------------------------------------------------------------
{ public Iterator<ArtifactMetadata> iterator()
this.scope = scope; {
} return classpath == null ? null : classpath.iterator();
//------------------------------------------------------------------------------------------- }
@Override
public String toString() // -------------------------------------------------------------------------------------------
{ public ClasspathContainer add( ArtifactMetadata md )
StringBuilder sb = new StringBuilder(256); {
sb.append("[scope="+scope.getScope() ); if ( classpath == null )
if(classpath != null) {
for( ArtifactMetadata md : classpath ) { classpath = new ArrayList<ArtifactMetadata>( 16 );
sb.append(": "+md.toString()+'{'+md.getArtifactUri()+'}'); }
}
sb.append(']'); classpath.add( md );
return sb.toString();
} return this;
//------------------------------------------------------------------------------------------- }
//-------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------
public List<ArtifactMetadata> getClasspath()
{
return classpath;
}
// -------------------------------------------------------------------------------------------
public MetadataTreeNode getClasspathAsTree()
throws MetadataResolutionException
{
if ( classpath == null || classpath.size() < 1 )
{
return null;
}
MetadataTreeNode tree = null;
MetadataTreeNode parent = null;
MetadataTreeNode node = null;
for ( ArtifactMetadata md : classpath )
{
node = new MetadataTreeNode( md, parent, md.isResolved(), md.getArtifactScope() );
if ( tree == null )
{
tree = node;
}
if ( parent != null )
{
parent.setNChildren( 1 );
parent.addChild( 0, node );
}
parent = node;
}
return tree;
}
public void setClasspath( List<ArtifactMetadata> classpath )
{
this.classpath = classpath;
}
public ArtifactScopeEnum getScope()
{
return scope;
}
public void setScope( ArtifactScopeEnum scope )
{
this.scope = scope;
}
// -------------------------------------------------------------------------------------------
@Override
public String toString()
{
StringBuilder sb = new StringBuilder( 256 );
sb.append( "[scope=" + scope.getScope() );
if ( classpath != null )
{
for ( ArtifactMetadata md : classpath )
{
sb.append( ": " + md.toString() + '{' + md.getArtifactUri() + '}' );
}
}
sb.append( ']' );
return sb.toString();
}
// -------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------
} }

View File

@ -1,5 +1,24 @@
package org.apache.maven.repository.metadata; package org.apache.maven.repository.metadata;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
@ -11,7 +30,7 @@ import org.codehaus.plexus.component.annotations.Requirement;
/** /**
* default implementation of the metadata classpath transformer * default implementation of the metadata classpath transformer
* *
* @author <a href="oleg@codehaus.org">Oleg Gusakov</a> * @author <a href="oleg@codehaus.org">Oleg Gusakov</a>
* *
*/ */
@ -23,44 +42,47 @@ implements ClasspathTransformation
GraphConflictResolver conflictResolver; GraphConflictResolver conflictResolver;
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public ClasspathContainer transform( public ClasspathContainer transform( MetadataGraph dirtyGraph, ArtifactScopeEnum scope, boolean resolve )
MetadataGraph dirtyGraph throws MetadataGraphTransformationException
, ArtifactScopeEnum scope {
, boolean resolve try
) {
throws MetadataGraphTransformationException if ( dirtyGraph == null || dirtyGraph.isEmpty() )
{ {
try { return null;
if( dirtyGraph == null }
|| dirtyGraph.isEmpty()
)
return null;
MetadataGraph cleanGraph = conflictResolver.resolveConflicts( dirtyGraph, scope ); MetadataGraph cleanGraph = conflictResolver.resolveConflicts( dirtyGraph, scope );
if ( cleanGraph == null || cleanGraph.isEmpty() )
{
return null;
}
ClasspathContainer cpc = new ClasspathContainer( scope );
if ( cleanGraph.isEmptyEdges() )
{
// single entry in the classpath, populated from itself
ArtifactMetadata amd = cleanGraph.getEntry().getMd();
cpc.add( amd );
}
else
{
ClasspathGraphVisitor v = new ClasspathGraphVisitor( cleanGraph, cpc );
MetadataGraphVertex entry = cleanGraph.getEntry();
ArtifactMetadata md = entry.getMd();
// entry point
v.visit( entry ); // , md.getVersion(), md.getArtifactUri() );
}
return cpc;
}
catch ( GraphConflictResolutionException e )
{
throw new MetadataGraphTransformationException( e );
}
}
if( cleanGraph == null
|| cleanGraph.isEmpty()
)
return null;
ClasspathContainer cpc = new ClasspathContainer( scope );
if( cleanGraph.isEmptyEdges() ) {
// single entry in the classpath, populated from itself
ArtifactMetadata amd = cleanGraph.getEntry().getMd();
cpc.add( amd );
} else {
ClasspathGraphVisitor v = new ClasspathGraphVisitor( cleanGraph, cpc );
MetadataGraphVertex entry = cleanGraph.getEntry();
ArtifactMetadata md = entry.getMd();
// entry point
v.visit( entry ); //, md.getVersion(), md.getArtifactUri() );
}
return cpc;
} catch (GraphConflictResolutionException e) {
throw new MetadataGraphTransformationException(e);
}
}
//=================================================================================================== //===================================================================================================
/** /**
* Helper class to traverse graph. Required to make the containing method thread-safe * Helper class to traverse graph. Required to make the containing method thread-safe
@ -68,82 +90,91 @@ implements ClasspathTransformation
*/ */
private class ClasspathGraphVisitor private class ClasspathGraphVisitor
{ {
MetadataGraph graph; MetadataGraph graph;
ClasspathContainer cpc;
List<MetadataGraphVertex> visited;
//-----------------------------------------------------------------------
protected ClasspathGraphVisitor( MetadataGraph cleanGraph, ClasspathContainer cpc )
{
this.cpc = cpc;
this.graph = cleanGraph;
visited = new ArrayList<MetadataGraphVertex>( cleanGraph.getVertices().size() ); ClasspathContainer cpc;
}
//-----------------------------------------------------------------------
protected void visit( MetadataGraphVertex node ) //, String version, String artifactUri )
{
ArtifactMetadata md = node.getMd();
if( visited.contains(node) )
return;
cpc.add( md ); List<MetadataGraphVertex> visited;
// -----------------------------------------------------------------------
protected ClasspathGraphVisitor( MetadataGraph cleanGraph, ClasspathContainer cpc )
{
this.cpc = cpc;
this.graph = cleanGraph;
visited = new ArrayList<MetadataGraphVertex>( cleanGraph.getVertices().size() );
}
// -----------------------------------------------------------------------
protected void visit( MetadataGraphVertex node ) // , String version, String artifactUri )
{
ArtifactMetadata md = node.getMd();
if ( visited.contains( node ) )
{
return;
}
cpc.add( md );
// //
// TreeSet<MetadataGraphEdge> deps = new TreeSet<MetadataGraphEdge>( // TreeSet<MetadataGraphEdge> deps = new TreeSet<MetadataGraphEdge>(
// new Comparator<MetadataGraphEdge>() // new Comparator<MetadataGraphEdge>()
// { // {
// public int compare( MetadataGraphEdge e1 // public int compare( MetadataGraphEdge e1
// , MetadataGraphEdge e2 // , MetadataGraphEdge e2
// ) // )
// { // {
// if( e1.getDepth() == e2.getDepth() ) // if( e1.getDepth() == e2.getDepth() )
// { // {
// if( e2.getPomOrder() == e1.getPomOrder() ) // if( e2.getPomOrder() == e1.getPomOrder() )
// return e1.getTarget().toString().compareTo(e2.getTarget().toString() ); // return e1.getTarget().toString().compareTo(e2.getTarget().toString() );
// //
// return e2.getPomOrder() - e1.getPomOrder(); // return e2.getPomOrder() - e1.getPomOrder();
// } // }
// //
// return e2.getDepth() - e1.getDepth(); // return e2.getDepth() - e1.getDepth();
// } // }
// } // }
// ); // );
List<MetadataGraphEdge> exits = graph.getExcidentEdges(node); List<MetadataGraphEdge> exits = graph.getExcidentEdges(node);
if( exits != null && exits.size() > 0)
{
MetadataGraphEdge[] sortedExits = exits.toArray( new MetadataGraphEdge[exits.size()] );
Arrays.sort( sortedExits
,
new Comparator<MetadataGraphEdge>()
{
public int compare( MetadataGraphEdge e1
, MetadataGraphEdge e2
)
{
if( e1.getDepth() == e2.getDepth() )
{
if( e2.getPomOrder() == e1.getPomOrder() )
return e1.getTarget().toString().compareTo(e2.getTarget().toString() );
return e2.getPomOrder() - e1.getPomOrder();
}
return e2.getDepth() - e1.getDepth(); if ( exits != null && exits.size() > 0 )
} {
} MetadataGraphEdge[] sortedExits = exits.toArray( new MetadataGraphEdge[exits.size()] );
); Arrays.sort( sortedExits
,
for( MetadataGraphEdge e : sortedExits ) { new Comparator<MetadataGraphEdge>()
MetadataGraphVertex targetNode = e.getTarget(); {
targetNode.getMd().setArtifactScope( e.getScope() ); public int compare( MetadataGraphEdge e1
targetNode.getMd().setWhy( e.getSource().getMd().toString() ); , MetadataGraphEdge e2
visit( targetNode ); )
} {
} if ( e1.getDepth() == e2.getDepth() )
{
} if ( e2.getPomOrder() == e1.getPomOrder() )
//----------------------------------------------------------------------- {
//----------------------------------------------------------------------- return e1.getTarget().toString().compareTo( e2.getTarget().toString() );
}
return e2.getPomOrder() - e1.getPomOrder();
}
return e2.getDepth() - e1.getDepth();
}
}
);
for ( MetadataGraphEdge e : sortedExits )
{
MetadataGraphVertex targetNode = e.getTarget();
targetNode.getMd().setArtifactScope( e.getScope() );
targetNode.getMd().setWhy( e.getSource().getMd().toString() );
visit( targetNode );
}
}
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------

View File

@ -1,5 +1,24 @@
package org.apache.maven.repository.metadata; package org.apache.maven.repository.metadata;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Component;
@ -7,44 +26,49 @@ import org.codehaus.plexus.component.annotations.Configuration;
/** /**
* @author <a href="mailto:oleg@codehaus.org">Oleg Gusakov</a> * @author <a href="mailto:oleg@codehaus.org">Oleg Gusakov</a>
* *
* @version $Id$ * @version $Id$
*/ */
@Component(role=GraphConflictResolutionPolicy.class) @Component(role=GraphConflictResolutionPolicy.class)
public class DefaultGraphConflictResolutionPolicy public class DefaultGraphConflictResolutionPolicy
implements GraphConflictResolutionPolicy implements GraphConflictResolutionPolicy
{ {
/** /**
* artifact, closer to the entry point, is selected * artifact, closer to the entry point, is selected
*/ */
@Configuration(name="closer-first", value="true") @Configuration(name="closer-first", value="true")
private boolean closerFirst = true; private boolean closerFirst = true;
/** /**
* newer artifact is selected * newer artifact is selected
*/ */
@Configuration(name="newer-first", value="true") @Configuration(name="newer-first", value="true")
private boolean newerFirst = true; private boolean newerFirst = true;
public MetadataGraphEdge apply(MetadataGraphEdge e1, MetadataGraphEdge e2) public MetadataGraphEdge apply( MetadataGraphEdge e1, MetadataGraphEdge e2 )
{ {
int depth1 = e1.getDepth(); int depth1 = e1.getDepth();
int depth2 = e2.getDepth(); int depth2 = e2.getDepth();
if( depth1 == depth2 ) {
ArtifactVersion v1 = new DefaultArtifactVersion( e1.getVersion() );
ArtifactVersion v2 = new DefaultArtifactVersion( e2.getVersion() );
if( newerFirst )
return v1.compareTo(v2) > 0 ? e1 : e2;
return v1.compareTo(v2) > 0 ? e2 : e1; if ( depth1 == depth2 )
} {
ArtifactVersion v1 = new DefaultArtifactVersion( e1.getVersion() );
if( closerFirst ) ArtifactVersion v2 = new DefaultArtifactVersion( e2.getVersion() );
return depth1 < depth2 ? e1 : e2;
return depth1 < depth2 ? e2 : e1; if ( newerFirst )
} {
return v1.compareTo( v2 ) > 0 ? e1 : e2;
}
return v1.compareTo( v2 ) > 0 ? e2 : e1;
}
if ( closerFirst )
{
return depth1 < depth2 ? e1 : e2;
}
return depth1 < depth2 ? e2 : e1;
}
} }

View File

@ -1,5 +1,24 @@
package org.apache.maven.repository.metadata; package org.apache.maven.repository.metadata;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -10,35 +29,35 @@ import org.apache.maven.artifact.ArtifactScopeEnum;
/** /**
* maven dependency metadata graph * maven dependency metadata graph
* *
* @author <a href="oleg@codehaus.org">Oleg Gusakov</a> * @author <a href="oleg@codehaus.org">Oleg Gusakov</a>
* *
*/ */
public class MetadataGraph public class MetadataGraph
{ {
public static int DEFAULT_VERTICES = 32; public static final int DEFAULT_VERTICES = 32;
public static int DEFAULT_EDGES = 64; public static final int DEFAULT_EDGES = 64;
// flags to indicate the granularity of vertices
private boolean versionedVertices = false;
private boolean scopedVertices = false;
/**
* the entry point we started building the graph from
*/
MetadataGraphVertex entry;
// graph vertices
TreeSet< MetadataGraphVertex > vertices;
/** // flags to indicate the granularity of vertices
private boolean versionedVertices = false;
private boolean scopedVertices = false;
/**
* the entry point we started building the graph from
*/
MetadataGraphVertex entry;
// graph vertices
TreeSet<MetadataGraphVertex> vertices;
/**
* incident and excident edges per node * incident and excident edges per node
*/ */
Map<MetadataGraphVertex, List<MetadataGraphEdge>> incidentEdges; Map<MetadataGraphVertex, List<MetadataGraphEdge>> incidentEdges;
Map<MetadataGraphVertex, List<MetadataGraphEdge>> excidentEdges; Map<MetadataGraphVertex, List<MetadataGraphEdge>> excidentEdges;
/** /**
* null in dirty graph, actual * null in dirty graph, actual
* scope for conflict-resolved graph * scope for conflict-resolved graph
*/ */
ArtifactScopeEnum scope; ArtifactScopeEnum scope;
@ -49,11 +68,11 @@ public class MetadataGraph
*/ */
public MetadataGraph( int nVertices ) public MetadataGraph( int nVertices )
{ {
init( nVertices, 2*nVertices ); init( nVertices, 2 * nVertices );
} }
public MetadataGraph( int nVertices, int nEdges ) public MetadataGraph( int nVertices, int nEdges )
{ {
init( nVertices, nEdges ); init( nVertices, nEdges );
} }
//------------------------------------------------------------------------ //------------------------------------------------------------------------
/** /**
@ -62,14 +81,14 @@ public class MetadataGraph
public MetadataGraph( MetadataGraphVertex entry ) public MetadataGraph( MetadataGraphVertex entry )
throws MetadataResolutionException throws MetadataResolutionException
{ {
checkVertex(entry); checkVertex( entry );
checkVertices(1); checkVertices( 1 );
entry.setCompareVersion( versionedVertices ); entry.setCompareVersion( versionedVertices );
entry.setCompareScope( scopedVertices ); entry.setCompareScope( scopedVertices );
vertices.add( entry ); vertices.add( entry );
this.entry = entry; this.entry = entry;
} }
//------------------------------------------------------------------------ //------------------------------------------------------------------------
/** /**
@ -78,16 +97,16 @@ public class MetadataGraph
public MetadataGraph( MetadataTreeNode tree ) public MetadataGraph( MetadataTreeNode tree )
throws MetadataResolutionException throws MetadataResolutionException
{ {
this( tree, false, false ); this( tree, false, false );
} }
//------------------------------------------------------------------------ //------------------------------------------------------------------------
/** /**
* construct graph from a "dirty" tree * construct graph from a "dirty" tree
* *
* @param tree "dirty" tree root * @param tree "dirty" tree root
* @param versionedVertices true if graph nodes should be versioned (different versions -> different nodes) * @param versionedVertices true if graph nodes should be versioned (different versions -> different nodes)
* @param scopedVertices true if graph nodes should be versioned and scoped (different versions and/or scopes -> different nodes) * @param scopedVertices true if graph nodes should be versioned and scoped (different versions and/or scopes -> different nodes)
* *
*/ */
public MetadataGraph( MetadataTreeNode tree, boolean versionedVertices, boolean scopedVertices ) public MetadataGraph( MetadataTreeNode tree, boolean versionedVertices, boolean scopedVertices )
throws MetadataResolutionException throws MetadataResolutionException
@ -97,12 +116,12 @@ public class MetadataGraph
throw new MetadataResolutionException( "tree is null" ); throw new MetadataResolutionException( "tree is null" );
} }
setVersionedVertices(versionedVertices); setVersionedVertices( versionedVertices );
setScopedVertices(scopedVertices); setScopedVertices( scopedVertices );
this.versionedVertices = scopedVertices || versionedVertices; this.versionedVertices = scopedVertices || versionedVertices;
this.scopedVertices = scopedVertices; this.scopedVertices = scopedVertices;
int count = countNodes( tree ); int count = countNodes( tree );
init( count, count + ( count / 2 ) ); init( count, count + ( count / 2 ) );
@ -114,7 +133,7 @@ public class MetadataGraph
, MetadataTreeNode node , MetadataTreeNode node
, int depth , int depth
, int pomOrder , int pomOrder
) )
throws MetadataResolutionException throws MetadataResolutionException
{ {
if ( node == null ) if ( node == null )
@ -123,20 +142,20 @@ public class MetadataGraph
} }
MetadataGraphVertex vertex = new MetadataGraphVertex( node.md, versionedVertices, scopedVertices ); MetadataGraphVertex vertex = new MetadataGraphVertex( node.md, versionedVertices, scopedVertices );
if( ! vertices.contains(vertex) ) if ( !vertices.contains( vertex ) )
{ {
vertices.add(vertex); vertices.add( vertex );
} }
if( parentVertex != null ) // then create the edge if ( parentVertex != null ) // then create the edge
{ {
ArtifactMetadata md = node.getMd(); ArtifactMetadata md = node.getMd();
MetadataGraphEdge e = new MetadataGraphEdge( md.version, md.resolved, md.artifactScope, md.artifactUri, depth, pomOrder ); MetadataGraphEdge e = new MetadataGraphEdge( md.version, md.resolved, md.artifactScope, md.artifactUri, depth, pomOrder );
addEdge( parentVertex, vertex, e); addEdge( parentVertex, vertex, e );
} }
else else
{ {
entry = vertex; entry = vertex;
} }
MetadataTreeNode[] kids = node.getChildren(); MetadataTreeNode[] kids = node.getChildren();
@ -145,49 +164,57 @@ public class MetadataGraph
return; return;
} }
for( int i = 0; i< kids.length; i++ ) for ( int i = 0; i < kids.length; i++ )
{ {
MetadataTreeNode n = kids[i]; MetadataTreeNode n = kids[i];
processTreeNodes( vertex, n, depth + 1, i ); processTreeNodes( vertex, n, depth + 1, i );
} }
} }
//------------------------------------------------------------------------ //------------------------------------------------------------------------
public MetadataGraphVertex findVertex( ArtifactMetadata md ) public MetadataGraphVertex findVertex( ArtifactMetadata md )
{ {
if( md == null || vertices == null || vertices.size() < 1 ) if ( md == null || vertices == null || vertices.size() < 1 )
return null; {
return null;
MetadataGraphVertex v = new MetadataGraphVertex(md); }
v.setCompareVersion(versionedVertices);
v.setCompareScope(scopedVertices);
for( MetadataGraphVertex gv : vertices ) MetadataGraphVertex v = new MetadataGraphVertex( md );
{ v.setCompareVersion( versionedVertices );
if( gv.equals(v) ) v.setCompareScope( scopedVertices );
return gv;
} for ( MetadataGraphVertex gv : vertices )
{
return null; if ( gv.equals( v ) )
{
return gv;
}
}
return null;
} }
//------------------------------------------------------------------------ //------------------------------------------------------------------------
public MetadataGraphVertex addVertex( ArtifactMetadata md ) public MetadataGraphVertex addVertex( ArtifactMetadata md )
{ {
if( md == null ) if ( md == null )
return null; {
return null;
checkVertices(); }
MetadataGraphVertex v = findVertex(md);
if( v != null)
return v;
v = new MetadataGraphVertex(md);
v.setCompareVersion(versionedVertices);
v.setCompareScope(scopedVertices);
vertices.add( v ); checkVertices();
return v;
MetadataGraphVertex v = findVertex( md );
if ( v != null )
{
return v;
}
v = new MetadataGraphVertex( md );
v.setCompareVersion( versionedVertices );
v.setCompareScope( scopedVertices );
vertices.add( v );
return v;
} }
//------------------------------------------------------------------------ //------------------------------------------------------------------------
/** /**
@ -195,136 +222,164 @@ public class MetadataGraph
*/ */
private void init( int nVertices, int nEdges ) private void init( int nVertices, int nEdges )
{ {
int nV = nVertices; int nV = nVertices;
if( nVertices < 1 ) if ( nVertices < 1 )
nV = 1; {
nV = 1;
checkVertices(nV); }
int nE = nVertices; checkVertices( nV );
if( nEdges <= nV )
nE = 2*nE; int nE = nVertices;
if ( nEdges <= nV )
checkEdges(nE); {
nE = 2 * nE;
}
checkEdges( nE );
} }
private void checkVertices() private void checkVertices()
{ {
checkVertices(DEFAULT_VERTICES); checkVertices( DEFAULT_VERTICES );
} }
private void checkVertices( int nVertices ) private void checkVertices( int nVertices )
{ {
if( vertices == null ) if ( vertices == null )
vertices = new TreeSet<MetadataGraphVertex>(); {
vertices = new TreeSet<MetadataGraphVertex>();
}
} }
private void checkEdges() private void checkEdges()
{ {
int count = DEFAULT_EDGES; int count = DEFAULT_EDGES;
if( vertices != null )
count = vertices.size() + vertices.size() / 2;
checkEdges( count ); if ( vertices != null )
{
count = vertices.size() + vertices.size() / 2;
}
checkEdges( count );
} }
private void checkEdges( int nEdges ) private void checkEdges( int nEdges )
{ {
if( incidentEdges == null ) if ( incidentEdges == null )
incidentEdges = new HashMap<MetadataGraphVertex, List<MetadataGraphEdge>>( nEdges ); {
if( excidentEdges == null ) incidentEdges = new HashMap<MetadataGraphVertex, List<MetadataGraphEdge>>( nEdges );
excidentEdges = new HashMap<MetadataGraphVertex, List<MetadataGraphEdge>>( nEdges ); }
if ( excidentEdges == null )
{
excidentEdges = new HashMap<MetadataGraphVertex, List<MetadataGraphEdge>>( nEdges );
}
} }
//------------------------------------------------------------------------ //------------------------------------------------------------------------
private static void checkVertex( MetadataGraphVertex v ) private static void checkVertex( MetadataGraphVertex v )
throws MetadataResolutionException throws MetadataResolutionException
{ {
if( v == null ) if ( v == null )
throw new MetadataResolutionException( "null vertex" ); {
if( v.getMd() == null ) throw new MetadataResolutionException( "null vertex" );
throw new MetadataResolutionException( "vertex without metadata" ); }
if ( v.getMd() == null )
{
throw new MetadataResolutionException( "vertex without metadata" );
}
} }
//------------------------------------------------------------------------ //------------------------------------------------------------------------
private static void checkEdge( MetadataGraphEdge e ) private static void checkEdge( MetadataGraphEdge e )
throws MetadataResolutionException throws MetadataResolutionException
{ {
if( e == null ) if ( e == null )
throw new MetadataResolutionException( "badly formed edge" ); {
throw new MetadataResolutionException( "badly formed edge" );
}
} }
//------------------------------------------------------------------------ //------------------------------------------------------------------------
public List<MetadataGraphEdge> getEdgesBetween( public List<MetadataGraphEdge> getEdgesBetween( MetadataGraphVertex vFrom, MetadataGraphVertex vTo )
MetadataGraphVertex vFrom
, MetadataGraphVertex vTo
)
{ {
List<MetadataGraphEdge> edges = getIncidentEdges(vTo); List<MetadataGraphEdge> edges = getIncidentEdges(vTo);
if( edges == null || edges.isEmpty() ) if ( edges == null || edges.isEmpty() )
return null; {
return null;
List<MetadataGraphEdge> res = new ArrayList<MetadataGraphEdge>( edges.size() ); }
for( MetadataGraphEdge e : edges ) List<MetadataGraphEdge> res = new ArrayList<MetadataGraphEdge>( edges.size() );
{
if( e.getSource().equals(vFrom) ) for ( MetadataGraphEdge e : edges )
res.add(e); {
} if ( e.getSource().equals( vFrom ) )
{
return res; res.add( e );
}
}
return res;
} }
//------------------------------------------------------------------------ //------------------------------------------------------------------------
public MetadataGraph addEdge( MetadataGraphVertex vFrom public MetadataGraph addEdge( MetadataGraphVertex vFrom, MetadataGraphVertex vTo, MetadataGraphEdge e )
, MetadataGraphVertex vTo
, MetadataGraphEdge e
)
throws MetadataResolutionException throws MetadataResolutionException
{ {
checkVertex(vFrom); checkVertex( vFrom );
checkVertex(vTo); checkVertex( vTo );
checkVertices(); checkVertices();
checkEdge(e);
checkEdges();
e.setSource(vFrom);
e.setTarget(vTo);
vFrom.setCompareVersion(versionedVertices); checkEdge( e );
vFrom.setCompareScope(scopedVertices); checkEdges();
List<MetadataGraphEdge> exList = excidentEdges.get(vFrom); e.setSource( vFrom );
if( exList == null ) { e.setTarget( vTo );
exList = new ArrayList<MetadataGraphEdge>();
excidentEdges.put( vFrom, exList ); vFrom.setCompareVersion( versionedVertices );
} vFrom.setCompareScope( scopedVertices );
if( !exList.contains(e) ) List<MetadataGraphEdge> exList = excidentEdges.get( vFrom );
exList.add(e); if ( exList == null )
{
List<MetadataGraphEdge> inList = incidentEdges.get(vTo); exList = new ArrayList<MetadataGraphEdge>();
if( inList == null ) { excidentEdges.put( vFrom, exList );
inList = new ArrayList<MetadataGraphEdge>(); }
incidentEdges.put( vTo, inList );
} if ( !exList.contains( e ) )
{
if( !inList.contains(e) ) exList.add( e );
inList.add(e); }
return this; List<MetadataGraphEdge> inList = incidentEdges.get( vTo );
if ( inList == null )
{
inList = new ArrayList<MetadataGraphEdge>();
incidentEdges.put( vTo, inList );
}
if ( !inList.contains( e ) )
{
inList.add( e );
}
return this;
} }
//------------------------------------------------------------------------ //------------------------------------------------------------------------
public MetadataGraph removeVertex( MetadataGraphVertex v ) public MetadataGraph removeVertex( MetadataGraphVertex v )
{ {
if( vertices!= null && v != null ) if ( vertices != null && v != null )
vertices.remove(v); {
vertices.remove( v );
if( incidentEdges!= null ) }
incidentEdges.remove(v);
if ( incidentEdges != null )
if( excidentEdges!= null ) {
excidentEdges.remove(v); incidentEdges.remove( v );
}
if ( excidentEdges != null )
{
excidentEdges.remove( v );
}
return this;
return this;
} }
//------------------------------------------------------------------------ //------------------------------------------------------------------------
private static int countNodes( MetadataTreeNode tree ) private static int countNodes( MetadataTreeNode tree )
@ -363,99 +418,110 @@ public class MetadataGraph
{ {
return vertices; return vertices;
} }
public List<MetadataGraphEdge> getIncidentEdges( MetadataGraphVertex vertex )
{
checkEdges();
return incidentEdges.get(vertex);
}
public List<MetadataGraphEdge> getExcidentEdges( MetadataGraphVertex vertex )
{
checkEdges();
return excidentEdges.get(vertex);
}
public boolean isVersionedVertices()
{
return versionedVertices;
}
public void setVersionedVertices(boolean versionedVertices)
{
this.versionedVertices = versionedVertices;
}
public boolean isScopedVertices()
{
return scopedVertices;
}
public void setScopedVertices(boolean scopedVertices)
{
this.scopedVertices = scopedVertices;
// scoped graph is versioned by definition public List<MetadataGraphEdge> getIncidentEdges( MetadataGraphVertex vertex )
if( scopedVertices ) {
versionedVertices = true; checkEdges();
} return incidentEdges.get( vertex );
public ArtifactScopeEnum getScope() }
{
return scope; public List<MetadataGraphEdge> getExcidentEdges( MetadataGraphVertex vertex )
} {
public void setScope(ArtifactScopeEnum scope) checkEdges();
{ return excidentEdges.get( vertex );
this.scope = scope; }
}
public boolean isVersionedVertices()
{
return versionedVertices;
}
public void setVersionedVertices( boolean versionedVertices )
{
this.versionedVertices = versionedVertices;
}
public boolean isScopedVertices()
{
return scopedVertices;
}
public void setScopedVertices( boolean scopedVertices )
{
this.scopedVertices = scopedVertices;
// scoped graph is versioned by definition
if ( scopedVertices )
{
versionedVertices = true;
}
}
public ArtifactScopeEnum getScope()
{
return scope;
}
public void setScope( ArtifactScopeEnum scope )
{
this.scope = scope;
}
// ------------------------------------------------------------------------
public boolean isEmpty()
{
return entry == null || vertices == null || vertices.isEmpty();
}
//------------------------------------------------------------------------ //------------------------------------------------------------------------
public boolean isEmpty() public boolean isEmptyEdges()
{ {
return return isEmpty() || incidentEdges == null || incidentEdges.isEmpty();
entry == null }
|| vertices == null
|| vertices.isEmpty()
;
}
//------------------------------------------------------------------------ //------------------------------------------------------------------------
public boolean isEmptyEdges() @Override
{ public String toString()
return {
isEmpty() StringBuilder sb = new StringBuilder( 512 );
|| incidentEdges == null if ( isEmpty() )
|| incidentEdges.isEmpty() {
; return "empty";
} }
//------------------------------------------------------------------------ for ( MetadataGraphVertex v : vertices )
@Override {
public String toString() sb.append( "Vertex: " + v.getMd().toString() + "\n" );
{ List<MetadataGraphEdge> ins = getIncidentEdges( v );
StringBuilder sb = new StringBuilder(512); if ( ins != null )
if( isEmpty() ) {
return "empty"; for ( MetadataGraphEdge e : ins )
for( MetadataGraphVertex v : vertices ) {
{ sb.append( " from : " + e.toString() + "\n" );
sb.append("Vertex: "+v.getMd().toString()+ "\n"); }
List<MetadataGraphEdge> ins = getIncidentEdges(v); }
if( ins != null ) else
for( MetadataGraphEdge e : ins ) {
{ sb.append( " no entries\n" );
sb.append(" from : "+e.toString()+"\n"); }
}
else List<MetadataGraphEdge> outs = getExcidentEdges( v );
sb.append(" no entries\n"); if ( outs != null )
{
List<MetadataGraphEdge> outs = getExcidentEdges(v); for ( MetadataGraphEdge e : outs )
if( outs != null ) {
for( MetadataGraphEdge e : outs ) sb.append( " to : " + e.toString() + "\n" );
{ }
sb.append(" to : "+e.toString()+ "\n"); }
} else
else {
sb.append(" no exit\n"); sb.append( " no exit\n" );
}
sb.append("-------------------------------------------------\n");
} sb.append( "-------------------------------------------------\n" );
sb.append("=============================================================\n"); }
return sb.toString(); sb.append( "=============================================================\n" );
} return sb.toString();
}
//------------------------------------------------------------------------ //------------------------------------------------------------------------
//------------------------------------------------------------------------ //------------------------------------------------------------------------
} }

View File

@ -1,10 +1,29 @@
package org.apache.maven.repository.metadata; package org.apache.maven.repository.metadata;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.artifact.ArtifactScopeEnum; import org.apache.maven.artifact.ArtifactScopeEnum;
/** /**
* metadata graph vertice - just a wrapper around artifact's metadata * metadata graph vertice - just a wrapper around artifact's metadata
* *
* @author <a href="oleg@codehaus.org">Oleg Gusakov</a> * @author <a href="oleg@codehaus.org">Oleg Gusakov</a>
*/ */
public class MetadataGraphVertex public class MetadataGraphVertex
@ -15,16 +34,16 @@ public class MetadataGraphVertex
// indications to use these in comparrison // indications to use these in comparrison
private boolean compareVersion = false; private boolean compareVersion = false;
private boolean compareScope = false; private boolean compareScope = false;
public MetadataGraphVertex( ArtifactMetadata md ) public MetadataGraphVertex( ArtifactMetadata md )
{ {
super(); super();
this.md = md; this.md = md;
} }
public MetadataGraphVertex( ArtifactMetadata md, boolean compareVersion, boolean compareScope ) public MetadataGraphVertex( ArtifactMetadata md, boolean compareVersion, boolean compareScope )
{ {
this(md); this( md );
this.compareVersion = compareVersion; this.compareVersion = compareVersion;
this.compareScope = compareScope; this.compareScope = compareScope;
} }
@ -38,125 +57,160 @@ public class MetadataGraphVertex
{ {
this.md = md; this.md = md;
} }
//---------------------------------------------------------------------
// ---------------------------------------------------------------------
public boolean isCompareVersion() public boolean isCompareVersion()
{ {
return compareVersion; return compareVersion;
} }
public void setCompareVersion(boolean compareVersion) public void setCompareVersion( boolean compareVersion )
{ {
this.compareVersion = compareVersion; this.compareVersion = compareVersion;
} }
public boolean isCompareScope() public boolean isCompareScope()
{ {
return compareScope; return compareScope;
} }
public void setCompareScope(boolean compareScope) public void setCompareScope( boolean compareScope )
{ {
this.compareScope = compareScope; this.compareScope = compareScope;
} }
//--------------------------------------------------------------------- // ---------------------------------------------------------------------
@Override @Override
public String toString() public String toString()
{ {
return "["+ (md == null ? "no metadata" : md.toString()) + "]"; return "[" + ( md == null ? "no metadata" : md.toString() ) + "]";
} }
//---------------------------------------------------------------------
private static int compareStrings( String s1, String s2 )
{
if( s1 == null && s2 == null )
return 0;
if( s1 == null && s2 != null ) // ---------------------------------------------------------------------
return -1; private static int compareStrings( String s1, String s2 )
{
if ( s1 == null && s2 == null )
{
return 0;
}
if( s1 != null && s2 == null ) if ( s1 == null && s2 != null )
return 1; {
return -1;
return s1.compareTo(s2); }
}
//---------------------------------------------------------------------
public int compareTo(MetadataGraphVertex vertex)
{
if( vertex == null || vertex.getMd() == null )
return 1;
ArtifactMetadata vmd = vertex.getMd();
if( vmd == null ) if ( s1 != null && s2 == null )
{ {
if( md == null ) return 1;
return 0; }
else
return 1;
}
int g = compareStrings( md.groupId, vmd.groupId );
if( g == 0 )
{
int a = compareStrings( md.artifactId, vmd.artifactId );
if( a == 0 )
{
if( compareVersion )
{
int v = compareStrings( md.version, vmd.version );
if( v == 0) {
if( compareScope ) {
String s1 = ArtifactScopeEnum.checkScope( md.artifactScope).getScope();
String s2 = ArtifactScopeEnum.checkScope(vmd.artifactScope).getScope();
return s1.compareTo(s2);
}
else
return 0;
}
else
return v;
}
else
return 0;
}
else
return a;
}
return g;
}
//---------------------------------------------------------------------
@Override
public boolean equals(Object vo)
{
if( vo == null || !(vo instanceof MetadataGraphVertex) )
return false;
return compareTo( (MetadataGraphVertex)vo ) == 0;
}
//---------------------------------------------------------------------
@Override return s1.compareTo( s2 );
public int hashCode() }
{
if( md == null )
return super.hashCode();
StringBuilder hashString = new StringBuilder(128);
hashString.append( md.groupId+"|" );
hashString.append( md.artifactId+"|" );
if( compareVersion )
hashString.append(md.version + "|");
if( compareScope )
hashString.append(md.getArtifactScope() + "|");
return hashString.toString().hashCode();
// BASE64Encoder b64 = new BASE64Encoder(); // ---------------------------------------------------------------------
// return b64.encode( hashString.toString().getBytes() ).hashCode(); public int compareTo( MetadataGraphVertex vertex )
} {
if ( vertex == null || vertex.getMd() == null )
//--------------------------------------------------------------------- {
//--------------------------------------------------------------------- return 1;
}
ArtifactMetadata vmd = vertex.getMd();
if ( vmd == null )
{
if ( md == null )
{
return 0;
}
else
{
return 1;
}
}
int g = compareStrings( md.groupId, vmd.groupId );
if ( g == 0 )
{
int a = compareStrings( md.artifactId, vmd.artifactId );
if ( a == 0 )
{
if ( compareVersion )
{
int v = compareStrings( md.version, vmd.version );
if ( v == 0 )
{
if ( compareScope )
{
String s1 = ArtifactScopeEnum.checkScope( md.artifactScope ).getScope();
String s2 = ArtifactScopeEnum.checkScope( vmd.artifactScope ).getScope();
return s1.compareTo( s2 );
}
else
{
return 0;
}
}
else
{
return v;
}
}
else
{
return 0;
}
}
else
{
return a;
}
}
return g;
}
// ---------------------------------------------------------------------
@Override
public boolean equals( Object vo )
{
if ( vo == null || !( vo instanceof MetadataGraphVertex ) )
{
return false;
}
return compareTo( (MetadataGraphVertex) vo ) == 0;
}
// ---------------------------------------------------------------------
@Override
public int hashCode()
{
if ( md == null )
{
return super.hashCode();
}
StringBuilder hashString = new StringBuilder( 128 );
hashString.append( md.groupId + "|" );
hashString.append( md.artifactId + "|" );
if ( compareVersion )
{
hashString.append( md.version + "|" );
}
if ( compareScope )
{
hashString.append( md.getArtifactScope() + "|" );
}
return hashString.toString().hashCode();
// BASE64Encoder b64 = new BASE64Encoder();
// return b64.encode( hashString.toString().getBytes() ).hashCode();
}
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
} }

View File

@ -1,23 +1,42 @@
package org.apache.maven.repository.metadata; package org.apache.maven.repository.metadata;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.artifact.ArtifactScopeEnum; import org.apache.maven.artifact.ArtifactScopeEnum;
import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
/** /**
* This object is tinted with ClasspathTransformation and GraphConflictResolver. * This object is tinted with ClasspathTransformation and GraphConflictResolver.
* Get rid of them after debugging * Get rid of them after debugging
* *
* @author <a href="oleg@codehaus.org">Oleg Gusakov</a> * @author <a href="oleg@codehaus.org">Oleg Gusakov</a>
*/ */
public class MetadataResolutionResult public class MetadataResolutionResult
{ {
MetadataTreeNode treeRoot; MetadataTreeNode treeRoot;
/** /**
* these components are are initialized on demand by * these components are are initialized on demand by
* explicit call of the initTreeProcessing() * explicit call of the initTreeProcessing()
*/ */
ClasspathTransformation classpathTransformation; ClasspathTransformation classpathTransformation;
GraphConflictResolver conflictResolver; GraphConflictResolver conflictResolver;
@ -40,84 +59,112 @@ public class MetadataResolutionResult
{ {
this.treeRoot = root; this.treeRoot = root;
} }
public void initTreeProcessing( PlexusContainer plexus ) public void initTreeProcessing( PlexusContainer plexus )
throws ComponentLookupException throws ComponentLookupException
{ {
classpathTransformation = (ClasspathTransformation)plexus.lookup(ClasspathTransformation.class); classpathTransformation = (ClasspathTransformation) plexus.lookup( ClasspathTransformation.class );
conflictResolver = (GraphConflictResolver)plexus.lookup(GraphConflictResolver.class); conflictResolver = (GraphConflictResolver) plexus.lookup( GraphConflictResolver.class );
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
public MetadataGraph getGraph() public MetadataGraph getGraph()
throws MetadataResolutionException throws MetadataResolutionException
{ {
return treeRoot == null ? null : new MetadataGraph(treeRoot); return treeRoot == null ? null : new MetadataGraph( treeRoot );
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
public MetadataGraph getGraph( ArtifactScopeEnum scope ) public MetadataGraph getGraph( ArtifactScopeEnum scope )
throws MetadataResolutionException, GraphConflictResolutionException throws MetadataResolutionException, GraphConflictResolutionException
{ {
if( treeRoot == null ) if ( treeRoot == null )
return null; {
return null;
if( conflictResolver == null ) }
return null;
if ( conflictResolver == null )
{
return null;
}
return conflictResolver.resolveConflicts( getGraph(), scope ); return conflictResolver.resolveConflicts( getGraph(), scope );
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
public MetadataGraph getGraph( MetadataResolutionRequestTypeEnum requestType ) public MetadataGraph getGraph( MetadataResolutionRequestTypeEnum requestType )
throws MetadataResolutionException, GraphConflictResolutionException throws MetadataResolutionException, GraphConflictResolutionException
{ {
if( requestType == null ) if ( requestType == null )
return null; {
return null;
if( treeRoot == null ) }
return null;
if ( treeRoot == null )
if( conflictResolver == null ) {
return null; return null;
}
if( requestType.equals(MetadataResolutionRequestTypeEnum.classpathCompile) )
return conflictResolver.resolveConflicts( getGraph(), ArtifactScopeEnum.compile ); if ( conflictResolver == null )
else if( requestType.equals(MetadataResolutionRequestTypeEnum.classpathRuntime) ) {
return conflictResolver.resolveConflicts( getGraph(), ArtifactScopeEnum.runtime ); return null;
else if( requestType.equals(MetadataResolutionRequestTypeEnum.classpathRuntime) ) }
return conflictResolver.resolveConflicts( getGraph(), ArtifactScopeEnum.test );
else if( requestType.equals(MetadataResolutionRequestTypeEnum.classpathRuntime) ) if ( requestType.equals( MetadataResolutionRequestTypeEnum.classpathCompile ) )
return conflictResolver.resolveConflicts( getGraph(), ArtifactScopeEnum.test ); {
else if( requestType.equals(MetadataResolutionRequestTypeEnum.graph) ) return conflictResolver.resolveConflicts( getGraph(), ArtifactScopeEnum.compile );
return getGraph(); }
else if( requestType.equals(MetadataResolutionRequestTypeEnum.versionedGraph) ) { else if ( requestType.equals( MetadataResolutionRequestTypeEnum.classpathRuntime ) )
return new MetadataGraph( getTree(), true, false ); {
} return conflictResolver.resolveConflicts( getGraph(), ArtifactScopeEnum.runtime );
else if( requestType.equals(MetadataResolutionRequestTypeEnum.scopedGraph) ) { }
return new MetadataGraph( getTree(), true, true ); else if ( requestType.equals( MetadataResolutionRequestTypeEnum.classpathRuntime ) )
} {
return null; return conflictResolver.resolveConflicts( getGraph(), ArtifactScopeEnum.test );
}
else if ( requestType.equals( MetadataResolutionRequestTypeEnum.classpathRuntime ) )
{
return conflictResolver.resolveConflicts( getGraph(), ArtifactScopeEnum.test );
}
else if ( requestType.equals( MetadataResolutionRequestTypeEnum.graph ) )
{
return getGraph();
}
else if ( requestType.equals( MetadataResolutionRequestTypeEnum.versionedGraph ) )
{
return new MetadataGraph( getTree(), true, false );
}
else if ( requestType.equals( MetadataResolutionRequestTypeEnum.scopedGraph ) )
{
return new MetadataGraph( getTree(), true, true );
}
return null;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
public ClasspathContainer getClasspath( ArtifactScopeEnum scope ) public ClasspathContainer getClasspath( ArtifactScopeEnum scope )
throws MetadataGraphTransformationException, MetadataResolutionException throws MetadataGraphTransformationException, MetadataResolutionException
{ {
if( classpathTransformation == null ) if ( classpathTransformation == null )
return null; {
return null;
}
MetadataGraph dirtyGraph = getGraph(); MetadataGraph dirtyGraph = getGraph();
if( dirtyGraph == null ) if ( dirtyGraph == null )
return null; {
return null;
}
return classpathTransformation.transform( dirtyGraph, scope, false ); return classpathTransformation.transform( dirtyGraph, scope, false );
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
public MetadataTreeNode getClasspathTree( ArtifactScopeEnum scope ) public MetadataTreeNode getClasspathTree( ArtifactScopeEnum scope )
throws MetadataGraphTransformationException, MetadataResolutionException throws MetadataGraphTransformationException, MetadataResolutionException
{ {
ClasspathContainer cpc = getClasspath(scope); ClasspathContainer cpc = getClasspath( scope );
if( cpc == null ) if ( cpc == null )
return null; {
return null;
}
return cpc.getClasspathAsTree(); return cpc.getClasspathAsTree();
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -147,8 +147,8 @@ under the License.
versioning.setLastUpdated( v.getLastUpdated() ); versioning.setLastUpdated( v.getLastUpdated() );
} }
if ( v.getLastUpdated() == null || v.getLastUpdated().length() == 0 || if ( v.getLastUpdated() == null || v.getLastUpdated().length() == 0
versioning.getLastUpdated().compareTo( v.getLastUpdated() ) >= 0 ) || versioning.getLastUpdated().compareTo( v.getLastUpdated() ) >= 0 )
{ {
changed = true; changed = true;
v.setLastUpdated( versioning.getLastUpdated() ); v.setLastUpdated( versioning.getLastUpdated() );

View File

@ -1,12 +1,30 @@
package org.apache.maven.repository; package org.apache.maven.repository;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.io.File; import java.io.File;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.PlexusTestCase;
@ -15,7 +33,7 @@ public class MirrorProcessorTest
{ {
private DefaultMirrorBuilder mirrorBuilder; private DefaultMirrorBuilder mirrorBuilder;
private ArtifactRepositoryFactory repositorySystem; private ArtifactRepositoryFactory repositorySystem;
protected void setUp() protected void setUp()
throws Exception throws Exception
{ {
@ -23,38 +41,40 @@ public class MirrorProcessorTest
repositorySystem = lookup( ArtifactRepositoryFactory.class ); repositorySystem = lookup( ArtifactRepositoryFactory.class );
mirrorBuilder.clearMirrors(); mirrorBuilder.clearMirrors();
} }
@Override @Override
protected void tearDown() throws Exception { protected void tearDown()
mirrorBuilder = null; throws Exception
super.tearDown(); {
mirrorBuilder = null;
super.tearDown();
} }
public void testAddMirrorWithNullRepositoryId() public void testAddMirrorWithNullRepositoryId()
{ {
mirrorBuilder.addMirror( null, "test", "http://www.nowhere.com/", null ); mirrorBuilder.addMirror( null, "test", "http://www.nowhere.com/", null );
} }
public void testExternalURL() public void testExternalURL()
{ {
assertTrue( mirrorBuilder.isExternalRepo( getRepo( "foo", "http://somehost" ) ) ); assertTrue( DefaultMirrorBuilder.isExternalRepo( getRepo( "foo", "http://somehost" ) ) );
assertTrue( mirrorBuilder.isExternalRepo( getRepo( "foo", "http://somehost:9090/somepath" ) ) ); assertTrue( DefaultMirrorBuilder.isExternalRepo( getRepo( "foo", "http://somehost:9090/somepath" ) ) );
assertTrue( mirrorBuilder.isExternalRepo( getRepo( "foo", "ftp://somehost" ) ) ); assertTrue( DefaultMirrorBuilder.isExternalRepo( getRepo( "foo", "ftp://somehost" ) ) );
assertTrue( mirrorBuilder.isExternalRepo( getRepo( "foo", "http://192.168.101.1" ) ) ); assertTrue( DefaultMirrorBuilder.isExternalRepo( getRepo( "foo", "http://192.168.101.1" ) ) );
assertTrue( mirrorBuilder.isExternalRepo( getRepo( "foo", "http://" ) ) ); assertTrue( DefaultMirrorBuilder.isExternalRepo( getRepo( "foo", "http://" ) ) );
// these are local // these are local
assertFalse( mirrorBuilder.isExternalRepo( getRepo( "foo", "http://localhost:8080" ) ) ); assertFalse( DefaultMirrorBuilder.isExternalRepo( getRepo( "foo", "http://localhost:8080" ) ) );
assertFalse( mirrorBuilder.isExternalRepo( getRepo( "foo", "http://127.0.0.1:9090" ) ) ); assertFalse( DefaultMirrorBuilder.isExternalRepo( getRepo( "foo", "http://127.0.0.1:9090" ) ) );
assertFalse( mirrorBuilder.isExternalRepo( getRepo( "foo", "file://localhost/somepath" ) ) ); assertFalse( DefaultMirrorBuilder.isExternalRepo( getRepo( "foo", "file://localhost/somepath" ) ) );
assertFalse( mirrorBuilder.isExternalRepo( getRepo( "foo", "file://localhost/D:/somepath" ) ) ); assertFalse( DefaultMirrorBuilder.isExternalRepo( getRepo( "foo", "file://localhost/D:/somepath" ) ) );
assertFalse( mirrorBuilder.isExternalRepo( getRepo( "foo", "http://localhost" ) ) ); assertFalse( DefaultMirrorBuilder.isExternalRepo( getRepo( "foo", "http://localhost" ) ) );
assertFalse( mirrorBuilder.isExternalRepo( getRepo( "foo", "http://127.0.0.1" ) ) ); assertFalse( DefaultMirrorBuilder.isExternalRepo( getRepo( "foo", "http://127.0.0.1" ) ) );
assertFalse( mirrorBuilder.isExternalRepo( getRepo( "foo", "file:///somepath" ) ) ); assertFalse( DefaultMirrorBuilder.isExternalRepo( getRepo( "foo", "file:///somepath" ) ) );
assertFalse( mirrorBuilder.isExternalRepo( getRepo( "foo", "file://D:/somepath" ) ) ); assertFalse( DefaultMirrorBuilder.isExternalRepo( getRepo( "foo", "file://D:/somepath" ) ) );
// not a proper url so returns false; // not a proper url so returns false;
assertFalse( mirrorBuilder.isExternalRepo( getRepo( "foo", "192.168.101.1" ) ) ); assertFalse( DefaultMirrorBuilder.isExternalRepo( getRepo( "foo", "192.168.101.1" ) ) );
assertFalse( mirrorBuilder.isExternalRepo( getRepo( "foo", "" ) ) ); assertFalse( DefaultMirrorBuilder.isExternalRepo( getRepo( "foo", "" ) ) );
} }
public void testMirrorLookup() public void testMirrorLookup()
@ -98,12 +118,12 @@ public class MirrorProcessorTest
mirrorBuilder.addMirror( "a2", "a,b", "http://a2", null ); mirrorBuilder.addMirror( "a2", "a,b", "http://a2", null );
mirrorBuilder.addMirror( "a", "a", "http://a", null ); mirrorBuilder.addMirror( "a", "a", "http://a", null );
//make sure repeated entries are skipped //make sure repeated entries are skipped
mirrorBuilder.addMirror( "a", "a", "http://a3", null ); mirrorBuilder.addMirror( "a", "a", "http://a3", null );
mirrorBuilder.addMirror( "b", "b", "http://b", null ); mirrorBuilder.addMirror( "b", "b", "http://b", null );
mirrorBuilder.addMirror( "c", "d,e", "http://de", null ); mirrorBuilder.addMirror( "c", "d,e", "http://de", null );
mirrorBuilder.addMirror( "c", "*", "http://wildcard", null ); mirrorBuilder.addMirror( "c", "*", "http://wildcard", null );
mirrorBuilder.addMirror( "c", "e,f", "http://ef", null ); mirrorBuilder.addMirror( "c", "e,f", "http://ef", null );
ArtifactRepository repo = null; ArtifactRepository repo = null;
repo = mirrorBuilder.getMirrorRepository( getRepo( "a", "http://a.a" ) ); repo = mirrorBuilder.getMirrorRepository( getRepo( "a", "http://a.a" ) );
@ -114,68 +134,68 @@ public class MirrorProcessorTest
repo = mirrorBuilder.getMirrorRepository( getRepo( "c", "http://c.c" ) ); repo = mirrorBuilder.getMirrorRepository( getRepo( "c", "http://c.c" ) );
assertEquals( "http://wildcard", repo.getUrl() ); assertEquals( "http://wildcard", repo.getUrl() );
repo = mirrorBuilder.getMirrorRepository( getRepo( "d", "http://d" ) ); repo = mirrorBuilder.getMirrorRepository( getRepo( "d", "http://d" ) );
assertEquals( "http://de", repo.getUrl() ); assertEquals( "http://de", repo.getUrl() );
repo = mirrorBuilder.getMirrorRepository( getRepo( "e", "http://e" ) ); repo = mirrorBuilder.getMirrorRepository( getRepo( "e", "http://e" ) );
assertEquals( "http://de", repo.getUrl() ); assertEquals( "http://de", repo.getUrl() );
repo = mirrorBuilder.getMirrorRepository( getRepo( "f", "http://f" ) ); repo = mirrorBuilder.getMirrorRepository( getRepo( "f", "http://f" ) );
assertEquals( "http://wildcard", repo.getUrl() ); assertEquals( "http://wildcard", repo.getUrl() );
} }
public void testPatterns() public void testPatterns()
{ {
assertTrue( mirrorBuilder.matchPattern( getRepo( "a" ), "*" ) ); assertTrue( DefaultMirrorBuilder.matchPattern( getRepo( "a" ), "*" ) );
assertTrue( mirrorBuilder.matchPattern( getRepo( "a" ), "*," ) ); assertTrue( DefaultMirrorBuilder.matchPattern( getRepo( "a" ), "*," ) );
assertTrue( mirrorBuilder.matchPattern( getRepo( "a" ), ",*," ) ); assertTrue( DefaultMirrorBuilder.matchPattern( getRepo( "a" ), ",*," ) );
assertTrue( mirrorBuilder.matchPattern( getRepo( "a" ), "*," ) ); assertTrue( DefaultMirrorBuilder.matchPattern( getRepo( "a" ), "*," ) );
assertTrue( mirrorBuilder.matchPattern( getRepo( "a" ), "a" ) ); assertTrue( DefaultMirrorBuilder.matchPattern( getRepo( "a" ), "a" ) );
assertTrue( mirrorBuilder.matchPattern( getRepo( "a" ), "a," ) ); assertTrue( DefaultMirrorBuilder.matchPattern( getRepo( "a" ), "a," ) );
assertTrue( mirrorBuilder.matchPattern( getRepo( "a" ), ",a," ) ); assertTrue( DefaultMirrorBuilder.matchPattern( getRepo( "a" ), ",a," ) );
assertTrue( mirrorBuilder.matchPattern( getRepo( "a" ), "a," ) ); assertTrue( DefaultMirrorBuilder.matchPattern( getRepo( "a" ), "a," ) );
assertFalse( mirrorBuilder.matchPattern( getRepo( "b" ), "a" ) ); assertFalse( DefaultMirrorBuilder.matchPattern( getRepo( "b" ), "a" ) );
assertFalse( mirrorBuilder.matchPattern( getRepo( "b" ), "a," ) ); assertFalse( DefaultMirrorBuilder.matchPattern( getRepo( "b" ), "a," ) );
assertFalse( mirrorBuilder.matchPattern( getRepo( "b" ), ",a" ) ); assertFalse( DefaultMirrorBuilder.matchPattern( getRepo( "b" ), ",a" ) );
assertFalse( mirrorBuilder.matchPattern( getRepo( "b" ), ",a," ) ); assertFalse( DefaultMirrorBuilder.matchPattern( getRepo( "b" ), ",a," ) );
assertTrue( mirrorBuilder.matchPattern( getRepo( "a" ), "a,b" ) ); assertTrue( DefaultMirrorBuilder.matchPattern( getRepo( "a" ), "a,b" ) );
assertTrue( mirrorBuilder.matchPattern( getRepo( "b" ), "a,b" ) ); assertTrue( DefaultMirrorBuilder.matchPattern( getRepo( "b" ), "a,b" ) );
assertFalse( mirrorBuilder.matchPattern( getRepo( "c" ), "a,b" ) ); assertFalse( DefaultMirrorBuilder.matchPattern( getRepo( "c" ), "a,b" ) );
assertTrue( mirrorBuilder.matchPattern( getRepo( "a" ), "*" ) ); assertTrue( DefaultMirrorBuilder.matchPattern( getRepo( "a" ), "*" ) );
assertTrue( mirrorBuilder.matchPattern( getRepo( "a" ), "*,b" ) ); assertTrue( DefaultMirrorBuilder.matchPattern( getRepo( "a" ), "*,b" ) );
assertTrue( mirrorBuilder.matchPattern( getRepo( "a" ), "*,!b" ) ); assertTrue( DefaultMirrorBuilder.matchPattern( getRepo( "a" ), "*,!b" ) );
assertFalse( mirrorBuilder.matchPattern( getRepo( "a" ), "*,!a" ) ); assertFalse( DefaultMirrorBuilder.matchPattern( getRepo( "a" ), "*,!a" ) );
assertFalse( mirrorBuilder.matchPattern( getRepo( "a" ), "!a,*" ) ); assertFalse( DefaultMirrorBuilder.matchPattern( getRepo( "a" ), "!a,*" ) );
assertTrue( mirrorBuilder.matchPattern( getRepo( "c" ), "*,!a" ) ); assertTrue( DefaultMirrorBuilder.matchPattern( getRepo( "c" ), "*,!a" ) );
assertTrue( mirrorBuilder.matchPattern( getRepo( "c" ), "!a,*" ) ); assertTrue( DefaultMirrorBuilder.matchPattern( getRepo( "c" ), "!a,*" ) );
assertFalse( mirrorBuilder.matchPattern( getRepo( "c" ), "!a,!c" ) ); assertFalse( DefaultMirrorBuilder.matchPattern( getRepo( "c" ), "!a,!c" ) );
assertFalse( mirrorBuilder.matchPattern( getRepo( "d" ), "!a,!c*" ) ); assertFalse( DefaultMirrorBuilder.matchPattern( getRepo( "d" ), "!a,!c*" ) );
} }
public void testPatternsWithExternal() public void testPatternsWithExternal()
{ {
assertTrue( mirrorBuilder.matchPattern( getRepo( "a", "http://localhost" ), "*" ) ); assertTrue( DefaultMirrorBuilder.matchPattern( getRepo( "a", "http://localhost" ), "*" ) );
assertFalse( mirrorBuilder.matchPattern( getRepo( "a", "http://localhost" ), "external:*" ) ); assertFalse( DefaultMirrorBuilder.matchPattern( getRepo( "a", "http://localhost" ), "external:*" ) );
assertTrue( mirrorBuilder.matchPattern( getRepo( "a", "http://localhost" ), "external:*,a" ) ); assertTrue( DefaultMirrorBuilder.matchPattern( getRepo( "a", "http://localhost" ), "external:*,a" ) );
assertFalse( mirrorBuilder.matchPattern( getRepo( "a", "http://localhost" ), "external:*,!a" ) ); assertFalse( DefaultMirrorBuilder.matchPattern( getRepo( "a", "http://localhost" ), "external:*,!a" ) );
assertTrue( mirrorBuilder.matchPattern( getRepo( "a", "http://localhost" ), "a,external:*" ) ); assertTrue( DefaultMirrorBuilder.matchPattern( getRepo( "a", "http://localhost" ), "a,external:*" ) );
assertFalse( mirrorBuilder.matchPattern( getRepo( "a", "http://localhost" ), "!a,external:*" ) ); assertFalse( DefaultMirrorBuilder.matchPattern( getRepo( "a", "http://localhost" ), "!a,external:*" ) );
assertFalse( mirrorBuilder.matchPattern( getRepo( "c", "http://localhost" ), "!a,external:*" ) ); assertFalse( DefaultMirrorBuilder.matchPattern( getRepo( "c", "http://localhost" ), "!a,external:*" ) );
assertTrue( mirrorBuilder.matchPattern( getRepo( "c", "http://somehost" ), "!a,external:*" ) ); assertTrue( DefaultMirrorBuilder.matchPattern( getRepo( "c", "http://somehost" ), "!a,external:*" ) );
} }
public void testMirrorProperUrlAndProtocolAndBasedir() public void testMirrorProperUrlAndProtocolAndBasedir()
{ {
@ -192,7 +212,7 @@ public class MirrorProcessorTest
/** /**
* Build an ArtifactRepository object. * Build an ArtifactRepository object.
* *
* @param id * @param id
* @param url * @param url
* @return * @return
@ -204,12 +224,12 @@ public class MirrorProcessorTest
/** /**
* Build an ArtifactRepository object. * Build an ArtifactRepository object.
* *
* @param id * @param id
* @return * @return
*/ */
private ArtifactRepository getRepo( String id ) private ArtifactRepository getRepo( String id )
{ {
return getRepo( id, "http://something" ); return getRepo( id, "http://something" );
} }
} }

View File

@ -34,10 +34,6 @@ import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.repository.legacy.ChecksumFailedException;
import org.apache.maven.repository.legacy.DefaultWagonManager;
import org.apache.maven.repository.legacy.UpdateCheckManager;
import org.apache.maven.repository.legacy.WagonManager;
import org.apache.maven.wagon.ResourceDoesNotExistException; import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException; import org.apache.maven.wagon.TransferFailedException;
import org.apache.maven.wagon.UnsupportedProtocolException; import org.apache.maven.wagon.UnsupportedProtocolException;
@ -63,48 +59,59 @@ public class DefaultWagonManagerTest
private TransferListener transferListener = new Debug(); private TransferListener transferListener = new Debug();
private ArtifactFactory artifactFactory; private ArtifactFactory artifactFactory;
private ArtifactRepositoryFactory artifactRepositoryFactory; private ArtifactRepositoryFactory artifactRepositoryFactory;
protected void setUp() protected void setUp()
throws Exception throws Exception
{ {
super.setUp(); super.setUp();
wagonManager = (DefaultWagonManager) lookup( WagonManager.class ); wagonManager = (DefaultWagonManager) lookup( WagonManager.class );
artifactFactory = lookup( ArtifactFactory.class ); artifactFactory = lookup( ArtifactFactory.class );
artifactRepositoryFactory = lookup( ArtifactRepositoryFactory.class ); artifactRepositoryFactory = lookup( ArtifactRepositoryFactory.class );
} }
@Override @Override
protected void tearDown() throws Exception { protected void tearDown()
wagonManager = null; throws Exception
artifactFactory = null; {
super.tearDown(); wagonManager = null;
artifactFactory = null;
super.tearDown();
} }
public void testUnnecessaryRepositoryLookup() throws Exception { public void testUnnecessaryRepositoryLookup()
throws Exception
{
Artifact artifact = createTestPomArtifact( "target/test-data/get-missing-pom" ); Artifact artifact = createTestPomArtifact( "target/test-data/get-missing-pom" );
List<ArtifactRepository> repos = new ArrayList<ArtifactRepository>(); List<ArtifactRepository> repos = new ArrayList<ArtifactRepository>();
repos.add(artifactRepositoryFactory.createArtifactRepository( "repo1", "string://url1", new ArtifactRepositoryLayoutStub(), null, null )); repos.add( artifactRepositoryFactory.createArtifactRepository( "repo1", "string://url1",
repos.add(artifactRepositoryFactory.createArtifactRepository( "repo2", "string://url2", new ArtifactRepositoryLayoutStub(), null, null )); new ArtifactRepositoryLayoutStub(), null, null ) );
repos.add( artifactRepositoryFactory.createArtifactRepository( "repo2", "string://url2",
new ArtifactRepositoryLayoutStub(), null, null ) );
StringWagon wagon = (StringWagon) wagonManager.getWagon( "string" ); StringWagon wagon = (StringWagon) wagonManager.getWagon( "string" );
wagon.addExpectedContent( repos.get(0).getLayout().pathOf( artifact ), "expected" ); wagon.addExpectedContent( repos.get( 0 ).getLayout().pathOf( artifact ), "expected" );
wagon.addExpectedContent( repos.get(1).getLayout().pathOf( artifact ), "expected" ); wagon.addExpectedContent( repos.get( 1 ).getLayout().pathOf( artifact ), "expected" );
class TransferListener extends AbstractTransferListener { class TransferListener
public List<TransferEvent> events = new ArrayList<TransferEvent>(); extends AbstractTransferListener
@Override {
public void transferInitiated(TransferEvent transferEvent) { public List<TransferEvent> events = new ArrayList<TransferEvent>();
events.add(transferEvent);
} @Override
}; public void transferInitiated( TransferEvent transferEvent )
{
events.add( transferEvent );
}
}
TransferListener listener = new TransferListener(); TransferListener listener = new TransferListener();
wagonManager.getArtifact( artifact, repos, listener ); wagonManager.getArtifact( artifact, repos, listener );
assertEquals(1, listener.events.size()); assertEquals( 1, listener.events.size() );
} }
public void testGetPomExistsLocallyForced() public void testGetPomExistsLocallyForced()
throws IOException, TransferFailedException, ResourceDoesNotExistException, UnsupportedProtocolException throws IOException, TransferFailedException, ResourceDoesNotExistException, UnsupportedProtocolException
{ {
@ -131,43 +138,43 @@ public class DefaultWagonManagerTest
public void testGetMissingJar() throws TransferFailedException, UnsupportedProtocolException, IOException public void testGetMissingJar() throws TransferFailedException, UnsupportedProtocolException, IOException
{ {
Artifact artifact = createTestArtifact( "target/test-data/get-missing-jar", "jar" ); Artifact artifact = createTestArtifact( "target/test-data/get-missing-jar", "jar" );
ArtifactRepository repo = createStringRepo(); ArtifactRepository repo = createStringRepo();
try try
{ {
wagonManager.getArtifact( artifact, repo, null ); wagonManager.getArtifact( artifact, repo, null );
fail(); fail();
} }
catch ( ResourceDoesNotExistException e ) catch ( ResourceDoesNotExistException e )
{ {
assertTrue( true ); assertTrue( true );
} }
assertFalse( artifact.getFile().exists() ); assertFalse( artifact.getFile().exists() );
} }
public void testGetMissingJarForced() throws TransferFailedException, UnsupportedProtocolException, IOException public void testGetMissingJarForced() throws TransferFailedException, UnsupportedProtocolException, IOException
{ {
Artifact artifact = createTestArtifact( "target/test-data/get-missing-jar", "jar" ); Artifact artifact = createTestArtifact( "target/test-data/get-missing-jar", "jar" );
ArtifactRepository repo = createStringRepo(); ArtifactRepository repo = createStringRepo();
try try
{ {
wagonManager.getArtifact( artifact, repo, null ); wagonManager.getArtifact( artifact, repo, null );
fail(); fail();
} }
catch ( ResourceDoesNotExistException e ) catch ( ResourceDoesNotExistException e )
{ {
assertTrue( true ); assertTrue( true );
} }
assertFalse( artifact.getFile().exists() ); assertFalse( artifact.getFile().exists() );
} }
public void testGetRemoteJar() public void testGetRemoteJar()
throws TransferFailedException, ResourceDoesNotExistException, UnsupportedProtocolException, IOException, throws TransferFailedException, ResourceDoesNotExistException, UnsupportedProtocolException, IOException,
AuthorizationException AuthorizationException
@ -249,10 +256,10 @@ public class DefaultWagonManagerTest
{ {
return artifactRepositoryFactory.createArtifactRepository( "id", "string://url", new ArtifactRepositoryLayoutStub(), null, null ); return artifactRepositoryFactory.createArtifactRepository( "id", "string://url", new ArtifactRepositoryLayoutStub(), null, null );
} }
/** /**
* Build an ArtifactRepository object. * Build an ArtifactRepository object.
* *
* @param id * @param id
* @param url * @param url
* @return * @return
@ -264,7 +271,7 @@ public class DefaultWagonManagerTest
/** /**
* Build an ArtifactRepository object. * Build an ArtifactRepository object.
* *
* @param id * @param id
* @return * @return
*/ */
@ -311,7 +318,7 @@ public class DefaultWagonManagerTest
/* getArtifact */ /* getArtifact */
assertFalse( "Transfer listener is registered before test", assertFalse( "Transfer listener is registered before test",
wagon.getTransferEventSupport().hasTransferListener( transferListener ) ); wagon.getTransferEventSupport().hasTransferListener( transferListener ) );
wagonManager.getArtifact( artifact, repo, transferListener); wagonManager.getArtifact( artifact, repo, transferListener );
assertFalse( "Transfer listener still registered after getArtifact", assertFalse( "Transfer listener still registered after getArtifact",
wagon.getTransferEventSupport().hasTransferListener( transferListener ) ); wagon.getTransferEventSupport().hasTransferListener( transferListener ) );
@ -331,16 +338,16 @@ public class DefaultWagonManagerTest
throws Exception throws Exception
{ {
ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL ); ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL );
ArtifactRepository repo = artifactRepositoryFactory.createArtifactRepository( "id", "string://url", new ArtifactRepositoryLayoutStub(), policy, policy ); ArtifactRepository repo = artifactRepositoryFactory.createArtifactRepository( "id", "string://url", new ArtifactRepositoryLayoutStub(), policy, policy );
Artifact artifact = Artifact artifact =
new DefaultArtifact( "sample.group", "sample-art", VersionRange.createFromVersion( "1.0" ), "scope", new DefaultArtifact( "sample.group", "sample-art", VersionRange.createFromVersion( "1.0" ), "scope",
"jar", "classifier", null ); "jar", "classifier", null );
artifact.setFile( getTestFile( "target/sample-art" ) ); artifact.setFile( getTestFile( "target/sample-art" ) );
StringWagon wagon = (StringWagon) wagonManager.getWagon( "string" ); StringWagon wagon = (StringWagon) wagonManager.getWagon( "string" );
wagon.clearExpectedContent(); wagon.clearExpectedContent();
wagon.addExpectedContent( "path", "lower-case-checksum" ); wagon.addExpectedContent( "path", "lower-case-checksum" );
wagon.addExpectedContent( "path.sha1", "2a25dc564a3b34f68237fc849066cbc7bb7a36a1" ); wagon.addExpectedContent( "path.sha1", "2a25dc564a3b34f68237fc849066cbc7bb7a36a1" );
@ -437,7 +444,7 @@ public class DefaultWagonManagerTest
{ {
return "test"; return "test";
} }
public String pathOfRemoteRepositoryMetadata( ArtifactMetadata metadata ) public String pathOfRemoteRepositoryMetadata( ArtifactMetadata metadata )
{ {
return "path"; return "path";

View File

@ -48,7 +48,6 @@ import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException
import org.apache.maven.artifact.versioning.OverConstrainedVersionException; import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest; import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
import org.apache.maven.repository.legacy.resolver.LegacyArtifactCollector;
import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.PlexusTestCase;
/** /**
@ -84,10 +83,12 @@ public class DefaultArtifactCollectorTest
} }
@Override @Override
protected void tearDown() throws Exception { protected void tearDown()
artifactCollector = null; throws Exception
artifactFactory = null; {
super.tearDown(); artifactCollector = null;
artifactFactory = null;
super.tearDown();
} }
// works, but we don't fail on cycles presently // works, but we don't fail on cycles presently
@ -738,7 +739,7 @@ public class DefaultArtifactCollectorTest
private ArtifactResolutionResult collect( Set artifacts, ArtifactFilter filter ) private ArtifactResolutionResult collect( Set artifacts, ArtifactFilter filter )
throws ArtifactResolutionException throws ArtifactResolutionException
{ {
return artifactCollector.collect( artifacts, projectArtifact.artifact, null, null, null, source, filter, return artifactCollector.collect( artifacts, projectArtifact.artifact, null, null, null, source, filter,
Collections.EMPTY_LIST, null ); Collections.EMPTY_LIST, null );
} }