fix for multiple jars/code folder problems and huge jars; also remove

oro.jar
This commit is contained in:
benfry
2008-05-29 22:10:10 +00:00
parent 5b2b931bf0
commit 3dd1cefafe
9 changed files with 124 additions and 180 deletions
-1
View File
@@ -6,6 +6,5 @@
<classpathentry kind="lib" path="build/shared/lib/antlr.jar"/>
<classpathentry kind="lib" path="build/shared/lib/registry.jar"/>
<classpathentry kind="lib" path="build/shared/lib/apple.jar"/>
<classpathentry kind="lib" path="build/shared/lib/oro.jar"/>
<classpathentry kind="output" path="app/bin"/>
</classpath>
+5 -2
View File
@@ -1146,7 +1146,7 @@ public class Editor extends JFrame {
runtime = new Runner(Editor.this, presenting);
// Cannot use invokeLater() here, otherwise it gets
// placed on the event thread--bad idea all around.
// placed on the event thread and causes a hang--bad idea all around.
Thread t = new Thread(new Runnable() {
public void run() {
runtime.launch();
@@ -1628,7 +1628,8 @@ public class Editor extends JFrame {
if (!handleExportCheckModified()) return;
toolbar.activate(EditorToolbar.EXPORT);
SwingUtilities.invokeLater(new Runnable() {
//SwingUtilities.invokeLater(new Runnable() {
Thread t = new Thread(new Runnable() {
public void run() {
try {
boolean success = sketch.exportApplet();
@@ -1645,6 +1646,7 @@ public class Editor extends JFrame {
//toolbar.clear();
toolbar.deactivate(EditorToolbar.EXPORT);
}});
t.start();
}
@@ -1652,6 +1654,7 @@ public class Editor extends JFrame {
if (!handleExportCheckModified()) return;
toolbar.activate(EditorToolbar.EXPORT);
//SwingUtilities.invokeLater(new Runnable() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
message("Exporting application...");
+69 -118
View File
@@ -35,7 +35,7 @@ import java.util.zip.*;
import javax.swing.*;
import com.oroinc.text.regex.*;
//import com.oroinc.text.regex.*;
/**
@@ -1348,7 +1348,7 @@ public class Sketch {
/**
* Build all the code for this sketch.
*
* In an advanced program, the returned classname could be different,
* In an advanced program, the returned class name could be different,
* which is why the className is set based on the return value.
* A compilation error will burp up a RunnerException.
*
@@ -1532,28 +1532,15 @@ public class Sketch {
// while this seems to store line and column internally,
// there doesn't seem to be a method to grab it..
// so instead it's done using a regexp
PatternMatcher matcher = new Perl5Matcher();
PatternCompiler compiler = new Perl5Compiler();
// line 3:1: unexpected char: 0xA0
String mess = "^line (\\d+):(\\d+):\\s";
Pattern pattern = null;
try {
pattern = compiler.compile(mess);
} catch (MalformedPatternException e) {
Base.showWarning("Internal Problem",
"An internal error occurred while trying\n" +
"to compile the sketch. Please report\n" +
"this online at http://processing.org/bugs", e);
}
// TODO not tested since removing ORO matcher.. ^ could be a problem
String mess = "^line (\\d+):(\\d+):\\s";
PatternMatcherInput input =
new PatternMatcherInput(tsre.toString());
if (matcher.contains(input, pattern)) {
MatchResult result = matcher.getMatch();
String[] matches = PApplet.match(tsre.toString(), mess);
if (matches != null) {
int errorLine = Integer.parseInt(matches[0]) - 1;
int errorColumn = Integer.parseInt(matches[1]);
int errorLine = Integer.parseInt(result.group(1).toString()) - 1;
int errorColumn = Integer.parseInt(result.group(2).toString());
int errorFile = 0;
for (int i = 1; i < codeCount; i++) {
if ((code[i].flavor == PDE) &&
@@ -1669,51 +1656,25 @@ public class Sketch {
/**
* Initiate export to applet.
* <PRE>
* +-------------------------------------------------------+
* + +
* + Export to: [ Applet (for the web) + ] [ OK ] +
* + +
* + > Advanced +
* + +
* + - - - - - - - - - - - - - - - - - - - - - - - - - - - +
* + Version: [ Java 1.1 + ] +
* + +
* + Recommended version of Java when exporting applets. +
* + - - - - - - - - - - - - - - - - - - - - - - - - - - - +
* + Version: [ Java 1.3 + ] +
* + +
* + Java 1.3 is not recommended for applets, +
* + unless you are using features that require it. +
* + Using a version of Java other than 1.1 will require +
* + your Windows users to install the Java Plug-In, +
* + and your Macintosh users to be running OS X. +
* + - - - - - - - - - - - - - - - - - - - - - - - - - - - +
* + Version: [ Java 1.4 + ] +
* + +
* + identical message as 1.3 above... +
* + +
* +-------------------------------------------------------+
* </PRE>
* Handle export to applet.
*/
public boolean exportApplet() throws Exception {
// make sure the user didn't hide the sketch folder
// Make sure the user didn't hide the sketch folder
ensureExistence();
// fix for issue posted on the board. make sure that the code
// is reloaded when exporting and an external editor is being used.
// Reload the code when an external editor is being used
if (Preferences.getBoolean("editor.external")) {
// nuke previous files and settings
load();
}
zipFileContents = new Hashtable();
// nuke the old applet folder because it can cause trouble
File appletFolder = new File(folder, "applet");
// Nuke the old applet folder because it can cause trouble
Base.removeDir(appletFolder);
// Create a fresh applet folder (needed before preproc is run below)
appletFolder.mkdirs();
zipFileContents = new Hashtable();
// build the sketch
String foundName = build(appletFolder.getPath(), name);
@@ -1721,7 +1682,7 @@ public class Sketch {
// (already reported) error during export, exit this function
if (foundName == null) return false;
// if name != exportSketchName, then that's weirdness
// If name != exportSketchName, then that's weirdness
// BUG unfortunately, that can also be a bug in the preproc :(
if (!name.equals(foundName)) {
Base.showWarning("Error during export",
@@ -1734,37 +1695,23 @@ public class Sketch {
int high = PApplet.DEFAULT_HEIGHT;
String renderer = "";
PatternMatcher matcher = new Perl5Matcher();
PatternCompiler compiler = new Perl5Compiler();
// This matches against any uses of the size() function, whether numbers
// or variables or whatever. This way, no warning is shown if size() isn't
// actually used in the applet, which is the case especially for beginners
// that are cutting/pasting from the reference.
String sizeRegex =
"[\\s\\;^]size\\s*\\(\\s*(\\S+)\\s*,\\s*(\\d+),?\\s*([^\\)]*)\\s*\\)";
// this matches against any uses of the size() function,
// whether they contain numbers of variables or whatever.
// this way, no warning is shown if size() isn't actually
// used in the applet, which is the case especially for
// beginners that are cutting/pasting from the reference.
// modified for 83 to match size(XXX, ddd so that it'll
// properly handle size(200, 200) and size(200, 200, P3D)
String sizing =
// match width, height and renderer string as well
"[\\s\\;]size\\s*\\(\\s*(\\S+)\\s*,\\s*(\\d+),?\\s*([^\\)]*)\\s*\\)";
// match just the width and height
//"[\\s\\;]size\\s*\\(\\s*(\\S+)\\s*,\\s*(\\d+)(.*)\\)";
Pattern pattern = compiler.compile(sizing);
// adds a space at the beginning, in case size() is the very
// first thing in the program (very common), since the regexp
// needs to check for things in front of it.
PatternMatcherInput input =
new PatternMatcherInput(" " + scrubComments(code[0].program));
if (matcher.contains(input, pattern)) {
MatchResult result = matcher.getMatch();
String scrubbed = scrubComments(code[0].program);
String[] matches = PApplet.match(scrubbed, sizeRegex);
if (matches != null) {
try {
wide = Integer.parseInt(result.group(1).toString());
high = Integer.parseInt(result.group(2).toString());
wide = Integer.parseInt(matches[0]);
high = Integer.parseInt(matches[1]);
// Adding back the trim() for 0136 to handle Bug #769
renderer = result.group(3).toString().trim();
if (matches.length == 3) renderer = matches[2].trim();
} catch (NumberFormatException e) {
// found a reference to size, but it didn't
@@ -1778,10 +1725,10 @@ public class Sketch {
}
} // else no size() command found
// originally tried to grab this with a regexp matcher,
// but it wouldn't span over multiple lines for the match.
// this could prolly be forced, but since that's the case
// better just to parse by hand.
// Grab the Javadoc-style description from the main code.
// Originally tried to grab this with a regexp matcher, but it wouldn't
// span over multiple lines for the match. This could prolly be forced,
// but since that's the case better just to parse by hand.
StringBuffer dbuffer = new StringBuffer();
String lines[] = PApplet.split(code[0].program, '\n');
for (int i = 0; i < lines.length; i++) {
@@ -1810,71 +1757,73 @@ public class Sketch {
}
String description = dbuffer.toString();
// Add links to all the code
StringBuffer sources = new StringBuffer();
for (int i = 0; i < codeCount; i++) {
sources.append("<a href=\"" + code[i].file.getName() + "\">" +
code[i].name + "</a> ");
}
//
// determine whether to use one jar file or several
StringBuffer archives = new StringBuffer();
boolean separateJar =
Preferences.getBoolean("export.applet.separate_jar_files");
if (renderer.equals("OPENGL")) {
separateJar = true;
// Copy the source files to the target, since we like
// to encourage people to share their code
for (int i = 0; i < codeCount; i++) {
try {
File exportedSource = new File(appletFolder, code[i].file.getName());
Base.copyFile(code[i].file, exportedSource);
} catch (IOException e) {
e.printStackTrace(); // ho hum, just move on...
}
}
// copy the loading gif to the applet
// Use separate jarfiles whenever a library or code folder is in use.
boolean separateJar =
Preferences.getBoolean("export.applet.separate_jar_files") ||
codeFolder.exists() ||
(libraryPath.length() != 0);
// Copy the loading gif to the applet
String LOADING_IMAGE = "loading.gif";
// Check if the user already has their own loader image
File loadingImage = new File(folder, LOADING_IMAGE);
if (!loadingImage.exists()) {
loadingImage = new File("lib", LOADING_IMAGE);
}
Base.copyFile(loadingImage, new File(appletFolder, LOADING_IMAGE));
// copy the source files to the target, since we like
// to encourage people to share their code
for (int i = 0; i < codeCount; i++) {
try {
Base.copyFile(code[i].file,
new File(appletFolder, code[i].file.getName()));
} catch (IOException e) {
e.printStackTrace();
}
}
// create new .jar file
// Create new .jar file
FileOutputStream zipOutputFile =
new FileOutputStream(new File(appletFolder, name + ".jar"));
ZipOutputStream zos = new ZipOutputStream(zipOutputFile);
ZipEntry entry;
StringBuffer archives = new StringBuffer();
archives.append(name + ".jar");
// add the manifest file
// Add the manifest file
addManifest(zos);
// add the contents of the code folder to the jar
// unpacks all jar files, unless multi jar files selected in prefs
if (codeFolder.exists()) {
String includes = Compiler.contentsToClassPath(codeFolder);
if (separateJar) {
String codeList[] = PApplet.split(includes, File.separatorChar);
String cp = "";
for (int i = 0; i < codeList.length; i++) {
if (codeList[i].toLowerCase().endsWith(".jar") ||
codeList[i].toLowerCase().endsWith(".zip")) {
System.out.println(includes);
String codeList[] = PApplet.split(includes, File.separatorChar);
String cp = "";
for (int i = 0; i < codeList.length; i++) {
if (codeList[i].toLowerCase().endsWith(".jar") ||
codeList[i].toLowerCase().endsWith(".zip")) {
if (separateJar) {
File exportFile = new File(codeFolder, codeList[i]);
String exportFilename = exportFile.getName();
Base.copyFile(exportFile, new File(appletFolder, exportFilename));
} else {
cp += codeList[i] + File.separatorChar;
packClassPathIntoZipFile(cp, zos);
cp += codeList[i] + File.pathSeparatorChar;
//packClassPathIntoZipFile(cp, zos);
}
}
} else {
packClassPathIntoZipFile(includes, zos);
}
if (!separateJar) {
packClassPathIntoZipFile(cp, zos);
}
}
@@ -1943,7 +1892,6 @@ public class Sketch {
if (dataFolder.exists()) {
String dataFiles[] = Base.listFiles(dataFolder, false);
int offset = folder.getAbsolutePath().length() + 1;
//int offset = dataFolder.getAbsolutePath().length() + 1;
for (int i = 0; i < dataFiles.length; i++) {
if (PApplet.platform == PApplet.WINDOWS) {
dataFiles[i] = dataFiles[i].replace('\\', '/');
@@ -2607,6 +2555,9 @@ public class Sketch {
ZipOutputStream zos)
throws IOException {
String pieces[] = PApplet.split(path, File.pathSeparatorChar);
new Exception().printStackTrace();
PApplet.println(pieces);
PApplet.println();
for (int i = 0; i < pieces.length; i++) {
if (pieces[i].length() == 0) continue;
+6 -6
View File
@@ -414,16 +414,16 @@ public class Compiler implements MessageConsumer {
/**
* Return the path for a folder, with appended paths to
* any .jar or .zip files inside that folder.
*
* Given a folder, return a list of absolute paths to all jar or zip files
* inside that folder, separated by pathSeparatorChar.
*
* This will prepend a colon (or whatever the path separator is)
* so that it can be directly appended to another path string.
*
* This function doesn't bother checking to see if there are any .class
* files in the folder or within a subfolder.
*
* As of 0136, this will no longer add the root folder as well.
*
* This function doesn't bother checking to see if there are any .class
* files in the folder or within a subfolder.
*/
static public String contentsToClassPath(File folder) {
if (folder == null) return "";
@@ -34,9 +34,6 @@ import java.io.*;
import antlr.*;
import antlr.collections.*;
//import antlr.collections.impl.*;
import com.oroinc.text.regex.*;
/**
@@ -247,31 +244,18 @@ public class PdePreprocessor {
// if this guy has his own imports, need to remove them
// just in case it's not an advanced mode sketch
PatternMatcher matcher = new Perl5Matcher();
PatternCompiler compiler = new Perl5Compiler();
String mess = "^\\s*(import\\s+)(\\S+)(\\s*;)";
String importRegexp = "[\\s^](import\\s+)(\\S+)(\\s*;)";
java.util.Vector imports = new java.util.Vector();
Pattern pattern = null;
try {
pattern = compiler.compile(mess);
} catch (MalformedPatternException e) {
e.printStackTrace();
return null;
}
do {
PatternMatcherInput input = new PatternMatcherInput(program);
if (!matcher.contains(input, pattern)) break;
String[] pieces = PApplet.match(program, importRegexp);
// Stop the loop if we've removed all the importy lines
if (pieces == null) break;
MatchResult result = matcher.getMatch();
String piece1 = result.group(1).toString();
String piece2 = result.group(2).toString(); // the package name
String piece3 = result.group(3).toString();
String piece = piece1 + piece2 + piece3;
int len = piece.length();
String piece = pieces[0] + pieces[1] + pieces[2];
int len = piece.length(); // how much to trim out
imports.add(piece2);
imports.add(pieces[1]); // the package name
int idx = program.indexOf(piece);
// just remove altogether?
program = program.substring(0, idx) + program.substring(idx + len);
+1 -1
View File
@@ -128,7 +128,7 @@ cd ..
cd app
CLASSPATH="../build/linux/work/lib/core.jar:../build/linux/work/lib/apple.jar:../build/linux/work/lib/antlr.jar:../build/linux/work/lib/oro.jar:../build/linux/work/lib/registry.jar:../build/linux/work/lib/tools.jar:../build/linux/work/java/lib/rt.jar"
CLASSPATH="../build/linux/work/lib/core.jar:../build/linux/work/lib/apple.jar:../build/linux/work/lib/antlr.jar:../build/linux/work/lib/registry.jar:../build/linux/work/lib/tools.jar:../build/linux/work/java/lib/rt.jar"
../build/linux/work/jikes -target 1.3 +D -classpath $CLASSPATH:../build/linux/work/classes -d ../build/linux/work/classes src/processing/app/*.java src/processing/app/debug/*.java src/processing/app/preproc/*.java src/processing/app/syntax/*.java src/processing/app/tools/*.java src/antlr/*.java src/antlr/java/*.java
+1 -11
View File
@@ -126,23 +126,13 @@ echo Building the PDE...
# compile the code as java 1.3, so that the application will run and
# show the user an error, rather than crapping out with some strange
# "class not found" crap
../build/macosx/work/jikes -target 1.3 +D -classpath ../build/macosx/work/classes:../build/macosx/work/lib/core.jar:../build/macosx/work/lib/antlr.jar:../build/macosx/work/lib/oro.jar:../build/macosx/work/lib/registry.jar:$CLASSPATH -d ../build/macosx/work/classes src/processing/app/*.java src/processing/app/debug/*.java src/processing/app/syntax/*.java src/processing/app/preproc/*.java src/processing/app/tools/*.java src/antlr/*.java src/antlr/java/*.java
#../build/macosx/work/jikes -target 1.3 +D -classpath ../build/macosx/work/classes:../build/macosx/work/lib/core.jar:../build/macosx/work/lib/antlr.jar:../build/macosx/work/lib/oro.jar:../build/macosx/work/lib/registry.jar:$CLASSPATH -d ../build/macosx/work/classes *.java syntax/*.java preproc/*.java tools/*.java
#javac -source 1.3 -target 1.3 -classpath ../build/macosx/work/classes:../build/macosx/work/lib/core.jar:../build/macosx/work/lib/antlr.jar:../build/macosx/work/lib/oro.jar:../build/macosx/work/lib/registry.jar:$CLASSPATH -d ../build/macosx/work/classes *.java syntax/*.java preproc/*.java tools/*.java
# version that follows includes jalopy.jar and log4j.jar
#../build/macosx/work/jikes -target 1.3 +D -classpath ../build/macosx/work/classes:../build/macosx/work/lib/core.jar:../build/macosx/work/lib/antlr.jar:../build/macosx/work/lib/oro.jar:../build/macosx/work/lib/registry.jar:../build/macosx/work/lib/jalopy.jar:../build/macosx/work/lib/log4j.jar:$CLASSPATH -d ../build/macosx/work/classes tools/*.java preproc/*.java syntax/*.java *.java
../build/macosx/work/jikes -target 1.3 +D -classpath ../build/macosx/work/classes:../build/macosx/work/lib/core.jar:../build/macosx/work/lib/antlr.jar:../build/macosx/work/lib/registry.jar:$CLASSPATH -d ../build/macosx/work/classes src/processing/app/*.java src/processing/app/debug/*.java src/processing/app/syntax/*.java src/processing/app/preproc/*.java src/processing/app/tools/*.java src/antlr/*.java src/antlr/java/*.java
cd ../build/macosx/work/classes
rm -f ../lib/pde.jar
zip -0rq ../lib/pde.jar .
cd ../..
# i fought the packages and the packages won
#cd ../..
#WORKLIB=processing/build/macosx/work/lib
#./processing/build/macosx/work/jikes -d . -target 1.3 +D -classpath $WORKLIB/core.jar:$WORKLIB/antlr.jar:$WORKLIB/oro.jar:$WORKLIB/registry.jar:$CLASSPATH -d . processing/app/*.java processing/app/preproc/*.java processing/app/syntax/*.java processing/app/tools/*.java
#zip -rq $WORKLIB/pde.jar processing/app/*.class processing/app/preproc/*.class processing/app/syntax/*.class processing/app/tools/*.class
# get the libs
mkdir -p work/Processing.app/Contents/Resources/Java/
cp work/lib/*.jar work/Processing.app/Contents/Resources/Java/
+1 -1
View File
@@ -168,7 +168,7 @@ fi
cd app
CLASSPATH="..\\build\\windows\\work\\lib\\core.jar;..\\build\\windows\\work\\lib\\apple.jar;..\\build\\windows\\work\\lib\antlr.jar;..\\build\\windows\\work\\lib\\oro.jar;..\\build\\windows\\work\\lib\\registry.jar;..\\build\\windows\\work\\lib\\tools.jar;..\\build\\windows\\work\\java\\lib\\rt.jar"
CLASSPATH="..\\build\\windows\\work\\lib\\core.jar;..\\build\\windows\\work\\lib\\apple.jar;..\\build\\windows\\work\\lib\antlr.jar;..\\build\\windows\\work\\lib\\registry.jar;..\\build\\windows\\work\\lib\\tools.jar;..\\build\\windows\\work\\java\\lib\\rt.jar"
# compile the code as java 1.3, so that the application will run and
# show the user an error, rather than crapping out with some strange
+34 -17
View File
@@ -1,5 +1,39 @@
0137 pde
X move to multiple jars whenever
X 1) a lib is in use, 2) code folder, 3) multiple files
X remove oro.jar dependency (not needed with PApplet.match)
X this is kind of messy and requires a bit of testing to ensure proper
X sometimes huge jar files when exporting with a code folder
X http://dev.processing.org/bugs/show_bug.cgi?id=541
X applet export with multiple jars having trouble (related?)
X http://dev.processing.org/bugs/show_bug.cgi?id=701
X applet export fails with opengl/code folder
X http://dev.processing.org/bugs/show_bug.cgi?id=714
_ inside the preproc
_ change the arrays of default imports (now using 1.5+, so no 1.1,1.3,1.4)
_ prompt user before nuking applet or application folders
_ along with a "don't ask me later"
_ update preferences.txt whenever opening/closing
_ otherwise recovery from restart can be annoying
_ improvements to linux script for debian
_ http://dev.processing.org/bugs/show_bug.cgi?id=596
_ more info on the script
_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=os_core_pde;action=display;num=1202689238
_ make.sh creating work/lib dirs.. no longer necessary?
_ don't copy hidden files (.svn especially) on export/save as
_ make .java files and friends go to correct locations on export (app)
_ native lib stuff, use native.txt in lib folder, then:
_ String osName = System.getProperty("os.name");
_ String osArch = System.getProperty("os.arch");
_ update to jogl 1.1.1
_ do this with enhanced library/platform support
@@ -73,21 +107,6 @@ _ pdf not rendering unicode (though it renders to screen)
_ try updating to newer itext
_ http://dev.processing.org/bugs/show_bug.cgi?id=727
_ huge jar files from 0124 export
_ http://dev.processing.org/bugs/show_bug.cgi?id=541
_ applet export fails with opengl/code folder
_ http://dev.processing.org/bugs/show_bug.cgi?id=714
_ applet export with multiple jars having trouble (related?)
_ http://dev.processing.org/bugs/show_bug.cgi?id=701
_ improvements to linux script for debian
_ http://dev.processing.org/bugs/show_bug.cgi?id=596
_ more info on the script
_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=os_core_pde;action=display;num=1202689238
_ make.sh creating work/lib dirs.. no longer necessary?
_ don't copy hidden files (.svn especially) on export/save as
_ sometimes not launching
_ (in particular while cpu load is a little higher on g5?)
_ http://dev.processing.org/bugs/show_bug.cgi?id=775
@@ -131,8 +150,6 @@ _ use debugger to get better exceptions
_ and getting the error to show up in the window inside p5
_ also highlighting the correct line
_ respond to stop/close events sent by the vm
_ remove oro.jar dependency (not needed with PApplet.match)
_ this is kind of messy and requires a bit of testing to ensure proper
_ refactor code to use more getter/setter methods
_ move the debug classes back into processing.app.debug
_ this will help the library stuff