fixing up command line tool

This commit is contained in:
benfry
2012-10-20 23:41:26 +00:00
parent d9d21cc417
commit 33eef596c6
2 changed files with 73 additions and 12 deletions

View File

@@ -25,6 +25,8 @@ import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import javax.swing.JOptionPane;
import processing.app.Base;
import processing.app.Editor;
import processing.core.PApplet;
@@ -35,7 +37,7 @@ public class InstallCommander implements Tool {
public String getMenuTitle() {
return "Install Command Line Tool";
return "Install “processing-java”";
}
@@ -46,23 +48,82 @@ public class InstallCommander implements Tool {
public void run() {
try {
final String primary =
"Install processing-java for all users?";
final String secondary =
"This will install the processing-java program, which is capable " +
"of building and running Java Mode sketches from the command line. " +
"Click “Yes” to install it for all users (an administrator password " +
"is required), or “No” to place the program in your home directory. " +
"If you rename or move Processing.app, " +
"you'll need to reinstall the tool.";
int result =
JOptionPane.showConfirmDialog(editor,
"<html> " +
"<head> <style type=\"text/css\">"+
"b { font: 13pt \"Lucida Grande\" }"+
"p { font: 11pt \"Lucida Grande\"; margin-top: 8px }"+
"</style> </head>" +
"<b>" + primary + "</b>" +
"<p>" + secondary + "</p>",
"Commander",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE);
if (result == JOptionPane.CANCEL_OPTION) {
return;
}
File file = File.createTempFile("processing", "commander");
PrintWriter writer = PApplet.createWriter(file);
writer.println("#!/bin/sh");
writer.println("echo 'bag of awesome'");
String[] jarList = new String[] {
"pde.jar",
"antlr.jar",
"jdt-core.jar",
"jna.jar",
"ant.jar",
"ant-launcher.jar",
"core/library/core.jar"
};
String classPath = PApplet.join(jarList, ":");
String javaRoot = System.getProperty("javaroot");
writer.println("cd \"" + javaRoot + "\" && " +
"/usr/libexec/java_home " +
"--request " +
"--version 1.6 " +
"--exec java " +
"-cp " + classPath +
" processing.mode.java.Commander \"$@\"");
writer.flush();
writer.close();
file.setExecutable(true);
System.out.println(System.getProperty("javaroot"));
if (true) return;
String sourcePath = file.getAbsolutePath();
String targetPath = "/usr/bin/processing-java";
String shellScript = "/bin/mv " + sourcePath + " " + targetPath;
String appleScript =
"do shell script \"" + shellScript + "\" with administrator privileges";
PApplet.exec(new String[] { "osascript", "-e", appleScript });
if (result == JOptionPane.YES_OPTION) {
String targetPath = "/usr/bin/processing-java";
String shellScript = "/bin/mv " + sourcePath + " " + targetPath;
String appleScript =
"do shell script \"" + shellScript + "\" with administrator privileges";
PApplet.exec(new String[] { "osascript", "-e", appleScript });
} else if (result == JOptionPane.NO_OPTION) {
File targetFile = new File(System.getProperty("user.home"), "processing-java");
String targetPath = targetFile.getAbsolutePath();
if (targetFile.exists()) {
Base.showWarning("File Already Exists",
"The processing-java program already exists at:\n" +
targetPath + "\n" +
"Please remove it and try again.", null);
} else {
PApplet.exec(new String[] { "mv", sourcePath, targetPath });
}
}
editor.statusNotice("Finished.");
} catch (IOException e) {
Base.showWarning("Error while installing",
"An error occurred and the tools were not installed.", e);

View File

@@ -322,7 +322,7 @@ public class Commander implements RunnerListener {
static void printCommandLine(PrintStream out) {
out.println("Command line edition for Processing " + Base.VERSION_NAME + " (Java Mode");
out.println("Command line edition for Processing " + Base.VERSION_NAME + " (Java Mode)");
out.println();
out.println("--help Show this help text. Congratulations.");
out.println();