aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-base/archiva-policies
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2019-07-19 19:29:01 +0200
committerMartin Stockhammer <martin_s@apache.org>2019-07-19 19:29:01 +0200
commit8e4acdc82a875ca32e39eb216b879c002d228de3 (patch)
tree0c255f334dd886636ae1d1343430c89b7f1e630a /archiva-modules/archiva-base/archiva-policies
parentd599b89e3d259266373717897f8b7fd24fc7fb8e (diff)
downloadarchiva-8e4acdc82a875ca32e39eb216b879c002d228de3.tar.gz
archiva-8e4acdc82a875ca32e39eb216b879c002d228de3.zip
Migrating to storage API
Diffstat (limited to 'archiva-modules/archiva-base/archiva-policies')
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/AbstractUpdatePolicy.java26
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/CachedFailuresPolicy.java4
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/ChecksumPolicy.java21
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/DownloadErrorPolicy.java5
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/DownloadPolicy.java7
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/PropagateErrorsDownloadPolicy.java4
-rw-r--r--archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/PropagateErrorsOnUpdateDownloadPolicy.java6
7 files changed, 30 insertions, 43 deletions
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 1fbbfece5..cf1c0da4a 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
@@ -20,13 +20,13 @@ package org.apache.archiva.policies;
*/
import org.apache.archiva.common.utils.VersionUtil;
+import org.apache.archiva.repository.content.StorageAsset;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.nio.file.Files;
-import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
@@ -106,7 +106,7 @@ public abstract class AbstractUpdatePolicy
}
@Override
- public void applyPolicy( String policySetting, Properties request, Path localFile )
+ public void applyPolicy( String policySetting, Properties request, StorageAsset localFile )
throws PolicyViolationException, PolicyConfigurationException
{
if ( !StringUtils.equals( request.getProperty( "filetype" ), "artifact" ) )
@@ -157,7 +157,7 @@ public abstract class AbstractUpdatePolicy
throw new PolicyViolationException( "NO to update, " + getUpdateMode() + " policy set to NEVER." );
}
- if ( !Files.exists(localFile) )
+ if ( !localFile.exists() )
{
// No file means it's ok.
log.debug( "OK to update {}, local file does not exist.", getUpdateMode() );
@@ -176,15 +176,7 @@ public abstract class AbstractUpdatePolicy
Calendar cal = Calendar.getInstance();
cal.add( Calendar.DAY_OF_MONTH, -1 );
Calendar fileCal = Calendar.getInstance();
- try
- {
- fileCal.setTimeInMillis( Files.getLastModifiedTime(localFile).toMillis() );
- }
- catch ( IOException e )
- {
- fileCal.setTimeInMillis( new Date().getTime() );
- log.error("Could not read modification time of {}", localFile);
- }
+ fileCal.setTimeInMillis( localFile.getModificationTime().toEpochMilli() );
if ( cal.after( fileCal ) )
{
@@ -203,15 +195,7 @@ public abstract class AbstractUpdatePolicy
Calendar cal = Calendar.getInstance();
cal.add( Calendar.HOUR, -1 );
Calendar fileCal = Calendar.getInstance();
- try
- {
- fileCal.setTimeInMillis( Files.getLastModifiedTime(localFile).toMillis() );
- }
- catch ( IOException e )
- {
- fileCal.setTimeInMillis( new Date().getTime() );
- log.error("Could not read modification time of {}", localFile);
- }
+ fileCal.setTimeInMillis( localFile.getModificationTime().toEpochMilli());
if ( cal.after( fileCal ) )
{
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 e92858fe8..ac20dbc8e 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
@@ -20,13 +20,13 @@ package org.apache.archiva.policies;
*/
import org.apache.archiva.policies.urlcache.UrlFailureCache;
+import org.apache.archiva.repository.content.StorageAsset;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.inject.Inject;
-import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
@@ -64,7 +64,7 @@ public class CachedFailuresPolicy
}
@Override
- public void applyPolicy( String policySetting, Properties request, Path localFile )
+ public void applyPolicy( String policySetting, Properties request, StorageAsset localFile )
throws PolicyViolationException, PolicyConfigurationException
{
if ( !options.contains( policySetting ) )
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 82d4d3da4..8f6885a6b 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
@@ -22,6 +22,7 @@ package org.apache.archiva.policies;
import org.apache.archiva.checksum.ChecksumAlgorithm;
import org.apache.archiva.checksum.ChecksummedFile;
import org.apache.archiva.checksum.UpdateStatus;
+import org.apache.archiva.repository.content.StorageAsset;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -80,7 +81,7 @@ public class ChecksumPolicy
}
@Override
- public void applyPolicy( String policySetting, Properties request, Path localFile )
+ public void applyPolicy( String policySetting, Properties request, StorageAsset localFile )
throws PolicyViolationException, PolicyConfigurationException
{
if ( "resource".equals( request.getProperty( "filetype" ) ) )
@@ -103,16 +104,16 @@ public class ChecksumPolicy
return;
}
- if ( !Files.exists(localFile) )
+ if ( !localFile.exists() )
{
// Local File does not exist.
throw new PolicyViolationException(
- "Checksum policy failure, local file " + localFile.toAbsolutePath() + " does not exist to check." );
+ "Checksum policy failure, local file " + localFile.getPath() + " does not exist to check." );
}
- if ( FAIL.equals( policySetting ) )
+ if ( FAIL.equals( policySetting ) && localFile.isFileBased() )
{
- ChecksummedFile checksum = new ChecksummedFile( localFile );
+ ChecksummedFile checksum = new ChecksummedFile( localFile.getFilePath() );
if ( checksum.isValidChecksums( algorithms ) )
{
return;
@@ -133,7 +134,7 @@ public class ChecksumPolicy
try
{
- Files.deleteIfExists( localFile );
+ localFile.getStorage().removeAsset( localFile );
}
catch ( IOException e )
{
@@ -141,12 +142,12 @@ public class ChecksumPolicy
}
throw new PolicyViolationException(
"Checksums do not match, policy set to FAIL, " + "deleting checksum files and local file "
- + localFile.toAbsolutePath() + "." );
+ + localFile.getPath() + "." );
}
- if ( FIX.equals( policySetting ) )
+ if ( FIX.equals( policySetting ) && localFile.isFileBased())
{
- ChecksummedFile checksum = new ChecksummedFile( localFile );
+ ChecksummedFile checksum = new ChecksummedFile( localFile.getFilePath() );
if ( checksum.fixChecksums( algorithms ).getTotalStatus() != UpdateStatus.ERROR )
{
log.debug( "Checksum policy set to FIX, checksum files have been updated." );
@@ -156,7 +157,7 @@ public class ChecksumPolicy
{
throw new PolicyViolationException(
"Checksum policy set to FIX, " + "yet unable to update checksums for local file "
- + localFile.toAbsolutePath() + "." );
+ + localFile.getPath() + "." );
}
}
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 90261737e..28de5336b 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
@@ -19,7 +19,8 @@ package org.apache.archiva.policies;
* under the License.
*/
-import java.nio.file.Path;
+import org.apache.archiva.repository.content.StorageAsset;
+
import java.util.Map;
import java.util.Properties;
@@ -43,7 +44,7 @@ public interface DownloadErrorPolicy
* @return whether to process the exception or not
* @throws PolicyConfigurationException if the policy is improperly configured
*/
- boolean applyPolicy( String policySetting, Properties request, Path localFile, Exception exception,
+ boolean applyPolicy( String 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 8d149e619..f9a144331 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
@@ -19,7 +19,8 @@ package org.apache.archiva.policies;
* under the License.
*/
-import java.nio.file.Path;
+import org.apache.archiva.repository.content.StorageAsset;
+
import java.util.Properties;
/**
@@ -37,9 +38,9 @@ public interface DownloadPolicy
* @param policySetting the policy setting.
* @param request the list of request properties that the policy might use.
* @param localFile
- *
+ *
* @throws PolicyViolationException if the policy has been violated.
*/
- void applyPolicy( String policySetting, Properties request, Path localFile )
+ void applyPolicy( String policySetting, Properties request, StorageAsset localFile )
throws PolicyViolationException, PolicyConfigurationException;
}
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 1fab1209a..7a0baefe1 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
@@ -19,12 +19,12 @@ package org.apache.archiva.policies;
* under the License.
*/
+import org.apache.archiva.repository.content.StorageAsset;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
-import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -64,7 +64,7 @@ public class PropagateErrorsDownloadPolicy
}
@Override
- public boolean applyPolicy( String policySetting, Properties request, Path localFile, Exception exception,
+ public boolean applyPolicy( String 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/PropagateErrorsOnUpdateDownloadPolicy.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/PropagateErrorsOnUpdateDownloadPolicy.java
index ec3289105..9b22a9b23 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
@@ -19,11 +19,11 @@ package org.apache.archiva.policies;
* under the License.
*/
+import org.apache.archiva.repository.content.StorageAsset;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.nio.file.Files;
-import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -55,7 +55,7 @@ public class PropagateErrorsOnUpdateDownloadPolicy
}
@Override
- public boolean applyPolicy( String policySetting, Properties request, Path localFile, Exception exception,
+ public boolean applyPolicy( String policySetting, Properties request, StorageAsset localFile, Exception exception,
Map<String, Exception> previousExceptions )
throws PolicyConfigurationException
{
@@ -76,7 +76,7 @@ public class PropagateErrorsOnUpdateDownloadPolicy
if ( NOT_PRESENT.equals( policySetting ) )
{
// cancel the exception if the file exists
- return !Files.exists(localFile);
+ return !localFile.exists();
}
throw new PolicyConfigurationException(