working on command line support, deal with prefs issues, handle error

messages
This commit is contained in:
benfry
2008-09-20 02:26:43 +00:00
parent 3fd0381cfa
commit fa45d375ec
6 changed files with 466 additions and 64 deletions

View File

@@ -86,6 +86,7 @@ public class Base {
static public void main(String args[]) {
/*
commandLine = false;
if (args.length >= 2) {
if (args[0].startsWith("--")) {
@@ -100,7 +101,55 @@ public class Base {
"Java 1.5 or later to run properly.\n" +
"Please visit java.com to upgrade.", null);
}
*/
initPlatform();
// Set the look and feel before opening the window
try {
platform.setLookAndFeel();
} catch (Exception e) {
System.err.println("Non-fatal error while setting the Look & Feel.");
System.err.println("The error message follows, however Processing should run fine.");
System.err.println(e.getMessage());
//e.printStackTrace();
}
// Use native popups so they don't look so crappy on osx
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
// Don't put anything above this line that might make GUI,
// because the platform has to be inited properly first.
// Make sure a full JDK is installed
initRequirements();
// run static initialization that grabs all the prefs
// try {
Preferences.init(null);
// } catch (Exception e) {
// e.printStackTrace();
// }
// Create a location for untitled sketches
untitledFolder = createTempFolder("untitled");
untitledFolder.deleteOnExit();
new Base(args);
}
static protected void setCommandLine() {
commandLine = true;
}
static protected boolean isCommandLine() {
return commandLine;
}
static protected void initPlatform() {
try {
Class platformClass = Class.forName("processing.app.Platform");
if (Base.isMacOS()) {
@@ -114,26 +163,12 @@ public class Base {
"An unknown error occurred while trying to load\n" +
"platform-specific code for your machine.", e);
}
if (!commandLine) {
// Set the look and feel before opening the window
try {
platform.setLookAndFeel();
} catch (Exception e) {
System.err.println("Non-fatal error while setting the Look & Feel.");
System.err.println("The error message follows, however Processing should run fine.");
System.err.println(e.getMessage());
//e.printStackTrace();
}
// Use native popups so they don't look so crappy on osx
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
}
// Don't put anything above this line that might make GUI.
}
static protected void initRequirements() {
try {
/*Class vmClass =*/ Class.forName("com.sun.jdi.VirtualMachine");
Class.forName("com.sun.jdi.VirtualMachine");
} catch (ClassNotFoundException cnfe) {
Base.showPlatforms();
Base.showError("Please install JDK 1.5 or later",
@@ -141,24 +176,6 @@ public class Base {
"to run. Please install JDK 1.5 or later.\n" +
"More information can be found in the reference.", cnfe);
}
// run static initialization that grabs all the prefs
try {
Preferences.init();
} catch (Exception e) {
e.printStackTrace();
}
if (commandLine) {
new Commander(args);
} else {
// Create a location for untitled sketches
untitledFolder = createTempFolder("untitled");
untitledFolder.deleteOnExit();
/*Base base =*/ new Base(args);
}
}

View File

@@ -3,8 +3,7 @@
/*
Part of the Processing project - http://processing.org
Copyright (c) 2004-08 Ben Fry and Casey Reas
Copyright (c) 2001-04 Massachusetts Institute of Technology
Copyright (c) 2008 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
@@ -28,10 +27,11 @@ import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import processing.app.debug.RunnerException;
import processing.core.PApplet;
import processing.core.PConstants;
import processing.app.debug.RunnerException;
public class Commander {
static final String helpArg = "--help";
@@ -42,6 +42,7 @@ public class Commander {
static final String exportAppletArg = "--export-applet";
static final String exportApplicationArg = "--export-application";
static final String platformArg = "--platform=";
static final String preferencesArg = "--preferences=";
static final int HELP = -1;
static final int PREPROCESS = 0;
@@ -50,9 +51,22 @@ public class Commander {
static final int EXPORT_APPLICATION = 3;
static public void main(String[] args) {
// 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 sketchPath = null;
String outputPath = null;
String preferencesPath = null;
//int[] platforms = null;
String[] platforms = null;
int mode = HELP;
@@ -97,7 +111,11 @@ public class Commander {
outputPath = arg.substring(outputArg.length());
}
}
// run static initialization that grabs all the prefs
// (also pass in a prefs path if that was specified)
Preferences.init(preferencesPath);
if (platforms == null) {
platforms = new String[] { "macosx", "windows", "linux" };
}
@@ -119,10 +137,11 @@ public class Commander {
complainAndQuit("Sketch path must point to the main .pde file.");
} else {
Sketch sketch = null;
boolean success = false;
try {
Sketch sketch = new Sketch(null, sketchPath);
boolean success = false;
sketch = new Sketch(null, sketchPath);
if (mode == PREPROCESS) {
success = sketch.preprocess(outputPath) != null;
@@ -161,9 +180,19 @@ public class Commander {
}
}
System.exit(success ? 0 : 1);
} catch (RunnerException re) {
// format the runner exception like emacs
//blah.java:2:10:2:13: Syntax Error: This is a big error message
String filename = sketch.getCode(re.getCodeIndex()).getFileName();
int line = re.getCodeLine();
int column = re.getCodeColumn();
if (column == -1) column = 0;
// TODO if column not specified, should just select the whole line.
System.err.println(filename + ":" +
line + ":" + column + ":" +
line + ":" + column + ":" + " " + re.getMessage());
} catch (IOException e) {
e.printStackTrace();
System.exit(1);

View File

@@ -133,7 +133,7 @@ public class Preferences {
static File preferencesFile;
static protected void init() {
static protected void init(String commandLinePrefs) {
// start by loading the defaults, in case something
// important was deleted from the user prefs
@@ -164,25 +164,37 @@ public class Preferences {
// other things that have to be set explicitly for the defaults
setColor("run.window.bgcolor", SystemColor.control);
// next load user preferences file
preferencesFile = Base.getSettingsFile(PREFS_FILE);
if (!preferencesFile.exists()) {
// create a new preferences file if none exists
// saves the defaults out to the file
save();
} else {
// load the previous preferences file
// Load a prefs file if specified on the command line
if (commandLinePrefs != null) {
try {
load(new FileInputStream(preferencesFile));
load(new FileInputStream(commandLinePrefs));
} catch (Exception ex) {
Base.showError("Error reading preferences",
"Error reading the preferences file. " +
"Please delete (or move)\n" +
preferencesFile.getAbsolutePath() +
" and restart Processing.", ex);
} catch (Exception poe) {
Base.showError("Error",
"Could not read preferences from " +
commandLinePrefs, poe);
}
} else if (!Base.isCommandLine()) {
// next load user preferences file
preferencesFile = Base.getSettingsFile(PREFS_FILE);
if (!preferencesFile.exists()) {
// create a new preferences file if none exists
// saves the defaults out to the file
save();
} else {
// load the previous preferences file
try {
load(new FileInputStream(preferencesFile));
} catch (Exception ex) {
Base.showError("Error reading preferences",
"Error reading the preferences file. " +
"Please delete (or move)\n" +
preferencesFile.getAbsolutePath() +
" and restart Processing.", ex);
}
}
}
}

79
build/cmd/dist.sh Executable file
View File

@@ -0,0 +1,79 @@
#!/bin/sh
REVISION=`head -c 4 ../../todo.txt`
ARCH=`uname -m`
if [ $ARCH != "i686" ]
then
echo At present, the Linux distribution can only be built on i686 \(32-bit\).
exit
fi
./make.sh
echo Creating linux distribution for revision $REVISION...
# remove any old boogers
rm -rf processing
rm -rf processing-*
mkdir processing
cp -r ../shared/lib processing/
cp -r ../shared/libraries processing/
cp -r ../shared/tools processing/
cp ../../app/lib/antlr.jar processing/lib/
cp ../../app/lib/ecj.jar processing/lib/
cp ../../app/lib/jna.jar processing/lib/
cp ../shared/revisions.txt processing/
echo Extracting examples...
unzip -q -d processing/ ../shared/examples.zip
echo Extracting reference...
unzip -q -d processing/ ../shared/reference.zip
# add the libraries folder with source
cp -r ../../net processing/libraries/
cp -r ../../opengl processing/libraries/
cp -r ../../serial processing/libraries/
cp -r ../../pdf processing/libraries/
cp -r ../../dxf processing/libraries/
cp -r ../../xml processing/libraries/
cp -r ../../candy processing/libraries/
# add java (jre) files
tar --extract --file=jre.tgz --ungzip --directory=processing
# grab pde.jar and export from the working dir
cp work/lib/pde.jar processing/lib/
cp work/lib/core.jar processing/lib/
# get platform-specific goodies from the dist dir
install -m 755 dist/processing processing/processing
# make sure notes.txt is unix LFs
# the 2> is because the app is a little chatty
dos2unix processing/revisions.txt 2> /dev/null
dos2unix processing/lib/preferences.txt 2> /dev/null
# remove boogers
find processing -name "*~" -exec rm -f {} ';'
find processing -name ".DS_Store" -exec rm -f {} ';'
find processing -name "._*" -exec rm -f {} ';'
find processing -name "Thumbs.db" -exec rm -f {} ';'
# clean out the cvs entries
find processing -name "CVS" -exec rm -rf {} ';' 2> /dev/null
find processing -name ".cvsignore" -exec rm -rf {} ';'
find processing -name ".svn" -exec rm -rf {} 2> /dev/null ';'
# zip it all up for release
echo Creating tarball and finishing...
P5=processing-$REVISION
mv processing $P5
tar cfz $P5.tgz $P5
# nah, keep the new directory around
#rm -rf $P5
#echo Done.

262
build/cmd/make.sh Executable file
View File

@@ -0,0 +1,262 @@
#!/bin/sh
### -- SETUP WORK DIR -------------------------------------------
if test -d work
then
BUILD_PREPROC=false
else
echo Setting up directories to build for Linux...
BUILD_PREPROC=true
mkdir work
cp -r ../shared/lib work/
cp -r ../shared/libraries work/
cp -r ../shared/tools work/
cp ../../app/lib/antlr.jar work/lib/
cp ../../app/lib/ecj.jar work/lib/
cp ../../app/lib/jna.jar work/lib/
echo Extracting examples...
unzip -q -d work/ ../shared/examples.zip
echo Extracting reference...
unzip -q -d work/ ../shared/reference.zip
cp -r ../../net work/libraries/
cp -r ../../opengl work/libraries/
cp -r ../../serial work/libraries/
cp -r ../../video work/libraries/
cp -r ../../pdf work/libraries/
cp -r ../../dxf work/libraries/
cp -r ../../xml work/libraries/
cp -r ../../candy work/libraries/
install -m 755 dist/processing work/processing
ARCH=`uname -m`
if [ $ARCH = "i686" ]
then
echo Extracting JRE...
tar --extract --file=jre.tgz --ungzip --directory=work
else
# echo This is not my beautiful house.
# if [ $ARCH = "x86_64" ]
# then
# echo You gots the 64.
# fi
echo "
The Java bundle that is included with Processing supports only i686 by default.
To build the code, you will need to install the Java 1.5.0_15 JDK (not a JRE,
and not any other version), and create a symlink to the directory where it is
installed. Create the symlink in the \"work\" directory, and named it \"java\":
ln -s /path/to/jdk1.5.0_15 `pwd`/work/java"
exit
fi
fi
cd ../..
### -- BUILD CORE ----------------------------------------------
echo Building processing.core
cd core
#CLASSPATH="../build/linux/work/java/lib/rt.jar"
#export CLASSPATH
perl preproc.pl
mkdir -p bin
../build/linux/work/java/bin/java \
-cp ../build/linux/work/java/lib/tools.jar \
com.sun.tools.javac.Main \
-d bin -source 1.5 -target 1.5 src/processing/core/*.java
find bin -name "*~" -exec rm -f {} ';'
rm -f ../build/linux/work/lib/core.jar
cd bin && zip -rq ../../build/linux/work/lib/core.jar processing/core/*.class && cd ..
# back to base processing dir
cd ..
### -- BUILD PREPROC ------------------------------------------------
echo Building PDE for JDK 1.5...
cd app
# long path is to avoid requiring java to be in your PATH
echo Building antlr grammar code...
# first build the default java goop
../build/linux/work/java/bin/java \
-cp ../build/linux/work/lib/antlr.jar antlr.Tool \
-o src/antlr/java \
src/antlr/java/java.g
# hack to get around path mess
cp src/antlr/java/JavaTokenTypes.txt src/processing/app/preproc/
# now build the pde stuff that extends the java classes
# this is totally ugly and needs to be fixed
# the problem is that -glib doesn't set the main path properly,
# so it's necessary to cd into the antlr/java folder, otherwise
# the JavaTokenTypes.txt file won't be found
cd src/antlr/java
../../../../build/linux/work/java/bin/java \
-cp ../../../../build/linux/work/lib/antlr.jar antlr.Tool \
-o ../../processing/app/preproc \
-glib java.g \
../../processing/app/preproc/pde.g
cd ../../..
# return to the root of the p5 folder
cd ..
### -- BUILD PDE ------------------------------------------------
cd app
rm -rf ../build/linux/work/classes
mkdir ../build/linux/work/classes
../build/linux/work/java/bin/java \
-cp ../build/linux/work/java/lib/tools.jar \
com.sun.tools.javac.Main \
-source 1.5 -target 1.5 \
-classpath ../build/linux/work/lib/core.jar:../build/linux/work/lib/antlr.jar:../build/linux/work/lib/ecj.jar:../build/linux/work/lib/jna.jar:../build/linux/work/java/lib/tools.jar \
-d ../build/linux/work/classes \
src/processing/app/*.java \
src/processing/app/debug/*.java \
src/processing/app/linux/*.java \
src/processing/app/preproc/*.java \
src/processing/app/syntax/*.java \
src/processing/app/tools/*.java \
src/antlr/*.java \
src/antlr/java/*.java
cd ../build/linux/work/classes
rm -f ../lib/pde.jar
zip -0rq ../lib/pde.jar .
cd ../../../..
### -- BUILD LIBRARIES ------------------------------------------------
cd build/linux
PLATFORM=linux
JAVAC="../build/linux/work/java/bin/java -cp ../build/linux/work/java/lib/tools.jar com.sun.tools.javac.Main -source 1.5 -target 1.5"
CORE=../build/$PLATFORM/work/lib/core.jar
LIBRARIES=../build/$PLATFORM/work/libraries
# move to processing/build
cd ..
# SERIAL LIBRARY
echo Building serial library...
cd ../serial
mkdir -p bin
$JAVAC \
-classpath "library/RXTXcomm.jar:$CORE" \
-d bin src/processing/serial/*.java
rm -f library/serial.jar
find bin -name "*~" -exec rm -f {} ';'
cd bin && zip -r0q ../library/serial.jar processing/serial/*.class && cd ..
mkdir -p $LIBRARIES/serial/library/
cp library/serial.jar $LIBRARIES/serial/library/
# NET LIBRARY
echo Building net library...
cd ../net
mkdir -p bin
$JAVAC \
-classpath "$CORE" \
-d bin src/processing/net/*.java
rm -f library/net.jar
find bin -name "*~" -exec rm -f {} ';'
cd bin && zip -r0q ../library/net.jar processing/net/*.class && cd ..
mkdir -p $LIBRARIES/net/library/
cp library/net.jar $LIBRARIES/net/library/
# OPENGL LIBRARY
echo Building OpenGL library...
cd ../opengl
mkdir -p bin
$JAVAC \
-classpath "library/jogl.jar:$CORE" \
-d bin src/processing/opengl/*.java
rm -f library/opengl.jar
find bin -name "*~" -exec rm -f {} ';'
cd bin && zip -r0q ../library/opengl.jar processing/opengl/*.class && cd ..
mkdir -p $LIBRARIES/opengl/library/
cp library/opengl.jar $LIBRARIES/opengl/library/
# PDF LIBRARY
echo Building PDF library...
cd ../pdf
mkdir -p bin
$JAVAC \
-classpath "library/itext.jar:$CORE" \
-d bin src/processing/pdf/*.java
rm -f library/pdf.jar
find bin -name "*~" -exec rm -f {} ';'
cd bin && zip -r0q ../library/pdf.jar processing/pdf/*.class && cd ..
mkdir -p $LIBRARIES/pdf/library/
cp library/pdf.jar $LIBRARIES/pdf/library/
# DXF LIBRARY
echo Building DXF library...
cd ../dxf
mkdir -p bin
$JAVAC \
-classpath "$CORE" \
-d bin src/processing/dxf/*.java
rm -f library/dxf.jar
find bin -name "*~" -exec rm -f {} ';'
cd bin && zip -r0q ../library/dxf.jar processing/dxf/*.class && cd ..
mkdir -p $LIBRARIES/dxf/library/
cp library/dxf.jar $LIBRARIES/dxf/library/
# XML LIBRARY
echo Building XML library...
cd ../xml
mkdir -p bin
$JAVAC \
-classpath "$CORE" \
-d bin src/processing/xml/*.java
rm -f library/xml.jar
find bin -name "*~" -exec rm -f {} ';'
cd bin && zip -r0q ../library/xml.jar processing/xml/*.class && cd ..
mkdir -p $LIBRARIES/xml/library/
cp library/xml.jar $LIBRARIES/xml/library/
# CANDY SVG LIBRARY
echo Building Candy SVG library...
cd ../candy
mkdir -p bin
$JAVAC \
-classpath "../xml/library/xml.jar:$CORE" \
-d bin src/processing/candy/*.java
rm -f library/candy.jar
find bin -name "*~" -exec rm -f {} ';'
cd bin && zip -r0q ../library/candy.jar processing/candy/*.class && cd ..
mkdir -p $LIBRARIES/candy/library/
cp library/candy.jar $LIBRARIES/candy/library/
echo
echo Done.

3
build/cmd/run.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/sh
cd work && ./processing && cd ..