]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1282] store more of the content in the file metadata repository
authorBrett Porter <brett@apache.org>
Wed, 25 Nov 2009 16:24:55 +0000 (16:24 +0000)
committerBrett Porter <brett@apache.org>
Wed, 25 Nov 2009 16:24:55 +0000 (16:24 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@884177 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectVersionFacet.java
archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectVersionMetadata.java
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacet.java
archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java

index 8cb109fcb640d4a8e385b1d3de992f25361fd023..a0ac18736656c6b0409fcbc013ad37c2385c9945 100644 (file)
@@ -1,5 +1,7 @@
 package org.apache.archiva.metadata.model;
 
+import java.util.Map;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -22,4 +24,6 @@ package org.apache.archiva.metadata.model;
 public interface ProjectVersionFacet
 {
     String getFacetId();
+
+    Map<String, String> toProperties();
 }
index 08f4b5a9c17a95fc9c80e2c165bbbe3bc1c50cbb..159afd15ca6d6694d4f256e15cf9e9a724ac38e5 100644 (file)
@@ -20,6 +20,7 @@ package org.apache.archiva.metadata.model;
  */
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -44,7 +45,7 @@ public class ProjectVersionMetadata
 
     private List<License> licenses;
 
-    private Map<String, ProjectVersionFacet> facets;
+    private Map<String, ProjectVersionFacet> facets = new HashMap<String, ProjectVersionFacet>();;
 
     public String getId()
     {
@@ -147,15 +148,21 @@ public class ProjectVersionMetadata
 
     public void addFacet( ProjectVersionFacet mavenProjectFacet )
     {
-        if ( this.facets == null )
-        {
-            this.facets = new HashMap<String, ProjectVersionFacet>();
-        }
         this.facets.put( mavenProjectFacet.getFacetId(), mavenProjectFacet );
     }
 
     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();
     }
 }
index fbcc31b75ca4b78410abc685224f58127d9ccd88..8b6b7edc60b851476366c4a7c8cf569ca8bd43ae 100644 (file)
@@ -19,6 +19,9 @@ package org.apache.archiva.metadata.repository.storage.maven2;
  * under the License.
  */
 
+import java.util.HashMap;
+import java.util.Map;
+
 import org.apache.archiva.metadata.model.ProjectVersionFacet;
 
 public class MavenProjectFacet
@@ -78,4 +81,19 @@ public class MavenProjectFacet
     {
         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;
+    }
 }
index c98974104a93110920cab71f472390e97066d92d..0c9b3ca48767f23fb480bc4e8b433845bf19c0b5 100644 (file)
@@ -31,8 +31,14 @@ import java.util.Map;
 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;
 
@@ -75,6 +81,42 @@ public class FileMetadataRepository
 
         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
         {
@@ -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,
                                 ArtifactMetadata artifact )
     {
@@ -115,8 +176,8 @@ public class FileMetadataRepository
         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 )
         {
@@ -158,6 +219,83 @@ public class FileMetadataRepository
         {
             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;
     }
@@ -185,10 +323,10 @@ public class FileMetadataRepository
         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
         {