Skip to content

Commit a9942e5

Browse files
committed
fix code signing, color checking, other misc for export
1 parent 8345a5e commit a9942e5

7 files changed

Lines changed: 354 additions & 112 deletions

File tree

app/src/processing/app/ColorChooser.java

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939

4040

4141
/**
42-
* Generic color selector frame, pulled from the Tool object.
42+
* Generic color selector frame, pulled from the Tool object. API not really
43+
* worked out here (what should the constructor be? how flexible?) So use with
44+
* caution and be ready for it to break in future releases.
4345
*/
4446
public class ColorChooser { //extends JFrame implements DocumentListener {
4547

@@ -60,14 +62,13 @@ public class ColorChooser { //extends JFrame implements DocumentListener {
6062
JDialog window;
6163

6264

63-
public String getMenuTitle() {
64-
return "Color Selector";
65-
}
65+
// public String getMenuTitle() {
66+
// return "Color Selector";
67+
// }
6668

6769

68-
public ColorChooser(Frame owner, boolean modal,
69-
String buttonName, ActionListener buttonListener) {
70-
//window = new jdi
70+
public ColorChooser(Frame owner, boolean modal, Color initialColor,
71+
String buttonName, ActionListener buttonListener) {
7172
//super("Color Selector");
7273
window = new JDialog(owner, "Color Selector", modal);
7374
window.getContentPane().setLayout(new BorderLayout());
@@ -93,7 +94,7 @@ public ColorChooser(Frame owner, boolean modal,
9394
box.add(sliderBox);
9495
box.add(Box.createHorizontalStrut(10));
9596

96-
box.add(createColorFields());
97+
box.add(createColorFields(buttonName, buttonListener));
9798
// System.out.println("1: " + hexField.getInsets());
9899

99100
box.add(Box.createHorizontalStrut(10));
@@ -117,12 +118,12 @@ public ColorChooser(Frame owner, boolean modal,
117118
window.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
118119
window.addWindowListener(new WindowAdapter() {
119120
public void windowClosing(WindowEvent e) {
120-
hideSelector();
121+
hide();
121122
}
122123
});
123124
Toolkit.registerWindowCloseKeys(window.getRootPane(), new ActionListener() {
124125
public void actionPerformed(ActionEvent actionEvent) {
125-
hideSelector();
126+
hide();
126127
}
127128
});
128129

@@ -137,20 +138,21 @@ public void actionPerformed(ActionEvent actionEvent) {
137138
blueField.getDocument().addDocumentListener(colorListener);
138139
hexField.getDocument().addDocumentListener(colorListener);
139140

141+
setColor(initialColor);
140142
// System.out.println("4: " + hexField.getInsets());
141143
}
142144

143145

144146
//hexField.setText("#FFFFFF");
145147

146148

147-
public void showSelector() {
149+
public void show() {
148150
window.setVisible(true);
149151
window.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
150152
}
151153

152154

153-
public void hideSelector() {
155+
public void hide() {
154156
window.setVisible(false);
155157
}
156158

@@ -160,6 +162,11 @@ public Color getColor() {
160162
}
161163

162164

165+
public void setColor(Color color) {
166+
updateRGB(color.getRGB());
167+
}
168+
169+
163170
public String getHexColor() {
164171
return "#" + PApplet.hex(red, 2) + PApplet.hex(green, 2) + PApplet.hex(blue, 2);
165172
}
@@ -313,7 +320,7 @@ public void run() {
313320
}
314321

315322

316-
protected Container createColorFields() {
323+
protected Container createColorFields(String buttonName, ActionListener buttonListener) {
317324
Box box = Box.createVerticalBox();
318325
box.setAlignmentY(0);
319326

@@ -403,7 +410,8 @@ public void paintComponent(Graphics g) {
403410
row = Box.createHorizontalBox();
404411
row.add(createFixedLabel(""));
405412
// Windows needs extra space, OS X and Linux do not
406-
final int hexCount = Base.isWindows() ? 7 : 5;
413+
// Mac OS X needs 6 because #CCCCCC is quite wide
414+
final int hexCount = Base.isWindows() ? 7 : 6;
407415
row.add(hexField = new NumberField(hexCount, true));
408416
row.add(Box.createHorizontalGlue());
409417
box.add(row);
@@ -421,19 +429,18 @@ public void paintComponent(Graphics g) {
421429

422430
//
423431

424-
/*
425432
row = Box.createHorizontalBox();
426433
if (Base.isMacOS()) {
427434
row.add(Box.createHorizontalStrut(11));
428435
} else {
429436
row.add(createFixedLabel(""));
430437
}
431-
JButton button = new JButton("Select");
438+
JButton button = new JButton(buttonName);
439+
button.addActionListener(buttonListener);
432440
//System.out.println("button: " + button.getInsets());
433441
row.add(button);
434442
row.add(Box.createHorizontalGlue());
435443
box.add(row);
436-
*/
437444

438445
//
439446

@@ -533,8 +540,7 @@ public Dimension getMaximumSize() {
533540

534541
public void keyPressed() {
535542
if (key == ESC) {
536-
//ColorSelector.this.setVisible(false);
537-
hideSelector();
543+
ColorChooser.this.hide();
538544
// don't quit out of processing
539545
// http://dev.processing.org/bugs/show_bug.cgi?id=1006
540546
key = 0;
@@ -604,8 +610,7 @@ public Dimension getMaximumSize() {
604610

605611
public void keyPressed() {
606612
if (key == ESC) {
607-
//ColorSelector.this.setVisible(false);
608-
hideSelector();
613+
ColorChooser.this.hide();
609614
// don't quit out of processing
610615
// http://dev.processing.org/bugs/show_bug.cgi?id=1006
611616
key = 0;

app/src/processing/app/Preferences.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,8 @@ public void actionPerformed(ActionEvent e) {
430430
deletePreviousBox.setBounds(left, top, d.width + 10, d.height);
431431
right = Math.max(right, left + d.width);
432432
top += d.height + GUI_BETWEEN;
433-
434-
433+
434+
435435
// // [ ] Use external editor
436436
//
437437
// externalEditorBox = new JCheckBox("Use external editor");

app/src/processing/app/exec/ProcessHelper.java

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -128,37 +128,19 @@ public ProcessResult execute(String outgoing) throws InterruptedException, IOExc
128128
}
129129

130130

131-
// static public ProcessResult execute(String exe, String[] args, File dir)
132-
// throws InterruptedException, IOException {
133-
// final StringWriter outWriter = new StringWriter();
134-
// final StringWriter errWriter = new StringWriter();
135-
// final long startTime = System.currentTimeMillis();
136-
//
137-
// final String prettyCommand = exe + " " + PApplet.join(args, " ");
138-
// System.out.println("pretty cmd is " + prettyCommand);
139-
// final Process process = dir == null ?
140-
// Runtime.getRuntime().exec(exe, args) :
141-
// Runtime.getRuntime().exec(exe, args, dir);
142-
// ProcessRegistry.watch(process);
143-
// try {
144-
// String title = prettyCommand;
145-
// new StreamPump(process.getInputStream(), "out: " + title).addTarget(outWriter).start();
146-
// new StreamPump(process.getErrorStream(), "err: " + title).addTarget(errWriter).start();
147-
// try {
148-
// final int result = process.waitFor();
149-
// final long time = System.currentTimeMillis() - startTime;
150-
// // System.err.println("ProcessHelper: <<<<< "
151-
// // + Thread.currentThread().getId() + " " + cmd[0] + " (" + time
152-
// // + "ms)");
153-
// return new ProcessResult(prettyCommand, result, outWriter.toString(),
154-
// errWriter.toString(), time);
155-
// } catch (final InterruptedException e) {
156-
// System.err.println("Interrupted: " + prettyCommand);
157-
// throw e;
158-
// }
159-
// } finally {
160-
// process.destroy();
161-
// ProcessRegistry.unwatch(process);
162-
// }
163-
// }
131+
static public boolean ffs(final String... cmd) {
132+
try {
133+
ProcessHelper helper = new ProcessHelper(cmd);
134+
ProcessResult result = helper.execute();
135+
if (result.succeeded()) {
136+
return true;
137+
}
138+
System.out.println(result.getStdout());
139+
System.err.println(result.getStderr());
140+
141+
} catch (Exception e) {
142+
e.printStackTrace();
143+
}
144+
return false;
145+
}
164146
}

app/src/processing/app/tools/ColorSelector.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import processing.app.*;
2525

26+
import java.awt.Color;
2627
import java.awt.datatransfer.Clipboard;
2728
import java.awt.datatransfer.StringSelection;
2829
import java.awt.event.*;
@@ -52,7 +53,8 @@ public String getMenuTitle() {
5253

5354
public void init(Editor editor) {
5455
if (selector == null) {
55-
selector = new ColorChooser(editor, false, "Copy", new ActionListener() {
56+
selector = new ColorChooser(editor, false, Color.WHITE,
57+
"Copy", new ActionListener() {
5658

5759
@Override
5860
public void actionPerformed(ActionEvent e) {
@@ -65,6 +67,6 @@ public void actionPerformed(ActionEvent e) {
6567

6668

6769
public void run() {
68-
selector.showSelector();
70+
selector.show();
6971
}
7072
}

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

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import org.apache.tools.ant.ProjectHelper;
3333

3434
import processing.app.*;
35+
import processing.app.exec.ProcessHelper;
36+
import processing.app.exec.ProcessResult;
3537
import processing.core.*;
3638
import processing.data.XML;
3739
import processing.mode.java.preproc.*;
@@ -1109,32 +1111,36 @@ protected boolean exportApplication() throws IOException, SketchException {
11091111
return false;
11101112
}
11111113

1112-
/*
11131114
File folder = null;
11141115
for (String platformName : PConstants.platformNames) {
11151116
int platform = Base.getPlatformIndex(platformName);
1117+
1118+
// Can only embed Java on the native platform
1119+
boolean embedJava = (platform == PApplet.platform) &&
1120+
Preferences.getBoolean("export.application.embed_java");
1121+
11161122
if (Preferences.getBoolean("export.application.platform." + platformName)) {
11171123
if (Library.hasMultipleArch(platform, importedLibraries)) {
11181124
// export the 32-bit version
11191125
folder = new File(sketch.getFolder(), "application." + platformName + "32");
1120-
if (!exportApplication(folder, platform, 32)) {
1126+
if (!exportApplication(folder, platform, 32, embedJava && Base.getNativeBits() == 32)) {
11211127
return false;
11221128
}
11231129
// export the 64-bit version
11241130
folder = new File(sketch.getFolder(), "application." + platformName + "64");
1125-
if (!exportApplication(folder, platform, 64)) {
1131+
if (!exportApplication(folder, platform, 64, embedJava && Base.getNativeBits() == 64)) {
11261132
return false;
11271133
}
11281134
} else { // just make a single one for this platform
11291135
folder = new File(sketch.getFolder(), "application." + platformName);
1130-
if (!exportApplication(folder, platform, 0)) {
1136+
if (!exportApplication(folder, platform, 0, embedJava)) {
11311137
return false;
11321138
}
11331139
}
11341140
}
11351141
}
1136-
*/
1137-
1142+
1143+
/*
11381144
File folder = null;
11391145
String platformName = Base.getPlatformName();
11401146
boolean embedJava = Preferences.getBoolean("export.application.embed_java");
@@ -1158,6 +1164,7 @@ protected boolean exportApplication() throws IOException, SketchException {
11581164
return false;
11591165
}
11601166
}
1167+
*/
11611168
return true; // all good
11621169
}
11631170

@@ -1200,6 +1207,7 @@ protected boolean exportApplication(File destFolder,
12001207
/// also where the jar files will be placed
12011208
File dotAppFolder = null;
12021209
String jvmRuntime = "";
1210+
String jdkPath = null;
12031211
if (exportPlatform == PConstants.MACOSX) {
12041212
dotAppFolder = new File(destFolder, sketch.getName() + ".app");
12051213

@@ -1209,6 +1217,7 @@ protected boolean exportApplication(File destFolder,
12091217
File jdkFolder = new File(Base.getJavaHome(), "../../..");
12101218
String jdkFolderName = jdkFolder.getCanonicalFile().getName();
12111219
jvmRuntime = "<key>JVMRuntime</key>\n <string>" + jdkFolderName + "</string>";
1220+
jdkPath = new File(dotAppFolder, "Contents/PlugIns/" + jdkFolderName + ".jdk").getAbsolutePath();
12121221
}
12131222

12141223
File contentsFolder = new File(dotAppFolder, "Contents");
@@ -1489,6 +1498,15 @@ protected boolean exportApplication(File destFolder,
14891498
pw.flush();
14901499
pw.close();
14911500

1501+
// attempt to code sign if the Xcode tools appear to be installed
1502+
if (Base.isMacOS() && new File("/usr/bin/codesign_allocate").exists()) {
1503+
if (embedJava) {
1504+
ProcessHelper.ffs("codesign", "--force", "--sign", "-", jdkPath);
1505+
}
1506+
String appPath = dotAppFolder.getAbsolutePath();
1507+
ProcessHelper.ffs("codesign", "--force", "--sign", "-", appPath);
1508+
}
1509+
14921510
} else if (exportPlatform == PConstants.WINDOWS) {
14931511
File buildFile = new File(destFolder, "launch4j-build.xml");
14941512
File configFile = new File(destFolder, "launch4j-config.xml");

0 commit comments

Comments
 (0)