Search in sources :

Example 16 with ConnectProviderOperation

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

the class GitImportWizard method importProjects.

private void importProjects(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    switch(importWithDirectoriesPage.getWizardSelection()) {
        case GitSelectWizardPage.EXISTING_PROJECTS_WIZARD:
            {
                final Set<ProjectRecord> projectsToCreate = new HashSet<>();
                final List<IWorkingSet> workingSets = new ArrayList<>();
                // get the data from the pages in the UI thread
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        projectsToCreate.addAll(projectsImportPage.getCheckedProjects());
                        IWorkingSet[] workingSetArray = projectsImportPage.getSelectedWorkingSets();
                        workingSets.addAll(Arrays.asList(workingSetArray));
                        projectsImportPage.saveWidgetValues();
                    }
                });
                ProjectUtils.createProjects(projectsToCreate, workingSets.toArray(new IWorkingSet[workingSets.size()]), monitor);
                break;
            }
        case GitSelectWizardPage.NEW_WIZARD:
            {
                final File[] repoDir = new File[1];
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        repoDir[0] = getTargetRepository().getDirectory();
                    }
                });
                final List<IProject> previousProjects = Arrays.asList(ResourcesPlugin.getWorkspace().getRoot().getProjects());
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        new NewProjectAction(PlatformUI.getWorkbench().getActiveWorkbenchWindow()).run();
                    }
                });
                IWorkspaceRunnable wsr = new IWorkspaceRunnable() {

                    @Override
                    public void run(IProgressMonitor actMonitor) throws CoreException {
                        IProject[] currentProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
                        SubMonitor progress = SubMonitor.convert(actMonitor, currentProjects.length);
                        for (IProject current : currentProjects) if (!previousProjects.contains(current)) {
                            ConnectProviderOperation cpo = new ConnectProviderOperation(current, repoDir[0]);
                            cpo.execute(progress.newChild(1));
                        } else {
                            progress.worked(1);
                        }
                    }
                };
                try {
                    ResourcesPlugin.getWorkspace().run(wsr, monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
                break;
            }
        case GitSelectWizardPage.GENERAL_WIZARD:
            {
                final String[] projectName = new String[1];
                final boolean[] defaultLocation = new boolean[1];
                final String[] path = new String[1];
                final File[] repoDir = new File[1];
                // get the data from the page in the UI thread
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        projectName[0] = createGeneralProjectPage.getProjectName();
                        defaultLocation[0] = createGeneralProjectPage.isDefaultLocation();
                        path[0] = importWithDirectoriesPage.getPath();
                        repoDir[0] = getTargetRepository().getDirectory();
                    }
                });
                try {
                    IWorkspaceRunnable wsr = new IWorkspaceRunnable() {

                        @Override
                        public void run(IProgressMonitor actMonitor) throws CoreException {
                            final IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(projectName[0]);
                            desc.setLocation(new Path(path[0]));
                            SubMonitor progress = SubMonitor.convert(actMonitor, 4);
                            IProject prj = ResourcesPlugin.getWorkspace().getRoot().getProject(desc.getName());
                            prj.create(desc, progress.newChild(1));
                            prj.open(progress.newChild(1));
                            ConnectProviderOperation cpo = new ConnectProviderOperation(prj, repoDir[0]);
                            cpo.execute(progress.newChild(1));
                            ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_ONE, progress.newChild(1));
                        }
                    };
                    ResourcesPlugin.getWorkspace().run(wsr, monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
                break;
            }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) HashSet(java.util.HashSet) Set(java.util.Set) IWorkingSet(org.eclipse.ui.IWorkingSet) SubMonitor(org.eclipse.core.runtime.SubMonitor) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProjectDescription(org.eclipse.core.resources.IProjectDescription) NewProjectAction(org.eclipse.ui.actions.NewProjectAction) ArrayList(java.util.ArrayList) List(java.util.List) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) IWorkingSet(org.eclipse.ui.IWorkingSet)

Example 17 with ConnectProviderOperation

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

the class NewRepositoryWizard method autoShareProjects.

/**
 * auto-share projects which are located inside newly created repository
 *
 * @param repoToCreate
 * @param projects
 */
private void autoShareProjects(Repository repoToCreate, IProject[] projects) {
    final Map<IProject, File> projectsMap = new HashMap<>();
    for (IProject project : projects) projectsMap.put(project, repoToCreate.getDirectory());
    ConnectProviderOperation op = new ConnectProviderOperation(projectsMap);
    JobUtil.scheduleUserJob(op, CoreText.Activator_AutoShareJobName, JobFamilies.AUTO_SHARE);
}
Also used : HashMap(java.util.HashMap) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) File(java.io.File) IProject(org.eclipse.core.resources.IProject)

