aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-base
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2019-09-06 21:14:28 +0200
committerMartin Stockhammer <martin_s@apache.org>2019-09-06 21:14:28 +0200
commit363c4c96083a5e4e80766c87fe15912866dc568f (patch)
tree6fcbdf95d5f9dead8849a38a7e47b7d2f0b6eb5d /archiva-modules/archiva-base
parentbc6065c1411229ba124283efa7fd4fce31f144f4 (diff)
downloadarchiva-363c4c96083a5e4e80766c87fe15912866dc568f.tar.gz
archiva-363c4c96083a5e4e80766c87fe15912866dc568f.zip
Switching to enum for policy options
Diffstat (limited to 'archiva-modules/archiva-base')
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java12
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/MavenProxyPropertyLoader.java4
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/AbstractPolicy.java10
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/AbstractUpdatePolicy.java16
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/CachedFailuresPolicy.java12
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/ChecksumOption.java56
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/ChecksumPolicy.java14
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/DownloadErrorOption.java55
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/DownloadErrorPolicy.java2
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/DownloadPolicy.java2
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/Policy.java8
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/PolicyOption.java33
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/PolicyUtil.java34
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/PropagateErrorsDownloadPolicy.java15
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/PropagateErrorsOnUpdateDownloadPolicy.java12
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/ReleasesPolicy.java2
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/SnapshotsPolicy.java2
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/StandardOption.java55
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/UpdateOption.java54
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/CachedFailuresPolicyTest.java10
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/ChecksumPolicyTest.java19
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/PropagateErrorsDownloadPolicyTest.java14
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/PropagateErrorsOnUpdateDownloadPolicyTest.java10
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/ReleasePolicyTest.java26
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/SnapshotsPolicyTest.java26
-rw-r--r--archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyHandler.java19
26 files changed, 404 insertions, 118 deletions
diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java
index fb940af02..b8b78d3b1 100644
--- a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java
+++ b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java
@@ -323,19 +323,19 @@ public class DefaultArchivaConfiguration
// Upgrade old policy settings.
if ("releases".equals(policyId) || "snapshots".equals(policyId)) {
if ("ignored".equals(setting)) {
- setting = AbstractUpdatePolicy.ALWAYS;
+ setting = AbstractUpdatePolicy.ALWAYS.getId();
} else if ("disabled".equals(setting)) {
- setting = AbstractUpdatePolicy.NEVER;
+ setting = AbstractUpdatePolicy.NEVER.getId();
}
} else if ("cache-failures".equals(policyId)) {
if ("ignored".equals(setting)) {
- setting = CachedFailuresPolicy.NO;
+ setting = CachedFailuresPolicy.NO.getId();
} else if ("cached".equals(setting)) {
- setting = CachedFailuresPolicy.YES;
+ setting = CachedFailuresPolicy.YES.getId();
}
} else if ("checksum".equals(policyId)) {
if ("ignored".equals(setting)) {
- setting = ChecksumPolicy.IGNORE;
+ setting = ChecksumPolicy.IGNORE.getId();
}
}
@@ -344,7 +344,7 @@ public class DefaultArchivaConfiguration
Policy policy = findPolicy(policyId);
// Does option exist?
if (!policy.getOptions().contains(setting)) {
- setting = policy.getDefaultOption();
+ setting = policy.getDefaultOption().getId();
}
connector.addPolicy(policyId, setting);
} else {
diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/MavenProxyPropertyLoader.java b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/MavenProxyPropertyLoader.java
index 5f9de1910..20e3f34cf 100644
--- a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/MavenProxyPropertyLoader.java
+++ b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/MavenProxyPropertyLoader.java
@@ -104,8 +104,8 @@ public class MavenProxyPropertyLoader
proxyConnector.setTargetRepoId( key );
proxyConnector.setProxyId( proxyKey );
// TODO: convert cachePeriod to closest "daily" or "hourly"
- proxyConnector.addPolicy( ProxyConnectorConfiguration.POLICY_SNAPSHOTS, SnapshotsPolicy.DAILY );
- proxyConnector.addPolicy( ProxyConnectorConfiguration.POLICY_RELEASES, ReleasesPolicy.ALWAYS );
+ proxyConnector.addPolicy( ProxyConnectorConfiguration.POLICY_SNAPSHOTS, SnapshotsPolicy.DAILY.getId() );
+ proxyConnector.addPolicy( ProxyConnectorConfiguration.POLICY_RELEASES, ReleasesPolicy.ALWAYS.getId() );
configuration.addProxyConnector( proxyConnector );
}
diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/AbstractPolicy.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/AbstractPolicy.java
index 2c6188687..daf45413b 100644
--- a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/AbstractPolicy.java
+++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/AbstractPolicy.java
@@ -82,17 +82,17 @@ public abstract class AbstractPolicy implements Policy {
@Override
public String getDescription(Locale locale) {
return MessageFormat.format(getBundle(locale).getString(getPolicyPrefix() + "description")
- , getOptions().stream().collect(Collectors.joining(",")));
+ , getOptions().stream().map(o -> o.getId()).collect(Collectors.joining(",")));
}
@Override
- public String getOptionDescription(Locale locale, String option) {
- return getBundle(locale).getString(getOptionPrefix()+option+".description");
+ public String getOptionDescription(Locale locale, PolicyOption option) {
+ return getBundle(locale).getString(getOptionPrefix()+option.getId()+".description");
}
@Override
- public String getOptionName(Locale locale, String option) {
- return getBundle(locale).getString(getOptionPrefix()+option+".name");
+ public String getOptionName(Locale locale, PolicyOption option) {
+ return getBundle(locale).getString(getOptionPrefix()+option.getId()+".name");
}
}
diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/AbstractUpdatePolicy.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/AbstractUpdatePolicy.java
index ef2bc7bff..f8259edb8 100644
--- a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/AbstractUpdatePolicy.java
+++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/AbstractUpdatePolicy.java
@@ -43,12 +43,12 @@ public abstract class AbstractUpdatePolicy
/**
* The ALWAYS policy setting means that the artifact is always updated from the remote repo.
*/
- public static final String ALWAYS = "always";
+ public static final PolicyOption ALWAYS = UpdateOption.ALWAYS;
/**
* The NEVER policy setting means that the artifact is never updated from the remote repo.
*/
- public static final String NEVER = "never";
+ public static final PolicyOption NEVER = UpdateOption.NEVER;
/**
* <p>
@@ -60,7 +60,7 @@ public abstract class AbstractUpdatePolicy
* <li>The local artifact has a last modified timestamp older than (now - 1 day).</li>
* </ul>
*/
- public static final String DAILY = "daily";
+ public static final UpdateOption DAILY = UpdateOption.DAILY;
/**
* <p>
@@ -72,16 +72,16 @@ public abstract class AbstractUpdatePolicy
* <li>The local artifact has a last modified timestamp older than (now - 1 hour).</li>
* </ul>
*/
- public static final String HOURLY = "hourly";
+ public static final UpdateOption HOURLY = UpdateOption.HOURLY;
/**
* The ONCE policy means that the artifact retrieval occurs only if the
* local artifact is not present. This means that the retrieval can only
* occur once.
*/
- public static final String ONCE = "once";
+ public static final UpdateOption ONCE = UpdateOption.ONCE;
- private List<String> options = new ArrayList<>( 5 );
+ private List<PolicyOption> options = new ArrayList<>( 5 );
public AbstractUpdatePolicy()
{
@@ -99,13 +99,13 @@ public abstract class AbstractUpdatePolicy
protected abstract String getUpdateMode();
@Override
- public List<String> getOptions()
+ public List<PolicyOption> getOptions()
{
return options;
}
@Override
- public void applyPolicy( String policySetting, Properties request, StorageAsset localFile )
+ public void applyPolicy( PolicyOption policySetting, Properties request, StorageAsset localFile )
throws PolicyViolationException, PolicyConfigurationException
{
if ( !StringUtils.equals( request.getProperty( "filetype" ), "artifact" ) )
diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/CachedFailuresPolicy.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/CachedFailuresPolicy.java
index 98176fb2a..6f010abf0 100644
--- a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/CachedFailuresPolicy.java
+++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/CachedFailuresPolicy.java
@@ -45,18 +45,18 @@ public class CachedFailuresPolicy
* The NO policy setting means that the the existence of old failures is <strong>not</strong> checked.
* All resource requests are allowed thru to the remote repo.
*/
- public static final String NO = "no";
+ public static final StandardOption NO = StandardOption.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";
+ public static final StandardOption YES = StandardOption.YES;
@Inject
private UrlFailureCache urlFailureCache;
- private List<String> options = new ArrayList<>( 2 );
+ private List<PolicyOption> options = new ArrayList<>( 2 );
public CachedFailuresPolicy()
{
@@ -66,7 +66,7 @@ public class CachedFailuresPolicy
}
@Override
- public void applyPolicy( String policySetting, Properties request, StorageAsset localFile )
+ public void applyPolicy( PolicyOption policySetting, Properties request, StorageAsset localFile )
throws PolicyViolationException, PolicyConfigurationException
{
if ( !options.contains( policySetting ) )
@@ -99,7 +99,7 @@ public class CachedFailuresPolicy
}
@Override
- public String getDefaultOption()
+ public PolicyOption getDefaultOption()
{
return NO;
}
@@ -112,7 +112,7 @@ public class CachedFailuresPolicy
@Override
- public List<String> getOptions()
+ public List<PolicyOption> getOptions()
{
return options;
}
diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/ChecksumOption.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/ChecksumOption.java
new file mode 100644
index 000000000..f4629eb86
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/ChecksumOption.java
@@ -0,0 +1,56 @@
+package org.apache.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.
+ */
+
+/**
+ * Options for checksum policy
+ *
+ * @author Martin Stockhammer <martin_s@apache.org>
+ */
+public enum ChecksumOption implements PolicyOption {
+
+ IGNORE("ignore"),FAIL("fail"),FIX("fix");
+
+ private final String id;
+
+ ChecksumOption(String id) {
+ this.id=id;
+ }
+
+ @Override
+ public String getId() {
+ return id;
+ }
+
+ @Override
+ public PolicyOption ofId(String id) {
+ for (StandardOption option : StandardOption.values()) {
+ if (option.getId().equals(id)) {
+ return option;
+ }
+ }
+ return StandardOption.NOOP;
+ }
+
+ @Override
+ public String toString() {
+ return id;
+ }
+}
diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/ChecksumPolicy.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/ChecksumPolicy.java
index 940e54cf1..94e8e45a5 100644
--- a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/ChecksumPolicy.java
+++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/ChecksumPolicy.java
@@ -55,25 +55,25 @@ public class ChecksumPolicy
* the state of, contents of, or validity of the checksum files are not
* checked.
*/
- public static final String IGNORE = "ignore";
+ public static final ChecksumOption IGNORE = ChecksumOption.IGNORE;
/**
* The FAIL policy indicates that if the checksum does not match the
* downloaded file, then remove the downloaded artifact, and checksum
* files, and fail the transfer to the client side.
*/
- public static final String FAIL = "fail";
+ public static final ChecksumOption FAIL = ChecksumOption.FAIL;
/**
* The FIX policy indicates that if the checksum does not match the
* downloaded file, then fix the checksum file locally, and return
* to the client side the corrected checksum.
*/
- public static final String FIX = "fix";
+ public static final ChecksumOption FIX = ChecksumOption.FIX;
private List<ChecksumAlgorithm> algorithms = Arrays.asList( ChecksumAlgorithm.SHA256, ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 );
- private List<String> options = new ArrayList<>( 3 );
+ private List<PolicyOption> options = new ArrayList<>( 3 );
public ChecksumPolicy()
{
@@ -84,7 +84,7 @@ public class ChecksumPolicy
}
@Override
- public void applyPolicy( String policySetting, Properties request, StorageAsset localFile )
+ public void applyPolicy( PolicyOption policySetting, Properties request, StorageAsset localFile )
throws PolicyViolationException, PolicyConfigurationException
{
if ( "resource".equals( request.getProperty( "filetype" ) ) )
@@ -169,7 +169,7 @@ public class ChecksumPolicy
}
@Override
- public String getDefaultOption()
+ public PolicyOption getDefaultOption()
{
return FIX;
}
@@ -181,7 +181,7 @@ public class ChecksumPolicy
}
@Override
- public List<String> getOptions()
+ public List<PolicyOption> getOptions()
{
return options;
}
diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/DownloadErrorOption.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/DownloadErrorOption.java
new file mode 100644
index 000000000..f1021b1b0
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/DownloadErrorOption.java
@@ -0,0 +1,55 @@
+package org.apache.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.
+ */
+
+/**
+ * Options for download error update policies
+ *
+ * @author Martin Stockhammer <martin_s@apache.org>
+ */
+public enum DownloadErrorOption implements PolicyOption {
+
+ STOP("stop"),QUEUE("queue-error"),IGNORE("ignore"),ALWAYS("always"), NOT_PRESENT("not-present");
+
+ private final String id;
+
+ DownloadErrorOption(String id) {
+ this.id = id;
+ }
+
+ @Override
+ public String getId() {
+ return id;
+ }
+
+ @Override
+ public PolicyOption ofId(String id) {
+ for (StandardOption option : StandardOption.values()) {
+ if (option.getId().equals(id)) {
+ return option;
+ }
+ }
+ return StandardOption.NOOP;
+ }
+
+ @Override
+ public String toString() {
+ return id;
+ }
+}
diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/DownloadErrorPolicy.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/DownloadErrorPolicy.java
index 63111a32e..5b37ac346 100644
--- a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/DownloadErrorPolicy.java
+++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/DownloadErrorPolicy.java
@@ -44,7 +44,7 @@ public interface DownloadErrorPolicy
* @return True, if the exception should be processed, False if the exception should be ignored.
* @throws PolicyConfigurationException if the policy is improperly configured
*/
- boolean applyPolicy( String policySetting, Properties request, StorageAsset localFile, Exception exception,
+ boolean applyPolicy( PolicyOption policySetting, Properties request, StorageAsset localFile, Exception exception,
Map<String, Exception> previousExceptions )
throws PolicyConfigurationException;
}
diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/DownloadPolicy.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/DownloadPolicy.java
index 1ee2713db..169dbb9c5 100644
--- a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/DownloadPolicy.java
+++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/DownloadPolicy.java
@@ -41,6 +41,6 @@ public interface DownloadPolicy
*
* @throws PolicyViolationException if the policy has been violated.
*/
- void applyPolicy( String policySetting, Properties request, StorageAsset localFile )
+ void applyPolicy( PolicyOption policySetting, Properties request, StorageAsset localFile )
throws PolicyViolationException, PolicyConfigurationException;
}
diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/Policy.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/Policy.java
index 3b3d06692..66dd57982 100644
--- a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/Policy.java
+++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/Policy.java
@@ -38,14 +38,14 @@ public interface Policy
*
* @return the list of options for this policy.
*/
- List<String> getOptions();
+ List<PolicyOption> getOptions();
/**
* Get the default option for this policy.
*
* @return the default policy for this policy.
*/
- String getDefaultOption();
+ PolicyOption getDefaultOption();
/**
* Get the id for this policy.
@@ -82,7 +82,7 @@ public interface Policy
* @return A description of the option in the requested language.
* @throws MissingResourceException if the option is not known by this policy.
*/
- String getOptionDescription(Locale locale, String option) throws MissingResourceException;
+ String getOptionDescription(Locale locale, PolicyOption option) throws MissingResourceException;
/**
* Returns a name for the given option.
@@ -91,5 +91,5 @@ public interface Policy
* @return A name in the requested language.
* @throws MissingResourceException if the option is not known by this policy.
*/
- String getOptionName(Locale locale, String option) throws MissingResourceException;
+ String getOptionName(Locale locale, PolicyOption option) throws MissingResourceException;
}
diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/PolicyOption.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/PolicyOption.java
new file mode 100644
index 000000000..55334c14e
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/PolicyOption.java
@@ -0,0 +1,33 @@
+package org.apache.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.
+ */
+
+/**
+ * Interface for all policy options. Normally they are enums.
+ * The id is a unique identifier. It is used for configuration and serialization.
+ *
+ * Implementations should always implement the #toString() method and return the id.
+ */
+public interface PolicyOption {
+
+ String getId();
+
+ PolicyOption ofId(String id);
+
+}
diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/PolicyUtil.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/PolicyUtil.java
new file mode 100644
index 000000000..755cae2e5
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/PolicyUtil.java
@@ -0,0 +1,34 @@
+package org.apache.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.
+ */
+
+/**
+ * Utility for policies.
+ *
+ * @author Martin Stockhammer <martin_s@apache.org>
+ */
+
+public class PolicyUtil {
+
+ public static PolicyOption findOption(final String id, final Policy policy) {
+ return policy.getOptions().stream().filter(o -> o.getId().equals(id)).findFirst().orElse(policy.getDefaultOption());
+ }
+
+}
diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/PropagateErrorsDownloadPolicy.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/PropagateErrorsDownloadPolicy.java
index a3ea38186..3852d7d9c 100644
--- a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/PropagateErrorsDownloadPolicy.java
+++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/PropagateErrorsDownloadPolicy.java
@@ -40,22 +40,23 @@ public class PropagateErrorsDownloadPolicy
private Logger log = LoggerFactory.getLogger( PropagateErrorsDownloadPolicy.class );
private static final String ID = "propagate-errors";
+
/**
* Signifies any error should stop searching for other proxies.
*/
- public static final String STOP = "stop";
+ public static final DownloadErrorOption STOP = DownloadErrorOption.STOP;
/**
* Propagate errors at the end after all are gathered, if there was no successful download from other proxies.
*/
- public static final String QUEUE = "queue-error";
+ public static final DownloadErrorOption QUEUE = DownloadErrorOption.QUEUE;
/**
* Ignore errors and treat as if it were not found.
*/
- public static final String IGNORE = "ignore";
+ public static final DownloadErrorOption IGNORE = DownloadErrorOption.IGNORE;
- private List<String> options = new ArrayList<>( 3 );
+ private List<PolicyOption> options = new ArrayList<>( 3 );
public PropagateErrorsDownloadPolicy()
{
@@ -65,7 +66,7 @@ public class PropagateErrorsDownloadPolicy
}
@Override
- public boolean applyPolicy( String policySetting, Properties request, StorageAsset localFile, Exception exception,
+ public boolean applyPolicy( PolicyOption policySetting, Properties request, StorageAsset localFile, Exception exception,
Map<String, Exception> previousExceptions )
throws PolicyConfigurationException
{
@@ -101,7 +102,7 @@ public class PropagateErrorsDownloadPolicy
}
@Override
- public String getDefaultOption()
+ public PolicyOption getDefaultOption()
{
return QUEUE;
}
@@ -113,7 +114,7 @@ public class PropagateErrorsDownloadPolicy
}
@Override
- public List<String> getOptions()
+ public List<PolicyOption> getOptions()
{
return options;
}
diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/PropagateErrorsOnUpdateDownloadPolicy.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/PropagateErrorsOnUpdateDownloadPolicy.java
index 579980607..d299fd67e 100644
--- a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/PropagateErrorsOnUpdateDownloadPolicy.java
+++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/PropagateErrorsOnUpdateDownloadPolicy.java
@@ -40,14 +40,14 @@ public class PropagateErrorsOnUpdateDownloadPolicy
/**
* Signifies any error should cause a failure whether the artifact is already present or not.
*/
- public static final String ALWAYS = "always";
+ public static final DownloadErrorOption ALWAYS = DownloadErrorOption.ALWAYS;
/**
* Signifies any error should cause a failure only if the artifact is not already present.
*/
- public static final String NOT_PRESENT = "artifact-not-present";
+ public static final DownloadErrorOption NOT_PRESENT = DownloadErrorOption.NOT_PRESENT;
- private static final List<String> options = new ArrayList<>( 2 );
+ private static final List<PolicyOption> options = new ArrayList<>( 2 );
public PropagateErrorsOnUpdateDownloadPolicy()
{
@@ -56,7 +56,7 @@ public class PropagateErrorsOnUpdateDownloadPolicy
}
@Override
- public boolean applyPolicy( String policySetting, Properties request, StorageAsset localFile, Exception exception,
+ public boolean applyPolicy( PolicyOption policySetting, Properties request, StorageAsset localFile, Exception exception,
Map<String, Exception> previousExceptions )
throws PolicyConfigurationException
{
@@ -85,7 +85,7 @@ public class PropagateErrorsOnUpdateDownloadPolicy
}
@Override
- public String getDefaultOption()
+ public PolicyOption getDefaultOption()
{
return NOT_PRESENT;
}
@@ -98,7 +98,7 @@ public class PropagateErrorsOnUpdateDownloadPolicy
@Override
- public List<String> getOptions()
+ public List<PolicyOption> getOptions()
{
return options;
}
diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/ReleasesPolicy.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/ReleasesPolicy.java
index bd863a529..029ff7411 100644
--- a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/ReleasesPolicy.java
+++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/ReleasesPolicy.java
@@ -38,7 +38,7 @@ public class ReleasesPolicy
* Defaults to {@link AbstractUpdatePolicy#HOURLY}
*/
@Override
- public String getDefaultOption()
+ public PolicyOption getDefaultOption()
{
return AbstractUpdatePolicy.HOURLY;
}
diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/SnapshotsPolicy.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/SnapshotsPolicy.java
index 2c37b80e2..69e1cbcf7 100644
--- a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/SnapshotsPolicy.java
+++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/SnapshotsPolicy.java
@@ -39,7 +39,7 @@ public class SnapshotsPolicy
* Defaults to {@link AbstractUpdatePolicy#HOURLY}
*/
@Override
- public String getDefaultOption()
+ public PolicyOption getDefaultOption()
{
return AbstractUpdatePolicy.HOURLY;
}
diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/StandardOption.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/StandardOption.java
new file mode 100644
index 000000000..24e7821b8
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/StandardOption.java
@@ -0,0 +1,55 @@
+package org.apache.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.
+ */
+
+/**
+ * Standard Options for policies.
+ *
+ * @author Martin Stockhammer <martin_s@apache.org>
+ */
+public enum StandardOption implements PolicyOption {
+
+ NOOP("noop"),YES("yes"),NO("no");
+
+ private final String id;
+
+ StandardOption(String id) {
+ this.id = id;
+ }
+
+ @Override
+ public String getId() {
+ return id;
+ }
+
+ @Override
+ public PolicyOption ofId(String id) {
+ for (StandardOption option : StandardOption.values()) {
+ if (option.getId().equals(id)) {
+ return option;
+ }
+ }
+ return NOOP;
+ }
+
+ @Override
+ public String toString() {
+ return id;
+ }
+}
diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/UpdateOption.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/UpdateOption.java
new file mode 100644
index 000000000..1b20f6736
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/UpdateOption.java
@@ -0,0 +1,54 @@
+package org.apache.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.
+ */
+
+/**
+ * Options for update policies
+ *
+ * @author Martin Stockhammer <martin_s@apache.org>
+ */
+public enum UpdateOption implements PolicyOption {
+ ALWAYS("always"), NEVER("never"), DAILY("daily"), HOURLY("hourly"), ONCE("once");
+
+ private final String id;
+
+ UpdateOption(String id) {
+ this.id=id;
+ }
+
+ @Override
+ public String getId() {
+ return id;
+ }
+
+ @Override
+ public PolicyOption ofId(String id) {
+ for (StandardOption option : StandardOption.values()) {
+ if (option.getId().equals(id)) {
+ return option;
+ }
+ }
+ return StandardOption.NOOP;
+ }
+
+ @Override
+ public String toString() {
+ return id;
+ }
+}
diff --git a/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/CachedFailuresPolicyTest.java b/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/CachedFailuresPolicyTest.java
index f103f94bb..27cda9728 100644
--- a/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/CachedFailuresPolicyTest.java
+++ b/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/CachedFailuresPolicyTest.java
@@ -127,12 +127,12 @@ public class CachedFailuresPolicyTest
DownloadPolicy policy = lookupPolicy();
assertEquals("Cache Failures Policy", policy.getName());
assertTrue(policy.getDescription(Locale.US).contains("if download failures will be cached"));
- assertEquals("Yes", policy.getOptionName(Locale.US, "yes"));
- assertEquals("No", policy.getOptionName(Locale.US, "no"));
- assertTrue(policy.getOptionDescription(Locale.US, "yes").contains("failures are cached and download is not attempted"));
- assertTrue(policy.getOptionDescription(Locale.US, "no").contains("failures are not cached"));
+ assertEquals("Yes", policy.getOptionName(Locale.US, StandardOption.YES));
+ assertEquals("No", policy.getOptionName(Locale.US, StandardOption.NO));
+ assertTrue(policy.getOptionDescription(Locale.US, StandardOption.YES).contains("failures are cached and download is not attempted"));
+ assertTrue(policy.getOptionDescription(Locale.US, StandardOption.NO).contains("failures are not cached"));
try {
- policy.getOptionName(Locale.US, "xxxx");
+ policy.getOptionName(Locale.US, StandardOption.NOOP);
// Exception should be thrown
assertTrue(false);
} catch (MissingResourceException e) {
diff --git a/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/ChecksumPolicyTest.java b/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/ChecksumPolicyTest.java
index e13664547..d4c131c8e 100644
--- a/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/ChecksumPolicyTest.java
+++ b/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/ChecksumPolicyTest.java
@@ -19,6 +19,7 @@ package org.apache.archiva.policies;
* under the License.
*/
+import org.apache.archiva.checksum.Checksum;
import org.apache.archiva.common.filelock.DefaultFileLockManager;
import org.apache.archiva.repository.storage.FilesystemStorage;
import org.apache.archiva.repository.storage.StorageAsset;
@@ -305,11 +306,11 @@ public class ChecksumPolicyTest
}
}
- private String createMessage( String settingType, String md5State, String sha1State )
+ private String createMessage( PolicyOption settingType, String md5State, String sha1State )
{
StringBuilder msg = new StringBuilder();
msg.append( "Expected result of ChecksumPolicy.apply(" );
- msg.append( settingType.toUpperCase() );
+ msg.append( settingType.getId().toUpperCase() );
msg.append( ") when working with " );
if ( md5State == null )
{
@@ -388,14 +389,14 @@ public class ChecksumPolicyTest
PostDownloadPolicy policy = lookupPolicy();
assertEquals("Checksum Policy", policy.getName());
assertTrue(policy.getDescription(Locale.US).contains("if the downloaded checksum of a artifact does not match"));
- assertEquals("Fail, if no match", policy.getOptionName(Locale.US, "fail"));
- assertEquals("Fix, if no match", policy.getOptionName(Locale.US, "fix"));
- assertEquals("Ignore, if no match", policy.getOptionName(Locale.US, "ignore"));
- assertTrue(policy.getOptionDescription(Locale.US, "fail").contains("download fails"));
- assertTrue(policy.getOptionDescription(Locale.US, "fix").contains("artifact will remain"));
- assertTrue(policy.getOptionDescription(Locale.US, "ignore").contains("error will be ignored"));
+ assertEquals("Fail, if no match", policy.getOptionName(Locale.US, ChecksumOption.FAIL));
+ assertEquals("Fix, if no match", policy.getOptionName(Locale.US, ChecksumOption.FIX));
+ assertEquals("Ignore, if no match", policy.getOptionName(Locale.US, ChecksumOption.IGNORE));
+ assertTrue(policy.getOptionDescription(Locale.US, ChecksumOption.FAIL).contains("download fails"));
+ assertTrue(policy.getOptionDescription(Locale.US, ChecksumOption.FIX).contains("artifact will remain"));
+ assertTrue(policy.getOptionDescription(Locale.US, ChecksumOption.IGNORE).contains("error will be ignored"));
try {
- policy.getOptionName(Locale.US, "xxxx");
+ policy.getOptionName(Locale.US, StandardOption.NOOP);
// Exception should be thrown
assertTrue(false);
} catch (MissingResourceException e) {
diff --git a/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/PropagateErrorsDownloadPolicyTest.java b/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/PropagateErrorsDownloadPolicyTest.java
index c169361fe..4aff8c7ab 100644
--- a/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/PropagateErrorsDownloadPolicyTest.java
+++ b/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/PropagateErrorsDownloadPolicyTest.java
@@ -124,14 +124,14 @@ public class PropagateErrorsDownloadPolicyTest
DownloadErrorPolicy policy = lookupPolicy();
assertEquals("Propagate Download Errors Policy", policy.getName());
assertTrue(policy.getDescription(Locale.US).contains("error occurs during download"));
- assertEquals("Stop on error", policy.getOptionName(Locale.US, "stop"));
- assertEquals("Continue on error", policy.getOptionName(Locale.US, "queue-error"));
- assertEquals("Ignore errors", policy.getOptionName(Locale.US, "ignore"));
- assertTrue(policy.getOptionDescription(Locale.US, "stop").contains("Stops the artifact download"));
- assertTrue(policy.getOptionDescription(Locale.US, "queue-error").contains("Checks further"));
- assertTrue(policy.getOptionDescription(Locale.US, "ignore").contains("not found"));
+ assertEquals("Stop on error", policy.getOptionName(Locale.US, DownloadErrorOption.STOP));
+ assertEquals("Continue on error", policy.getOptionName(Locale.US, DownloadErrorOption.QUEUE));
+ assertEquals("Ignore errors", policy.getOptionName(Locale.US, DownloadErrorOption.IGNORE));
+ assertTrue(policy.getOptionDescription(Locale.US, DownloadErrorOption.STOP).contains("Stops the artifact download"));
+ assertTrue(policy.getOptionDescription(Locale.US, DownloadErrorOption.QUEUE).contains("Checks further"));
+ assertTrue(policy.getOptionDescription(Locale.US, DownloadErrorOption.IGNORE).contains("not found"));
try {
- policy.getOptionName(Locale.US, "xxxx");
+ policy.getOptionName(Locale.US, StandardOption.NOOP);
// Exception should be thrown
assertTrue(false);
} catch (MissingResourceException e) {
diff --git a/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/PropagateErrorsOnUpdateDownloadPolicyTest.java b/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/PropagateErrorsOnUpdateDownloadPolicyTest.java
index 303e7a09c..9c09bd92f 100644
--- a/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/PropagateErrorsOnUpdateDownloadPolicyTest.java
+++ b/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/PropagateErrorsOnUpdateDownloadPolicyTest.java
@@ -117,12 +117,12 @@ public class PropagateErrorsOnUpdateDownloadPolicyTest
DownloadErrorPolicy policy = lookupPolicy();
assertEquals("Propagate Errors on Update Policy", policy.getName());
assertTrue(policy.getDescription(Locale.US).contains("during download of an artifact that exists already"));
- assertEquals("Propagate always", policy.getOptionName(Locale.US, "always"));
- assertEquals("Propagate only, if not exists", policy.getOptionName(Locale.US, "not-present"));
- assertTrue(policy.getOptionDescription(Locale.US, "always").contains("even if the file exists"));
- assertTrue(policy.getOptionDescription(Locale.US, "not-present").contains("if the file does not exist"));
+ assertEquals("Propagate always", policy.getOptionName(Locale.US, DownloadErrorOption.ALWAYS));
+ assertEquals("Propagate only, if not exists", policy.getOptionName(Locale.US, DownloadErrorOption.NOT_PRESENT));
+ assertTrue(policy.getOptionDescription(Locale.US, DownloadErrorOption.ALWAYS).contains("even if the file exists"));
+ assertTrue(policy.getOptionDescription(Locale.US, DownloadErrorOption.NOT_PRESENT).contains("if the file does not exist"));
try {
- policy.getOptionName(Locale.US, "xxxx");
+ policy.getOptionName(Locale.US, StandardOption.NOOP);
// Exception should be thrown
assertTrue(false);
} catch (MissingResourceException e) {
diff --git a/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/ReleasePolicyTest.java b/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/ReleasePolicyTest.java
index 92d2ece89..6b9efa20f 100644
--- a/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/ReleasePolicyTest.java
+++ b/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/ReleasePolicyTest.java
@@ -327,7 +327,7 @@ public class ReleasePolicyTest
assertReleasesPolicy( ReleasesPolicy.ONCE, PATH_VERSION_METADATA, WITH_LOCAL );
}
- private void assertReleasesPolicy( String setting, String path, boolean createLocalFile )
+ private void assertReleasesPolicy( PolicyOption setting, String path, boolean createLocalFile )
throws Exception
{
PreDownloadPolicy policy = lookupPolicy();
@@ -360,7 +360,7 @@ public class ReleasePolicyTest
policy.applyPolicy( setting, request, localFile );
}
- private void assertReleasesPolicyViolation( String setting, String path, boolean createLocalFile )
+ private void assertReleasesPolicyViolation( PolicyOption setting, String path, boolean createLocalFile )
throws Exception
{
try
@@ -394,18 +394,18 @@ public class ReleasePolicyTest
PreDownloadPolicy policy = lookupPolicy();
assertEquals("Release Artifact Update Policy", policy.getName());
assertTrue(policy.getDescription(Locale.US).contains("when a release artifact will be updated"));
- assertEquals("Update always", policy.getOptionName(Locale.US, "always"));
- assertEquals("Do not download from remote", policy.getOptionName(Locale.US, "never"));
- assertEquals("Update, if older than a day", policy.getOptionName(Locale.US, "daily"));
- assertEquals("Update, if older than a hour", policy.getOptionName(Locale.US, "hourly"));
- assertEquals("Download only once", policy.getOptionName(Locale.US, "once"));
- assertTrue(policy.getOptionDescription(Locale.US, "always").contains("each download"));
- assertTrue(policy.getOptionDescription(Locale.US, "never").contains("never from the remote"));
- assertTrue(policy.getOptionDescription(Locale.US, "daily").contains("older than one day"));
- assertTrue(policy.getOptionDescription(Locale.US, "hourly").contains("older than one hour"));
- assertTrue(policy.getOptionDescription(Locale.US, "once").contains("if it does not exist"));
+ assertEquals("Update always", policy.getOptionName(Locale.US, UpdateOption.ALWAYS));
+ assertEquals("Do not download from remote", policy.getOptionName(Locale.US, UpdateOption.NEVER));
+ assertEquals("Update, if older than a day", policy.getOptionName(Locale.US, UpdateOption.DAILY));
+ assertEquals("Update, if older than a hour", policy.getOptionName(Locale.US, UpdateOption.HOURLY));
+ assertEquals("Download only once", policy.getOptionName(Locale.US, UpdateOption.ONCE));
+ assertTrue(policy.getOptionDescription(Locale.US, UpdateOption.ALWAYS).contains("each download"));
+ assertTrue(policy.getOptionDescription(Locale.US, UpdateOption.NEVER).contains("never from the remote"));
+ assertTrue(policy.getOptionDescription(Locale.US, UpdateOption.DAILY).contains("older than one day"));
+ assertTrue(policy.getOptionDescription(Locale.US, UpdateOption.HOURLY).contains("older than one hour"));
+ assertTrue(policy.getOptionDescription(Locale.US, UpdateOption.ONCE).contains("if it does not exist"));
try {
- policy.getOptionName(Locale.US, "xxxx");
+ policy.getOptionName(Locale.US, StandardOption.NOOP);
// Exception should be thrown
assertTrue(false);
} catch (MissingResourceException e) {
diff --git a/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/SnapshotsPolicyTest.java b/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/SnapshotsPolicyTest.java
index 39a8afe4a..635d216c4 100644
--- a/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/SnapshotsPolicyTest.java
+++ b/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/SnapshotsPolicyTest.java
@@ -326,7 +326,7 @@ public class SnapshotsPolicyTest
assertSnapshotPolicy( SnapshotsPolicy.ONCE, PATH_VERSION_METADATA, WITH_LOCAL );
}
- private void assertSnapshotPolicy( String setting, String path, boolean createLocalFile )
+ private void assertSnapshotPolicy( PolicyOption setting, String path, boolean createLocalFile )
throws Exception
{
PreDownloadPolicy policy = lookupPolicy();
@@ -359,7 +359,7 @@ public class SnapshotsPolicyTest
policy.applyPolicy( setting, request, localFile );
}
- private void assertSnapshotPolicyViolation( String setting, String path, boolean createLocalFile )
+ private void assertSnapshotPolicyViolation( PolicyOption setting, String path, boolean createLocalFile )
throws Exception
{
try
@@ -393,18 +393,18 @@ public class SnapshotsPolicyTest
PreDownloadPolicy policy = lookupPolicy();
assertEquals("Snapshot Artifact Update Policy", policy.getName());
assertTrue(policy.getDescription(Locale.US).contains("when a snapshot artifact will be updated"));
- assertEquals("Update always", policy.getOptionName(Locale.US, "always"));
- assertEquals("Do not download from remote", policy.getOptionName(Locale.US, "never"));
- assertEquals("Update, if older than a day", policy.getOptionName(Locale.US, "daily"));
- assertEquals("Update, if older than a hour", policy.getOptionName(Locale.US, "hourly"));
- assertEquals("Download only once", policy.getOptionName(Locale.US, "once"));
- assertTrue(policy.getOptionDescription(Locale.US, "always").contains("each download"));
- assertTrue(policy.getOptionDescription(Locale.US, "never").contains("never from the remote"));
- assertTrue(policy.getOptionDescription(Locale.US, "daily").contains("older than one day"));
- assertTrue(policy.getOptionDescription(Locale.US, "hourly").contains("older than one hour"));
- assertTrue(policy.getOptionDescription(Locale.US, "once").contains("if it does not exist"));
+ assertEquals("Update always", policy.getOptionName(Locale.US, UpdateOption.ALWAYS));
+ assertEquals("Do not download from remote", policy.getOptionName(Locale.US, UpdateOption.NEVER));
+ assertEquals("Update, if older than a day", policy.getOptionName(Locale.US, UpdateOption.DAILY));
+ assertEquals("Update, if older than a hour", policy.getOptionName(Locale.US, UpdateOption.HOURLY));
+ assertEquals("Download only once", policy.getOptionName(Locale.US, UpdateOption.ONCE));
+ assertTrue(policy.getOptionDescription(Locale.US, UpdateOption.ALWAYS).contains("each download"));
+ assertTrue(policy.getOptionDescription(Locale.US, UpdateOption.NEVER).contains("never from the remote"));
+ assertTrue(policy.getOptionDescription(Locale.US, UpdateOption.DAILY).contains("older than one day"));
+ assertTrue(policy.getOptionDescription(Locale.US, UpdateOption.HOURLY).contains("older than one hour"));
+ assertTrue(policy.getOptionDescription(Locale.US, UpdateOption.ONCE).contains("if it does not exist"));
try {
- policy.getOptionName(Locale.US, "xxxx");
+ policy.getOptionName(Locale.US, StandardOption.NOOP);
// Exception should be thrown
assertTrue(false);
} catch (MissingResourceException e) {
diff --git a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyHandler.java b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyHandler.java
index c524524f9..f954158c6 100644
--- a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyHandler.java
+++ b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyHandler.java
@@ -711,9 +711,9 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
* @param policies the map of policies to execute. (Map of String policy keys, to {@link DownloadPolicy} objects)
* @param settings the map of settings for the policies to execute. (Map of String policy keys, to String policy
* setting)
- * @param request the request properties (utilized by the {@link DownloadPolicy#applyPolicy(String, Properties, StorageAsset)}
+ * @param request the request properties (utilized by the {@link DownloadPolicy#applyPolicy(PolicyOption, Properties, StorageAsset)}
* )
- * @param localFile the local file (utilized by the {@link DownloadPolicy#applyPolicy(String, Properties, StorageAsset)})
+ * @param localFile the local file (utilized by the {@link DownloadPolicy#applyPolicy(PolicyOption, Properties, StorageAsset)})
* @throws PolicyViolationException
*/
private void validatePolicies( Map<String, ? extends DownloadPolicy> policies, Map<String, String> settings,
@@ -726,14 +726,12 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
// so substring after last # to get the hint as with plexus
String key = StringUtils.substringAfterLast( entry.getKey(), "#" );
DownloadPolicy policy = entry.getValue();
- String defaultSetting = policy.getDefaultOption();
+ PolicyOption option = PolicyUtil.findOption(settings.get(key), policy);
- String setting = StringUtils.defaultString( settings.get( key ), defaultSetting );
-
- log.debug( "Applying [{}] policy with [{}]", key, setting );
+ log.debug( "Applying [{}] policy with [{}]", key, option );
try
{
- policy.applyPolicy( setting, request, localFile );
+ policy.applyPolicy( option, request, localFile );
}
catch ( PolicyConfigurationException e )
{
@@ -755,14 +753,13 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
// so substring after last # to get the hint as with plexus
String key = StringUtils.substringAfterLast( entry.getKey(), "#" );
DownloadErrorPolicy policy = entry.getValue();
- String defaultSetting = policy.getDefaultOption();
- String setting = StringUtils.defaultString( settings.get( key ), defaultSetting );
+ PolicyOption option = PolicyUtil.findOption(settings.get(key), policy);
- log.debug( "Applying [{}] policy with [{}]", key, setting );
+ log.debug( "Applying [{}] policy with [{}]", key, option );
try
{
// all policies must approve the exception, any can cancel
- process = policy.applyPolicy( setting, request, localFile, exception, previousExceptions );
+ process = policy.applyPolicy( option, request, localFile, exception, previousExceptions );
if ( !process )
{
break;