@@ -127,6 +127,8 @@ public void addConfiguredRuntime(FileSet runtime) throws BuildException {
127127 }
128128
129129 this .runtime = runtime ;
130+
131+ // TODO Add default excludes
130132 }
131133
132134 public void addConfiguredClassPath (FileSet classPath ) {
@@ -214,14 +216,11 @@ public void execute() throws BuildException {
214216 throw new IllegalStateException ("Main class name is required." );
215217 }
216218
217- if (classPath .isEmpty ()) {
218- throw new IllegalStateException ("Class path is required." );
219- }
220-
221- // Create directory structure
219+ // Create the app bundle
222220 try {
223221 System .out .println ("Creating app bundle: " + name );
224222
223+ // Create directory structure
225224 File rootDirectory = new File (outputDirectory , name + ".app" );
226225 delete (rootDirectory );
227226 rootDirectory .mkdir ();
@@ -258,76 +257,92 @@ public void execute() throws BuildException {
258257 executableFile .setExecutable (true );
259258
260259 // Copy runtime to PlugIns folder
261- if (runtime != null ) {
262- // Create root directory
263- File runtimeDirectory = runtime .getDir ();
264- File pluginDirectory = new File (plugInsDirectory , runtimeDirectory .getName ());
265- pluginDirectory .mkdir ();
266-
267- // Create Contents directory
268- File runtimeContentsDirectory = new File (runtimeDirectory , "Contents" );
269- File pluginContentsDirectory = new File (pluginDirectory , runtimeContentsDirectory .getName ());
270- pluginContentsDirectory .mkdir ();
271-
272- // Copy MacOS directory
273- File runtimeMacOSDirectory = new File (runtimeContentsDirectory , "MacOS" );
274- copy (runtimeMacOSDirectory , new File (pluginContentsDirectory , runtimeMacOSDirectory .getName ()));
275-
276- // Copy Info.plist file
277- File runtimeInfoPlistFile = new File (runtimeContentsDirectory , "Info.plist" );
278- copy (runtimeInfoPlistFile , new File (pluginContentsDirectory , runtimeInfoPlistFile .getName ()));
279-
280- // Copy included contents of Home directory
281- DirectoryScanner directoryScanner = runtime .getDirectoryScanner (getProject ());
282- String [] includedFiles = directoryScanner .getIncludedFiles ();
283-
284- for (int i = 0 ; i < includedFiles .length ; i ++) {
285- String includedFile = includedFiles [i ];
286- File source = new File (runtimeDirectory , includedFile );
287- File destination = new File (pluginDirectory , includedFile );
288- copy (source , destination );
289- }
290- }
260+ copyRuntime (plugInsDirectory );
291261
292262 // Copy class path entries to Java folder
293- for (FileSet fileSet : classPath ) {
294- File classPathDirectory = fileSet .getDir ();
295- DirectoryScanner directoryScanner = fileSet .getDirectoryScanner (getProject ());
296- String [] includedFiles = directoryScanner .getIncludedFiles ();
297-
298- for (int i = 0 ; i < includedFiles .length ; i ++) {
299- String includedFile = includedFiles [i ];
300- File source = new File (classPathDirectory , includedFile );
301- File destination = new File (javaDirectory , new File (includedFile ).getName ());
302- copy (source , destination );
303- }
304- }
263+ copyClassPathEntries (javaDirectory );
305264
306- // Copy native libraries to MacOS folder
307- for (FileSet fileSet : libraryPath ) {
308- File libraryPathDirectory = fileSet .getDir ();
309- DirectoryScanner directoryScanner = fileSet .getDirectoryScanner (getProject ());
310- String [] includedFiles = directoryScanner .getIncludedFiles ();
311-
312- for (int i = 0 ; i < includedFiles .length ; i ++) {
313- String includedFile = includedFiles [i ];
314- File source = new File (libraryPathDirectory , includedFile );
315- File destination = new File (macOSDirectory , new File (includedFile ).getName ());
316- copy (source , destination );
317- }
318- }
265+ // Copy library path entries to MacOS folder
266+ copyLibraryPathEntries (macOSDirectory );
319267
320268 // Copy icon to Resources folder
321- if (icon == null ) {
322- copy (getClass ().getResource (DEFAULT_ICON_NAME ), new File (resourcesDirectory , DEFAULT_ICON_NAME ));
323- } else {
324- copy (icon , new File (resourcesDirectory , icon .getName ()));
325- }
269+ copyIcon (resourcesDirectory );
326270 } catch (IOException exception ) {
327271 throw new BuildException (exception );
328272 }
329273 }
330274
275+ private void copyRuntime (File plugInsDirectory ) throws IOException {
276+ if (runtime != null ) {
277+ // Create root directory
278+ File runtimeDirectory = runtime .getDir ();
279+ File pluginDirectory = new File (plugInsDirectory , runtimeDirectory .getName ());
280+ pluginDirectory .mkdir ();
281+
282+ // Create Contents directory
283+ File runtimeContentsDirectory = new File (runtimeDirectory , "Contents" );
284+ File pluginContentsDirectory = new File (pluginDirectory , runtimeContentsDirectory .getName ());
285+ pluginContentsDirectory .mkdir ();
286+
287+ // Copy MacOS directory
288+ File runtimeMacOSDirectory = new File (runtimeContentsDirectory , "MacOS" );
289+ copy (runtimeMacOSDirectory , new File (pluginContentsDirectory , runtimeMacOSDirectory .getName ()));
290+
291+ // Copy Info.plist file
292+ File runtimeInfoPlistFile = new File (runtimeContentsDirectory , "Info.plist" );
293+ copy (runtimeInfoPlistFile , new File (pluginContentsDirectory , runtimeInfoPlistFile .getName ()));
294+
295+ // Copy included contents of Home directory
296+ DirectoryScanner directoryScanner = runtime .getDirectoryScanner (getProject ());
297+ String [] includedFiles = directoryScanner .getIncludedFiles ();
298+
299+ for (int i = 0 ; i < includedFiles .length ; i ++) {
300+ String includedFile = includedFiles [i ];
301+ File source = new File (runtimeDirectory , includedFile );
302+ File destination = new File (pluginDirectory , includedFile );
303+ copy (source , destination );
304+ }
305+ }
306+ }
307+
308+ private void copyClassPathEntries (File javaDirectory ) throws IOException {
309+ for (FileSet fileSet : classPath ) {
310+ File classPathDirectory = fileSet .getDir ();
311+ DirectoryScanner directoryScanner = fileSet .getDirectoryScanner (getProject ());
312+ String [] includedFiles = directoryScanner .getIncludedFiles ();
313+
314+ for (int i = 0 ; i < includedFiles .length ; i ++) {
315+ String includedFile = includedFiles [i ];
316+ File source = new File (classPathDirectory , includedFile );
317+ File destination = new File (javaDirectory , new File (includedFile ).getName ());
318+ copy (source , destination );
319+ }
320+ }
321+ }
322+
323+ private void copyLibraryPathEntries (File macOSDirectory ) throws IOException {
324+ for (FileSet fileSet : libraryPath ) {
325+ File libraryPathDirectory = fileSet .getDir ();
326+ DirectoryScanner directoryScanner = fileSet .getDirectoryScanner (getProject ());
327+ String [] includedFiles = directoryScanner .getIncludedFiles ();
328+
329+ for (int i = 0 ; i < includedFiles .length ; i ++) {
330+ String includedFile = includedFiles [i ];
331+ File source = new File (libraryPathDirectory , includedFile );
332+ File destination = new File (macOSDirectory , new File (includedFile ).getName ());
333+ copy (source , destination );
334+ }
335+ }
336+ }
337+
338+ private void copyIcon (File resourcesDirectory ) throws IOException {
339+ if (icon == null ) {
340+ copy (getClass ().getResource (DEFAULT_ICON_NAME ), new File (resourcesDirectory , DEFAULT_ICON_NAME ));
341+ } else {
342+ copy (icon , new File (resourcesDirectory , icon .getName ()));
343+ }
344+ }
345+
331346 private void writeInfoPlist (File file ) throws IOException {
332347 Writer out = new BufferedWriter (new FileWriter (file ));
333348 XMLOutputFactory output = XMLOutputFactory .newInstance ();
0 commit comments