Example usage for java.nio.file FileVisitOption FOLLOW_LINKS

List of usage examples for java.nio.file FileVisitOption FOLLOW_LINKS

Introduction

In this page you can find the example usage for java.nio.file FileVisitOption FOLLOW_LINKS.

Prototype

FileVisitOption FOLLOW_LINKS

To view the source code for java.nio.file FileVisitOption FOLLOW_LINKS.

Click Source Link

Document

Follow symbolic links.

Usage

From source file:org.craftercms.studio.impl.v1.repository.disk.DiskContentRepository.java

/**
 * bootstrap the repository//from  ww w .j a  v  a2s . com
 */
public void bootstrap() throws Exception {
    Path cstudioFolder = constructRepoPath("cstudio");
    boolean bootstrapCheck = Files.exists(cstudioFolder);

    if (bootstrapEnabled && !bootstrapCheck) {
        try {
            logger.error("Bootstrapping repository for Crafter CMS");
            Files.createDirectories(constructRepoPath());
        } catch (Exception alreadyExistsErr) {
            // do nothing.
        }

        RequestContext context = RequestContext.getCurrent();
        //ServletContext servletContext = context.getServletContext();

        String bootstrapFolderPath = this.ctx.getRealPath(File.separator + "repo-bootstrap");// + File.separator + "bootstrap.xml");
        Path source = java.nio.file.FileSystems.getDefault().getPath(bootstrapFolderPath);
        //source = source.getParent();

        logger.info("Bootstrapping with baseline @ " + source.toFile().toString());

        Path target = constructRepoPath();

        TreeCopier tc = new TreeCopier(source, target, false, false);
        EnumSet<FileVisitOption> opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
        Files.walkFileTree(source, opts, Integer.MAX_VALUE, tc);
    }
}

From source file:org.craftercms.studio.impl.v1.repository.git.GitContentRepository.java

private void copyContentFromBlueprint(String blueprint, String site) {
    Path siteRepoPath = Paths.get(rootPath, "sites", site);
    Path blueprintPath = Paths.get(rootPath, "global-configuration", "blueprints", blueprint);
    EnumSet<FileVisitOption> opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
    TreeCopier tc = new TreeCopier(blueprintPath, siteRepoPath);
    try {//  w ww .  ja va2s  .  c  om
        Files.walkFileTree(blueprintPath, opts, Integer.MAX_VALUE, tc);
    } catch (IOException err) {
        logger.error("Error copping files from blueprint", err);
    }
}

From source file:org.craftercms.studio.impl.v1.repository.git.GitContentRepository.java

/**
 * bootstrap the repository/*from w w  w. ja va 2 s.  co  m*/
 */
public void bootstrap() throws Exception {
    Path globalConfigFolder = Paths.get(rootPath, "global-configuration");
    boolean bootstrapCheck = Files.exists(globalConfigFolder);

    if (bootstrapEnabled && !bootstrapCheck) {
        try {
            logger.error("Bootstrapping repository for Crafter CMS");
            Files.createDirectories(globalConfigFolder);
        } catch (Exception alreadyExistsErr) {
            // do nothing.
        }
        try {
            Path globalConfigRepoPath = Paths.get(globalConfigFolder.toAbsolutePath().toString(), ".git");
            Repository repository = FileRepositoryBuilder.create(globalConfigRepoPath.toFile());
            repository.create();
        } catch (IOException e) {
            logger.error("Error while creating global configuration repository", e);
        }

        String bootstrapFolderPath = this.ctx.getRealPath(File.separator + "gitrepo-bootstrap");
        Path source = java.nio.file.FileSystems.getDefault().getPath(bootstrapFolderPath);

        logger.info("Bootstrapping with baseline @ " + source.toFile().toString());

        Path target = Paths.get(rootPath);

        TreeCopier tc = new TreeCopier(source, target);
        EnumSet<FileVisitOption> opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
        Files.walkFileTree(source, opts, Integer.MAX_VALUE, tc);

        try {
            Repository globalConfigRepo = getGlobalConfigurationRepositoryInstance();

            Git git = new Git(globalConfigRepo);

            Status status = git.status().call();

            if (status.hasUncommittedChanges() || !status.isClean()) {
                DirCache dirCache = git.add().addFilepattern(".").call();
                RevCommit commit = git.commit().setMessage("initial content").call();
                String tmp = commit.getId().toString();
            }
        } catch (IOException | GitAPIException err) {
            logger.error("error creating initial commit for global configuration", err);
        }
    }
}

From source file:org.craftercms.studio.impl.v1.repository.git.GitContentRepositoryHelper.java

