Skip to content

Commit 0b83cad

Browse files
committed
hoisting some code from Java Mode for use with Jython (also fixes processing#601)
1 parent 750d3f3 commit 0b83cad

7 files changed

Lines changed: 68 additions & 51 deletions

File tree

app/src/processing/app/platform/MacPlatform.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import processing.app.Base;
3535
import processing.app.Messages;
3636
import processing.app.ui.About;
37+
import processing.core.PApplet;
38+
import processing.data.StringList;
3739

3840

3941
/**
@@ -148,6 +150,36 @@ protected String getDocumentsFolder() throws FileNotFoundException {
148150
}
149151

150152

153+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
154+
155+
156+
static private Boolean xcodeInstalled;
157+
158+
static public boolean isXcodeInstalled() {
159+
if (xcodeInstalled == null) {
160+
// Note that xcode-select is *not* an xcrun tool: it's part of the OS.
161+
// pkgutil --file-info /usr/bin/xcode-select
162+
// https://stackoverflow.com/a/32752859/18247494
163+
StringList stdout = new StringList();
164+
StringList stderr = new StringList();
165+
int result = PApplet.exec(stdout, stderr, "/usr/bin/xcode-select", "-p");
166+
167+
// Returns 0 if installed, 2 if not (-1 if exception)
168+
// http://stackoverflow.com/questions/15371925
169+
xcodeInstalled = (result == 0);
170+
}
171+
return xcodeInstalled;
172+
}
173+
174+
175+
static public void resetXcodeInstalled() {
176+
xcodeInstalled = null; // give them another chance
177+
}
178+
179+
180+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
181+
182+
151183
/*
152184
// Some of these are supposedly constants in com.apple.eio.FileManager,
153185
// however they don't seem to link properly from Eclipse.

app/src/processing/app/ui/ExportPrompt.java

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@
2121
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2222
*/
2323

24-
package processing.mode.java;
24+
package processing.app.ui;
2525

2626
import processing.app.Language;
2727
import processing.app.Platform;
2828
import processing.app.Preferences;
2929
import processing.app.SketchException;
30-
import processing.app.ui.ColorChooser;
31-
import processing.app.ui.Editor;
30+
import processing.app.platform.MacPlatform;
3231
import processing.core.PApplet;
3332
import processing.data.StringDict;
3433
import processing.data.StringList;
@@ -41,15 +40,14 @@
4140
import java.awt.event.ActionListener;
4241
import java.awt.event.MouseAdapter;
4342
import java.awt.event.MouseEvent;
44-
import java.io.IOException;
4543
import java.util.ArrayList;
4644
import java.util.List;
4745

4846

4947
public class ExportPrompt {
5048
static final String MACOS_EXPORT_WIKI =
5149
"https://github.com/processing/processing4/wiki/Exporting-Applications#macos";
52-
static final String EXPORT_VARIANTS = "export.application.variants";
50+
static public final String EXPORT_VARIANTS = "export.application.variants";
5351

5452
static public final String JAVA_DOWNLOAD_URL = "https://adoptium.net/";
5553

@@ -59,12 +57,14 @@ public class ExportPrompt {
5957
List<JCheckBox> variantButtons;
6058

6159
final Editor editor;
60+
final Runnable callback;
6261

63-
static ExportPrompt inst;
62+
// static ExportPrompt inst;
6463

6564

66-
private ExportPrompt(JavaEditor editor) {
65+
public ExportPrompt(Editor editor, Runnable callback) {
6766
this.editor = editor;
67+
this.callback = callback;
6868

6969
String pref = Preferences.get(EXPORT_VARIANTS);
7070
if (pref == null) {
@@ -111,15 +111,7 @@ protected boolean anyExportButton() {
111111
}
112112

113113

114-
static protected boolean trigger(JavaEditor editor) throws IOException, SketchException {
115-
if (inst == null) {
116-
inst = new ExportPrompt(editor);
117-
}
118-
return inst.trigger();
119-
}
120-
121-
122-
protected boolean trigger() throws IOException, SketchException {
114+
public boolean trigger() throws SketchException {
123115
final JDialog dialog = new JDialog(editor, Language.text("export"), true);
124116

125117
JPanel panel = new JPanel();
@@ -264,7 +256,7 @@ public void mousePressed(MouseEvent event) {
264256
"or they will be reported as damaged or unsafe. ";
265257

266258
//if (false && new File("/usr/bin/codesign_allocate").exists()) {
267-
if (JavaBuild.isXcodeInstalled()) {
259+
if (MacPlatform.isXcodeInstalled()) {
268260
thePain += "<br/>" +
269261
"This application will be “self-signed” which means that " +
270262
"macOS may complain that it comes from an unidentified developer. " +
@@ -293,14 +285,14 @@ public void mousePressed(MouseEvent event) {
293285

294286
area.addMouseListener(new MouseAdapter() {
295287
public void mousePressed(MouseEvent event) {
296-
if (JavaBuild.isXcodeInstalled()) {
288+
if (MacPlatform.isXcodeInstalled()) {
297289
Platform.openURL(MACOS_EXPORT_WIKI);
298290

299291
} else {
300292
// Launch the process asynchronously
301293
PApplet.exec("xcode-select", "--install");
302294
// Reset the installed state so that the message will change.
303-
JavaBuild.resetXcodeInstalled();
295+
MacPlatform.resetXcodeInstalled();
304296
// Close the window so that we can rebuild it with different text
305297
// once they've finished installing the Command Line Tools.
306298
dialog.setVisible(false);
@@ -349,7 +341,8 @@ public void mousePressed(MouseEvent event) {
349341

350342
Object value = optionPane.getValue();
351343
if (value.equals(exportButton)) {
352-
return ((JavaMode) editor.getMode()).handleExportApplication(editor.getSketch());
344+
//return ((JavaMode) editor.getMode()).handleExportApplication(editor.getSketch());
345+
callback.run();
353346
} else if (value.equals(cancelButton) || value.equals(-1)) {
354347
// closed window by hitting Cancel or ESC
355348
editor.statusNotice(Language.text("export.notice.exporting.cancel"));

core/todo.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1292 (4.1.4)
1+
1292 (4.1.4 or 4.2)
22

33

44
_ args passed to main() aren't working

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

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
Part of the Processing project - http://processing.org
55
6-
Copyright (c) 2012-19 The Processing Foundation
6+
Copyright (c) 2012-23 The Processing Foundation
77
Copyright (c) 2004-12 Ben Fry and Casey Reas
88
Copyright (c) 2001-04 Massachusetts Institute of Technology
99
@@ -36,6 +36,8 @@
3636

3737
import processing.app.*;
3838
import processing.app.exec.ProcessHelper;
39+
import processing.app.platform.MacPlatform;
40+
import processing.app.ui.ExportPrompt;
3941
import processing.core.PApplet;
4042
import processing.core.PConstants;
4143
import processing.data.StringList;
@@ -915,7 +917,7 @@ protected boolean exportApplication(File destFolder,
915917
// attempt to code sign if the Xcode tools appear to be installed
916918
String appPath = dotAppFolder.getAbsolutePath();
917919
if (Platform.isMacOS()) {
918-
if (isXcodeInstalled()) {
920+
if (MacPlatform.isXcodeInstalled()) {
919921
// if (embedJava) {
920922
// ProcessHelper.ffs("codesign", "--force", "--sign", "--deep", "-", jdkPath);
921923
// }
@@ -1084,30 +1086,6 @@ static public String[] getArgsJavaFX(String modulePath) {
10841086
}
10851087

10861088

1087-
static Boolean xcodeInstalled;
1088-
1089-
static protected boolean isXcodeInstalled() {
1090-
if (xcodeInstalled == null) {
1091-
// Note that xcode-select is *not* an xcrun tool: it's part of the OS.
1092-
// pkgutil --file-info /usr/bin/xcode-select
1093-
// https://stackoverflow.com/a/32752859/18247494
1094-
StringList stdout = new StringList();
1095-
StringList stderr = new StringList();
1096-
int result = PApplet.exec(stdout, stderr, "/usr/bin/xcode-select", "-p");
1097-
1098-
// Returns 0 if installed, 2 if not (-1 if exception)
1099-
// http://stackoverflow.com/questions/15371925
1100-
xcodeInstalled = (result == 0);
1101-
}
1102-
return xcodeInstalled;
1103-
}
1104-
1105-
1106-
static protected void resetXcodeInstalled() {
1107-
xcodeInstalled = null; // give them another chance
1108-
}
1109-
1110-
11111089
/**
11121090
* Run the launch4j build.xml file through ant to create the exe.
11131091
* Most of this code was lifted from Android mode.

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
Part of the Processing project - http://processing.org
55
6-
Copyright (c) 2012-22 The Processing Foundation
6+
Copyright (c) 2012-23 The Processing Foundation
77
Copyright (c) 2004-12 Ben Fry and Casey Reas
88
Copyright (c) 2001-04 Massachusetts Institute of Technology
99
@@ -475,7 +475,15 @@ public void handleExportApplication() {
475475
if (handleExportCheckModified()) {
476476
statusNotice(Language.text("export.notice.exporting"));
477477
try {
478-
if (ExportPrompt.trigger(this)) {
478+
ExportPrompt ep = new ExportPrompt(this, () -> {
479+
try {
480+
jmode.handleExportApplication(getSketch());
481+
} catch (Exception e) {
482+
statusNotice(Language.text("export.notice.exporting.error"));
483+
e.printStackTrace();
484+
}
485+
});
486+
if (ep.trigger()) {
479487
Platform.openFolder(sketch.getFolder());
480488
statusNotice(Language.text("export.notice.exporting.done"));
481489
//} else {

java/src/processing/mode/java/JavaMode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
Part of the Processing project - http://processing.org
55
6-
Copyright (c) 2010-11 Ben Fry and Casey Reas
6+
Copyright (c) 2010-23 Ben Fry and Casey Reas
77
Copyright (c) 2012-19 The Processing Foundation
88
99
This program is free software; you can redistribute it and/or modify

todo.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
1292 (4.1.4)
1+
1292 (4.1.4 or 4.2)
2+
X application exported to the wrong folder
3+
X https://github.com/processing/processing4/issues/601
4+
5+
python
6+
X move ExportDialog to processing.app.ui (out of Java Mode) so it can be used by Jython
7+
X move isXcodeInstalled() methods from JavaBuild into MacPlatform
28

39

410
manager

0 commit comments

Comments
 (0)