From 05d2784124cb48259973715da6db1e32840a574d Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Fri, 20 Nov 2009 12:14:04 +0000 Subject: [PATCH] [MRM-1282] load content only from a single node at a time git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@882532 13f79535-47bb-0310-9956-ffa450edef68 --- .../ArchivaMetadataCreationConsumer.java | 8 +-- .../metadata/model/ProjectBuildMetadata.java | 15 ---- .../metadata/model/ProjectMetadata.java | 15 ---- .../repository/MetadataRepository.java | 7 +- .../file/FileMetadataRepository.java | 71 +++++++++++++------ 5 files changed, 61 insertions(+), 55 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java index b5609e2f8..0783a8fd8 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java @@ -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() diff --git a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectBuildMetadata.java b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectBuildMetadata.java index 35e7d4505..8b2d707d8 100644 --- a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectBuildMetadata.java +++ b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectBuildMetadata.java @@ -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 artifacts = new LinkedHashMap(); - 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 getArtifacts() - { - return artifacts.values(); - } } diff --git a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectMetadata.java b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectMetadata.java index 528642920..09707e2d3 100644 --- a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectMetadata.java +++ b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectMetadata.java @@ -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 builds = new LinkedHashMap(); 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 getBuilds() - { - return builds.values(); - } } diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java index f77253078..744ba95a3 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java @@ -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 ); } diff --git a/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java b/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java index c39f8f0e3..2e3fca39c 100644 --- a/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java +++ b/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java @@ -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" ) ); -- 2.39.5