Skip to content

Commit

Permalink
Merge pull request #54 from thomas3/master
Browse files Browse the repository at this point in the history
Refine selection of binary bundle for macOS based on OS version
  • Loading branch information
lukaszlenart authored Mar 15, 2017
2 parents e8b5854 + 0fc105a commit 23e128e
Showing 1 changed file with 27 additions and 28 deletions.
55 changes: 27 additions & 28 deletions src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,34 @@
*/
package com.akathist.maven.plugins.launch4j;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

import net.sf.launch4j.Builder;
import net.sf.launch4j.BuilderException;
import net.sf.launch4j.config.Config;
import net.sf.launch4j.config.ConfigPersister;

import net.sf.launch4j.config.ConfigPersisterException;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactCollector;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.plugins.annotations.*;
import org.apache.maven.project.MavenProject;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.*;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

/**
* Wraps a jar in a Windows executable.
*/
Expand Down Expand Up @@ -462,14 +451,16 @@ private File unpackWorkDir(Artifact a) throws MojoExecutionException {
File platJar = a.getFile();
File dest = platJar.getParentFile();
File marker = new File(dest, platJar.getName() + ".unpacked");
String n = platJar.getName();
File workdir = new File(dest, n.substring(0, n.length() - 4));

// If the artifact is a SNAPSHOT, then a.getVersion() will report the long timestamp,
// but getFile() will be 1.1-SNAPSHOT.
// Since getFile() doesn't use the timestamp, all timestamps wind up in the same place.
// Therefore we need to expand the jar every time, if the marker file is stale.
if (marker.exists() && marker.lastModified() > platJar.lastModified()) {
// if (marker.exists() && marker.platJar.getName().indexOf("SNAPSHOT") == -1) {
getLog().info("Platform-specific work directory already exists: " + dest.getAbsolutePath());
getLog().info("Platform-specific work directory already exists: " + workdir.getAbsolutePath());
} else {
JarFile jf = null;
try {
Expand Down Expand Up @@ -526,8 +517,6 @@ private File unpackWorkDir(Artifact a) throws MojoExecutionException {
}
}

String n = platJar.getName();
File workdir = new File(dest, n.substring(0, n.length() - 4));
setPermissions(workdir);
return workdir;
}
Expand Down Expand Up @@ -608,7 +597,7 @@ private Artifact chooseBinaryBits() throws MojoExecutionException {
} else if ("Solaris".equals(os) || "SunOS".equals(os)) {
plat = "solaris";
} else if ("Mac OS X".equals(os) || "Darwin".equals(os)) {
plat = "mac";
plat = isBelowMacOSX_10_8() ? "mac" : "osx";
} else {
throw new MojoExecutionException("Sorry, Launch4j doesn't support the '" + os + "' OS.");
}
Expand All @@ -617,6 +606,16 @@ private Artifact chooseBinaryBits() throws MojoExecutionException {
getLaunch4jVersion(), "jar", "workdir-" + plat);
}

private static boolean isBelowMacOSX_10_8() {
String[] parts = System.getProperty("os.version").split("\\.");
try {
int major = Integer.parseInt(parts[0]);
int minor = Integer.parseInt(parts[1]);
return (major < 10) || (major == 10) && (minor < 8);
} catch (NumberFormatException e) {
return false;
}
}

private File getBaseDir() {
return basedir;
Expand Down Expand Up @@ -739,4 +738,4 @@ private String getLaunch4jVersion() throws MojoExecutionException {

return version;
}
}
}

0 comments on commit 23e128e

Please sign in to comment.