use of processing.data.XML in project processing by processing.
the class JavaBuild method exportApplication.
/**
* Export to application without GUI. Also called by the Commander.
*/
protected boolean exportApplication(File destFolder, int exportPlatform, String exportVariant, boolean embedJava) throws IOException, SketchException {
// http://code.google.com/p/processing/issues/detail?id=884
for (Library library : importedLibraries) {
if (!library.supportsArch(exportPlatform, exportVariant)) {
String pn = PConstants.platformNames[exportPlatform];
Messages.showWarning("Quibbles 'n Bits", "The application." + pn + exportVariant + " folder will not be created\n" + "because no " + exportVariant + " version of " + library.getName() + " is available for " + pn, null);
// don't cancel all exports for this, just move along
return true;
}
}
/// prep the output directory
mode.prepareExportFolder(destFolder);
/// figure out where the jar files will be placed
File jarFolder = new File(destFolder, "lib");
/// where all the skeleton info lives
/// on macosx, need to copy .app skeleton since that's
/// also where the jar files will be placed
File dotAppFolder = null;
String jvmRuntime = "";
String jdkPath = null;
if (exportPlatform == PConstants.MACOSX) {
dotAppFolder = new File(destFolder, sketch.getName() + ".app");
File contentsOrig = new File(Platform.getJavaHome(), "../../../../..");
if (embedJava) {
File jdkFolder = new File(Platform.getJavaHome(), "../../..");
String jdkFolderName = jdkFolder.getCanonicalFile().getName();
jvmRuntime = "<key>JVMRuntime</key>\n <string>" + jdkFolderName + "</string>";
jdkPath = new File(dotAppFolder, "Contents/PlugIns/" + jdkFolderName).getAbsolutePath();
}
File contentsFolder = new File(dotAppFolder, "Contents");
contentsFolder.mkdirs();
// Info.plist will be written later
// set the jar folder to a different location than windows/linux
//jarFolder = new File(dotAppFolder, "Contents/Resources/Java");
jarFolder = new File(contentsFolder, "Java");
File macosFolder = new File(contentsFolder, "MacOS");
macosFolder.mkdirs();
Util.copyFile(new File(contentsOrig, "MacOS/Processing"), new File(contentsFolder, "MacOS/" + sketch.getName()));
File pkgInfo = new File(contentsFolder, "PkgInfo");
PrintWriter writer = PApplet.createWriter(pkgInfo);
writer.println("APPL????");
writer.flush();
writer.close();
// Use faster(?) native copy here (also to do sym links)
if (embedJava) {
Util.copyDirNative(new File(contentsOrig, "PlugIns"), new File(contentsFolder, "PlugIns"));
}
File resourcesFolder = new File(contentsFolder, "Resources");
Util.copyDir(new File(contentsOrig, "Resources/en.lproj"), new File(resourcesFolder, "en.lproj"));
Util.copyFile(mode.getContentFile("application/sketch.icns"), new File(resourcesFolder, "sketch.icns"));
} else if (exportPlatform == PConstants.LINUX) {
if (embedJava) {
Util.copyDirNative(Platform.getJavaHome(), new File(destFolder, "java"));
}
} else if (exportPlatform == PConstants.WINDOWS) {
if (embedJava) {
Util.copyDir(Platform.getJavaHome(), new File(destFolder, "java"));
}
}
if (!jarFolder.exists())
jarFolder.mkdirs();
/// start copying all jar files
StringList jarList = new StringList();
/// create the main .jar file
// HashMap<String,Object> zipFileContents = new HashMap<String,Object>();
FileOutputStream zipOutputFile = new FileOutputStream(new File(jarFolder, sketch.getName() + ".jar"));
ZipOutputStream zos = new ZipOutputStream(zipOutputFile);
// ZipEntry entry;
// add the manifest file so that the .jar can be double clickable
addManifest(zos);
// add the project's .class files to the jar
// (just grabs everything from the build directory,
// since there may be some inner classes)
// TODO this needs to be recursive (for packages)
// File classFiles[] = tempClassesFolder.listFiles(new FilenameFilter() {
// public boolean accept(File dir, String name) {
// return name.endsWith(".class");
// }
// });
// for (File file : classFiles) {
// entry = new ZipEntry(file.getName());
// zos.putNextEntry(entry);
// zos.write(Base.loadBytesRaw(file));
// zos.closeEntry();
// }
addClasses(zos, binFolder);
// 'data' folder next to 'lib'.
if (sketch.hasDataFolder()) {
if (exportPlatform == PConstants.MACOSX) {
Util.copyDir(sketch.getDataFolder(), new File(jarFolder, "data"));
} else {
Util.copyDir(sketch.getDataFolder(), new File(destFolder, "data"));
}
}
// add the contents of the code folder to the jar
if (sketch.hasCodeFolder()) {
String includes = Util.contentsToClassPath(sketch.getCodeFolder());
// Use tokens to get rid of extra blanks, which causes huge exports
String[] codeList = PApplet.splitTokens(includes, File.pathSeparator);
for (int i = 0; i < codeList.length; i++) {
if (codeList[i].toLowerCase().endsWith(".jar") || codeList[i].toLowerCase().endsWith(".zip")) {
File exportFile = new File(codeList[i]);
String exportFilename = exportFile.getName();
Util.copyFile(exportFile, new File(jarFolder, exportFilename));
jarList.append(exportFilename);
} else {
// cp += codeList[i] + File.pathSeparator;
}
}
}
zos.flush();
zos.close();
jarList.append(sketch.getName() + ".jar");
/// add contents of 'library' folders to the export
for (Library library : importedLibraries) {
// add each item from the library folder / export list to the output
for (File exportFile : library.getApplicationExports(exportPlatform, exportVariant)) {
// System.out.println("export: " + exportFile);
String exportName = exportFile.getName();
if (!exportFile.exists()) {
System.err.println(exportFile.getName() + " is mentioned in export.txt, but it's " + "a big fat lie and does not exist.");
} else if (exportFile.isDirectory()) {
Util.copyDir(exportFile, new File(jarFolder, exportName));
} else if (exportName.toLowerCase().endsWith(".zip") || exportName.toLowerCase().endsWith(".jar")) {
Util.copyFile(exportFile, new File(jarFolder, exportName));
jarList.append(exportName);
} else {
// Starting with 2.0a2 put extra export files (DLLs, plugins folder,
// anything else for libraries) inside lib or Contents/Resources/Java
Util.copyFile(exportFile, new File(jarFolder, exportName));
}
}
}
/// create platform-specific CLASSPATH based on included jars
String exportClassPath = null;
if (exportPlatform == PConstants.MACOSX) {
exportClassPath = "$JAVAROOT/" + jarList.join(":$JAVAROOT/");
} else if (exportPlatform == PConstants.WINDOWS) {
exportClassPath = jarList.join(",");
} else if (exportPlatform == PConstants.LINUX) {
// why is $APPDIR at the front of this list?
exportClassPath = "$APPDIR" + ":$APPDIR/lib/" + jarList.join(":$APPDIR/lib/");
}
/// figure out run options for the VM
StringList runOptions = new StringList();
// https://github.com/processing/processing/pull/4406
if (Preferences.getBoolean("run.options.memory") && !exportVariant.equals("armv6hf")) {
runOptions.append("-Xms" + Preferences.get("run.options.memory.initial") + "m");
runOptions.append("-Xmx" + Preferences.get("run.options.memory.maximum") + "m");
}
// https://github.com/processing/processing/issues/2239
runOptions.append("-Djna.nosys=true");
// https://github.com/processing/processing/issues/4608
if (embedJava) {
// if people don't embed Java, it might be a mess, but what can we do?
if (exportPlatform == PConstants.MACOSX) {
runOptions.append("-Djava.ext.dirs=$APP_ROOT/Contents/PlugIns/jdk" + PApplet.javaVersionName + ".jdk/Contents/Home/jre/lib/ext");
} else if (exportPlatform == PConstants.WINDOWS) {
runOptions.append("-Djava.ext.dirs=\"%EXEDIR%\\java\\lib\\ext\"");
} else if (exportPlatform == PConstants.LINUX) {
runOptions.append("-Djava.ext.dirs=\"$APPDIR/java/lib/ext\"");
}
}
// https://github.com/processing/processing/issues/2559
if (exportPlatform == PConstants.WINDOWS) {
runOptions.append("-Djava.library.path=\"%EXEDIR%\\lib\"");
}
if (exportPlatform == PConstants.MACOSX) {
StringBuilder runOptionsXML = new StringBuilder();
for (String opt : runOptions) {
runOptionsXML.append(" <string>");
runOptionsXML.append(opt);
runOptionsXML.append("</string>");
runOptionsXML.append('\n');
}
String PLIST_TEMPLATE = "Info.plist.tmpl";
File plistTemplate = new File(sketch.getFolder(), PLIST_TEMPLATE);
if (!plistTemplate.exists()) {
plistTemplate = mode.getContentFile("application/" + PLIST_TEMPLATE);
}
File plistFile = new File(dotAppFolder, "Contents/Info.plist");
PrintWriter pw = PApplet.createWriter(plistFile);
String[] lines = PApplet.loadStrings(plistTemplate);
for (int i = 0; i < lines.length; i++) {
if (lines[i].indexOf("@@") != -1) {
StringBuilder sb = new StringBuilder(lines[i]);
int index = 0;
while ((index = sb.indexOf("@@jvm_runtime@@")) != -1) {
sb.replace(index, index + "@@jvm_runtime@@".length(), jvmRuntime);
}
while ((index = sb.indexOf("@@jvm_options_list@@")) != -1) {
sb.replace(index, index + "@@jvm_options_list@@".length(), runOptionsXML.toString());
}
while ((index = sb.indexOf("@@sketch@@")) != -1) {
sb.replace(index, index + "@@sketch@@".length(), sketch.getName());
}
while ((index = sb.indexOf("@@lsuipresentationmode@@")) != -1) {
sb.replace(index, index + "@@lsuipresentationmode@@".length(), Preferences.getBoolean("export.application.present") ? "4" : "0");
}
lines[i] = sb.toString();
}
// explicit newlines to avoid Windows CRLF
pw.print(lines[i] + "\n");
}
pw.flush();
pw.close();
// attempt to code sign if the Xcode tools appear to be installed
if (Platform.isMacOS() && isXcodeInstalled()) {
if (embedJava) {
ProcessHelper.ffs("codesign", "--force", "--sign", "-", jdkPath);
}
String appPath = dotAppFolder.getAbsolutePath();
ProcessHelper.ffs("codesign", "--force", "--sign", "-", appPath);
}
} else if (exportPlatform == PConstants.WINDOWS) {
File buildFile = new File(destFolder, "launch4j-build.xml");
File configFile = new File(destFolder, "launch4j-config.xml");
XML project = new XML("project");
XML target = project.addChild("target");
target.setString("name", "windows");
XML taskdef = target.addChild("taskdef");
taskdef.setString("name", "launch4j");
taskdef.setString("classname", "net.sf.launch4j.ant.Launch4jTask");
String launchPath = mode.getContentFile("application/launch4j").getAbsolutePath();
taskdef.setString("classpath", launchPath + "/launch4j.jar:" + launchPath + "/lib/xstream.jar");
XML launch4j = target.addChild("launch4j");
// not all launch4j options are available when embedded inside the ant
// build file (i.e. the icon param doesn't work), so use a config file
//<launch4j configFile="windows/work/config.xml" />
launch4j.setString("configFile", configFile.getAbsolutePath());
XML config = new XML("launch4jConfig");
config.addChild("headerType").setContent("gui");
config.addChild("dontWrapJar").setContent("true");
config.addChild("downloadUrl").setContent("http://java.com/download");
File exeFile = new File(destFolder, sketch.getName() + ".exe");
config.addChild("outfile").setContent(exeFile.getAbsolutePath());
File iconFile = mode.getContentFile("application/sketch.ico");
config.addChild("icon").setContent(iconFile.getAbsolutePath());
XML clazzPath = config.addChild("classPath");
clazzPath.addChild("mainClass").setContent(sketch.getName());
for (String jarName : jarList) {
clazzPath.addChild("cp").setContent("lib/" + jarName);
}
XML jre = config.addChild("jre");
if (embedJava) {
jre.addChild("path").setContent("java");
}
// Need u74 for a major JavaFX issue (upside-down display)
// https://github.com/processing/processing/issues/3795
jre.addChild("minVersion").setContent("1.8.0_74");
for (String opt : runOptions) {
jre.addChild("opt").setContent(opt);
}
config.save(configFile);
project.save(buildFile);
if (!buildWindowsLauncher(buildFile, "windows")) {
// don't delete the build file, might be useful for debugging
return false;
}
configFile.delete();
buildFile.delete();
} else {
File shellScript = new File(destFolder, sketch.getName());
PrintWriter pw = PApplet.createWriter(shellScript);
// Do the newlines explicitly so that Windows CRLF
// isn't used when exporting for Unix.
pw.print("#!/bin/sh\n\n");
// allow symlinks
pw.print("APPDIR=$(readlink -f \"$0\")\n");
// more POSIX compliant
pw.print("APPDIR=$(dirname \"$APPDIR\")\n");
if (embedJava) {
// https://github.com/processing/processing/issues/2349
pw.print("$APPDIR/java/bin/");
}
String runOptionsStr = runOptions.join(" ");
pw.print("java " + runOptionsStr + " -Djava.library.path=\"$APPDIR:$APPDIR/lib\"" + //" -Djna.nosys=true" +
" -cp \"" + exportClassPath + "\"" + " " + sketch.getName() + " \"$@\"\n");
pw.flush();
pw.close();
String shellPath = shellScript.getAbsolutePath();
// will work on osx or *nix, but just dies on windows, oh well..
if (!Platform.isWindows()) {
Runtime.getRuntime().exec(new String[] { "chmod", "+x", shellPath });
}
}
/// copy the source files to the target
/// (we like to encourage people to share their code)
File sourceFolder = new File(destFolder, "source");
sourceFolder.mkdirs();
for (SketchCode code : sketch.getCode()) {
try {
code.copyTo(new File(sourceFolder, code.getFileName()));
} catch (IOException e) {
e.printStackTrace();
}
}
// move the .java file from the preproc there too
String preprocFilename = sketch.getName() + ".java";
File preprocFile = new File(srcFolder, preprocFilename);
if (preprocFile.exists()) {
Util.copyFile(preprocFile, new File(sourceFolder, preprocFilename));
} else {
System.err.println("Could not copy source file: " + preprocFile.getAbsolutePath());
}
/// goodbye
return true;
}
use of processing.data.XML in project Most-Pixels-Ever-Processing by shiffman.
the class TCPClient method loadSettings.
/**
* Loads the settings from the Client XML file.
*
* @param filename the path to the XML file
*/
private void loadSettings(String filename) {
// parse XML file
XML xml = p5parent.loadXML(filename);
setServer(xml.getChild("server/ip").getContent());
setPort(xml.getChild("server/port").getIntContent());
setID(xml.getChild("id").getIntContent());
XML name = xml.getChild("name");
if (name != null) {
setClientName(name.getContent());
}
XML asynch = xml.getChild("asynchronous");
if (asynch != null) {
String a = asynch.getContent();
asynchronous = Boolean.parseBoolean(a);
if (asynchronous) {
XML receive = xml.getChild("asynchreceive");
if (receive != null) {
String r = receive.getContent();
asynchreceive = Boolean.parseBoolean(r);
}
}
}
String v = xml.getChild("verbose").getContent();
VERBOSE = Boolean.parseBoolean(v);
// Implement name
if (!asynchronous) {
int w = xml.getChild("local_dimensions/width").getIntContent();
int h = xml.getChild("local_dimensions/height").getIntContent();
setLocalDimensions(w, h);
int x = xml.getChild("local_location/x").getIntContent();
int y = xml.getChild("local_location/y").getIntContent();
setOffsets(x, y);
int mw = xml.getChild("master_dimensions/width").getIntContent();
int mh = xml.getChild("master_dimensions/height").getIntContent();
setLocalDimensions(w, h);
XML offset = xml.getChild("offset_window");
if (offset != null) {
offsetWindow = Boolean.parseBoolean(offset.getContent());
}
XML simxml = xml.getChild("simulation");
if (simxml != null) {
simulation = Boolean.parseBoolean(simxml.getContent());
simFPS = simxml.getInt("fps");
if (simFPS < 1)
simFPS = 30;
}
setMasterDimensions(mw, mh);
out("Settings: server = " + hostName + ":" + serverPort + ", id = " + id + ", local dimensions = " + lWidth + ", " + lHeight + ", location = " + xOffset + ", " + yOffset);
}
}
Aggregations