Quellcode durchsuchen

Dependency cleanup

pull/56/head
Martin Stockhammer vor 4 Jahren
Ursprung
Commit
13ffcca2c1

+ 439
- 0
archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/utils/PathUtil.java Datei anzeigen

@@ -23,16 +23,27 @@ import org.apache.commons.lang3.StringUtils;

import java.net.MalformedURLException;
import java.net.URI;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.stream.StreamSupport;

/**
*
* PathUtil - simple utility methods for path manipulation.
*
* Some code is from Apache Ant SelectorUtils
*
*/
public class PathUtil
{

public static final String DEEP_TREE_MATCH = "**";

public static String toUrl( String path )
{
// Is our work already done for us?
@@ -114,4 +125,432 @@ public class PathUtil
return Paths.get(uri);
}
}

public static boolean isAbsolutePath(String path) {
try
{
return Paths.get( path ).isAbsolute( );
} catch (Exception e) {
return false;
}
}

public static char getSeparatorChar() {
return FileSystems.getDefault( ).getSeparator( ).charAt( 0 );
}

public static String[] dissect(String pathString) {
Path path = Paths.get(pathString);
return StreamSupport.stream(path.spliterator(), false).map(Path::toString)
.toArray(String[]::new);
}

public static String separatorsToUnix(String path)
{
return path != null && path.indexOf( 92 ) != -1 ? path.replace( '\\', '/' ) : path;
}


/**
* Tests whether or not a given path matches a given pattern.
*
* If you need to call this method multiple times with the same
* pattern you should rather use TokenizedPath
*
* @param pattern The pattern to match against. Must not be
* <code>null</code>.
* @param str The path to match, as a String. Must not be
* <code>null</code>.
*
* @return <code>true</code> if the pattern matches against the string,
* or <code>false</code> otherwise.
*/
public static boolean matchPath(String pattern, String str) {
String[] patDirs = tokenizePathAsArray(pattern);
return matchPath(patDirs, tokenizePathAsArray(str), true);
}

/**
* Tests whether or not a given path matches a given pattern.
*
* If you need to call this method multiple times with the same
* pattern you should rather use TokenizedPattern
*
*
* @param pattern The pattern to match against. Must not be
* <code>null</code>.
* @param str The path to match, as a String. Must not be
* <code>null</code>.
* @param isCaseSensitive Whether or not matching should be performed
* case sensitively.
*
* @return <code>true</code> if the pattern matches against the string,
* or <code>false</code> otherwise.
*/
public static boolean matchPath(String pattern, String str,
boolean isCaseSensitive) {
String[] patDirs = tokenizePathAsArray(pattern);
return matchPath(patDirs, tokenizePathAsArray(str), isCaseSensitive);
}

/**
* Core implementation of matchPath. It is isolated so that it
* can be called from TokenizedPattern.
*/
static boolean matchPath(String[] tokenizedPattern, String[] strDirs,
boolean isCaseSensitive) {
int patIdxStart = 0;
int patIdxEnd = tokenizedPattern.length - 1;
int strIdxStart = 0;
int strIdxEnd = strDirs.length - 1;

// up to first '**'
while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) {
String patDir = tokenizedPattern[patIdxStart];
if (patDir.equals(DEEP_TREE_MATCH)) {
break;
}
if (!match(patDir, strDirs[strIdxStart], isCaseSensitive)) {
return false;
}
patIdxStart++;
strIdxStart++;
}
if (strIdxStart > strIdxEnd) {
// String is exhausted
for (int i = patIdxStart; i <= patIdxEnd; i++) {
if (!tokenizedPattern[i].equals(DEEP_TREE_MATCH)) {
return false;
}
}
return true;
}
if (patIdxStart > patIdxEnd) {
// String not exhausted, but pattern is. Failure.
return false;
}

// up to last '**'
while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) {
String patDir = tokenizedPattern[patIdxEnd];
if (patDir.equals(DEEP_TREE_MATCH)) {
break;
}
if (!match(patDir, strDirs[strIdxEnd], isCaseSensitive)) {
return false;
}
patIdxEnd--;
strIdxEnd--;
}
if (strIdxStart > strIdxEnd) {
// String is exhausted
for (int i = patIdxStart; i <= patIdxEnd; i++) {
if (!tokenizedPattern[i].equals(DEEP_TREE_MATCH)) {
return false;
}
}
return true;
}