Example 18 with ConnectProviderOperation

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

the class TestRepository method connect.

/**
 * Connect a project to this repository
 *
 * @param project
 * @throws CoreException
 */
public void connect(IProject project) throws CoreException {
    ConnectProviderOperation op = new ConnectProviderOperation(project, this.getRepository().getDirectory());
    op.execute(null);
}
Also used : ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation)

Example 19 with ConnectProviderOperation

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

the class LocalRepositoryTestCase method shareProjects.

protected void shareProjects(File repositoryDir) throws Exception {
    Repository myRepository = lookupRepository(repositoryDir);
    FilenameFilter projectFilter = new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            return name.equals(".project");
        }
    };
    for (File file : myRepository.getWorkTree().listFiles()) {
        if (file.isDirectory()) {
            if (file.list(projectFilter).length > 0) {
                IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(file.getName());
                desc.setLocation(new Path(file.getPath()));
                IProject prj = ResourcesPlugin.getWorkspace().getRoot().getProject(file.getName());
                prj.create(desc, null);
                prj.open(null);
                try {
                    new ConnectProviderOperation(prj, myRepository.getDirectory()).execute(null);
                } catch (Exception e) {
                    Activator.logError("Failed to connect project to repository", e);
                }
                assertConnected(prj);
            }
        }
    }
    TestUtil.waitForJobs(50, 5000);
}
Also used : Path(org.eclipse.core.runtime.Path) FilenameFilter(java.io.FilenameFilter) Repository(org.eclipse.jgit.lib.Repository) IProjectDescription(org.eclipse.core.resources.IProjectDescription) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException)

Example 20 with ConnectProviderOperation

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

the class LocalRepositoryTestCase method createProjectAndCommitToRepository.

protected File createProjectAndCommitToRepository(String repoName, String project1Name, String project2Name) throws Exception {
    Repository myRepository = createLocalTestRepository(repoName);
    File gitDir = myRepository.getDirectory();
    // we need to commit into master first
    IProject firstProject = createStandardTestProjectInRepository(myRepository, project1Name);
    try {
        new ConnectProviderOperation(firstProject, gitDir).execute(null);
    } catch (Exception e) {
        Activator.logError("Failed to connect project to repository", e);
    }
    assertConnected(firstProject);
    IProject secondProject = null;
    if (project2Name != null) {
        secondProject = createStandardTestProjectInRepository(myRepository, project2Name);
        try {
            new ConnectProviderOperation(secondProject, gitDir).execute(null);
        } catch (Exception e) {
            Activator.logError("Failed to connect project to repository", e);
        }
        assertConnected(secondProject);
    }
    IFile dotProject = firstProject.getFile(".project");
    assertTrue(".project is not accessible: " + dotProject, dotProject.isAccessible());
    IFolder folder = firstProject.getFolder(FOLDER);
    IFile textFile = folder.getFile(FILE1);
    IFile textFile2 = folder.getFile(FILE2);
    IFile[] commitables = null;
    if (secondProject != null) {
        folder = secondProject.getFolder(FOLDER);
        IFile secondtextFile = folder.getFile(FILE1);
        IFile secondtextFile2 = folder.getFile(FILE2);
        commitables = new IFile[] { dotProject, textFile, textFile2, secondtextFile, secondtextFile2 };
    } else {
        commitables = new IFile[] { dotProject, textFile, textFile2 };
    }
    ArrayList<IFile> untracked = new ArrayList<IFile>();
    untracked.addAll(Arrays.asList(commitables));
    // commit to stable
    CommitOperation op = new CommitOperation(commitables, untracked, TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER, "Initial commit");
    op.execute(null);
    // now create a stable branch (from master)
    createStableBranch(myRepository);
    // and check in some stuff into master again
    String newContent = "Touched at " + System.currentTimeMillis();
    IFile file = touch(firstProject.getName(), FOLDER + '/' + FILE1, newContent);
    addAndCommit(file, newContent);
    // Make sure cache entry is already listening for changes
    IndexDiffCache cache = Activator.getDefault().getIndexDiffCache();
    cache.getIndexDiffCacheEntry(lookupRepository(gitDir));
    return gitDir;
}
Also used : IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) IndexDiffCache(org.eclipse.egit.core.internal.indexdiff.IndexDiffCache) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) Repository(org.eclipse.jgit.lib.Repository) CommitOperation(org.eclipse.egit.core.op.CommitOperation) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder)

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