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

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

Introduction

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

Prototype

public static void delete(File f) throws IOException 

Source Link

Document

Delete file or empty folder

Usage

From source file:com.google.gct.idea.appengine.synchronization.SampleSyncTaskTest.java

License:Apache License

@Override
public void tearDown() throws IOException {
    FileUtils.delete(new File(mockAndroidRepoPath));
}

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

License:Open Source License

@Override
public void doWork() {
    try {//from   w ww .j a  v a2s  .c  o  m
        Git git;
        if (!cacheDir.exists()) {
            cacheDir.mkdirs();
            git = Git.cloneRepository().setURI(repoUri).setDirectory(cacheDir).setNoCheckout(true)
                    .setProgressMonitor(this).call();
        } else {
            git = Git.open(cacheDir);
            git.fetch().setProgressMonitor(this).call();
        }
        git.close();
    } catch (RepositoryNotFoundException | InvalidRemoteException ex) {
        Logger.getLogger(GITUpdateTask.class.getName()).log(Level.SEVERE, "Could not find repository", ex);
        try {
            FileUtils.delete(cacheDir);
            run();
        } catch (IOException | StackOverflowError ex1) {
            throw new RuntimeException("Fix of broken repository failed", ex1);
        }
    } catch (GitAPIException | IOException ex) {
        throw new RuntimeException("Could not download data", ex);
    }
}

From source file:it.com.atlassian.labs.speakeasy.util.jgit.WalkFetchConnection.java

License:Eclipse Distribution License

private boolean downloadPackedObject(final ProgressMonitor monitor, final AnyObjectId id)
        throws TransportException {
    // Search for the object in a remote pack whose index we have,
    // but whose pack we do not yet have.
    ///*from w w w  .ja  v a  2 s  . c om*/
    final Iterator<RemotePack> packItr = unfetchedPacks.iterator();
    while (packItr.hasNext() && !monitor.isCancelled()) {
        final RemotePack pack = packItr.next();
        try {
            pack.openIndex(monitor);
        } catch (IOException err) {
            // If the index won't open its either not found or
            // its a format we don't recognize. In either case
            // we may still be able to obtain the object from
            // another source, so don't consider it a failure.
            //
            recordError(id, err);
            packItr.remove();
            continue;
        }

        if (monitor.isCancelled()) {
            // If we were cancelled while the index was opening
            // the open may have aborted. We can't search an
            // unopen index.
            //
            return false;
        }

        if (!pack.index.hasObject(id)) {
            // Not in this pack? Try another.
            //
            continue;
        }

        // It should be in the associated pack. Download that
        // and attach it to the local repository so we can use
        // all of the contained objects.
        //
        try {
            pack.downloadPack(monitor);
        } catch (IOException err) {
            // If the pack failed to download, index correctly,
            // or open in the local repository we may still be
            // able to obtain this object from another pack or
            // an alternate.
            //
            recordError(id, err);
            continue;
        } finally {
            // If the pack was good its in the local repository
            // and Repository.hasObject(id) will succeed in the
            // future, so we do not need this data anymore. If
            // it failed the index and pack are unusable and we
            // shouldn't consult them again.
            //
            try {
                if (pack.tmpIdx != null)
                    FileUtils.delete(pack.tmpIdx);
            } catch (IOException e) {
                throw new TransportException(e.getMessage(), e);
            }
            packItr.remove();
        }

        if (!alreadyHave(id)) {
            // What the hell? This pack claimed to have
            // the object, but after indexing we didn't
            // actually find it in the pack.
            //
            recordError(id, new FileNotFoundException(
                    MessageFormat.format(JGitText.get().objectNotFoundIn, id.name(), pack.packName)));
            continue;
        }

        // Complete any other objects that we can.
        //
        final Iterator<ObjectId> pending = swapFetchQueue();
        while (pending.hasNext()) {
            final ObjectId p = pending.next();
            if (pack.index.hasObject(p)) {
                pending.remove();
                process(p);
            } else {
                workQueue.add(p);
            }
        }
        return true;

    }
    return false;
}

From source file:licenseUtil.LicenseUtil.java

License:Apache License

