use of java.nio.file.Paths in project buck by facebook.
the class JavacStepTest method missingBootclasspathDirFailsWithError.
@Test
public void missingBootclasspathDirFailsWithError() throws Exception {
FakeJavac fakeJavac = new FakeJavac();
BuildRuleResolver buildRuleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(buildRuleResolver);
SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
ProjectFilesystem fakeFilesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
JavacOptions javacOptions = JavacOptions.builder().setSourceLevel("8.0").setTargetLevel("8.0").setBootclasspath("/no-such-dir").build();
ClasspathChecker classpathChecker = new ClasspathChecker("/", ":", Paths::get, dir -> false, file -> false, (path, glob) -> ImmutableSet.of());
JavacStep step = new JavacStep(Paths.get("output"), NoOpClassUsageFileWriter.instance(), Optional.empty(), ImmutableSortedSet.of(), Paths.get("pathToSrcsList"), ImmutableSortedSet.of(), fakeJavac, javacOptions, BuildTargetFactory.newInstance("//foo:bar"), Optional.empty(), sourcePathResolver, ruleFinder, fakeFilesystem, classpathChecker, Optional.empty());
FakeProcess fakeJavacProcess = new FakeProcess(1, "javac stdout\n", "javac stderr\n");
ExecutionContext executionContext = TestExecutionContext.newBuilder().setProcessExecutor(new FakeProcessExecutor(Functions.constant(fakeJavacProcess), new TestConsole())).build();
BuckEventBusFactory.CapturingConsoleEventListener listener = new BuckEventBusFactory.CapturingConsoleEventListener();
executionContext.getBuckEventBus().register(listener);
StepExecutionResult result = step.execute(executionContext);
assertThat(result, equalTo(StepExecutionResult.ERROR));
assertThat(listener.getLogMessages(), equalTo(ImmutableList.of("Invalid Java compiler options: Bootstrap classpath /no-such-dir " + "contains no valid entries")));
}
use of java.nio.file.Paths in project spring-loaded by spring-projects.
the class Issue173 method url.
public static URI url(Object... args) {
try {
/* flattening the paths */
final List<String> paths = Arrays.stream(args).flatMap(arg -> {
if (arg instanceof Collection) {
return ((Collection<Object>) arg).stream();
} else if (arg instanceof Object[]) {
return Arrays.stream((Object[]) arg);
}
return Arrays.stream(new Object[] { arg });
}).map(Object::toString).map(String::toLowerCase).collect(Collectors.toList());
Path path = Paths.get("/", paths.toArray(new String[0]));
URI uri = new URI("https", "www.redacted.com", path.toString(), null);
return uri;
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
use of java.nio.file.Paths in project karaf by apache.
the class FilesStream method stream.
/**
* Returns a stream of Paths for the given fileNames.
* The given names can be delimited by ",". A name can also contain
* {@link java.nio.file.FileSystem#getPathMatcher} syntax to refer to matching files.
*
* @param fileNames list of names
* @return Paths to the scripts
*/
public static Stream<Path> stream(String fileNames) {
if (fileNames == null) {
return Stream.empty();
}
List<String> files = new ArrayList<>();
List<String> generators = new ArrayList<>();
StringBuilder buf = new StringBuilder(fileNames.length());
boolean hasUnescapedReserved = false;
boolean escaped = false;
for (int i = 0; i < fileNames.length(); i++) {
char c = fileNames.charAt(i);
if (escaped) {
buf.append(c);
escaped = false;
} else if (c == '\\') {
escaped = true;
} else if (c == ',') {
if (hasUnescapedReserved) {
generators.add(buf.toString());
} else {
files.add(buf.toString());
}
hasUnescapedReserved = false;
buf.setLength(0);
} else if ("*?{[".indexOf(c) >= 0) {
hasUnescapedReserved = true;
buf.append(c);
} else {
buf.append(c);
}
}
if (buf.length() > 0) {
if (hasUnescapedReserved) {
generators.add(buf.toString());
} else {
files.add(buf.toString());
}
}
Path cur = Paths.get(System.getProperty("karaf.base"));
return Stream.concat(files.stream().map(cur::resolve), generators.stream().flatMap(s -> files(cur, s)));
}
use of java.nio.file.Paths in project cogcomp-nlp by CogComp.
the class EREDocumentReader method getFileListing.
/**
* ERE corpus directory has two directories: source/ and ere/. The source/ directory contains
* original text in an xml format. The ere/ directory contains markup files corresponding in a
* many-to-one relationship with the source/ files: related annotation files have the same
* prefix as the corresponding source file (up to the .xml suffix).
* (NOTE: release 1 (LDC2015E29) has two subdirectories for both source and annotation: one version is slightly
* modified by adding xml markup to make the source documents well-formed, which changes the annotation offsets.
*
* This method generates a List of List of Paths: each component List has the source file as its
* first element, and markup files as its remaining elements. It expects {@link
* super.getSourceDirectory()} to return the root directory of the ERE corpus, under which
* should be data/source/ and data/ere/ directories containing source files and annotation files
* respectively.
*
* @return a list of Path objects corresponding to files containing corpus documents to process.
*/
@Override
public List<List<Path>> getFileListing() throws IOException {
FilenameFilter sourceFilter = (dir, name) -> name.endsWith(getRequiredSourceFileExtension());
/*
* returns the FULL PATH of each file
*/
String sourceDir = resourceManager.getString(CorpusReaderConfigurator.SOURCE_DIRECTORY.key);
List<String> sourceFileList = Arrays.asList(IOUtils.lsFilesRecursive(sourceDir, sourceFilter));
LinkedList<String> annotationFileList = new LinkedList<>();
FilenameFilter annotationFilter = (dir, name) -> name.endsWith(getRequiredAnnotationFileExtension());
String annotationDir = resourceManager.getString(CorpusReaderConfigurator.ANNOTATION_DIRECTORY.key);
annotationFileList.addAll(Arrays.stream(IOUtils.lsFilesRecursive(annotationDir, annotationFilter)).map(IOUtils::getFileName).collect(Collectors.toList()));
List<List<Path>> pathList = new ArrayList<>();
/*
* fileList has multiple entries per single annotation: a source file plus one or more
* annotation files. These files share a prefix -- the stem of the file containing
* the source text.
*/
for (String fileName : sourceFileList) {
List<Path> sourceAndAnnotations = new ArrayList<>();
// source file
Path fPath = Paths.get(fileName);
sourceAndAnnotations.add(fPath);
// strip *source* extension
String stem = this.getFileStem(fPath, getRequiredSourceFileExtension());
for (String annFile : annotationFileList) {
if (annFile.startsWith(stem)) {
logger.debug("Processing file '{}'", annFile);
sourceAndAnnotations.add(Paths.get(resourceManager.getString(CorpusReaderConfigurator.ANNOTATION_DIRECTORY.key) + annFile));
}
}
pathList.add(sourceAndAnnotations);
}
return pathList;
}
use of java.nio.file.Paths in project jabref by JabRef.
the class WrapFileLinks method format.
@Override
public String format(String field) {
if (field == null) {
return "";
}
StringBuilder sb = new StringBuilder();
// Build the list containing the links:
List<LinkedFile> fileList = FileFieldParser.parse(field);
// counter for relevant iterations
int piv = 1;
for (LinkedFile flEntry : fileList) {
// Use this entry if we don't discriminate on types, or if the type fits:
if ((fileType == null) || flEntry.getFileType().equalsIgnoreCase(fileType)) {
for (FormatEntry entry : format) {
switch(entry.getType()) {
case STRING:
sb.append(entry.getString());
break;
case ITERATION_COUNT:
sb.append(piv);
break;
case FILE_PATH:
List<String> dirs;
// starting the export, which contains the database's file directory:
if ((prefs.getFileDirForDatabase() == null) || prefs.getFileDirForDatabase().isEmpty()) {
dirs = prefs.getGeneratedDirForDatabase();
} else {
dirs = prefs.getFileDirForDatabase();
}
String pathString = flEntry.findIn(dirs.stream().map(Paths::get).collect(Collectors.toList())).map(path -> path.toAbsolutePath().toString()).orElse(flEntry.getLink());
sb.append(replaceStrings(pathString));
break;
case RELATIVE_FILE_PATH:
/*
* Stumbled over this while investigating
*
* https://sourceforge.net/tracker/index.php?func=detail&aid=1469903&group_id=92314&atid=600306
*/
//f.toURI().toString();
sb.append(replaceStrings(flEntry.getLink()));
break;
case FILE_EXTENSION:
FileHelper.getFileExtension(flEntry.getLink()).ifPresent(extension -> sb.append(replaceStrings(extension)));
break;
case FILE_TYPE:
sb.append(replaceStrings(flEntry.getFileType()));
break;
case FILE_DESCRIPTION:
sb.append(replaceStrings(flEntry.getDescription()));
break;
default:
break;
}
}
// update counter
piv++;
}
}
return sb.toString();
}
Aggregations