Search in sources :

Example 26 with ConnectProviderOperation

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

the class ConnectProviderOperationTest method testNewRepository.

@Test
public void testNewRepository() throws CoreException, IOException {
    Repository repository = FileRepositoryBuilder.create(gitDir);
    repository.create();
    repository.close();
    ConnectProviderOperation operation = new ConnectProviderOperation(project.getProject(), gitDir);
    operation.execute(null);
    assertTrue(RepositoryProvider.isShared(project.getProject()));
    assertTrue(gitDir.exists());
}
Also used : TestRepository(org.eclipse.egit.core.test.TestRepository) Repository(org.eclipse.jgit.lib.Repository) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) Test(org.junit.Test)

Example 27 with ConnectProviderOperation

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

the class ConnectProviderOperationTest method testNoAutoIgnoresDerivedFolder.

@Test
public void testNoAutoIgnoresDerivedFolder() throws Exception {
    // disable auto-ignore
    IEclipsePreferences p = InstanceScope.INSTANCE.getNode(Activator.getPluginId());
    boolean autoignore = p.getBoolean(GitCorePreferences.core_autoIgnoreDerivedResources, false);
    if (autoignore) {
        p.putBoolean(GitCorePreferences.core_autoIgnoreDerivedResources, false);
    }
    try {
        Repository repository = FileRepositoryBuilder.create(gitDir);
        repository.create();
        repository.close();
        project.setBinFolderDerived();
        project.createSourceFolder();
        // not connected: no ignore
        IFolder binFolder = project.getProject().getFolder("bin");
        IPath binPath = binFolder.getLocation();
        assertTrue(binFolder.exists());
        assertFalse(RepositoryUtil.canBeAutoIgnored(binPath));
        IFolder srcFolder = project.getProject().getFolder("src");
        IPath srcPath = srcFolder.getLocation();
        assertTrue(srcFolder.exists());
        assertFalse(RepositoryUtil.canBeAutoIgnored(srcPath));
        IFolder notThere = project.getProject().getFolder("notThere");
        IPath notTherePath = notThere.getLocation();
        assertFalse(notThere.exists());
        assertFalse(RepositoryUtil.canBeAutoIgnored(notTherePath));
        // connect to git
        ConnectProviderOperation operation = new ConnectProviderOperation(project.getProject(), gitDir);
        operation.execute(null);
        assertTrue(RepositoryProvider.isShared(project.getProject()));
        Job.getJobManager().join(JobFamilies.AUTO_IGNORE, null);
        // connected, and *can* be automatically ignored
        assertTrue(RepositoryUtil.canBeAutoIgnored(binPath));
        // connected, and *can* be automatically ignored
        assertTrue(RepositoryUtil.canBeAutoIgnored(srcPath));
        // connected but not existing: we should not autoignore
        assertFalse(RepositoryUtil.canBeAutoIgnored(notTherePath));
        assertTrue(gitDir.exists());
    } finally {
        if (autoignore) {
            p.putBoolean(GitCorePreferences.core_autoIgnoreDerivedResources, true);
        }
    }
}
Also used : TestRepository(org.eclipse.egit.core.test.TestRepository) Repository(org.eclipse.jgit.lib.Repository) IPath(org.eclipse.core.runtime.IPath) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 28 with ConnectProviderOperation

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

the class ConnectProviderOperationTest method testNewUnsharedFile.

@Test
public void testNewUnsharedFile() throws CoreException, Exception {
    project.createSourceFolder();
    IFile fileA = project.getProject().getFolder("src").getFile("A.java");
    String srcA = "class A {\n" + "}\n";
    fileA.create(new ByteArrayInputStream(srcA.getBytes("UTF-8")), false, null);
    TestRepository thisGit = new TestRepository(gitDir);
    File committable = new File(fileA.getLocationURI());
    thisGit.addAndCommit(project.project, committable, "testNewUnsharedFile\n\nJunit tests\n");
    assertNull(RepositoryProvider.getProvider(project.getProject()));
    ConnectProviderOperation operation = new ConnectProviderOperation(project.getProject(), gitDir);
    operation.execute(null);
    assertNotNull(RepositoryProvider.getProvider(project.getProject()));
}
Also used : TestRepository(org.eclipse.egit.core.test.TestRepository) IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Test(org.junit.Test)

Example 29 with ConnectProviderOperation

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

the class ProjectUtils method createProjects.

/**
 * Create (import) a set of existing projects. The projects are
 * automatically connected to the repository they reside in.
 *
 * @param projectsToCreate
 *            the projects to create
 * @param open
 *            true to open existing projects, false to leave in current
 *            state
 * @param selectedWorkingSets
 *            the workings sets to add the created projects to, may be null
 *            or empty
 * @param monitor
 * @throws InvocationTargetException
 * @throws InterruptedException
 */
public static void createProjects(final Set<ProjectRecord> projectsToCreate, final boolean open, final IWorkingSet[] selectedWorkingSets, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    if (projectsToCreate.isEmpty()) {
        return;
    }
    IWorkspaceRunnable wsr = new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor actMonitor) throws CoreException {
            IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
            if (actMonitor.isCanceled()) {
                throw new OperationCanceledException();
            }
            Map<IProject, File> projectsToConnect = new HashMap<>();
            SubMonitor progress = SubMonitor.convert(actMonitor, projectsToCreate.size() * 2 + 1);
            for (ProjectRecord projectRecord : projectsToCreate) {
                if (progress.isCanceled()) {
                    throw new OperationCanceledException();
                }
                progress.setTaskName(projectRecord.getProjectLabel());
                IProject project = createExistingProject(projectRecord, open, progress.newChild(1));
                if (project == null) {
                    continue;
                }
                RepositoryFinder finder = new RepositoryFinder(project);
                finder.setFindInChildren(false);
                Collection<RepositoryMapping> mappings = finder.find(progress.newChild(1));
                if (!mappings.isEmpty()) {
                    RepositoryMapping mapping = mappings.iterator().next();
                    IPath absolutePath = mapping.getGitDirAbsolutePath();
                    if (absolutePath != null) {
                        projectsToConnect.put(project, absolutePath.toFile());
                    }
                }
                if (selectedWorkingSets != null && selectedWorkingSets.length > 0) {
                    workingSetManager.addToWorkingSets(project, selectedWorkingSets);
                }
            }
            if (!projectsToConnect.isEmpty()) {
                ConnectProviderOperation connect = new ConnectProviderOperation(projectsToConnect);
                connect.execute(progress.newChild(1));
            }
        }
    };
    try {
        ResourcesPlugin.getWorkspace().run(wsr, monitor);
    } catch (OperationCanceledException e) {
        throw new InterruptedException();
    } catch (CoreException e) {
        throw new InvocationTargetException(e);
    }
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) RepositoryFinder(org.eclipse.egit.core.project.RepositoryFinder) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) 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) IWorkingSetManager(org.eclipse.ui.IWorkingSetManager) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) File(java.io.File)

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