Search in sources :

Example 51 with Job

use of org.eclipse.core.runtime.jobs.Job in project xtext-xtend by eclipse.

the class OverrideIndicatorModelListener method asyncUpdateAnnotationModel.

private void asyncUpdateAnnotationModel() {
    if (currentJob != null) {
        currentJob.cancel();
    }
    currentJob = new Job(JOB_NAME) {

        @Override
        public IStatus run(IProgressMonitor monitor) {
            try {
                return updateAnnotationModel(monitor);
            } catch (OperationCanceledException e) {
                return Status.CANCEL_STATUS;
            } catch (Exception e) {
                LOG.error("Error updating override indicator", e);
                return Status.OK_STATUS;
            }
        }
    };
    currentJob.setRule(SCHEDULING_RULE);
    currentJob.setPriority(Job.DECORATE);
    currentJob.setSystem(true);
    currentJob.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) Job(org.eclipse.core.runtime.jobs.Job) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException)

Example 52 with Job

use of org.eclipse.core.runtime.jobs.Job in project xtext-xtend by eclipse.

the class ResourceStorageTest method doWorkInJob.

protected void doWorkInJob(final Procedure0 work) {
    try {
        final ArrayList<Throwable> throwables = CollectionLiterals.<Throwable>newArrayList();
        StringConcatenation _builder = new StringConcatenation();
        String _name = this.getClass().getName();
        _builder.append(_name);
        _builder.append(".TestJob");
        final Procedure1<Job> _function = (Job it) -> {
            it.setRule(SchedulingRuleFactory.INSTANCE.newSequence());
        };
        final Job testShouldLoadFromStorageJob = ObjectExtensions.<Job>operator_doubleArrow(new Job(_builder.toString()) {

            @Override
            protected IStatus run(final IProgressMonitor monitor) {
                IStatus _xblockexpression = null;
                {
                    try {
                        work.apply();
                    } catch (final Throwable _t) {
                        if (_t instanceof Throwable) {
                            final Throwable t = (Throwable) _t;
                            throwables.add(t);
                        } else {
                            throw Exceptions.sneakyThrow(_t);
                        }
                    }
                    _xblockexpression = Status.OK_STATUS;
                }
                return _xblockexpression;
            }
        }, _function);
        testShouldLoadFromStorageJob.schedule();
        testShouldLoadFromStorageJob.join();
        final Throwable t = IterableExtensions.<Throwable>head(throwables);
        if ((t != null)) {
            Throwables.propagate(t);
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Job(org.eclipse.core.runtime.jobs.Job)

Example 53 with Job

use of org.eclipse.core.runtime.jobs.Job in project linuxtools by eclipse.

the class BuildDockerImageLaunchConfigurationDelegate method launch.

@Override
public void launch(final ILaunchConfiguration configuration, final String mode, final ILaunch launch, final IProgressMonitor monitor) throws CoreException {
    final String sourcePathLocation = configuration.getAttribute(SOURCE_PATH_LOCATION, (String) null);
    final boolean sourcePathWorkspaceRelativeLocation = configuration.getAttribute(SOURCE_PATH_WORKSPACE_RELATIVE_LOCATION, false);
    final IPath sourcePath = BuildDockerImageUtils.getPath(sourcePathLocation, sourcePathWorkspaceRelativeLocation);
    final String connectionName = configuration.getAttribute(DOCKER_CONNECTION, (String) null);
    final String repoName = configuration.getAttribute(REPO_NAME, (String) null);
    final IDockerConnection connection = DockerConnectionManager.getInstance().getConnectionByName(connectionName);
    final Map<String, Object> buildOptions = new HashMap<>();
    buildOptions.put(QUIET_BUILD, configuration.getAttribute(QUIET_BUILD, false));
    buildOptions.put(NO_CACHE, configuration.getAttribute(NO_CACHE, false));
    buildOptions.put(RM_INTERMEDIATE_CONTAINERS, configuration.getAttribute(RM_INTERMEDIATE_CONTAINERS, true));
    buildOptions.put(FORCE_RM_INTERMEDIATE_CONTAINERS, configuration.getAttribute(FORCE_RM_INTERMEDIATE_CONTAINERS, false));
    if (connection != null && sourcePath != null) {
        final Job buildImageJob = new BuildDockerImageJob(connection, sourcePath, repoName, buildOptions);
        buildImageJob.schedule();
    } else {
        final ILaunchGroup launchGroup = DebugUITools.getLaunchGroup(configuration, // $NON-NLS-1$
        "run");
        // prompt the user with the launch configuration editor
        Display.getDefault().syncExec(() -> DebugUITools.openLaunchConfigurationDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), configuration, launchGroup.getIdentifier(), null));
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) BuildDockerImageJob(org.eclipse.linuxtools.internal.docker.ui.jobs.BuildDockerImageJob) ILaunchGroup(org.eclipse.debug.ui.ILaunchGroup) Job(org.eclipse.core.runtime.jobs.Job) BuildDockerImageJob(org.eclipse.linuxtools.internal.docker.ui.jobs.BuildDockerImageJob)

Example 54 with Job

use of org.eclipse.core.runtime.jobs.Job in project linuxtools by eclipse.

the class DockerComposeUpLaunchConfigurationDelegate method launch.

@Override
public void launch(final ILaunchConfiguration configuration, final String mode, final ILaunch launch, final IProgressMonitor monitor) throws CoreException {
    final String sourcePathLocation = configuration.getAttribute(WORKING_DIR, (String) null);
    final boolean sourcePathWorkspaceRelativeLocation = configuration.getAttribute(WORKING_DIR_WORKSPACE_RELATIVE_LOCATION, false);
    final IPath sourcePath = BuildDockerImageUtils.getPath(sourcePathLocation, sourcePathWorkspaceRelativeLocation);
    final String connectionName = configuration.getAttribute(DOCKER_CONNECTION, (String) null);
    final IDockerConnection connection = DockerConnectionManager.getInstance().getConnectionByName(connectionName);
    if (connection != null && sourcePath != null) {
        final Job dockerComposeUpJob = new DockerComposeUpJob(connection, sourcePath.toOSString(), configuration);
        dockerComposeUpJob.schedule();
    } else {
        final ILaunchGroup launchGroup = DebugUITools.getLaunchGroup(configuration, // $NON-NLS-1$
        "run");
        // prompt the user with the launch configuration editor
        Display.getDefault().syncExec(() -> DebugUITools.openLaunchConfigurationDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), configuration, launchGroup.getIdentifier(), null));
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) DockerComposeUpJob(org.eclipse.linuxtools.internal.docker.ui.jobs.DockerComposeUpJob) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) ILaunchGroup(org.eclipse.debug.ui.ILaunchGroup) Job(org.eclipse.core.runtime.jobs.Job) DockerComposeUpJob(org.eclipse.linuxtools.internal.docker.ui.jobs.DockerComposeUpJob)

