* Expanding Proxy / Policy tests.

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches/archiva-jpox-database-refactor@529107 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Joakim Erdfelt 2007-04-16 00:49:33 +00:00
parent 4e7c4eff6c
commit 46fefb7f3e
4 changed files with 37 additions and 21 deletions

View File

@ -88,62 +88,64 @@ public abstract class AbstractUpdatePolicy
}
protected abstract boolean isSnapshotPolicy();
protected abstract String getUpdateMode();
public boolean applyPolicy( String policySetting, Properties request, File localFile )
{
String version = request.getProperty( "version", "" );
boolean isSnapshotVersion = false;
if( StringUtils.isNotBlank( version ) )
if ( StringUtils.isNotBlank( version ) )
{
isSnapshotVersion = VersionUtil.isSnapshot( version );
}
// Test for mismatches.
if ( !isSnapshotVersion && isSnapshotPolicy() )
{
getLogger().debug( "Non-snapshot version detected in during snapshot policy. ignoring policy.");
return true;
}
if ( isSnapshotVersion && !isSnapshotPolicy() )
{
getLogger().debug( "Snapshot version detected in during release policy. ignoring policy.");
return true;
}
if ( !validPolicyCodes.contains( policySetting ) )
{
// No valid code? false it is then.
getLogger().error( "Unknown artifact-update policyCode [" + policySetting + "]" );
return false;
}
if ( IGNORED.equals( policySetting ) )
{
// Disabled means no.
getLogger().debug( "OK to update, policy ignored." );
// Ignored means ok to update.
getLogger().debug( "OK to update, " + getUpdateMode() + " policy set to IGNORED." );
return true;
}
// Test for mismatches.
if ( !isSnapshotVersion && isSnapshotPolicy() )
{
getLogger().debug( "OK to update, snapshot policy does not apply for non-snapshot versions." );
return true;
}
if ( isSnapshotVersion && !isSnapshotPolicy() )
{
getLogger().debug( "OK to update, release policy does not apply for snapshot versions." );
return true;
}
if ( DISABLED.equals( policySetting ) )
{
// Disabled means no.
getLogger().debug( "NO to update, disabled." );
getLogger().debug( "NO to update, " + getUpdateMode() + " policy set to DISABLED." );
return false;
}
if ( !localFile.exists() )
{
// No file means it's ok.
getLogger().debug( "OK to update, local file does not exist." );
getLogger().debug( "OK to update " + getUpdateMode() + ", local file does not exist." );
return true;
}
if ( ONCE.equals( policySetting ) )
{
// File exists, but policy is once.
getLogger().debug( "NO to update, local file exist (and policy is ONCE)." );
getLogger().debug( "NO to update" + getUpdateMode() + ", local file exist (and policy is ONCE)." );
return false;
}

View File

@ -73,6 +73,7 @@ public class CachedFailuresPolicy
if ( IGNORED.equals( policySetting ) )
{
// Ignore.
getLogger().debug( "OK to fetch, check-failures policy set to IGNORED." );
return true;
}
@ -82,9 +83,12 @@ public class CachedFailuresPolicy
{
if ( urlFailureCache.hasFailedBefore( url ) )
{
getLogger().debug( "NO to fetch, check-failures detected previous failure on url: " + url );
return false;
}
}
getLogger().debug( "OK to fetch, check-failures detected no issues." );
return true;
}

View File

@ -42,4 +42,9 @@ public class ReleasesPolicy
{
return false;
}
protected String getUpdateMode()
{
return "releases";
}
}

View File

@ -42,4 +42,9 @@ public class SnapshotsPolicy
{
return true;
}
protected String getUpdateMode()
{
return "snapshots";
}
}