[MRM-1282] store more of the content in the file metadata repository

git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@884177 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2009-11-25 16:24:55 +00:00
parent 9c2b960aea
commit 9062810001
4 changed files with 177 additions and 10 deletions

View File

@ -1,5 +1,7 @@
package org.apache.archiva.metadata.model; package org.apache.archiva.metadata.model;
import java.util.Map;
/* /*
* Licensed to the Apache Software Foundation (ASF) under one * Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file * or more contributor license agreements. See the NOTICE file
@ -22,4 +24,6 @@ package org.apache.archiva.metadata.model;
public interface ProjectVersionFacet public interface ProjectVersionFacet
{ {
String getFacetId(); String getFacetId();
Map<String, String> toProperties();
} }

View File

@ -20,6 +20,7 @@ package org.apache.archiva.metadata.model;
*/ */
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -44,7 +45,7 @@ public class ProjectVersionMetadata
private List<License> licenses; private List<License> licenses;
private Map<String, ProjectVersionFacet> facets; private Map<String, ProjectVersionFacet> facets = new HashMap<String, ProjectVersionFacet>();;
public String getId() public String getId()
{ {
@ -147,15 +148,21 @@ public class ProjectVersionMetadata
public void addFacet( ProjectVersionFacet mavenProjectFacet ) public void addFacet( ProjectVersionFacet mavenProjectFacet )
{ {
if ( this.facets == null )
{
this.facets = new HashMap<String, ProjectVersionFacet>();
}
this.facets.put( mavenProjectFacet.getFacetId(), mavenProjectFacet ); this.facets.put( mavenProjectFacet.getFacetId(), mavenProjectFacet );
} }
public ProjectVersionFacet getFacet( String facetId ) public ProjectVersionFacet getFacet( String facetId )
{ {
return this.facets != null ? this.facets.get( facetId ) : null; return this.facets.get( facetId );
}
public Collection<ProjectVersionFacet> getAllFacets()
{
return this.facets.values();
}
public Collection<String> getAllFacetIds()
{
return this.facets.keySet();
} }
} }

View File

@ -19,6 +19,9 @@ package org.apache.archiva.metadata.repository.storage.maven2;
* under the License. * under the License.
*/ */
import java.util.HashMap;
import java.util.Map;
import org.apache.archiva.metadata.model.ProjectVersionFacet; import org.apache.archiva.metadata.model.ProjectVersionFacet;
public class MavenProjectFacet public class MavenProjectFacet
@ -78,4 +81,19 @@ public class MavenProjectFacet
{ {
return FACET_ID; return FACET_ID;
} }
public Map<String, String> toProperties()
{
Map<String, String> properties = new HashMap<String,String>();
properties.put( getFacetId() + ":groupId", groupId );
properties.put( getFacetId() + ":artifactId", artifactId );
properties.put( getFacetId() + ":packaging", packaging );
if ( parent != null )
{
properties.put( getFacetId() + ":parent.groupId", parent.getGroupId() );
properties.put( getFacetId() + ":parent.artifactId", parent.getArtifactId() );
properties.put( getFacetId() + ":parent.version", parent.getVersion() );
}
return properties;
}
} }

View File

