1 package org.apache.archiva.metadata.repository.file;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
23 import java.io.FileInputStream;
24 import java.io.FileNotFoundException;
25 import java.io.FileOutputStream;
26 import java.io.IOException;
27 import java.util.Properties;
29 import org.apache.archiva.metadata.model.ArtifactMetadata;
30 import org.apache.archiva.metadata.model.ProjectBuildMetadata;
31 import org.apache.archiva.metadata.model.ProjectMetadata;
32 import org.apache.archiva.metadata.repository.MetadataRepository;
33 import org.apache.commons.io.IOUtils;
35 public class FileMetadataRepository
36 implements MetadataRepository
38 private File directory;
40 public FileMetadataRepository( File directory )
42 this.directory = directory;
45 public void updateProject( ProjectMetadata project )
47 // TODO: this is a more braindead implementation than we would normally expect, for prototyping purposes
50 File projectDirectory = new File( this.directory, project.getId() );
51 Properties properties = new Properties();
52 properties.setProperty( "id", project.getId() );
53 writeProperties( properties, projectDirectory );
55 catch ( IOException e )
62 public void updateBuild( String projectId, ProjectBuildMetadata build )
64 File directory = new File( this.directory, projectId );
66 Properties properties = new Properties();
67 properties.setProperty( "id", build.getId() );
71 writeProperties( properties, new File( directory, build.getId() ) );
73 catch ( IOException e )
76 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
80 public void updateArtifact( String projectId, String buildId, ArtifactMetadata artifact )
82 File directory = new File( this.directory, projectId + "/" + buildId );
84 Properties properties = new Properties();
85 FileInputStream in = null;
88 in = new FileInputStream( new File( directory, "metadata.xml" ) );
89 properties.load( in );
91 catch ( FileNotFoundException e )
93 // skip - use blank properties
95 catch ( IOException e )
98 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
102 IOUtils.closeQuietly( in );
105 properties.setProperty( artifact.getId() + ".updated", Long.toString( artifact.getUpdated().getTime() ) );
106 properties.setProperty( artifact.getId() + ".size", Long.toString( artifact.getSize() ) );
110 writeProperties( properties, directory );
112 catch ( IOException e )
115 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
119 private void writeProperties( Properties properties, File directory )
123 FileOutputStream os = new FileOutputStream( new File( directory, "metadata.xml" ) );
126 properties.storeToXML( os, null );
130 IOUtils.closeQuietly( os );