use of java.nio.file.InvalidPathException in project jetty.project by eclipse.
the class FileSystemResourceTest method testAddPath_WindowsSlash.
@Test
public void testAddPath_WindowsSlash() throws Exception {
Path dir = testdir.getPath().normalize().toRealPath();
Files.createDirectories(dir);
Path basePath = dir.resolve("base");
FS.ensureDirExists(basePath);
Path dirPath = basePath.resolve("aa");
FS.ensureDirExists(dirPath);
Path filePath = dirPath.resolve("foo.txt");
Files.createFile(filePath);
try (Resource base = newResource(basePath.toFile())) {
assertThat("Exists: " + basePath, base.exists(), is(true));
assertThat("Alias: " + basePath, base, hasNoAlias());
Resource r = base.addPath("aa\\/foo.txt");
assertThat("getURI()", r.getURI().toASCIIString(), containsString("aa%5C/foo.txt"));
if (OS.IS_WINDOWS) {
assertThat("isAlias()", r.isAlias(), is(true));
assertThat("getAlias()", r.getAlias(), notNullValue());
assertThat("getAlias()", r.getAlias().toASCIIString(), containsString("aa/foo.txt"));
assertThat("Exists: " + r, r.exists(), is(true));
} else {
assertThat("isAlias()", r.isAlias(), is(false));
assertThat("Exists: " + r, r.exists(), is(false));
}
} catch (InvalidPathException e) {
// Exception is acceptable
}
}
use of java.nio.file.InvalidPathException in project jetty.project by eclipse.
the class FileSystemResourceTest method testExist_BadURINull.
@Test
public void testExist_BadURINull() throws Exception {
Path dir = testdir.getPath().normalize().toRealPath();
Files.createDirectories(dir);
Path path = dir.resolve("a.jsp");
Files.createFile(path);
try {
// request with null at end
URI uri = testdir.getPath().toUri().resolve("a.jsp%00");
assertThat("Null URI", uri, notNullValue());
Resource r = newResource(uri);
// if we have r, then it better not exist
assertFalse(r.exists());
} catch (InvalidPathException e) {
// Exception is acceptable
}
}
use of java.nio.file.InvalidPathException in project buck by facebook.
the class FileClassPathRunner method readUrls.
// @VisibleForTesting
@SuppressWarnings("PMD.EmptyCatchBlock")
static List<URL> readUrls(List<Path> paths, boolean modifySystemClassPathProperty) throws IOException {
List<URL> readUrls = new LinkedList<>();
List<String> classPathEntries = new LinkedList<>();
// format of "file/" to indicate a directory and assuming all other files are jars.
for (Path path : paths) {
if (!Files.exists(path)) {
continue;
}
List<String> lines = Files.readAllLines(path, UTF_8);
for (String line : lines) {
if (line.isEmpty()) {
continue;
}
try {
Path entry = Paths.get(line);
readUrls.add(entry.toUri().toURL());
classPathEntries.add(entry.toString());
} catch (InvalidPathException e) {
// Carry on regardless --- java allows us to put absolute garbage into the classpath.
}
}
}
String classpathProperty = System.getProperty("java.class.path");
if (classpathProperty == null) {
throw new NullPointerException("java.class.path system property must not be null");
}
StringBuilder newClassPath = new StringBuilder();
constructNewClassPath(newClassPath, classpathProperty, classPathEntries);
if (modifySystemClassPathProperty) {
System.setProperty("java.class.path", newClassPath.toString());
}
return readUrls;
}
use of java.nio.file.InvalidPathException in project buck by facebook.
the class ProjectWorkspace method setUp.
/**
* This will copy the template directory, renaming files named {@code foo.fixture} to {@code foo}
* in the process. Files whose names end in {@code .expected} will not be copied.
*/
@SuppressWarnings("PMD.EmptyCatchBlock")
public ProjectWorkspace setUp() throws IOException {
MoreFiles.copyRecursively(templatePath, destPath, BUILD_FILE_RENAME);
// Stamp the buck-out directory if it exists and isn't stamped already
try (OutputStream outputStream = new BufferedOutputStream(Channels.newOutputStream(Files.newByteChannel(destPath.resolve(BuckConstant.getBuckOutputPath().resolve(".currentversion")), ImmutableSet.<OpenOption>of(StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE))))) {
outputStream.write(BuckVersion.getVersion().getBytes(Charsets.UTF_8));
} catch (FileAlreadyExistsException | NoSuchFileException e) {
// If the current version file already exists we don't need to create it
// If buck-out doesn't exist we don't need to stamp it
}
if (Platform.detect() == Platform.WINDOWS) {
// Hack for symlinks on Windows.
SimpleFileVisitor<Path> copyDirVisitor = new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
// On NTFS length of path must be greater than 0 and less than 4096.
if (attrs.size() > 0 && attrs.size() <= 4096) {
String linkTo = new String(Files.readAllBytes(path), UTF_8);
Path linkToFile;
try {
linkToFile = templatePath.resolve(linkTo);
} catch (InvalidPathException e) {
// link.
return FileVisitResult.CONTINUE;
}
if (Files.isRegularFile(linkToFile)) {
Files.copy(linkToFile, path, StandardCopyOption.REPLACE_EXISTING);
} else if (Files.isDirectory(linkToFile)) {
Files.delete(path);
MoreFiles.copyRecursively(linkToFile, path);
}
}
return FileVisitResult.CONTINUE;
}
};
Files.walkFileTree(destPath, copyDirVisitor);
}
if (!Files.exists(getPath(".buckconfig.local"))) {
manageLocalConfigs = true;
// Disable the directory cache by default. Tests that want to enable it can call
// `enableDirCache` on this object. Only do this if a .buckconfig.local file does not already
// exist, however (we assume the test knows what it is doing at that point).
addBuckConfigLocalOption("cache", "mode", "");
// Limit the number of threads by default to prevent multiple integration tests running at the
// same time from creating a quadratic number of threads. Tests can disable this using
// `disableThreadLimitOverride`.
addBuckConfigLocalOption("build", "threads", "2");
}
isSetUp = true;
return this;
}
use of java.nio.file.InvalidPathException in project es6draft by anba.
the class TraceurFileModuleLoader method normalizeName.
@Override
public FileSourceIdentifier normalizeName(String unnormalizedName, SourceIdentifier referrerId) throws MalformedNameException {
FileSourceIdentifier normalizedName = super.normalizeName(unnormalizedName, referrerId);
try {
Path fileName = normalizedName.getPath().getFileName();
if (!fileName.toString().endsWith(".js")) {
Path path = Paths.get(normalizedName.getPath() + ".js");
normalizedName = new FileSourceIdentifier(getBaseDirectory(), path);
}
return normalizedName;
} catch (InvalidPathException e) {
throw new MalformedNameException(unnormalizedName);
}
}
Aggregations