Search in sources :

Example 6 with Paths

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")));
}
Also used : BuckEventBusFactory(com.facebook.buck.event.BuckEventBusFactory) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) FakeProcess(com.facebook.buck.util.FakeProcess) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Paths(java.nio.file.Paths) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 7 with Paths

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);
    }
}
Also used : Arrays(java.util.Arrays) List(java.util.List) Paths(java.nio.file.Paths) URISyntaxException(java.net.URISyntaxException) Collection(java.util.Collection) URI(java.net.URI) Path(java.nio.file.Path) Collectors(java.util.stream.Collectors) Path(java.nio.file.Path) Collection(java.util.Collection) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 8 with Paths

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)));
}
Also used : Path(java.nio.file.Path) Logger(org.slf4j.Logger) FileVisitor(java.nio.file.FileVisitor) Files(java.nio.file.Files) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) ArrayList(java.util.ArrayList) FileVisitResult(java.nio.file.FileVisitResult) List(java.util.List) Stream(java.util.stream.Stream) FileVisitOption(java.nio.file.FileVisitOption) Paths(java.nio.file.Paths) PathMatcher(java.nio.file.PathMatcher) Path(java.nio.file.Path) EnumSet(java.util.EnumSet) ArrayList(java.util.ArrayList)

Example 9 with Paths

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;
}
Also used : FilenameFilter(java.io.FilenameFilter) java.util(java.util) IntPair(edu.illinois.cs.cogcomp.core.datastructures.IntPair) TextAnnotationBuilder(edu.illinois.cs.cogcomp.annotation.TextAnnotationBuilder) Annotator(edu.illinois.cs.cogcomp.annotation.Annotator) TokenizerTextAnnotationBuilder(edu.illinois.cs.cogcomp.nlp.utility.TokenizerTextAnnotationBuilder) LoggerFactory(org.slf4j.LoggerFactory) XmlDocumentReader(edu.illinois.cs.cogcomp.nlp.corpusreaders.XmlDocumentReader) Pair(edu.illinois.cs.cogcomp.core.datastructures.Pair) ViewNames(edu.illinois.cs.cogcomp.core.datastructures.ViewNames) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) IOUtils(edu.illinois.cs.cogcomp.core.io.IOUtils) Path(java.nio.file.Path) XmlTextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.XmlTextAnnotation) ResourceManager(edu.illinois.cs.cogcomp.core.utilities.configuration.ResourceManager) Logger(org.slf4j.Logger) XmlDocumentProcessor(edu.illinois.cs.cogcomp.core.utilities.XmlDocumentProcessor) IOException(java.io.IOException) XmlTextAnnotationMaker(edu.illinois.cs.cogcomp.annotation.XmlTextAnnotationMaker) CorpusReaderConfigurator(edu.illinois.cs.cogcomp.nlp.corpusreaders.CorpusReaderConfigurator) Collectors(java.util.stream.Collectors) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent) StatefulTokenizer(edu.illinois.cs.cogcomp.nlp.tokenizer.StatefulTokenizer) Paths(java.nio.file.Paths) View(edu.illinois.cs.cogcomp.core.datastructures.textannotation.View) ACEReader(edu.illinois.cs.cogcomp.nlp.corpusreaders.ACEReader) Path(java.nio.file.Path) FilenameFilter(java.io.FilenameFilter) IOUtils(edu.illinois.cs.cogcomp.core.io.IOUtils)

Example 10 with Paths

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();
}
Also used : FileFieldParser(org.jabref.model.entry.FileFieldParser) List(java.util.List) Paths(java.nio.file.Paths) Map(java.util.Map) AbstractParamLayoutFormatter(org.jabref.logic.layout.AbstractParamLayoutFormatter) HashMap(java.util.HashMap) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) Collectors(java.util.stream.Collectors) LinkedFile(org.jabref.model.entry.LinkedFile) ArrayList(java.util.ArrayList) FileHelper(org.jabref.model.util.FileHelper) LinkedFile(org.jabref.model.entry.LinkedFile) Paths(java.nio.file.Paths)

Aggregations

Paths (java.nio.file.Paths)19 Path (java.nio.file.Path)12 IOException (java.io.IOException)10 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)8 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)8 ImmutableSet (com.google.common.collect.ImmutableSet)8 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)7 ExecutionContext (com.facebook.buck.step.ExecutionContext)7 List (java.util.List)7 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)6 ImmutableList (com.google.common.collect.ImmutableList)6 ImmutableMap (com.google.common.collect.ImmutableMap)6 Optional (java.util.Optional)6 BuckEventBusFactory (com.facebook.buck.event.BuckEventBusFactory)5 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)5 SourcePath (com.facebook.buck.rules.SourcePath)5 StepExecutionResult (com.facebook.buck.step.StepExecutionResult)5 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)5 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)5 BuildTarget (com.facebook.buck.model.BuildTarget)4