command line starting to work again

This commit is contained in:
benfry
2012-07-24 10:45:08 +00:00
parent 80c873bc7f
commit 84a2b3f7c7
10 changed files with 442 additions and 384 deletions

View File

@@ -3,7 +3,7 @@
/*
Part of the Processing project - http://processing.org
Copyright (c) 2008-10 Ben Fry and Casey Reas
Copyright (c) 2008-12 Ben Fry and Casey Reas
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -22,20 +22,18 @@
package processing.mode.java;
/*
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import processing.app.Base;
import processing.app.Library;
import processing.app.Preferences;
import processing.app.SketchException;
import processing.app.RunnerListener;
import processing.app.Sketch;
import processing.core.PApplet;
import processing.mode.java.runner.*;
*/
/**
@@ -52,16 +50,15 @@ import processing.mode.java.runner.*;
* --run Preprocess, compile, and run a sketch.
* --present Preprocess, compile, and run a sketch full screen.
*
* --export-applet Export an applet.
* --export-application Export an application.
* --export Export an application.
* --platform Specify the platform (export to application only).
* Should be one of 'windows', 'macosx', or 'linux'.
* --bits Must be specified if libraries are used that are
* 32- or 64-bit specific such as the OpenGL library.
* Otherwise specify 0 or leave it out.
*
* --preferences=<file> Specify a preferences file to use. Required if the
* sketch uses libraries found in your sketchbook folder.
// *
// * --preferences=<file> Specify a preferences file to use. Required if the
// * sketch uses libraries found in your sketchbook folder.
* </PRE>
*
* To build the command line version, first build for your platform,
@@ -70,7 +67,6 @@ import processing.mode.java.runner.*;
*
* @author fry
*/
/*
public class Commander implements RunnerListener {
static final String helpArg = "--help";
static final String preprocArg = "--preprocess";
@@ -78,8 +74,9 @@ public class Commander implements RunnerListener {
static final String runArg = "--run";
static final String presentArg = "--present";
static final String sketchArg = "--sketch=";
static final String forceArg = "--force";
static final String outputArg = "--output=";
static final String exportAppletArg = "--export-applet";
// static final String exportAppletArg = "--export-applet";
static final String exportApplicationArg = "--export-application";
static final String platformArg = "--platform=";
static final String bitsArg = "--bits=";
@@ -90,34 +87,46 @@ public class Commander implements RunnerListener {
static final int BUILD = 1;
static final int RUN = 2;
static final int PRESENT = 3;
static final int EXPORT_APPLET = 4;
// static final int EXPORT_APPLET = 4;
static final int EXPORT_APPLICATION = 5;
Sketch sketch;
static public void main(String[] args) {
if (args == null || args.length == 0) {
// System.out.println(System.getProperty("user.dir"));
args = new String[] {
"--export-application",
"--platform=windows",
"--bits=64",
"--sketch=/Users/fry/coconut/processing/java/examples/Basics/Lights/Directional",
"--output=/Users/fry/Desktop/test-build"
};
}
// Do this early so that error messages go to the console
Base.setCommandLine();
// init the platform so that prefs and other native code is ready to go
Base.initPlatform();
// make sure a full JDK is installed
Base.initRequirements();
// run static initialization that grabs all the prefs
//Preferences.init(null);
// launch command line handler
new Commander(args);
}
public Commander(String[] args) {
String sketchFolder = null;
String sketchPath = null;
File sketchFolder = null;
String pdePath = null; // path to the .pde file
String outputPath = null;
String preferencesPath = null;
int platformIndex = PApplet.platform; // default to this platform
File outputFolder = null;
boolean force = false; // replace that no good output folder
// String preferencesPath = null;
int platform = PApplet.platform; // default to this platform
int platformBits = 0;
int mode = HELP;
int task = HELP;
for (String arg : args) {
if (arg.length() == 0) {
@@ -126,75 +135,103 @@ public class Commander implements RunnerListener {
} else if (arg.equals(helpArg)) {
// mode already set to HELP
} else if (arg.equals(preprocArg)) {
task = PREPROCESS;
} else if (arg.equals(buildArg)) {
mode = BUILD;
task = BUILD;
} else if (arg.equals(runArg)) {
mode = RUN;
task = RUN;
} else if (arg.equals(presentArg)) {
mode = PRESENT;
task = PRESENT;
} else if (arg.equals(preprocArg)) {
mode = PREPROCESS;
} else if (arg.equals(exportAppletArg)) {
mode = EXPORT_APPLET;
// } else if (arg.equals(exportAppletArg)) {
// task = EXPORT_APPLET;
} else if (arg.equals(exportApplicationArg)) {
mode = EXPORT_APPLICATION;
task = EXPORT_APPLICATION;
} else if (arg.startsWith(platformArg)) {
String platformStr = arg.substring(platformArg.length());
platformIndex = Base.getPlatformIndex(platformStr);
if (platformIndex == -1) {
platform = Base.getPlatformIndex(platformStr);
if (platform == -1) {
complainAndQuit(platformStr + " should instead be " +
"'windows', 'macosx', or 'linux'.");
}
} else if (arg.startsWith(bitsArg)) {
String bitsStr = arg.substring(bitsArg.length());
if (bitsStr.equals("32")) {
platformBits = 32;
} else if (bitsStr.equals("64")) {
platformBits = 64;
} else {
complainAndQuit("Bits should be either 32 or 64, not " + bitsStr);
}
} else if (arg.startsWith(sketchArg)) {
sketchFolder = arg.substring(sketchArg.length());
File sketchy = new File(sketchFolder);
File pdeFile = new File(sketchy, sketchy.getName() + ".pde");
sketchPath = arg.substring(sketchArg.length());
sketchFolder = new File(sketchPath);
if (!sketchFolder.exists()) {
complainAndQuit(sketchFolder + " does not exist.");
}
File pdeFile = new File(sketchFolder, sketchFolder.getName() + ".pde");
if (!pdeFile.exists()) {
complainAndQuit("Not a valid sketch folder. " + pdeFile + " does not exist.");
}
pdePath = pdeFile.getAbsolutePath();
} else if (arg.startsWith(preferencesArg)) {
preferencesPath = arg.substring(preferencesArg.length());
// } else if (arg.startsWith(preferencesArg)) {
// preferencesPath = arg.substring(preferencesArg.length());
} else if (arg.startsWith(outputArg)) {
outputPath = arg.substring(outputArg.length());
} else if (arg.equals(forceArg)) {
force = true;
} else {
complainAndQuit("I don't know anything about " + arg + ".");
}
}
if ((outputPath == null) &&
(mode == PREPROCESS || mode == BUILD ||
mode == RUN || mode == PRESENT)) {
complainAndQuit("An output path must be specified when using " +
preprocArg + ", " + buildArg + ", " +
runArg + ", or " + presentArg + ".");
}
if (mode == HELP) {
// if ((outputPath == null) &&
// (task == PREPROCESS || task == BUILD ||
// task == RUN || task == PRESENT)) {
// complainAndQuit("An output path must be specified when using " +
// preprocArg + ", " + buildArg + ", " +
// runArg + ", or " + presentArg + ".");
// }
if (task == HELP) {
printCommandLine(System.out);
System.exit(0);
}
// --present --platform=windows "--sketch=/Applications/Processing 0148/examples/Basics/Arrays/Array" --output=test-build
File outputFolder = new File(outputPath);
if (!outputFolder.exists()) {
if (!outputFolder.mkdirs()) {
complainAndQuit("Could not create the output folder.");
}
if (outputPath == null) {
complainAndQuit("An output path must be specified.");
}
// run static initialization that grabs all the prefs
// (also pass in a prefs path if that was specified)
Preferences.init(preferencesPath);
outputFolder = new File(outputPath);
if (outputFolder.exists() && !force) {
complainAndQuit("The output folder already exists. Use --force to overwrite it.");
}
if (sketchFolder == null) {
if (!outputFolder.mkdirs()) {
complainAndQuit("Could not create the output folder.");
}
// // run static initialization that grabs all the prefs
// // (also pass in a prefs path if that was specified)
// if (preferencesPath != null) {
// Preferences.init(preferencesPath);
// }
Preferences.init(null);
Base.locateSketchbookFolder();
if (sketchPath == null) {
complainAndQuit("No sketch path specified.");
} else if (outputPath.equals(pdePath)) {
@@ -207,42 +244,57 @@ public class Commander implements RunnerListener {
//Sketch sketch = null;
boolean success = false;
JavaMode javaMode =
new JavaMode(null, Base.getContentFile("modes/java"));
try {
sketch = new Sketch(null, pdePath);
if (mode == PREPROCESS) {
sketch = new Sketch(pdePath, javaMode);
/*
if (task == PREPROCESS) {
JavaBuild build = new JavaBuild(sketch);
build.preprocess(new File(sketchFolder), true);
success = sketch.preprocess(new File(outputPath)) != null;
} else if (mode == BUILD) {
success = sketch.build(outputPath) != null;
} else*/ if (task == BUILD) {
JavaBuild build = new JavaBuild(sketch);
String mainClassName =
build.build(new File(sketchPath), outputFolder, true);
success = mainClassName != null;
} else if (mode == RUN || mode == PRESENT) {
String className = sketch.build(outputPath);
} else if (task == RUN || task == PRESENT) {
JavaBuild build = new JavaBuild(sketch);
String className = build.build(sketchFolder, outputFolder, true);
if (className != null) {
success = true;
Runner runner = new Runner(this, sketch);
runner.launch(className, mode == PRESENT);
Runner runner = new Runner(build, this);
runner.launch(task == PRESENT);
} else {
success = false;
}
} else if (mode == EXPORT_APPLET) {
if (outputPath != null) {
success = sketch.exportApplet(outputPath);
// } else if (task == EXPORT_APPLET) {
// if (outputPath != null) {
// success = sketch.exportApplet(outputPath);
// } else {
// String target = sketchFolder + File.separatorChar + "applet";
// success = sketch.exportApplet(target);
// }
} else if (task == EXPORT_APPLICATION) {
if (outputPath == null) {
javaMode.handleExportApplication(sketch);
} else {
String target = sketchFolder + File.separatorChar + "applet";
success = sketch.exportApplet(target);
}
} else if (mode == EXPORT_APPLICATION) {
if (outputPath != null) {
success = sketch.exportApplication(outputPath, platformIndex, platformBits);
} else {
//String sketchFolder =
// pdePath.substring(0, pdePath.lastIndexOf(File.separatorChar));
outputPath =
sketchFolder + File.separatorChar +
"application." + Base.getPlatformName(platformIndex);
success = sketch.exportApplication(outputPath, platformIndex, platformBits);
JavaBuild build = new JavaBuild(sketch);
build.build(true);
if (build != null) {
// if (platformBits == 0) {
// platformBits = Base.getNativeBits();
// }
if (platformBits == 0 &&
Library.hasMultipleArch(platform, build.getImportedLibraries())) {
complainAndQuit("This sketch can be exported for 32- or 64-bit, please specify one.");
}
success = build.exportApplication(outputFolder, platform, platformBits);
}
}
}
System.exit(success ? 0 : 1);
@@ -257,10 +309,12 @@ public class Commander implements RunnerListener {
}
}
public void statusNotice(String message) {
System.err.println(message);
}
public void statusError(String message) {
System.err.println(message);
}
@@ -294,29 +348,51 @@ public class Commander implements RunnerListener {
static void printCommandLine(PrintStream out) {
out.println("Processing " + Base.VERSION_NAME + " rocks the console.");
out.println("Standard (Java) mode command line edition for Processing " + Base.VERSION_NAME);
out.println();
out.println("--help Show this help text.");
out.println("--help Show this help text. Congratulations.");
out.println();
out.println("--sketch=<name> Specify the sketch folder (required)");
out.println("--output=<name> Specify the output folder (required and");
out.println(" cannot be the same as the sketch folder.)");
out.println("--force The sketch will not build if the output");
out.println(" folder already exists, because the contents");
out.println(" will be replaced. This option overrides.");
out.println();
out.println("--preprocess Preprocess a sketch into .java files.");
out.println("--build Preprocess and compile a sketch into .class files.");
out.println("--run Preprocess, compile, and run a sketch.");
out.println("--present Preprocess, compile, and run a sketch full screen.");
out.println();
out.println("--export-applet Export an applet.");
out.println("--export-application Export an application.");
out.println("--export Export an application.");
out.println("--platform Specify the platform (export to application only).");
out.println(" Should be one of 'windows', 'macosx', or 'linux'.");
out.println("--bits Must be specified if libraries are used that are");
out.println(" 32- or 64-bit specific such as the OpenGL library.");
out.println(" Otherwise specify 0 or leave it out.");
out.println();
out.println("--preferences=<file> Specify a preferences file to use. Required if the");
out.println(" sketch uses libraries found in your sketchbook folder.");
out.println(" Otherwise specify 0 or leave it out.");
// out.println();
// out.println("--preferences=<file> Specify a preferences file to use. Required if the");
// out.println(" sketch uses libraries found in your sketchbook folder.");
}
}
*/
@Override
public void startIndeterminate() {
}
@Override
public void stopIndeterminate() {
}
@Override
public void statusHalt() {
}
@Override
public boolean isHalted() {
return false;
}
}

