Example usage for org.eclipse.jdt.core JavaCore run

List of usage examples for org.eclipse.jdt.core JavaCore run

Introduction

In this page you can find the example usage for org.eclipse.jdt.core JavaCore run.

Prototype

public static void run(IWorkspaceRunnable action, ISchedulingRule rule, IProgressMonitor monitor)
        throws CoreException 

Source Link

Document

Runs the given action as an atomic Java model operation.

Usage

From source file:com.google.gdt.eclipse.core.sdk.ClasspathContainerUpdateJob.java

License:Open Source License

@Override
protected IStatus run(IProgressMonitor jobMonitor) {
    try {//from w  w  w  . ja va  2 s  .  co  m
        IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
            public void run(IProgressMonitor runnableMonitor) throws CoreException {
                IJavaProject[] projects = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot())
                        .getJavaProjects();
                runnableMonitor.beginTask(LaunchingMessages.LaunchingPlugin_0, projects.length + 1);
                rebindContainers(runnableMonitor, projects);
                runnableMonitor.done();
            }

            /**
             * Rebind all of the classpath containers whose comparison ID matches
             * the expected ID.
             */
            private void rebindContainers(IProgressMonitor runnableMonitor, IJavaProject[] projects)
                    throws CoreException {
                for (IJavaProject project : projects) {
                    // Update the progress monitor
                    runnableMonitor.worked(1);
                    IClasspathEntry[] rawClasspathEntries = project.getRawClasspath();
                    for (IClasspathEntry rawClasspathEntry : rawClasspathEntries) {
                        if (rawClasspathEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER) {
                            continue;
                        }

                        IPath path = rawClasspathEntry.getPath();
                        if (path == null || path.segmentCount() == 0) {
                            continue;
                        }

                        Object actualComparisonId = classpathContainerInitializer.getComparisonID(path,
                                project);
                        if (!actualComparisonId.equals(expectedComparisonId)) {
                            continue;
                        }

                        classpathContainerInitializer.initialize(path, project);
                    }
                }
            }
        };
        JavaCore.run(runnable, null, jobMonitor);
        return Status.OK_STATUS;
    } catch (CoreException e) {
        return e.getStatus();
    }
}

From source file:com.windowtester.codegen.ui.WorkbenchRunnableAdapter.java

License:Open Source License

public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    try {//w w w. j  a v  a2s.  c o  m
        JavaCore.run(fWorkspaceRunnable, fRule, monitor);
    } catch (OperationCanceledException e) {
        throw new InterruptedException(e.getMessage());
    } catch (CoreException e) {
        throw new InvocationTargetException(e);
    }
}

From source file:net.rim.ejde.internal.imports.WorkspaceRunnableAdapter.java

License:Open Source License

public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    try {/*from w w  w .j  a  va  2s  .c om*/
        JavaCore.run(_runnable, _rule, monitor);
    } catch (OperationCanceledException e) {
        _log.error(e);
        throw new InterruptedException(e.getMessage());
    } catch (CoreException e) {
        _log.error(e);
        throw new InvocationTargetException(e);
    }
}

From source file:nz.ac.auckland.ptjava.internal.newprojectwizard.RunnableAdapter.java

License:Open Source License

/**
 * Runs the given IWorkspaceRunnable, using the given scheduling rule.
 * Note that the code is not run in the UI thread.
 * @param monitor The progress monitor to notify User of progress.
 *///from www  .j a  va2 s  .  c  o  m
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    try {
        JavaCore.run(fWorkspaceRunnable, fRule, monitor);
    } catch (OperationCanceledException e) {
        throw new InterruptedException(e.getMessage());
    } catch (CoreException e) {
        throw new InvocationTargetException(e);
    }
}

From source file:org.dyno.visual.swing.wizards.WorkbenchRunnableAdapter.java

License:Open Source License

public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    try {//from w  w  w  . j  av  a 2s . c  o  m
        JavaCore.run(fWorkspaceRunnable, fRule, monitor);
    } catch (OperationCanceledException e) {
        VisualSwingPlugin.getLogger().error(e);
        throw new InterruptedException(e.getMessage());
    } catch (CoreException e) {
        VisualSwingPlugin.getLogger().error(e);
        throw new InvocationTargetException(e);
    }
}

From source file:org.eclipse.jst.jsp.core.internal.validation.JSPBatchValidator.java

License:Open Source License

public IStatus validateInJob(final IValidationContext helper, final IReporter reporter)
        throws ValidationException {
    Job currentJob = Job.getJobManager().currentJob();
    ISchedulingRule rule = null;/*from  ww w.  j  a  v  a  2 s .c  om*/
    if (currentJob != null) {
        rule = currentJob.getRule();
    }
    IWorkspaceRunnable validationRunnable = new IWorkspaceRunnable() {
        public void run(IProgressMonitor monitor) throws CoreException {
            try {
                doValidate(helper, reporter);
            } catch (ValidationException e) {
                throw new CoreException(
                        new Status(IStatus.ERROR, PLUGIN_ID_JSP_CORE, 0, PLUGIN_ID_JSP_CORE, e));
            }
        }
    };
    try {
        JavaCore.run(validationRunnable, rule, new NullProgressMonitor());
    } catch (CoreException e) {
        if (e.getCause() instanceof ValidationException) {
            throw (ValidationException) e.getCause();
        }
        throw new ValidationException(new LocalizedMessage(IMessage.ERROR_AND_WARNING, e.getMessage()), e);
    }
    return Status.OK_STATUS;
}

