Example usage for org.eclipse.jgit.util FileUtils SKIP_MISSING

List of usage examples for org.eclipse.jgit.util FileUtils SKIP_MISSING

Introduction

In this page you can find the example usage for org.eclipse.jgit.util FileUtils SKIP_MISSING.

Prototype

int SKIP_MISSING

To view the source code for org.eclipse.jgit.util FileUtils SKIP_MISSING.

Click Source Link

Document

Option to skip deletion if file doesn't exist

Usage

From source file:de.hub.srcrepo.ProjectUtil.java

License:Open Source License

private static void closeMissingProject(IProject p, File projectFile, IProgressMonitor monitor)
        throws CoreException {
    // Create temporary .project file so it can be closed
    boolean closeFailed = false;
    File projectRoot = projectFile.getParentFile();
    if (!projectRoot.isFile()) {
        boolean hasRoot = projectRoot.exists();
        try {//from   www .ja  va 2 s . c  om
            if (!hasRoot)
                FileUtils.mkdirs(projectRoot, true);
            if (projectFile.createNewFile())
                p.close(new SubProgressMonitor(monitor, 1));
            else
                closeFailed = true;
        } catch (IOException e) {
            closeFailed = true;
        } finally {
            // Clean up created .project file
            try {
                FileUtils.delete(projectFile, FileUtils.RETRY | FileUtils.SKIP_MISSING);
            } catch (IOException e) {
                closeFailed = true;
            }
            // Clean up created folder
            if (!hasRoot)
                try {
                    FileUtils.delete(projectRoot,
                            FileUtils.RETRY | FileUtils.SKIP_MISSING | FileUtils.RECURSIVE);
                } catch (IOException e) {
                    closeFailed = true;
                }
        }
    } else
        closeFailed = true;
    // Delete projects that can't be closed
    if (closeFailed)
        p.delete(false, true, new SubProgressMonitor(monitor, 1));
}

From source file:de._692b8c32.cdlauncher.tasks.ExtractZipTask.java

License:Open Source License

@Override
public void doWork() {
    setProgress(-1);//  ww  w  .ja  v  a  2  s . c  o m

    try {
        FileUtils.delete(destinationDir, FileUtils.RECURSIVE | FileUtils.SKIP_MISSING);
        try (ZipFile zipFile = new ZipFile(cacheFile)) {
            zipFile.stream().filter(entry -> !entry.isDirectory()).forEach(entry -> {
                try {
                    String name = entry.getName();
                    for (int i = 0; i < skipSourceParts; i++) {
                        name = name.substring(name.indexOf("/"));
                    }
                    File file = new File(destinationDir, name);
                    file.getParentFile().mkdirs();
                    Files.copy(zipFile.getInputStream(entry), file.toPath());
                } catch (IOException ex) {
                    throw new RuntimeException("Failed to extract file from zip", ex);
                }
            });
        }
    } catch (IOException ex) {
        throw new RuntimeException("Failed to extract zip", ex);
    }
}

From source file:de._692b8c32.cdlauncher.tasks.GITCheckoutTask.java

License:Open Source License

@Override
public void doWork() {
    setProgress(-1);//w w w .j  a v  a  2s. c o  m

    try {
        Git git = Git.open(cacheDir);
        git.reset().setMode(ResetCommand.ResetType.HARD).call();
        git.checkout().setAllPaths(true).setForce(true).setName(branch).setStartPoint(startPoint.getValue())
                .call();

        if (destinationDir != null) {
            FileUtils.delete(destinationDir, FileUtils.RECURSIVE | FileUtils.SKIP_MISSING);
            destinationDir.mkdirs();
            Files.list(cacheDir.toPath()).filter(path -> !(".git".equals(path.getFileName().toString())))
                    .forEach(path -> {
                        try {
                            Files.move(path, destinationDir.toPath().resolve(path.getFileName()),
                                    StandardCopyOption.ATOMIC_MOVE);
                        } catch (IOException ex) {
                            throw new RuntimeException("Failed to move " + path.getFileName(), ex);
                        }
                    });
        }
        git.close();
    } catch (RepositoryNotFoundException | InvalidRemoteException ex) {
        throw new RuntimeException("Could not find repository");
    } catch (GitAPIException | IOException ex) {
        throw new RuntimeException("Could not checkout data", ex);
    }
}

From source file:org.eclipse.egit.ui.internal.dialogs.NonDeletedFilesDialog.java

License:Open Source License

