]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1282] load content only from a single node at a time
authorBrett Porter <brett@apache.org>
Fri, 20 Nov 2009 12:14:04 +0000 (12:14 +0000)
committerBrett Porter <brett@apache.org>
Fri, 20 Nov 2009 12:14:04 +0000 (12:14 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@882532 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java
archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectBuildMetadata.java
archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectMetadata.java
archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java
archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java

index b5609e2f8e771cca2591a7bac0a35a1bc38aac52..0783a8fd83eefeb279d0f23a6d991b74a97b8428 100644 (file)
@@ -152,13 +152,13 @@ public class ArchivaMetadataCreationConsumer
         artifactMeta.setUpdated( file.lastModified() );
         artifactMeta.setSize( file.length() );
 
-        build.addArtifact( artifactMeta );
-        project.addBuild( build );
-
         // TODO: store "whenGathered"
 
+        // TODO: transaction
         // read the metadata and update it if it is newer or doesn't exist
-        metadataRepository.update( project );
+        metadataRepository.updateArtifact( metadataId, build.getId(), artifactMeta );
+        metadataRepository.updateBuild( metadataId, build );
+        metadataRepository.updateProject( project );
     }
 
     public void completeScan()
index 35e7d450513cdb1adb557712b9d84ed45e152d24..8b2d707d86db649be0e413f8f32f30b2ea803bb9 100644 (file)
@@ -19,16 +19,10 @@ package org.apache.archiva.metadata.model;
  * under the License.
  */
 
-import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
 public class ProjectBuildMetadata
 {
     private String id;
 
-    private Map<String, ArtifactMetadata> artifacts = new LinkedHashMap<String, ArtifactMetadata>();
-
     public String getId()
     {
         return id;
@@ -39,13 +33,4 @@ public class ProjectBuildMetadata
         this.id = id;
     }
 
-    public void addArtifact( ArtifactMetadata artifact )
-    {
-        this.artifacts.put( artifact.getId(), artifact );
-    }
-
-    public Collection<ArtifactMetadata> getArtifacts()
-    {
-        return artifacts.values();
-    }
 }
index 5286429203b4b4aa05214b1b3a2c144c5d03d330..09707e2d39379e844ba15c100a61910cc8d6df2b 100644 (file)
@@ -19,15 +19,9 @@ package org.apache.archiva.metadata.model;
  * under the License.
  */
 
-import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
 public class ProjectMetadata
 {
     private String id;
-    
-    private Map<String, ProjectBuildMetadata> builds = new LinkedHashMap<String, ProjectBuildMetadata>();
 
     public void setId( String id )
     {
@@ -39,13 +33,4 @@ public class ProjectMetadata
         return id;
     }
 
-    public void addBuild( ProjectBuildMetadata build )
-    {
-        this.builds.put( build.getId(), build );
-    }
-
-    public Collection<ProjectBuildMetadata> getBuilds()
-    {
-        return builds.values();
-    }
 }
index f77253078146dfd8d55f7f93874ea16b70f733fa..744ba95a3d02a98651b5f9c7cdf03b1ce740dd52 100644 (file)
@@ -19,6 +19,8 @@ package org.apache.archiva.metadata.repository;
  * under the License.
  */
 
+import org.apache.archiva.metadata.model.ArtifactMetadata;
+import org.apache.archiva.metadata.model.ProjectBuildMetadata;
 import org.apache.archiva.metadata.model.ProjectMetadata;
 
 public interface MetadataRepository
@@ -28,6 +30,9 @@ public interface MetadataRepository
      * Update metadata for a particular project in the metadata repository, or create it if it does not already exist.
      * @param project the project metadata to create or update
      */
-    void update( ProjectMetadata project );
+    void updateProject( ProjectMetadata project );
 
+    void updateArtifact( String projectId, String buildId, ArtifactMetadata artifactMeta );
+
+    void updateBuild( String projectId, ProjectBuildMetadata build );
 }
index c39f8f0e37b43884bb52fbf6d8ccc3bd7a94ccea..2e3fca39cf9754089932b1438dfdab426dd168fa 100644 (file)
@@ -20,6 +20,7 @@ package org.apache.archiva.metadata.repository.file;
  */
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -41,18 +42,15 @@ public class FileMetadataRepository
         this.directory = directory;
     }
 
-    public void update( ProjectMetadata project )
+    public void updateProject( ProjectMetadata project )
     {
         // TODO: this is a more braindead implementation than we would normally expect, for prototyping purposes
         try
         {
             File projectDirectory = new File( this.directory, project.getId() );
-            store( project, projectDirectory );
-
-            for ( ProjectBuildMetadata build : project.getBuilds() )
-            {
-                store( build, projectDirectory );
-            }
+            Properties properties = new Properties();
+            properties.setProperty( "id", project.getId() );
+            writeProperties( properties, projectDirectory );
         }
         catch ( IOException e )
         {
@@ -61,32 +59,65 @@ public class FileMetadataRepository
         }
     }
 
-    private void store( ProjectBuildMetadata build, File directory )
-        throws FileNotFoundException, IOException
+    public void updateBuild( String projectId, ProjectBuildMetadata build )
     {
+        File directory = new File( this.directory, projectId );
+
         Properties properties = new Properties();
         properties.setProperty( "id", build.getId() );
-        
-        for ( ArtifactMetadata artifact : build.getArtifacts() )
+
+        try
+        {
+            writeProperties( properties, new File( directory, build.getId() ) );
+        }
+        catch ( IOException e )
         {
-            properties.setProperty( artifact.getId() + ".updated", Long.toString( artifact.getUpdated().getTime() ) );
-            properties.setProperty( artifact.getId() + ".size", Long.toString( artifact.getSize() ) );
+            // TODO
+            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
         }
-        
-        writeProperties( properties, new File( directory, build.getId() ) );
     }
 
-    private void store( ProjectMetadata project, File directory )
-        throws FileNotFoundException, IOException
+    public void updateArtifact( String projectId, String buildId, ArtifactMetadata artifact )
     {
+        File directory = new File( this.directory, projectId + "/" + buildId );
 
         Properties properties = new Properties();
-        properties.setProperty( "id", project.getId() );
-        writeProperties( properties, directory );
+        FileInputStream in = null;
+        try
+        {
+            in = new FileInputStream( new File( directory, "metadata.xml" ) );
+            properties.load( in );
+        }
+        catch ( FileNotFoundException e )
+        {
+            // skip - use blank properties
+        }
+        catch ( IOException e )
+        {
+            // TODO
+            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+        }
+        finally
+        {
+            IOUtils.closeQuietly( in );
+        }
+
+        properties.setProperty( artifact.getId() + ".updated", Long.toString( artifact.getUpdated().getTime() ) );
+        properties.setProperty( artifact.getId() + ".size", Long.toString( artifact.getSize() ) );
+
+        try
+        {
+            writeProperties( properties, directory );
+        }
+        catch ( IOException e )
+        {
+            // TODO
+            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+        }
     }
 
     private void writeProperties( Properties properties, File directory )
-        throws FileNotFoundException, IOException
+        throws IOException
     {
         directory.mkdirs();
         FileOutputStream os = new FileOutputStream( new File( directory, "metadata.xml" ) );