1 package org.apache.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.springframework.stereotype.Service;
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 @Service( "downloadErrorPolicy#propagate-errors-on-update" )
35 public class PropagateErrorsOnUpdateDownloadPolicy
36 implements DownloadErrorPolicy
39 * Signifies any error should cause a failure whether the artifact is already present or not.
41 public static final String ALWAYS = "always";
44 * Signifies any error should cause a failure only if the artifact is not already present.
46 public static final String NOT_PRESENT = "artifact not already present";
48 private List<String> options = new ArrayList<>( 2 );
50 public PropagateErrorsOnUpdateDownloadPolicy()
52 options.add( ALWAYS );
53 options.add( NOT_PRESENT );
57 public boolean applyPolicy( String policySetting, Properties request, File localFile, Exception exception,
58 Map<String, Exception> previousExceptions )
59 throws PolicyConfigurationException
61 if ( !options.contains( policySetting ) )
64 throw new PolicyConfigurationException(
65 "Unknown error policy setting [" + policySetting + "], valid settings are [" + StringUtils.join(
66 options.iterator(), "," ) + "]" );
69 if ( ALWAYS.equals( policySetting ) )
71 // throw ther exception regardless
75 if ( NOT_PRESENT.equals( policySetting ) )
77 // cancel the exception if the file exists
78 return !localFile.exists();
81 throw new PolicyConfigurationException(
82 "Unable to process checksum policy of [" + policySetting + "], please file a bug report." );
86 public String getDefaultOption()
94 return "propagate-errors-on-update";
98 public String getName()
100 return "Return error when";
104 public List<String> getOptions()