PR: MRM-42

Submitted by: Maria Odea Ching

Applied patch fixed a bug from scheduler and indexer usage

git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@382329 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Edwin L. Punzalan 2006-03-02 09:21:15 +00:00
parent 43b79ffe9d
commit 4bb48a7d7b
6 changed files with 70 additions and 36 deletions

View File

@ -19,9 +19,9 @@ package org.apache.maven.repository.discovery;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.repository.ArtifactUtils;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.repository.ArtifactUtils;
import org.codehaus.plexus.util.StringUtils;
import java.io.File;
@ -36,7 +36,7 @@ import java.util.StringTokenizer;
*
* @author John Casey
* @author Brett Porter
* @plexus.component role="org.apache.maven.repository.discovery.ArtifactDiscoverer" role-hint="default" instantiation-strategy="per-lookup"
* @plexus.component role="org.apache.maven.repository.discovery.ArtifactDiscoverer" role-hint="org.apache.maven.repository.discovery.DefaultArtifactDiscoverer"
*/
public class DefaultArtifactDiscoverer
extends AbstractArtifactDiscoverer
@ -108,13 +108,18 @@ public class DefaultArtifactDiscoverer
try
{
Model model = mavenReader.read( new FileReader( filename ) );
if ( ( pomArtifact != null ) && ( "pom".equals( model.getPackaging() ) ) )
if ( ( model != null ) && ( "pom".equals( model.getPackaging() ) ) )
{
artifacts.add( model );
}
/*if ( ( pomArtifact != null ) && ( "pom".equals( model.getPackaging() ) ) )
{
if ( convertSnapshots || !pomArtifact.isSnapshot() )
{
artifacts.add( pomArtifact );
}
}
*/
}
catch ( Exception e )
{

View File

@ -17,16 +17,13 @@ package org.apache.maven.repository.discovery;
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.DefaultArtifactHandler;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.Metadata;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
import org.apache.maven.artifact.versioning.VersionRange;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
@ -46,12 +43,17 @@ import java.util.StringTokenizer;
/**
* This class gets all the paths that contain the metadata files.
*
* @plexus.component role="org.apache.maven.repository.discovery.MetadataDiscoverer" role-hint="default" instantiation-strategy="per-lookup"
* @plexus.component role="org.apache.maven.repository.discovery.MetadataDiscoverer" role-hint="org.apache.maven.repository.discovery.DefaultMetadataDiscoverer"
*/
public class DefaultMetadataDiscoverer
extends AbstractArtifactDiscoverer
implements MetadataDiscoverer
{
/**
* @plexus.requirement
*/
private ArtifactFactory artifactFactory;
/**
* Standard patterns to include in discovery of metadata files.
*/
@ -126,20 +128,33 @@ public class DefaultMetadataDiscoverer
Iterator it = pathParts.iterator();
String tmpDir = (String) it.next();
ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
VersionRange version = VersionRange.createFromVersion( metaVersion );
Artifact artifact =
new DefaultArtifact( metaGroupId, metaArtifactId, version, "compile", "jar", "", handler );
//ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
//if( metaVersion != null && !metaVersion.equals( "" ) )
//{
// VersionRange version = VersionRange.createFromVersion( metaVersion );
//}
Artifact artifact = null;
if ( metaVersion != null && !metaVersion.equals( "" ) )
{
artifact = artifactFactory.createBuildArtifact( metaGroupId, metaArtifactId, metaVersion, "jar" );
}
// snapshotMetadata
if ( tmpDir.equals( metaVersion ) )
if ( tmpDir != null && tmpDir.equals( metaVersion ) )
{
metadata = new SnapshotArtifactRepositoryMetadata( artifact );
if ( artifact != null )
{
metadata = new SnapshotArtifactRepositoryMetadata( artifact );
}
}
else if ( tmpDir.equals( metaArtifactId ) )
else if ( tmpDir != null && tmpDir.equals( metaArtifactId ) )
{
// artifactMetadata
metadata = new ArtifactRepositoryMetadata( artifact );
if ( artifact != null )
{
metadata = new ArtifactRepositoryMetadata( artifact );
}
}
else
{
@ -161,7 +176,7 @@ public class DefaultMetadataDiscoverer
}
// groupMetadata
if ( metaGroupId.equals( groupDir ) )
if ( metaGroupId != null && metaGroupId.equals( groupDir ) )
{
metadata = new GroupRepositoryMetadata( metaGroupId );
}

View File

@ -17,10 +17,10 @@ package org.apache.maven.repository.discovery;
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.codehaus.plexus.util.StringUtils;
import java.io.File;
@ -37,13 +37,14 @@ import java.util.StringTokenizer;
*
* @author John Casey
* @author Brett Porter
* @plexus.component role="org.apache.maven.repository.discovery.ArtifactDiscoverer" role-hint="legacy" instantiation-strategy="per-lookup"
* @plexus.component role="org.apache.maven.repository.discovery.ArtifactDiscoverer" role-hint="org.apache.maven.repository.discovery.LegacyArtifactDiscoverer"
*/
public class LegacyArtifactDiscoverer
extends AbstractArtifactDiscoverer
implements ArtifactDiscoverer
{
private final static String POM = ".pom";
private final static String DELIM = "\\";
/**
@ -75,7 +76,8 @@ public class LegacyArtifactDiscoverer
return artifacts;
}
public List discoverStandalonePoms( ArtifactRepository repository, String blacklistedPatterns, boolean convertSnapshots )
public List discoverStandalonePoms( ArtifactRepository repository, String blacklistedPatterns,
boolean convertSnapshots )
{
List artifacts = new ArrayList();
@ -96,7 +98,7 @@ public class LegacyArtifactDiscoverer
try
{
Model model = mavenReader.read( new FileReader( filename ) );
if ( ( pomArtifact != null ) && ( "pom".equals(model.getPackaging()) ) )
if ( ( pomArtifact != null ) && ( "pom".equals( model.getPackaging() ) ) )
{
if ( convertSnapshots || !pomArtifact.isSnapshot() )
{
@ -104,9 +106,9 @@ public class LegacyArtifactDiscoverer
}
}
}
catch (Exception e)
catch ( Exception e )
{
System.out.println( "error reading file: " + filename );
System.out.println( "error reading file: " + filename );
e.printStackTrace();
}
}

View File

@ -21,6 +21,7 @@ import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.model.Model;
import org.codehaus.plexus.PlexusTestCase;
import java.io.File;
@ -49,12 +50,12 @@ public class DefaultArtifactDiscovererTest
{
super.setUp();
discoverer = (ArtifactDiscoverer) lookup( ArtifactDiscoverer.ROLE, "default" );
discoverer = (ArtifactDiscoverer) lookup( ArtifactDiscoverer.ROLE,
"org.apache.maven.repository.discovery.DefaultArtifactDiscoverer" );
factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
File basedir = getTestFile( "src/test/repository" );
ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
@ -361,19 +362,28 @@ public class DefaultArtifactDiscovererTest
List artifacts = discoverer.discoverStandalonePoms( repository, null, false );
assertEquals( 4, artifacts.size() );
Iterator itr = artifacts.iterator();
Artifact artifact = (Artifact) itr.next();
//Artifact artifact = (Artifact) itr.next();
Model model = (Model) itr.next();
Artifact artifact =
createArtifact( model.getGroupId(), model.getArtifactId(), model.getVersion(), model.getPackaging() );
assertEquals( "org.apache.maven", artifact.getGroupId() );
assertEquals( "B", artifact.getArtifactId() );
assertEquals( "1.0", artifact.getVersion() );
artifact = (Artifact) itr.next();
model = (Model) itr.next();
artifact =
createArtifact( model.getGroupId(), model.getArtifactId(), model.getVersion(), model.getPackaging() );
assertEquals( "org.apache.maven", artifact.getGroupId() );
assertEquals( "B", artifact.getArtifactId() );
assertEquals( "2.0", artifact.getVersion() );
artifact = (Artifact) itr.next();
model = (Model) itr.next();
artifact =
createArtifact( model.getGroupId(), model.getArtifactId(), model.getVersion(), model.getPackaging() );
assertEquals( "org.apache.maven", artifact.getGroupId() );
assertEquals( "discovery", artifact.getArtifactId() );
assertEquals( "1.0", artifact.getVersion() );
artifact = (Artifact) itr.next();
model = (Model) itr.next();
artifact =
createArtifact( model.getGroupId(), model.getArtifactId(), model.getVersion(), model.getPackaging() );
assertEquals( "org.apache.testgroup", artifact.getGroupId() );
assertEquals( "discovery", artifact.getArtifactId() );
assertEquals( "1.0", artifact.getVersion() );

View File

@ -40,7 +40,8 @@ public class DefaultMetadataDiscovererTest
{
super.setUp();
discoverer = (MetadataDiscoverer) lookup( MetadataDiscoverer.ROLE, "default" );
discoverer = (MetadataDiscoverer) lookup( MetadataDiscoverer.ROLE,
"org.apache.maven.repository.discovery.DefaultMetadataDiscoverer" );
repositoryLocation = getTestFile( "src/test/repository" );
}

View File

@ -17,16 +17,16 @@ package org.apache.maven.repository.discovery;
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.codehaus.plexus.PlexusTestCase;
import java.io.File;
import java.net.MalformedURLException;
import java.util.Iterator;
import java.util.List;
import java.net.MalformedURLException;
import java.io.File;
/**
* Test the legacy artifact discoverer.
@ -49,7 +49,8 @@ public class LegacyArtifactDiscovererTest
{
super.setUp();
discoverer = (ArtifactDiscoverer) lookup( ArtifactDiscoverer.ROLE, "legacy" );
discoverer = (ArtifactDiscoverer) lookup( ArtifactDiscoverer.ROLE,
"org.apache.maven.repository.discovery.LegacyArtifactDiscoverer" );
factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );