Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
PropagateErrorsOnUpdateDownloadPolicy |
|
| 0.0;0 |
1 | package org.apache.maven.archiva.policies; | |
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 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 | ||
30 | /** | |
31 | * PropagateErrorsPolicy - a policy applied on error to determine how to treat the error. | |
32 | * | |
33 | * @plexus.component role="org.apache.maven.archiva.policies.DownloadErrorPolicy" | |
34 | * role-hint="propagate-errors-on-update" | |
35 | */ | |
36 | public class PropagateErrorsOnUpdateDownloadPolicy | |
37 | implements DownloadErrorPolicy | |
38 | { | |
39 | /** | |
40 | * Signifies any error should cause a failure whether the artifact is already present or not. | |
41 | */ | |
42 | public static final String ALWAYS = "always"; | |
43 | ||
44 | /** | |
45 | * Signifies any error should cause a failure only if the artifact is not already present. | |
46 | */ | |
47 | public static final String NOT_PRESENT = "artifact not already present"; | |
48 | ||
49 | 0 | private List<String> options = new ArrayList<String>(); |
50 | ||
51 | public PropagateErrorsOnUpdateDownloadPolicy() | |
52 | 0 | { |
53 | 0 | options.add( ALWAYS ); |
54 | 0 | options.add( NOT_PRESENT ); |
55 | 0 | } |
56 | ||
57 | public boolean applyPolicy( String policySetting, Properties request, File localFile, Exception exception, | |
58 | Map<String,Exception> previousExceptions ) | |
59 | throws PolicyConfigurationException | |
60 | { | |
61 | 0 | if ( !options.contains( policySetting ) ) |
62 | { | |
63 | // Not a valid code. | |
64 | 0 | throw new PolicyConfigurationException( "Unknown error policy setting [" + policySetting |
65 | + "], valid settings are [" + StringUtils.join( options.iterator(), "," ) + "]" ); | |
66 | } | |
67 | ||
68 | 0 | if ( ALWAYS.equals( policySetting ) ) |
69 | { | |
70 | // throw ther exception regardless | |
71 | 0 | return true; |
72 | } | |
73 | ||
74 | 0 | if ( NOT_PRESENT.equals( policySetting ) ) |
75 | { | |
76 | // cancel the exception if the file exists | |
77 | 0 | return !localFile.exists(); |
78 | } | |
79 | ||
80 | 0 | throw new PolicyConfigurationException( "Unable to process checksum policy of [" + policySetting |
81 | + "], please file a bug report." ); | |
82 | } | |
83 | ||
84 | public String getDefaultOption() | |
85 | { | |
86 | 0 | return NOT_PRESENT; |
87 | } | |
88 | ||
89 | public String getId() | |
90 | { | |
91 | 0 | return "propagate-errors-on-update"; |
92 | } | |
93 | ||
94 | public String getName() | |
95 | { | |
96 | 0 | return "Return error when"; |
97 | } | |
98 | ||
99 | public List<String> getOptions() | |
100 | { | |
101 | 0 | return options; |
102 | } | |
103 | } |