@@ -66,8 +66,8 @@ public class AppBundlerTask extends Task {
66
66
private String copyright = "" ;
67
67
68
68
// JVM info properties
69
- private File runtime = null ;
70
69
private String mainClassName = null ;
70
+ private FileSet runtime = null ;
71
71
private ArrayList <File > classPath = new ArrayList <>();
72
72
private ArrayList <File > libraryPath = new ArrayList <>();
73
73
private ArrayList <String > options = new ArrayList <>();
@@ -85,8 +85,6 @@ public class AppBundlerTask extends Task {
85
85
private static final String ARRAY_TAG = "array" ;
86
86
private static final String STRING_TAG = "string" ;
87
87
88
- private static final int BUFFER_SIZE = 1024 ;
89
-
90
88
public void setOutputDirectory (File outputDirectory ) {
91
89
this .outputDirectory = outputDirectory ;
92
90
}
@@ -119,16 +117,16 @@ public void setCopyright(String copyright) {
119
117
this .copyright = copyright ;
120
118
}
121
119
122
- public File getRuntime ( ) {
123
- return runtime ;
120
+ public void setMainClassName ( String mainClassName ) {
121
+ this . mainClassName = mainClassName ;
124
122
}
125
123
126
- public void setRuntime (File runtime ) {
127
- this .runtime = runtime ;
128
- }
124
+ public void addConfiguredRuntime (FileSet runtime ) throws BuildException {
125
+ if (this .runtime != null ) {
126
+ throw new BuildException ("Runtime already specified." );
127
+ }
129
128
130
- public void setMainClassName (String mainClassName ) {
131
- this .mainClassName = mainClassName ;
129
+ this .runtime = runtime ;
132
130
}
133
131
134
132
public void addConfiguredClassPath (FileSet classPath ) {
@@ -142,7 +140,7 @@ public void addConfiguredClassPath(FileSet classPath) {
142
140
}
143
141
}
144
142
145
- public void addConfiguredLibraryPath (FileSet libraryPath ) throws BuildException {
143
+ public void addConfiguredLibraryPath (FileSet libraryPath ) {
146
144
File parent = libraryPath .getDir ();
147
145
148
146
DirectoryScanner directoryScanner = libraryPath .getDirectoryScanner (getProject ());
@@ -226,16 +224,6 @@ public void execute() throws BuildException {
226
224
throw new IllegalStateException ("Copyright is required." );
227
225
}
228
226
229
- if (runtime != null ) {
230
- if (!runtime .exists ()) {
231
- throw new IllegalStateException ("Runtime does not exist." );
232
- }
233
-
234
- if (!runtime .isDirectory ()) {
235
- throw new IllegalStateException ("Invalid runtime." );
236
- }
237
- }
238
-
239
227
if (mainClassName == null ) {
240
228
throw new IllegalStateException ("Main class name is required." );
241
229
}
@@ -288,7 +276,31 @@ public void execute() throws BuildException {
288
276
289
277
// Copy runtime to PlugIns folder (if specified)
290
278
if (runtime != null ) {
291
- copy (runtime , new File (plugInsDirectory , runtime .getName ()));
279
+ // Create root directory
280
+ File runtimeDirectory = runtime .getDir ();
281
+ File pluginDirectory = new File (plugInsDirectory , runtimeDirectory .getName ());
282
+ pluginDirectory .mkdir ();
283
+
284
+ // Create Contents directory
285
+ File runtimeContentsDirectory = new File (runtimeDirectory , "Contents" );
286
+ File pluginContentsDirectory = new File (pluginDirectory , runtimeContentsDirectory .getName ());
287
+ pluginContentsDirectory .mkdir ();
288
+
289
+ // Copy MacOS directory
290
+ File runtimeMacOSDirectory = new File (runtimeContentsDirectory , "MacOS" );
291
+ copy (runtimeMacOSDirectory , new File (pluginContentsDirectory , runtimeMacOSDirectory .getName ()));
292
+
293
+ // Copy Info.plist file
294
+ File runtimeInfoPlistFile = new File (runtimeContentsDirectory , "Info.plist" );
295
+ copy (runtimeInfoPlistFile , new File (pluginContentsDirectory , runtimeInfoPlistFile .getName ()));
296
+
297
+ // Copy included contents of Home directory
298
+ DirectoryScanner directoryScanner = runtime .getDirectoryScanner (getProject ());
299
+ String [] includedFiles = directoryScanner .getIncludedFiles ();
300
+
301
+ for (int i = 0 ; i < includedFiles .length ; i ++) {
302
+ copy (new File (runtimeDirectory , includedFiles [i ]), new File (pluginDirectory , includedFiles [i ]));
303
+ }
292
304
}
293
305
294
306
// Copy class path entries to Java folder
@@ -357,7 +369,7 @@ private void writeInfoPlist(File file) throws IOException {
357
369
358
370
// Write runtime
359
371
if (runtime != null ) {
360
- writeProperty (xout , "JVMRuntime" , runtime .getName ());
372
+ writeProperty (xout , "JVMRuntime" , runtime .getDir (). getName ());
361
373
}
362
374
363
375
// Write main class name
@@ -465,6 +477,8 @@ private static void copy(File source, File destination) throws IOException {
465
477
Path sourcePath = source .toPath ();
466
478
Path destinationPath = destination .toPath ();
467
479
480
+ destination .getParentFile ().mkdirs ();
481
+
468
482
Files .copy (sourcePath , destinationPath , StandardCopyOption .REPLACE_EXISTING , LinkOption .NOFOLLOW_LINKS );
469
483
470
484
if (Files .isDirectory (sourcePath , LinkOption .NOFOLLOW_LINKS )) {
0 commit comments