Skip to content

Commit f5dd2de

Browse files
author
mgricken
committed
Java Language Level Converter command line interface.
git-svn-id: file:///tmp/test-svn/trunk@5187 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent bdd7aa6 commit f5dd2de

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

drjava/lib/javalanglevels-base.jar

238 Bytes
Binary file not shown.

drjava/src/edu/rice/cs/drjava/DrJava.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public class DrJava {
145145
private static volatile File _propertiesFile = DEFAULT_PROPERTIES_FILE;
146146

147147
/** Configuration object with all customized and default values. Initialized from _propertiesFile. */
148-
private static volatile FileConfiguration _config = _initConfig();
148+
private static volatile FileConfiguration _config;
149149

150150
/** Returns the properties file used by the configuration object. */
151151
public static File getPropertiesFile() { return _propertiesFile; }
@@ -403,7 +403,6 @@ static boolean handleCommandLineArgs(String[] args) {
403403
}
404404
// arg.length > i+1 implying args list incudes config file name and perhaps files to open
405405
setPropertiesFile(args[argIndex++]);
406-
_config = _initConfig(); // read specified .djrava file into _config
407406
}
408407

409408
else if (arg.startsWith("-X") || arg.startsWith("-D")) {
@@ -420,6 +419,13 @@ else if (arg.equals("-delete-after-restart")) {
420419
deleteAfterRestart.delete();
421420
}
422421

422+
else if (arg.equals("-jll")) {
423+
String[] argsForJLL = new String[args.length-argIndex];
424+
System.arraycopy(args, argIndex, argsForJLL, 0, argsForJLL.length);
425+
edu.rice.cs.javalanglevels.LanguageLevelConverter.main(argsForJLL);
426+
System.exit(0);
427+
}
428+
423429
else if (arg.equals("-help") || arg.equals("-?")) {
424430
displayUsage();
425431
return false;
@@ -431,6 +437,8 @@ else if (arg.equals("-help") || arg.equals("-?")) {
431437
}
432438
}
433439

440+
_config = _initConfig(); // read specified .djrava file into _config
441+
434442
if ((!("".equals(getConfig().getSetting(MASTER_JVM_XMX)))) &&
435443
(!(edu.rice.cs.drjava.config.OptionConstants.heapSizeChoices.get(0).equals(getConfig().getSetting(MASTER_JVM_XMX))))) {
436444
_jvmArgs.add("-Xmx" + getConfig().getSetting(MASTER_JVM_XMX).trim() + "M");
@@ -472,6 +480,7 @@ static void displayUsage() {
472480
System.out.println(" -help | -? print this help message");
473481
System.out.println(" -X<jvmOption> specify a JVM configuration option for the master DrJava JVM");
474482
System.out.println(" -D<name>[=<value>] set a Java property for the master DrJava JVM");
483+
System.out.println(" -jll [ARGS] invoke the Java Language Level converter, specify files in ARGS");
475484
}
476485

477486
/** Switches the config object to use a custom config file. Ensures that Java source files aren't

javalanglevels/src/edu/rice/cs/javalanglevels/LanguageLevelConverter.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.io.*;
4646
import edu.rice.cs.plt.reflect.JavaVersion;
4747
import edu.rice.cs.plt.iter.IterUtil;
48+
import edu.rice.cs.plt.io.IOUtil;
4849

4950
/** This class represents the mechanism by which we convert a language level file to a .java file of the same name by
5051
* first visiting the file to error-check it, and then augment the file. This class is tested at the top level in the
@@ -444,13 +445,23 @@ public static boolean versionIs15(JavaVersion version) {
444445
/**Do a conversion from the command line, to allow quick testing*/
445446
public static void main(String[] args) {
446447
LanguageLevelConverter llc = new LanguageLevelConverter();
448+
449+
if (args.length==0) {
450+
System.out.println("Java Language Level Converter");
451+
System.out.println("Please pass file names (*.dj0, *.dj1, *.dj2) as arguments.");
452+
System.out.println("Note: The converter will use Java's classpath to resolve classes.");
453+
System.out.println(" If classes are not found, use java -cp <classpath> to set the classpath.");
454+
return;
455+
}
456+
447457
File[] files = new File[args.length];
448458
for (int i = 0; i < args.length; i++) {
449459
files[i] = new File(args[i]);
450460
}
451461

452462
Pair<LinkedList<JExprParseException>, LinkedList<Pair<String, JExpressionIF>>> result =
453-
llc.convert(files, new Options(JavaVersion.JAVA_5, IterUtil.<File>empty()));
463+
llc.convert(files, new Options(JavaVersion.JAVA_5,
464+
IOUtil.parsePath(System.getProperty("java.class.path", ""))));
454465
System.out.println(result.getFirst().size() + result.getSecond().size() + " errors.");
455466
for(JExprParseException p : result.getFirst()) {
456467
System.out.println(p);

0 commit comments

Comments
 (0)