From source file:org.eclipse.jst.jsp.core.internal.validation.JSPBatchValidator.java

License:Open Source License

public ValidationResult validate(final IResource resource, int kind, ValidationState state,
        IProgressMonitor monitor) {//from   w  w  w  . ja va2  s  .co m
    if (resource.getType() != IResource.FILE)
        return null;
    if (!shouldValidate((IFile) resource))
        return null;
    final ValidationResult result = new ValidationResult();
    final IReporter reporter = result.getReporter(monitor);

    if (result.getDependsOn() != null) {
        fDependsOn = new HashSet(Arrays.asList(result.getDependsOn()));
    } else {
        fDependsOn = new HashSet();
    }

    // add web.xml as a dependency
    addDependsOn(DeploymentDescriptorPropertyCache.getInstance().getWebXML(resource.getFullPath()));

    // List relevant JSP 2.0 preludes/codas as dependencies
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    PropertyGroup[] propertyGroups = DeploymentDescriptorPropertyCache.getInstance()
            .getPropertyGroups(resource.getFullPath());
    for (int j = 0; j < propertyGroups.length; j++) {
        IPath[] preludes = propertyGroups[j].getIncludePrelude();
        for (int i = 0; i < preludes.length; i++) {
            addDependsOn(workspaceRoot.getFile(preludes[i]));
        }
        IPath[] codas = propertyGroups[j].getIncludeCoda();
        for (int i = 0; i < codas.length; i++) {
            addDependsOn(workspaceRoot.getFile(codas[i]));
        }
    }

    IWorkspaceRunnable validationRunnable = new IWorkspaceRunnable() {
        public void run(IProgressMonitor monitor) throws CoreException {
            if (fragmentCheck((IFile) resource)) {
                validateFile((IFile) resource, reporter);
            }
            IResource[] resources = (IResource[]) fDependsOn.toArray(new IResource[fDependsOn.size()]);
            result.setDependsOn(resources);
            fDependsOn.clear();
        }
    };
    Job currentJob = Job.getJobManager().currentJob();
    ISchedulingRule rule = null;
    if (currentJob != null) {
        rule = currentJob.getRule();
    }
    try {
        JavaCore.run(validationRunnable, rule, new NullProgressMonitor());
    } catch (CoreException e) {
        Logger.logException(e);
    }
    return result;
}

From source file:org.eclipse.wst.xml.search.editor.validation.XMLReferencesBatchValidator.java

License:Open Source License

public IStatus validateInJob(final IValidationContext helper, final IReporter reporter)
        throws ValidationException {
    Job currentJob = Job.getJobManager().currentJob();
    ISchedulingRule rule = null;//from   w  ww.j a  v  a2  s  .c  o  m
    if (currentJob != null) {
        rule = currentJob.getRule();
    }
    IWorkspaceRunnable validationRunnable = new IWorkspaceRunnable() {
        public void run(IProgressMonitor monitor) throws CoreException {
            try {
                doValidate(helper, reporter);
            } catch (ValidationException e) {
                throw new CoreException(new Status(IStatus.ERROR, XMLSearchEditorPlugin.PLUGIN_ID, 0,
                        XMLSearchEditorPlugin.PLUGIN_ID, e));
            }
        }
    };
    try {
        JavaCore.run(validationRunnable, rule, new NullProgressMonitor());
    } catch (CoreException e) {
        if (e.getCause() instanceof ValidationException) {
            throw (ValidationException) e.getCause();
        }
        throw new ValidationException(new LocalizedMessage(IMessage.ERROR_AND_WARNING, e.getMessage()), e);
    }
    return Status.OK_STATUS;
}

From source file:org.eclipse.wst.xml.search.editor.validation.XMLReferencesBatchValidator.java

License:Open Source License

@Override
public ValidationResult validate(final IResource resource, int kind, ValidationState state,
        IProgressMonitor monitor) {/*from  w w w.j av  a2 s  .c  om*/
    if (resource.getType() != IResource.FILE)
        return null;
    final ValidationResult result = new ValidationResult();
    final IReporter reporter = result.getReporter(monitor);
    fDependsOn = new HashSet<IResource>();

    IWorkspaceRunnable validationRunnable = new IWorkspaceRunnable() {
        public void run(IProgressMonitor monitor) throws CoreException {
            validateFile((IFile) resource, reporter);
            result.setDependsOn((IResource[]) fDependsOn.toArray(new IResource[fDependsOn.size()]));
            fDependsOn.clear();
        }
    };
    Job currentJob = Job.getJobManager().currentJob();
    ISchedulingRule rule = null;
    if (currentJob != null) {
        rule = currentJob.getRule();
    }
    try {
        JavaCore.run(validationRunnable, rule, new NullProgressMonitor());
    } catch (CoreException e) {
        Trace.trace(Trace.SEVERE, "", e);
    }
    return result;
}