1 11 package org.eclipse.jdt.internal.debug.ui.jres; 12 13 import java.io.IOException ; 14 import java.lang.reflect.InvocationTargetException ; 15 16 import javax.xml.parsers.ParserConfigurationException ; 17 import javax.xml.transform.TransformerException ; 18 19 import org.eclipse.core.runtime.IProgressMonitor; 20 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 21 import org.eclipse.jdt.internal.launching.VMDefinitionsContainer; 22 import org.eclipse.jdt.launching.IVMInstall; 23 import org.eclipse.jdt.launching.IVMInstallType; 24 import org.eclipse.jdt.launching.JavaRuntime; 25 import org.eclipse.jface.operation.IRunnableWithProgress; 26 27 30 public class JREsUpdater { 31 32 private VMDefinitionsContainer fOriginalVMs; 34 35 38 public JREsUpdater() { 39 fOriginalVMs = new VMDefinitionsContainer(); 40 IVMInstall def = JavaRuntime.getDefaultVMInstall(); 41 if (def != null) { 42 fOriginalVMs.setDefaultVMInstallCompositeID(JavaRuntime.getCompositeIdFromVM(def)); 43 } 44 45 IVMInstallType[] types = JavaRuntime.getVMInstallTypes(); 46 for (int i = 0; i < types.length; i++) { 47 IVMInstall[] vms = types[i].getVMInstalls(); 48 for (int j = 0; j < vms.length; j++) { 49 fOriginalVMs.addVM(vms[j]); 50 } 51 } 52 } 53 54 61 public boolean updateJRESettings(IVMInstall[] jres, IVMInstall defaultJRE) { 62 63 VMDefinitionsContainer vmContainer = new VMDefinitionsContainer(); 65 66 String defaultVMId = JavaRuntime.getCompositeIdFromVM(defaultJRE); 68 vmContainer.setDefaultVMInstallCompositeID(defaultVMId); 69 70 for (int i = 0; i < jres.length; i++) { 72 vmContainer.addVM(jres[i]); 73 } 74 75 76 saveVMDefinitions(vmContainer); 78 79 return true; 80 } 81 82 private void saveVMDefinitions(final VMDefinitionsContainer container) { 83 IRunnableWithProgress runnable = new IRunnableWithProgress() { 84 public void run(IProgressMonitor monitor) throws InvocationTargetException , InterruptedException { 85 try { 86 monitor.beginTask(JREMessages.JREsUpdater_0, 100); 87 String vmDefXML = container.getAsXML(); 88 monitor.worked(40); 89 JavaRuntime.getPreferences().setValue(JavaRuntime.PREF_VM_XML, vmDefXML); 90 monitor.worked(30); 91 JavaRuntime.savePreferences(); 92 monitor.worked(30); 93 } catch (IOException ioe) { 94 JDIDebugUIPlugin.log(ioe); 95 } catch (ParserConfigurationException e) { 96 JDIDebugUIPlugin.log(e); 97 } catch (TransformerException e) { 98 JDIDebugUIPlugin.log(e); 99 } finally { 100 monitor.done(); 101 } 102 103 } 104 }; 105 try { 106 JDIDebugUIPlugin.getDefault().getWorkbench().getProgressService().busyCursorWhile(runnable); 107 } catch (InvocationTargetException e) { 108 JDIDebugUIPlugin.log(e); 109 } catch (InterruptedException e) { 110 JDIDebugUIPlugin.log(e); 111 } 112 } 113 } 114 | Popular Tags |