1 package org.apache.maven.archiva.consumers.lucene;
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.database.updater.DatabaseCleanupConsumer;
25 import org.apache.maven.archiva.indexer.RepositoryContentIndex;
26 import org.apache.maven.archiva.indexer.RepositoryContentIndexFactory;
27 import org.apache.maven.archiva.indexer.RepositoryIndexException;
28 import org.apache.maven.archiva.indexer.bytecode.BytecodeRecord;
29 import org.apache.maven.archiva.indexer.filecontent.FileContentRecord;
30 import org.apache.maven.archiva.indexer.hashcodes.HashcodesRecord;
31 import org.apache.maven.archiva.model.ArchivaArtifact;
32 import org.apache.maven.archiva.repository.ManagedRepositoryContent;
33 import org.apache.maven.archiva.repository.RepositoryContentFactory;
34 import org.apache.maven.archiva.repository.RepositoryException;
37 import java.util.List;
40 * LuceneCleanupRemoveIndexedConsumer
43 * @plexus.component role="org.apache.maven.archiva.database.updater.DatabaseCleanupConsumer"
44 * role-hint="not-present-remove-indexed" instantiation-strategy="per-lookup"
46 public class LuceneCleanupRemoveIndexedConsumer
47 extends AbstractMonitoredConsumer
48 implements DatabaseCleanupConsumer
51 * @plexus.configuration default-value="not-present-remove-indexed"
56 * @plexus.configuration default-value="Remove indexed content if not present on filesystem."
58 private String description;
61 * @plexus.requirement role-hint="lucene"
63 private RepositoryContentIndexFactory repoIndexFactory;
68 private RepositoryContentFactory repoFactory;
70 public void beginScan()
72 // TODO Auto-generated method stub
76 public void completeScan()
78 // TODO Auto-generated method stub
82 public List<String> getIncludedTypes()
84 // TODO Auto-generated method stub
88 public void processArchivaArtifact( ArchivaArtifact artifact )
89 throws ConsumerException
93 ManagedRepositoryContent repoContent =
94 repoFactory.getManagedRepositoryContent( artifact.getModel().getRepositoryId() );
96 File file = new File( repoContent.getRepoRoot(), repoContent.toPath( artifact ) );
100 RepositoryContentIndex bytecodeIndex = repoIndexFactory.createBytecodeIndex( repoContent.getRepository() );
101 RepositoryContentIndex hashcodesIndex = repoIndexFactory.createHashcodeIndex( repoContent.getRepository() );
102 RepositoryContentIndex fileContentIndex =
103 repoIndexFactory.createFileContentIndex( repoContent.getRepository() );
105 FileContentRecord fileContentRecord = new FileContentRecord();
106 fileContentRecord.setFilename( repoContent.toPath( artifact ) );
107 fileContentIndex.deleteRecord( fileContentRecord );
109 HashcodesRecord hashcodesRecord = new HashcodesRecord();
110 hashcodesRecord.setArtifact( artifact );
111 hashcodesIndex.deleteRecord( hashcodesRecord );
113 BytecodeRecord bytecodeRecord = new BytecodeRecord();
114 bytecodeRecord.setArtifact( artifact );
115 bytecodeIndex.deleteRecord( bytecodeRecord );
118 catch ( RepositoryException e )
120 throw new ConsumerException( "Can't run index cleanup consumer: " + e.getMessage() );
122 catch ( RepositoryIndexException e )
124 throw new ConsumerException( e.getMessage() );
128 public String getDescription()
133 public String getId()
138 public boolean isPermanent()
143 public void setRepositoryIndexFactory( RepositoryContentIndexFactory repoIndexFactory )
145 this.repoIndexFactory = repoIndexFactory;
148 public void setRepositoryContentFactory( RepositoryContentFactory repoFactory )
150 this.repoFactory = repoFactory;