|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2005 IBM Corporation. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.jdt.launching.j9; |
| 12 |
|
| 13 |
import java.io.File; |
| 14 |
import java.io.FileFilter; |
| 15 |
import java.io.FileInputStream; |
| 16 |
import java.io.IOException; |
| 17 |
import java.text.DateFormat; |
| 18 |
import java.text.MessageFormat; |
| 19 |
import java.util.ArrayList; |
| 20 |
import java.util.Arrays; |
| 21 |
import java.util.Date; |
| 22 |
import java.util.HashMap; |
| 23 |
import java.util.Iterator; |
| 24 |
import java.util.List; |
| 25 |
import java.util.Map; |
| 26 |
import java.util.jar.Attributes; |
| 27 |
import java.util.jar.JarFile; |
| 28 |
import java.util.jar.Manifest; |
| 29 |
|
| 30 |
import org.eclipse.core.runtime.CoreException; |
| 31 |
import org.eclipse.core.runtime.IConfigurationElement; |
| 32 |
import org.eclipse.core.runtime.IExtensionPoint; |
| 33 |
import org.eclipse.core.runtime.IPath; |
| 34 |
import org.eclipse.core.runtime.Path; |
| 35 |
import org.eclipse.core.runtime.Platform; |
| 36 |
import org.eclipse.debug.core.ILaunchConfiguration; |
| 37 |
import org.eclipse.jdi.Bootstrap; |
| 38 |
import org.eclipse.jdt.core.IJavaProject; |
| 39 |
import org.eclipse.jdt.internal.launching.LaunchingPlugin; |
| 40 |
import org.eclipse.jdt.internal.launching.RuntimeClasspathProvider; |
| 41 |
import org.eclipse.jdt.internal.launching.j9.J9ConnectorDelegate; |
| 42 |
import org.eclipse.jdt.internal.launching.j9.J9LauncherMessages; |
| 43 |
import org.eclipse.jdt.internal.launching.j9.J9LaunchingPlugin; |
| 44 |
import org.eclipse.jdt.internal.launching.j9.J9SocketAttachConnector; |
| 45 |
import org.eclipse.jdt.internal.launching.j9.J9VMContentProvider; |
| 46 |
import org.eclipse.jdt.internal.launching.j9.J9VMInstall; |
| 47 |
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; |
| 48 |
import org.eclipse.jdt.launching.IRuntimeClasspathEntry; |
| 49 |
import org.eclipse.jdt.launching.IRuntimeClasspathProvider; |
| 50 |
import org.eclipse.jdt.launching.IVMConnector; |
| 51 |
import org.eclipse.jdt.launching.IVMInstall; |
| 52 |
import org.eclipse.jdt.launching.IVMInstallType; |
| 53 |
import org.eclipse.jdt.launching.JavaRuntime; |
| 54 |
import org.eclipse.jdt.launching.VMRunnerConfiguration; |
| 55 |
import org.eclipse.jface.preference.IPreferenceStore; |
| 56 |
|
| 57 |
import com.sun.jdi.connect.AttachingConnector; |
| 58 |
import com.sun.jdi.connect.ListeningConnector; |
| 59 |
|
| 60 |
/** |
| 61 |
* The central access point for J9 launching support, |
| 62 |
* similar to <code>JavaRuntime</code> |
| 63 |
* <p> |
| 64 |
* This class provides static methods only; it is not intended to be |
| 65 |
* instantiated or subclassed by clients. |
| 66 |
* </p> |
| 67 |
* @see org.eclipse.jdt.launching.JavaRuntime |
| 68 |
*/ |
| 69 |
public class J9Launching { |
| 70 |
|
| 71 |
/** |
| 72 |
* Default j9 debug symbol path providers. |
| 73 |
*/ |
| 74 |
private static IRuntimeClasspathProvider fgDefaultSymbolPathProvider = new StandardSymbolPathProvider(); |
| 75 |
|
| 76 |
/** |
| 77 |
* Path providers keyed by id |
| 78 |
*/ |
| 79 |
private static Map fgPathProviders = null; |
| 80 |
|
| 81 |
/** |
| 82 |
* Check if a VM install is a J9 VM install. |
| 83 |
* |
| 84 |
* @param vmInstall The vm install to check. |
| 85 |
* @return True if the id of the IVMInstallType of vmInstall equals ID_J9_VM_INSTALL_TYPE |
| 86 |
*/ |
| 87 |
public static boolean isJ9VMInstall(IVMInstall vmInstall) { |
| 88 |
return vmInstall.getVMInstallType().getId().equals(IJ9LaunchConfigurationConstants.ID_J9_VM_INSTALL_TYPE); |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Get all J9 VMs. |
| 93 |
* |
| 94 |
* @return all configured J9 VM instance |
| 95 |
*/ |
| 96 |
public static IVMInstall[] getJ9VMInstalls() { |
| 97 |
IVMInstallType vmInstallType = |
| 98 |
JavaRuntime.getVMInstallType( |
| 99 |
IJ9LaunchConfigurationConstants.ID_J9_VM_INSTALL_TYPE); |
| 100 |
return vmInstallType.getVMInstalls(); |
| 101 |
} |
| 102 |
|
| 103 |
/** |
| 104 |
* Finds the J9 VM with the given name. |
| 105 |
* |
| 106 |
* @param name the VM name |
| 107 |
* @return a VM instance, or <code>null</code> if not found |
| 108 |
*/ |
| 109 |
public static J9VMInstall findJ9VMInstallByName(String name) { |
| 110 |
IVMInstallType vmInstallType = |
| 111 |
JavaRuntime.getVMInstallType( |
| 112 |
IJ9LaunchConfigurationConstants.ID_J9_VM_INSTALL_TYPE); |
| 113 |
return (J9VMInstall)vmInstallType.findVMInstallByName(name); |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* Finds the J9 VM with the given id. |
| 118 |
* |
| 119 |
* @param id the VM id |
| 120 |
* @return a VM instance, or <code>null</code> if not found |
| 121 |
*/ |
| 122 |
public static J9VMInstall findJ9VMInstall(String id) { |
| 123 |
IVMInstallType vmInstallType = |
| 124 |
JavaRuntime.getVMInstallType( |
| 125 |
IJ9LaunchConfigurationConstants.ID_J9_VM_INSTALL_TYPE); |
| 126 |
return (J9VMInstall)vmInstallType.findVMInstall(id); |
| 127 |
} |
| 128 |
|
| 129 |
/** |
| 130 |
* Returns the path to the default J9 install, or null if there is no default J9 install. |
| 131 |
* |
| 132 |
* @return IPath |
| 133 |
*/ |
| 134 |
public static IPath getDefaultIveDir() { |
| 135 |
IVMInstall vm = getDefaultJ9VMInstall(); |
| 136 |
|
| 137 |
if (vm == null) { |
| 138 |
return null; |
| 139 |
} |
| 140 |
|
| 141 |
return new Path(vm.getInstallLocation().getAbsolutePath()); |
| 142 |
} |
| 143 |
|
| 144 |
/** |
| 145 |
* Get the default J9 VM. |
| 146 |
* |
| 147 |
* @return the workspace default J9VM instance, |
| 148 |
* Returns <code>null</code> if no J9 VMs have been configured. |
| 149 |
*/ |
| 150 |
public static J9VMInstall getDefaultJ9VMInstall() { |
| 151 |
IPreferenceStore store = J9LaunchingPlugin.getDefault().getPreferenceStore(); |
| 152 |
String id = store.getString(IJ9LaunchConfigurationConstants.PREF_DEFAULT_J9); |
| 153 |
if (id == null || "".equals(id)) { //$NON-NLS-1$ |
| 154 |
return null; |
| 155 |
} else { |
| 156 |
return findJ9VMInstall(id); |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
/** |
| 161 |
* Returns the VM assigned to build the given Java project |
| 162 |
* if it is a J9 VM. |
| 163 |
* If not, the workspace default J9 VM is returned. |
| 164 |
* @param project If <code>null</code>, the default J9 VM is returned |
| 165 |
* @return J9 IVMInstall of project, or the default J9 VM. |
| 166 |
* Returns <code>null</code> if no J9 VMs have been configured. |
| 167 |
*/ |
| 168 |
public static J9VMInstall getJ9VMInstall(IJavaProject project) { |
| 169 |
try { |
| 170 |
if (project != null) { |
| 171 |
IVMInstall projectDefaultVM = null; |
| 172 |
projectDefaultVM = J9VMContentProvider.getVMInstallFromResource(project); |
| 173 |
if (projectDefaultVM == null) |
| 174 |
projectDefaultVM = JavaRuntime.getVMInstall(project); |
| 175 |
if (projectDefaultVM != null && isJ9VMInstall(projectDefaultVM)) { |
| 176 |
return (J9VMInstall)projectDefaultVM; |
| 177 |
} |
| 178 |
} |
| 179 |
} catch (CoreException e) { |
| 180 |
J9LaunchingPlugin.getDefault().getLog().log(e.getStatus()); |
| 181 |
} |
| 182 |
return getDefaultJ9VMInstall(); |
| 183 |
} |
| 184 |
|
| 185 |
/** |
| 186 |
* Return a JDI socket transport attaching connector |
| 187 |
* |
| 188 |
* @exception CoreException if unable to locate the connector |
| 189 |
*/ |
| 190 |
public static AttachingConnector getAttachingConnector() throws CoreException { |
| 191 |
AttachingConnector connector= null; |
| 192 |
Iterator iter= Bootstrap.virtualMachineManager().attachingConnectors().iterator(); |
| 193 |
while (iter.hasNext()) { |
| 194 |
AttachingConnector lc= (AttachingConnector) iter.next(); |
| 195 |
if (lc.name().equals("com.sun.jdi.SocketAttach")) { //$NON-NLS-1$ |
| 196 |
connector= lc; |
| 197 |
break; |
| 198 |
} |
| 199 |
} |
| 200 |
if (connector == null) { |
| 201 |
J9LaunchingPlugin.abort(J9LauncherMessages.getString("J9Launching.Socket_attaching_connector_not_available"), null, IJavaLaunchConfigurationConstants.ERR_CONNECTOR_NOT_AVAILABLE); //$NON-NLS-1$ |
| 202 |
} |
| 203 |
return connector; |
| 204 |
} |
| 205 |
|
| 206 |
/** |
| 207 |
* |
| 208 |
* @exception CoreException if unable to locate the connector |
| 209 |
*/ |
| 210 |
public static ListeningConnector getListeningConnector() throws CoreException { |
| 211 |
ListeningConnector connector= null; |
| 212 |
Iterator iter= Bootstrap.virtualMachineManager().listeningConnectors().iterator(); |
| 213 |
while (iter.hasNext()) { |
| 214 |
ListeningConnector lc= (ListeningConnector) iter.next(); |
| 215 |
if (lc.name().equals("com.sun.jdi.SocketListen")) { //$NON-NLS-1$ |
| 216 |
connector= lc; |
| 217 |
break; |
| 218 |
} |
| 219 |
} |
| 220 |
if (connector == null) { |
| 221 |
J9LaunchingPlugin.abort(J9LauncherMessages.getString("J9Launching.Socket_attaching_connector_not_available"), null, IJavaLaunchConfigurationConstants.ERR_CONNECTOR_NOT_AVAILABLE); //$NON-NLS-1$ |
| 222 |
} |
| 223 |
return connector; |
| 224 |
} |
| 225 |
|
| 226 |
|
| 227 |
/** |
| 228 |
* Utility function to return string "{element} at localhost:{port}" for rendering debug target. |
| 229 |
*/ |
| 230 |
public static String renderDebugTarget(String elementToRun, int host) { |
| 231 |
String format= J9LauncherMessages.getString("J9Launching.format.dbgTarget"); //$NON-NLS-1$ |
| 232 |
return MessageFormat.format(format, new String[] { elementToRun, String.valueOf(host) }); |
| 233 |
} |
| 234 |
|
| 235 |
/** |
| 236 |
* Utility function to return string "{commandLine[0]} ({timestamp})" for rendering a debug process. |
| 237 |
*/ |
| 238 |
public static String renderProcessLabel(String[] commandLine) { |
| 239 |
String format= J9LauncherMessages.getString("J9Launching.format.processLabel"); //$NON-NLS-1$ |
| 240 |
String timestamp= DateFormat.getInstance().format(new Date(System.currentTimeMillis())); |
| 241 |
return MessageFormat.format(format, new String[] { commandLine[0], timestamp }); |
| 242 |
} |
| 243 |
|
| 244 |
/** |
| 245 |
* Return string "commandLine[1..max]" for rendering debug process. |
| 246 |
*/ |
| 247 |
public static String renderCommandLine(String[] commandLine) { |
| 248 |
if (commandLine.length < 1) |
| 249 |
return ""; //$NON-NLS-1$ |
| 250 |
StringBuffer buf= new StringBuffer(commandLine[0]); |
| 251 |
for (int i= 1; i < commandLine.length; i++) { |
| 252 |
buf.append(' '); |
| 253 |
buf.append(commandLine[i]); |
| 254 |
} |
| 255 |
return buf.toString(); |
| 256 |
} |
| 257 |
|
| 258 |
/** |
| 259 |
* Returns the j9 debug symbol lookup path provider for the given launch configuration. |
| 260 |
* |
| 261 |
* @param configuration launch configuration |
| 262 |
* @return symbol lookup path provider |
| 263 |
* @exception CoreException if unable to resolve the path provider |
| 264 |
* @since 2.0 |
| 265 |
*/ |
| 266 |
public static IRuntimeClasspathProvider getSymbolLookupPathProvider(ILaunchConfiguration configuration) throws CoreException { |
| 267 |
String providerId = configuration.getAttribute(IJ9LaunchConfigurationConstants.ATTR_SYMBOL_PATH_PROVIDER, (String)null); |
| 268 |
IRuntimeClasspathProvider provider = null; |
| 269 |
if (providerId == null) { |
| 270 |
provider = fgDefaultSymbolPathProvider; |
| 271 |
} else { |
| 272 |
provider = (IRuntimeClasspathProvider)getClasspathProviders().get(providerId); |
| 273 |
} |
| 274 |
return provider; |
| 275 |
} |
| 276 |
|
| 277 |
/** |
| 278 |
* Computes and returns the unresolved j9 debug symbol lookup path for the given launch |
| 279 |
* configuration. |
| 280 |
* |
| 281 |
* @param configuration launch configuration |
| 282 |
* @return runtime classpath entries |
| 283 |
* @exception CoreException if unable to compute the symbol lookup path |
| 284 |
* @since 2.0 |
| 285 |
*/ |
| 286 |
public static IRuntimeClasspathEntry[] computeUnresolvedSymbolLookupPath(ILaunchConfiguration configuration) throws CoreException { |
| 287 |
return getSymbolLookupPathProvider(configuration).computeUnresolvedClasspath(configuration); |
| 288 |
} |
| 289 |
|
| 290 |
/** |
| 291 |
* Resolves the given j9 debug symbol lookup path, returning the resolved symbol lookup path |
| 292 |
* in the context of the given launch configuration. |
| 293 |
* |
| 294 |
* @param entries unresolved entries |
| 295 |
* @param configuration launch configuration |
| 296 |
* @return resolved entries |
| 297 |
* @exception CoreException if unable to resolve the symbol lookup path |
| 298 |
* @since 2.0 |
| 299 |
*/ |
| 300 |
public static IRuntimeClasspathEntry[] resolveSymbolLookupPath(IRuntimeClasspathEntry[] entries, ILaunchConfiguration configuration) throws CoreException { |
| 301 |
return getSymbolLookupPathProvider(configuration).resolveClasspath(entries, configuration); |
| 302 |
} |
| 303 |
|
| 304 |
/** |
| 305 |
* Return the resolved and absolute j9 debug symbol path calculated from the |
| 306 |
* resolved symbol classpath of a launch configuration. |
| 307 |
* |
| 308 |
* @param configuration launch configuration |
| 309 |
* @return the set of absolute directory names containing 1 or more symbol files |
| 310 |
* @see J9ProxyAttachConnector#J9ProxyAttachConnector(String, String, String[], String, IVMInstall) |
| 311 |
*/ |
| 312 |
public static String[] getResolvedSymbolLookupPath(ILaunchConfiguration configuration) throws CoreException { |
| 313 |
IRuntimeClasspathEntry[] entries = J9Launching.computeUnresolvedSymbolLookupPath(configuration); |
| 314 |
entries = J9Launching.resolveSymbolLookupPath(entries, configuration); |
| 315 |
List symbolPath = new ArrayList(entries.length); |
| 316 |
for (int i = 0; i < entries.length; i++) { |
| 317 |
String entry = entries[i].getLocation(); |
| 318 |
// entry will be null in the case where you originally had a project in your symbol path that has since been deleted. |
| 319 |
if (entry != null) { |
| 320 |
addSymbolFileEntry(symbolPath, entry); |
| 321 |
} |
| 322 |
} |
| 323 |
return (String[])symbolPath.toArray(new String[symbolPath.size()]); |
| 324 |
} |
| 325 |
|
| 326 |
/** |
| 327 |
* @return Returns J9 IVMInstall for connector, |
| 328 |
* or null if connector has no J9 IVMInstall |
| 329 |
*/ |
| 330 |
public static J9VMInstall getJ9VMInstall(IVMConnector connector, Map arguments, IJavaProject project) throws CoreException { |
| 331 |
if (connector instanceof J9ConnectorDelegate) { |
| 332 |
String vmName = (String)arguments.get(J9SocketAttachConnector.ARG_VM_INSTALL_NAME); |
| 333 |
|
| 334 |
// If default VM is selected, take default VM for project |
| 335 |
if (vmName == null || vmName.equals(J9SocketAttachConnector.DEFAULT_JRE_NAME)) { |
| 336 |
return getJ9VMInstall(project); |
| 337 |
} else { |
| 338 |
return findJ9VMInstallByName(vmName); |
| 339 |
} |
| 340 |
} |
| 341 |
return getJ9VMInstall(project); |
| 342 |
} |
| 343 |
|
| 344 |
/** |
| 345 |
* If the entry denotes a symbol file, add it. If the entry |
| 346 |
* does not denote a symbol file, but the directory of the entry |
| 347 |
* contains symbol files, add that directory. |
| 348 |
*/ |
| 349 |
private static void addSymbolFileEntry(List symbolPath, String entry) { |
| 350 |
if (!entry.toLowerCase().endsWith(".sym")) { //$NON-NLS-1$ |
| 351 |
File dir = new File(entry); |
| 352 |
if (!dir.isDirectory()) { |
| 353 |
dir = dir.getParentFile(); |
| 354 |
} |
| 355 |
File files[] = dir.listFiles(new FileFilter() { |
| 356 |
public boolean accept(File target) { |
| 357 |
return target.getName().toLowerCase().endsWith(".sym"); //$NON-NLS-1$ |
| 358 |
} |
| 359 |
}); |
| 360 |
if (files == null || files.length == 0) { |
| 361 |
return; |
| 362 |
} |
| 363 |
entry = dir.getAbsolutePath(); |
| 364 |
} |
| 365 |
if (!symbolPath.contains(entry)) { |
| 366 |
symbolPath.add(entry); |
| 367 |
} |
| 368 |
} |
| 369 |
|
| 370 |
/** |
| 371 |
* Returns all registered classpath providers. |
| 372 |
*/ |
| 373 |
private static Map getClasspathProviders() { |
| 374 |
if (fgPathProviders == null) { |
| 375 |
initializeProviders(); |
| 376 |
} |
| 377 |
return fgPathProviders; |
| 378 |
} |
| 379 |
|
| 380 |
private static void initializeProviders() { |
| 381 |
/* |
| 382 |
* LL: Migration to 3.0: IPluginDescriptor.getExtensionPoint() has been deprecated. |
| 383 |
* Use Platform.getExtensionRegistry().getExtensionPoint() instead. |
| 384 |
*/ |
| 385 |
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(LaunchingPlugin.getUniqueIdentifier(), JavaRuntime.EXTENSION_POINT_RUNTIME_CLASSPATH_PROVIDERS); |
| 386 |
IConfigurationElement[] extensions = point.getConfigurationElements(); |
| 387 |
fgPathProviders = new HashMap(extensions.length); |
| 388 |
for (int i = 0; i < extensions.length; i++) { |
| 389 |
RuntimeClasspathProvider res = new RuntimeClasspathProvider(extensions[i]); |
| 390 |
fgPathProviders.put(res.getIdentifier(), res); |
| 391 |
} |
| 392 |
} |
| 393 |
|
| 394 |
/** |
| 395 |
* @return Returns whether to run the J9 VM as console application. |
| 396 |
* Returns true by default, if no vm specific attributes are provided. |
| 397 |
*/ |
| 398 |
public static boolean runAsConsole(Map vmSpecificAttributesMap) { // KMH |
| 399 |
if (vmSpecificAttributesMap == null) |
| 400 |
return true; // the default for run on console is true. |
| 401 |
return Boolean.valueOf((String)vmSpecificAttributesMap.get(IJ9LaunchConfigurationConstants.ATTR_RUN_AS_CONSOLE)).booleanValue(); |
| 402 |
} |
| 403 |
|
| 404 |
/** |
| 405 |
* @return Returns whether the -jxe option should be used to run an application, if possible. |
| 406 |
* Returns true by default, if no vm specific attributes are provided. |
| 407 |
*/ |
| 408 |
public static boolean executeFromArchive(Map vmSpecificAttributesMap) { |
| 409 |
return vmSpecificAttributesMap == null || Boolean.valueOf((String)vmSpecificAttributesMap.get(IJ9LaunchConfigurationConstants.ATTR_EXECUTE_FROM_ARCHIVE)).booleanValue(); |
| 410 |
} |
| 411 |
|
| 412 |
private static File getExecutableArchiveFile(String workingDir, String archiveFileName, String startupClass) { |
| 413 |
File archiveFile = new File(archiveFileName); |
| 414 |
if (workingDir != null && !archiveFile.isAbsolute()) { |
| 415 |
archiveFile = new File(workingDir, archiveFileName); |
| 416 |
} |
| 417 |
|
| 418 |
if (!startupClass.equals(getStartupClass(archiveFile))) { |
| 419 |
return null; |
| 420 |
} |
| 421 |
|
| 422 |
// Make file relative |
| 423 |
// Commented out because it makes path translation for devices harder |
| 424 |
// if (workingDir != null) { |
| 425 |
// int index = archiveFileName.indexOf(workingDir); |
| 426 |
// if (index != -1) { |
| 427 |
// archiveFile = new File(archiveFileName.substring(workingDir.length() + 1, archiveFileName.length())); |
| 428 |
// } |
| 429 |
// } |
| 430 |
return archiveFile; |
| 431 |
} |
| 432 |
|
| 433 |
public static boolean isJxeArchive(File archiveFile) { |
| 434 |
return archiveFile.getName().endsWith(".jxe"); //$NON-NLS-1$ |
| 435 |
} |
| 436 |
|
| 437 |
public static boolean isJarArchive(File archiveFile) { |
| 438 |
return archiveFile.getName().endsWith(".jar"); //$NON-NLS-1$ |
| 439 |
} |
| 440 |
|
| 441 |
/** |
| 442 |
* @return Returns startup class (using dots in the qualified name, not slashes), or null |
| 443 |
*/ |
| 444 |
public static String getStartupClass(File archiveFile) { |
| 445 |
try { |
| 446 |
String startupClass = null; |
| 447 |
if (isJxeArchive(archiveFile)) { |
| 448 |
JxeInfo jxeInfo = new JxeInfo(new FileInputStream(archiveFile)); |
| 449 |
startupClass = jxeInfo.getStartupClass(); |
| 450 |
} else if (isJarArchive(archiveFile)) { |
| 451 |
JarFile jar = new JarFile(archiveFile); |
| 452 |
Manifest m = jar.getManifest(); |
| 453 |
if (m != null) { |
| 454 |
startupClass = m.getMainAttributes().getValue(Attributes.Name.MAIN_CLASS); |
| 455 |
} |
| 456 |
jar.close(); //Sri! 104644 |
| 457 |
} |
| 458 |
return startupClass == null ? null : startupClass.replace('/','.'); |
| 459 |
} catch (IOException e) { |
| 460 |
// Assume not a jxe/jar file |
| 461 |
} |
| 462 |
return null; |
| 463 |
} |
| 464 |
|
| 465 |
/** |
| 466 |
* Adapt the VMRunnerConfiguration to ATTR_EXECUTE_FROM_ARCHIVE. |
| 467 |
* If the option is set, the boot- and classpath will be scanned for |
| 468 |
* a JXE or JAR with a startup class. |
| 469 |
* If an executable JXE is found, the -jxe option will be used to launch the application, |
| 470 |
* and all boot- and classpath entries will be moved to the boot path. |
| 471 |
* If an executable JAR is found on the classpath and the vm supports it, |
| 472 |
* the -jar option will be used to launch the application. |
| 473 |
* An executable jar on the boot path is ignored because -jar puts classes on the classpath. |
| 474 |
*/ |
| 475 |
public static VMRunnerConfiguration adaptVMRunnerConfiguration(VMRunnerConfiguration config, J9VMInstall vm) throws CoreException { |
| 476 |
if (executeFromArchive(config.getVMSpecificAttributesMap())) { |
| 477 |
List bootPath = new ArrayList(); |
| 478 |
if (config.getBootClassPath() != null) { |
| 479 |
bootPath.addAll(Arrays.asList(config.getBootClassPath())); |
| 480 |
} |
| 481 |
List classPath = new ArrayList(Arrays.asList(config.getClassPath())); |
| 482 |
List combinedPath = new ArrayList(bootPath); |
| 483 |
combinedPath.addAll(classPath); |
| 484 |
for (Iterator iter = combinedPath.iterator(); iter.hasNext();) { |
| 485 |
String archiveFileName = (String)iter.next(); |
| 486 |
File archiveFile = getExecutableArchiveFile(config.getWorkingDirectory(), archiveFileName, config.getClassToLaunch()); |
| 487 |
if (archiveFile != null) { |
| 488 |
boolean isJxeArchive = isJxeArchive(archiveFile); |
| 489 |
if (isJxeArchive || (!vm.isPre20J9Version() && !bootPath.contains(archiveFileName))) { |
| 490 |
String vmArgs[] = config.getVMArguments(); |
| 491 |
List vmArgList = new ArrayList(vmArgs.length + 2); |
| 492 |
vmArgList.addAll(Arrays.asList(vmArgs)); |
| 493 |
String newBootPath[]; |
| 494 |
String newClassPath[]; |
| 495 |
String classToLaunch = config.getClassToLaunch(); |
| 496 |
// TODO remove this special case which takes the bin folder |
| 497 |
// off the class path only when a .jxe is being built |
| 498 |
List removeList = new ArrayList(); |
| 499 |
for (Iterator iterator = classPath.iterator(); iterator.hasNext();) { |
| 500 |
String element = (String) iterator.next(); |
| 501 |
if (element.endsWith("bin")) { //$NON-NLS-1$ |
| 502 |
removeList.add(element); |
| 503 |
} |
| 504 |
} |
| 505 |
classPath.removeAll(removeList); |
| 506 |
newClassPath = (String[])classPath.toArray(new String[classPath.size()]); |
| 507 |
combinedPath.removeAll(removeList); |
| 508 |
|
| 509 |
if (isJxeArchive) { |
| 510 |
if (vm.is21J9Version()) { |
| 511 |
if (config.getBootClassPath().length == 0) { |
| 512 |
config.setBootClassPath(null); |
| 513 |
newBootPath = new String[0]; |
| 514 |
} else |
| 515 |
newBootPath = config.getBootClassPath(); |
| 516 |
} else { |
| 517 |
// there is no class to launch for this case |
| 518 |
classToLaunch = ""; //$NON-NLS-1$ |
| 519 |
combinedPath.remove(archiveFileName); |
| 520 |
vmArgList.add("-jxe:"+archiveFile.getPath()); //$NON-NLS-1$ |
| 521 |
newBootPath = new String[combinedPath.size()]; |
| 522 |
combinedPath.toArray(newBootPath); |
| 523 |
newClassPath = new String[0]; |
| 524 |
} |
| 525 |
} |
| 526 |
else { |
| 527 |
if (config.getBootClassPath().length == 0) { |
| 528 |
config.setBootClassPath(null); |
| 529 |
newBootPath = new String[0]; |
| 530 |
} else |
| 531 |
newBootPath = config.getBootClassPath(); |
| 532 |
// vmArgList.add("-jar"); //$NON-NLS-1$ |
| 533 |
// vmArgList.add(archiveFile.getPath()); |
| 534 |
// newBootPath = new String[bootPath.size()]; |
| 535 |
// bootPath.toArray(newBootPath); |
| 536 |
// classPath.remove(archiveFileName); |
| 537 |
// newClassPath = new String[classPath.size()]; |
| 538 |
// classPath.toArray(newClassPath); |
| 539 |
} |
| 540 |
VMRunnerConfiguration adaptedConfig = new VMRunnerConfiguration(classToLaunch, newClassPath); //$NON-NLS-1$ |
| 541 |
if (newBootPath.length == 0 && config.getBootClassPath() == null) { |
| 542 |
adaptedConfig.setBootClassPath(null); |
| 543 |
} else { |
| 544 |
adaptedConfig.setBootClassPath(newBootPath); |
| 545 |
} |
| 546 |
vmArgs = new String[vmArgList.size()]; |
| 547 |
vmArgList.toArray(vmArgs); |
| 548 |
adaptedConfig.setProgramArguments(config.getProgramArguments()); |
| 549 |
adaptedConfig.setVMArguments(vmArgs); |
| 550 |
adaptedConfig.setWorkingDirectory(config.getWorkingDirectory()); |
| 551 |
adaptedConfig.setVMSpecificAttributesMap(config.getVMSpecificAttributesMap()); |
| 552 |
|
| 553 |
return adaptedConfig; |
| 554 |
} |
| 555 |
} |
| 556 |
} |
| 557 |
} |
| 558 |
return config; |
| 559 |
} |
| 560 |
} |