-
Notifications
You must be signed in to change notification settings - Fork 446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #495. Enhanced locateJDKPackagerTool
to work on Windows when SBT...
#496
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
package com.typesafe.sbt.packager.jdkpackager | ||
|
||
import java.io.FileNotFoundException | ||
|
||
import com.typesafe.sbt.packager.chmod | ||
import sbt._ | ||
|
||
import scala.tools.util.PathResolver | ||
import scala.util.Try | ||
/** | ||
* Support/helper functions for interacting with the `javapackager` tool. | ||
* @author <a href="mailto:[email protected]">Simeon H.K. Fitch</a> | ||
|
@@ -11,19 +15,45 @@ import sbt._ | |
object JDKPackagerHelper { | ||
|
||
/** Attempts to compute the path to the `javapackager` tool. */ | ||
def locateJDKPackagerTool(): Option[File] = { | ||
val jdkHome = sys.props.get("java.home").map(p ⇒ file(p)) | ||
|
||
// TODO: How to get version of javaHome target? | ||
val javaVersion = VersionNumber(sys.props("java.specification.version")) | ||
val toolname = javaVersion.numbers.take(2) match { | ||
case Seq(1, m) if m >= 8 ⇒ "javapackager" | ||
case _ ⇒ sys.error("Need at least JDK version 1.8 to run JDKPackager plugin") | ||
def locateJDKPackagerTool(javaHome: Option[File]): Option[File] = { | ||
val toolname = sys.props("os.name").toLowerCase match { | ||
case os if os.contains("win") ⇒ "javapackager.exe" | ||
case _ ⇒ "javapackager" | ||
} | ||
jdkHome | ||
.map(f ⇒ if (f.getName == "jre") f / ".." else f) | ||
.map(f ⇒ f / "bin" / toolname) | ||
.filter(_.exists()) | ||
|
||
// This approach to getting JDK bits is borrowed from: http://stackoverflow.com/a/25163628/296509 | ||
// Starting with an ordered list of possible java directory sources, create derivative and | ||
// then test for the tool. It's nasty looking because there's no canonical way of finding the | ||
// JDK from the JRE, and JDK_HOME isn't always defined. | ||
Seq( | ||
// Build-defined | ||
javaHome, | ||
// Environment override | ||
sys.env.get("JDK_HOME").map(file), | ||
sys.env.get("JAVA_HOME").map(file), | ||
// MacOS X | ||
Try("/usr/libexec/java_home".!!.trim).toOption.map(file), | ||
// From system properties | ||
sys.props.get("java.home").map(file) | ||
) | ||
// Unlift Option-s | ||
.flatten | ||
// For each base directory, add the parent variant to cover nested JREs on Unix. | ||
.flatMap { | ||
f ⇒ Seq(f, f.getAbsoluteFile) | ||
} | ||
// On Windows we're often running in the JRE and not the JDK. If JDK is installed, | ||
// it's likely to be in a parallel directory, with the "jre" prefix changed to "jdk" | ||
.flatMap { f ⇒ | ||
if (f.getName.startsWith("jre")) { | ||
Seq(f, f.getParentFile / ("jdk" + f.getName.drop(3))) | ||
} else Seq(f) | ||
} | ||
// Now search for the tool | ||
.map { n => | ||
n / "bin" / toolname | ||
} | ||
.find(_.exists) | ||
} | ||
|
||
/** | ||
|
@@ -112,7 +142,7 @@ object JDKPackagerHelper { | |
// To help debug arguments, create a bash script doing the same. | ||
val script = file(argMap("-outdir")) / "jdkpackager.sh" | ||
IO.write(script, s"#!/bin/bash\n$argString\n") | ||
chmod(script, "766") | ||
Try(chmod(script, "766")) | ||
|
||
Process(args) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,8 @@ mainClass in Compile := Some("ExampleApp") | |
|
||
enablePlugins(JDKPackagerPlugin) | ||
|
||
maintainer := "Simeon H.K Fitch <[email protected]>" | ||
// This becomes the Start Menu subdirectory for the windows installers. | ||
maintainer := "Previously Owned Cats, Inc." | ||
|
||
packageSummary := "JDKPackagerPlugin example package thingy" | ||
|
||
|
Binary file modified
BIN
+16.6 KB
(100%)
test-project-jdkpackager/src/deploy/package/windows/jdkpackager-example.ico
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I didn't know that setting. One couldn't believe how hard it is to find the JDK on a system -.-