Skip to content

Commit c25624b

Browse files
committed
make mac bundler work with platform specific native jars, not just common ones
1 parent f410440 commit c25624b

File tree

8 files changed

+61
-27
lines changed

8 files changed

+61
-27
lines changed

README

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
== This is the read me ==
1+
#### This is the read me
2+
23

34
AppBundler is an Ant task for packaging up Desktop Java apps as native
45
executables. It can package Mac OS X .app bundles, Windows EXEs, JNLPs,

build.xml

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
</fileset>
2626
</copy>
2727
</target>
28+
29+
<target name="jar">
30+
<jar destfile="dist/AppBundler.jar" basedir="build/classes"/>
31+
</target>
2832

2933
<target name="clean">
3034
<delete dir="build"/>

src/com/joshondesign/appbundler/NativeLib.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,27 @@ public File[] getOSDirs() {
5454
return new File(baseDir,"native").listFiles();
5555
}
5656

57-
public Iterable<File> getJars() {
57+
public Iterable<File> getCommonJars() {
5858
List<File> jars = new ArrayList<File>();
59+
p("base dir = " + baseDir);
5960
for(File f : baseDir.listFiles()) {
6061
if(!f.isDirectory() && f.exists() && f.getName().endsWith(".jar")) {
6162
jars.add(f);
6263
}
6364
}
6465
return jars;
6566
}
67+
public Iterable<File> getPlatformJars(String osString) {
68+
List<File> jars = new ArrayList<File>();
69+
for(File osDir : getOSDirs()) {
70+
if(osString.equals(osDir.getName())) {
71+
for(File file : osDir.listFiles()) {
72+
if(file.getName().toLowerCase().endsWith(".jar")) {
73+
jars.add(file);
74+
}
75+
}
76+
}
77+
}
78+
return jars;
79+
}
6680
}

src/com/joshondesign/appbundler/Util.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static void copyToFile(File srcFile, File dstFile) throws FileNotFoundExc
3030
}
3131
fin.close();
3232
fout.close();
33-
p("m copied file: " + srcFile.getName());
33+
p("copied file: " + srcFile.getName());
3434
}
3535

3636
private static void p(String s) {
@@ -48,6 +48,6 @@ public static void copyToFile(URL resource, File dstFile) throws FileNotFoundExc
4848
}
4949
in.close();
5050
fout.close();
51-
p("m copied jar: " + resource.toString());
51+
p("copied jar: " + resource.toString());
5252
}
5353
}

src/com/joshondesign/appbundler/mac/MacBundler.java

