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.*;
* @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) {
} 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;
}
}
*/
import java.io.File;
+import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
* 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);
}
/**
*/
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;
* 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;
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 );