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.database.Constraint;
26 import org.apache.maven.archiva.database.RepositoryProblemDAO;
27 import org.apache.maven.archiva.database.constraints.RepositoryProblemByArtifactConstraint;
28 import org.apache.maven.archiva.model.ArchivaArtifact;
29 import org.apache.maven.archiva.database.ArtifactDAO;
30 import org.apache.maven.archiva.database.ArchivaDatabaseException;
31 import org.apache.maven.archiva.model.RepositoryProblem;
32 import org.apache.maven.archiva.repository.ManagedRepositoryContent;
33 import org.apache.maven.archiva.repository.RepositoryContentFactory;
34 import org.apache.maven.archiva.repository.RepositoryException;
36 import java.util.List;
40 * Consumer for cleaning up the database of artifacts that are no longer existing in the repository.
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;
69 * @plexus.requirement role-hint="jdo"
71 private RepositoryProblemDAO repositoryProblemDAO;
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(), repositoryContent.toPath( artifact ) );
106 artifactDAO.deleteArtifact( artifact );
108 // Remove all repository problems related to this artifact
109 Constraint artifactConstraint = new RepositoryProblemByArtifactConstraint( artifact );
110 List<RepositoryProblem> repositoryProblems =
111 repositoryProblemDAO.queryRepositoryProblems( artifactConstraint );
113 if ( repositoryProblems != null )
115 for ( RepositoryProblem repositoryProblem : repositoryProblems )
117 repositoryProblemDAO.deleteRepositoryProblem( repositoryProblem );
122 catch ( RepositoryException re )
124 throw new ConsumerException( "Can't run database cleanup remove artifact consumer: " +
127 catch ( ArchivaDatabaseException e )
129 throw new ConsumerException( e.getMessage() );
133 public String getDescription()
138 public String getId()
143 public boolean isPermanent()
148 public void setArtifactDAO( ArtifactDAO artifactDAO)
150 this.artifactDAO = artifactDAO;
153 public void setRepositoryProblemDAO( RepositoryProblemDAO repositoryProblemDAO )
155 this.repositoryProblemDAO = repositoryProblemDAO;
158 public void setRepositoryFactory( RepositoryContentFactory repositoryFactory )
160 this.repositoryFactory = repositoryFactory;