22
22
import java .io .FileOutputStream ;
23
23
import java .io .IOException ;
24
24
import java .io .InputStream ;
25
+ import java .nio .file .Files ;
26
+ import java .nio .file .Path ;
27
+ import java .nio .file .Paths ;
28
+ import java .nio .file .StandardCopyOption ;
29
+ import java .util .ArrayList ;
25
30
import java .util .Date ;
26
31
import java .util .Enumeration ;
27
32
import java .util .List ;
@@ -281,6 +286,8 @@ public void execute() throws MojoExecutionException {
281
286
printState ();
282
287
}
283
288
289
+ File workdir = setupBuildEnvironment ();
290
+
284
291
Config c = new Config ();
285
292
286
293
c .setHeaderType (headerType );
@@ -297,8 +304,8 @@ public void execute() throws MojoExecutionException {
297
304
c .setRestartOnCrash (restartOnCrash );
298
305
c .setManifest (manifest );
299
306
c .setIcon (icon );
300
- c .setHeaderObjects (objs );
301
- c .setLibs (libs );
307
+ c .setHeaderObjects (relativizeAndCopy ( workdir , objs ) );
308
+ c .setLibs (relativizeAndCopy ( workdir , libs ) );
302
309
c .setVariables (vars );
303
310
304
311
if (classPath != null ) {
@@ -321,7 +328,6 @@ public void execute() throws MojoExecutionException {
321
328
}
322
329
323
330
ConfigPersister .getInstance ().setAntConfig (c , getBaseDir ());
324
- File workdir = setupBuildEnvironment ();
325
331
Builder b = new Builder (new MavenLog (getLog ()), workdir );
326
332
327
333
try {
@@ -455,6 +461,36 @@ private void setPermissions(File workdir) {
455
461
}
456
462
}
457
463
464
+ /**
465
+ * If custom header objects or libraries shall be linked, they need to sit inside the launch4j working dir.
466
+ */
467
+ private List <String > relativizeAndCopy (File workdir , List <String > paths ) throws MojoExecutionException {
468
+ if (paths == null ) return null ;
469
+
470
+ List <String > result = new ArrayList <>();
471
+ for (String path : paths ) {
472
+ Path source = basedir .toPath ().resolve (path );
473
+ Path dest = workdir .toPath ().resolve (basedir .toPath ().relativize (source ));
474
+
475
+ if (!source .startsWith (basedir .toPath ())) {
476
+ throw new MojoExecutionException ("File must reside in the project directory: " + path );
477
+ }
478
+
479
+ if (Files .exists (source )) {
480
+ try {
481
+ Path target = Files .copy (source , dest , StandardCopyOption .REPLACE_EXISTING );
482
+ result .add (workdir .toPath ().relativize (target ).toString ());
483
+ } catch (IOException e ) {
484
+ throw new MojoExecutionException ("Can't copy file to workdir" , e );
485
+ }
486
+ } else {
487
+ result .add (path );
488
+ }
489
+ }
490
+
491
+ return result ;
492
+ }
493
+
458
494
/**
459
495
* Downloads the platform-specific parts, if necessary.
460
496
*/
0 commit comments