1 package org.apache.maven.archiva.policies;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import org.apache.commons.lang.StringUtils;
23 import org.codehaus.plexus.logging.AbstractLogEnabled;
26 import java.util.ArrayList;
27 import java.util.List;
29 import java.util.Properties;
32 * PropagateErrorsPolicy - a policy applied on error to determine how to treat the error.
34 * @plexus.component role="org.apache.maven.archiva.policies.DownloadErrorPolicy"
35 * role-hint="propagate-errors-on-update"
37 public class PropagateErrorsOnUpdateDownloadPolicy
38 extends AbstractLogEnabled
39 implements DownloadErrorPolicy
42 * Signifies any error should cause a failure whether the artifact is already present or not.
44 public static final String ALWAYS = "always";
47 * Signifies any error should cause a failure only if the artifact is not already present.
49 public static final String NOT_PRESENT = "artifact not already present";
51 private List<String> options = new ArrayList<String>();
53 public PropagateErrorsOnUpdateDownloadPolicy()
55 options.add( ALWAYS );
56 options.add( NOT_PRESENT );
59 public boolean applyPolicy( String policySetting, Properties request, File localFile, Exception exception,
60 Map<String,Exception> previousExceptions )
61 throws PolicyConfigurationException
63 if ( !options.contains( policySetting ) )
66 throw new PolicyConfigurationException( "Unknown error policy setting [" + policySetting
67 + "], valid settings are [" + StringUtils.join( options.iterator(), "," ) + "]" );
70 if ( ALWAYS.equals( policySetting ) )
72 // throw ther exception regardless
76 if ( NOT_PRESENT.equals( policySetting ) )
78 // cancel the exception if the file exists
79 return !localFile.exists();
82 throw new PolicyConfigurationException( "Unable to process checksum policy of [" + policySetting
83 + "], please file a bug report." );
86 public String getDefaultOption()
93 return "propagate-errors-on-update";
96 public String getName()
98 return "Return error when";
101 public List<String> getOptions()