1 4 package org.terracotta.dso; 5 6 import org.eclipse.core.runtime.CoreException; 7 import org.eclipse.core.runtime.IPath; 8 import org.eclipse.debug.core.DebugPlugin; 9 import org.eclipse.debug.core.ILaunchConfiguration; 10 import org.eclipse.debug.core.ILaunchConfigurationType; 11 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 12 import org.eclipse.debug.core.ILaunchManager; 13 import org.eclipse.debug.core.Launch; 14 import org.eclipse.debug.core.model.IProcess; 15 import org.eclipse.debug.core.model.IStreamMonitor; 16 import org.eclipse.debug.core.model.IStreamsProxy; 17 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; 18 import org.eclipse.jdt.launching.JavaLaunchDelegate; 19 20 import com.tc.object.tools.BootJarSignature; 21 import com.tc.object.tools.UnsupportedVMException; 22 23 import java.io.File ; 24 25 public class BootJarHelper implements IJavaLaunchConfigurationConstants { 26 private static BootJarHelper m_helper; 27 28 private static final String LAUNCH_LABEL = 29 "DSO BootJar Namer"; 30 31 private static final String CLASSPATH_PROVIDER = 32 "org.terracotta.dso.classpathProvider"; 33 34 private static final String BOOT_JAR_NAMER = 35 "com.tc.object.tools.BootJarSignature"; 36 37 public static synchronized BootJarHelper getHelper() { 38 if(m_helper == null) { 39 m_helper = new BootJarHelper(); 40 } 41 return m_helper; 42 } 43 44 private BootJarHelper() { 45 super(); 46 } 47 48 51 public String getBootJarName() throws CoreException { 52 return getBootJarName(null); 53 } 54 55 58 public String getBootJarName(String jreContainerPath) throws CoreException { 59 ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager(); 60 ILaunchConfigurationType type = manager.getLaunchConfigurationType(ID_JAVA_APPLICATION); 61 ILaunchConfiguration[] configs = manager.getLaunchConfigurations(type); 62 63 for(int i = 0; i < configs.length; i++) { 64 ILaunchConfiguration config = configs[i]; 65 66 if(config.getName().equals(LAUNCH_LABEL)) { 67 config.delete(); 68 break; 69 } 70 } 71 72 ILaunchConfigurationWorkingCopy wc = type.newInstance(null, LAUNCH_LABEL); 73 String runMode = ILaunchManager.RUN_MODE; 74 JavaLaunchDelegate delegate = new JavaLaunchDelegate(); 75 Launch launch = new Launch(wc, runMode, null); 76 77 wc.setAttribute(ATTR_CLASSPATH_PROVIDER, CLASSPATH_PROVIDER); 78 wc.setAttribute(ATTR_MAIN_TYPE_NAME, BOOT_JAR_NAMER); 79 80 if(jreContainerPath != null) { 81 wc.setAttribute(ATTR_JRE_CONTAINER_PATH, jreContainerPath); 82 } 83 84 delegate.launch(wc, runMode, launch, null); 85 86 IProcess process = launch.getProcesses()[0]; 87 IStreamsProxy streamsProxy = process.getStreamsProxy(); 88 IStreamMonitor outMonitor = streamsProxy.getOutputStreamMonitor(); 89 90 while(!process.isTerminated()) { 91 try { 92 Thread.sleep(100); 93 } catch(Exception e) {} 94 } 95 96 return outMonitor.getContents().trim(); 97 } 98 99 102 public IPath getBootJarPath() throws CoreException { 103 return getBootJarPath(getBootJarName()); 104 } 105 106 109 public IPath getBootJarPathForThisVM() throws UnsupportedVMException { 110 return getBootJarPath(BootJarSignature.getBootJarNameForThisVM()); 111 } 112 113 116 public IPath getBootJarPath(String bootJarName) { 117 IPath libDirPath = TcPlugin.getDefault().getLibDirPath(); 118 IPath bootJarPath = libDirPath.append("dso-boot").append(bootJarName); 119 120 return bootJarPath; 121 } 122 123 public File getBootJarFileForThisVM() throws UnsupportedVMException { 124 return getBootJarPathForThisVM().toFile(); 125 } 126 127 130 public File getBootJarFile() throws CoreException { 131 return getBootJarPath().toFile(); 132 } 133 } 134 | Popular Tags |