@Override
protected void buttonPressed(int buttonId) {
    if (buttonId == RETRY) {
        boolean refresh = false;
        List<String> newPaths = new ArrayList<String>();
        for (String filePath : filePaths) {
            File file = new File(repository.getWorkTree(), filePath);
            try {
                FileUtils.delete(file, FileUtils.SKIP_MISSING | FileUtils.RECURSIVE);
                refresh = true;//from  ww  w  . j  ava 2  s  . com
            } catch (IOException e) {
                newPaths.add(filePath);
            }
        }
        filePaths.clear();
        filePaths.addAll(newPaths);
        tree.setInput(filePaths);
        tree.expandAll();
        if (refresh) {
            try {
                ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
            } catch (CoreException e) {
                Activator.handleError(e.getMessage(), e, false);
            }
        }
        retry.setEnabled(!filePaths.isEmpty());
        return;
    }
    super.buttonPressed(buttonId);
}

From source file:org.eclipse.egit.ui.internal.repository.tree.command.RemoveCommand.java

License:Open Source License

/**
 * Remove or delete the repository//from   ww  w. ja  v a2  s  .c om
 *
 * @param event
 * @param delete
 *            if <code>true</code>, the repository will be deleted from disk
 */
protected void removeRepository(final ExecutionEvent event, final boolean delete) {
    IWorkbenchSite activeSite = HandlerUtil.getActiveSite(event);
    IWorkbenchSiteProgressService service = (IWorkbenchSiteProgressService) activeSite
            .getService(IWorkbenchSiteProgressService.class);

    // get selected nodes
    final List<RepositoryNode> selectedNodes;
    try {
        selectedNodes = getSelectedNodes(event);
    } catch (ExecutionException e) {
        Activator.handleError(e.getMessage(), e, true);
        return;
    }

    if (delete) {
        String title = UIText.RemoveCommand_DeleteConfirmTitle;
        if (selectedNodes.size() > 1) {
            String message = NLS.bind(UIText.RemoveCommand_DeleteConfirmSingleMessage,
                    Integer.valueOf(selectedNodes.size()));
            if (!MessageDialog.openConfirm(getShell(event), title, message))
                return;
        } else if (selectedNodes.size() == 1) {
            String name = org.eclipse.egit.core.Activator.getDefault().getRepositoryUtil()
                    .getRepositoryName(selectedNodes.get(0).getObject());
            String message = NLS.bind(UIText.RemoveCommand_DeleteConfirmMultiMessage, name);
            if (!MessageDialog.openConfirm(getShell(event), title, message))
                return;
        }
    }

    Job job = new Job("Remove Repositories Job") { //$NON-NLS-1$

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            final List<IProject> projectsToDelete = new ArrayList<IProject>();

            monitor.setTaskName(UIText.RepositoriesView_DeleteRepoDeterminProjectsMessage);

            for (RepositoryNode node : selectedNodes) {
                if (node.getRepository().isBare())
                    continue;
                File workDir = node.getRepository().getWorkTree();
                final IPath wdPath = new Path(workDir.getAbsolutePath());
                for (IProject prj : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
                    if (monitor.isCanceled())
                        return Status.OK_STATUS;
                    if (wdPath.isPrefixOf(prj.getLocation())) {
                        projectsToDelete.add(prj);
                    }
                }
            }

            final boolean[] confirmedCanceled = new boolean[] { false, false };

            if (!projectsToDelete.isEmpty()) {
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        try {
                            confirmedCanceled[0] = confirmProjectDeletion(projectsToDelete, event);
                        } catch (OperationCanceledException e) {
                            confirmedCanceled[1] = true;
                        }
                    }
                });
            }
            if (confirmedCanceled[1]) {
                // canceled: return
                return Status.OK_STATUS;
            }
            if (confirmedCanceled[0]) {
                // confirmed deletion
                IWorkspaceRunnable wsr = new IWorkspaceRunnable() {

                    public void run(IProgressMonitor actMonitor) throws CoreException {

                        for (IProject prj : projectsToDelete)
                            prj.delete(false, false, actMonitor);
                    }
                };

                try {
                    ResourcesPlugin.getWorkspace().run(wsr, ResourcesPlugin.getWorkspace().getRoot(),
                            IWorkspace.AVOID_UPDATE, monitor);
                } catch (CoreException e1) {
                    Activator.logError(e1.getMessage(), e1);
                }
            }
            for (RepositoryNode node : selectedNodes) {
                util.removeDir(node.getRepository().getDirectory());
            }

            if (delete) {
                try {
                    for (RepositoryNode node : selectedNodes) {
                        Repository repo = node.getRepository();
                        if (!repo.isBare())
                            FileUtils.delete(repo.getWorkTree(), FileUtils.RECURSIVE | FileUtils.RETRY);
                        FileUtils.delete(repo.getDirectory(),
                                FileUtils.RECURSIVE | FileUtils.RETRY | FileUtils.SKIP_MISSING);
                    }
                } catch (IOException e) {
                    return Activator.createErrorStatus(e.getMessage(), e);
                }
            }
            return Status.OK_STATUS;
        }
    };

    service.schedule(job);
}