diff options
author | Joakim Erdfelt <joakime@apache.org> | 2007-11-01 06:21:26 +0000 |
---|---|---|
committer | Joakim Erdfelt <joakime@apache.org> | 2007-11-01 06:21:26 +0000 |
commit | baf4c89435e946517008e02706d98029adebbdec (patch) | |
tree | 2ac4ceb5b2989411d612f700c8c2330e4d293390 /archiva-base/archiva-configuration/src | |
parent | 255949579d3ab36bf59eda5948cf28321db59e18 (diff) | |
download | archiva-baf4c89435e946517008e02706d98029adebbdec.tar.gz archiva-baf4c89435e946517008e02706d98029adebbdec.zip |
[MRM-547] proxy connectors: cache failures options are confusing
[MRM-549] proxy connectors: no "always" option for releases and snapshots policies
Applying changes to policy naming per decisions made in dev@archiva mailing list.
Updating DefaultArchivaConfiguration.load() to automatically adjust old configuration settings to new values.
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@590908 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-base/archiva-configuration/src')
3 files changed, 269 insertions, 5 deletions
diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java index 4ea345016..52701830c 100644 --- a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java +++ b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java @@ -19,10 +19,18 @@ package org.apache.maven.archiva.configuration; * under the License. */ +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.MapUtils; import org.apache.commons.io.FileUtils; import org.apache.maven.archiva.configuration.functors.ProxyConnectorConfigurationOrderComparator; import org.apache.maven.archiva.configuration.io.registry.ConfigurationRegistryReader; import org.apache.maven.archiva.configuration.io.registry.ConfigurationRegistryWriter; +import org.apache.maven.archiva.policies.AbstractUpdatePolicy; +import org.apache.maven.archiva.policies.CachedFailuresPolicy; +import org.apache.maven.archiva.policies.ChecksumPolicy; +import org.apache.maven.archiva.policies.DownloadPolicy; +import org.apache.maven.archiva.policies.PostDownloadPolicy; +import org.apache.maven.archiva.policies.PreDownloadPolicy; import org.codehaus.plexus.evaluator.DefaultExpressionEvaluator; import org.codehaus.plexus.evaluator.EvaluatorException; import org.codehaus.plexus.evaluator.ExpressionEvaluator; @@ -37,13 +45,16 @@ import org.codehaus.plexus.util.StringUtils; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.Map.Entry; /** * <p> @@ -87,9 +98,17 @@ public class DefaultArchivaConfiguration */ private Configuration configuration; - private static final String KEY = "org.apache.maven.archiva"; + /** + * @plexus.requirement role="org.apache.maven.archiva.policies.PreDownloadPolicy" + */ + private Map<String, PreDownloadPolicy> prePolicies; /** + * @plexus.requirement role="org.apache.maven.archiva.policies.PostDownloadPolicy" + */ + private Map<String, PostDownloadPolicy> postPolicies; + + /** * @plexus.configuration default-value="${user.home}/.m2/archiva.xml" */ private String userConfigFilename; @@ -115,6 +134,8 @@ public class DefaultArchivaConfiguration */ private boolean isConfigurationDefaulted = false; + private static final String KEY = "org.apache.maven.archiva"; + public synchronized Configuration getConfiguration() { if ( configuration == null ) @@ -176,9 +197,89 @@ public class DefaultArchivaConfiguration registry.removeSubset( KEY + ".repositories" ); } - // Normalize the order fields in the proxy connectors. if ( !config.getProxyConnectors().isEmpty() ) { + // Fix Proxy Connector Settings. + + List<ProxyConnectorConfiguration> proxyConnectorList = new ArrayList<ProxyConnectorConfiguration>(); + // Create a copy of the list to read from (to prevent concurrent modification exceptions) + proxyConnectorList.addAll( config.getProxyConnectors() ); + // Remove the old connector list. + config.getProxyConnectors().clear(); + + for ( ProxyConnectorConfiguration connector : proxyConnectorList ) + { + // Fix policies + boolean connectorValid = true; + + Map<String, String> policies = new HashMap<String, String>(); + // Make copy of policies + policies.putAll( connector.getPolicies() ); + // Clear out policies + connector.getPolicies().clear(); + + // Work thru policies. cleaning them up. + for ( Entry<String, String> entry : policies.entrySet() ) + { + String policyId = entry.getKey(); + String setting = entry.getValue(); + + // Upgrade old policy settings. + if ( "releases".equals( policyId ) || "snapshots".equals( policyId ) ) + { + if ( "ignored".equals( setting ) ) + { + setting = AbstractUpdatePolicy.ALWAYS; + } + else if ( "disabled".equals( setting ) ) + { + setting = AbstractUpdatePolicy.NEVER; + } + } + else if ( "cache-failures".equals( policyId ) ) + { + if ( "ignored".equals( setting ) ) + { + setting = CachedFailuresPolicy.NO; + } + else if ( "cached".equals( setting ) ) + { + setting = CachedFailuresPolicy.YES; + } + } + else if ( "checksum".equals( policyId ) ) + { + if ( "ignored".equals( setting ) ) + { + setting = ChecksumPolicy.IGNORE; + } + } + + // Validate existance of policy key. + if ( policyExists( policyId ) ) + { + DownloadPolicy policy = findPolicy( policyId ); + // Does option exist? + if ( !policy.getOptions().contains( setting ) ) + { + setting = policy.getDefaultOption(); + } + connector.addPolicy( policyId, setting ); + } + else + { + // Policy key doesn't exist. Don't add it to golden version. + getLogger().warn( "Policy [" + policyId + "] does not exist." ); + } + } + + if ( connectorValid ) + { + config.addProxyConnector( connector ); + } + } + + // Normalize the order fields in the proxy connectors. Map<String, java.util.List<ProxyConnectorConfiguration>> proxyConnectorMap = config .getProxyConnectorAsMap(); @@ -200,6 +301,54 @@ public class DefaultArchivaConfiguration return config; } + private DownloadPolicy findPolicy( String policyId ) + { + if ( MapUtils.isEmpty( prePolicies ) ) + { + getLogger().error( "No PreDownloadPolicies found!" ); + return null; + } + + if ( MapUtils.isEmpty( postPolicies ) ) + { + getLogger().error( "No PostDownloadPolicies found!" ); + return null; + } + + DownloadPolicy policy; + + policy = prePolicies.get( policyId ); + if ( policy != null ) + { + return policy; + } + + policy = postPolicies.get( policyId ); + if ( policy != null ) + { + return policy; + } + + return null; + } + + private boolean policyExists( String policyId ) + { + if ( MapUtils.isEmpty( prePolicies ) ) + { + getLogger().error( "No PreDownloadPolicies found!" ); + return false; + } + + if ( MapUtils.isEmpty( postPolicies ) ) + { + getLogger().error( "No PostDownloadPolicies found!" ); + return false; + } + + return ( prePolicies.containsKey( policyId ) || postPolicies.containsKey( policyId ) ); + } + private Registry readDefaultConfiguration() { // if it contains some old configuration, remove it (Archiva 0.9) @@ -288,7 +437,7 @@ public class DefaultArchivaConfiguration { // TODO: may not be needed under commons-configuration 1.4 - check // UPDATE: Upgrading to commons-configuration 1.4 breaks half the unit tests. 2007-10-11 (joakime) - + String contents = "<configuration />"; if ( !writeFile( "user configuration", userConfigFilename, contents ) ) { diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/MavenProxyPropertyLoader.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/MavenProxyPropertyLoader.java index 33fdb51b3..e48b2d39a 100644 --- a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/MavenProxyPropertyLoader.java +++ b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/MavenProxyPropertyLoader.java @@ -107,7 +107,7 @@ public class MavenProxyPropertyLoader proxyConnector.setProxyId( proxyKey ); // TODO: convert cachePeriod to closest "daily" or "hourly" proxyConnector.addPolicy( ProxyConnectorConfiguration.POLICY_SNAPSHOTS, SnapshotsPolicy.DAILY ); - proxyConnector.addPolicy( ProxyConnectorConfiguration.POLICY_RELEASES, ReleasesPolicy.IGNORED ); + proxyConnector.addPolicy( ProxyConnectorConfiguration.POLICY_RELEASES, ReleasesPolicy.ALWAYS ); configuration.addProxyConnector( proxyConnector ); } diff --git a/archiva-base/archiva-configuration/src/test/resources/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.xml b/archiva-base/archiva-configuration/src/test/resources/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.xml index b0ca9d638..abd8baae5 100644 --- a/archiva-base/archiva-configuration/src/test/resources/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.xml +++ b/archiva-base/archiva-configuration/src/test/resources/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.xml @@ -29,6 +29,14 @@ <role>org.codehaus.plexus.registry.Registry</role> <role-hint>empty</role-hint> </requirement> + <requirement> + <role>org.apache.maven.archiva.policies.PreDownloadPolicy</role> + <field-name>prePolicies</field-name> + </requirement> + <requirement> + <role>org.apache.maven.archiva.policies.PostDownloadPolicy</role> + <field-name>postPolicies</field-name> + </requirement> </requirements> </component> <component> @@ -48,6 +56,14 @@ <role>org.codehaus.plexus.registry.Registry</role> <role-hint>upgrade-09</role-hint> </requirement> + <requirement> + <role>org.apache.maven.archiva.policies.PreDownloadPolicy</role> + <field-name>prePolicies</field-name> + </requirement> + <requirement> + <role>org.apache.maven.archiva.policies.PostDownloadPolicy</role> + <field-name>postPolicies</field-name> + </requirement> </requirements> </component> <component> @@ -71,6 +87,14 @@ <role>org.codehaus.plexus.registry.Registry</role> <role-hint>configured</role-hint> </requirement> + <requirement> + <role>org.apache.maven.archiva.policies.PreDownloadPolicy</role> + <field-name>prePolicies</field-name> + </requirement> + <requirement> + <role>org.apache.maven.archiva.policies.PostDownloadPolicy</role> + <field-name>postPolicies</field-name> + </requirement> </requirements> </component> <component> @@ -95,6 +119,14 @@ <role>org.codehaus.plexus.registry.Registry</role> <role-hint>autodetect-v1</role-hint> </requirement> + <requirement> + <role>org.apache.maven.archiva.policies.PreDownloadPolicy</role> + <field-name>prePolicies</field-name> + </requirement> + <requirement> + <role>org.apache.maven.archiva.policies.PostDownloadPolicy</role> + <field-name>postPolicies</field-name> + </requirement> </requirements> </component> <component> @@ -120,6 +152,14 @@ <role>org.codehaus.plexus.registry.Registry</role> <role-hint>archiva-v1</role-hint> </requirement> + <requirement> + <role>org.apache.maven.archiva.policies.PreDownloadPolicy</role> + <field-name>prePolicies</field-name> + </requirement> + <requirement> + <role>org.apache.maven.archiva.policies.PostDownloadPolicy</role> + <field-name>postPolicies</field-name> + </requirement> </requirements> </component> <component> @@ -144,6 +184,14 @@ <role>org.codehaus.plexus.registry.Registry</role> <role-hint>save</role-hint> </requirement> + <requirement> + <role>org.apache.maven.archiva.policies.PreDownloadPolicy</role> + <field-name>prePolicies</field-name> + </requirement> + <requirement> + <role>org.apache.maven.archiva.policies.PostDownloadPolicy</role> + <field-name>postPolicies</field-name> + </requirement> </requirements> </component> <component> @@ -167,6 +215,14 @@ <role>org.codehaus.plexus.registry.Registry</role> <role-hint>save-user</role-hint> </requirement> + <requirement> + <role>org.apache.maven.archiva.policies.PreDownloadPolicy</role> + <field-name>prePolicies</field-name> + </requirement> + <requirement> + <role>org.apache.maven.archiva.policies.PostDownloadPolicy</role> + <field-name>postPolicies</field-name> + </requirement> </requirements> <configuration> <userConfigFilename>${basedir}/target/test/test-file-user.xml</userConfigFilename> @@ -195,6 +251,14 @@ <role>org.codehaus.plexus.registry.Registry</role> <role-hint>configuration-both</role-hint> </requirement> + <requirement> + <role>org.apache.maven.archiva.policies.PreDownloadPolicy</role> + <field-name>prePolicies</field-name> + </requirement> + <requirement> + <role>org.apache.maven.archiva.policies.PostDownloadPolicy</role> + <field-name>postPolicies</field-name> + </requirement> </requirements> </component> <component> @@ -220,6 +284,14 @@ <role>org.codehaus.plexus.registry.Registry</role> <role-hint>read-saved</role-hint> </requirement> + <requirement> + <role>org.apache.maven.archiva.policies.PreDownloadPolicy</role> + <field-name>prePolicies</field-name> + </requirement> + <requirement> + <role>org.apache.maven.archiva.policies.PostDownloadPolicy</role> + <field-name>postPolicies</field-name> + </requirement> </requirements> <configuration> <userConfigFilename>${basedir}/target/test/test-file.xml</userConfigFilename> @@ -246,6 +318,14 @@ <role>org.codehaus.plexus.registry.Registry</role> <role-hint>cron-expressions</role-hint> </requirement> + <requirement> + <role>org.apache.maven.archiva.policies.PreDownloadPolicy</role> + <field-name>prePolicies</field-name> + </requirement> + <requirement> + <role>org.apache.maven.archiva.policies.PostDownloadPolicy</role> + <field-name>postPolicies</field-name> + </requirement> </requirements> <configuration> <userConfigFilename>${basedir}/target/test/test-file.xml</userConfigFilename> @@ -272,6 +352,14 @@ <role>org.codehaus.plexus.registry.Registry</role> <role-hint>not-allowed-to-write-to-both</role-hint> </requirement> + <requirement> + <role>org.apache.maven.archiva.policies.PreDownloadPolicy</role> + <field-name>prePolicies</field-name> + </requirement> + <requirement> + <role>org.apache.maven.archiva.policies.PostDownloadPolicy</role> + <field-name>postPolicies</field-name> + </requirement> </requirements> <configuration> <user-config-filename>${basedir}/target/*intentionally:invalid*/.m2/archiva-user.xml</user-config-filename> @@ -301,6 +389,14 @@ <role>org.codehaus.plexus.registry.Registry</role> <role-hint>not-allowed-to-write-to-user</role-hint> </requirement> + <requirement> + <role>org.apache.maven.archiva.policies.PreDownloadPolicy</role> + <field-name>prePolicies</field-name> + </requirement> + <requirement> + <role>org.apache.maven.archiva.policies.PostDownloadPolicy</role> + <field-name>postPolicies</field-name> + </requirement> </requirements> <configuration> <user-config-filename>${basedir}/target/*intentionally:invalid*/.m2/archiva-user.xml</user-config-filename> @@ -320,6 +416,25 @@ </properties> </configuration> </component> - + + <component> + <role>org.codehaus.plexus.cache.Cache</role> + <role-hint>url-failures-cache</role-hint> + <implementation>org.codehaus.plexus.cache.ehcache.EhcacheCache</implementation> + <description>URL Failure Cache</description> + <configuration> + <disk-expiry-thread-interval-seconds>600</disk-expiry-thread-interval-seconds> + <disk-persistent>false</disk-persistent> + <eternal>false</eternal> + <max-elements-in-memory>1000</max-elements-in-memory> + <memory-eviction-policy>LRU</memory-eviction-policy> + <name>cache</name> + <overflow-to-disk>false</overflow-to-disk> + <!-- 45 minutes = 2700 seconds --> + <time-to-idle-seconds>2700</time-to-idle-seconds> + <!-- 30 minutes = 1800 seconds --> + <time-to-live-seconds>1800</time-to-live-seconds> + </configuration> + </component> </components> </component-set> |