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
23 import java.util.ArrayList;
24 import java.util.List;
26 import java.util.Properties;
28 import org.apache.commons.lang.StringUtils;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.stereotype.Service;
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 @Service("downloadErrorPolicy#propagate-errors")
40 public class PropagateErrorsDownloadPolicy
41 implements DownloadErrorPolicy
43 private Logger log = LoggerFactory.getLogger( PropagateErrorsDownloadPolicy.class );
46 * Signifies any error should stop searching for other proxies.
48 public static final String STOP = "stop";
51 * Propagate errors at the end after all are gathered, if there was no successful download from other proxies.
53 public static final String QUEUE = "queue error";
56 * Ignore errors and treat as if it were not found.
58 public static final String IGNORE = "ignore";
60 private List<String> options = new ArrayList<String>();
62 public PropagateErrorsDownloadPolicy()
66 options.add( IGNORE );
69 public boolean applyPolicy( String policySetting, Properties request, File localFile, Exception exception,
70 Map<String, Exception> previousExceptions )
71 throws PolicyConfigurationException
73 if ( !options.contains( policySetting ) )
76 throw new PolicyConfigurationException( "Unknown error policy setting [" + policySetting +
77 "], valid settings are [" + StringUtils.join( options.iterator(), "," ) + "]" );
80 if ( IGNORE.equals( policySetting ) )
83 log.debug( "Error policy set to IGNORE." );
87 String repositoryId = request.getProperty( "remoteRepositoryId" );
88 if ( STOP.equals( policySetting ) )
93 if ( QUEUE.equals( policySetting ) )
95 previousExceptions.put( repositoryId, exception );
99 throw new PolicyConfigurationException(
100 "Unable to process checksum policy of [" + policySetting + "], please file a bug report." );
103 public String getDefaultOption()
108 public String getId()
110 return "propagate-errors";
113 public String getName()
115 return "On remote error";
118 public List<String> getOptions()