You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2009/07/10 12:59:32 UTC
svn commit: r792882 -
/harmony/enhanced/tools/trunk/eclipse/org.apache.harmony.eclipse.jdt.launching/src/org/apache/harmony/eclipse/jdt/launching/HyVMInstall.java
Author: tellison
Date: Fri Jul 10 10:59:32 2009
New Revision: 792882
URL: http://svn.apache.org/viewvc?rev=792882&view=rev
Log:
Update the Harmony install plugin to report the Java version of a particular install.
Usually Eclipse will invoke the VM with a program to look at the system properties, but I figured we can look in the LUNI manifest at the "Specification-Version" more quickly.
Modified:
harmony/enhanced/tools/trunk/eclipse/org.apache.harmony.eclipse.jdt.launching/src/org/apache/harmony/eclipse/jdt/launching/HyVMInstall.java
Modified: harmony/enhanced/tools/trunk/eclipse/org.apache.harmony.eclipse.jdt.launching/src/org/apache/harmony/eclipse/jdt/launching/HyVMInstall.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/tools/trunk/eclipse/org.apache.harmony.eclipse.jdt.launching/src/org/apache/harmony/eclipse/jdt/launching/HyVMInstall.java?rev=792882&r1=792881&r2=792882&view=diff
==============================================================================
--- harmony/enhanced/tools/trunk/eclipse/org.apache.harmony.eclipse.jdt.launching/src/org/apache/harmony/eclipse/jdt/launching/HyVMInstall.java (original)
+++ harmony/enhanced/tools/trunk/eclipse/org.apache.harmony.eclipse.jdt.launching/src/org/apache/harmony/eclipse/jdt/launching/HyVMInstall.java Fri Jul 10 10:59:32 2009
@@ -17,8 +17,13 @@
package org.apache.harmony.eclipse.jdt.launching;
+import java.io.File;
+import java.io.IOException;
import java.util.List;
+import java.util.jar.Attributes;
+import java.util.jar.JarFile;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.jdt.launching.AbstractVMInstall;
import org.eclipse.jdt.launching.IVMInstallType;
@@ -27,104 +32,141 @@
public class HyVMInstall extends AbstractVMInstall {
- /*
- * Constructor for a VM install.
- */
- HyVMInstall(IVMInstallType type, String id) {
- super(type, id);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jdt.launching.IVMInstall#getVMRunner(java.lang.String)
- */
- public IVMRunner getVMRunner(String mode) {
- if (ILaunchManager.RUN_MODE.equals(mode)) {
- return new HyVMRunner(this);
- } else if (ILaunchManager.DEBUG_MODE.equals(mode)) {
- return new HyDebugVMRunner(this);
- }
- return null;
- }
-
- public void setLibraryLocations(LibraryLocation[] locations) {
- // If the libs are being explicitly set, then don't monkey with them
- if (locations != null) {
- super.setLibraryLocations(locations);
- return;
- }
-
- if (locations == null) {
- super.setLibraryLocations(locations);
- return;
- }
-
- // 'null' means use the default locations, which for us depends
- // upon the argument list.
-
- // find the vm subdir and VMI name
- String subdir = "default"; //$NON-NLS-1$
- String vminame = "harmonyvm"; //$NON-NLS-1$
- String[] args = getVMArguments();
- if (args != null) {
- for (int i = 0; i < args.length; i++) {
- if (args[i].startsWith("-vmdir:")) { //$NON-NLS-1$
- subdir = args[i].substring("-vmdir:".length()); //$NON-NLS-1$
- }
- if (args[i].startsWith("-vm:")) { //$NON-NLS-1$
- vminame = args[i].substring("-vm:".length()); //$NON-NLS-1$
- }
- }
- }
-
- // Build a library location for the kernel classes
- LibraryLocation[] kernel = kernelLocation(subdir, vminame);
- LibraryLocation[] stdDefaults = getVMInstallType()
- .getDefaultLibraryLocations(getInstallLocation());
-
- // Ensure we don't duplicate the kernel
- boolean found = false;
- for (int i = 0; i < stdDefaults.length; i++) {
- LibraryLocation location = stdDefaults[i];
- if (location.getSystemLibraryPath().equals(
- kernel[0].getSystemLibraryPath())) {
- found = true;
- break;
- }
- }
-
- if (found) {
- super.setLibraryLocations(null);
- } else {
- LibraryLocation[] allLibs = new LibraryLocation[kernel.length + stdDefaults.length];
- System.arraycopy(kernel, 0, allLibs, 0, kernel.length);
- System.arraycopy(stdDefaults, 0, allLibs, kernel.length, stdDefaults.length);
- super.setLibraryLocations(allLibs);
- }
- }
-
- private LibraryLocation[] kernelLocation(String subdir, String vmname) {
- List kernelLibraries = ((HyVMInstallType) getVMInstallType()).getKernelLibraries(
- getInstallLocation(), subdir, vmname);
-
- LibraryLocation[] kernelLibrariesLocation = new LibraryLocation[kernelLibraries.size()];
- for (int i = 0; i < kernelLibraries.size(); i++) {
- kernelLibrariesLocation[i] = (LibraryLocation) kernelLibraries.get(i);
- }
-
- return kernelLibrariesLocation;
- }
-
- /*
- * (non-Javadoc) The setVMArgs does not cause an event change, so we have to
- * subclass here to (potentially) change our library path based on changes
- * to the -vmdir argument.
- *
- * @see org.eclipse.jdt.launching.IVMInstall#setVMArgs(java.lang.String)
- */
- public void setVMArgs(String vmArgs) {
- super.setVMArgs(vmArgs);
- setLibraryLocations(getLibraryLocations());
- }
+ /*
+ * Constructor for a VM install.
+ */
+ HyVMInstall(IVMInstallType type, String id) {
+ super(type, id);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jdt.launching.IVMInstall#getVMRunner(java.lang.String)
+ */
+ public IVMRunner getVMRunner(String mode) {
+ if (ILaunchManager.RUN_MODE.equals(mode)) {
+ return new HyVMRunner(this);
+ } else if (ILaunchManager.DEBUG_MODE.equals(mode)) {
+ return new HyDebugVMRunner(this);
+ }
+ return null;
+ }
+
+ public void setLibraryLocations(LibraryLocation[] locations) {
+ // If the libs are being explicitly set, then don't monkey with them
+ if (locations != null) {
+ super.setLibraryLocations(locations);
+ return;
+ }
+
+ if (locations == null) {
+ super.setLibraryLocations(locations);
+ return;
+ }
+
+ // 'null' means use the default locations, which for us depends
+ // upon the argument list.
+
+ // find the vm subdir and VMI name
+ String subdir = "default"; //$NON-NLS-1$
+ String vminame = "harmonyvm"; //$NON-NLS-1$
+ String[] args = getVMArguments();
+ if (args != null) {
+ for (int i = 0; i < args.length; i++) {
+ if (args[i].startsWith("-vmdir:")) { //$NON-NLS-1$
+ subdir = args[i].substring("-vmdir:".length()); //$NON-NLS-1$
+ }
+ if (args[i].startsWith("-vm:")) { //$NON-NLS-1$
+ vminame = args[i].substring("-vm:".length()); //$NON-NLS-1$
+ }
+ }
+ }
+
+ // Build a library location for the kernel classes
+ LibraryLocation[] kernel = kernelLocation(subdir, vminame);
+ LibraryLocation[] stdDefaults = getVMInstallType().getDefaultLibraryLocations(
+ getInstallLocation());
+
+ // Ensure we don't duplicate the kernel
+ boolean found = false;
+ for (int i = 0; i < stdDefaults.length; i++) {
+ LibraryLocation location = stdDefaults[i];
+ if (location.getSystemLibraryPath().equals(kernel[0].getSystemLibraryPath())) {
+ found = true;
+ break;
+ }
+ }
+
+ if (found) {
+ super.setLibraryLocations(null);
+ } else {
+ LibraryLocation[] allLibs = new LibraryLocation[kernel.length
+ + stdDefaults.length];
+ System.arraycopy(kernel, 0, allLibs, 0, kernel.length);
+ System.arraycopy(stdDefaults, 0, allLibs, kernel.length, stdDefaults.length);
+ super.setLibraryLocations(allLibs);
+ }
+ }
+
+ private LibraryLocation[] kernelLocation(String subdir, String vmname) {
+ List kernelLibraries = ((HyVMInstallType) getVMInstallType()).getKernelLibraries(
+ getInstallLocation(), subdir, vmname);
+
+ LibraryLocation[] kernelLibrariesLocation = new LibraryLocation[kernelLibraries
+ .size()];
+ for (int i = 0; i < kernelLibraries.size(); i++) {
+ kernelLibrariesLocation[i] = (LibraryLocation) kernelLibraries.get(i);
+ }
+
+ return kernelLibrariesLocation;
+ }
+
+ /*
+ * (non-Javadoc) The setVMArgs does not cause an event change, so we have to
+ * subclass here to (potentially) change our library path based on changes
+ * to the -vmdir argument.
+ *
+ * @see org.eclipse.jdt.launching.IVMInstall#setVMArgs(java.lang.String)
+ */
+ public void setVMArgs(String vmArgs) {
+ super.setVMArgs(vmArgs);
+ setLibraryLocations(getLibraryLocations());
+ }
+
+ /**
+ * Returns the version string for the Java implementation, or null if it is
+ * unknown.
+ */
+ public String getJavaVersion() {
+ HyVMInstallType installType = (HyVMInstallType) getVMInstallType();
+ File installLocation = getInstallLocation();
+ if (installLocation == null) {
+ return null;
+ }
+ // Look for the luni library
+ LibraryLocation[] libraries = installType
+ .getDefaultLibraryLocations(installLocation);
+ for (LibraryLocation library : libraries) {
+ IPath libPath = library.getSystemLibraryPath();
+ if (libPath.lastSegment().equals("luni.jar")) {
+ return findSpecVersionFrom(libPath);
+ }
+ }
+ return null;
+ }
+
+ private String findSpecVersionFrom(IPath libPath) {
+ try {
+ JarFile luni = new JarFile(libPath.toFile());
+ Attributes attribs = luni.getManifest().getMainAttributes();
+ luni.close();
+ return attribs.getValue(Attributes.Name.SPECIFICATION_VERSION);
+ } catch (IOException e) {
+ HyLaunchingPlugin.getDefault().log("Problem reading spec version from LUNI",
+ e);
+ return null;
+ }
+ }
+
}