1 11 package org.eclipse.pde.internal.ui.wizards.tools; 12 13 import org.eclipse.core.resources.IFile; 14 import org.eclipse.core.resources.IProject; 15 import org.eclipse.core.resources.IProjectDescription; 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.core.resources.IWorkspaceRunnable; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IProgressMonitor; 20 import org.eclipse.core.runtime.IStatus; 21 import org.eclipse.core.runtime.Status; 22 import org.eclipse.core.runtime.jobs.Job; 23 import org.eclipse.jdt.core.JavaCore; 24 import org.eclipse.pde.core.plugin.IPluginModelBase; 25 import org.eclipse.pde.internal.core.builders.PDEMarkerFactory; 26 import org.eclipse.pde.internal.ui.IPDEUIConstants; 27 import org.eclipse.pde.internal.ui.PDEPlugin; 28 import org.eclipse.pde.internal.ui.PDEUIMessages; 29 import org.eclipse.pde.internal.ui.wizards.plugin.ClasspathComputer; 30 31 public class UpdateClasspathJob extends Job { 32 IPluginModelBase[] fModels; 33 34 37 public UpdateClasspathJob(IPluginModelBase[] models) { 38 super(PDEUIMessages.UpdateClasspathJob_title); 39 setPriority(Job.LONG); 40 fModels = models; 41 } 42 45 public boolean doUpdateClasspath(IProgressMonitor monitor, 46 IPluginModelBase[] models) throws CoreException { 47 monitor.beginTask(PDEUIMessages.UpdateClasspathJob_task, 48 models.length); 49 try { 50 for (int i = 0; i < models.length; i++) { 51 IPluginModelBase model = models[i]; 52 monitor.subTask(models[i].getPluginBase().getId()); 53 IProject project = model.getUnderlyingResource().getProject(); 55 if (!project.hasNature(JavaCore.NATURE_ID)) { 56 monitor.worked(1); 57 continue; 58 } 59 IProjectDescription projDesc = project.getDescription(); 60 if (projDesc == null) continue; 61 projDesc.setReferencedProjects(new IProject[0]); 62 project.setDescription(projDesc, null); 63 IFile file = project.getFile(".project"); if (file.exists()) 65 file.deleteMarkers(PDEMarkerFactory.MARKER_ID, true, IResource.DEPTH_ZERO); 66 ClasspathComputer.setClasspath(project, model); 67 monitor.worked(1); 68 if (monitor.isCanceled()) 69 return false; 70 } 71 } finally { 72 monitor.done(); 73 } 74 return true; 75 } 76 77 class UpdateClasspathWorkspaceRunnable implements IWorkspaceRunnable { 78 boolean fCanceled = false; 79 public void run(IProgressMonitor monitor) 80 throws CoreException { 81 fCanceled = doUpdateClasspath(monitor, fModels); 82 } 83 public boolean isCanceled(){ 84 return fCanceled; 85 } 86 } 87 90 protected IStatus run(IProgressMonitor monitor) { 91 try { 92 UpdateClasspathWorkspaceRunnable runnable = new UpdateClasspathWorkspaceRunnable(); 93 PDEPlugin.getWorkspace().run(runnable, monitor); 94 if(runnable.isCanceled()){ 95 return new Status(IStatus.CANCEL, IPDEUIConstants.PLUGIN_ID, IStatus.CANCEL, "",null); } 97 98 } catch (CoreException e) { 99 String title = PDEUIMessages.UpdateClasspathJob_error_title; 100 String message = PDEUIMessages.UpdateClasspathJob_error_message; 101 PDEPlugin.logException(e, title, message); 102 return new Status(IStatus.ERROR, IPDEUIConstants.PLUGIN_ID, IStatus.OK, message, e); 103 } 104 return new Status(IStatus.OK, IPDEUIConstants.PLUGIN_ID, IStatus.OK, "",null); } 106 107 } 108 | Popular Tags |