Skip to content

Commit 1e87b76

Browse files
committed
working on OS X export with embedded JRE
1 parent e4a2c08 commit 1e87b76

5 files changed

Lines changed: 82 additions & 15 deletions

File tree

app/src/processing/app/Base.java

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2401,12 +2401,26 @@ static public File getContentFile(String name) {
24012401
}
24022402

24032403

2404-
// static public File getJavaHome() {
2405-
// }
2404+
static public File getJavaHome() {
2405+
if (isMacOS()) {
2406+
//return "Contents/PlugIns/jdk1.7.0_40.jdk/Contents/Home/jre/bin/java";
2407+
File[] plugins = getContentFile("../PlugIns").listFiles(new FilenameFilter() {
2408+
public boolean accept(File dir, String name) {
2409+
return name.endsWith(".jdk") && dir.isDirectory();
2410+
}
2411+
});
2412+
return new File(plugins[0], "Contents/Home/jre");
2413+
}
2414+
// On all other platforms, it's the 'java' folder adjacent to Processing
2415+
return getContentFile("java");
2416+
}
24062417

24072418

24082419
/** Get the path to the embedded Java executable. */
24092420
static public String getJavaPath() {
2421+
String javaPath = "bin/java" + (isWindows() ? ".exe" : "");
2422+
return new File(getJavaHome(), javaPath).getAbsolutePath();
2423+
/*
24102424
if (isMacOS()) {
24112425
//return "Contents/PlugIns/jdk1.7.0_40.jdk/Contents/Home/jre/bin/java";
24122426
File[] plugins = getContentFile("../PlugIns").listFiles(new FilenameFilter() {
@@ -2429,6 +2443,7 @@ public boolean accept(File dir, String name) {
24292443
System.err.println("No appropriate platform found. " +
24302444
"Hoping that Java is in the path.");
24312445
return Base.isWindows() ? "java.exe" : "java";
2446+
*/
24322447
}
24332448

24342449

@@ -2569,6 +2584,7 @@ static public void copyFile(File sourceFile,
25692584
to = null;
25702585

25712586
targetFile.setLastModified(sourceFile.lastModified());
2587+
targetFile.setExecutable(sourceFile.canExecute());
25722588
}
25732589

25742590

@@ -2639,6 +2655,28 @@ static public void copyDir(File sourceDir,
26392655
}
26402656
}
26412657
}
2658+
2659+
2660+
static public void copyDirNative(File sourceDir,
2661+
File targetDir) throws IOException {
2662+
Process process = null;
2663+
if (Base.isMacOS() || Base.isLinux()) {
2664+
process = Runtime.getRuntime().exec(new String[] {
2665+
"cp", "-a", sourceDir.getAbsolutePath(), targetDir.getAbsolutePath()
2666+
});
2667+
} else {
2668+
// TODO implement version that uses XCOPY here on Windows
2669+
throw new RuntimeException("Not yet implemented on Windows");
2670+
}
2671+
try {
2672+
int result = process.waitFor();
2673+
if (result != 0) {
2674+
throw new IOException("Error while copying (result " + result + ")");
2675+
}
2676+
} catch (InterruptedException e) {
2677+
e.printStackTrace();
2678+
}
2679+
}
26422680

26432681

26442682
/**

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

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,11 +1162,42 @@ protected boolean exportApplication(File destFolder,
11621162
File dotAppFolder = null;
11631163
if (exportPlatform == PConstants.MACOSX) {
11641164
dotAppFolder = new File(destFolder, sketch.getName() + ".app");
1165-
// String APP_SKELETON = "skeleton.app";
1166-
//File dotAppSkeleton = new File(folder, APP_SKELETON);
1167-
File dotAppSkeleton = mode.getContentFile("application/template.app");
1168-
Base.copyDir(dotAppSkeleton, dotAppFolder);
11691165

1166+
File contentsOrig = new File(Base.getJavaHome(), "../../../../..");
1167+
1168+
// File dotAppSkeleton = mode.getContentFile("application/template.app");
1169+
// Base.copyDir(dotAppSkeleton, dotAppFolder);
1170+
File contentsFolder = new File(dotAppFolder, "Contents");
1171+
contentsFolder.mkdirs();
1172+
1173+
// Info.plist will be written later
1174+
1175+
// set the jar folder to a different location than windows/linux
1176+
//jarFolder = new File(dotAppFolder, "Contents/Resources/Java");
1177+
jarFolder = new File(contentsFolder, "Java");
1178+
1179+
File macosFolder = new File(contentsFolder, "MacOS");
1180+
macosFolder.mkdirs();
1181+
Base.copyFile(new File(contentsOrig, "MacOS/Processing"),
1182+
new File(contentsFolder, "MacOS/" + sketch.getName()));
1183+
1184+
File pkgInfo = new File(contentsFolder, "PkgInfo");
1185+
PrintWriter writer = PApplet.createWriter(pkgInfo);
1186+
writer.println("APPL????");
1187+
writer.flush();
1188+
writer.close();
1189+
1190+
// Use faster(?) native copy here (also to do sym links)
1191+
Base.copyDirNative(new File(contentsOrig, "PlugIns"),
1192+
new File(contentsFolder, "PlugIns"));
1193+
1194+
File resourcesFolder = new File(contentsFolder, "Resources");
1195+
Base.copyDir(new File(contentsOrig, "Resources/en.lproj"),
1196+
new File(resourcesFolder, "en.lproj"));
1197+
Base.copyFile(mode.getContentFile("application/sketch.icns"),
1198+
new File(resourcesFolder, "sketch.icns"));
1199+
1200+
/*
11701201
String stubName = "Contents/MacOS/JavaApplicationStub";
11711202
// need to set the stub to executable
11721203
// will work on osx or *nix, but just dies on windows, oh well..
@@ -1189,13 +1220,11 @@ protected boolean exportApplication(File destFolder,
11891220
String stubPath = stubFile.getAbsolutePath();
11901221
Runtime.getRuntime().exec(new String[] { "chmod", "+x", stubPath });
11911222
}
1192-
1193-
// set the jar folder to a different location than windows/linux
1194-
jarFolder = new File(dotAppFolder, "Contents/Resources/Java");
1223+
*/
11951224
}
11961225

11971226

1198-
/// make the jar folder (windows and linux)
1227+
/// make the jar folder (all platforms)
11991228

12001229
if (!jarFolder.exists()) jarFolder.mkdirs();
12011230

build/build.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -542,11 +542,11 @@
542542
<option value="-Xmx256M" />
543543
-->
544544

545-
<option value="-Dapple.laf.useScreenMenuBar=true"/>
546-
<option value="-Dcom.apple.macos.use-file-dialog-packages=true"/>
547-
<option value="-Dcom.apple.macos.useScreenMenuBar=true"/>
548-
<option value="-Dcom.apple.mrj.application.apple.menu.about.name=${bundle.name}"/>
549-
<option value="-Dcom.apple.smallTabs=true"/>
545+
<option value="-Dapple.laf.useScreenMenuBar=true" />
546+
<option value="-Dcom.apple.macos.use-file-dialog-packages=true" />
547+
<option value="-Dcom.apple.macos.useScreenMenuBar=true" />
548+
<option value="-Dcom.apple.mrj.application.apple.menu.about.name=${bundle.name}" />
549+
<option value="-Dcom.apple.smallTabs=true" />
550550

551551
<!--
552552
the old options; most of these are probably no longer useful

build/macosx/appbundler.jar

76 Bytes
Binary file not shown.

java/application/sketch.icns

171 KB
Binary file not shown.

0 commit comments

Comments
 (0)