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.commons.lang.StringUtils;
23 import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
24 import org.apache.maven.archiva.consumers.ConsumerException;
25 import org.apache.maven.archiva.consumers.DatabaseCleanupConsumer;
26 import org.apache.maven.archiva.model.ArchivaArtifact;
27 import org.apache.maven.archiva.model.ArchivaProjectModel;
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.database.ProjectModelDAO;
32 import org.apache.maven.archiva.database.ArchivaDatabaseException;
34 import java.util.List;
38 * Consumer for removing or deleting from the database the project models fo artifacts that have been
39 * deleted/removed from 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-project"
47 * instantiation-strategy="per-lookup"
49 public class DatabaseCleanupRemoveProjectConsumer
50 extends AbstractMonitoredConsumer
51 implements DatabaseCleanupConsumer
54 * @plexus.configuration default-value="not-present-remove-db-project"
59 * @plexus.configuration default-value="Remove project from database if not present on filesystem."
61 private String description;
64 * @plexus.requirement role-hint="jdo"
66 private ProjectModelDAO projectModelDAO;
71 private RepositoryContentFactory repositoryFactory;
73 public void beginScan()
75 // TODO Auto-generated method stub
78 public void completeScan()
80 // TODO Auto-generated method stub
83 public List<String> getIncludedTypes()
88 public void processArchivaArtifact( ArchivaArtifact artifact )
89 throws ConsumerException
91 if ( !StringUtils.equals( "pom", artifact.getType() ) )
93 // Not a pom. Skip it.
99 ManagedRepositoryContent repositoryContent =
100 repositoryFactory.getManagedRepositoryContent( artifact.getModel().getRepositoryId() );
102 File file = new File( repositoryContent.getRepoRoot(), repositoryContent.toPath( artifact ) );
106 ArchivaProjectModel projectModel = projectModelDAO.getProjectModel(
107 artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() );
109 projectModelDAO.deleteProjectModel( projectModel );
112 catch ( RepositoryException re )
114 throw new ConsumerException( "Can't run database cleanup remove artifact consumer: " +
117 catch ( ArchivaDatabaseException e )
119 throw new ConsumerException( e.getMessage() );
124 public String getDescription()
129 public String getId()
134 public boolean isPermanent()
139 public void setProjectModelDAO( ProjectModelDAO projectModelDAO )
141 this.projectModelDAO = projectModelDAO;
144 public void setRepositoryFactory( RepositoryContentFactory repositoryFactory )
146 this.repositoryFactory = repositoryFactory;