while (patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd) {
int patIdxTmp = -1;
for (int i = patIdxStart + 1; i <= patIdxEnd; i++) {
if (tokenizedPattern[i].equals(DEEP_TREE_MATCH)) {
patIdxTmp = i;
break;
}
}
if (patIdxTmp == patIdxStart + 1) {
// '**/**' situation, so skip one
patIdxStart++;
continue;
}
// Find the pattern between padIdxStart & padIdxTmp in str between
// strIdxStart & strIdxEnd
int patLength = (patIdxTmp - patIdxStart - 1);
int strLength = (strIdxEnd - strIdxStart + 1);
int foundIdx = -1;
strLoop:
for (int i = 0; i <= strLength - patLength; i++) {
for (int j = 0; j < patLength; j++) {
String subPat = tokenizedPattern[patIdxStart + j + 1];
String subStr = strDirs[strIdxStart + i + j];
if (!match(subPat, subStr, isCaseSensitive)) {
continue strLoop;
}
}
foundIdx = strIdxStart + i;
break;
}
if (foundIdx == -1) {
return false;
}

patIdxStart = patIdxTmp;
strIdxStart = foundIdx + patLength;
}

for (int i = patIdxStart; i <= patIdxEnd; i++) {
if (!DEEP_TREE_MATCH.equals(tokenizedPattern[i])) {
return false;
}
}
return true;
}

/**
* Tests whether or not a string matches against a pattern.
* The pattern may contain two special characters:<br>
* '*' means zero or more characters<br>
* '?' means one and only one character
*
* @param pattern The pattern to match against.
* Must not be <code>null</code>.
* @param str The string which must be matched against the pattern.
* Must not be <code>null</code>.
*
* @return <code>true</code> if the string matches against the pattern,
* or <code>false</code> otherwise.
*/
public static boolean match(String pattern, String str) {
return match(pattern, str, true);
}

/**
* Tests whether or not a string matches against a pattern.
* The pattern may contain two special characters:<br>
* '*' means zero or more characters<br>
* '?' means one and only one character
*
* @param pattern The pattern to match against.
* Must not be <code>null</code>.
* @param str The string which must be matched against the pattern.
* Must not be <code>null</code>.
* @param caseSensitive Whether or not matching should be performed
* case sensitively.
*
*
* @return <code>true</code> if the string matches against the pattern,
* or <code>false</code> otherwise.
*/
public static boolean match(String pattern, String str,
boolean caseSensitive) {
char[] patArr = pattern.toCharArray();
char[] strArr = str.toCharArray();
int patIdxStart = 0;
int patIdxEnd = patArr.length - 1;
int strIdxStart = 0;
int strIdxEnd = strArr.length - 1;

boolean containsStar = false;
for (char ch : patArr) {
if (ch == '*') {
containsStar = true;
break;
}
}

if (!containsStar) {
// No '*'s, so we make a shortcut
if (patIdxEnd != strIdxEnd) {
return false; // Pattern and string do not have the same size
}
for (int i = 0; i <= patIdxEnd; i++) {
char ch = patArr[i];
if (ch != '?' && different(caseSensitive, ch, strArr[i])) {
return false; // Character mismatch
}
}
return true; // String matches against pattern
}

if (patIdxEnd == 0) {
return true; // Pattern contains only '*', which matches anything
}

// Process characters before first star
while (true) {
char ch = patArr[patIdxStart];
if (ch == '*' || strIdxStart > strIdxEnd) {
break;
}
if (ch != '?'
&& different(caseSensitive, ch, strArr[strIdxStart])) {
return false; // Character mismatch
}
patIdxStart++;
strIdxStart++;
}
if (strIdxStart > strIdxEnd) {
// All characters in the string are used. Check if only '*'s are
// left in the pattern. If so, we succeeded. Otherwise failure.
return allStars(patArr, patIdxStart, patIdxEnd);
}

// Process characters after last star
while (true) {
char ch = patArr[patIdxEnd];
if (ch == '*' || strIdxStart > strIdxEnd) {
break;
}
if (ch != '?' && different(caseSensitive, ch, strArr[strIdxEnd])) {
return false; // Character mismatch
}
patIdxEnd--;
strIdxEnd--;
}
if (strIdxStart > strIdxEnd) {
// All characters in the string are used. Check if only '*'s are
// left in the pattern. If so, we succeeded. Otherwise failure.
return allStars(patArr, patIdxStart, patIdxEnd);
}

// process pattern between stars. padIdxStart and patIdxEnd point
// always to a '*'.
while (patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd) {
int patIdxTmp = -1;
for (int i = patIdxStart + 1; i <= patIdxEnd; i++) {
if (patArr[i] == '*') {
patIdxTmp = i;
break;
}
}
if (patIdxTmp == patIdxStart + 1) {
// Two stars next to each other, skip the first one.
patIdxStart++;
continue;
}
// Find the pattern between padIdxStart & padIdxTmp in str between
// strIdxStart & strIdxEnd
int patLength = (patIdxTmp - patIdxStart - 1);
int strLength = (strIdxEnd - strIdxStart + 1);
int foundIdx = -1;
strLoop:
for (int i = 0; i <= strLength - patLength; i++) {
for (int j = 0; j < patLength; j++) {
char ch = patArr[patIdxStart + j + 1];
if (ch != '?' && different(caseSensitive, ch,
strArr[strIdxStart + i + j])) {
continue strLoop;
}
}
foundIdx = strIdxStart + i;
break;
}

if (foundIdx == -1) {
return false;
}
patIdxStart = patIdxTmp;
strIdxStart = foundIdx + patLength;
}

// All characters in the string are used. Check if only '*'s are left
// in the pattern. If so, we succeeded. Otherwise failure.
return allStars(patArr, patIdxStart, patIdxEnd);
}

