Search in sources :

Example 11 with WorkspaceJob

use of org.eclipse.core.resources.WorkspaceJob in project bndtools by bndtools.

the class CnfWatcher method processEvent.

private void processEvent(IResourceChangeEvent event) {
    try {
        final Workspace workspace = Central.getWorkspaceIfPresent();
        if (workspace == null) {
            // this can happen during first project creation in an empty workspace
            logger.logInfo("Unable to get workspace", null);
            return;
        }
        final IProject cnfProject = WorkspaceUtils.findCnfProject(ResourcesPlugin.getWorkspace().getRoot(), workspace);
        if (cnfProject == null)
            return;
        IResourceDelta delta = event.getDelta();
        if (delta.findMember(cnfProject.getFullPath()) == null)
            return;
        Collection<Project> allProjects = workspace.getAllProjects();
        if (allProjects.isEmpty())
            return;
        Project p = allProjects.iterator().next();
        DeltaWrapper dw = new DeltaWrapper(p, delta, new BuildLogger(0));
        if (dw.hasCnfChanged()) {
            workspace.clear();
            workspace.forceRefresh();
            workspace.getPlugins();
            BndtoolsBuilder.dirty.addAll(allProjects);
            WorkspaceJob j = new WorkspaceJob("Update errors on workspace") {

                @Override
                public IStatus runInWorkspace(IProgressMonitor arg0) throws CoreException {
                    try {
                        MarkerSupport ms = new MarkerSupport(cnfProject);
                        ms.deleteMarkers("*");
                        ms.setMarkers(workspace, BndtoolsConstants.MARKER_BND_WORKSPACE_PROBLEM);
                        return Status.OK_STATUS;
                    } catch (Exception e) {
                        return new Status(IStatus.ERROR, BndtoolsBuilder.PLUGIN_ID, "updating errors for workspace", e);
                    }
                }
            };
            j.schedule();
        }
    } catch (Exception e) {
        logger.logError("Detecting changes in cnf failed, ignoring", e);
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) Project(aQute.bnd.build.Project) IProject(org.eclipse.core.resources.IProject) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) Workspace(aQute.bnd.build.Workspace) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 12 with WorkspaceJob

use of org.eclipse.core.resources.WorkspaceJob in project bndtools by bndtools.

the class BndConfigurator method getBuildParticipant.

@Override
public AbstractBuildParticipant getBuildParticipant(final IMavenProjectFacade projectFacade, MojoExecution execution, IPluginExecutionMetadata executionMetadata) {
    return new MojoExecutionBuildParticipant(execution, true, true) {

        @Override
        public Set<IProject> build(int kind, IProgressMonitor monitor) throws Exception {
            // build mojo like normal
            final Set<IProject> build = super.build(kind, monitor);
            // now we make sure jar is built in separate job, doing this during maven builder will throw lifecycle errors
            new WorkspaceJob("Executing " + projectFacade.getProject().getName() + " jar:jar goal") {

                @Override
                public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
                    execJarMojo(projectFacade, monitor);
                    projectFacade.getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);
                    return Status.OK_STATUS;
                }
            }.schedule();
            return build;
        }
    };
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IProject(org.eclipse.core.resources.IProject) MojoExecutionBuildParticipant(org.eclipse.m2e.core.project.configurator.MojoExecutionBuildParticipant)

Example 13 with WorkspaceJob

use of org.eclipse.core.resources.WorkspaceJob in project bndtools by bndtools.

the class AddFilesToRepositoryWizard method performFinish.

@Override
public boolean performFinish() {
    WorkspaceJob job = new WorkspaceJob("Adding files to repository") {

        @Override
        public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
            return performFinishAddFiles(monitor);
        }
    };
    job.schedule();
    return true;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob)

Aggregations

WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)13 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)13 CoreException (org.eclipse.core.runtime.CoreException)11 IStatus (org.eclipse.core.runtime.IStatus)7 Status (org.eclipse.core.runtime.Status)5 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)3 File (java.io.File)3 IOException (java.io.IOException)3 IFile (org.eclipse.core.resources.IFile)3 IProject (org.eclipse.core.resources.IProject)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 Workspace (aQute.bnd.build.Workspace)2 RemoteRepositoryPlugin (aQute.bnd.service.RemoteRepositoryPlugin)2 RepositoryBundle (bndtools.model.repo.RepositoryBundle)2 RepositoryBundleVersion (bndtools.model.repo.RepositoryBundleVersion)2 RepositoryEntry (bndtools.model.repo.RepositoryEntry)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2