Search in sources :

Example 6 with ConnectProviderOperation

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

the class GitProjectSetCapabilityTest method connectProject.

private void connectProject(IProject project, File gitDir) throws CoreException {
    ConnectProviderOperation operation = new ConnectProviderOperation(project.getProject(), gitDir);
    operation.execute(null);
}
Also used : ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation)

Example 7 with ConnectProviderOperation

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

the class ProjectReferenceImporter method importProjects.

private List<IProject> importProjects(final Set<ProjectReference> projects, final IPath workDir, final File repositoryPath, final IProgressMonitor monitor) throws TeamException {
    try {
        List<IProject> importedProjects = new ArrayList<IProject>();
        // import projects from the current repository to workspace
        final IWorkspace workspace = ResourcesPlugin.getWorkspace();
        final IWorkspaceRoot root = workspace.getRoot();
        SubMonitor progress = SubMonitor.convert(monitor, projects.size());
        for (final ProjectReference projectToImport : projects) {
            SubMonitor subProgress = SubMonitor.convert(progress.newChild(1), 3);
            final IPath projectDir = workDir.append(projectToImport.getProjectDir());
            final IProjectDescription projectDescription = workspace.loadProjectDescription(projectDir.append(IProjectDescription.DESCRIPTION_FILE_NAME));
            final IProject project = root.getProject(projectDescription.getName());
            if (!project.exists()) {
                project.create(projectDescription, subProgress.newChild(1));
                importedProjects.add(project);
            }
            subProgress.setWorkRemaining(2);
            project.open(subProgress.newChild(1));
            final ConnectProviderOperation connectProviderOperation = new ConnectProviderOperation(project, repositoryPath);
            connectProviderOperation.execute(subProgress.newChild(1));
        }
        return importedProjects;
    } catch (final CoreException e) {
        throw TeamException.asTeamException(e);
    }
}
Also used : ProjectReference(org.eclipse.egit.core.ProjectReference) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) ArrayList(java.util.ArrayList) SubMonitor(org.eclipse.core.runtime.SubMonitor) IProjectDescription(org.eclipse.core.resources.IProjectDescription) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) IProject(org.eclipse.core.resources.IProject)

Example 8 with ConnectProviderOperation

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

the class AddCommand method autoShareProjects.

private void autoShareProjects(File repositoryDir) {
    // Don't even try to auto-share for bare repositories.
    IPath workingDirPath;
    try {
        Repository repo = Activator.getDefault().getRepositoryCache().lookupRepository(repositoryDir);
        if (repo.isBare()) {
            return;
        }
        workingDirPath = new Path(repo.getWorkTree().getAbsolutePath());
    } catch (IOException e) {
        org.eclipse.egit.ui.Activator.logError(e.getLocalizedMessage(), e);
        return;
    }
    Map<IProject, File> connections = new HashMap<>();
    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    for (IProject project : projects) {
        // Skip closed projects
        if (!project.isAccessible()) {
            continue;
        }
        RepositoryProvider provider = RepositoryProvider.getProvider(project);
        if (provider != null) {
            continue;
        }
        IPath location = project.getLocation();
        if (location == null) {
            continue;
        }
        // even search for a mapping.
        if (!workingDirPath.isPrefixOf(location)) {
            continue;
        }
        RepositoryFinder f = new RepositoryFinder(project);
        f.setFindInChildren(false);
        try {
            List<RepositoryMapping> mappings = f.find(new NullProgressMonitor());
            if (!mappings.isEmpty()) {
                // Connect to the first one; it's the innermost.
                IPath gitDir = mappings.get(0).getGitDirAbsolutePath();
                if (gitDir != null) {
                    connections.put(project, gitDir.toFile());
                }
            }
        } catch (CoreException e) {
            // Ignore this project in that case
            continue;
        }
    }
    if (!connections.isEmpty()) {
        ConnectProviderOperation operation = new ConnectProviderOperation(connections);
        operation.setRefreshResources(false);
        JobUtil.scheduleUserJob(operation, CoreText.Activator_AutoShareJobName, JobFamilies.AUTO_SHARE);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) RepositoryFinder(org.eclipse.egit.core.project.RepositoryFinder) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) Repository(org.eclipse.jgit.lib.Repository) CoreException(org.eclipse.core.runtime.CoreException) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) File(java.io.File) RepositoryProvider(org.eclipse.team.core.RepositoryProvider)

Example 9 with ConnectProviderOperation

use of org.eclipse.egit.core.op.ConnectProviderOperation 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 10 with ConnectProviderOperation

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

the class GitResourceVariantTreeTest method shouldReturnTwoRoots.

/**
 * When we have two or more project associated with repository, roots()
 * method should return list of project. In this case we have two project
 * associated with particular repository, therefore '2' value is expected.
 *
 * @throws Exception
 */
@Test
public void shouldReturnTwoRoots() throws Exception {
    // when
    // create second project
    TestProject secondProject = new TestProject(true, "Project-2");
    try {
        IProject secondIProject = secondProject.project;
        // add connect project with repository
        new ConnectProviderOperation(secondIProject, gitDir).execute(null);
        try (Git git = new Git(repo)) {
            git.commit().setAuthor("JUnit", "junit@egit.org").setMessage("Initial commit").call();
        }
        GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, HEAD, false);
        GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
        // given
        GitResourceVariantTree grvt = new GitTestResourceVariantTree(dataSet, null, null);
        // then
        IResource[] roots = grvt.roots();
        // sort in order to be able to assert the project instances
        Arrays.sort(roots, new Comparator<IResource>() {

            @Override
            public int compare(IResource r1, IResource r2) {
                String path1 = r1.getFullPath().toString();
                String path2 = r2.getFullPath().toString();
                return path1.compareTo(path2);
            }
        });
        assertEquals(2, roots.length);
        IResource actualProject = roots[0];
        assertEquals(this.project.project, actualProject);
        IResource actualProject1 = roots[1];
        assertEquals(secondIProject, actualProject1);
    } finally {
        secondProject.dispose();
    }
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) IProject(org.eclipse.core.resources.IProject) Git(org.eclipse.jgit.api.Git) TestProject(org.eclipse.egit.core.test.TestProject) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) IResource(org.eclipse.core.resources.IResource) Test(org.junit.Test)

Aggregations

ConnectProviderOperation (org.eclipse.egit.core.op.ConnectProviderOperation)29 IProject (org.eclipse.core.resources.IProject)16 File (java.io.File)14 Repository (org.eclipse.jgit.lib.Repository)12 Test (org.junit.Test)11 IFile (org.eclipse.core.resources.IFile)10 CoreException (org.eclipse.core.runtime.CoreException)9 Path (org.eclipse.core.runtime.Path)9 IProjectDescription (org.eclipse.core.resources.IProjectDescription)7 IPath (org.eclipse.core.runtime.IPath)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 ArrayList (java.util.ArrayList)6 IFolder (org.eclipse.core.resources.IFolder)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)5 SubMonitor (org.eclipse.core.runtime.SubMonitor)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IOException (java.io.IOException)4 TestRepository (org.eclipse.egit.core.test.TestRepository)4 Git (org.eclipse.jgit.api.Git)4 HashMap (java.util.HashMap)3