1 | |
package org.apache.maven.archiva.policies; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.io.File; |
23 | |
import java.util.ArrayList; |
24 | |
import java.util.List; |
25 | |
import java.util.Map; |
26 | |
import java.util.Properties; |
27 | |
|
28 | |
import org.apache.commons.lang.StringUtils; |
29 | |
import org.slf4j.Logger; |
30 | |
import org.slf4j.LoggerFactory; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public class PropagateErrorsDownloadPolicy |
39 | |
implements DownloadErrorPolicy |
40 | |
{ |
41 | 0 | private Logger log = LoggerFactory.getLogger( PropagateErrorsDownloadPolicy.class ); |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
public static final String STOP = "stop"; |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
public static final String QUEUE = "queue error"; |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
public static final String IGNORE = "ignore"; |
57 | |
|
58 | 0 | private List<String> options = new ArrayList<String>(); |
59 | |
|
60 | |
public PropagateErrorsDownloadPolicy() |
61 | 0 | { |
62 | 0 | options.add( STOP ); |
63 | 0 | options.add( QUEUE ); |
64 | 0 | options.add( IGNORE ); |
65 | 0 | } |
66 | |
|
67 | |
public boolean applyPolicy( String policySetting, Properties request, File localFile, Exception exception, |
68 | |
Map<String, Exception> previousExceptions ) |
69 | |
throws PolicyConfigurationException |
70 | |
{ |
71 | 0 | if ( !options.contains( policySetting ) ) |
72 | |
{ |
73 | |
|
74 | 0 | throw new PolicyConfigurationException( "Unknown error policy setting [" + policySetting + |
75 | |
"], valid settings are [" + StringUtils.join( options.iterator(), "," ) + "]" ); |
76 | |
} |
77 | |
|
78 | 0 | if ( IGNORE.equals( policySetting ) ) |
79 | |
{ |
80 | |
|
81 | 0 | log.debug( "Error policy set to IGNORE." ); |
82 | 0 | return false; |
83 | |
} |
84 | |
|
85 | 0 | String repositoryId = request.getProperty( "remoteRepositoryId" ); |
86 | 0 | if ( STOP.equals( policySetting ) ) |
87 | |
{ |
88 | 0 | return true; |
89 | |
} |
90 | |
|
91 | 0 | if ( QUEUE.equals( policySetting ) ) |
92 | |
{ |
93 | 0 | previousExceptions.put( repositoryId, exception ); |
94 | 0 | return true; |
95 | |
} |
96 | |
|
97 | 0 | throw new PolicyConfigurationException( |
98 | |
"Unable to process checksum policy of [" + policySetting + "], please file a bug report." ); |
99 | |
} |
100 | |
|
101 | |
public String getDefaultOption() |
102 | |
{ |
103 | 0 | return QUEUE; |
104 | |
} |
105 | |
|
106 | |
public String getId() |
107 | |
{ |
108 | 0 | return "propagate-errors"; |
109 | |
} |
110 | |
|
111 | |
public String getName() |
112 | |
{ |
113 | 0 | return "On remote error"; |
114 | |
} |
115 | |
|
116 | |
public List<String> getOptions() |
117 | |
{ |
118 | 0 | return options; |
119 | |
} |
120 | |
} |