Coverage Report - org.apache.maven.archiva.policies.PropagateErrorsDownloadPolicy
 
Classes in this File Line Coverage Branch Coverage Complexity
PropagateErrorsDownloadPolicy
0%
0/23
0%
0/8
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  
 import org.slf4j.Logger;
 30  
 import org.slf4j.LoggerFactory;
 31  
 
 32  
 /**
 33  
  * PropagateErrorsPolicy - a policy applied on error to determine how to treat the error.
 34  
  *
 35  
  * @plexus.component role="org.apache.maven.archiva.policies.DownloadErrorPolicy"
 36  
  * role-hint="propagate-errors"
 37  
  */
 38  
 public class PropagateErrorsDownloadPolicy
 39  
     implements DownloadErrorPolicy
 40  
 {
 41  0
     private Logger log = LoggerFactory.getLogger( PropagateErrorsDownloadPolicy.class );
 42  
     
 43  
     /**
 44  
      * Signifies any error should stop searching for other proxies.
 45  
      */
 46  
     public static final String STOP = "stop";
 47  
 
 48  
     /**
 49  
      * Propagate errors at the end after all are gathered, if there was no successful download from other proxies.
 50  
      */
 51  
     public static final String QUEUE = "queue error";
 52  
 
 53  
     /**
 54  
      * Ignore errors and treat as if it were not found.
 55  
      */
 56  
     public static final String IGNORE = "ignore";
 57  
 
 58  0
     private List<String> options = new ArrayList<String>();
 59  
 
 60  
     public PropagateErrorsDownloadPolicy()
 61  0
     {
 62  0
         options.add( STOP );
 63  0
         options.add( QUEUE );
 64  0
         options.add( IGNORE );
 65  0
     }
 66  
 
 67  
     public boolean applyPolicy( String policySetting, Properties request, File localFile, Exception exception,
 68  
                                 Map<String, Exception> previousExceptions )
 69  
         throws PolicyConfigurationException
 70  
     {
 71  0
         if ( !options.contains( policySetting ) )
 72  
         {
 73  
             // Not a valid code.
 74  0
             throw new PolicyConfigurationException( "Unknown error policy setting [" + policySetting +
 75  
                 "], valid settings are [" + StringUtils.join( options.iterator(), "," ) + "]" );
 76  
         }
 77  
 
 78  0
         if ( IGNORE.equals( policySetting ) )
 79  
         {
 80  
             // Ignore.
 81  0
             log.debug( "Error policy set to IGNORE." );
 82  0
             return false;
 83  
         }
 84  
 
 85  0
         String repositoryId = request.getProperty( "remoteRepositoryId" );
 86  0
         if ( STOP.equals( policySetting ) )
 87  
         {
 88  0
             return true;
 89  
         }
 90  
 
 91  0
         if ( QUEUE.equals( policySetting ) )
 92  
         {
 93  0
             previousExceptions.put( repositoryId, exception );
 94  0
             return true;
 95  
         }
 96  
 
 97  0
         throw new PolicyConfigurationException(
 98  
             "Unable to process checksum policy of [" + policySetting + "], please file a bug report." );
 99  
     }
 100  
 
 101  
     public String getDefaultOption()
 102  
     {
 103  0
         return QUEUE;
 104  
     }
 105  
 
 106  
     public String getId()
 107  
     {
 108  0
         return "propagate-errors";
 109  
     }
 110  
 
 111  
     public String getName()
 112  
     {
 113  0
         return "On remote error";
 114  
     }
 115  
 
 116  
     public List<String> getOptions()
 117  
     {
 118  0
         return options;
 119  
     }
 120  
 }