From b2bd2c421701bc4d5361495e249ffea50849c4ab Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Thu, 24 Oct 2013 21:50:51 -0400 Subject: [PATCH] Add option to not embed the Java runtime --- app/src/processing/mode/java/Commander.java | 10 ++++- app/src/processing/mode/java/JavaBuild.java | 41 +++++++++++++------- app/src/processing/mode/java/JavaEditor.java | 34 ++++++++++++++-- core/todo.txt | 6 +++ java/application/Info.plist.tmpl | 3 +- todo.txt | 3 +- 6 files changed, 75 insertions(+), 22 deletions(-) diff --git a/app/src/processing/mode/java/Commander.java b/app/src/processing/mode/java/Commander.java index b69cf4bbe..72dff1808 100644 --- a/app/src/processing/mode/java/Commander.java +++ b/app/src/processing/mode/java/Commander.java @@ -48,6 +48,7 @@ public class Commander implements RunnerListener { static final String forceArg = "--force"; static final String outputArg = "--output="; static final String exportApplicationArg = "--export"; + static final String noJavaArg = "--export"; static final String platformArg = "--platform="; static final String bitsArg = "--bits="; // static final String preferencesArg = "--preferences="; @@ -109,6 +110,7 @@ public class Commander implements RunnerListener { int platform = PApplet.platform; // default to this platform int platformBits = 0; int task = HELP; + boolean embedJava = true; // Turns out the output goes as MacRoman or something else useless. // http://code.google.com/p/processing/issues/detail?id=1418 @@ -145,6 +147,9 @@ public class Commander implements RunnerListener { } else if (arg.equals(exportApplicationArg)) { task = EXPORT; + + } else if (arg.equals(noJavaArg)) { + embedJava = false; } else if (arg.startsWith(platformArg)) { complainAndQuit("The --platform option has been removed from Processing 2.1.", false); @@ -156,7 +161,7 @@ public class Commander implements RunnerListener { // } } else if (arg.startsWith(bitsArg)) { - complainAndQuit("The --platform option has been removed from Processing 2.1.", false); + complainAndQuit("The --bits option has been removed from Processing 2.1.", false); // String bitsStr = arg.substring(bitsArg.length()); // if (bitsStr.equals("32")) { // platformBits = 32; @@ -279,7 +284,7 @@ public class Commander implements RunnerListener { Library.hasMultipleArch(platform, build.getImportedLibraries())) { complainAndQuit("This sketch can be exported for 32- or 64-bit, please specify one.", true); } - success = build.exportApplication(outputFolder, platform, platformBits); + success = build.exportApplication(outputFolder, platform, platformBits, embedJava); } } } @@ -369,6 +374,7 @@ public class Commander implements RunnerListener { out.println("--present Preprocess, compile, and run a sketch full screen."); out.println(); out.println("--export Export an application."); + out.println("--no-java Do not embed Java. Use at your own risk!"); // out.println("--platform Specify the platform (export to application only)."); // out.println(" Should be one of 'windows', 'macosx', or 'linux'."); // out.println("--bits Must be specified if libraries are used that are"); diff --git a/app/src/processing/mode/java/JavaBuild.java b/app/src/processing/mode/java/JavaBuild.java index f09a2e1fe..f42d0930d 100644 --- a/app/src/processing/mode/java/JavaBuild.java +++ b/app/src/processing/mode/java/JavaBuild.java @@ -1118,23 +1118,24 @@ public class JavaBuild { File folder = null; String platformName = Base.getPlatformName(); + boolean embedJava = Preferences.getBoolean("export.application.embed_java"); if (Library.hasMultipleArch(PApplet.platform, importedLibraries)) { if (Base.getNativeBits() == 32) { // export the 32-bit version folder = new File(sketch.getFolder(), "application." + platformName + "32"); - if (!exportApplication(folder, PApplet.platform, 32)) { + if (!exportApplication(folder, PApplet.platform, 32, embedJava)) { return false; } } else if (Base.getNativeBits() == 64) { // export the 64-bit version folder = new File(sketch.getFolder(), "application." + platformName + "64"); - if (!exportApplication(folder, PApplet.platform, 64)) { + if (!exportApplication(folder, PApplet.platform, 64, embedJava)) { return false; } } } else { // just make a single one for this platform folder = new File(sketch.getFolder(), "application." + platformName); - if (!exportApplication(folder, PApplet.platform, 0)) { + if (!exportApplication(folder, PApplet.platform, 0, embedJava)) { return false; } } @@ -1147,7 +1148,8 @@ public class JavaBuild { */ protected boolean exportApplication(File destFolder, int exportPlatform, - int exportBits) throws IOException, SketchException { + int exportBits, + boolean embedJava) throws IOException, SketchException { // TODO this should probably be a dialog box instead of a warning // on the terminal. And the message should be written better than this. // http://code.google.com/p/processing/issues/detail?id=884 @@ -1178,13 +1180,18 @@ public class JavaBuild { /// on macosx, need to copy .app skeleton since that's /// also where the jar files will be placed File dotAppFolder = null; - String jdkFolderName = null; +// String jdkFolderName = null; + String jvmRuntime = ""; if (exportPlatform == PConstants.MACOSX) { dotAppFolder = new File(destFolder, sketch.getName() + ".app"); File contentsOrig = new File(Base.getJavaHome(), "../../../../.."); - File jdkFolder = new File(Base.getJavaHome(), "../../.."); - jdkFolderName = jdkFolder.getCanonicalFile().getName(); + + if (embedJava) { + File jdkFolder = new File(Base.getJavaHome(), "../../.."); + String jdkFolderName = jdkFolder.getCanonicalFile().getName(); + jvmRuntime = "JVMRuntime\n " + jdkFolderName + ""; + } // File dotAppSkeleton = mode.getContentFile("application/template.app"); // Base.copyDir(dotAppSkeleton, dotAppFolder); @@ -1209,8 +1216,10 @@ public class JavaBuild { writer.close(); // Use faster(?) native copy here (also to do sym links) - Base.copyDirNative(new File(contentsOrig, "PlugIns"), - new File(contentsFolder, "PlugIns")); + if (embedJava) { + Base.copyDirNative(new File(contentsOrig, "PlugIns"), + new File(contentsFolder, "PlugIns")); + } File resourcesFolder = new File(contentsFolder, "Resources"); Base.copyDir(new File(contentsOrig, "Resources/en.lproj"), @@ -1243,10 +1252,14 @@ public class JavaBuild { } */ } else if (exportPlatform == PConstants.LINUX) { - Base.copyDirNative(Base.getJavaHome(), new File(destFolder, "java")); + if (embedJava) { + Base.copyDirNative(Base.getJavaHome(), new File(destFolder, "java")); + } } else if (exportPlatform == PConstants.WINDOWS) { - Base.copyDir(Base.getJavaHome(), new File(destFolder, "java")); + if (embedJava) { + Base.copyDir(Base.getJavaHome(), new File(destFolder, "java")); + } } @@ -1480,9 +1493,9 @@ public class JavaBuild { if (lines[i].indexOf("@@") != -1) { StringBuffer sb = new StringBuffer(lines[i]); int index = 0; - while ((index = sb.indexOf("@@jdk_folder@@")) != -1) { - sb.replace(index, index + "@@jdk_folder@@".length(), - jdkFolderName); + 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(), diff --git a/app/src/processing/mode/java/JavaEditor.java b/app/src/processing/mode/java/JavaEditor.java index ce81e060e..676db1272 100644 --- a/app/src/processing/mode/java/JavaEditor.java +++ b/app/src/processing/mode/java/JavaEditor.java @@ -266,7 +266,9 @@ public class JavaEditor extends Editor { label2.setAlignmentX(Component.LEFT_ALIGNMENT); panel.add(label1); panel.add(label2); - int wide = label1.getPreferredSize().width; + // The longer line is different between Windows and OS X. + int wide = Math.max(label1.getPreferredSize().width, + label2.getPreferredSize().width); panel.add(Box.createVerticalStrut(12)); /* @@ -312,6 +314,9 @@ public class JavaEditor extends Editor { panel.add(platformPanel); */ + //int indent = new JCheckBox().getPreferredSize().width; + int indent = 0; + final JCheckBox showStopButton = new JCheckBox("Show a Stop button"); showStopButton.setSelected(Preferences.getBoolean("export.application.stop")); showStopButton.addItemListener(new ItemListener() { @@ -320,7 +325,7 @@ public class JavaEditor extends Editor { } }); showStopButton.setEnabled(Preferences.getBoolean("export.application.fullscreen")); - showStopButton.setBorder(new EmptyBorder(3, 13, 6, 13)); + showStopButton.setBorder(new EmptyBorder(3, 13 + indent, 6, 13)); final JCheckBox fullScreenButton = new JCheckBox("Full Screen (Present mode)"); fullScreenButton.setSelected(Preferences.getBoolean("export.application.fullscreen")); @@ -333,10 +338,33 @@ public class JavaEditor extends Editor { }); fullScreenButton.setBorder(new EmptyBorder(3, 13, 3, 13)); + boolean embed = Preferences.getBoolean("export.application.embed_java"); + final String embedWarning = "Embedding Java makes larger applications"; + final String nopeWarning = "Users will have to install the latest Java 7"; + final JLabel warningLabel = new JLabel(embed ? embedWarning : nopeWarning); + warningLabel.setBorder(new EmptyBorder(3, 13 + indent, 3, 13)); + + final JCheckBox embedJavaButton = new JCheckBox("Embed Java"); + embedJavaButton.setSelected(embed); + embedJavaButton.addItemListener(new ItemListener() { + public void itemStateChanged(ItemEvent e) { + boolean selected = embedJavaButton.isSelected(); + Preferences.setBoolean("export.application.embed_java", selected); + if (selected) { + warningLabel.setText(embedWarning); + } else { + warningLabel.setText(nopeWarning); + } + } + }); + embedJavaButton.setBorder(new EmptyBorder(3, 13, 3, 13)); + JPanel optionPanel = new JPanel(); optionPanel.setLayout(new BoxLayout(optionPanel, BoxLayout.Y_AXIS)); optionPanel.add(fullScreenButton); optionPanel.add(showStopButton); + optionPanel.add(embedJavaButton); + optionPanel.add(warningLabel); optionPanel.setBorder(new TitledBorder("Options")); // wide = Math.max(wide, platformPanel.getPreferredSize().width); optionPanel.setAlignmentX(Component.LEFT_ALIGNMENT); @@ -351,7 +379,7 @@ public class JavaEditor extends Editor { // good = new Dimension(wide, platformPanel.getPreferredSize().height); // platformPanel.setMaximumSize(good); good = new Dimension(wide, optionPanel.getPreferredSize().height); - optionPanel.setMaximumSize(good); +// optionPanel.setMaximumSize(good); String[] options = { "Export", "Cancel" }; final JOptionPane optionPane = new JOptionPane(panel, diff --git a/core/todo.txt b/core/todo.txt index f627eaa82..bb5f08b62 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -1,5 +1,11 @@ 0223 core +opengl +X Using sketchQuality() does not work properly with P3D, OPENGL, P2D +X https://github.com/processing/processing/pull/2157 +X Fix crashes when the sketch window is resized +X https://github.com/processing/processing/issues/1880 +X https://github.com/processing/processing/pull/2156 high _ Sort out blending differences with P2D/P3D diff --git a/java/application/Info.plist.tmpl b/java/application/Info.plist.tmpl index 787f56ed2..28a2e0277 100644 --- a/java/application/Info.plist.tmpl +++ b/java/application/Info.plist.tmpl @@ -32,8 +32,7 @@ Created with Processing - JVMRuntime - @@jdk_folder@@ + @@jvm_runtime@@ JVMMainClassName @@sketch@@ diff --git a/todo.txt b/todo.txt index d51447484..2b03264cc 100644 --- a/todo.txt +++ b/todo.txt @@ -1,10 +1,11 @@ 0223 pde -_ reset font smoothing for everyone to its default by changing the pref +X reset font smoothing for everyone to its default by changing the pref # To reset everyone's default, replaced editor.antialias with editor.smooth # for 2.1. Fonts are unusably gross on OS X (and Linux) w/o smoothing and # the Oracle JVM, and many longtime users have anti-aliasing turned off. X https://github.com/processing/processing/issues/2164 X https://github.com/processing/processing/issues/2160 +X Add option to not embed the Java runtime (saves space, but breakage) _ emacs style errors in commander aren't quite right _ https://github.com/processing/processing/issues/2158