< prev index next >
src/java.base/share/native/libjli/java.c
Print this page
@@ -170,10 +170,13 @@
static void GrowKnownVMs(int minimum);
static int KnownVMIndex(const char* name);
static void FreeKnownVMs();
static jboolean IsWildCardEnabled();
+
+#define SOURCE_LAUNCHER_MAIN_ENTRY "jdk.compiler/com.sun.tools.javac.launcher.Main"
+
/*
* This reports error. VM will not be created and no usage is printed.
*/
#define REPORT_ERROR(AC_ok, AC_failure_message, AC_questionable_arg) \
do { \
@@ -212,11 +215,11 @@
/*
* Entry point.
*/
JNIEXPORT int JNICALL
-JLI_Launch(int argc, char ** argv, /* main argc, argc */
+JLI_Launch(int argc, char ** argv, /* main argc, argv */
int jargc, const char** jargv, /* java args */
int appclassc, const char** appclassv, /* app classpath */
const char* fullversion, /* full version defined */
const char* dotversion, /* UNUSED dot version defined */
const char* pname, /* program name */
@@ -315,12 +318,11 @@
}
/* Parse command line options; if the return value of
* ParseArguments is false, the program should exit.
*/
- if (!ParseArguments(&argc, &argv, &mode, &what, &ret, jrepath))
- {
+ if (!ParseArguments(&argc, &argv, &mode, &what, &ret, jrepath)) {
return(ret);
}
/* Override class path if -jar flag was specified */
if (mode == LM_JAR) {
@@ -583,11 +585,12 @@
static jboolean
IsLauncherOption(const char* name) {
return IsClassPathOption(name) ||
IsLauncherMainOption(name) ||
JLI_StrCmp(name, "--describe-module") == 0 ||
- JLI_StrCmp(name, "-d") == 0;
+ JLI_StrCmp(name, "-d") == 0 ||
+ JLI_StrCmp(name, "--source") == 0;
}
/*
* Test if the given name is a module-system white-space option that
* will be passed to the VM with its corresponding long-form option
@@ -625,10 +628,33 @@
return IsModuleOption(name) ||
IsLauncherOption(name);
}
/*
+ * Check if it is OK to set the mode.
+ * If the mode was previously set, and should not be changed,
+ * a fatal error is reported.
+ */
+static int
+checkMode(int mode, int newMode, const char *arg) {
+ if (mode == LM_SOURCE) {
+ JLI_ReportErrorMessage(ARG_ERROR14, arg);
+ exit(1);
+ }
+ return newMode;
+}
+
+/*
+ * Test if an arg identifies a source file.
+ */
+jboolean
+IsSourceFile(const char *arg) {
+ struct stat st;
+ return (JLI_HasSuffix(arg, ".java") && stat(arg, &st) == 0);
+}
+
+/*
* Checks the command line options to find which JVM type was
* specified. If no command line option was given for the JVM type,
* the default type is used. The environment variable
* JDK_ALTERNATE_VM and the command line option -XXaltjvm= are also
* checked as ways of specifying which JVM type to invoke.
@@ -1228,11 +1254,12 @@
} else if (JLI_StrCCmp(arg, "--") == 0 && (equals = JLI_StrChr(arg, '=')) != NULL) {
value = equals+1;
if (JLI_StrCCmp(arg, "--describe-module=") == 0 ||
JLI_StrCCmp(arg, "--module=") == 0 ||
- JLI_StrCCmp(arg, "--class-path=") == 0) {
+ JLI_StrCCmp(arg, "--class-path=") == 0||
+ JLI_StrCCmp(arg, "--source=") == 0) {
kind = LAUNCHER_OPTION_WITH_ARGUMENT;
} else {
kind = VM_LONG_OPTION;
}
}
@@ -1272,21 +1299,33 @@
/*
* Option to set main entry point
*/
if (JLI_StrCmp(arg, "-jar") == 0) {
ARG_CHECK(argc, ARG_ERROR2, arg);
- mode = LM_JAR;
+ mode = checkMode(mode, LM_JAR, arg);
} else if (JLI_StrCmp(arg, "--module") == 0 ||
JLI_StrCCmp(arg, "--module=") == 0 ||
JLI_StrCmp(arg, "-m") == 0) {
REPORT_ERROR (has_arg, ARG_ERROR5, arg);
SetMainModule(value);
- mode = LM_MODULE;
+ mode = checkMode(mode, LM_MODULE, arg);
if (has_arg) {
*pwhat = value;
break;
}
+ } else if (JLI_StrCmp(arg, "--source") == 0 ||
+ JLI_StrCCmp(arg, "--source=") == 0) {
+ REPORT_ERROR (has_arg, ARG_ERROR13, arg);
+ mode = LM_SOURCE;
+ if (has_arg) {
+ const char *prop = "-Djdk.internal.javac.source=";
+ size_t size = JLI_StrLen(prop) + JLI_StrLen(value) + 1;
+ char *propValue = (char *)JLI_MemAlloc(size + 1);
+ JLI_StrCpy(propValue, prop);
+ JLI_StrCat(propValue, value);
+ AddOption(propValue, NULL);
+ }
} else if (JLI_StrCmp(arg, "--class-path") == 0 ||
JLI_StrCCmp(arg, "--class-path=") == 0 ||
JLI_StrCmp(arg, "-classpath") == 0 ||
JLI_StrCmp(arg, "-cp") == 0) {
REPORT_ERROR (has_arg_any_len, ARG_ERROR1, arg);
@@ -1433,17 +1472,27 @@
/* default to LM_CLASS if -m, -jar and -cp options are
* not specified */
if (!_have_classpath) {
SetClassPath(".");
}
- mode = LM_CLASS;
+ mode = IsSourceFile(arg) ? LM_SOURCE : LM_CLASS;
+ } else if (mode == LM_CLASS && IsSourceFile(arg)) {
+ /* override LM_CLASS mode if given a source file */
+ mode = LM_SOURCE;
}
+ if (mode == LM_SOURCE) {
+ AddOption("--add-modules=ALL-DEFAULT", NULL);
+ *pwhat = SOURCE_LAUNCHER_MAIN_ENTRY;
+ *pargc = argc + 1;
+ *pargv = argv - 1;
+ } else {
if (argc >= 0) {
*pargc = argc;
*pargv = argv;
}
+ }
*pmode = mode;
return JNI_TRUE;
}
< prev index next >