Search in sources :

Example 1 with DisconnectProviderOperation

use of org.eclipse.egit.core.op.DisconnectProviderOperation in project jbosstools-openshift by jbosstools.

the class TestRepository method disconnect.

/**
 * Disconnects provider from project
 *
 * @param project
 * @throws CoreException
 */
public void disconnect(IProject project) throws CoreException {
    Collection<IProject> projects = Collections.singleton(project.getProject());
    DisconnectProviderOperation disconnect = new DisconnectProviderOperation(projects);
    disconnect.execute(null);
}
Also used : DisconnectProviderOperation(org.eclipse.egit.core.op.DisconnectProviderOperation) IProject(org.eclipse.core.resources.IProject)

Example 2 with DisconnectProviderOperation

use of org.eclipse.egit.core.op.DisconnectProviderOperation in project egit by eclipse.

the class GitBlobStorageTest method testGitFileHistorySingleProjectOk.

@Test
public void testGitFileHistorySingleProjectOk() throws Exception {
    IProgressMonitor progress = new NullProgressMonitor();
    TestProject singleRepoProject = new TestProject(true, "Project-2");
    IProject proj = singleRepoProject.getProject();
    File singleProjectGitDir = new File(proj.getLocation().toFile(), Constants.DOT_GIT);
    if (singleProjectGitDir.exists())
        FileUtils.delete(singleProjectGitDir, FileUtils.RECURSIVE | FileUtils.RETRY);
    Repository singleProjectRepo = FileRepositoryBuilder.create(singleProjectGitDir);
    singleProjectRepo.create();
    // Repository must be mapped in order to test the GitFileHistory
    Activator.getDefault().getRepositoryUtil().addConfiguredRepository(singleProjectGitDir);
    ConnectProviderOperation connectOp = new ConnectProviderOperation(proj, singleProjectGitDir);
    connectOp.execute(progress);
    try (Git git = new Git(singleProjectRepo)) {
        IFile file = proj.getFile("file");
        file.create(new ByteArrayInputStream("data".getBytes("UTF-8")), 0, progress);
        git.add().addFilepattern(".").call();
        RevCommit commit = git.commit().setAuthor("JUnit", "junit@jgit.org").setAll(true).setMessage("First commit").call();
        GitFileHistoryProvider fhProvider = new GitFileHistoryProvider();
        IFileHistory fh = fhProvider.getFileHistoryFor(singleRepoProject.getProject(), 0, null);
        assertNotNull(fh);
        assertEquals(fh.getFileRevisions().length, 1);
        assertNotNull(fh.getFileRevision(commit.getId().getName()));
    } finally {
        DisconnectProviderOperation disconnectOp = new DisconnectProviderOperation(Collections.singletonList(proj));
        disconnectOp.execute(progress);
        Activator.getDefault().getRepositoryUtil().removeDir(singleProjectGitDir);
        singleProjectRepo.close();
        singleRepoProject.dispose();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) IProject(org.eclipse.core.resources.IProject) IFileHistory(org.eclipse.team.core.history.IFileHistory) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Repository(org.eclipse.jgit.lib.Repository) Git(org.eclipse.jgit.api.Git) TestProject(org.eclipse.egit.core.test.TestProject) ByteArrayInputStream(java.io.ByteArrayInputStream) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) IFile(org.eclipse.core.resources.IFile) File(java.io.File) DisconnectProviderOperation(org.eclipse.egit.core.op.DisconnectProviderOperation) RevCommit(org.eclipse.jgit.revwalk.RevCommit) GitFileHistoryProvider(org.eclipse.egit.core.internal.storage.GitFileHistoryProvider) Test(org.junit.Test)

Example 3 with DisconnectProviderOperation

use of org.eclipse.egit.core.op.DisconnectProviderOperation in project egit by eclipse.

the class SharingWizardTest method erase.

private void erase(String projectName, Set<File> dirs) throws CoreException, IOException {
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    if (project.exists()) {
        RepositoryMapping repo = RepositoryMapping.getMapping(project);
        if (repo != null) {
            IPath gitDirAbsolutePath = repo.getGitDirAbsolutePath();
            File canonicalFile = gitDirAbsolutePath.toFile().getCanonicalFile();
            dirs.add(canonicalFile);
            File workspacePath = ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile().getCanonicalFile();
            File gitDirParent = canonicalFile.getParentFile();
            if (!(gitDirParent.toString() + File.separator).startsWith(workspacePath.toString() + File.separator))
                if (!(gitDirParent.toString() + File.separator).startsWith(getTestDirectory().getAbsolutePath().toString() + File.separator))
                    fail("Attempting cleanup of directory neither in workspace nor test directory" + canonicalFile);
            new DisconnectProviderOperation(Collections.singleton(project)).execute(null);
        }
        project.close(null);
        project.delete(true, true, null);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) File(java.io.File) DisconnectProviderOperation(org.eclipse.egit.core.op.DisconnectProviderOperation) IProject(org.eclipse.core.resources.IProject)

Example 4 with DisconnectProviderOperation

use of org.eclipse.egit.core.op.DisconnectProviderOperation in project egit by eclipse.

the class TestRepository method disconnect.

/**
 * Disconnects provider from project
 *
 * @param project
 * @throws Exception
 */
public void disconnect(IProject project) throws Exception {
    Collection<IProject> projects = Collections.singleton(project.getProject());
    DisconnectProviderOperation disconnect = new DisconnectProviderOperation(projects);
    ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor monitor) throws CoreException {
            disconnect.execute(null);
        }
    }, project, IWorkspace.AVOID_UPDATE, null);
    TestUtils.waitForJobs(5000, null);
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) DisconnectProviderOperation(org.eclipse.egit.core.op.DisconnectProviderOperation) IProject(org.eclipse.core.resources.IProject)

Example 5 with DisconnectProviderOperation

use of org.eclipse.egit.core.op.DisconnectProviderOperation in project egit by eclipse.

the class DisconnectActionHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IProject[] selectedProjects = getProjectsForSelectedResources();
    List<IProject> projects = new ArrayList<>(selectedProjects.length);
    for (IProject project : selectedProjects) {
        if (project.isOpen() && ResourceUtil.isSharedWithGit(project)) {
            projects.add(project);
        }
    }
    if (projects.isEmpty()) {
        return null;
    }
    JobUtil.scheduleUserJob(new DisconnectProviderOperation(projects), UIText.Disconnect_disconnect, JobFamilies.DISCONNECT, new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent actEvent) {
            GitLightweightDecorator.refresh();
        }
    });
    return null;
}
Also used : JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) ArrayList(java.util.ArrayList) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) DisconnectProviderOperation(org.eclipse.egit.core.op.DisconnectProviderOperation) IProject(org.eclipse.core.resources.IProject)

Aggregations

IProject (org.eclipse.core.resources.IProject)5 DisconnectProviderOperation (org.eclipse.egit.core.op.DisconnectProviderOperation)5 File (java.io.File)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1 IFile (org.eclipse.core.resources.IFile)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)1 GitFileHistoryProvider (org.eclipse.egit.core.internal.storage.GitFileHistoryProvider)1 ConnectProviderOperation (org.eclipse.egit.core.op.ConnectProviderOperation)1 RepositoryMapping (org.eclipse.egit.core.project.RepositoryMapping)1 TestProject (org.eclipse.egit.core.test.TestProject)1 Git (org.eclipse.jgit.api.Git)1 Repository (org.eclipse.jgit.lib.Repository)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1