Search in sources :

Example 6 with FileVisitOption

use of java.nio.file.FileVisitOption in project raml-module-builder by folio-org.

the class RamlDirCopier method copy.

/**
 * Copy a RAML directory tree to a target directory tree and
 * dereference all $ref references of all .json and .schema files.
 * It does not delete any existing files or directories at target,
 * but a file may get overwritten.
 *
 * @param sourceDir  directory tree to copy
 * @param targetDir  target directory
 * @throws IOException  on read or write error
 */
public static void copy(Path sourceDir, Path targetDir) throws IOException {
    File targetFile = targetDir.toFile();
    if (!targetFile.isDirectory()) {
        targetFile.mkdirs();
    }
    Set<FileVisitOption> options = Collections.emptySet();
    RamlDirCopier ramlDirCopier = new RamlDirCopier(sourceDir, targetDir);
    Files.walkFileTree(sourceDir, options, Integer.MAX_VALUE, ramlDirCopier.ramlTypeCollectorVisitor);
    Files.walkFileTree(sourceDir, options, Integer.MAX_VALUE, ramlDirCopier.fileVisitor);
}
Also used : FileVisitOption(java.nio.file.FileVisitOption) File(java.io.File)

Example 7 with FileVisitOption

use of java.nio.file.FileVisitOption in project elasticsearch by elastic.

the class LogConfigurator method configure.

