1 11 package org.eclipse.jdt.internal.ui.macbundler; 12 13 import java.io.*; 14 import java.io.File ; 15 import java.util.*; 16 import java.util.Properties ; 17 18 import org.eclipse.core.runtime.CoreException; 19 20 import org.eclipse.jface.util.*; 21 import org.eclipse.jface.util.ListenerList; 22 23 import org.eclipse.debug.core.*; 24 import org.eclipse.jdt.core.IJavaProject; 25 import org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate; 26 27 28 class BundleDescription implements BundleAttributes { 29 30 private static final String STUB= "/System/Library/Frameworks/JavaVM.framework/Versions/A/Resources/MacOS/JavaApplicationStub"; private static final String ICON= "/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Resources/GenericApp.icns"; 33 private ListenerList fListeners= new ListenerList(); 34 private Properties fProperties= new Properties (); 35 private List fClassPath= new ArrayList(); 36 private List fResources= new ArrayList(); 37 Properties fProperties2= new Properties (); 38 39 40 BundleDescription() { 41 clear(); 42 } 43 44 void clear() { 45 fProperties.clear(); 46 fClassPath.clear(); 47 fResources.clear(); 48 fProperties2.clear(); 49 fProperties.put(SIGNATURE, "????"); fProperties.put(ICONFILE, ICON); 51 } 52 53 void addResource(ResourceInfo ri, boolean onClasspath) { 54 if (onClasspath) 55 fClassPath.add(ri); 56 else 57 fResources.add(ri); 58 } 59 60 boolean removeResource(ResourceInfo ri, boolean onClasspath) { 61 if (onClasspath) 62 return fClassPath.remove(ri); 63 return fResources.remove(ri); 64 } 65 66 ResourceInfo[] getResources(boolean onClasspath) { 67 if (onClasspath) 68 return (ResourceInfo[]) fClassPath.toArray(new ResourceInfo[fClassPath.size()]); 69 return (ResourceInfo[]) fResources.toArray(new ResourceInfo[fResources.size()]); 70 } 71 72 void addListener(IPropertyChangeListener listener) { 73 fListeners.add(listener); 74 } 75 76 void removeListener(IPropertyChangeListener listener) { 77 fListeners.remove(listener); 78 } 79 80 String get(String key) { 81 return fProperties.getProperty(key); 82 } 83 84 public String get(String key, String dflt) { 85 return fProperties.getProperty(key, dflt); 86 } 87 88 public boolean get(String key, boolean dflt) { 89 Boolean v= (Boolean ) fProperties.get(key); 90 if (v == null) 91 return dflt; 92 return v.booleanValue(); 93 } 94 95 void setValue(String key, Object value) { 96 fProperties.put(key, value); 97 } 98 99 void inititialize(ILaunchConfiguration lc) { 100 AbstractJavaLaunchConfigurationDelegate lcd; 101 try { 102 lcd= (AbstractJavaLaunchConfigurationDelegate) lc.getType().getDelegate(ILaunchManager.RUN_MODE); 103 } catch (CoreException e) { 104 return; 105 } 106 107 String appName= lc.getName(); 108 fProperties.put(APPNAME, appName); 109 fProperties.put(GETINFO, appName + Util.getString("BundleDescription.copyright.format")); 111 try { 112 fProperties.put(MAINCLASS, lcd.getMainTypeName(lc)); 113 } catch (CoreException e) { 114 fProperties.put(MAINCLASS, ""); } 116 try { 117 fProperties.put(ARGUMENTS, lcd.getProgramArguments(lc)); 118 } catch (CoreException e) { 119 fProperties.put(ARGUMENTS, ""); } 121 String wd= null; 122 try { 123 wd= lcd.getWorkingDirectory(lc).getAbsolutePath(); 124 } catch (CoreException e) { 126 } 128 try { 129 fProperties.put(MAINCLASS, lcd.getMainTypeName(lc)); 130 } catch (CoreException e) { 131 fProperties.put(MAINCLASS, ""); } 133 134 try { 135 String [] classpath= lcd.getClasspath(lc); 136 for (int i= 0; i < classpath.length; i++) 137 addResource(new ResourceInfo(classpath[i]), true); } catch (CoreException e) { 139 } 141 142 String vmOptions2= ""; String vmOptions= null; 144 try { 145 vmOptions= lcd.getVMArguments(lc); 146 } catch (CoreException e) { 147 } 149 if (vmOptions != null) { 150 StringTokenizer st= new StringTokenizer(vmOptions); 151 while (st.hasMoreTokens()) { 152 String token= st.nextToken(); 153 int pos= token.indexOf('='); 154 if (pos > 2 && token.startsWith("-D")) { String key= token.substring(2, pos).trim(); 156 String value= token.substring(pos+1).trim(); 157 int l= value.length(); 158 if (l >= 2 && value.charAt(0) == '"' && value.charAt(l-1) == '"') 159 value= value.substring(1, l-1); 160 if ("java.library.path".equals(key)) { addDllDir(wd, value); 162 } else { 163 fProperties2.put(key, value); 164 } 165 } else { 166 vmOptions2= vmOptions2 + token + ' '; 167 } 168 } 169 } 170 171 fProperties.put(VMOPTIONS, vmOptions2); 172 173 boolean isSWT= false; 174 Iterator iter= fResources.iterator(); 175 while (iter.hasNext()) { 176 ResourceInfo ri= (ResourceInfo) iter.next(); 177 if (ri.fPath.indexOf("libswt-carbon") >= 0) { isSWT= true; 179 break; 180 } 181 } 182 fProperties.put(USES_SWT, Boolean.valueOf(isSWT)); 183 184 String launcher= null; 185 if (isSWT) 186 launcher= System.getProperty("org.eclipse.swtlauncher"); 188 if (launcher == null) { 189 setValue(JVMVERSION, "1.4*"); launcher= STUB; } 192 setValue(LAUNCHER, launcher); 193 194 195 IJavaProject p= null; 196 try { 197 p= lcd.getJavaProject(lc); 198 } catch (CoreException e) { 199 } 201 if (p != null) 202 fProperties.put(IDENTIFIER, p.getElementName()); 203 else 204 fProperties.put(IDENTIFIER, ""); 206 fireChange(); 207 } 208 209 void fireChange() { 210 PropertyChangeEvent e= new PropertyChangeEvent(this, ALL, null, null); 211 Object [] listeners= fListeners.getListeners(); 212 for (int i= 0; i < listeners.length; i++) 213 ((IPropertyChangeListener)listeners[i]).propertyChange(e); 214 } 215 216 private void addDllDir(String wd, String path) { 217 File lib_dir; 218 if (path.startsWith("../")) { lib_dir= new File (wd, path); 220 } else { 221 lib_dir= new File (path); 222 } 223 if (lib_dir.isDirectory()) { 224 File [] dlls= lib_dir.listFiles(); 225 for (int j= 0; j < dlls.length; j++) { 226 try { 227 String name= dlls[j].getCanonicalPath(); 228 if (name.endsWith(".jnilib")) addResource(new ResourceInfo(name), false); } catch (IOException e) { 231 e.printStackTrace(); 233 } 234 } 235 } 236 } 237 238 static boolean verify(ILaunchConfiguration lc) { 239 String name= lc.getName(); 240 if (name.indexOf("jpage") >= 0) return false; 242 AbstractJavaLaunchConfigurationDelegate lcd; 243 try { 244 lcd= (AbstractJavaLaunchConfigurationDelegate) lc.getType().getDelegate(ILaunchManager.RUN_MODE); 245 if (lcd.getMainTypeName(lc) == null) 246 return false; 247 return true; 248 } catch (CoreException e) { 249 return false; 250 } 251 } 252 253 static boolean matches(ILaunchConfiguration lc, IJavaProject project) { 254 AbstractJavaLaunchConfigurationDelegate lcd; 255 try { 256 lcd= (AbstractJavaLaunchConfigurationDelegate) lc.getType().getDelegate(ILaunchManager.RUN_MODE); 257 } catch (CoreException e) { 258 return false; 259 } 260 IJavaProject p= null; 261 try { 262 p= lcd.getJavaProject(lc); 263 } catch (CoreException e) { 264 return false; 265 } 266 return project != null && project.equals(p); 267 } 268 } 269 | Popular Tags |