import java.util.Properties;
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.ProjectVersionFacet;
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
+import org.apache.archiva.metadata.model.Scm;
import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.commons.io.IOUtils;
Properties properties = new Properties();
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
{
}
}
+ 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,
ArtifactMetadata artifact )
{
FileInputStream in = null;
try
{
- in = new FileInputStream( new File( directory, "metadata.xml" ) );
- properties.loadFromXML( in );
+ in = new FileInputStream( new File( directory, "metadata.properties" ) );
+ properties.load( in );
}
catch ( FileNotFoundException e )
{
{
versionMetadata = new ProjectVersionMetadata();
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;
}
throws IOException
{
directory.mkdirs();
- FileOutputStream os = new FileOutputStream( new File( directory, "metadata.xml" ) );
+ FileOutputStream os = new FileOutputStream( new File( directory, "metadata.properties" ) );
try
{
- properties.storeToXML( os, null );
+ properties.store( os, null );
}
finally
{