aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-base
diff options
context:
space:
mode:
authorEric Barboni <skygo@apache.org>2020-02-17 15:25:42 +0100
committerMartin <m.stockhammer@web.de>2020-02-17 22:49:18 +0100
commit23737aaa3d19a79eb9471e4e9d3e67b92b4594ef (patch)
treede802f13063d86cc35ad3b8dbff1e99eb5c60c50 /archiva-modules/archiva-base
parentb06b167a847a04b5136e9d7b6a9fa4c04d776894 (diff)
downloadarchiva-23737aaa3d19a79eb9471e4e9d3e67b92b4594ef.tar.gz
archiva-23737aaa3d19a79eb9471e4e9d3e67b92b4594ef.zip
Change configuration to handle windows path restriction
Diffstat (limited to 'archiva-modules/archiva-base')
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java9
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/util/PathMatcher.java35
-rw-r--r--archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java4
3 files changed, 32 insertions, 16 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 97777d051..11ae70569 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
@@ -46,6 +46,7 @@ import javax.inject.Inject;
import javax.inject.Named;
import java.io.IOException;
import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
@@ -553,10 +554,9 @@ public class DefaultArchivaConfiguration
* @param contents the contents to write.
* @return true if write successful.
*/
- private boolean writeFile(String filetype, String path, String contents, boolean createDirs) {
- Path file = Paths.get(path);
-
+ private boolean writeFile(String filetype, String path, String contents, boolean createDirs) {
try {
+ Path file = Paths.get(path);
// Check parent directory (if it is declared)
final Path parent = file.getParent();
if (parent != null) {
@@ -574,6 +574,9 @@ public class DefaultArchivaConfiguration
} catch (IOException e) {
log.error("Unable to create {} file: {}", filetype, e.getMessage(), e);
return false;
+ } catch (InvalidPathException ipe) {
+ log.error("Unable to read {} file: {}", path, ipe.getMessage(), ipe);
+ return false;
}
}
diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/util/PathMatcher.java b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/util/PathMatcher.java
index 2e77b38a0..11e5ed519 100644
--- a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/util/PathMatcher.java
+++ b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/util/PathMatcher.java
@@ -20,6 +20,7 @@ package org.apache.archiva.configuration.util;
*/
import java.io.File;
+import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -226,8 +227,8 @@ public class PathMatcher
* or <code>false</code> otherwise.
*/
public static boolean matchPath(String pattern, String str) {
- String[] patDirs = tokenizePathAsArray(pattern);
- return matchPath(patDirs, tokenizePathAsArray(str), true);
+ String[] patDirs = tokenizePathAsArray( pattern, false );
+ return matchPath(patDirs, tokenizePathAsArray( str, true ), true);
}
/**
@@ -248,20 +249,30 @@ public class PathMatcher
*/
public static boolean matchPath(String pattern, String str,
boolean isCaseSensitive) {
- String[] patDirs = tokenizePathAsArray(pattern);
- return matchPath(patDirs, tokenizePathAsArray(str), isCaseSensitive);
+ String[] patDirs = tokenizePathAsArray( pattern, false );
+ return matchPath(patDirs, tokenizePathAsArray( str, false ), isCaseSensitive);
}
-
- static String[] tokenizePathAsArray(String path) {
+ /**
+ *
+ * @param path
+ * @param osspecific
+ * @return
+ */
+ static String[] tokenizePathAsArray(String path, boolean osSpecific) {
Path root = null;
- Path fsPath = Paths.get( path );
-
- if ( fsPath.isAbsolute()) {
- root = fsPath.getRoot( );
- path = root.relativize( fsPath ).toString();
+ try
+ {
+ Path fsPath = Paths.get( path );
+ if ( fsPath.isAbsolute() ) {
+ root = fsPath.getRoot();
+ path = root.relativize( fsPath ).toString();
+ }
+ } catch (InvalidPathException ipe )
+ {
+ // invalid path, windauze hate **/*
}
- char sep = File.separatorChar;
+ char sep = osSpecific ? File.separatorChar : '/';
int start = 0;
int len = path.length();
int count = 0;
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java
index 625c4574a..8dfcdb22d 100644
--- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java
+++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java
@@ -19,6 +19,7 @@ package org.apache.archiva.consumers.core.repository;
* under the License.
*/
+import java.io.File;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.archiva.metadata.repository.RepositorySession;
@@ -163,7 +164,8 @@ public abstract class AbstractRepositoryPurgeTest
atf.setRetentionPeriod( Period.ofDays( TEST_DAYS_OLDER) );
String path = AbstractRepositoryPurgeTest.fixPath(
basePath.resolve( repoId ).toAbsolutePath().toString() );
- config.setLocation( new URI( path ) );
+ File file = new File( path );
+ config.setLocation( file.toURI() );
atf.setDeleteReleasedSnapshots( true );
atf.setRetentionCount( TEST_RETENTION_COUNT );