Example 55 with Job

use of org.eclipse.core.runtime.jobs.Job in project linuxtools by eclipse.

the class AbstractTest method buildProject.

protected void buildProject(IProject proj) throws CoreException {
    IWorkspace wsp = ResourcesPlugin.getWorkspace();
    final IProject curProject = proj;
    ISchedulingRule rule = wsp.getRuleFactory().buildRule();
    Job buildJob = new // $NON-NLS-1$
    Job(// $NON-NLS-1$
    "project build job") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                curProject.build(IncrementalProjectBuilder.FULL_BUILD, null);
            } catch (CoreException e) {
                fail(e.getStatus().getMessage());
            } catch (OperationCanceledException e) {
                fail(NLS.bind(Messages.getString("AbstractTest.Build_cancelled"), curProject.getName(), // $NON-NLS-1$
                e.getMessage()));
            }
            return Status.OK_STATUS;
        }
    };
    buildJob.setRule(rule);
    buildJob.schedule();
    try {
        buildJob.join();
    } catch (InterruptedException e) {
        fail(NLS.bind(Messages.getString("AbstractTest.Build_interrupted"), curProject.getName(), // $NON-NLS-1$
        e.getMessage()));
    }
    IStatus status = buildJob.getResult();
    if (status.getCode() != IStatus.OK) {
        fail(NLS.bind(Messages.getString("AbstractTest.Build_failed"), curProject.getName(), // $NON-NLS-1$
        status.getMessage()));
    }
    IWorkspaceRunnable runnable = monitor -> curProject.refreshLocal(IResource.DEPTH_INFINITE, null);
    wsp.run(runnable, wsp.getRoot(), IWorkspace.AVOID_UPDATE, null);
}
Also used : DebugPlugin(org.eclipse.debug.core.DebugPlugin) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) LocalFile(org.eclipse.core.internal.filesystem.local.LocalFile) CoreException(org.eclipse.core.runtime.CoreException) CProjectHelper(org.eclipse.linuxtools.internal.profiling.tests.CProjectHelper) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IncrementalProjectBuilder(org.eclipse.core.resources.IncrementalProjectBuilder) ManagedCProjectNature(org.eclipse.cdt.managedbuilder.core.ManagedCProjectNature) IStatus(org.eclipse.core.runtime.IStatus) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IPath(org.eclipse.core.runtime.IPath) IOverwriteQuery(org.eclipse.ui.dialogs.IOverwriteQuery) Assert.fail(org.junit.Assert.fail) URI(java.net.URI) Bundle(org.osgi.framework.Bundle) EFS(org.eclipse.core.filesystem.EFS) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) ImportOperation(org.eclipse.ui.wizards.datatransfer.ImportOperation) NLS(org.eclipse.osgi.util.NLS) Status(org.eclipse.core.runtime.Status) IBinary(org.eclipse.cdt.core.model.IBinary) EFSExtensionManager(org.eclipse.cdt.utils.EFSExtensionManager) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunchManager(org.eclipse.debug.core.ILaunchManager) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkspaceDescription(org.eclipse.core.resources.IWorkspaceDescription) ScannerConfigNature(org.eclipse.cdt.build.core.scannerconfig.ScannerConfigNature) Path(org.eclipse.core.runtime.Path) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) FileSystemStructureProvider(org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CCorePlugin(org.eclipse.cdt.core.CCorePlugin) IProject(org.eclipse.core.resources.IProject) IWorkspace(org.eclipse.core.resources.IWorkspace) ICProject(org.eclipse.cdt.core.model.ICProject) IFileStore(org.eclipse.core.filesystem.IFileStore) Job(org.eclipse.core.runtime.jobs.Job) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) File(java.io.File) IDebugUIConstants(org.eclipse.debug.ui.IDebugUIConstants) FileLocator(org.eclipse.core.runtime.FileLocator) ICDTLaunchConfigurationConstants(org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants) IIndexManager(org.eclipse.cdt.core.index.IIndexManager) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IResource(org.eclipse.core.resources.IResource) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) Job(org.eclipse.core.runtime.jobs.Job) IProject(org.eclipse.core.resources.IProject) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Aggregations

Job (org.eclipse.core.runtime.jobs.Job)177 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)134 IStatus (org.eclipse.core.runtime.IStatus)33 IOException (java.io.IOException)27 File (java.io.File)20 Status (org.eclipse.core.runtime.Status)20 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)20 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)20 CoreException (org.eclipse.core.runtime.CoreException)17 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)17 JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)14 DockerException (org.eclipse.linuxtools.docker.core.DockerException)14 IFile (org.eclipse.core.resources.IFile)13 URL (java.net.URL)11 ArrayList (java.util.ArrayList)11 IPath (org.eclipse.core.runtime.IPath)10 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)9 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)9 DockerConnection (org.eclipse.linuxtools.internal.docker.core.DockerConnection)8 Display (org.eclipse.swt.widgets.Display)8