From: Brett Porter Date: Tue, 2 Dec 2008 00:37:27 +0000 (+0000) Subject: [MRM-1025] write more information out X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5b04d5d6f7789cc2fce113bd18e3d24383b50287;p=archiva.git [MRM-1025] write more information out git-svn-id: https://svn.apache.org/repos/asf/archiva/branches@722312 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/MRM-1025/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectBuildMetadata.java b/MRM-1025/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectBuildMetadata.java index 57b9f4d0c..650871c4c 100644 --- a/MRM-1025/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectBuildMetadata.java +++ b/MRM-1025/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectBuildMetadata.java @@ -1,5 +1,6 @@ package org.apache.archiva.metadata.model; +import java.util.Collection; import java.util.LinkedHashMap; import java.util.Map; @@ -42,4 +43,9 @@ public class ProjectBuildMetadata { this.artifacts.put( artifact.getId(), artifact ); } + + public Collection getArtifacts() + { + return artifacts.values(); + } } diff --git a/MRM-1025/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectMetadata.java b/MRM-1025/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectMetadata.java index 783c91313..107fd373c 100644 --- a/MRM-1025/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectMetadata.java +++ b/MRM-1025/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectMetadata.java @@ -1,5 +1,6 @@ package org.apache.archiva.metadata.model; +import java.util.Collection; import java.util.LinkedHashMap; import java.util.Map; @@ -42,4 +43,9 @@ public class ProjectMetadata { this.builds.put( build.getId(), build ); } + + public Collection getBuilds() + { + return builds.values(); + } } diff --git a/MRM-1025/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java b/MRM-1025/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java index 9241ad316..c39f8f0e3 100644 --- a/MRM-1025/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java +++ b/MRM-1025/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java @@ -25,6 +25,8 @@ import java.io.FileOutputStream; import java.io.IOException; import java.util.Properties; +import org.apache.archiva.metadata.model.ArtifactMetadata; +import org.apache.archiva.metadata.model.ProjectBuildMetadata; import org.apache.archiva.metadata.model.ProjectMetadata; import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.commons.io.IOUtils; @@ -32,8 +34,8 @@ import org.apache.commons.io.IOUtils; public class FileMetadataRepository implements MetadataRepository { - private File directory; - + private File directory; + public FileMetadataRepository( File directory ) { this.directory = directory; @@ -41,9 +43,16 @@ public class FileMetadataRepository public void update( ProjectMetadata project ) { + // TODO: this is a more braindead implementation than we would normally expect, for prototyping purposes try { - store( project ); + File projectDirectory = new File( this.directory, project.getId() ); + store( project, projectDirectory ); + + for ( ProjectBuildMetadata build : project.getBuilds() ) + { + store( build, projectDirectory ); + } } catch ( IOException e ) { @@ -52,14 +61,33 @@ public class FileMetadataRepository } } - private void store( ProjectMetadata project ) + private void store( ProjectBuildMetadata build, File directory ) throws FileNotFoundException, IOException { - // TODO: this is a more braindead implementation than we would normally expect, for prototyping purposes + Properties properties = new Properties(); + properties.setProperty( "id", build.getId() ); + for ( ArtifactMetadata artifact : build.getArtifacts() ) + { + properties.setProperty( artifact.getId() + ".updated", Long.toString( artifact.getUpdated().getTime() ) ); + properties.setProperty( artifact.getId() + ".size", Long.toString( artifact.getSize() ) ); + } + + writeProperties( properties, new File( directory, build.getId() ) ); + } + + private void store( ProjectMetadata project, File directory ) + throws FileNotFoundException, IOException + { + Properties properties = new Properties(); - properties.put( "id", project.getId() ); - File directory = new File( this.directory, project.getId() ); + properties.setProperty( "id", project.getId() ); + writeProperties( properties, directory ); + } + + private void writeProperties( Properties properties, File directory ) + throws FileNotFoundException, IOException + { directory.mkdirs(); FileOutputStream os = new FileOutputStream( new File( directory, "metadata.xml" ) ); try