18
18
*/
19
19
package com .akathist .maven .plugins .launch4j ;
20
20
21
- import java .io .File ;
22
- import java .io .FileOutputStream ;
23
- import java .io .IOException ;
24
- import java .io .InputStream ;
25
- import java .nio .file .Files ;
26
- import java .nio .file .Path ;
27
- import java .nio .file .StandardCopyOption ;
28
- import java .util .ArrayList ;
29
- import java .util .Date ;
30
- import java .util .Enumeration ;
31
- import java .util .List ;
32
- import java .util .Set ;
33
- import java .util .jar .JarEntry ;
34
- import java .util .jar .JarFile ;
35
-
36
21
import net .sf .launch4j .Builder ;
37
22
import net .sf .launch4j .BuilderException ;
38
23
import net .sf .launch4j .config .Config ;
39
24
import net .sf .launch4j .config .ConfigPersister ;
40
-
41
25
import net .sf .launch4j .config .ConfigPersisterException ;
42
26
import org .apache .maven .artifact .Artifact ;
43
27
import org .apache .maven .artifact .factory .ArtifactFactory ;
44
- import org .apache .maven .artifact .metadata .ArtifactMetadataSource ;
45
28
import org .apache .maven .artifact .repository .ArtifactRepository ;
46
- import org .apache .maven .artifact .resolver .ArtifactCollector ;
47
29
import org .apache .maven .artifact .resolver .ArtifactNotFoundException ;
48
30
import org .apache .maven .artifact .resolver .ArtifactResolutionException ;
49
31
import org .apache .maven .artifact .resolver .ArtifactResolver ;
50
32
import org .apache .maven .plugin .AbstractMojo ;
51
33
import org .apache .maven .plugin .MojoExecutionException ;
52
34
import org .apache .maven .plugin .logging .Log ;
53
- import org .apache .maven .plugins .annotations .Component ;
54
- import org .apache .maven .plugins .annotations .LifecyclePhase ;
55
- import org .apache .maven .plugins .annotations .Mojo ;
56
- import org .apache .maven .plugins .annotations .Parameter ;
57
- import org .apache .maven .plugins .annotations .ResolutionScope ;
35
+ import org .apache .maven .plugins .annotations .*;
58
36
import org .apache .maven .project .MavenProject ;
59
37
38
+ import java .io .File ;
39
+ import java .io .FileOutputStream ;
40
+ import java .io .IOException ;
41
+ import java .io .InputStream ;
42
+ import java .nio .file .Files ;
43
+ import java .nio .file .Path ;
44
+ import java .nio .file .StandardCopyOption ;
45
+ import java .util .*;
46
+ import java .util .jar .JarEntry ;
47
+ import java .util .jar .JarFile ;
48
+
60
49
/**
61
50
* Wraps a jar in a Windows executable.
62
51
*/
@@ -462,14 +451,16 @@ private File unpackWorkDir(Artifact a) throws MojoExecutionException {
462
451
File platJar = a .getFile ();
463
452
File dest = platJar .getParentFile ();
464
453
File marker = new File (dest , platJar .getName () + ".unpacked" );
454
+ String n = platJar .getName ();
455
+ File workdir = new File (dest , n .substring (0 , n .length () - 4 ));
465
456
466
457
// If the artifact is a SNAPSHOT, then a.getVersion() will report the long timestamp,
467
458
// but getFile() will be 1.1-SNAPSHOT.
468
459
// Since getFile() doesn't use the timestamp, all timestamps wind up in the same place.
469
460
// Therefore we need to expand the jar every time, if the marker file is stale.
470
461
if (marker .exists () && marker .lastModified () > platJar .lastModified ()) {
471
462
// if (marker.exists() && marker.platJar.getName().indexOf("SNAPSHOT") == -1) {
472
- getLog ().info ("Platform-specific work directory already exists: " + dest .getAbsolutePath ());
463
+ getLog ().info ("Platform-specific work directory already exists: " + workdir .getAbsolutePath ());
473
464
} else {
474
465
JarFile jf = null ;
475
466
try {
@@ -526,8 +517,6 @@ private File unpackWorkDir(Artifact a) throws MojoExecutionException {
526
517
}
527
518
}
528
519
529
- String n = platJar .getName ();
530
- File workdir = new File (dest , n .substring (0 , n .length () - 4 ));
531
520
setPermissions (workdir );
532
521
return workdir ;
533
522
}
@@ -608,7 +597,7 @@ private Artifact chooseBinaryBits() throws MojoExecutionException {
608
597
} else if ("Solaris" .equals (os ) || "SunOS" .equals (os )) {
609
598
plat = "solaris" ;
610
599
} else if ("Mac OS X" .equals (os ) || "Darwin" .equals (os )) {
611
- plat = "mac" ;
600
+ plat = isBelowMacOSX_10_8 () ? "mac" : "osx " ;
612
601
} else {
613
602
throw new MojoExecutionException ("Sorry, Launch4j doesn't support the '" + os + "' OS." );
614
603
}
@@ -617,6 +606,16 @@ private Artifact chooseBinaryBits() throws MojoExecutionException {
617
606
getLaunch4jVersion (), "jar" , "workdir-" + plat );
618
607
}
619
608
609
+ private static boolean isBelowMacOSX_10_8 () {
610
+ String [] parts = System .getProperty ("os.version" ).split ("\\ ." );
611
+ try {
612
+ int major = Integer .parseInt (parts [0 ]);
613
+ int minor = Integer .parseInt (parts [1 ]);
614
+ return (major < 10 ) || (major == 10 ) && (minor < 8 );
615
+ } catch (NumberFormatException e ) {
616
+ return false ;
617
+ }
618
+ }
620
619
621
620
private File getBaseDir () {
622
621
return basedir ;
@@ -739,4 +738,4 @@ private String getLaunch4jVersion() throws MojoExecutionException {
739
738
740
739
return version ;
741
740
}
742
- }
741
+ }
0 commit comments