Search in sources :

Example 6 with IgnoreOperation

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

the class IgnoreOperationTest method testIgnoreFile.

@Test
public void testIgnoreFile() throws Exception {
    IFile aFile = project.createFile("aFile.txt", new byte[0]);
    IgnoreOperation operation = executeIgnore(aFile.getLocation());
    String content = project.getFileContent(Constants.GITIGNORE_FILENAME);
    assertEquals("/aFile.txt\n", content);
    assertFalse(operation.isGitignoreOutsideWSChanged());
}
Also used : IFile(org.eclipse.core.resources.IFile) IgnoreOperation(org.eclipse.egit.core.op.IgnoreOperation) Test(org.junit.Test)

Example 7 with IgnoreOperation

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

the class IgnoreOperationTest method testWithNestedProjects.

@Test
public void testWithNestedProjects() throws Exception {
    TestProject nested = new TestProject(true, "Project-1/Project-2");
    try {
        // Use Project-1 to create folder, Project-2 to get file to try to
        // confuse any caches in workspace root (location -> IResource).
        project.createFolder("Project-2/please");
        IFile ignoreme = nested.createFile("please/ignoreme", new byte[0]);
        IgnoreOperation operation = executeIgnore(ignoreme.getLocation());
        String content = nested.getFileContent("please/.gitignore");
        assertEquals("/ignoreme\n", content);
        assertFalse(operation.isGitignoreOutsideWSChanged());
    } finally {
        nested.dispose();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) TestProject(org.eclipse.egit.core.test.TestProject) IgnoreOperation(org.eclipse.egit.core.op.IgnoreOperation) Test(org.junit.Test)

Example 8 with IgnoreOperation

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

the class IgnoreOperationTest method executeIgnore.

private IgnoreOperation executeIgnore(IPath... paths) throws Exception {
    final IgnoreOperation operation = new IgnoreOperation(Arrays.asList(paths));
    Job job = new Job("Ignoring resources for test") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                operation.execute(monitor);
            } catch (CoreException e) {
                return e.getStatus();
            }
            return Status.OK_STATUS;
        }
    };
    job.setRule(operation.getSchedulingRule());
    job.schedule();
    job.join();
    if (!job.getResult().isOK())
        fail("Ignore job failed: " + job.getResult());
    return operation;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IgnoreOperation(org.eclipse.egit.core.op.IgnoreOperation) Job(org.eclipse.core.runtime.jobs.Job)

Example 9 with IgnoreOperation

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

the class IgnoreOperationTest method testSchedulingRule.

@Test
public void testSchedulingRule() throws Exception {
    IFolder binFolder = project.getProject().getFolder("bin");
    IgnoreOperation operation = executeIgnore(binFolder.getLocation());
    assertNotNull(operation.getSchedulingRule());
}
Also used : IgnoreOperation(org.eclipse.egit.core.op.IgnoreOperation) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 10 with IgnoreOperation

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

the class IgnoreOperationUI method run.

/**
 * Run the operation.
 */
public void run() {
    if (paths.size() > WARNING_THRESHOLD) {
        Shell shell = PlatformUI.getWorkbench().getModalDialogShellProvider().getShell();
        if (!MessageDialog.openQuestion(shell, MessageFormat.format(UIText.IgnoreActionHandler_manyFilesToBeIgnoredTitle, Integer.toString(paths.size())), UIText.IgnoreActionHandler_manyFilesToBeIgnoredQuestion)) {
            return;
        }
    }
    final IgnoreOperation operation = new IgnoreOperation(paths);
    String jobname = UIText.IgnoreActionHandler_addToGitignore;
    Job job = new WorkspaceJob(jobname) {

        @Override
        public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
            try {
                try {
                    operation.execute(monitor);
                } catch (CoreException e) {
                    return Activator.createErrorStatus(e.getStatus().getMessage(), e);
                }
                if (operation.isGitignoreOutsideWSChanged()) {
                    refresh();
                }
                if (monitor.isCanceled()) {
                    throw new OperationCanceledException();
                }
                return Status.OK_STATUS;
            } finally {
                monitor.done();
            }
        }
    };
    job.setUser(true);
    job.setRule(operation.getSchedulingRule());
    job.schedule();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IgnoreOperation(org.eclipse.egit.core.op.IgnoreOperation) Job(org.eclipse.core.runtime.jobs.Job) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob)

Aggregations

IgnoreOperation (org.eclipse.egit.core.op.IgnoreOperation)10 Test (org.junit.Test)8 IFolder (org.eclipse.core.resources.IFolder)5 IFile (org.eclipse.core.resources.IFile)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 CoreException (org.eclipse.core.runtime.CoreException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Job (org.eclipse.core.runtime.jobs.Job)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1 IPath (org.eclipse.core.runtime.IPath)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 TestProject (org.eclipse.egit.core.test.TestProject)1 Shell (org.eclipse.swt.widgets.Shell)1