]> source.dussan.org Git - archiva.git/blob
da1392fae1017da0269b8785603bbb1cfc8a89a8
[archiva.git] /
1 package org.apache.maven.archiva.consumers.lucene;
2
3 /*
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
11  *
12  *  http://www.apache.org/licenses/LICENSE-2.0
13  *
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
19  * under the License.
20  */
21
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.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;
35
36 import java.io.File;
37 import java.util.List;
38
39 /**
40  * LuceneCleanupRemoveIndexedConsumer
41  * 
42  * @version $Id$
43  * @plexus.component role="org.apache.maven.archiva.consumers.DatabaseCleanupConsumer"
44  *                   role-hint="not-present-remove-indexed" instantiation-strategy="per-lookup"
45  */
46 public class LuceneCleanupRemoveIndexedConsumer
47     extends AbstractMonitoredConsumer
48     implements DatabaseCleanupConsumer
49 {
50     /**
51      * @plexus.configuration default-value="not-present-remove-indexed"
52      */
53     private String id;
54
55     /**
56      * @plexus.configuration default-value="Remove indexed content if not present on filesystem."
57      */
58     private String description;
59
60     /**
61      * @plexus.requirement role-hint="lucene"
62      */
63     private RepositoryContentIndexFactory repoIndexFactory;
64
65     /**
66      * @plexus.requirement
67      */
68     private RepositoryContentFactory repoFactory;
69
70     public void beginScan()
71     {
72         // TODO Auto-generated method stub
73
74     }
75
76     public void completeScan()
77     {
78         // TODO Auto-generated method stub
79
80     }
81
82     public List<String> getIncludedTypes()
83     {
84         // TODO Auto-generated method stub
85         return null;
86     }
87
88     public void processArchivaArtifact( ArchivaArtifact artifact )
89         throws ConsumerException
90     {
91         try
92         {   
93             ManagedRepositoryContent repoContent =
94                 repoFactory.getManagedRepositoryContent( artifact.getModel().getRepositoryId() );
95
96             File file = new File( repoContent.getRepoRoot(), repoContent.toPath( artifact ) );
97             
98             if( !file.exists() )
99             {   
100                 RepositoryContentIndex bytecodeIndex = repoIndexFactory.createBytecodeIndex( repoContent.getRepository() );
101                 RepositoryContentIndex hashcodesIndex = repoIndexFactory.createHashcodeIndex( repoContent.getRepository() );
102                 RepositoryContentIndex fileContentIndex =
103                     repoIndexFactory.createFileContentIndex( repoContent.getRepository() );
104     
105                 FileContentRecord fileContentRecord = new FileContentRecord();
106                 fileContentRecord.setFilename( repoContent.toPath( artifact ) );
107                 fileContentIndex.deleteRecord( fileContentRecord );
108     
109                 HashcodesRecord hashcodesRecord = new HashcodesRecord();
110                 hashcodesRecord.setArtifact( artifact );
111                 hashcodesIndex.deleteRecord( hashcodesRecord );
112     
113                 BytecodeRecord bytecodeRecord = new BytecodeRecord();
114                 bytecodeRecord.setArtifact( artifact );
115                 bytecodeIndex.deleteRecord( bytecodeRecord );
116             }                
117         }
118         catch ( RepositoryException e )
119         {
120             throw new ConsumerException( "Can't run index cleanup consumer: " + e.getMessage() );
121         }
122         catch ( RepositoryIndexException e )
123         {
124             throw new ConsumerException( e.getMessage() );
125         }
126     }
127
128     public String getDescription()
129     {
130         return description;
131     }
132
133     public String getId()
134     {
135         return id;
136     }
137
138     public boolean isPermanent()
139     {
140         return false;
141     }
142
143     public void setRepositoryIndexFactory( RepositoryContentIndexFactory repoIndexFactory )
144     {
145         this.repoIndexFactory = repoIndexFactory;
146     }
147
148     public void setRepositoryContentFactory( RepositoryContentFactory repoFactory )
149     {
150         this.repoFactory = repoFactory;
151     }
152 }