View File

@@ -1115,23 +1115,23 @@ public class JavaBuild {
/**
* Export to application without GUI.
* Export to application without GUI. Also called by the Commander.
*/
private boolean exportApplication(File destFolder,
int exportPlatform,
int exportBits) throws IOException, SketchException {
protected boolean exportApplication(File destFolder,
int exportPlatform,
int exportBits) throws IOException, SketchException {
// TODO this should probably be a dialog box instead of a warning
// on the terminal. And the message should be written better than this.
// http://code.google.com/p/processing/issues/detail?id=884
for (Library library : importedLibraries) {
if (!library.supportsArch(exportPlatform, exportBits)) {
String pn = PConstants.platformNames[exportPlatform];
System.err.println("The application." + pn + exportBits +
" folder will not be created because no " +
exportBits + "-bit version of " +
library.getName() +
" is available for " + pn);
return true; // don't cancel export for this, just move along
Base.showWarning("Quibbles 'n Bits",
"The application." + pn + exportBits +
" folder will not be created\n" +
"because no " + exportBits + "-bit version of " +
library.getName() + " is available for " + pn, null);
return true; // don't cancel all exports for this, just move along
}
}

View File

@@ -60,32 +60,6 @@ public class JavaMode extends Mode {
Base.showError("Problem loading keywords",
"Could not load keywords.txt, please re-install Processing.", e);
}
/*
item = newJMenuItem("Export", 'E');
if (editor != null) {
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
editor.handleExport();
}
});
} else {
item.setEnabled(false);
}
fileMenu.add(item);
item = newJMenuItemShift("Export Application", 'E');
if (editor != null) {
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
editor.handleExportApplication();
}
});
} else {
item.setEnabled(false);
}
fileMenu.add(item);
*/
}