1 4 package org.terracotta.dso.launch; 5 6 import org.eclipse.core.resources.IFile; 7 import org.eclipse.core.resources.IProject; 8 import org.eclipse.core.runtime.CoreException; 9 import org.eclipse.core.runtime.IPath; 10 import org.eclipse.core.runtime.IProgressMonitor; 11 import org.eclipse.core.runtime.IStatus; 12 import org.eclipse.core.runtime.Status; 13 import org.eclipse.debug.core.ILaunch; 14 import org.eclipse.debug.core.ILaunchConfiguration; 15 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 16 import org.eclipse.jdt.core.IJavaProject; 17 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; 18 import org.eclipse.jdt.launching.IVMInstall; 19 import org.eclipse.jdt.launching.JavaLaunchDelegate; 20 import org.eclipse.jdt.launching.JavaRuntime; 21 import org.eclipse.swt.widgets.Display; 22 import org.eclipse.ui.IWorkbench; 23 import org.eclipse.ui.PlatformUI; 24 import org.terracotta.dso.BootJarHelper; 25 import org.terracotta.dso.ClasspathProvider; 26 import org.terracotta.dso.ConfigurationHelper; 27 import org.terracotta.dso.ServerTracker; 28 import org.terracotta.dso.TcPlugin; 29 import org.terracotta.dso.actions.BuildBootJarAction; 30 31 34 35 public class ConfigurationDelegate extends JavaLaunchDelegate 36 implements IJavaLaunchConfigurationConstants 37 { 38 public void launch( 39 ILaunchConfiguration config, 40 String mode, 41 ILaunch launch, 42 IProgressMonitor monitor) throws CoreException 43 { 44 try { 45 Display.getDefault().syncExec(new Runnable () { 46 public void run() { 47 IWorkbench workbench = PlatformUI.getWorkbench(); 48 if(workbench != null) { 49 workbench.saveAllEditors(false); 50 } 51 } 52 }); 53 54 ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy(); 55 final IJavaProject javaProject = getJavaProject(wc); 56 final IProject project = javaProject.getProject(); 57 58 final TcPlugin plugin = TcPlugin.getDefault(); 59 String vmArgs = wc.getAttribute(ATTR_VM_ARGUMENTS, ""); 60 IPath libDirPath = plugin.getLibDirPath(); 61 IFile configFile = plugin.getConfigurationFile(project); 62 63 if(!plugin.continueWithConfigProblems(project)) { 64 return; 65 } 66 67 final ServerTracker tracker = ServerTracker.getDefault(); 68 if(!tracker.anyRunning(javaProject)) { 69 tracker.startServer(javaProject, plugin.getAnyServerName(project)); 70 } 71 72 IPath configPath = configFile.getLocation(); 73 String configProp = " -Dtc.config=\"" + toOSString(configPath) + "\""; 74 75 String portablePath = null; 76 IPath jrePath = JavaRuntime.computeJREEntry(javaProject).getPath(); 77 if(jrePath != null) { 78 portablePath = jrePath.makeAbsolute().toPortableString(); 79 } 80 81 String jreContainerPath = wc.getAttribute(ATTR_JRE_CONTAINER_PATH, portablePath); 82 String bootJarName = BootJarHelper.getHelper().getBootJarName(jreContainerPath); 83 84 if(bootJarName == null || bootJarName.length() == 0) { 85 IVMInstall vmInstall = getVMInstall(wc); 86 String vmName; 87 88 if(vmInstall != null) { 89 vmName = vmInstall.getName(); 90 } else { 91 vmName = jreContainerPath.substring(jreContainerPath.lastIndexOf('/')+1); 92 } 93 94 throw new RuntimeException ("Can't determine BootJar name for runtime '"+vmName+"'"); 95 } 96 97 IFile localBootJar = project.getFile(bootJarName); 98 IPath bootPath; 99 100 testEnsureBootJar(plugin, javaProject, localBootJar, jreContainerPath); 101 102 if(localBootJar.exists()) { 103 bootPath = localBootJar.getLocation(); 104 } 105 else { 106 bootPath = BootJarHelper.getHelper().getBootJarPath(bootJarName); 107 } 108 109 String bootProp = " -Xbootclasspath/p:\"" + toOSString(bootPath) + "\""; 110 111 if(!configPath.toFile().exists()) { 112 String path = configPath.toOSString(); 113 plugin.openError("Project config file '" + path + 114 "' not found", 115 new RuntimeException ("tc.config not found: " + path)); 116 } 117 118 if(!bootPath.toFile().exists()) { 119 String path = bootPath.toOSString(); 120 plugin.openError("System bootjar '" + path + 121 "' not found", 122 new RuntimeException ("bootjar not found: " + path)); 123 } 124 125 String cpProp; 126 if(libDirPath.append("tc.jar").toFile().exists()) { 127 cpProp = " -Dtc.install-root=\"" + toOSString(plugin.getLocation()) + "\""; 128 } 129 else { 130 cpProp = " -Dtc.classpath=\"" + ClasspathProvider.makeDevClasspath() + "\""; 131 } 132 133 wc.setAttribute(ATTR_VM_ARGUMENTS, 134 cpProp + configProp + bootProp + " " + vmArgs); 135 136 super.launch(wc, mode, launch, monitor); 137 } catch(Throwable t) { 138 String msg = "Unable to launch '"+config.getName()+"'\n\n"+t.getLocalizedMessage(); 139 Status status = new Status(IStatus.ERROR, TcPlugin.getPluginId(), 1, msg, t); 140 throw new CoreException(status); 141 } 142 } 143 144 private static String toOSString(IPath path) { 145 return path.makeAbsolute().toOSString(); 146 } 147 148 private void testEnsureBootJar( 149 final TcPlugin plugin, 150 final IJavaProject javaProject, 151 final IFile bootJar, 152 final String jreContainerPath) 153 { 154 IProject project = javaProject.getProject(); 155 ConfigurationHelper configHelper = plugin.getConfigurationHelper(project); 156 IFile configFile = plugin.getConfigurationFile(project); 157 boolean stdBootJarExists = false; 158 boolean configHasBootJarClasses = configHelper.hasBootJarClasses(); 159 160 try { 161 stdBootJarExists = BootJarHelper.getHelper().getBootJarFile().exists(); 162 } catch(CoreException ce) {} 163 164 if(!stdBootJarExists || (configFile != null && configHasBootJarClasses)) { 165 long bootStamp = bootJar.getLocalTimeStamp(); 166 long confStamp = configFile.getLocalTimeStamp(); 167 168 if(!bootJar.exists() || (configHasBootJarClasses && bootStamp < confStamp)) { 169 Display.getDefault().syncExec(new Runnable () { 170 public void run() { 171 BuildBootJarAction bbja = new BuildBootJarAction(javaProject); 172 bbja.setJREContainerPath(jreContainerPath); 173 bbja.run(null); 174 } 175 }); 176 } 177 } 178 } 179 } 180 | Popular Tags |