org.apache.maven.archiva.policies.CachedFailuresPolicy Maven / Gradle / Ivy
package org.apache.maven.archiva.policies;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.policies.urlcache.UrlFailureCache;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
/**
* {@link PreDownloadPolicy} to check if the requested url has failed before.
*
* @author Joakim Erdfelt
* @version $Id: CachedFailuresPolicy.java 590908 2007-11-01 06:21:26Z joakime $
* @plexus.component role="org.apache.maven.archiva.policies.PreDownloadPolicy"
* role-hint="cache-failures"
*/
public class CachedFailuresPolicy
extends AbstractLogEnabled
implements PreDownloadPolicy
{
/**
* The NO policy setting means that the the existence of old failures is not checked.
* All resource requests are allowed thru to the remote repo.
*/
public static final String NO = "no";
/**
* The YES policy setting means that the existence of old failures is checked, and will
* prevent the request from being performed against the remote repo.
*/
public static final String YES = "yes";
/**
* @plexus.requirement role-hint="default"
*/
private UrlFailureCache urlFailureCache;
private List options = new ArrayList();
public CachedFailuresPolicy()
{
options.add( NO );
options.add( YES );
}
public void applyPolicy( String policySetting, Properties request, File localFile )
throws PolicyViolationException, PolicyConfigurationException
{
if ( !options.contains( policySetting ) )
{
// Not a valid code.
throw new PolicyConfigurationException( "Unknown cache-failues policy setting [" + policySetting
+ "], valid settings are [" + StringUtils.join( options.iterator(), "," ) + "]" );
}
if ( NO.equals( policySetting ) )
{
// Skip.
getLogger().debug( "OK to fetch, check-failures policy set to NO." );
return;
}
String url = request.getProperty( "url" );
if ( StringUtils.isNotBlank( url ) )
{
if ( urlFailureCache.hasFailedBefore( url ) )
{
throw new PolicyViolationException( "NO to fetch, check-failures detected previous failure on url: " + url );
}
}
getLogger().debug( "OK to fetch, check-failures detected no issues." );
}
public String getDefaultOption()
{
return NO;
}
public String getId()
{
return "cache-failures";
}
public List getOptions()
{
return options;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy