Skip to content

Commit c40214b

Browse files
committed
Add option to not embed the Java runtime
1 parent cca37ba commit c40214b

File tree

6 files changed

+75
-22
lines changed

6 files changed

+75
-22
lines changed

app/src/processing/mode/java/Commander.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class Commander implements RunnerListener {
4848
static final String forceArg = "--force";
4949
static final String outputArg = "--output=";
5050
static final String exportApplicationArg = "--export";
51+
static final String noJavaArg = "--export";
5152
static final String platformArg = "--platform=";
5253
static final String bitsArg = "--bits=";
5354
// static final String preferencesArg = "--preferences=";
@@ -109,6 +110,7 @@ public Commander(String[] args) {
109110
int platform = PApplet.platform; // default to this platform
110111
int platformBits = 0;
111112
int task = HELP;
113+
boolean embedJava = true;
112114

113115
// Turns out the output goes as MacRoman or something else useless.
114116
// http://code.google.com/p/processing/issues/detail?id=1418
@@ -145,6 +147,9 @@ public Commander(String[] args) {
145147

146148
} else if (arg.equals(exportApplicationArg)) {
147149
task = EXPORT;
150+
151+
} else if (arg.equals(noJavaArg)) {
152+
embedJava = false;
148153

149154
} else if (arg.startsWith(platformArg)) {
150155
complainAndQuit("The --platform option has been removed from Processing 2.1.", false);
@@ -156,7 +161,7 @@ public Commander(String[] args) {
156161
// }
157162

158163
} else if (arg.startsWith(bitsArg)) {
159-
complainAndQuit("The --platform option has been removed from Processing 2.1.", false);
164+
complainAndQuit("The --bits option has been removed from Processing 2.1.", false);
160165
// String bitsStr = arg.substring(bitsArg.length());
161166
// if (bitsStr.equals("32")) {
162167
// platformBits = 32;
@@ -279,7 +284,7 @@ public Commander(String[] args) {
279284
Library.hasMultipleArch(platform, build.getImportedLibraries())) {
280285
complainAndQuit("This sketch can be exported for 32- or 64-bit, please specify one.", true);
281286
}
282-
success = build.exportApplication(outputFolder, platform, platformBits);
287+
success = build.exportApplication(outputFolder, platform, platformBits, embedJava);
283288
}
284289
}
285290
}
@@ -369,6 +374,7 @@ static void printCommandLine(PrintStream out) {
369374
out.println("--present Preprocess, compile, and run a sketch full screen.");
370375
out.println();
371376
out.println("--export Export an application.");
377+
out.println("--no-java Do not embed Java. Use at your own risk!");
372378
// out.println("--platform Specify the platform (export to application only).");
373379
// out.println(" Should be one of 'windows', 'macosx', or 'linux'.");
374380
// out.println("--bits Must be specified if libraries are used that are");

app/src/processing/mode/java/JavaBuild.java

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,23 +1118,24 @@ protected boolean exportApplication() throws IOException, SketchException {
11181118

11191119
File folder = null;
11201120
String platformName = Base.getPlatformName();
1121+
boolean embedJava = Preferences.getBoolean("export.application.embed_java");
11211122
if (Library.hasMultipleArch(PApplet.platform, importedLibraries)) {
11221123
if (Base.getNativeBits() == 32) {
11231124
// export the 32-bit version
11241125
folder = new File(sketch.getFolder(), "application." + platformName + "32");
1125-
if (!exportApplication(folder, PApplet.platform, 32)) {
1126+
if (!exportApplication(folder, PApplet.platform, 32, embedJava)) {
11261127
return false;
11271128
}
11281129
} else if (Base.getNativeBits() == 64) {
11291130
// export the 64-bit version
11301131
folder = new File(sketch.getFolder(), "application." + platformName + "64");
1131-
if (!exportApplication(folder, PApplet.platform, 64)) {
1132+
if (!exportApplication(folder, PApplet.platform, 64, embedJava)) {
11321133
return false;
11331134
}
11341135
}
11351136
} else { // just make a single one for this platform
11361137
folder = new File(sketch.getFolder(), "application." + platformName);
1137-
if (!exportApplication(folder, PApplet.platform, 0)) {
1138+
if (!exportApplication(folder, PApplet.platform, 0, embedJava)) {
11381139
return false;
11391140
}
11401141
}
@@ -1147,7 +1148,8 @@ protected boolean exportApplication() throws IOException, SketchException {
11471148
*/
11481149
protected boolean exportApplication(File destFolder,
11491150
int exportPlatform,
1150-
int exportBits) throws IOException, SketchException {
1151+
int exportBits,
1152+
boolean embedJava) throws IOException, SketchException {
11511153
// TODO this should probably be a dialog box instead of a warning
11521154
// on the terminal. And the message should be written better than this.
11531155
// http://code.google.com/p/processing/issues/detail?id=884
@@ -1178,13 +1180,18 @@ protected boolean exportApplication(File destFolder,
11781180
/// on macosx, need to copy .app skeleton since that's
11791181
/// also where the jar files will be placed
11801182
File dotAppFolder = null;
1181-
String jdkFolderName = null;
1183+
// String jdkFolderName = null;
1184+
String jvmRuntime = "";
11821185
if (exportPlatform == PConstants.MACOSX) {
11831186
dotAppFolder = new File(destFolder, sketch.getName() + ".app");
11841187

11851188
File contentsOrig = new File(Base.getJavaHome(), "../../../../..");
1186-
File jdkFolder = new File(Base.getJavaHome(), "../../..");
1187-
jdkFolderName = jdkFolder.getCanonicalFile().getName();
1189+
1190+
if (embedJava) {
1191+
File jdkFolder = new File(Base.getJavaHome(), "../../..");
1192+
String jdkFolderName = jdkFolder.getCanonicalFile().getName();
1193+
jvmRuntime = "<key>JVMRuntime</key>\n <string>" + jdkFolderName + "</string>";
1194+
}
11881195

11891196
// File dotAppSkeleton = mode.getContentFile("application/template.app");
11901197
// Base.copyDir(dotAppSkeleton, dotAppFolder);
@@ -1209,8 +1216,10 @@ protected boolean exportApplication(File destFolder,
12091216
writer.close();
12101217

12111218
// Use faster(?) native copy here (also to do sym links)
1212-
Base.copyDirNative(new File(contentsOrig, "PlugIns"),
1213-
new File(contentsFolder, "PlugIns"));
1219+
if (embedJava) {
1220+
Base.copyDirNative(new File(contentsOrig, "PlugIns"),
1221+
new File(contentsFolder, "PlugIns"));
1222+
}
12141223

12151224
File resourcesFolder = new File(contentsFolder, "Resources");
12161225
Base.copyDir(new File(contentsOrig, "Resources/en.lproj"),
@@ -1243,10 +1252,14 @@ protected boolean exportApplication(File destFolder,
12431252
}
12441253
*/
12451254
} else if (exportPlatform == PConstants.LINUX) {
1246-
Base.copyDirNative(Base.getJavaHome(), new File(destFolder, "java"));
1255+
if (embedJava) {
1256+
Base.copyDirNative(Base.getJavaHome(), new File(destFolder, "java"));
1257+
}
12471258

12481259
} else if (exportPlatform == PConstants.WINDOWS) {
1249-
Base.copyDir(Base.getJavaHome(), new File(destFolder, "java"));
1260+
if (embedJava) {
1261+
Base.copyDir(Base.getJavaHome(), new File(destFolder, "java"));
1262+
}
12501263
}
12511264

12521265

@@ -1480,9 +1493,9 @@ protected boolean exportApplication(File destFolder,
14801493
if (lines[i].indexOf("@@") != -1) {
14811494
StringBuffer sb = new StringBuffer(lines[i]);
14821495
int index = 0;
1483-
while ((index = sb.indexOf("@@jdk_folder@@")) != -1) {
1484-
sb.replace(index, index + "@@jdk_folder@@".length(),
1485-
jdkFolderName);
1496+
while ((index = sb.indexOf("@@jvm_runtime@@")) != -1) {
1497+
sb.replace(index, index + "@@jvm_runtime@@".length(),
1498+
jvmRuntime);
14861499
}
14871500
while ((index = sb.indexOf("@@jvm_options_list@@")) != -1) {
14881501
sb.replace(index, index + "@@jvm_options_list@@".length(),

app/src/processing/mode/java/JavaEditor.java

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,9 @@ protected boolean exportApplicationPrompt() throws IOException, SketchException
266266
label2.setAlignmentX(Component.LEFT_ALIGNMENT);
267267
panel.add(label1);
268268
panel.add(label2);
269-
int wide = label1.getPreferredSize().width;
269+
// The longer line is different between Windows and OS X.
270+
int wide = Math.max(label1.getPreferredSize().width,
271+
label2.getPreferredSize().width);
270272
panel.add(Box.createVerticalStrut(12));
271273

272274
/*
@@ -312,6 +314,9 @@ public void itemStateChanged(ItemEvent e) {
312314
panel.add(platformPanel);
313315
*/
314316

317+
//int indent = new JCheckBox().getPreferredSize().width;
318+
int indent = 0;
319+
315320
final JCheckBox showStopButton = new JCheckBox("Show a Stop button");
316321
showStopButton.setSelected(Preferences.getBoolean("export.application.stop"));
317322
showStopButton.addItemListener(new ItemListener() {
@@ -320,7 +325,7 @@ public void itemStateChanged(ItemEvent e) {
320325
}
321326
});
322327
showStopButton.setEnabled(Preferences.getBoolean("export.application.fullscreen"));
323-
showStopButton.setBorder(new EmptyBorder(3, 13, 6, 13));
328+
showStopButton.setBorder(new EmptyBorder(3, 13 + indent, 6, 13));
324329

325330
final JCheckBox fullScreenButton = new JCheckBox("Full Screen (Present mode)");
326331
fullScreenButton.setSelected(Preferences.getBoolean("export.application.fullscreen"));
@@ -333,10 +338,33 @@ public void itemStateChanged(ItemEvent e) {
333338
});
334339
fullScreenButton.setBorder(new EmptyBorder(3, 13, 3, 13));
335340

341+
boolean embed = Preferences.getBoolean("export.application.embed_java");
342+
final String embedWarning = "Embedding Java makes larger applications";
343+
final String nopeWarning = "Users will have to install the latest Java 7";
344+
final JLabel warningLabel = new JLabel(embed ? embedWarning : nopeWarning);
345+
warningLabel.setBorder(new EmptyBorder(3, 13 + indent, 3, 13));
346+
347+
final JCheckBox embedJavaButton = new JCheckBox("Embed Java");
348+
embedJavaButton.setSelected(embed);
349+
embedJavaButton.addItemListener(new ItemListener() {
350+
public void itemStateChanged(ItemEvent e) {
351+
boolean selected = embedJavaButton.isSelected();
352+
Preferences.setBoolean("export.application.embed_java", selected);
353+
if (selected) {
354+
warningLabel.setText(embedWarning);
355+
} else {
356+
warningLabel.setText(nopeWarning);
357+
}
358+
}
359+
});
360+
embedJavaButton.setBorder(new EmptyBorder(3, 13, 3, 13));
361+
336362
JPanel optionPanel = new JPanel();
337363
optionPanel.setLayout(new BoxLayout(optionPanel, BoxLayout.Y_AXIS));
338364
optionPanel.add(fullScreenButton);
339365
optionPanel.add(showStopButton);
366+
optionPanel.add(embedJavaButton);
367+
optionPanel.add(warningLabel);
340368
optionPanel.setBorder(new TitledBorder("Options"));
341369
// wide = Math.max(wide, platformPanel.getPreferredSize().width);
342370
optionPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
@@ -351,7 +379,7 @@ public void itemStateChanged(ItemEvent e) {
351379
// good = new Dimension(wide, platformPanel.getPreferredSize().height);
352380
// platformPanel.setMaximumSize(good);
353381
good = new Dimension(wide, optionPanel.getPreferredSize().height);
354-
optionPanel.setMaximumSize(good);
382+
// optionPanel.setMaximumSize(good);
355383

356384
String[] options = { "Export", "Cancel" };
357385
final JOptionPane optionPane = new JOptionPane(panel,

core/todo.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
0223 core
22

3+
opengl
4+
X Using sketchQuality() does not work properly with P3D, OPENGL, P2D
5+
X https://github.com/processing/processing/pull/2157
6+
X Fix crashes when the sketch window is resized
7+
X https://github.com/processing/processing/issues/1880
8+
X https://github.com/processing/processing/pull/2156
39

410
high
511
_ Sort out blending differences with P2D/P3D

java/application/Info.plist.tmpl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
<string>Created with Processing</string>
3333
<!-- End of the set that can be customized -->
3434

35-
<key>JVMRuntime</key>
36-
<string>@@jdk_folder@@</string>
35+
@@jvm_runtime@@
3736

3837
<key>JVMMainClassName</key>
3938
<string>@@sketch@@</string>

todo.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
0223 pde
2-
_ reset font smoothing for everyone to its default by changing the pref
2+
X reset font smoothing for everyone to its default by changing the pref
33
# To reset everyone's default, replaced editor.antialias with editor.smooth
44
# for 2.1. Fonts are unusably gross on OS X (and Linux) w/o smoothing and
55
# the Oracle JVM, and many longtime users have anti-aliasing turned off.
66
X https://github.com/processing/processing/issues/2164
77
X https://github.com/processing/processing/issues/2160
8+
X Add option to not embed the Java runtime (saves space, but breakage)
89

910
_ emacs style errors in commander aren't quite right
1011
_ https://github.com/processing/processing/issues/2158

0 commit comments

Comments
 (0)