import org.apache.maven.artifact.factory.ArtifactFactory;\r
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;\r
import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;\r
+import org.apache.maven.artifact.repository.metadata.Metadata;\r
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;\r
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;\r
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;\r
+import org.apache.maven.model.Model;\r
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;\r
import org.apache.maven.repository.indexing.query.Query;\r
import org.codehaus.plexus.logging.AbstractLogEnabled;\r
+import org.codehaus.plexus.util.IOUtil;\r
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;\r
\r
import java.io.File;\r
-import java.io.FileInputStream;\r
+import java.io.FileNotFoundException;\r
+import java.io.FileReader;\r
import java.io.IOException;\r
-import java.io.InputStream;\r
-import java.io.InputStreamReader;\r
import java.net.MalformedURLException;\r
import java.util.ArrayList;\r
import java.util.Collections;\r
import java.util.HashMap;\r
-import java.util.Iterator;\r
import java.util.List;\r
import java.util.Map;\r
import java.util.StringTokenizer;\r
{\r
throw new RepositoryIndexSearchException( "Unable to search index: " + e.getMessage(), e );\r
}\r
- catch ( XmlPullParserException xe )\r
- {\r
- throw new RepositoryIndexSearchException( "Unable to parse metadata file: " + xe.getMessage(), xe );\r
- }\r
-\r
finally\r
{\r
try\r
*\r
* @param hits the search result set\r
* @return List\r
- * @throws IOException\r
*/\r
private List buildList( Hits hits )\r
- throws MalformedURLException, IOException, XmlPullParserException\r
+ throws RepositoryIndexSearchException, IOException\r
{\r
for ( int i = 0; i < hits.length(); i++ )\r
{\r
* @return Object\r
*/\r
protected RepositoryIndexSearchHit createSearchedObjectFromIndexDocument( Document doc )\r
- throws MalformedURLException, IOException, XmlPullParserException\r
+ throws RepositoryIndexSearchException\r
{\r
RepositoryIndexSearchHit searchHit = null;\r
\r
// the document is of type artifact\r
+ String groupId = doc.get( RepositoryIndex.FLD_GROUPID );\r
+ String artifactId = doc.get( RepositoryIndex.FLD_ARTIFACTID );\r
+ String version = doc.get( RepositoryIndex.FLD_VERSION );\r
if ( doc.get( RepositoryIndex.FLD_DOCTYPE ).equals( RepositoryIndex.ARTIFACT ) )\r
{\r
- String groupId = doc.get( RepositoryIndex.FLD_GROUPID );\r
- String artifactId = doc.get( RepositoryIndex.FLD_ARTIFACTID );\r
- String version = doc.get( RepositoryIndex.FLD_VERSION );\r
String packaging = doc.get( RepositoryIndex.FLD_PACKAGING );\r
Artifact artifact = factory.createBuildArtifact( groupId, artifactId, version, packaging );\r
\r
// the document is of type model\r
else if ( doc.get( RepositoryIndex.FLD_DOCTYPE ).equals( RepositoryIndex.POM ) )\r
{\r
- InputStream is = new FileInputStream( new File( index.getRepository().getBasedir() +\r
- doc.get( RepositoryIndex.FLD_GROUPID ).replace( '.', '/' ) + "/" +\r
- doc.get( RepositoryIndex.FLD_ARTIFACTID ) + "/" + doc.get( RepositoryIndex.FLD_VERSION ) + "/" +\r
- doc.get( RepositoryIndex.FLD_ARTIFACTID ) + "-" + doc.get( RepositoryIndex.FLD_VERSION ) + ".pom" ) );\r
- MavenXpp3Reader reader = new MavenXpp3Reader();\r
+ Artifact pomArtifact = factory.createProjectArtifact( groupId, artifactId, version );\r
\r
searchHit = new RepositoryIndexSearchHit( false, false, true );\r
- searchHit.setObject( reader.read( new InputStreamReader( is ) ) );\r
-\r
+ searchHit.setObject( readPom( pomArtifact ) );\r
}\r
// the document is of type metadata\r
else if ( doc.get( RepositoryIndex.FLD_DOCTYPE ).equals( RepositoryIndex.METADATA ) )\r
}\r
\r
Collections.reverse( pathParts );\r
- Iterator it = pathParts.iterator();\r
- String metadataFile = (String) it.next();\r
- String tmpDir = (String) it.next();\r
+ String tmpDir = (String) pathParts.get( 1 );\r
+\r
+ RepositoryMetadata repoMetadata;\r
\r
- String metadataType;\r
- if ( tmpDir.equals( doc.get( RepositoryIndex.FLD_VERSION ) ) )\r
+ if ( tmpDir.equals( version ) )\r
{\r
- metadataType = MetadataRepositoryIndex.SNAPSHOT_METADATA;\r
+ repoMetadata = new SnapshotArtifactRepositoryMetadata(\r
+ factory.createBuildArtifact( groupId, artifactId, version, "jar" ) );\r
}\r
- else if ( tmpDir.equals( doc.get( RepositoryIndex.FLD_ARTIFACTID ) ) )\r
+ else if ( tmpDir.equals( artifactId ) )\r
{\r
- metadataType = MetadataRepositoryIndex.ARTIFACT_METADATA;\r
+ repoMetadata = new ArtifactRepositoryMetadata(\r
+ factory.createBuildArtifact( groupId, artifactId, version, "jar" ) );\r
}\r
else\r
{\r
- metadataType = MetadataRepositoryIndex.GROUP_METADATA;\r
+ repoMetadata = new GroupRepositoryMetadata( groupId );\r
}\r
\r
- RepositoryMetadata repoMetadata = getMetadata( doc.get( RepositoryIndex.FLD_GROUPID ),\r
- doc.get( RepositoryIndex.FLD_ARTIFACTID ),\r
- doc.get( RepositoryIndex.FLD_VERSION ), metadataFile,\r
- metadataType );\r
+ repoMetadata.setMetadata( readMetadata( repoMetadata ) );\r
+\r
searchHit = new RepositoryIndexSearchHit( false, true, false );\r
searchHit.setObject( repoMetadata );\r
}\r
/**\r
* Create RepositoryMetadata object.\r
*\r
- * @param groupId the groupId to be set\r
- * @param artifactId the artifactId to be set\r
- * @param version the version to be set\r
- * @param filename the name of the metadata file\r
- * @param metadataType the type of RepositoryMetadata object to be created (GROUP, ARTIFACT or SNAPSHOT)\r
* @return RepositoryMetadata\r
- * @throws IOException\r
- * @throws XmlPullParserException\r
*/\r
- private RepositoryMetadata getMetadata( String groupId, String artifactId, String version, String filename,\r
- String metadataType )\r
- throws IOException, XmlPullParserException\r
+ private Metadata readMetadata( RepositoryMetadata repoMetadata )\r
+ throws RepositoryIndexSearchException\r
{\r
- RepositoryMetadata repoMetadata = null;\r
+ File file = new File( index.getRepository().getBasedir(),\r
+ index.getRepository().pathOfRemoteRepositoryMetadata( repoMetadata ) );\r
\r
- // TODO! file handles left open\r
- InputStream is;\r
MetadataXpp3Reader metadataReader = new MetadataXpp3Reader();\r
\r
- //group metadata\r
- if ( metadataType.equals( MetadataRepositoryIndex.GROUP_METADATA ) )\r
+ FileReader reader = null;\r
+ try\r
{\r
- // TODO! use pathOfMetadata\r
- is = new FileInputStream(\r
- new File( index.getRepository().getBasedir() + groupId.replace( '.', '/' ) + "/" + filename ) );\r
- repoMetadata = new GroupRepositoryMetadata( groupId );\r
- repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) );\r
+ reader = new FileReader( file );\r
+ return metadataReader.read( reader );\r
}\r
- //artifact metadata\r
- else if ( metadataType.equals( MetadataRepositoryIndex.ARTIFACT_METADATA ) )\r
+ catch ( FileNotFoundException e )\r
{\r
- // TODO! use pathOfMetadata\r
- is = new FileInputStream( new File( index.getRepository().getBasedir() + groupId.replace( '.', '/' ) + "/" +\r
- artifactId + "/" + filename ) );\r
- repoMetadata =\r
- new ArtifactRepositoryMetadata( factory.createBuildArtifact( groupId, artifactId, version, "jar" ) );\r
- repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) );\r
+ throw new RepositoryIndexSearchException( "Unable to find metadata file: " + e.getMessage(), e );\r
}\r
- //snapshot/version metadata\r
- else if ( metadataType.equals( MetadataRepositoryIndex.SNAPSHOT_METADATA ) )\r
+ catch ( IOException e )\r
+ {\r
+ throw new RepositoryIndexSearchException( "Unable to read metadata file: " + e.getMessage(), e );\r
+ }\r
+ catch ( XmlPullParserException xe )\r
{\r
- // TODO! use pathOfMetadata\r
- is = new FileInputStream( new File( index.getRepository().getBasedir() + groupId.replace( '.', '/' ) + "/" +\r
- artifactId + "/" + version + "/" + filename ) );\r
- repoMetadata = new SnapshotArtifactRepositoryMetadata(\r
- factory.createBuildArtifact( groupId, artifactId, version, "jar" ) );\r
- repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) );\r
+ throw new RepositoryIndexSearchException( "Unable to parse metadata file: " + xe.getMessage(), xe );\r
}\r
+ finally\r
+ {\r
+ IOUtil.close( reader );\r
+ }\r
+ }\r
\r
- return repoMetadata;\r
+ /**\r
+ * Create RepositoryMetadata object.\r
+ *\r
+ * @return RepositoryMetadata\r
+ */\r
+ private Model readPom( Artifact pomArtifact )\r
+ throws RepositoryIndexSearchException\r
+ {\r
+ File file = new File( index.getRepository().getBasedir(), index.getRepository().pathOf( pomArtifact ) );\r
+\r
+ MavenXpp3Reader r = new MavenXpp3Reader();\r
+\r
+ FileReader reader = null;\r
+ try\r
+ {\r
+ reader = new FileReader( file );\r
+ return r.read( reader );\r
+ }\r
+ catch ( FileNotFoundException e )\r
+ {\r
+ throw new RepositoryIndexSearchException( "Unable to find requested POM: " + e.getMessage(), e );\r
+ }\r
+ catch ( IOException e )\r
+ {\r
+ throw new RepositoryIndexSearchException( "Unable to read POM: " + e.getMessage(), e );\r
+ }\r
+ catch ( XmlPullParserException xe )\r
+ {\r
+ throw new RepositoryIndexSearchException( "Unable to parse POM: " + xe.getMessage(), xe );\r
+ }\r
+ finally\r
+ {\r
+ IOUtil.close( reader );\r
+ }\r
}\r
\r
}\r
public class MetadataRepositoryIndex\r
extends AbstractRepositoryIndex\r
{\r
- protected static final String GROUP_METADATA = "GROUP_METADATA";\r
-\r
- protected static final String ARTIFACT_METADATA = "ARTIFACT_METADATA";\r
-\r
- protected static final String SNAPSHOT_METADATA = "SNAPSHOT_METADATA";\r
-\r
/**\r
* Class Constructor\r
*\r
// artifactId, version based on its location\r
Document doc = new Document();\r
doc.add( Field.Keyword( FLD_ID, (String) repoMetadata.getKey() ) );\r
- String path = "";\r
Metadata metadata = repoMetadata.getMetadata();\r
\r
- if ( repoMetadata.storedInGroupDirectory() && !repoMetadata.storedInArtifactVersionDirectory() )\r
- {\r
- path = repoMetadata.getGroupId() + "/";\r
- }\r
- else if ( !repoMetadata.storedInGroupDirectory() && !repoMetadata.storedInArtifactVersionDirectory() )\r
- {\r
- path = repoMetadata.getGroupId() + "/" + repoMetadata.getArtifactId() + "/";\r
- }\r
- else if ( !repoMetadata.storedInGroupDirectory() && repoMetadata.storedInArtifactVersionDirectory() )\r
- {\r
- path = repoMetadata.getGroupId() + "/" + repoMetadata.getArtifactId() + "/" +\r
- repoMetadata.getBaseVersion() + "/";\r
- }\r
-\r
- if ( !"".equals( repoMetadata.getRemoteFilename() ) && repoMetadata.getRemoteFilename() != null )\r
- {\r
- path = path + repoMetadata.getRemoteFilename();\r
- }\r
- else\r
- {\r
- path = path + repoMetadata.getLocalFilename( repository );\r
- }\r
- doc.add( Field.Text( FLD_NAME, path ) );\r
+ doc.add( Field.Text( FLD_NAME, repository.pathOfRemoteRepositoryMetadata( repoMetadata ) ) );\r
\r
Versioning versioning = metadata.getVersioning();\r
if ( versioning != null )\r
import org.apache.maven.repository.indexing.query.SinglePhraseQuery;\r
import org.codehaus.plexus.PlexusTestCase;\r
import org.codehaus.plexus.util.FileUtils;\r
+import org.codehaus.plexus.util.IOUtil;\r
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;\r
\r
import java.io.File;\r
-import java.io.InputStream;\r
-import java.io.InputStreamReader;\r
-import java.net.URL;\r
+import java.io.FileNotFoundException;\r
+import java.io.FileReader;\r
+import java.io.IOException;\r
import java.util.Iterator;\r
import java.util.List;\r
\r
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );\r
MetadataRepositoryIndex indexer = factory.createMetadataRepositoryIndex( indexPath, repository );\r
\r
- RepositoryMetadata repoMetadata =\r
- getMetadata( "org.apache.maven", null, null, "maven-metadata.xml", MetadataRepositoryIndex.GROUP_METADATA );\r
+ RepositoryMetadata repoMetadata = new GroupRepositoryMetadata( "org.apache.maven" );\r
+ repoMetadata.setMetadata( readMetadata( repoMetadata ) );\r
indexer.index( repoMetadata );\r
indexer.optimize();\r
indexer.close();\r
\r
- repoMetadata = getMetadata( "org.apache.maven", "maven-artifact", "2.0.1", "maven-metadata.xml",\r
- MetadataRepositoryIndex.ARTIFACT_METADATA );\r
+ repoMetadata = new ArtifactRepositoryMetadata( getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" ) );\r
+ repoMetadata.setMetadata( readMetadata( repoMetadata ) );\r
indexer.index( repoMetadata );\r
indexer.optimize();\r
indexer.close();\r
\r
- repoMetadata = getMetadata( "org.apache.maven", "maven-artifact", "2.0.1", "maven-metadata.xml",\r
- MetadataRepositoryIndex.SNAPSHOT_METADATA );\r
+ repoMetadata =\r
+ new SnapshotArtifactRepositoryMetadata( getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" ) );\r
+ repoMetadata.setMetadata( readMetadata( repoMetadata ) );\r
indexer.index( repoMetadata );\r
indexer.optimize();\r
indexer.close();\r
\r
- repoMetadata = getMetadata( "test", null, null, "maven-metadata.xml", MetadataRepositoryIndex.GROUP_METADATA );\r
+ repoMetadata = new GroupRepositoryMetadata( "test" );\r
+ repoMetadata.setMetadata( readMetadata( repoMetadata ) );\r
indexer.index( repoMetadata );\r
indexer.optimize();\r
indexer.close();\r
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );\r
MetadataRepositoryIndex indexer = factory.createMetadataRepositoryIndex( indexPath, repository );\r
\r
- RepositoryMetadata repoMetadata =\r
- getMetadata( "org.apache.maven", null, null, "maven-metadata.xml", MetadataRepositoryIndex.GROUP_METADATA );\r
+ RepositoryMetadata repoMetadata = new GroupRepositoryMetadata( "org.apache.maven" );\r
+ repoMetadata.setMetadata( readMetadata( repoMetadata ) );\r
indexer.deleteDocument( RepositoryIndex.FLD_ID, (String) repoMetadata.getKey() );\r
\r
RepositoryIndexSearcher repoSearcher = factory.createDefaultRepositoryIndexSearcher( indexer );\r
assertEquals( 0, metadataList.size() );\r
}\r
\r
- /**\r
- * Create RepositoryMetadata object.\r
- *\r
- * @param groupId the groupId to be set\r
- * @param artifactId the artifactId to be set\r
- * @param version the version to be set\r
- * @param filename the name of the metadata file\r
- * @param metadataType the type of RepositoryMetadata object to be created (GROUP, ARTIFACT or SNAPSHOT)\r
- * @return RepositoryMetadata\r
- * @throws Exception\r
- */\r
- private RepositoryMetadata getMetadata( String groupId, String artifactId, String version, String filename,\r
- String metadataType )\r
- throws Exception\r
- {\r
- RepositoryMetadata repoMetadata = null;\r
- URL url;\r
- InputStream is;\r
- MetadataXpp3Reader metadataReader = new MetadataXpp3Reader();\r
-\r
- //group metadata\r
- if ( metadataType.equals( MetadataRepositoryIndex.GROUP_METADATA ) )\r
- {\r
- url = new File( repository.getBasedir() + groupId.replace( '.', '/' ) + "/" + filename ).toURL();\r
- is = url.openStream();\r
- repoMetadata = new GroupRepositoryMetadata( groupId );\r
- repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) );\r
- }\r
- //artifact metadata\r
- else if ( metadataType.equals( MetadataRepositoryIndex.ARTIFACT_METADATA ) )\r
- {\r
- url = new File(\r
- repository.getBasedir() + groupId.replace( '.', '/' ) + "/" + artifactId + "/" + filename ).toURL();\r
- is = url.openStream();\r
- repoMetadata = new ArtifactRepositoryMetadata( getArtifact( groupId, artifactId, version ) );\r
- repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) );\r
- }\r
- //snapshot/version metadata\r
- else if ( metadataType.equals( MetadataRepositoryIndex.SNAPSHOT_METADATA ) )\r
- {\r
- url = new File( repository.getBasedir() + groupId.replace( '.', '/' ) + "/" + artifactId + "/" + version +\r
- "/" + filename ).toURL();\r
- is = url.openStream();\r
- repoMetadata = new SnapshotArtifactRepositoryMetadata( getArtifact( groupId, artifactId, version ) );\r
- repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) );\r
- }\r
-\r
- return repoMetadata;\r
- }\r
-\r
\r
/**\r
* Create artifact object.\r
}\r
return artifactFactory.createBuildArtifact( groupId, artifactId, version, "jar" );\r
}\r
+\r
+ /**\r
+ * Create RepositoryMetadata object.\r
+ *\r
+ * @return RepositoryMetadata\r
+ */\r
+ private Metadata readMetadata( RepositoryMetadata repoMetadata )\r
+ throws RepositoryIndexSearchException\r
+ {\r
+ File file = new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( repoMetadata ) );\r
+\r
+ MetadataXpp3Reader metadataReader = new MetadataXpp3Reader();\r
+\r
+ FileReader reader = null;\r
+ try\r
+ {\r
+ reader = new FileReader( file );\r
+ return metadataReader.read( reader );\r
+ }\r
+ catch ( FileNotFoundException e )\r
+ {\r
+ throw new RepositoryIndexSearchException( "Unable to find metadata file: " + e.getMessage(), e );\r
+ }\r
+ catch ( IOException e )\r
+ {\r
+ throw new RepositoryIndexSearchException( "Unable to read metadata file: " + e.getMessage(), e );\r
+ }\r
+ catch ( XmlPullParserException xe )\r
+ {\r
+ throw new RepositoryIndexSearchException( "Unable to parse metadata file: " + xe.getMessage(), xe );\r
+ }\r
+ finally\r
+ {\r
+ IOUtil.close( reader );\r
+ }\r
+ }\r
}\r
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;\r
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;\r
import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;\r
+import org.apache.maven.artifact.repository.metadata.Metadata;\r
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;\r
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;\r
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;\r
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;\r
import org.codehaus.plexus.PlexusTestCase;\r
import org.codehaus.plexus.util.FileUtils;\r
+import org.codehaus.plexus.util.IOUtil;\r
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;\r
\r
import java.io.File;\r
+import java.io.FileNotFoundException;\r
import java.io.FileReader;\r
-import java.io.InputStream;\r
-import java.io.InputStreamReader;\r
-import java.net.URL;\r
+import java.io.IOException;\r
import java.util.Iterator;\r
import java.util.List;\r
import java.util.Map;\r
indexer.close();\r
\r
MetadataRepositoryIndex metaIndexer = factory.createMetadataRepositoryIndex( indexPath, repository );\r
- RepositoryMetadata repoMetadata =\r
- getMetadata( "org.apache.maven", null, null, "maven-metadata.xml", MetadataRepositoryIndex.GROUP_METADATA );\r
+ RepositoryMetadata repoMetadata = new GroupRepositoryMetadata( "org.apache.maven" );\r
+ repoMetadata.setMetadata( readMetadata( repoMetadata ) );\r
metaIndexer.index( repoMetadata );\r
metaIndexer.optimize();\r
metaIndexer.close();\r
\r
- repoMetadata = getMetadata( "org.apache.maven", "maven-artifact", "2.0.1", "maven-metadata.xml",\r
- MetadataRepositoryIndex.ARTIFACT_METADATA );\r
+ repoMetadata = new ArtifactRepositoryMetadata( getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" ) );\r
+ repoMetadata.setMetadata( readMetadata( repoMetadata ) );\r
metaIndexer.index( repoMetadata );\r
metaIndexer.optimize();\r
metaIndexer.close();\r
\r
- repoMetadata = getMetadata( "org.apache.maven", "maven-artifact", "2.0.1", "maven-metadata.xml",\r
- MetadataRepositoryIndex.SNAPSHOT_METADATA );\r
+ repoMetadata =\r
+ new SnapshotArtifactRepositoryMetadata( getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" ) );\r
+ repoMetadata.setMetadata( readMetadata( repoMetadata ) );\r
metaIndexer.index( repoMetadata );\r
metaIndexer.optimize();\r
metaIndexer.close();\r
\r
- repoMetadata = getMetadata( "test", null, null, "maven-metadata.xml", MetadataRepositoryIndex.GROUP_METADATA );\r
+ repoMetadata = new GroupRepositoryMetadata( "test" );\r
+ repoMetadata.setMetadata( readMetadata( repoMetadata ) );\r
metaIndexer.index( repoMetadata );\r
metaIndexer.optimize();\r
metaIndexer.close();\r
}\r
\r
\r
- /**\r
- * Method for creating RepositoryMetadata object\r
- *\r
- * @param groupId the groupId to be set\r
- * @param artifactId the artifactId to be set\r
- * @param version the version to be set\r
- * @param filename the name of the metadata file\r
- * @param metadataType the type of RepositoryMetadata object to be created (GROUP, ARTIFACT or SNAPSHOT)\r
- * @return RepositoryMetadata\r
- * @throws Exception\r
- */\r
- private RepositoryMetadata getMetadata( String groupId, String artifactId, String version, String filename,\r
- String metadataType )\r
- throws Exception\r
- {\r
- RepositoryMetadata repoMetadata = null;\r
- URL url;\r
- InputStream is;\r
- MetadataXpp3Reader metadataReader = new MetadataXpp3Reader();\r
-\r
- //group metadata\r
- if ( metadataType.equals( MetadataRepositoryIndex.GROUP_METADATA ) )\r
- {\r
- url = new File( repository.getBasedir() + groupId.replace( '.', '/' ) + "/" + filename ).toURL();\r
- is = url.openStream();\r
- repoMetadata = new GroupRepositoryMetadata( groupId );\r
- repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) );\r
- }\r
- //artifact metadata\r
- else if ( metadataType.equals( MetadataRepositoryIndex.ARTIFACT_METADATA ) )\r
- {\r
- url = new File(\r
- repository.getBasedir() + groupId.replace( '.', '/' ) + "/" + artifactId + "/" + filename ).toURL();\r
- is = url.openStream();\r
- repoMetadata = new ArtifactRepositoryMetadata( getArtifact( groupId, artifactId, version ) );\r
- repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) );\r
- }\r
- //snapshot/version metadata\r
- else if ( metadataType.equals( MetadataRepositoryIndex.SNAPSHOT_METADATA ) )\r
- {\r
- url = new File( repository.getBasedir() + groupId.replace( '.', '/' ) + "/" + artifactId + "/" + version +\r
- "/" + filename ).toURL();\r
- is = url.openStream();\r
- repoMetadata = new SnapshotArtifactRepositoryMetadata( getArtifact( groupId, artifactId, version ) );\r
- repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) );\r
- }\r
-\r
- return repoMetadata;\r
- }\r
-\r
/**\r
* Method for creating Artifact object\r
*\r
return new File( path.substring( 0, path.lastIndexOf( '.' ) ) + ".pom" );\r
}\r
\r
+ /**\r
+ * Create RepositoryMetadata object.\r
+ *\r
+ * @return RepositoryMetadata\r
+ */\r
+ private Metadata readMetadata( RepositoryMetadata repoMetadata )\r
+ throws RepositoryIndexSearchException\r
+ {\r
+ File file = new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( repoMetadata ) );\r
+\r
+ MetadataXpp3Reader metadataReader = new MetadataXpp3Reader();\r
+\r
+ FileReader reader = null;\r
+ try\r
+ {\r
+ reader = new FileReader( file );\r
+ return metadataReader.read( reader );\r
+ }\r
+ catch ( FileNotFoundException e )\r
+ {\r
+ throw new RepositoryIndexSearchException( "Unable to find metadata file: " + e.getMessage(), e );\r
+ }\r
+ catch ( IOException e )\r
+ {\r
+ throw new RepositoryIndexSearchException( "Unable to read metadata file: " + e.getMessage(), e );\r
+ }\r
+ catch ( XmlPullParserException xe )\r
+ {\r
+ throw new RepositoryIndexSearchException( "Unable to parse metadata file: " + xe.getMessage(), xe );\r
+ }\r
+ finally\r
+ {\r
+ IOUtil.close( reader );\r
+ }\r
+ }\r
}\r