KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > terracotta > dso > BootJarHelper


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

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 JavaDoc;
24
25 public class BootJarHelper implements IJavaLaunchConfigurationConstants {
26   private static BootJarHelper m_helper;
27   
28   private static final String JavaDoc LAUNCH_LABEL =
29     "DSO BootJar Namer";
30
31   private static final String JavaDoc CLASSPATH_PROVIDER =
32     "org.terracotta.dso.classpathProvider";
33   
34   private static final String JavaDoc 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   /**
49    * Retrieve the name of the default bootjar.
50    */

51   public String JavaDoc getBootJarName() throws CoreException {
52     return getBootJarName(null);
53   }
54   
55   /**
56    * Retrieve the name of the default bootjar.
57    */

58   public String JavaDoc getBootJarName(String JavaDoc 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 JavaDoc 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 JavaDoc e) {/**/}
94     }
95     
96     return outMonitor.getContents().trim();
97   }
98   
99   /**
100    * Retrieve the bootjar path.
101    */

102   public IPath getBootJarPath() throws CoreException {
103     return getBootJarPath(getBootJarName());
104   }
105   
106   /**
107    * Retrieve the bootjar path for the current VM.
108    */

109   public IPath getBootJarPathForThisVM() throws UnsupportedVMException {
110     return getBootJarPath(BootJarSignature.getBootJarNameForThisVM());
111   }
112
113   /**
114    * Retrieve the bootjar path given the bootjar name.
115    */

116   public IPath getBootJarPath(String JavaDoc 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 JavaDoc getBootJarFileForThisVM() throws UnsupportedVMException {
124     return getBootJarPathForThisVM().toFile();
125   }
126   
127   /**
128    * Retrieve the bootjar file.
129    */

130   public File JavaDoc getBootJarFile() throws CoreException {
131     return getBootJarPath().toFile();
132   }
133 }
134
Popular Tags