mirror of
https://github.com/processing/processing4.git
synced 2026-02-10 09:09:26 +01:00
more work on build/export
This commit is contained in:
@@ -366,108 +366,4 @@ public class PdeCompiler implements PdeMessageConsumer {
|
||||
}
|
||||
return importCount;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
|
||||
|
||||
/**
|
||||
* Slurps up .class files from a colon (or semicolon on windows)
|
||||
* separated list of paths and adds them to a ZipOutputStream.
|
||||
*/
|
||||
static public void magicExports(String path, ZipOutputStream zos)
|
||||
throws IOException {
|
||||
String pieces[] =
|
||||
BApplet.splitStrings(path, File.pathSeparatorChar);
|
||||
|
||||
for (int i = 0; i < pieces.length; i++) {
|
||||
if (pieces[i].length() == 0) continue;
|
||||
//System.out.println("checking piece " + pieces[i]);
|
||||
|
||||
// is it a jar file or directory?
|
||||
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()) {
|
||||
// actually 'continue's for all dir entries
|
||||
|
||||
} else {
|
||||
String name = entry.getName();
|
||||
// ignore contents of the META-INF folders
|
||||
if (name.indexOf("META-INF") == 0) continue;
|
||||
ZipEntry entree = new ZipEntry(name);
|
||||
|
||||
zos.putNextEntry(entree);
|
||||
byte buffer[] = new byte[(int) entry.getSize()];
|
||||
InputStream is = file.getInputStream(entry);
|
||||
|
||||
int offset = 0;
|
||||
int remaining = buffer.length;
|
||||
while (remaining > 0) {
|
||||
int count = is.read(buffer, offset, remaining);
|
||||
offset += count;
|
||||
remaining -= count;
|
||||
}
|
||||
|
||||
zos.write(buffer);
|
||||
zos.flush();
|
||||
zos.closeEntry();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error in file " + pieces[i]);
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else { // not a .jar or .zip, prolly a directory
|
||||
File dir = new File(pieces[i]);
|
||||
// but must be a dir, since it's one of several paths
|
||||
// just need to check if it exists
|
||||
if (dir.exists()) {
|
||||
magicExportsRecursive(dir, null, zos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Continue the process of magical exporting. This function
|
||||
* can be called recursively to walk through folders looking
|
||||
* for more goodies that will be added to the ZipOutputStream.
|
||||
*/
|
||||
static public void magicExportsRecursive(File dir, String sofar,
|
||||
ZipOutputStream zos)
|
||||
throws IOException {
|
||||
|
||||
String files[] = dir.list();
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
//if (files[i].equals(".") || files[i].equals("..")) continue;
|
||||
// ignore . .. and .DS_Store
|
||||
if (files[i].charAt(0) == '.') continue;
|
||||
|
||||
File sub = new File(dir, files[i]);
|
||||
String nowfar = (sofar == null) ?
|
||||
files[i] : (sofar + "/" + files[i]);
|
||||
|
||||
if (sub.isDirectory()) {
|
||||
magicExportsRecursive(sub, nowfar, zos);
|
||||
|
||||
} else {
|
||||
// don't add .jar and .zip files, since they only work
|
||||
// inside the root, and they're unpacked
|
||||
if (!files[i].toLowerCase().endsWith(".jar") &&
|
||||
!files[i].toLowerCase().endsWith(".zip") &&
|
||||
files[i].charAt(0) != '.') {
|
||||
ZipEntry entry = new ZipEntry(nowfar);
|
||||
zos.putNextEntry(entry);
|
||||
zos.write(PdeBase.grabFile(sub));
|
||||
zos.closeEntry();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user