mirror of https://github.com/apache/archiva.git
[MRM-118] remove code that manually constructs repository paths
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@412631 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9db3258834
commit
2ace38a72f
|
@ -24,24 +24,25 @@ import org.apache.maven.artifact.Artifact;
|
||||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||||
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
|
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
|
||||||
import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
|
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.RepositoryMetadata;
|
||||||
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
|
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
|
||||||
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
|
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
|
||||||
|
import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||||
import org.apache.maven.repository.indexing.query.Query;
|
import org.apache.maven.repository.indexing.query.Query;
|
||||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||||
|
import org.codehaus.plexus.util.IOUtil;
|
||||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
@ -113,11 +114,6 @@ public class DefaultRepositoryIndexSearcher
|
||||||
{
|
{
|
||||||
throw new RepositoryIndexSearchException( "Unable to search index: " + e.getMessage(), e );
|
throw new RepositoryIndexSearchException( "Unable to search index: " + e.getMessage(), e );
|
||||||
}
|
}
|
||||||
catch ( XmlPullParserException xe )
|
|
||||||
{
|
|
||||||
throw new RepositoryIndexSearchException( "Unable to parse metadata file: " + xe.getMessage(), xe );
|
|
||||||
}
|
|
||||||
|
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -151,10 +147,9 @@ public class DefaultRepositoryIndexSearcher
|
||||||
*
|
*
|
||||||
* @param hits the search result set
|
* @param hits the search result set
|
||||||
* @return List
|
* @return List
|
||||||
* @throws IOException
|
|
||||||
*/
|
*/
|
||||||
private List buildList( Hits hits )
|
private List buildList( Hits hits )
|
||||||
throws MalformedURLException, IOException, XmlPullParserException
|
throws RepositoryIndexSearchException, IOException
|
||||||
{
|
{
|
||||||
for ( int i = 0; i < hits.length(); i++ )
|
for ( int i = 0; i < hits.length(); i++ )
|
||||||
{
|
{
|
||||||
|
@ -172,16 +167,16 @@ public class DefaultRepositoryIndexSearcher
|
||||||
* @return Object
|
* @return Object
|
||||||
*/
|
*/
|
||||||
protected RepositoryIndexSearchHit createSearchedObjectFromIndexDocument( Document doc )
|
protected RepositoryIndexSearchHit createSearchedObjectFromIndexDocument( Document doc )
|
||||||
throws MalformedURLException, IOException, XmlPullParserException
|
throws RepositoryIndexSearchException
|
||||||
{
|
{
|
||||||
RepositoryIndexSearchHit searchHit = null;
|
RepositoryIndexSearchHit searchHit = null;
|
||||||
|
|
||||||
// the document is of type artifact
|
// the document is of type artifact
|
||||||
|
String groupId = doc.get( RepositoryIndex.FLD_GROUPID );
|
||||||
|
String artifactId = doc.get( RepositoryIndex.FLD_ARTIFACTID );
|
||||||
|
String version = doc.get( RepositoryIndex.FLD_VERSION );
|
||||||
if ( doc.get( RepositoryIndex.FLD_DOCTYPE ).equals( RepositoryIndex.ARTIFACT ) )
|
if ( doc.get( RepositoryIndex.FLD_DOCTYPE ).equals( RepositoryIndex.ARTIFACT ) )
|
||||||
{
|
{
|
||||||
String groupId = doc.get( RepositoryIndex.FLD_GROUPID );
|
|
||||||
String artifactId = doc.get( RepositoryIndex.FLD_ARTIFACTID );
|
|
||||||
String version = doc.get( RepositoryIndex.FLD_VERSION );
|
|
||||||
String packaging = doc.get( RepositoryIndex.FLD_PACKAGING );
|
String packaging = doc.get( RepositoryIndex.FLD_PACKAGING );
|
||||||
Artifact artifact = factory.createBuildArtifact( groupId, artifactId, version, packaging );
|
Artifact artifact = factory.createBuildArtifact( groupId, artifactId, version, packaging );
|
||||||
|
|
||||||
|
@ -203,15 +198,10 @@ public class DefaultRepositoryIndexSearcher
|
||||||
// the document is of type model
|
// the document is of type model
|
||||||
else if ( doc.get( RepositoryIndex.FLD_DOCTYPE ).equals( RepositoryIndex.POM ) )
|
else if ( doc.get( RepositoryIndex.FLD_DOCTYPE ).equals( RepositoryIndex.POM ) )
|
||||||
{
|
{
|
||||||
InputStream is = new FileInputStream( new File( index.getRepository().getBasedir() +
|
Artifact pomArtifact = factory.createProjectArtifact( groupId, artifactId, version );
|
||||||
doc.get( RepositoryIndex.FLD_GROUPID ).replace( '.', '/' ) + "/" +
|
|
||||||
doc.get( RepositoryIndex.FLD_ARTIFACTID ) + "/" + doc.get( RepositoryIndex.FLD_VERSION ) + "/" +
|
|
||||||
doc.get( RepositoryIndex.FLD_ARTIFACTID ) + "-" + doc.get( RepositoryIndex.FLD_VERSION ) + ".pom" ) );
|
|
||||||
MavenXpp3Reader reader = new MavenXpp3Reader();
|
|
||||||
|
|
||||||
searchHit = new RepositoryIndexSearchHit( false, false, true );
|
searchHit = new RepositoryIndexSearchHit( false, false, true );
|
||||||
searchHit.setObject( reader.read( new InputStreamReader( is ) ) );
|
searchHit.setObject( readPom( pomArtifact ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
// the document is of type metadata
|
// the document is of type metadata
|
||||||
else if ( doc.get( RepositoryIndex.FLD_DOCTYPE ).equals( RepositoryIndex.METADATA ) )
|
else if ( doc.get( RepositoryIndex.FLD_DOCTYPE ).equals( RepositoryIndex.METADATA ) )
|
||||||
|
@ -224,28 +214,27 @@ public class DefaultRepositoryIndexSearcher
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.reverse( pathParts );
|
Collections.reverse( pathParts );
|
||||||
Iterator it = pathParts.iterator();
|
String tmpDir = (String) pathParts.get( 1 );
|
||||||
String metadataFile = (String) it.next();
|
|
||||||
String tmpDir = (String) it.next();
|
|
||||||
|
|
||||||
String metadataType;
|
RepositoryMetadata repoMetadata;
|
||||||
if ( tmpDir.equals( doc.get( RepositoryIndex.FLD_VERSION ) ) )
|
|
||||||
|
if ( tmpDir.equals( version ) )
|
||||||
{
|
{
|
||||||
metadataType = MetadataRepositoryIndex.SNAPSHOT_METADATA;
|
repoMetadata = new SnapshotArtifactRepositoryMetadata(
|
||||||
|
factory.createBuildArtifact( groupId, artifactId, version, "jar" ) );
|
||||||
}
|
}
|
||||||
else if ( tmpDir.equals( doc.get( RepositoryIndex.FLD_ARTIFACTID ) ) )
|
else if ( tmpDir.equals( artifactId ) )
|
||||||
{
|
{
|
||||||
metadataType = MetadataRepositoryIndex.ARTIFACT_METADATA;
|
repoMetadata = new ArtifactRepositoryMetadata(
|
||||||
|
factory.createBuildArtifact( groupId, artifactId, version, "jar" ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
metadataType = MetadataRepositoryIndex.GROUP_METADATA;
|
repoMetadata = new GroupRepositoryMetadata( groupId );
|
||||||
}
|
}
|
||||||
|
|
||||||
RepositoryMetadata repoMetadata = getMetadata( doc.get( RepositoryIndex.FLD_GROUPID ),
|
repoMetadata.setMetadata( readMetadata( repoMetadata ) );
|
||||||
doc.get( RepositoryIndex.FLD_ARTIFACTID ),
|
|
||||||
doc.get( RepositoryIndex.FLD_VERSION ), metadataFile,
|
|
||||||
metadataType );
|
|
||||||
searchHit = new RepositoryIndexSearchHit( false, true, false );
|
searchHit = new RepositoryIndexSearchHit( false, true, false );
|
||||||
searchHit.setObject( repoMetadata );
|
searchHit.setObject( repoMetadata );
|
||||||
}
|
}
|
||||||
|
@ -256,56 +245,74 @@ public class DefaultRepositoryIndexSearcher
|
||||||
/**
|
/**
|
||||||
* Create RepositoryMetadata object.
|
* Create RepositoryMetadata object.
|
||||||
*
|
*
|
||||||
* @param groupId the groupId to be set
|
|
||||||
* @param artifactId the artifactId to be set
|
|
||||||
* @param version the version to be set
|
|
||||||
* @param filename the name of the metadata file
|
|
||||||
* @param metadataType the type of RepositoryMetadata object to be created (GROUP, ARTIFACT or SNAPSHOT)
|
|
||||||
* @return RepositoryMetadata
|
* @return RepositoryMetadata
|
||||||
* @throws IOException
|
|
||||||
* @throws XmlPullParserException
|
|
||||||
*/
|
*/
|
||||||
private RepositoryMetadata getMetadata( String groupId, String artifactId, String version, String filename,
|
private Metadata readMetadata( RepositoryMetadata repoMetadata )
|
||||||
String metadataType )
|
throws RepositoryIndexSearchException
|
||||||
throws IOException, XmlPullParserException
|
|
||||||
{
|
{
|
||||||
RepositoryMetadata repoMetadata = null;
|
File file = new File( index.getRepository().getBasedir(),
|
||||||
|
index.getRepository().pathOfRemoteRepositoryMetadata( repoMetadata ) );
|
||||||
|
|
||||||
// TODO! file handles left open
|
|
||||||
InputStream is;
|
|
||||||
MetadataXpp3Reader metadataReader = new MetadataXpp3Reader();
|
MetadataXpp3Reader metadataReader = new MetadataXpp3Reader();
|
||||||
|
|
||||||
//group metadata
|
FileReader reader = null;
|
||||||
if ( metadataType.equals( MetadataRepositoryIndex.GROUP_METADATA ) )
|
try
|
||||||
{
|
{
|
||||||
// TODO! use pathOfMetadata
|
reader = new FileReader( file );
|
||||||
is = new FileInputStream(
|
return metadataReader.read( reader );
|
||||||
new File( index.getRepository().getBasedir() + groupId.replace( '.', '/' ) + "/" + filename ) );
|
|
||||||
repoMetadata = new GroupRepositoryMetadata( groupId );
|
|
||||||
repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) );
|
|
||||||
}
|
}
|
||||||
//artifact metadata
|
catch ( FileNotFoundException e )
|
||||||
else if ( metadataType.equals( MetadataRepositoryIndex.ARTIFACT_METADATA ) )
|
|
||||||
{
|
{
|
||||||
// TODO! use pathOfMetadata
|
throw new RepositoryIndexSearchException( "Unable to find metadata file: " + e.getMessage(), e );
|
||||||
is = new FileInputStream( new File( index.getRepository().getBasedir() + groupId.replace( '.', '/' ) + "/" +
|
|
||||||
artifactId + "/" + filename ) );
|
|
||||||
repoMetadata =
|
|
||||||
new ArtifactRepositoryMetadata( factory.createBuildArtifact( groupId, artifactId, version, "jar" ) );
|
|
||||||
repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) );
|
|
||||||
}
|
}
|
||||||
//snapshot/version metadata
|
catch ( IOException e )
|
||||||
else if ( metadataType.equals( MetadataRepositoryIndex.SNAPSHOT_METADATA ) )
|
|
||||||
{
|
{
|
||||||
// TODO! use pathOfMetadata
|
throw new RepositoryIndexSearchException( "Unable to read metadata file: " + e.getMessage(), e );
|
||||||
is = new FileInputStream( new File( index.getRepository().getBasedir() + groupId.replace( '.', '/' ) + "/" +
|
|
||||||
artifactId + "/" + version + "/" + filename ) );
|
|
||||||
repoMetadata = new SnapshotArtifactRepositoryMetadata(
|
|
||||||
factory.createBuildArtifact( groupId, artifactId, version, "jar" ) );
|
|
||||||
repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) );
|
|
||||||
}
|
}
|
||||||
|
catch ( XmlPullParserException xe )
|
||||||
|
{
|
||||||
|
throw new RepositoryIndexSearchException( "Unable to parse metadata file: " + xe.getMessage(), xe );
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IOUtil.close( reader );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return repoMetadata;
|
/**
|
||||||
|
* Create RepositoryMetadata object.
|
||||||
|
*
|
||||||
|
* @return RepositoryMetadata
|
||||||
|
*/
|
||||||
|
private Model readPom( Artifact pomArtifact )
|
||||||
|
throws RepositoryIndexSearchException
|
||||||
|
{
|
||||||
|
File file = new File( index.getRepository().getBasedir(), index.getRepository().pathOf( pomArtifact ) );
|
||||||
|
|
||||||
|
MavenXpp3Reader r = new MavenXpp3Reader();
|
||||||
|
|
||||||
|
FileReader reader = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
reader = new FileReader( file );
|
||||||
|
return r.read( reader );
|
||||||
|
}
|
||||||
|
catch ( FileNotFoundException e )
|
||||||
|
{
|
||||||
|
throw new RepositoryIndexSearchException( "Unable to find requested POM: " + e.getMessage(), e );
|
||||||
|
}
|
||||||
|
catch ( IOException e )
|
||||||
|
{
|
||||||
|
throw new RepositoryIndexSearchException( "Unable to read POM: " + e.getMessage(), e );
|
||||||
|
}
|
||||||
|
catch ( XmlPullParserException xe )
|
||||||
|
{
|
||||||
|
throw new RepositoryIndexSearchException( "Unable to parse POM: " + xe.getMessage(), xe );
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IOUtil.close( reader );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,12 +34,6 @@ import java.util.List;
|
||||||
public class MetadataRepositoryIndex
|
public class MetadataRepositoryIndex
|
||||||
extends AbstractRepositoryIndex
|
extends AbstractRepositoryIndex
|
||||||
{
|
{
|
||||||
protected static final String GROUP_METADATA = "GROUP_METADATA";
|
|
||||||
|
|
||||||
protected static final String ARTIFACT_METADATA = "ARTIFACT_METADATA";
|
|
||||||
|
|
||||||
protected static final String SNAPSHOT_METADATA = "SNAPSHOT_METADATA";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Constructor
|
* Class Constructor
|
||||||
*
|
*
|
||||||
|
@ -86,32 +80,9 @@ public class MetadataRepositoryIndex
|
||||||
// artifactId, version based on its location
|
// artifactId, version based on its location
|
||||||
Document doc = new Document();
|
Document doc = new Document();
|
||||||
doc.add( Field.Keyword( FLD_ID, (String) repoMetadata.getKey() ) );
|
doc.add( Field.Keyword( FLD_ID, (String) repoMetadata.getKey() ) );
|
||||||
String path = "";
|
|
||||||
Metadata metadata = repoMetadata.getMetadata();
|
Metadata metadata = repoMetadata.getMetadata();
|
||||||
|
|
||||||
if ( repoMetadata.storedInGroupDirectory() && !repoMetadata.storedInArtifactVersionDirectory() )
|
doc.add( Field.Text( FLD_NAME, repository.pathOfRemoteRepositoryMetadata( repoMetadata ) ) );
|
||||||
{
|
|
||||||
path = repoMetadata.getGroupId() + "/";
|
|
||||||
}
|
|
||||||
else if ( !repoMetadata.storedInGroupDirectory() && !repoMetadata.storedInArtifactVersionDirectory() )
|
|
||||||
{
|
|
||||||
path = repoMetadata.getGroupId() + "/" + repoMetadata.getArtifactId() + "/";
|
|
||||||
}
|
|
||||||
else if ( !repoMetadata.storedInGroupDirectory() && repoMetadata.storedInArtifactVersionDirectory() )
|
|
||||||
{
|
|
||||||
path = repoMetadata.getGroupId() + "/" + repoMetadata.getArtifactId() + "/" +
|
|
||||||
repoMetadata.getBaseVersion() + "/";
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !"".equals( repoMetadata.getRemoteFilename() ) && repoMetadata.getRemoteFilename() != null )
|
|
||||||
{
|
|
||||||
path = path + repoMetadata.getRemoteFilename();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
path = path + repoMetadata.getLocalFilename( repository );
|
|
||||||
}
|
|
||||||
doc.add( Field.Text( FLD_NAME, path ) );
|
|
||||||
|
|
||||||
Versioning versioning = metadata.getVersioning();
|
Versioning versioning = metadata.getVersioning();
|
||||||
if ( versioning != null )
|
if ( versioning != null )
|
||||||
|
|
|
@ -34,11 +34,13 @@ import org.apache.maven.repository.indexing.query.RangeQuery;
|
||||||
import org.apache.maven.repository.indexing.query.SinglePhraseQuery;
|
import org.apache.maven.repository.indexing.query.SinglePhraseQuery;
|
||||||
import org.codehaus.plexus.PlexusTestCase;
|
import org.codehaus.plexus.PlexusTestCase;
|
||||||
import org.codehaus.plexus.util.FileUtils;
|
import org.codehaus.plexus.util.FileUtils;
|
||||||
|
import org.codehaus.plexus.util.IOUtil;
|
||||||
|
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.FileReader;
|
||||||
import java.net.URL;
|
import java.io.IOException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -98,25 +100,27 @@ public class MetadataRepositoryIndexingTest
|
||||||
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );
|
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );
|
||||||
MetadataRepositoryIndex indexer = factory.createMetadataRepositoryIndex( indexPath, repository );
|
MetadataRepositoryIndex indexer = factory.createMetadataRepositoryIndex( indexPath, repository );
|
||||||
|
|
||||||
RepositoryMetadata repoMetadata =
|
RepositoryMetadata repoMetadata = new GroupRepositoryMetadata( "org.apache.maven" );
|
||||||
getMetadata( "org.apache.maven", null, null, "maven-metadata.xml", MetadataRepositoryIndex.GROUP_METADATA );
|
repoMetadata.setMetadata( readMetadata( repoMetadata ) );
|
||||||
indexer.index( repoMetadata );
|
indexer.index( repoMetadata );
|
||||||
indexer.optimize();
|
indexer.optimize();
|
||||||
indexer.close();
|
indexer.close();
|
||||||
|
|
||||||
repoMetadata = getMetadata( "org.apache.maven", "maven-artifact", "2.0.1", "maven-metadata.xml",
|
repoMetadata = new ArtifactRepositoryMetadata( getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" ) );
|
||||||
MetadataRepositoryIndex.ARTIFACT_METADATA );
|
repoMetadata.setMetadata( readMetadata( repoMetadata ) );
|
||||||
indexer.index( repoMetadata );
|
indexer.index( repoMetadata );
|
||||||
indexer.optimize();
|
indexer.optimize();
|
||||||
indexer.close();
|
indexer.close();
|
||||||
|
|
||||||
repoMetadata = getMetadata( "org.apache.maven", "maven-artifact", "2.0.1", "maven-metadata.xml",
|
repoMetadata =
|
||||||
MetadataRepositoryIndex.SNAPSHOT_METADATA );
|
new SnapshotArtifactRepositoryMetadata( getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" ) );
|
||||||
|
repoMetadata.setMetadata( readMetadata( repoMetadata ) );
|
||||||
indexer.index( repoMetadata );
|
indexer.index( repoMetadata );
|
||||||
indexer.optimize();
|
indexer.optimize();
|
||||||
indexer.close();
|
indexer.close();
|
||||||
|
|
||||||
repoMetadata = getMetadata( "test", null, null, "maven-metadata.xml", MetadataRepositoryIndex.GROUP_METADATA );
|
repoMetadata = new GroupRepositoryMetadata( "test" );
|
||||||
|
repoMetadata.setMetadata( readMetadata( repoMetadata ) );
|
||||||
indexer.index( repoMetadata );
|
indexer.index( repoMetadata );
|
||||||
indexer.optimize();
|
indexer.optimize();
|
||||||
indexer.close();
|
indexer.close();
|
||||||
|
@ -254,8 +258,8 @@ public class MetadataRepositoryIndexingTest
|
||||||
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );
|
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );
|
||||||
MetadataRepositoryIndex indexer = factory.createMetadataRepositoryIndex( indexPath, repository );
|
MetadataRepositoryIndex indexer = factory.createMetadataRepositoryIndex( indexPath, repository );
|
||||||
|
|
||||||
RepositoryMetadata repoMetadata =
|
RepositoryMetadata repoMetadata = new GroupRepositoryMetadata( "org.apache.maven" );
|
||||||
getMetadata( "org.apache.maven", null, null, "maven-metadata.xml", MetadataRepositoryIndex.GROUP_METADATA );
|
repoMetadata.setMetadata( readMetadata( repoMetadata ) );
|
||||||
indexer.deleteDocument( RepositoryIndex.FLD_ID, (String) repoMetadata.getKey() );
|
indexer.deleteDocument( RepositoryIndex.FLD_ID, (String) repoMetadata.getKey() );
|
||||||
|
|
||||||
RepositoryIndexSearcher repoSearcher = factory.createDefaultRepositoryIndexSearcher( indexer );
|
RepositoryIndexSearcher repoSearcher = factory.createDefaultRepositoryIndexSearcher( indexer );
|
||||||
|
@ -264,56 +268,6 @@ public class MetadataRepositoryIndexingTest
|
||||||
assertEquals( 0, metadataList.size() );
|
assertEquals( 0, metadataList.size() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create RepositoryMetadata object.
|
|
||||||
*
|
|
||||||
* @param groupId the groupId to be set
|
|
||||||
* @param artifactId the artifactId to be set
|
|
||||||
* @param version the version to be set
|
|
||||||
* @param filename the name of the metadata file
|
|
||||||
* @param metadataType the type of RepositoryMetadata object to be created (GROUP, ARTIFACT or SNAPSHOT)
|
|
||||||
* @return RepositoryMetadata
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
private RepositoryMetadata getMetadata( String groupId, String artifactId, String version, String filename,
|
|
||||||
String metadataType )
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
RepositoryMetadata repoMetadata = null;
|
|
||||||
URL url;
|
|
||||||
InputStream is;
|
|
||||||
MetadataXpp3Reader metadataReader = new MetadataXpp3Reader();
|
|
||||||
|
|
||||||
//group metadata
|
|
||||||
if ( metadataType.equals( MetadataRepositoryIndex.GROUP_METADATA ) )
|
|
||||||
{
|
|
||||||
url = new File( repository.getBasedir() + groupId.replace( '.', '/' ) + "/" + filename ).toURL();
|
|
||||||
is = url.openStream();
|
|
||||||
repoMetadata = new GroupRepositoryMetadata( groupId );
|
|
||||||
repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) );
|
|
||||||
}
|
|
||||||
//artifact metadata
|
|
||||||
else if ( metadataType.equals( MetadataRepositoryIndex.ARTIFACT_METADATA ) )
|
|
||||||
{
|
|
||||||
url = new File(
|
|
||||||
repository.getBasedir() + groupId.replace( '.', '/' ) + "/" + artifactId + "/" + filename ).toURL();
|
|
||||||
is = url.openStream();
|
|
||||||
repoMetadata = new ArtifactRepositoryMetadata( getArtifact( groupId, artifactId, version ) );
|
|
||||||
repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) );
|
|
||||||
}
|
|
||||||
//snapshot/version metadata
|
|
||||||
else if ( metadataType.equals( MetadataRepositoryIndex.SNAPSHOT_METADATA ) )
|
|
||||||
{
|
|
||||||
url = new File( repository.getBasedir() + groupId.replace( '.', '/' ) + "/" + artifactId + "/" + version +
|
|
||||||
"/" + filename ).toURL();
|
|
||||||
is = url.openStream();
|
|
||||||
repoMetadata = new SnapshotArtifactRepositoryMetadata( getArtifact( groupId, artifactId, version ) );
|
|
||||||
repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
return repoMetadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create artifact object.
|
* Create artifact object.
|
||||||
|
@ -333,4 +287,40 @@ public class MetadataRepositoryIndexingTest
|
||||||
}
|
}
|
||||||
return artifactFactory.createBuildArtifact( groupId, artifactId, version, "jar" );
|
return artifactFactory.createBuildArtifact( groupId, artifactId, version, "jar" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create RepositoryMetadata object.
|
||||||
|
*
|
||||||
|
* @return RepositoryMetadata
|
||||||
|
*/
|
||||||
|
private Metadata readMetadata( RepositoryMetadata repoMetadata )
|
||||||
|
throws RepositoryIndexSearchException
|
||||||
|
{
|
||||||
|
File file = new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( repoMetadata ) );
|
||||||
|
|
||||||
|
MetadataXpp3Reader metadataReader = new MetadataXpp3Reader();
|
||||||
|
|
||||||
|
FileReader reader = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
reader = new FileReader( file );
|
||||||
|
return metadataReader.read( reader );
|
||||||
|
}
|
||||||
|
catch ( FileNotFoundException e )
|
||||||
|
{
|
||||||
|
throw new RepositoryIndexSearchException( "Unable to find metadata file: " + e.getMessage(), e );
|
||||||
|
}
|
||||||
|
catch ( IOException e )
|
||||||
|
{
|
||||||
|
throw new RepositoryIndexSearchException( "Unable to read metadata file: " + e.getMessage(), e );
|
||||||
|
}
|
||||||
|
catch ( XmlPullParserException xe )
|
||||||
|
{
|
||||||
|
throw new RepositoryIndexSearchException( "Unable to parse metadata file: " + xe.getMessage(), xe );
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IOUtil.close( reader );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
|
||||||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
||||||
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
|
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
|
||||||
import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
|
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.RepositoryMetadata;
|
||||||
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
|
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
|
||||||
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
|
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
|
||||||
|
@ -30,12 +31,13 @@ import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||||
import org.codehaus.plexus.PlexusTestCase;
|
import org.codehaus.plexus.PlexusTestCase;
|
||||||
import org.codehaus.plexus.util.FileUtils;
|
import org.codehaus.plexus.util.FileUtils;
|
||||||
|
import org.codehaus.plexus.util.IOUtil;
|
||||||
|
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.InputStream;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -109,25 +111,27 @@ public class RepositoryIndexSearchLayerTest
|
||||||
indexer.close();
|
indexer.close();
|
||||||
|
|
||||||
MetadataRepositoryIndex metaIndexer = factory.createMetadataRepositoryIndex( indexPath, repository );
|
MetadataRepositoryIndex metaIndexer = factory.createMetadataRepositoryIndex( indexPath, repository );
|
||||||
RepositoryMetadata repoMetadata =
|
RepositoryMetadata repoMetadata = new GroupRepositoryMetadata( "org.apache.maven" );
|
||||||
getMetadata( "org.apache.maven", null, null, "maven-metadata.xml", MetadataRepositoryIndex.GROUP_METADATA );
|
repoMetadata.setMetadata( readMetadata( repoMetadata ) );
|
||||||
metaIndexer.index( repoMetadata );
|
metaIndexer.index( repoMetadata );
|
||||||
metaIndexer.optimize();
|
metaIndexer.optimize();
|
||||||
metaIndexer.close();
|
metaIndexer.close();
|
||||||
|
|
||||||
repoMetadata = getMetadata( "org.apache.maven", "maven-artifact", "2.0.1", "maven-metadata.xml",
|
repoMetadata = new ArtifactRepositoryMetadata( getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" ) );
|
||||||
MetadataRepositoryIndex.ARTIFACT_METADATA );
|
repoMetadata.setMetadata( readMetadata( repoMetadata ) );
|
||||||
metaIndexer.index( repoMetadata );
|
metaIndexer.index( repoMetadata );
|
||||||
metaIndexer.optimize();
|
metaIndexer.optimize();
|
||||||
metaIndexer.close();
|
metaIndexer.close();
|
||||||
|
|
||||||
repoMetadata = getMetadata( "org.apache.maven", "maven-artifact", "2.0.1", "maven-metadata.xml",
|
repoMetadata =
|
||||||
MetadataRepositoryIndex.SNAPSHOT_METADATA );
|
new SnapshotArtifactRepositoryMetadata( getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" ) );
|
||||||
|
repoMetadata.setMetadata( readMetadata( repoMetadata ) );
|
||||||
metaIndexer.index( repoMetadata );
|
metaIndexer.index( repoMetadata );
|
||||||
metaIndexer.optimize();
|
metaIndexer.optimize();
|
||||||
metaIndexer.close();
|
metaIndexer.close();
|
||||||
|
|
||||||
repoMetadata = getMetadata( "test", null, null, "maven-metadata.xml", MetadataRepositoryIndex.GROUP_METADATA );
|
repoMetadata = new GroupRepositoryMetadata( "test" );
|
||||||
|
repoMetadata.setMetadata( readMetadata( repoMetadata ) );
|
||||||
metaIndexer.index( repoMetadata );
|
metaIndexer.index( repoMetadata );
|
||||||
metaIndexer.optimize();
|
metaIndexer.optimize();
|
||||||
metaIndexer.close();
|
metaIndexer.close();
|
||||||
|
@ -342,56 +346,6 @@ public class RepositoryIndexSearchLayerTest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method for creating RepositoryMetadata object
|
|
||||||
*
|
|
||||||
* @param groupId the groupId to be set
|
|
||||||
* @param artifactId the artifactId to be set
|
|
||||||
* @param version the version to be set
|
|
||||||
* @param filename the name of the metadata file
|
|
||||||
* @param metadataType the type of RepositoryMetadata object to be created (GROUP, ARTIFACT or SNAPSHOT)
|
|
||||||
* @return RepositoryMetadata
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
private RepositoryMetadata getMetadata( String groupId, String artifactId, String version, String filename,
|
|
||||||
String metadataType )
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
RepositoryMetadata repoMetadata = null;
|
|
||||||
URL url;
|
|
||||||
InputStream is;
|
|
||||||
MetadataXpp3Reader metadataReader = new MetadataXpp3Reader();
|
|
||||||
|
|
||||||
//group metadata
|
|
||||||
if ( metadataType.equals( MetadataRepositoryIndex.GROUP_METADATA ) )
|
|
||||||
{
|
|
||||||
url = new File( repository.getBasedir() + groupId.replace( '.', '/' ) + "/" + filename ).toURL();
|
|
||||||
is = url.openStream();
|
|
||||||
repoMetadata = new GroupRepositoryMetadata( groupId );
|
|
||||||
repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) );
|
|
||||||
}
|
|
||||||
//artifact metadata
|
|
||||||
else if ( metadataType.equals( MetadataRepositoryIndex.ARTIFACT_METADATA ) )
|
|
||||||
{
|
|
||||||
url = new File(
|
|
||||||
repository.getBasedir() + groupId.replace( '.', '/' ) + "/" + artifactId + "/" + filename ).toURL();
|
|
||||||
is = url.openStream();
|
|
||||||
repoMetadata = new ArtifactRepositoryMetadata( getArtifact( groupId, artifactId, version ) );
|
|
||||||
repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) );
|
|
||||||
}
|
|
||||||
//snapshot/version metadata
|
|
||||||
else if ( metadataType.equals( MetadataRepositoryIndex.SNAPSHOT_METADATA ) )
|
|
||||||
{
|
|
||||||
url = new File( repository.getBasedir() + groupId.replace( '.', '/' ) + "/" + artifactId + "/" + version +
|
|
||||||
"/" + filename ).toURL();
|
|
||||||
is = url.openStream();
|
|
||||||
repoMetadata = new SnapshotArtifactRepositoryMetadata( getArtifact( groupId, artifactId, version ) );
|
|
||||||
repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
return repoMetadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method for creating Artifact object
|
* Method for creating Artifact object
|
||||||
*
|
*
|
||||||
|
@ -457,4 +411,39 @@ public class RepositoryIndexSearchLayerTest
|
||||||
return new File( path.substring( 0, path.lastIndexOf( '.' ) ) + ".pom" );
|
return new File( path.substring( 0, path.lastIndexOf( '.' ) ) + ".pom" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create RepositoryMetadata object.
|
||||||
|
*
|
||||||
|
* @return RepositoryMetadata
|
||||||
|
*/
|
||||||
|
private Metadata readMetadata( RepositoryMetadata repoMetadata )
|
||||||
|
throws RepositoryIndexSearchException
|
||||||
|
{
|
||||||
|
File file = new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( repoMetadata ) );
|
||||||
|
|
||||||
|
MetadataXpp3Reader metadataReader = new MetadataXpp3Reader();
|
||||||
|
|
||||||
|
FileReader reader = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
reader = new FileReader( file );
|
||||||
|
return metadataReader.read( reader );
|
||||||
|
}
|
||||||
|
catch ( FileNotFoundException e )
|
||||||
|
{
|
||||||
|
throw new RepositoryIndexSearchException( "Unable to find metadata file: " + e.getMessage(), e );
|
||||||
|
}
|
||||||
|
catch ( IOException e )
|
||||||
|
{
|
||||||
|
throw new RepositoryIndexSearchException( "Unable to read metadata file: " + e.getMessage(), e );
|
||||||
|
}
|
||||||
|
catch ( XmlPullParserException xe )
|
||||||
|
{
|
||||||
|
throw new RepositoryIndexSearchException( "Unable to parse metadata file: " + xe.getMessage(), xe );
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IOUtil.close( reader );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue