1 package org.apache.maven.archiva.consumers.database;
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
22 import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
23 import org.apache.maven.archiva.consumers.ConsumerException;
24 import org.apache.maven.archiva.consumers.DatabaseCleanupConsumer;
25 import org.apache.maven.archiva.model.ArchivaArtifact;
26 import org.apache.maven.archiva.database.ArtifactDAO;
27 import org.apache.maven.archiva.database.ArchivaDatabaseException;
28 import org.apache.maven.archiva.repository.ManagedRepositoryContent;
29 import org.apache.maven.archiva.repository.RepositoryContentFactory;
30 import org.apache.maven.archiva.repository.RepositoryException;
31 import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout;
32 import org.apache.maven.archiva.repository.layout.LayoutException;
33 import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayoutFactory;
35 import java.util.List;
39 * Consumer for cleaning up the database of artifacts that are no longer existing in the repository.
41 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
42 * <a href="mailto:oching@apache.org">Maria Odea Ching</a>
45 * @plexus.component role="org.apache.maven.archiva.consumers.DatabaseCleanupConsumer"
46 * role-hint="not-present-remove-db-artifact"
47 * instantiation-strategy="per-lookup"
49 public class DatabaseCleanupRemoveArtifactConsumer
50 extends AbstractMonitoredConsumer
51 implements DatabaseCleanupConsumer
54 * @plexus.configuration default-value="not-present-remove-db-artifact"
59 * @plexus.configuration default-value="Remove artifact from database if not present on filesystem."
61 private String description;
64 * @plexus.requirement role-hint="jdo"
66 private ArtifactDAO artifactDAO;
71 private BidirectionalRepositoryLayoutFactory layoutFactory;
76 private RepositoryContentFactory repositoryFactory;
78 public void beginScan()
80 // TODO Auto-generated method stub
84 public void completeScan()
86 // TODO Auto-generated method stub
89 public List<String> getIncludedTypes()
94 public void processArchivaArtifact( ArchivaArtifact artifact )
95 throws ConsumerException
99 ManagedRepositoryContent repositoryContent =
100 repositoryFactory.getManagedRepositoryContent( artifact.getModel().getRepositoryId() );
102 File file = new File( repositoryContent.getRepoRoot(), toPath( artifact ) );
106 artifactDAO.deleteArtifact( artifact );
109 catch ( RepositoryException re )
111 throw new ConsumerException( "Can't run database cleanup remove artifact consumer: " +
114 catch ( ArchivaDatabaseException e )
116 throw new ConsumerException( e.getMessage() );
120 public String getDescription()
125 public String getId()
130 public boolean isPermanent()
135 public void setArtifactDAO( ArtifactDAO artifactDAO)
137 this.artifactDAO = artifactDAO;
140 public void setBidirectionalRepositoryLayoutFactory( BidirectionalRepositoryLayoutFactory layoutFactory )
142 this.layoutFactory = layoutFactory;
145 public void setRepositoryFactory( RepositoryContentFactory repositoryFactory )
147 this.repositoryFactory = repositoryFactory;
150 private String toPath( ArchivaArtifact artifact )
154 BidirectionalRepositoryLayout layout = layoutFactory.getLayout( artifact );
156 return layout.toPath( artifact );
158 catch ( LayoutException e )
160 getLogger().warn( "Unable to calculate path for artifact: " + artifact );