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.maven.archiva.configuration.ManagedRepositoryConfiguration; |
23 | |
import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; |
24 | |
import org.apache.maven.archiva.consumers.ConsumerException; |
25 | |
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; |
26 | |
import org.codehaus.plexus.digest.ChecksumFile; |
27 | |
import org.codehaus.plexus.digest.Digester; |
28 | |
import org.codehaus.plexus.digest.DigesterException; |
29 | |
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; |
30 | |
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; |
31 | |
|
32 | |
import java.io.File; |
33 | |
import java.io.FileNotFoundException; |
34 | |
import java.io.IOException; |
35 | |
import java.util.ArrayList; |
36 | |
import java.util.Date; |
37 | |
import java.util.Iterator; |
38 | |
import java.util.List; |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | 0 | public class ValidateChecksumConsumer |
49 | |
extends AbstractMonitoredConsumer |
50 | |
implements KnownRepositoryContentConsumer, Initializable |
51 | |
{ |
52 | |
private static final String NOT_VALID_CHECKSUM = "checksum-not-valid"; |
53 | |
|
54 | |
private static final String CHECKSUM_NOT_FOUND = "checksum-not-found"; |
55 | |
|
56 | |
private static final String CHECKSUM_DIGESTER_FAILURE = "checksum-digester-failure"; |
57 | |
|
58 | |
private static final String CHECKSUM_IO_ERROR = "checksum-io-error"; |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
private String id; |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
private String description; |
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
private ChecksumFile checksum; |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
private List<Digester> digesterList; |
79 | |
|
80 | |
private File repositoryDir; |
81 | |
|
82 | 0 | private List<String> includes = new ArrayList<String>(); |
83 | |
|
84 | |
public String getId() |
85 | |
{ |
86 | 0 | return this.id; |
87 | |
} |
88 | |
|
89 | |
public String getDescription() |
90 | |
{ |
91 | 0 | return this.description; |
92 | |
} |
93 | |
|
94 | |
public boolean isPermanent() |
95 | |
{ |
96 | 0 | return false; |
97 | |
} |
98 | |
|
99 | |
public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered ) |
100 | |
throws ConsumerException |
101 | |
{ |
102 | 0 | this.repositoryDir = new File( repository.getLocation() ); |
103 | 0 | } |
104 | |
|
105 | |
public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo ) |
106 | |
throws ConsumerException |
107 | |
{ |
108 | 0 | beginScan( repository, whenGathered ); |
109 | 0 | } |
110 | |
|
111 | |
public void completeScan() |
112 | |
{ |
113 | |
|
114 | 0 | } |
115 | |
|
116 | |
public void completeScan( boolean executeOnEntireRepo ) |
117 | |
{ |
118 | 0 | completeScan(); |
119 | 0 | } |
120 | |
|
121 | |
public List<String> getExcludes() |
122 | |
{ |
123 | 0 | return null; |
124 | |
} |
125 | |
|
126 | |
public List<String> getIncludes() |
127 | |
{ |
128 | 0 | return this.includes; |
129 | |
} |
130 | |
|
131 | |
public void processFile( String path ) |
132 | |
throws ConsumerException |
133 | |
{ |
134 | 0 | File checksumFile = new File( this.repositoryDir, path ); |
135 | |
try |
136 | |
{ |
137 | 0 | if ( !checksum.isValidChecksum( checksumFile ) ) |
138 | |
{ |
139 | 0 | triggerConsumerWarning( NOT_VALID_CHECKSUM, "The checksum for " + checksumFile + " is invalid." ); |
140 | |
} |
141 | |
} |
142 | 0 | catch ( FileNotFoundException e ) |
143 | |
{ |
144 | 0 | triggerConsumerError( CHECKSUM_NOT_FOUND, "File not found during checksum validation: " + e.getMessage() ); |
145 | |
} |
146 | 0 | catch ( DigesterException e ) |
147 | |
{ |
148 | 0 | triggerConsumerError( CHECKSUM_DIGESTER_FAILURE, |
149 | |
"Digester failure during checksum validation on " + checksumFile ); |
150 | |
} |
151 | 0 | catch ( IOException e ) |
152 | |
{ |
153 | 0 | triggerConsumerError( CHECKSUM_IO_ERROR, "Checksum I/O error during validation on " + checksumFile ); |
154 | 0 | } |
155 | 0 | } |
156 | |
|
157 | |
public void processFile( String path, boolean executeOnEntireRepo ) |
158 | |
throws Exception |
159 | |
{ |
160 | 0 | processFile( path ); |
161 | 0 | } |
162 | |
|
163 | |
public void initialize() |
164 | |
throws InitializationException |
165 | |
{ |
166 | 0 | for ( Iterator<Digester> itDigesters = digesterList.iterator(); itDigesters.hasNext(); ) |
167 | |
{ |
168 | 0 | Digester digester = itDigesters.next(); |
169 | 0 | includes.add( "**/*" + digester.getFilenameExtension() ); |
170 | 0 | } |
171 | 0 | } |
172 | |
} |