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;
public class FileMetadataRepository
implements MetadataRepository
{
- private File directory;
-
+ private File directory;
+
public FileMetadataRepository( File directory )
{
this.directory = directory;
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 )
{
}
}
- 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