1 11 package org.eclipse.jdt.internal.debug.ui.launcher; 12 13 14 import java.lang.reflect.InvocationTargetException ; 15 16 import org.eclipse.core.resources.IMarker; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IPath; 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.jdt.core.IClasspathEntry; 23 import org.eclipse.jdt.core.IJavaProject; 24 import org.eclipse.jdt.core.JavaCore; 25 import org.eclipse.jdt.debug.ui.IJavaDebugUIConstants; 26 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 27 import org.eclipse.jdt.launching.JavaRuntime; 28 import org.eclipse.jdt.ui.wizards.BuildPathDialogAccess; 29 import org.eclipse.jface.operation.IRunnableWithProgress; 30 import org.eclipse.ui.PlatformUI; 31 32 import com.ibm.icu.text.MessageFormat; 33 34 37 public class SelectSystemLibraryQuickFix extends JREResolution { 38 39 private IPath fOldPath; 40 private IJavaProject fProject; 41 42 public SelectSystemLibraryQuickFix(IPath oldPath, IJavaProject project) { 43 fOldPath = oldPath; 44 fProject = project; 45 } 46 47 50 public void run(IMarker marker) { 51 try { 52 handleContainerResolutionError(fOldPath, fProject); 53 } catch (CoreException e) { 54 JDIDebugUIPlugin.statusDialog(LauncherMessages.JREContainerResolution_Unable_to_update_classpath_1, e.getStatus()); 55 } 56 } 57 58 protected void handleContainerResolutionError(final IPath oldPath, final IJavaProject project) throws CoreException { 59 60 String lib = oldPath.segment(0); 61 IPath initialPath = null; 62 if (JavaRuntime.JRELIB_VARIABLE.equals(lib)) { 63 initialPath = JavaRuntime.newDefaultJREContainerPath(); 64 } else if (JavaRuntime.JRE_CONTAINER.equals(lib)) { 65 initialPath = oldPath; 66 } 67 IClasspathEntry initialEntry = JavaCore.newContainerEntry(initialPath); 68 final IClasspathEntry containerEntry = BuildPathDialogAccess.configureContainerEntry(JDIDebugUIPlugin.getActiveWorkbenchShell(), initialEntry, project, new IClasspathEntry[]{}); 69 if (containerEntry == null || containerEntry.getPath().equals(oldPath)) { 70 return; 71 } 72 73 IRunnableWithProgress runnable = new IRunnableWithProgress() { 74 public void run(IProgressMonitor monitor) throws InvocationTargetException { 75 try { 76 IPath newPath = containerEntry.getPath(); 77 IClasspathEntry[] classpath = project.getRawClasspath(); 78 for (int i = 0; i < classpath.length; i++) { 79 if (classpath[i].getPath().equals(oldPath)) { 80 classpath[i] = JavaCore.newContainerEntry(newPath, classpath[i].isExported()); 81 break; 82 } 83 } 84 project.setRawClasspath(classpath, monitor); 85 } catch (CoreException e) { 87 throw new InvocationTargetException (e); 88 } 89 } 90 }; 91 92 try { 93 PlatformUI.getWorkbench().getProgressService().busyCursorWhile(runnable); 94 } catch (InvocationTargetException e) { 95 if (e.getTargetException() instanceof CoreException) { 96 throw (CoreException)e.getTargetException(); 97 } 98 throw new CoreException(new Status(IStatus.ERROR, 99 JDIDebugUIPlugin.getUniqueIdentifier(), 100 IJavaDebugUIConstants.INTERNAL_ERROR, 101 LauncherMessages.JREContainerResolution_An_exception_occurred_while_updating_the_classpath__1, e.getTargetException())); 102 } catch (InterruptedException e) { 103 } 105 } 106 109 public String getLabel() { 110 return MessageFormat.format(LauncherMessages.JREContainerResolution_Select_a_system_library_to_use_when_building__0__2, new String []{fProject.getElementName()}); 111 } 112 113 } 114 | Popular Tags |