private static boolean allStars(char[] chars, int start, int end) {
for (int i = start; i <= end; ++i) {
if (chars[i] != '*') {
return false;
}
}
return true;
}

private static boolean different(
boolean caseSensitive, char ch, char other) {
return caseSensitive
? ch != other
: Character.toUpperCase(ch) != Character.toUpperCase(other);
}

/**
* Breaks a path up into a Vector of path elements, tokenizing on
* <code>File.separator</code>.
*
* @param path Path to tokenize. Must not be <code>null</code>.
*
* @return a Vector of path elements from the tokenized path
*/
public static Vector<String> tokenizePath( String path) {
return tokenizePath(path, FileSystems.getDefault( ).getSeparator());
}

/**
* Breaks a path up into a Vector of path elements, tokenizing on
*
* @param path Path to tokenize. Must not be <code>null</code>.
* @param separator the separator against which to tokenize.
*
* @return a Vector of path elements from the tokenized path
* @since Ant 1.6
*/
public static Vector<String> tokenizePath(String path, String separator) {
Vector<String> ret = new Vector<>();
if (isAbsolutePath(path)) {
String[] s = dissect(path);
ret.add(s[0]);
path = s[1];
}
StringTokenizer st = new StringTokenizer(path, separator);
while (st.hasMoreTokens()) {
ret.addElement(st.nextToken());
}
return ret;
}

/**
* Same as {@link #tokenizePath tokenizePath} but hopefully faster.
*/
/* package */
static String[] tokenizePathAsArray(String path) {
String root = null;
if (isAbsolutePath(path)) {
String[] s = dissect(path);
root = s[0];
path = s[1];
}
char sep = getSeparatorChar();
int start = 0;
int len = path.length();
int count = 0;
for (int pos = 0; pos < len; pos++) {
if (path.charAt(pos) == sep) {
if (pos != start) {
count++;
}
start = pos + 1;
}
}
if (len != start) {
count++;
}
String[] l = new String[count + ((root == null) ? 0 : 1)];

if (root != null) {
l[0] = root;
count = 1;
} else {
count = 0;
}
start = 0;
for (int pos = 0; pos < len; pos++) {
if (path.charAt(pos) == sep) {
if (pos != start) {
String tok = path.substring(start, pos);
l[count++] = tok;
}
start = pos + 1;
}
}
if (len != start) {
String tok = path.substring(start);
l[count/*++*/] = tok;
}
return l;
}


}