public static LicensingList processProjectsInFolder(File directory, String currentVersion,
        Boolean mavenProjectsOnly) throws IOException {

    LicensingList result = new LicensingList();

    File[] subdirs = directory.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY);
    File gitDir = new File(directory.getPath() + File.separator + ".git");
    File pomFile = new File(directory.getPath() + File.separator + "pom.xml");

    if (mavenProjectsOnly) {
        // check pom.xml
        if (!pomFile.exists()) {
            return result;
        }//from   w  w w.j a va 2 s .co m
    } else {
        // check git and update
        if (gitDir.exists()) {
            logger.info("update local repository");
            Utils.updateRepository(directory.getPath());
        }
        for (File dir : subdirs) {
            result.addAll(processProjectsInFolder(dir, currentVersion, true));
        }
        //return result;
    }
    logger.info("process directory: " + directory.getName());

    // check git and update
    if (gitDir.exists()) {
        logger.info("update local repository");
        Utils.updateRepository(directory.getPath());
    }

    if (pomFile.exists()) {
        logger.info("build effective-pom");
        File pom = new File(directory.getPath() + File.separator + EFFECTIVE_POM_FN);
        Utils.writeEffectivePom(new File(directory.getPath()), pom.getAbsolutePath());
        MavenProject project = null;
        try {
            project = Utils.readPom(pom);
        } catch (Exception e) {
            logger.warn("Could not read from pom file: \"" + pom.getPath() + "\" because of " + e.getMessage());
            return result;
        }
        FileUtils.delete(pom);

        // death first
        for (String module : project.getModules()) {
            File subdirectory = new File(directory + File.separator + module);
            result.addAll(processProjectsInFolder(subdirectory, currentVersion, true));
        }

        // add all licence objects of child modules
        for (LicensingObject licensingObject : result) {
            licensingObject.put(project.getArtifactId(), currentVersion);
        }

        result.addMavenProject(project, currentVersion);
    }
    return result;
}

From source file:org.eclipse.egit.core.internal.util.ProjectUtilTest.java

License:Open Source License

@Test
public void testCloseMissingProject() throws Exception {
    IProject p = mock(IProject.class);
    File projectFile = project.getProject().getLocation().append(".project").toFile();
    FileUtils.delete(projectFile);
    ProjectUtil.closeMissingProject(p, projectFile, new NullProgressMonitor());
    verify(p).close(any(IProgressMonitor.class));
}

From source file:org.eclipse.egit.core.project.GitProjectData.java

License:Open Source License

/**
 * Store information about the repository connection in the workspace
 *
 * @throws CoreException//from   w w  w .j  a  v a  2  s .  c  o m
 */
public void store() throws CoreException {
    final File dat = propertyFile();
    final File tmp;
    boolean ok = false;

    try {
        trace("save " + dat); //$NON-NLS-1$
        tmp = File.createTempFile("gpd_", //$NON-NLS-1$
                ".prop", //$NON-NLS-1$
                dat.getParentFile());
        final FileOutputStream o = new FileOutputStream(tmp);
        try {
            final Properties p = new Properties();
            for (final RepositoryMapping repoMapping : mappings) {
                repoMapping.store(p);
            }
            p.store(o, "GitProjectData"); //$NON-NLS-1$
            ok = true;
        } finally {
            o.close();
            if (!ok && tmp.exists()) {
                FileUtils.delete(tmp);
            }
        }
        if (dat.exists())
            FileUtils.delete(dat);
        if (!tmp.renameTo(dat)) {
            if (tmp.exists())
                FileUtils.delete(tmp);
            throw new CoreException(Activator.error(NLS.bind(CoreText.GitProjectData_saveFailed, dat), null));
        }
    } catch (IOException ioe) {
        throw new CoreException(Activator.error(NLS.bind(CoreText.GitProjectData_saveFailed, dat), ioe));
    }
}

From source file:org.eclipse.egit.core.test.GitTestCase.java

License:Open Source License

protected ObjectId createFileCorruptShort(Repository repository, IProject actProject, String name,
        String content) throws IOException {
    ObjectId id = createFile(repository, actProject, name, content);
    File file = new File(repository.getDirectory(),
            "objects/" + id.name().substring(0, 2) + "/" + id.name().substring(2));
    byte[] readFully = IO.readFully(file);
    FileUtils.delete(file);
    FileOutputStream fileOutputStream = new FileOutputStream(file);
    byte[] truncatedData = new byte[readFully.length - 1];
    System.arraycopy(readFully, 0, truncatedData, 0, truncatedData.length);
    fileOutputStream.write(truncatedData);
    fileOutputStream.close();//from  ww  w .  j  a  va 2 s.  c o m
    return id;
}

