1 package org.apache.maven.archiva.reporting;
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;
27 * Find artifacts in the repository that are considered old.
29 * @plexus.component role="org.apache.maven.archiva.reporting.ArtifactReportProcessor" role-hint="old-artifact"
30 * @todo make this configurable from the web interface
32 public class OldArtifactReportProcessor
33 implements ArtifactReportProcessor
35 private static final String ROLE_HINT = "old-artifact";
38 * The maximum age of an artifact before it is reported old, specified in seconds. The default is 1 year.
40 * @plexus.configuration default-value="31536000"
44 public void processArtifact( Artifact artifact, Model model, ReportingDatabase reporter )
46 ArtifactRepository repository = artifact.getRepository();
48 if ( !"file".equals( repository.getProtocol() ) )
50 // We can't check other types of URLs yet. Need to use Wagon, with an exists() method.
51 throw new UnsupportedOperationException(
52 "Can't process repository '" + repository.getUrl() + "'. Only file based repositories are supported" );
55 adjustDistributionArtifactHandler( artifact );
57 String artifactPath = repository.pathOf( artifact );
59 //get the location of the artifact itself
60 File file = new File( repository.getBasedir(), artifactPath );
64 if ( System.currentTimeMillis() - file.lastModified() > maxAge * 1000 )
66 // TODO: reason could be an i18n key derived from the processor and the problem ID and the
67 reporter.addNotice( artifact, ROLE_HINT, "old-artifact",
68 "The artifact is older than the maximum age of " + maxAge + " seconds." );
73 throw new IllegalStateException( "Couldn't find artifact " + file );
77 private static void adjustDistributionArtifactHandler( Artifact artifact )
79 // need to tweak these as they aren't currently in the known type converters. TODO - add them in Maven
80 if ( "distribution-zip".equals( artifact.getType() ) )
82 artifact.setArtifactHandler( new DefaultArtifactHandler( "zip" ) );
84 else if ( "distribution-tgz".equals( artifact.getType() ) )
86 artifact.setArtifactHandler( new DefaultArtifactHandler( "tar.gz" ) );