+ 91
- 42
archiva-modules/archiva-base/archiva-proxy/pom.xml Datei anzeigen

@@ -44,16 +44,6 @@
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-repository-layer</artifactId>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
@@ -67,15 +57,64 @@
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-proxy-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-storage-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-storage-fs</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva.components</groupId>
<artifactId>archiva-components-spring-taskqueue</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-common</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-policies</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-repository-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-model</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-checksum</artifactId>
</dependency>


<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<!--
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
-->
<!--
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
@@ -84,34 +123,43 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.plexus</artifactId>
</dependency>
<!--
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.plexus</artifactId>
</dependency>
-->
<!--
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<classifier>no_aop</classifier>
</dependency>
-->
<!--
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-plexus-bridge</artifactId>
</dependency>
-->
<dependency>
<groupId>org.apache.archiva.components.registry</groupId>
<artifactId>archiva-components-spring-registry-commons</artifactId>
<scope>test</scope>
</dependency>
<!--
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-core</artifactId>
<scope>test</scope>
</dependency>
-->

<!--
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http</artifactId>
@@ -128,6 +176,7 @@
<artifactId>wagon-http-lightweight</artifactId>
<scope>provided</scope>
</dependency>
-->
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-test-utils</artifactId>
@@ -144,25 +193,28 @@
<artifactId>redback-rbac-cached</artifactId>
<scope>test</scope>
</dependency>
<!--
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-security-common</artifactId>
</dependency>
-->

<!--
<dependency>
<groupId>org.apache.archiva.redback</groupId>
<artifactId>redback-common-test-resources</artifactId>
<scope>test</scope>
</dependency>
-->
<!--
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
-->
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
@@ -170,26 +222,6 @@
</dependency>


<!-- START Needed for JDK >= 9 -->
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<scope>test</scope>
</dependency>

<!-- END Needed for JDK >= 9 -->

<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
@@ -225,4 +257,21 @@
</plugins>
</pluginManagement>
</build>

<profiles>
<profile>
<id>jdk9+</id>
<activation>
<jdk>[1.9,)</jdk>
</activation>
<dependencies>
<!-- Needed for JDK >= 9 -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>
</project>

+ 5
- 4
archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyHandler.java Datei anzeigen

@@ -22,6 +22,7 @@ package org.apache.archiva.proxy;
import org.apache.archiva.checksum.ChecksumAlgorithm;
import org.apache.archiva.checksum.ChecksumUtil;
import org.apache.archiva.common.filelock.FileLockManager;
import org.apache.archiva.common.utils.PathUtil;
import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.configuration.ProxyConnectorConfiguration;
import org.apache.archiva.configuration.ProxyConnectorRuleConfiguration;
@@ -54,10 +55,8 @@ import org.apache.archiva.repository.storage.StorageUtil;
import org.apache.archiva.scheduler.ArchivaTaskScheduler;
import org.apache.archiva.scheduler.repository.model.RepositoryTask;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
import org.apache.tools.ant.types.selectors.SelectorUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MarkerFactory;
@@ -136,6 +135,8 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
return proxyConnectorRuleConfigurations;
}



@Override
public StorageAsset fetchFromProxies( ManagedRepository repository, ArtifactReference artifact )
throws ProxyDownloadException
@@ -164,7 +165,7 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
if ( SystemUtils.IS_OS_WINDOWS )
{
// toPath use system PATH_SEPARATOR so on windows url are \ which doesn't work very well :-)
targetPath = FilenameUtils.separatorsToUnix( targetPath );
targetPath = PathUtil.separatorsToUnix( targetPath );
}

try
@@ -770,7 +771,7 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
pattern = "/" + pattern;
}

if ( SelectorUtils.matchPath( pattern, path, false ) )
if ( PathUtil.matchPath( pattern, path, false ) )
{
return true;
}

+ 1
- 0
status-dep.txt Datei anzeigen

@@ -15,6 +15,7 @@ archiva-modules
archiva-repository-api
archiva-xml-tools
archiva-repository-layer
archiva-proxy-api




Laden…
Abbrechen
Speichern