From source file:org.eclipse.egit.core.test.op.CreatePatchOperationTest.java

License:Open Source License

@Test
public void testUpdateWorkspacePatchPrefixes() throws Exception {
    // setup workspace
    File newFile = testRepository.createFile(project.getProject(), "new-file");
    testRepository.appendFileContent(newFile, "new content");
    File deletedFile = testRepository.createFile(project.getProject(), "deleted-file");
    commit = testRepository.addAndCommit(project.getProject(), deletedFile, "whatever");
    FileUtils.delete(deletedFile);

    // unprocessed patch
    DiffFormatter diffFmt = new DiffFormatter(null);
    diffFmt.setRepository(testRepository.getRepository());
    StringBuilder sb = new StringBuilder();
    sb.append("diff --git a/deleted-file b/deleted-file").append("\n");
    sb.append("deleted file mode 100644").append("\n");
    sb.append("index e69de29..0000000").append("\n");
    sb.append("--- a/deleted-file").append("\n");
    sb.append("+++ /dev/null").append("\n");
    sb.append("diff --git a/new-file b/new-file").append("\n");
    sb.append("new file mode 100644").append("\n");
    sb.append("index 0000000..47d2739").append("\n");
    sb.append("--- /dev/null").append("\n");
    sb.append("+++ b/new-file").append("\n");
    sb.append("@@ -0,0 +1 @@").append("\n");
    sb.append("+new content").append("\n");
    sb.append("\\ No newline at end of file").append("\n");
    sb.append(SIMPLE_PATCH_CONTENT);/* www.j av  a 2s  .  c  om*/

    // update patch
    CreatePatchOperation op = new CreatePatchOperation(testRepository.getRepository(), null);
    op.updateWorkspacePatchPrefixes(sb, diffFmt);
    // add workspace header
    StringBuilder sb1 = new StringBuilder("### Eclipse Workspace Patch 1.0\n#P ")
            .append(project.getProject().getName()).append("\n").append(sb);

    assertPatch(SIMPLE_WORKSPACE_PATCH_CONTENT, sb1.toString());
}

From source file:org.eclipse.egit.core.test.op.CreatePatchOperationTest.java

License:Open Source License

@Test
public void testWorkspacePatchForCommit() throws Exception {
    // setup workspace
    File deletedFile = testRepository.createFile(project.getProject(), "deleted-file");
    commit = testRepository.addAndCommit(project.getProject(), deletedFile, "whatever");
    FileUtils.delete(deletedFile);
    testRepository.appendFileContent(file, "another line");
    File newFile = testRepository.createFile(project.getProject(), "new-file");
    testRepository.appendFileContent(newFile, "new content");
    testRepository.untrack(deletedFile);
    testRepository.track(file);//  w w  w. j  a v  a 2s  . c o  m
    testRepository.track(newFile);
    commit = testRepository.commit("2nd commit");

    // create patch
    CreatePatchOperation operation = new CreatePatchOperation(testRepository.getRepository(), commit);

    operation.setHeaderFormat(DiffHeaderFormat.WORKSPACE);
    operation.execute(new NullProgressMonitor());

    assertPatch(SIMPLE_WORKSPACE_PATCH_CONTENT, operation.getPatchContent());
}

From source file:org.eclipse.egit.core.test.op.CreatePatchOperationTest.java

License:Open Source License

@Test
public void testWorkspacePatchForWorkingDir() throws Exception {
    // setup workspace
    testRepository.addToIndex(project.getProject().findMember(".classpath"));
    testRepository.addToIndex(project.getProject().findMember(".project"));
    testRepository.commit("commit all");
    testRepository.appendFileContent(file, "another line");
    File newFile = testRepository.createFile(project.getProject(), "new-file");
    testRepository.appendFileContent(newFile, "new content");
    File deletedFile = testRepository.createFile(project.getProject(), "deleted-file");
    commit = testRepository.addAndCommit(project.getProject(), deletedFile, "whatever");
    FileUtils.delete(deletedFile);

    // create patch
    CreatePatchOperation operation = new CreatePatchOperation(testRepository.getRepository(), null);

    operation.setHeaderFormat(DiffHeaderFormat.WORKSPACE);
    operation.execute(new NullProgressMonitor());

    assertPatch(SIMPLE_WORKSPACE_PATCH_CONTENT, operation.getPatchContent());
}