1 package org.apache.maven.archiva.reporting.processor;
4 * Copyright 2005-2006 The Apache Software Foundation.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import org.apache.maven.artifact.Artifact;
20 import org.apache.maven.artifact.handler.DefaultArtifactHandler;
21 import org.apache.maven.artifact.repository.ArtifactRepository;
22 import org.apache.maven.model.Model;
23 import org.apache.maven.archiva.reporting.processor.ArtifactReportProcessor;
24 import org.apache.maven.archiva.reporting.database.ReportingDatabase;
29 * Find artifacts in the repository that are considered old.
31 * @plexus.component role="org.apache.maven.archiva.reporting.processor.ArtifactReportProcessor" role-hint="old-artifact"
32 * @todo make this configurable from the web interface
34 public class OldArtifactReportProcessor
35 implements ArtifactReportProcessor
37 private static final String ROLE_HINT = "old-artifact";
40 * The maximum age of an artifact before it is reported old, specified in seconds. The default is 1 year.
42 * @plexus.configuration default-value="31536000"
46 public void processArtifact( Artifact artifact, Model model, ReportingDatabase reporter )
48 ArtifactRepository repository = artifact.getRepository();
50 if ( !"file".equals( repository.getProtocol() ) )
52 // We can't check other types of URLs yet. Need to use Wagon, with an exists() method.
53 throw new UnsupportedOperationException(
54 "Can't process repository '" + repository.getUrl() + "'. Only file based repositories are supported" );
57 adjustDistributionArtifactHandler( artifact );
59 String artifactPath = repository.pathOf( artifact );
61 //get the location of the artifact itself
62 File file = new File( repository.getBasedir(), artifactPath );
66 if ( System.currentTimeMillis() - file.lastModified() > maxAge * 1000 )
68 // TODO: reason could be an i18n key derived from the processor and the problem ID and the
69 reporter.addNotice( artifact, ROLE_HINT, "old-artifact",
70 "The artifact is older than the maximum age of " + maxAge + " seconds." );
75 throw new IllegalStateException( "Couldn't find artifact " + file );
79 private static void adjustDistributionArtifactHandler( Artifact artifact )
81 // need to tweak these as they aren't currently in the known type converters. TODO - add them in Maven
82 if ( "distribution-zip".equals( artifact.getType() ) )
84 artifact.setArtifactHandler( new DefaultArtifactHandler( "zip" ) );
86 else if ( "distribution-tgz".equals( artifact.getType() ) )
88 artifact.setArtifactHandler( new DefaultArtifactHandler( "tar.gz" ) );