@ -31,8 +31,14 @@ import java.util.Map;
import java.util.Properties; import java.util.Properties;
import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.CiManagement;
import org.apache.archiva.metadata.model.IssueManagement;
import org.apache.archiva.metadata.model.License;
import org.apache.archiva.metadata.model.Organization;
import org.apache.archiva.metadata.model.ProjectMetadata; import org.apache.archiva.metadata.model.ProjectMetadata;
import org.apache.archiva.metadata.model.ProjectVersionFacet;
import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.model.Scm;
import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
@ -75,6 +81,42 @@ public class FileMetadataRepository
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty( "id", versionMetadata.getId() ); properties.setProperty( "id", versionMetadata.getId() );
setProperty( properties, "name", versionMetadata.getName() );
setProperty( properties, "description", versionMetadata.getDescription() );
setProperty( properties, "url", versionMetadata.getUrl() );
if ( versionMetadata.getScm() != null )
{
setProperty( properties, "scm.connection", versionMetadata.getScm().getConnection() );
setProperty( properties, "scm.developerConnection", versionMetadata.getScm().getDeveloperConnection() );
setProperty( properties, "scm.url", versionMetadata.getScm().getUrl() );
}
if ( versionMetadata.getCiManagement() != null )
{
setProperty( properties, "ci.system", versionMetadata.getCiManagement().getSystem() );
setProperty( properties, "ci.url", versionMetadata.getCiManagement().getUrl() );
}
if ( versionMetadata.getIssueManagement() != null )
{
setProperty( properties, "issue.system", versionMetadata.getIssueManagement().getSystem() );
setProperty( properties, "issue.url", versionMetadata.getIssueManagement().getUrl() );
}
if ( versionMetadata.getOrganization() != null )
{
setProperty( properties, "org.name", versionMetadata.getOrganization().getName() );
setProperty( properties, "org.url", versionMetadata.getOrganization().getUrl() );
}
int i = 0;
for ( License license : versionMetadata.getLicenses() )
{
setProperty( properties, "license." + i + ".name", license.getName() );
setProperty( properties, "license." + i + ".url", license.getUrl() );
i++;
}
properties.setProperty( "facetIds", join( versionMetadata.getAllFacetIds() ) );
for ( ProjectVersionFacet facet : versionMetadata.getAllFacets() )
{
properties.putAll( facet.toProperties() );
}
try try
{ {
@ -87,6 +129,25 @@ public class FileMetadataRepository
} }
} }
private String join( Collection<String> ids )
{
StringBuilder s = new StringBuilder();
for ( String id : ids )
{
s.append( id );
s.append( "," );
}
return s.substring( 0, s.length() - 1 );
}
private void setProperty( Properties properties, String name, String value )
{
if ( value != null )
{
properties.setProperty( name, value );
}
}
public void updateArtifact( String repoId, String namespace, String projectId, String projectVersion, public void updateArtifact( String repoId, String namespace, String projectId, String projectVersion,
ArtifactMetadata artifact ) ArtifactMetadata artifact )
{ {
@ -115,8 +176,8 @@ public class FileMetadataRepository
FileInputStream in = null; FileInputStream in = null;
try try
{ {
in = new FileInputStream( new File( directory, "metadata.xml" ) ); in = new FileInputStream( new File( directory, "metadata.properties" ) );
properties.loadFromXML( in ); properties.load( in );
} }
catch ( FileNotFoundException e ) catch ( FileNotFoundException e )
{ {
@ -158,6 +219,83 @@ public class FileMetadataRepository
{ {
versionMetadata = new ProjectVersionMetadata(); versionMetadata = new ProjectVersionMetadata();
versionMetadata.setId( id ); versionMetadata.setId( id );
versionMetadata.setName( properties.getProperty( "name" ) );
versionMetadata.setDescription( properties.getProperty( "description" ) );
versionMetadata.setUrl( properties.getProperty( "url" ) );
String scmConnection = properties.getProperty( "scm.connection" );
String scmDeveloperConnection = properties.getProperty( "scm.developerConnection" );
String scmUrl = properties.getProperty( "scm.url" );
if ( scmConnection != null || scmDeveloperConnection != null || scmUrl != null )
{
Scm scm = new Scm();
scm.setConnection( scmConnection );
scm.setDeveloperConnection( scmDeveloperConnection );
scm.setUrl( scmUrl );
versionMetadata.setScm( scm );
}
String ciSystem = properties.getProperty( "ci.system" );
String ciUrl = properties.getProperty( "ci.url" );
if ( ciSystem != null || ciUrl != null )
{
CiManagement ci = new CiManagement();
ci.setSystem( ciSystem );
ci.setUrl( ciUrl );
versionMetadata.setCiManagement( ci );
}
String issueSystem = properties.getProperty( "issue.system" );
String issueUrl = properties.getProperty( "issue.url" );
if ( issueSystem != null || issueUrl != null )
{
IssueManagement issueManagement = new IssueManagement();
issueManagement.setSystem( ciSystem );
issueManagement.setUrl( ciUrl );
versionMetadata.setIssueManagement( issueManagement );
}
String orgName = properties.getProperty( "org.name" );
String orgUrl = properties.getProperty( "org.url" );
if ( orgName != null || orgUrl != null )
{
Organization org = new Organization();
org.setName( orgName );
org.setUrl( orgUrl );
versionMetadata.setOrganization( org );
}
boolean done = false;
int i = 0;
while ( !done )
{
String licenseName = properties.getProperty( "license." + i + ".name" );
String licenseUrl = properties.getProperty( "license." + i + ".url" );
if ( licenseName != null || licenseUrl != null )
{
License license = new License();
license.setName( licenseName );
license.setUrl( licenseUrl );
versionMetadata.addLicense( license );
}
else
{
done = true;
}
i++;
}
for ( String facetId : properties.getProperty( "facetIds" ).split( "," ) )
{
// TODO: we need a factory for the facets here
// call fromProperties( properties )
// versionMetadata.addFacet( );
}
for ( ProjectVersionFacet facet : versionMetadata.getAllFacets() )
{
properties.putAll( facet.toProperties() );
}
} }
return versionMetadata; return versionMetadata;
} }
@ -185,10 +323,10 @@ public class FileMetadataRepository
throws IOException throws IOException
{ {
directory.mkdirs(); directory.mkdirs();
FileOutputStream os = new FileOutputStream( new File( directory, "metadata.xml" ) ); FileOutputStream os = new FileOutputStream( new File( directory, "metadata.properties" ) );
try try
{ {
properties.storeToXML( os, null ); properties.store( os, null );
} }
finally finally
{ {