public boolean copyContentFromBlueprint(String blueprint, String site) {
    boolean toReturn = true;

    // Build a path to the Sandbox repo we'll be copying to
    Path siteRepoPath = buildRepoPath(GitRepositories.SANDBOX, site);
    // Build a path to the blueprint
    Path blueprintPath = buildRepoPath(GitRepositories.GLOBAL).resolve(
            Paths.get(studioConfiguration.getProperty(StudioConfiguration.BLUE_PRINTS_PATH), blueprint));
    EnumSet<FileVisitOption> opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
    // Let's copy!
    TreeCopier tc = new TreeCopier(blueprintPath, siteRepoPath);
    try {/*w w  w  .  ja  v a2 s  . com*/
        Files.walkFileTree(blueprintPath, opts, Integer.MAX_VALUE, tc);
    } catch (IOException err) {
        logger.error("Error copping files from blueprint", err);
        toReturn = false;
    }

    return toReturn;
}

From source file:org.eclipse.jdt.ls.core.internal.JDTUtilsTest.java

@Test
public void testFakeCompilationUnit() throws Exception {
    String tempDir = System.getProperty("java.io.tmpdir");
    File dir = new File(tempDir, "/test/src/org/eclipse");
    dir.mkdirs();/*from w w w.  j a  va 2  s  . c o  m*/
    File file = new File(dir, "Test.java");
    file.createNewFile();
    URI uri = file.toURI();
    JDTUtils.resolveCompilationUnit(uri);
    IProject project = WorkspaceHelper.getProject(ProjectsManager.DEFAULT_PROJECT_NAME);
    IFile iFile = project.getFile("/src/org/eclipse/Test.java");
    assertTrue(iFile.getFullPath().toString() + " doesn't exist.", iFile.exists());
    Path path = Paths.get(tempDir + "/test");
    Files.walk(path, FileVisitOption.FOLLOW_LINKS).sorted(Comparator.reverseOrder()).map(Path::toFile)
            .forEach(File::delete);
}

From source file:org.esa.nest.util.FileIOUtils.java

public static void copyFolder(final Path source, final Path target) throws IOException {
    // follow links when copying files
    final EnumSet<FileVisitOption> opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
    final CopyDirVisitor tc = new CopyDirVisitor(source, target, false);
    Files.walkFileTree(source, opts, Integer.MAX_VALUE, tc);
}

From source file:org.esa.nest.util.FileIOUtils.java

public static void moveFolder(final Path source, final Path target) throws IOException {
    // follow links when copying files
    final EnumSet<FileVisitOption> opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
    final CopyDirVisitor tc = new CopyDirVisitor(source, target, true);
    Files.walkFileTree(source, opts, Integer.MAX_VALUE, tc);
}

From source file:org.hyperledger.fabric.sdk.helper.SDKUtil.java

/**
 * Delete a file or directory/*www  .  j  a v  a 2s  .c om*/
 * @param file {@link File} representing file or directory
 * @throws IOException
 */
public static void deleteFileOrDirectory(File file) throws IOException {
    if (file.exists()) {
        if (file.isDirectory()) {
            Path rootPath = Paths.get(file.getAbsolutePath());

            Files.walk(rootPath, FileVisitOption.FOLLOW_LINKS).sorted(Comparator.reverseOrder())
                    .map(Path::toFile).forEach(File::delete);
        } else {
            file.delete();
        }
    } else {
        throw new RuntimeException("File or directory does not exist");
    }
}

From source file:org.mitre.mpf.mvc.util.NIOUtils.java

public static long getSubFilesAndDirsCount(final Path p) {
    long count = 0;
    //help from http://stackoverflow.com/questions/18300105/number-of-subfolders-in-a-folder-directory
    try {//from   www  .  ja  v  a2  s .c  om
        count = Files.walk(p, 1, FileVisitOption.FOLLOW_LINKS).count() - 1; // '-1' because the Path param (p) is also counted in
    } catch (IOException e) {
        log.error("Error determing the count of sub files and directories.", e);
    }

    return count;
}

From source file:org.omegat.util.FileUtil.java

/**
 * Returns a list of all files under the root directory by absolute path.
 * /* ww w.  j a  v  a 2  s . com*/
 * @throws IOException
 */
public static List<File> buildFileList(File rootDir, boolean recursive) throws IOException {
    int depth = recursive ? Integer.MAX_VALUE : 0;
    try (Stream<Path> stream = Files.find(rootDir.toPath(), depth, (p, attr) -> p.toFile().isFile(),
            FileVisitOption.FOLLOW_LINKS)) {
        return stream.map(Path::toFile).sorted(StreamUtil.localeComparator(File::getPath))
                .collect(Collectors.toList());
    }
}