Skip to content

Commit 23e128e

Browse files
authored
Merge pull request #54 from thomas3/master
Refine selection of binary bundle for macOS based on OS version
2 parents e8b5854 + 0fc105a commit 23e128e

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java

+27-28
Original file line numberDiff line numberDiff line change
@@ -18,45 +18,34 @@
1818
*/
1919
package com.akathist.maven.plugins.launch4j;
2020

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-
3621
import net.sf.launch4j.Builder;
3722
import net.sf.launch4j.BuilderException;
3823
import net.sf.launch4j.config.Config;
3924
import net.sf.launch4j.config.ConfigPersister;
40-
4125
import net.sf.launch4j.config.ConfigPersisterException;
4226
import org.apache.maven.artifact.Artifact;
4327
import org.apache.maven.artifact.factory.ArtifactFactory;
44-
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
4528
import org.apache.maven.artifact.repository.ArtifactRepository;
46-
import org.apache.maven.artifact.resolver.ArtifactCollector;
4729
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
4830
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
4931
import org.apache.maven.artifact.resolver.ArtifactResolver;
5032
import org.apache.maven.plugin.AbstractMojo;
5133
import org.apache.maven.plugin.MojoExecutionException;
5234
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.*;
5836
import org.apache.maven.project.MavenProject;
5937

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+
6049
/**
6150
* Wraps a jar in a Windows executable.
6251
*/
@@ -462,14 +451,16 @@ private File unpackWorkDir(Artifact a) throws MojoExecutionException {
462451
File platJar = a.getFile();
463452
File dest = platJar.getParentFile();
464453
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));
465456

466457
// If the artifact is a SNAPSHOT, then a.getVersion() will report the long timestamp,
467458
// but getFile() will be 1.1-SNAPSHOT.
468459
// Since getFile() doesn't use the timestamp, all timestamps wind up in the same place.
469460
// Therefore we need to expand the jar every time, if the marker file is stale.
470461
if (marker.exists() && marker.lastModified() > platJar.lastModified()) {
471462
// 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());
473464
} else {
474465
JarFile jf = null;
475466
try {
@@ -526,8 +517,6 @@ private File unpackWorkDir(Artifact a) throws MojoExecutionException {
526517
}
527518
}
528519

529-
String n = platJar.getName();
530-
File workdir = new File(dest, n.substring(0, n.length() - 4));
531520
setPermissions(workdir);
532521
return workdir;
533522
}
@@ -608,7 +597,7 @@ private Artifact chooseBinaryBits() throws MojoExecutionException {
608597
} else if ("Solaris".equals(os) || "SunOS".equals(os)) {
609598
plat = "solaris";
610599
} else if ("Mac OS X".equals(os) || "Darwin".equals(os)) {
611-
plat = "mac";
600+
plat = isBelowMacOSX_10_8() ? "mac" : "osx";
612601
} else {
613602
throw new MojoExecutionException("Sorry, Launch4j doesn't support the '" + os + "' OS.");
614603
}
@@ -617,6 +606,16 @@ private Artifact chooseBinaryBits() throws MojoExecutionException {
617606
getLaunch4jVersion(), "jar", "workdir-" + plat);
618607
}
619608

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+
}
620619

621620
private File getBaseDir() {
622621
return basedir;
@@ -739,4 +738,4 @@ private String getLaunch4jVersion() throws MojoExecutionException {
739738

740739
return version;
741740
}
742-
}
741+
}

0 commit comments

Comments
 (0)