private static void configure(final Settings settings, final Path configsPath, final Path logsPath) throws IOException, UserException {
    Objects.requireNonNull(settings);
    Objects.requireNonNull(configsPath);
    Objects.requireNonNull(logsPath);
    setLogConfigurationSystemProperty(logsPath, settings);
    // we initialize the status logger immediately otherwise Log4j will complain when we try to get the context
    configureStatusLogger();
    final LoggerContext context = (LoggerContext) LogManager.getContext(false);
    final List<AbstractConfiguration> configurations = new ArrayList<>();
    final PropertiesConfigurationFactory factory = new PropertiesConfigurationFactory();
    final Set<FileVisitOption> options = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
    Files.walkFileTree(configsPath, options, Integer.MAX_VALUE, new SimpleFileVisitor<Path>() {

        @Override
        public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
            if (file.getFileName().toString().equals("log4j2.properties")) {
                configurations.add((PropertiesConfiguration) factory.getConfiguration(context, file.toString(), file.toUri()));
            }
            return FileVisitResult.CONTINUE;
        }
    });
    if (configurations.isEmpty()) {
        throw new UserException(ExitCodes.CONFIG, "no log4j2.properties found; tried [" + configsPath + "] and its subdirectories");
    }
    context.start(new CompositeConfiguration(configurations));
    configureLoggerLevels(settings);
}
Also used : Path(java.nio.file.Path) FileVisitOption(java.nio.file.FileVisitOption) CompositeConfiguration(org.apache.logging.log4j.core.config.composite.CompositeConfiguration) ArrayList(java.util.ArrayList) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) LoggerContext(org.apache.logging.log4j.core.LoggerContext) PropertiesConfiguration(org.apache.logging.log4j.core.config.properties.PropertiesConfiguration) AbstractConfiguration(org.apache.logging.log4j.core.config.AbstractConfiguration) PropertiesConfigurationFactory(org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory) UserException(org.elasticsearch.cli.UserException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Example 8 with FileVisitOption

use of java.nio.file.FileVisitOption in project jetty.project by eclipse.

the class CorrectMavenCentralRefs method fix.

public void fix(Path buildRoot) throws IOException {
    // Find all of the *.mod files
    PathFinder finder = new PathFinder();
    finder.setFileMatcher("glob:**/*.mod");
    finder.setBase(buildRoot);
    // Matcher for target directories
    PathMatcher targetMatcher = PathMatchers.getMatcher("glob:**/target/**");
    PathMatcher testMatcher = PathMatchers.getMatcher("glob:**/test/**");
    System.out.printf("Walking path: %s%n", buildRoot);
    Set<FileVisitOption> options = Collections.emptySet();
    Files.walkFileTree(buildRoot, options, 30, finder);
    System.out.printf("Found: %d hits%n", finder.getHits().size());
    int count = 0;
    for (Path path : finder.getHits()) {
        if (Files.isDirectory(path)) {
            // skip
            continue;
        }
        if (targetMatcher.matches(path)) {
            // skip
            continue;
        }
        if (testMatcher.matches(path)) {
            // skip
            continue;
        }
        if (processModFile(path)) {
            count++;
        }
    }
    System.out.printf("Processed %,d modules", count);
}
Also used : Path(java.nio.file.Path) PathMatcher(java.nio.file.PathMatcher) FileVisitOption(java.nio.file.FileVisitOption) PathFinder(org.eclipse.jetty.start.PathFinder)

Example 9 with FileVisitOption

use of java.nio.file.FileVisitOption in project vcell by virtualcell.

the class CopySimFiles method execute.

@Override
public int execute() {
    try {
        // append to log, if it exists already
        pw = new PrintWriter(new FileWriter(logName, true));
        try {
            fs = FileSystems.getDefault();
            Path from = fs.getPath(fromDirectory);
            File toDir = new File(toDirectory);
            if (!toDir.exists()) {
                toDir.mkdir();
                if (lg.isDebugEnabled()) {
                    lg.debug("copying " + from + " to " + toDir + " (created)");
                }
            } else if (lg.isDebugEnabled()) {
                lg.debug("copying " + from + " to " + toDir + " (exists)");
            }
            Set<FileVisitOption> empty = Collections.emptySet();
            Files.walkFileTree(from, empty, 1, this);
            return 0;
        } finally {
            pw.close();
            pw = null;
        }
    } catch (IOException e) {
        exc = e;
        return 1;
    }
}
Also used : Path(java.nio.file.Path) FileVisitOption(java.nio.file.FileVisitOption) FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 10 with FileVisitOption

use of java.nio.file.FileVisitOption in project liferay-ide by liferay.

the class IOUtil method copyDirToDir.

public static void copyDirToDir(File src, File dest) {
    Path targetPath = Paths.get(dest.getPath().toString());
    Path sourcePath = Paths.get(src.getPath().toString());
    EnumSet<FileVisitOption> opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
    TreeCopier tc = new TreeCopier(sourcePath, targetPath);
    try {
        Files.walkFileTree(sourcePath, opts, Integer.MAX_VALUE, tc);
    } catch (IOException ioe) {
        LiferayCore.logError("copy folder " + src.getName() + " error", ioe);
    }
}
Also used : Path(java.nio.file.Path) FileVisitOption(java.nio.file.FileVisitOption) IOException(java.io.IOException)

Aggregations

FileVisitOption (java.nio.file.FileVisitOption)21 Path (java.nio.file.Path)18 IOException (java.io.IOException)12 FileVisitResult (java.nio.file.FileVisitResult)6 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)6 File (java.io.File)5 HashSet (java.util.HashSet)5 HashMap (java.util.HashMap)4 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)4 Test (org.junit.Test)4 FileWriter (java.io.FileWriter)2 PrintWriter (java.io.PrintWriter)2 FileSystem (java.nio.file.FileSystem)2 PathMatcher (java.nio.file.PathMatcher)2 ArrayList (java.util.ArrayList)2 LoggerContext (org.apache.logging.log4j.core.LoggerContext)2 AbstractConfiguration (org.apache.logging.log4j.core.config.AbstractConfiguration)2 CompositeConfiguration (org.apache.logging.log4j.core.config.composite.CompositeConfiguration)2 PropertiesConfiguration (org.apache.logging.log4j.core.config.properties.PropertiesConfiguration)2 PropertiesConfigurationFactory (org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory)2