@@ -66,8 +66,8 @@ public class AppBundlerTask extends Task {
6666 private String copyright = "" ;
6767
6868 // JVM info properties
69- private File runtime = null ;
7069 private String mainClassName = null ;
70+ private FileSet runtime = null ;
7171 private ArrayList <File > classPath = new ArrayList <>();
7272 private ArrayList <File > libraryPath = new ArrayList <>();
7373 private ArrayList <String > options = new ArrayList <>();
@@ -85,8 +85,6 @@ public class AppBundlerTask extends Task {
8585 private static final String ARRAY_TAG = "array" ;
8686 private static final String STRING_TAG = "string" ;
8787
88- private static final int BUFFER_SIZE = 1024 ;
89-
9088 public void setOutputDirectory (File outputDirectory ) {
9189 this .outputDirectory = outputDirectory ;
9290 }
@@ -119,16 +117,16 @@ public void setCopyright(String copyright) {
119117 this .copyright = copyright ;
120118 }
121119
122- public File getRuntime ( ) {
123- return runtime ;
120+ public void setMainClassName ( String mainClassName ) {
121+ this . mainClassName = mainClassName ;
124122 }
125123
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+ }
129128
130- public void setMainClassName (String mainClassName ) {
131- this .mainClassName = mainClassName ;
129+ this .runtime = runtime ;
132130 }
133131
134132 public void addConfiguredClassPath (FileSet classPath ) {
@@ -142,7 +140,7 @@ public void addConfiguredClassPath(FileSet classPath) {
142140 }
143141 }
144142
145- public void addConfiguredLibraryPath (FileSet libraryPath ) throws BuildException {
143+ public void addConfiguredLibraryPath (FileSet libraryPath ) {
146144 File parent = libraryPath .getDir ();
147145
148146 DirectoryScanner directoryScanner = libraryPath .getDirectoryScanner (getProject ());
@@ -226,16 +224,6 @@ public void execute() throws BuildException {
226224 throw new IllegalStateException ("Copyright is required." );
227225 }
228226
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-
239227 if (mainClassName == null ) {
240228 throw new IllegalStateException ("Main class name is required." );
241229 }
@@ -288,7 +276,31 @@ public void execute() throws BuildException {
288276
289277 // Copy runtime to PlugIns folder (if specified)
290278 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+ }
292304 }
293305
294306 // Copy class path entries to Java folder
@@ -357,7 +369,7 @@ private void writeInfoPlist(File file) throws IOException {
357369
358370 // Write runtime
359371 if (runtime != null ) {
360- writeProperty (xout , "JVMRuntime" , runtime .getName ());
372+ writeProperty (xout , "JVMRuntime" , runtime .getDir (). getName ());
361373 }
362374
363375 // Write main class name
@@ -465,6 +477,8 @@ private static void copy(File source, File destination) throws IOException {
465477 Path sourcePath = source .toPath ();
466478 Path destinationPath = destination .toPath ();
467479
480+ destination .getParentFile ().mkdirs ();
481+
468482 Files .copy (sourcePath , destinationPath , StandardCopyOption .REPLACE_EXISTING , LinkOption .NOFOLLOW_LINKS );
469483
470484 if (Files .isDirectory (sourcePath , LinkOption .NOFOLLOW_LINKS )) {
0 commit comments