Search in sources :

Example 61 with Job

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

the class SpecfileEditorPrepareSourcesActionDelegate method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final Shell shell = HandlerUtil.getActiveShellChecked(event);
    final SpecfileParser specparser = new SpecfileParser();
    final IResource resource = RPMHandlerUtils.getResource(event);
    final RPMProject rpj = RPMHandlerUtils.getRPMProject(resource);
    final IFile workFile = (IFile) rpj.getSpecFile();
    final Specfile specfile = specparser.parse(workFile);
    if (!downloadFile(shell, rpj, specfile)) {
        return null;
    }
    Job job = new // $NON-NLS-1$
    Job(// $NON-NLS-1$
    "Preparing sources") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            monitor.beginTask(NLS.bind(Messages.PrepareSources_prepareSources, rpj.getSpecFile().getName()), IProgressMonitor.UNKNOWN);
            // $NON-NLS-1$
            int offset = rpj.getSpecFile().getName().lastIndexOf(".");
            MessageConsoleStream out = getConsole(rpj.getSpecFile().getName().substring(0, offset)).newMessageStream();
            IStatus is = null;
            try {
                is = rpj.buildPrep(out);
            } catch (CoreException e) {
                SpecfileLog.logError(Messages.PrepareSources_coreException, e);
                RPMUtils.showErrorDialog(shell, Messages.PrepareSources_error, Messages.PrepareSources_coreException);
                return is;
            } finally {
                monitor.done();
            }
            return is;
        }
    };
    // suppress UI. That's done in encapsulated
    job.setUser(true);
    job.schedule();
    return null;
}
Also used : Specfile(org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) RPMProject(org.eclipse.linuxtools.rpm.core.RPMProject) MessageConsoleStream(org.eclipse.ui.console.MessageConsoleStream) DownloadJob(org.eclipse.linuxtools.rpm.core.utils.DownloadJob) Job(org.eclipse.core.runtime.jobs.Job) SpecfileParser(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser) IResource(org.eclipse.core.resources.IResource)

Example 62 with Job

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

the class GcovTest method testGcovSummaryByLaunch.

@Test
public void testGcovSummaryByLaunch() {
    display.syncExec(() -> {
        try {
            CommonNavigator vc = (CommonNavigator) window.getActivePage().showView(ProjectExplorer.VIEW_ID);
            vc.selectReveal(new StructuredSelection(project.getFile(getBinName())));
            Menu menu = new MenuManager().createContextMenu(vc.getCommonViewer().getControl());
            new ProfileContextualLaunchAction(menu);
            for (MenuItem item : menu.getItems()) {
                if (item.getText().endsWith("Profile Code Coverage")) {
                    ((ActionContributionItem) item.getData()).getAction().run();
                    break;
                }
            }
        } catch (PartInitException e1) {
            Assert.fail("Cannot show Project Explorer.");
        }
        try {
            window.getActivePage().showView("org.eclipse.linuxtools.gcov.view");
        } catch (PartInitException e2) {
            Assert.fail("Cannot show GCov View.");
        }
    });
    // Wait for the build job to finish (note: DebugUIPlugin doesn't put launch jobs in a family)
    Job[] jobs = Job.getJobManager().find(null);
    for (Job job : jobs) {
        if (job.getName().contains("Gcov")) {
            try {
                job.join();
            } catch (InterruptedException e) {
            }
            break;
        }
    }
}
Also used : CommonNavigator(org.eclipse.ui.navigator.CommonNavigator) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) MenuManager(org.eclipse.jface.action.MenuManager) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) PartInitException(org.eclipse.ui.PartInitException) Job(org.eclipse.core.runtime.jobs.Job) Test(org.junit.Test) AbstractTest(org.eclipse.linuxtools.profiling.tests.AbstractTest)

Example 63 with Job

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

the class DownloadPrepareSourcesTest method downloadFile.

/**
 * Download and also test if the file was downloaded correctly
 *
 * @param project The RPM project
 * @throws IOException
 * @throws InterruptedException
 */
public void downloadFile(RPMProject project) throws IOException, InterruptedException {
    // connect to the URL
    URL url = new URL("http://ftp.gnu.org/gnu/hello/hello-2.8.tar.gz");
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    assertEquals(connection.getResponseCode(), HttpURLConnection.HTTP_OK);
    // download the file
    String filename = "hello-2.8.tar.gz";
    IFile file = project.getConfiguration().getSourcesFolder().getFile(new Path(filename));
    Job downloadJob = new DownloadJob(file, connection);
    downloadJob.setUser(true);
    downloadJob.schedule();
    downloadJob.join();
    assertEquals(downloadJob.getResult(), Status.OK_STATUS);
}
Also used : Path(org.eclipse.core.runtime.Path) HttpURLConnection(java.net.HttpURLConnection) IFile(org.eclipse.core.resources.IFile) DownloadJob(org.eclipse.linuxtools.rpm.core.utils.DownloadJob) Job(org.eclipse.core.runtime.jobs.Job) DownloadJob(org.eclipse.linuxtools.rpm.core.utils.DownloadJob) URL(java.net.URL)

Example 64 with Job

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

the class SpecfileEditorRPMBuildHandler method execute.

@Override
public Object execute(ExecutionEvent event) {
    final IResource resource = getResource(event);
    rpj = getRPMProject(resource);
    if (rpj != null) {
        Job job = new RPMExportOperation(rpj, event.getParameter(BUILD_TYPE));
        job.setUser(true);
        job.schedule();
    }
    return null;
}
Also used : RPMExportOperation(org.eclipse.linuxtools.rpm.ui.RPMExportOperation) Job(org.eclipse.core.runtime.jobs.Job) IResource(org.eclipse.core.resources.IResource)

Example 65 with Job

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

the class CreaterepoCommandHandler method execute.

@Override
public Object execute(ExecutionEvent event) {
    // $NON-NLS-1$
    final String executionType = event.getParameter("executionType");
    try {
        IWorkbench wb = PlatformUI.getWorkbench();
        IWorkbenchPage wbPage = wb.getActiveWorkbenchWindow().getActivePage();
        IEditorInput editorInput = wbPage.getActiveEditor().getEditorInput();
        IResource resource = ResourceUtil.getResource(editorInput);
        final CreaterepoProject project = new CreaterepoProject(resource.getProject());
        Job executeCreaterepo = new Job(Messages.Createrepo_jobName) {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                try {
                    monitor.beginTask(Messages.CreaterepoProject_executeCreaterepo, IProgressMonitor.UNKNOWN);
                    MessageConsoleStream os = CreaterepoUtils.findConsole(Messages.CreaterepoProject_consoleName).newMessageStream();
                    if (executionType.equals("refresh")) {
                        // $NON-NLS-1$
                        return project.update(os);
                    } else {
                        return project.createrepo(os);
                    }
                } catch (CoreException e) {
                    Activator.logError(Messages.Createrepo_errorExecuting, e);
                } finally {
                    monitor.done();
                }
                return null;
            }
        };
        executeCreaterepo.setUser(true);
        executeCreaterepo.schedule();
    } catch (CoreException e) {
        Activator.logError(Messages.CreaterepoProject_executeCreaterepo, e);
    }
    return null;
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) MessageConsoleStream(org.eclipse.ui.console.MessageConsoleStream) Job(org.eclipse.core.runtime.jobs.Job) CreaterepoProject(org.eclipse.linuxtools.internal.rpm.createrepo.CreaterepoProject) IEditorInput(org.eclipse.ui.IEditorInput) IResource(org.eclipse.core.resources.IResource)

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