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;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
28 import java.util.ArrayList;
29 import java.util.List;
31 import java.util.Properties;
34 * PropagateErrorsPolicy - a policy applied on error to determine how to treat the error.
36 * @plexus.component role="org.apache.maven.archiva.policies.DownloadErrorPolicy"
37 * role-hint="propagate-errors"
39 public class PropagateErrorsDownloadPolicy
40 implements DownloadErrorPolicy
42 private Logger log = LoggerFactory.getLogger( PropagateErrorsDownloadPolicy.class );
45 * Signifies any error should stop searching for other proxies.
47 public static final String STOP = "stop";
50 * Propagate errors at the end after all are gathered, if there was no successful download from other proxies.
52 public static final String QUEUE = "queue error";
55 * Ignore errors and treat as if it were not found.
57 public static final String IGNORE = "ignore";
59 private List<String> options = new ArrayList<String>();
61 public PropagateErrorsDownloadPolicy()
65 options.add( IGNORE );
68 public boolean applyPolicy( String policySetting, Properties request, File localFile, Exception exception,
69 Map<String, Exception> previousExceptions )
70 throws PolicyConfigurationException
72 if ( !options.contains( policySetting ) )
75 throw new PolicyConfigurationException( "Unknown error policy setting [" + policySetting +
76 "], valid settings are [" + StringUtils.join( options.iterator(), "," ) + "]" );
79 if ( IGNORE.equals( policySetting ) )
82 log.debug( "Error policy set to IGNORE." );
86 String repositoryId = request.getProperty( "remoteRepositoryId" );
87 if ( STOP.equals( policySetting ) )
92 if ( QUEUE.equals( policySetting ) )
94 previousExceptions.put( repositoryId, exception );
98 throw new PolicyConfigurationException(
99 "Unable to process checksum policy of [" + policySetting + "], please file a bug report." );
102 public String getDefaultOption()
107 public String getId()
109 return "propagate-errors";
112 public String getName()
114 return "On remote error";
117 public List<String> getOptions()