mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
fixing methods for "magic imports"
This commit is contained in:
+100
-42
@@ -75,6 +75,14 @@ public class PdeCompiler implements PdeMessageConsumer {
|
||||
((PdeBase.platform != PdeBase.MACOSX) ? "jikes" :
|
||||
System.getProperty("user.dir") + File.separator + "jikes"),
|
||||
|
||||
// this doesn't help much.. also java 1.4 seems to not support
|
||||
// -source 1.1 for javac, and jikes seems to also have dropped it.
|
||||
// for versions of jikes that don't complain, "final int" inside
|
||||
// a function doesn't throw an error, so it could just be a
|
||||
// ms jvm error that this sort of thing doesn't work. blech.
|
||||
//"-source",
|
||||
//"1.1",
|
||||
|
||||
// necessary to make output classes compatible with 1.1
|
||||
// i.e. so that exported applets can work with ms jvm on the web
|
||||
"-target",
|
||||
@@ -314,76 +322,125 @@ public class PdeCompiler implements PdeMessageConsumer {
|
||||
e.printStackTrace(); // this would be odd
|
||||
}
|
||||
//System.out.println("included path is " + abuffer.toString());
|
||||
magicImports(abuffer.toString());
|
||||
makeImportsFromClassPath(abuffer.toString());
|
||||
return abuffer.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate a list of packages for an import list
|
||||
* based on the contents of a classpath.
|
||||
* A classpath, separated by the path separator, will contain
|
||||
* a series of .jar/.zip files or directories containing .class
|
||||
* files, or containing subdirectories that have .class files.
|
||||
*
|
||||
* @param path the input classpath
|
||||
* @return array of possible package names
|
||||
*/
|
||||
static public String[] magicImports(String path) {
|
||||
String imports[] = new String[100];
|
||||
int importCount = 0;
|
||||
|
||||
static public String[] makeImportsFromClassPath(String path) {
|
||||
Hashtable table = new Hashtable();
|
||||
String pieces[] =
|
||||
BApplet.split(path, File.pathSeparatorChar);
|
||||
|
||||
for (int i = 0; i < pieces.length; i++) {
|
||||
//System.out.println("checking piece " + pieces[i]);
|
||||
//System.out.println("checking piece '" + pieces[i] + "'");
|
||||
if (pieces[i].length() == 0) continue;
|
||||
|
||||
if (pieces[i].toLowerCase().endsWith(".jar") ||
|
||||
pieces[i].toLowerCase().endsWith(".zip")) {
|
||||
try {
|
||||
ZipFile file = new ZipFile(pieces[i]);
|
||||
Enumeration entries = file.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
ZipEntry entry = (ZipEntry) entries.nextElement();
|
||||
if (entry.isDirectory()) {
|
||||
String name = entry.getName();
|
||||
if (name.equals("META-INF/")) continue;
|
||||
name = name.substring(0, name.length() - 1);
|
||||
name = name.replace('/', '.');
|
||||
makeImportsFromZip(pieces[i], table);
|
||||
|
||||
if (importCount == imports.length) {
|
||||
String temp[] = new String[importCount << 1];
|
||||
System.arraycopy(imports, 0, temp, 0, importCount);
|
||||
imports = temp;
|
||||
}
|
||||
imports[importCount++] = name;
|
||||
//System.out.println("import " + name + ".*;");
|
||||
}
|
||||
//System.out.print(entry.isDirectory() ? "D " : "c ");
|
||||
//System.out.println(entry.getName());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error in file " + pieces[i]);
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
} else { // it's another type of file or directory
|
||||
File dir = new File(pieces[i]);
|
||||
if (dir.exists()) {
|
||||
importCount = magicImportsRecursive(dir, null,
|
||||
imports, importCount);
|
||||
if (dir.exists() && dir.isDirectory()) {
|
||||
makeImportsFromFolder(dir, null, table);
|
||||
//importCount = magicImportsRecursive(dir, null,
|
||||
// table);
|
||||
//imports, importCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
String output[] = new String[importCount];
|
||||
System.arraycopy(imports, 0, output, 0, importCount);
|
||||
int tableCount = table.size();
|
||||
String output[] = new String[tableCount];
|
||||
int index = 0;
|
||||
Enumeration e = table.keys();
|
||||
while (e.hasMoreElements()) {
|
||||
output[index++] = ((String) e.nextElement()).replace('/', '.');
|
||||
}
|
||||
//System.arraycopy(imports, 0, output, 0, importCount);
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
static public void makeImportsFromZip(String filename, Hashtable table) {
|
||||
try {
|
||||
ZipFile file = new ZipFile(filename);
|
||||
Enumeration entries = file.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
ZipEntry entry = (ZipEntry) entries.nextElement();
|
||||
|
||||
if (!entry.isDirectory()) {
|
||||
String name = entry.getName();
|
||||
|
||||
if (name.endsWith(".class")) {
|
||||
int slash = name.lastIndexOf('/');
|
||||
if (slash == -1) continue;
|
||||
|
||||
String pname = name.substring(0, slash);
|
||||
if (table.get(pname) == null) {
|
||||
table.put(pname, new Object());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("Ignoring " + filename + " (" + e.getMessage() + ")");
|
||||
//e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Support function for magicImports()
|
||||
* Make list of package names by traversing a directory hierarchy.
|
||||
* Each time a class is found in a folder, add its containing set
|
||||
* of folders to the package list. If another folder is found,
|
||||
* walk down into that folder and continue.
|
||||
*/
|
||||
static public void makeImportsFromFolder(File dir, String sofar,
|
||||
Hashtable table) {
|
||||
//String imports[],
|
||||
//int importCount) {
|
||||
//System.err.println("checking dir '" + dir + "'");
|
||||
boolean foundClass = false;
|
||||
String files[] = dir.list();
|
||||
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
if (files[i].equals(".") || files[i].equals("..")) continue;
|
||||
|
||||
File sub = new File(dir, files[i]);
|
||||
if (sub.isDirectory()) {
|
||||
String nowfar =
|
||||
(sofar == null) ? files[i] : (sofar + "." + files[i]);
|
||||
makeImportsFromFolder(sub, nowfar, table);
|
||||
//System.out.println(nowfar);
|
||||
//imports[importCount++] = nowfar;
|
||||
//importCount = magicImportsRecursive(sub, nowfar,
|
||||
// imports, importCount);
|
||||
} else if (!foundClass) { // if no classes found in this folder yet
|
||||
if (files[i].endsWith(".class")) {
|
||||
//System.out.println("unique class: " + files[i] + " for " + sofar);
|
||||
table.put(sofar, new Object());
|
||||
foundClass = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
//return importCount;
|
||||
}
|
||||
|
||||
/*
|
||||
static public int magicImportsRecursive(File dir, String sofar,
|
||||
String imports[],
|
||||
int importCount) {
|
||||
Hashtable table) {
|
||||
//String imports[],
|
||||
//int importCount) {
|
||||
System.err.println("checking dir '" + dir + "'");
|
||||
String files[] = dir.list();
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
if (files[i].equals(".") || files[i].equals("..")) continue;
|
||||
@@ -401,4 +458,5 @@ public class PdeCompiler implements PdeMessageConsumer {
|
||||
}
|
||||
return importCount;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
+11
-4
@@ -648,17 +648,24 @@ public class PdeSketch {
|
||||
throws PdeException {
|
||||
|
||||
String importPackageList[] = null;
|
||||
classPath = buildPath + File.pathSeparator +
|
||||
System.getProperty("java.class.path");
|
||||
|
||||
String javaClassPath = System.getProperty("java.class.path");
|
||||
// remove quotes if any.. this is an annoying thing on windows
|
||||
if (javaClassPath.startsWith("\"") && javaClassPath.endsWith("\"")) {
|
||||
javaClassPath = javaClassPath.substring(1, javaClassPath.length() - 1);
|
||||
}
|
||||
|
||||
classPath = buildPath + File.pathSeparator + javaClassPath;
|
||||
//System.out.println("cp = " + classPath);
|
||||
|
||||
// figure out the contents of the code folder to see if there
|
||||
// are files that need to be added to the imports
|
||||
//File codeFolder = new File(folder, "code");
|
||||
if (codeFolder.exists()) {
|
||||
externalRuntime = true;
|
||||
classPath += File.separator +
|
||||
classPath += File.pathSeparator +
|
||||
PdeCompiler.contentsToClassPath(codeFolder);
|
||||
importPackageList = PdeCompiler.magicImports(classPath);
|
||||
importPackageList = PdeCompiler.makeImportsFromClassPath(classPath);
|
||||
//libraryPath = codeFolder.getCanonicalPath();
|
||||
libraryPath = codeFolder.getAbsolutePath();
|
||||
} else {
|
||||
|
||||
@@ -30,7 +30,7 @@ fi
|
||||
# includes jaws.jar
|
||||
#CLASSPATH=\"java\\lib\\rt.jar\;java\\lib\\jaws.jar\;lib\;lib\\build\;lib\\pde.jar\;lib\\kjc.jar\;lib\\antlr.jar\;lib\\oro.jar\;lib\\comm.jar\;lib\\RXTXcomm.jar\;${QT_JAVA_PATH}\"
|
||||
|
||||
CLASSPATH=\"java\\lib\\rt.jar\;lib\;lib\\build\;lib\\pde.jar\;lib\\kjc.jar\;lib\\antlr.jar\;lib\\oro.jar\;lib\\comm.jar\;lib\\RXTXcomm.jar\;${QT_JAVA_PATH}\"
|
||||
CLASSPATH=\"java\\lib\\rt.jar\;lib\;lib\\build\;lib\\pde.jar\;lib\\kjc.jar\;lib\\antlr.jar\;lib\\oro.jar\;lib\\comm.jar\;${QT_JAVA_PATH}\"
|
||||
export CLASSPATH
|
||||
|
||||
#cd work && ./java/bin/java -Xint PdeBase
|
||||
|
||||
@@ -73,10 +73,9 @@ X when 'skNew' is cancelled in 'open' mode, nullpointerex at the top
|
||||
X if a "save as" is forced, make sure that the sketchbook menu is updated
|
||||
X sort sketch names in the open menu
|
||||
X http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1074981609
|
||||
|
||||
_ warn about writing non-1.1 code.
|
||||
_ will jikes do it if the -source is set to 1.1?
|
||||
_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_Software;action=display;num=1079867179;start=0
|
||||
X code folder was causing mega-crashes
|
||||
X rewrite magic import methods to only use packages where classes found
|
||||
X was adding all folders in the classpath
|
||||
|
||||
_ dashes shouldn't be allowed in filenames for sketches
|
||||
_ actually, lost the naming stuff because now using FileDialog
|
||||
@@ -89,7 +88,7 @@ _ implement hide/unhide
|
||||
_ export is badly broken
|
||||
_ get the console working again
|
||||
_ appendText is disabled due to NullPointerEx on startup
|
||||
_ ctrl-5 (confirmed on xp) is marking the current sketch as modified
|
||||
_ ctrl-5 (at least on xp) is marking the current sketch as modified
|
||||
_ running present mode with a bug in the program hoses things
|
||||
_ make sure the program compiles before starting present mode
|
||||
_ if 'applet.html' is in sketch folder, use that as the template
|
||||
@@ -431,11 +430,19 @@ PDE / Details
|
||||
1 _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_Software;action=display;num=1075659029
|
||||
|
||||
|
||||
PDE / Compiler
|
||||
|
||||
1 _ warn about writing non-1.1 code.
|
||||
1 X will jikes do it if the -source is set to 1.1? nope..
|
||||
1 X notes inside PdeCompiler
|
||||
1 _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_Software;action=display;num=1079867179;start=0
|
||||
|
||||
|
||||
PDE / Font Builder
|
||||
|
||||
1 _ close/hide window on 'ESC'
|
||||
1 _ loading is very slow on the first time (getting all font names)
|
||||
1 _ show a progress/status bar while it's happening
|
||||
1 _ show a progress/status bar while it's happening?
|
||||
1 _ font builder chopping off parts of letters
|
||||
1 _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1076358432;start=0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user