+32-15
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
* To change this template use File | Settings | File Templates.
2323
*/
2424
public class MacBundler {
25+
26+
private static final String OSNAME = "mac";
2527

2628
public static void start(AppDescription app, String dest_dir) throws Exception {
2729
//create the dir structure
28-
File destDir = new File(dest_dir+"/mac/");
30+
File destDir = new File(dest_dir+"/"+OSNAME+"/");
2931
File appDir = new File(destDir,app.getName()+".app");
3032
appDir.mkdirs();
3133
p("app dir exists = " + appDir.exists());
@@ -40,10 +42,10 @@ public static void start(AppDescription app, String dest_dir) throws Exception {
4042

4143

4244
for(Jar jar : app.getJars()) {
43-
p("processing jar = " + jar.getName() + " os = "+jar.getOS());
45+
//p("processing jar = " + jar.getName() + " os = "+jar.getOS());
4446
if(jar.isOSSpecified()) {
45-
if(!jar.matchesOS("mac")) {
46-
p(" skipping jar");
47+
if(!jar.matchesOS(OSNAME)) {
48+
p(" skipping jar " + jar.getName());
4749
continue;
4850
}
4951
}
@@ -109,13 +111,14 @@ public static void start(AppDescription app, String dest_dir) throws Exception {
109111

110112
// set the bundle bit
111113
try {
112-
Runtime.getRuntime().exec("/Developer/Tools/SetFile -a B "+appDir);
114+
//Runtime.getRuntime().exec("/Developer/Tools/SetFile -a B "+appDir);
113115
} catch (Exception ex) {
114116
ex.printStackTrace();
115117
}
116118
}
117119

118120
private static void processInfoPlist(AppDescription app, File contentsDir) throws Exception {
121+
p("Processing the info plist");
119122

120123
XMLWriter out = new XMLWriter(new File(contentsDir,"Info.plist"));
121124
out.header();
@@ -175,7 +178,15 @@ private static void processInfoPlist(AppDescription app, File contentsDir) throw
175178
out.start("string").text("$JAVAROOT/"+jar.getName()).end();
176179
}
177180
for(NativeLib lib : app.getNativeLibs()) {
178-
for(File jar : lib.getJars()) {
181+
p("native lib: " + lib.getName());
182+
p("getting the common jars");
183+
for(File jar : lib.getCommonJars()) {
184+
p("adding native common jar to plist: " + jar.getName());
185+
out.start("string").text("$JAVAROOT/"+jar.getName()).end();
186+
}
187+
p("getting the platform jars");
188+
for(File jar : lib.getPlatformJars(OSNAME)) {
189+
p("adding native only jar to plist: " + jar.getName());
179190
out.start("string").text("$JAVAROOT/"+jar.getName()).end();
180191
}
181192
}
@@ -206,18 +217,24 @@ private static void p(String s) {
206217
private static void processNatives(File javaDir, AppDescription app) throws IOException {
207218
//track the list of files in the appbundler_tasks.xml
208219
for(NativeLib lib : app.getNativeLibs()) {
209-
p("sucking in native lib: " + lib);
220+
p("=== sucking in native lib: " + lib.getName());
210221
for(File os : lib.getOSDirs()) {
211-
p("os = " + os.getName());
212-
for(File file : os.listFiles()) {
213-
p(" file = " + file.getName());
214-
File destFile = new File(javaDir, file.getName());
215-
p("copying to file: " + destFile);
216-
Util.copyToFile(file, destFile);
222+
//p("os = " + os.getName());
223+
if(OSNAME.equals(os.getName())) {
224+
for(File file : os.listFiles()) {
225+
//p(" file = " + file.getName());
226+
File destFile = new File(javaDir, file.getName());
227+
//p("copying to file: " + destFile);
228+
Util.copyToFile(file, destFile);
229+
}
217230
}
218231
}
219-
for(File jar : lib.getJars()) {
220-
p("copying over native lib jar: " + jar.getName());
232+
for(File jar : lib.getCommonJars()) {
233+
p("copying over native common jar: " + jar.getName());
234+
Util.copyToFile(jar, new File(javaDir, jar.getName()));
235+
}
236+
for(File jar : lib.getPlatformJars(OSNAME)) {
237+
p("copying over native only jar: " + jar.getName());
221238
Util.copyToFile(jar, new File(javaDir, jar.getName()));
222239
}
223240
}

src/com/joshondesign/appbundler/onejar/OneJarBundler.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import java.io.InputStream;
1717
import java.io.OutputStreamWriter;
1818
import java.io.PrintWriter;
19-
import java.io.StringReader;
2019
import java.io.StringWriter;
2120
import java.util.HashSet;
2221
import java.util.Set;
@@ -138,7 +137,7 @@ private static void processNatives(XMLWriter xml, JarOutputStream jarOut, AppDes
138137
xml.end();
139138
}
140139
}
141-
for(File jar : lib.getJars()) {
140+
for(File jar : lib.getCommonJars()) {
142141
p("copying over native lib jar: " + jar.getName());
143142
copyJar(jarOut, jar, writtenNames);
144143
}

src/com/joshondesign/appbundler/webos/WebosBundler.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private static void generateRunScript(File appDir, AppDescription app) throws IO
105105
}
106106
}
107107
}
108-
for(File jar : lib.getJars()) {
108+
for(File jar : lib.getCommonJars()) {
109109
out.print(jar.getName()+":");
110110
}
111111
}
@@ -136,7 +136,7 @@ private static void processNatives(File appDir, AppDescription app, String targe
136136
}
137137
}
138138
}
139-
for(File jar : lib.getJars()) {
139+
for(File jar : lib.getCommonJars()) {
140140
p("copying over native lib jar: " + jar.getName());
141141
Util.copyToFile(jar, new File(appDir, jar.getName()));
142142
}

src/com/joshondesign/appbundler/win/WindowsBundler.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010
import com.joshondesign.appbundler.NativeLib;
1111
import com.joshondesign.appbundler.Util;
1212
import com.joshondesign.xml.XMLWriter;
13-
import java.io.BufferedOutputStream;
13+
1414
import java.io.File;
1515
import java.io.FileNotFoundException;
1616
import java.io.IOException;
1717
import java.io.InputStream;
18-
import java.io.OutputStream;
1918
import java.util.HashMap;
2019
import java.util.Map;
2120

@@ -116,7 +115,7 @@ private static void processNatives(File javaDir, AppDescription app) throws IOEx
116115
Util.copyToFile(file, destFile);
117116
}
118117
}
119-
for(File jar : lib.getJars()) {
118+
for(File jar : lib.getCommonJars()) {
120119
p("copying over native lib jar: " + jar.getName());
121120
Util.copyToFile(jar, new File(javaDir, jar.getName()));
122121
}
@@ -138,7 +137,7 @@ private static void generateProjectFile(XMLWriter xml, AppDescription app) throw
138137
xml.start("classPath").text("lib\\"+jar.getName()).end();
139138
}
140139
for(NativeLib lib : app.getNativeLibs()) {
141-
for(File jar : lib.getJars()) {
140+
for(File jar : lib.getCommonJars()) {
142141
xml.start("classPath").text("lib\\"+jar.getName()).end();
143142
}
144143
}

0 commit comments

Comments
 (0)