1 | |
package org.apache.maven.archiva.consumers.core; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import org.apache.commons.collections.CollectionUtils; |
23 | |
import org.apache.commons.lang.StringUtils; |
24 | |
import org.apache.maven.archiva.configuration.ArchivaConfiguration; |
25 | |
import org.apache.maven.archiva.configuration.ConfigurationNames; |
26 | |
import org.apache.maven.archiva.configuration.FileTypes; |
27 | |
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; |
28 | |
import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; |
29 | |
import org.apache.maven.archiva.consumers.ConsumerException; |
30 | |
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; |
31 | |
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; |
32 | |
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; |
33 | |
import org.codehaus.plexus.registry.Registry; |
34 | |
import org.codehaus.plexus.registry.RegistryListener; |
35 | |
|
36 | |
import java.io.File; |
37 | |
import java.util.ArrayList; |
38 | |
import java.util.Date; |
39 | |
import java.util.List; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | 0 | public class AutoRemoveConsumer |
50 | |
extends AbstractMonitoredConsumer |
51 | |
implements KnownRepositoryContentConsumer, RegistryListener, Initializable |
52 | |
{ |
53 | |
|
54 | |
|
55 | |
|
56 | |
private String id; |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
private String description; |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
private ArchivaConfiguration configuration; |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
private FileTypes filetypes; |
72 | |
|
73 | |
private File repositoryDir; |
74 | |
|
75 | 0 | private List<String> includes = new ArrayList<String>(); |
76 | |
|
77 | |
public String getId() |
78 | |
{ |
79 | 0 | return this.id; |
80 | |
} |
81 | |
|
82 | |
public String getDescription() |
83 | |
{ |
84 | 0 | return this.description; |
85 | |
} |
86 | |
|
87 | |
public boolean isPermanent() |
88 | |
{ |
89 | 0 | return false; |
90 | |
} |
91 | |
|
92 | |
public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered ) |
93 | |
throws ConsumerException |
94 | |
{ |
95 | 0 | this.repositoryDir = new File( repository.getLocation() ); |
96 | 0 | } |
97 | |
|
98 | |
public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo ) |
99 | |
throws ConsumerException |
100 | |
{ |
101 | 0 | beginScan( repository, whenGathered ); |
102 | 0 | } |
103 | |
|
104 | |
public void completeScan() |
105 | |
{ |
106 | |
|
107 | 0 | } |
108 | |
|
109 | |
public void completeScan( boolean executeOnEntireRepo ) |
110 | |
{ |
111 | 0 | completeScan(); |
112 | 0 | } |
113 | |
|
114 | |
public List<String> getExcludes() |
115 | |
{ |
116 | 0 | return null; |
117 | |
} |
118 | |
|
119 | |
public List<String> getIncludes() |
120 | |
{ |
121 | 0 | return includes; |
122 | |
} |
123 | |
|
124 | |
public void processFile( String path ) |
125 | |
throws ConsumerException |
126 | |
{ |
127 | 0 | File file = new File( this.repositoryDir, path ); |
128 | 0 | if ( file.exists() ) |
129 | |
{ |
130 | 0 | triggerConsumerInfo( "(Auto) Removing File: " + file.getAbsolutePath() ); |
131 | 0 | file.delete(); |
132 | |
} |
133 | 0 | } |
134 | |
|
135 | |
public void processFile( String path, boolean executeOnEntireRepo ) |
136 | |
throws ConsumerException |
137 | |
{ |
138 | 0 | processFile( path ); |
139 | 0 | } |
140 | |
|
141 | |
public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) |
142 | |
{ |
143 | 0 | if ( ConfigurationNames.isRepositoryScanning( propertyName ) ) |
144 | |
{ |
145 | 0 | initIncludes(); |
146 | |
} |
147 | 0 | } |
148 | |
|
149 | |
public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue ) |
150 | |
{ |
151 | |
|
152 | 0 | } |
153 | |
|
154 | |
private void initIncludes() |
155 | |
{ |
156 | 0 | includes.clear(); |
157 | |
|
158 | 0 | includes.addAll( filetypes.getFileTypePatterns( FileTypes.AUTO_REMOVE ) ); |
159 | 0 | } |
160 | |
|
161 | |
public void initialize() |
162 | |
throws InitializationException |
163 | |
{ |
164 | 0 | configuration.addChangeListener( this ); |
165 | |
|
166 | 0 | initIncludes(); |
167 | 0 | } |
168 | |
} |