harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arc...@apache.org
Subject svn commit: r368928 - in /incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm: java/org/dellroad/jc/vm/JarLoader.java libjc/jc_invoke.c
Date Sat, 14 Jan 2006 00:08:04 GMT
Author: archie
Date: Fri Jan 13 16:08:01 2006
New Revision: 368928

URL: http://svn.apache.org/viewcvs?rev=368928&view=rev
Log:
Fix bug in "-jar" support: we were prepending the JAR file to
the java.class.path too late in the process.

Modified:
    incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/vm/JarLoader.java
    incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/jc_invoke.c

Modified: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/vm/JarLoader.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/vm/JarLoader.java?rev=368928&r1=368927&r2=368928&view=diff
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/vm/JarLoader.java
(original)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/vm/JarLoader.java
Fri Jan 13 16:08:01 2006
@@ -15,7 +15,7 @@
 //  See the License for the specific language governing permissions and
 //  limitations under the License.
 //
-// $Id: JarLoader.java,v 1.1.1.1 2004/02/20 05:15:26 archiecobbs Exp $
+// $Id$
 //
 
 package org.dellroad.jc.vm;
@@ -73,12 +73,6 @@
 			    + Attributes.Name.MAIN_CLASS + "'' attribute"
 			    + " found in manifest of ``" + jarfile + "''");
 		}
-
-		// Prepend JAR file to class path
-		System.setProperty("java.class.path",
-		    "file://" + jarfile.getAbsolutePath()
-		      + System.getProperty("path.separator", ":")
-		      + System.getProperty("java.class.path", "."));
 
 		// Find the main class
 		Class cl;

Modified: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/jc_invoke.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/jc_invoke.c?rev=368928&r1=368927&r2=368928&view=diff
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/jc_invoke.c (original)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/jc_invoke.c Fri
Jan 13 16:08:01 2006
@@ -136,7 +136,8 @@
 };
 
 /* Internal functions */
-static int	jc_run(JNIEnv *env, jboolean jar, int ac, const char **av);
+static int	jc_run(JNIEnv *env, const char *main_class,
+			int ac, const char **av);
 static int	jc_read_options(_jc_printer *printer, poptContext pctx,
 			const char *path);
 static int	jc_process_verbose(JavaVMInitArgs *args,
@@ -164,13 +165,15 @@
 	int rtn = _JC_RETURN_ERROR;
 	poptContext pctx = NULL;
 	jboolean jar = JNI_FALSE;
+	const char *classpath = ".";
+	const char *main_class;
 	const char *home_dir;
 	JavaVM *vm = NULL;
 	JNIEnv *env = NULL;
 	const char **params;
-	int got_classpath = 0;
 	char **av = NULL;
 	int num_params;
+	char *temp;
 	void *envp;
 	int ac = 0;
 	int op;
@@ -348,8 +351,8 @@
 
 		switch (op) {
 		case OPT_CLASSPATH:
-			got_classpath = 1;
-			/* FALLTHROUGH */
+			classpath = value;
+			break;
 		case OPT_LIBRARYPATH:
 		case OPT_BOOTCLASSPATH:
 		    {
@@ -446,13 +449,6 @@
 		goto usage;
 	}
 
-	/* If no classpath was explicitly specified, use "." as a default */
-	if (!got_classpath) {
-		if (jc_add_vm_property(&vm_args, printer, JAVA_CLASS_PATH,
-		    sizeof(JAVA_CLASS_PATH) - 1, ".") != JNI_OK)
-			goto done;
-	}
-
 	/* Get class name and parameters */
 	params = poptGetArgs(pctx);
 	for (num_params = 0; params != NULL
@@ -462,6 +458,27 @@
 		goto done;
 	}
 
+	/* For -jar, prepend JAR file to classpath */
+	if (jar) {
+		if ((temp = alloca(strlen(params[0]) + 1
+		    + strlen(classpath) + 1)) == NULL) {
+			jc_print(printer, stderr,
+			    "jc: %s: %s\n", "alloca", strerror(errno));
+			goto done;
+		}
+		sprintf(temp, "%s:%s", params[0], classpath);
+		classpath = temp;
+		main_class = JC_JAR_LOADER_CLASS;
+	} else {
+		main_class = *params++;
+		num_params--;
+	}
+
+	/* Set classpath property */
+	if (jc_add_vm_property(&vm_args, printer, JAVA_CLASS_PATH,
+	    sizeof(JAVA_CLASS_PATH) - 1, classpath) != JNI_OK)
+		goto done;
+
 	/* Create new VM */
 	if (JNI_CreateJavaVM(&vm, &envp, &vm_args) != JNI_OK) {
 		jc_print(printer, stderr, "jc: failed to create VM\n");
@@ -476,8 +493,8 @@
 	vm_args.options = NULL;
 
 	/* Run program */
-	if ((rtn = jc_run(env, jar, num_params, params))
-	    == _JC_RETURN_EXCEPTION)
+	if ((rtn = jc_run(env, main_class,
+	    num_params, params)) == _JC_RETURN_EXCEPTION)
 		(*env)->ExceptionDescribe(env);
 
 	/* Free parsing context */
@@ -507,24 +524,14 @@
  * Run the Java program.
  */
 static int
-jc_run(JNIEnv *env, jboolean jar, int ac, const char **av)
+jc_run(JNIEnv *env, const char *main_class, int ac, const char **av)
 {
-	const char *main_class;
 	jclass string_class;
 	jarray param_array;
 	jmethodID method;
 	jclass class;
 	char *buf;
 	int i;
-
-	/* Get main class and params */
-	if (jar)
-		main_class = JC_JAR_LOADER_CLASS;
-	else {
-		main_class = av[0];
-		av++;
-		ac--;
-	}
 
 	/* Build String[] array of parameters */
 	if ((string_class = (*env)->FindClass(env, "java/lang/String")) == NULL)



Mime
View raw message