Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsacha committed Sep 2, 2022
2 parents 688d22c + a512f07 commit 951b041
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 3.4.2
version = 3.5.9

runner.dialect = scala212source3

Expand Down
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ SBT settings provided by `sbt-install4j` plugin:

The `sbt-install4j` executes Install4J compiler. It needs to know its location. It will attempts to determine location base on the OS used. On Windows it is assumed to be:
```
C:\Program Files\Install4J7\bin\intall4jc.exe
C:\Program Files\Install4J10\bin\intall4jc.exe
```

On Mac OS X:
Expand All @@ -105,14 +105,16 @@ On Mac OS X:

On Linux:
```
/opt/install4j/bin/install4jc
/opt/install4j10/bin/install4jc
```

If the Install4J is installed in a different location you can specify location of the compiler using the environment variable `INSTALL4JC_FILE` or setting `install4jcFile`. For multi-platform builds it is preferred to use the environment variable `INSTALL4JC_FILE`.
If the Install4J is installed in a different location you can specify location of the compiler using the environment
variable `INSTALL4JC_FILE`, property `INSTALL4JC_FILE`, or SBT setting `install4jcFile`. For multi-platform builds it is
preferred to use the environment variable `INSTALL4JC_FILE`.

You can set the environment variable when starting SBT using `-D` option, for instance:
You can set the property variable when starting SBT using `-D` option, for instance:
```cmd
$ sbt -DINSTALL4JC_FILE="C:/Program Files/install4j8/bin/install4jc.exe"
$ sbt -DINSTALL4JC_FILE="C:/Program Files/install4j11/bin/install4jc.exe"
```

## Example of a Complete Application
Expand All @@ -121,6 +123,12 @@ $ sbt -DINSTALL4JC_FILE="C:/Program Files/install4j8/bin/install4jc.exe"

## Tips & Tricks

### Compiling against Install4J API
If you use Install4J API in your application and using version other than the default for `sbt-install4j` you will need to set environment variable `INSTALL4J_HOME`.

For instance, `sbt-install4j` uses Install4J 7 as default, but you have Install4J 9 installed, then set `INSTALL4J_HOME` the installation directory. On Windows that would typically be `C:\Program Files\install4j10`

### Debugging
To see debugging information set SBT logging level to `debug`:
```cmd
sbt> debug
Expand Down
6 changes: 3 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ sbtPlugin := true

name := "sbt-install4j"
organization := "com.github.jpsacha"
version := "1.4.0"
version := "1.4.0.1-SNAPSHOT"

homepage := Some(url("http://github.com/jpsacha/sbt-install4j"))
organizationHomepage := Some(url("http://github.com/jpsacha"))
startYear := Some(2014)
licenses := Seq("Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0.html"))
description := "SBT plugin for building installers with Install4J."

scalaVersion := "2.12.15"
scalaVersion := "2.12.16"

scalacOptions := Seq("-deprecation", "-unchecked", "-Xsource:3")

libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.11" % "test"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.13" % "test"

Test / packageBin / publishArtifact := false
Test / packageDoc / publishArtifact := false
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
# limitations under the License.
#

sbt.version=1.6.2
sbt.version=1.7.1
2 changes: 1 addition & 1 deletion project/sbt-sonatype.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// [https://github.com/xerial/sbt-sonatype]
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.10")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.13")
// [https://github.com/sbt/sbt-pgp]
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2")
57 changes: 38 additions & 19 deletions src/main/scala/net/ij_plugins/sf/sbt/install4j/Defaults.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package net.ij_plugins.sf.sbt.install4j

import sbt.Keys.TaskStreams

import java.io.File

Expand All @@ -25,46 +24,66 @@ object Defaults {
val INSTALL4J_HOME_ENV = "INSTALL4J_HOME"
val INSTALL4JC_FILE_ENV = "INSTALL4JC_FILE"

def install4jHomeDir(taskStreams: Option[TaskStreams] = None): String = {
val logger = taskStreams.map(_.log)
private val debugMode = false

val install4JHomeEnv = System.getProperty(INSTALL4J_HOME_ENV, null)
logger.foreach(_.debug(s"INSTALL4JC_FILE_ENV: $install4JHomeEnv"))
private def debug(msg: String): Unit =
if (debugMode) println(s"[install4j] $msg")

private def getPropOrEnv(name: String): Option[String] = {
val prop = System.getProperty(name, null)
debug(s"system property $name: $prop")
val r = {
if (prop == null) {
val env = System.getenv(name)
debug(s"environmental variable $name: $env")
env
} else {
prop
}
}
Option(r)
}

def install4jHomeDir(): File = {

// First check for INSTALL4J_HOME, and if available use that
Option(install4JHomeEnv) match {
val install4JHomeEnv = getPropOrEnv(INSTALL4J_HOME_ENV)

debug(s"$INSTALL4J_HOME_ENV: $install4JHomeEnv")

val r = install4JHomeEnv match {
case Some(s) => s
case _ =>
val osName = System.getProperty("os.name")

if (osName.startsWith("Windows"))
"C:/Program Files/install4j9"
"C:/Program Files/install4j10"
else if (osName.equals("Linux"))
"/opt/install4j9"
"/opt/install4j10"
else if (osName.equals("Mac OS X"))
"/Applications/install4j.app/Contents/Resources/app"
else
throw new UnsupportedOperationException(
"Cannot determine default 'Install4jHomeDir'. Unsupported OS: " + osName
)
)
}
}

def install4jCompilerFile(
install4jHomeDir: String = Defaults.install4jHomeDir(),
taskStreams: Option[TaskStreams] = None
): File = {
debug(s"install4jHomeDir: $r")
new File(r)
}

val logger = taskStreams.map(_.log)
def install4jCompilerFile(install4jHomeDir: File): File = {

val installJCFileEnv = System.getProperty(INSTALL4JC_FILE_ENV, null)
logger.foreach(_.debug(s"INSTALL4JC_FILE_ENV: $installJCFileEnv"))
val installJCFileEnv = getPropOrEnv(INSTALL4JC_FILE_ENV)
debug(s"$INSTALL4JC_FILE_ENV: $installJCFileEnv")

// First check for INSTALL4JC_PATH, and if available use that
Option(installJCFileEnv) match {
val r = installJCFileEnv match {
case Some(s) => new File(s)
case _ => new File(install4jHomeDir, "bin/" + compilerName())
case _ => new File(install4jHomeDir, "bin/" + compilerName())
}
debug(s"install4jCompilerFile: $r")
r
}

def compilerName(): String = {
Expand Down
25 changes: 13 additions & 12 deletions src/main/scala/net/ij_plugins/sf/sbt/install4j/SBTInstall4J.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ object SBTInstall4J extends sbt.AutoPlugin {
"install4jCompilerVariables",
"Override a compiler variable with a different value. " +
"In the map, the `key` is variable's name, the `value` is variable's value."
)
)
}

import net.ij_plugins.sf.sbt.install4j.SBTInstall4J.autoImport.*
Expand All @@ -106,6 +106,7 @@ object SBTInstall4J extends sbt.AutoPlugin {
install4j := {
// get the result of parsing
val extraArgs: Seq[String] = spaceDelimited("<arg>").parsed
streams.value.log.debug("extraArgs: " + extraArgs.mkString(", "))

// Run dependent tasks first
val _v1 = (Compile / packageBin).value
Expand All @@ -124,14 +125,14 @@ object SBTInstall4J extends sbt.AutoPlugin {
extraOptions = install4jExtraOptions.value,
extraArgs = extraArgs,
streams.value
)
)
},
install4jCopyDependedJars := copyDependedJars(
(Runtime / dependencyClasspath).value,
crossTarget.value,
install4jCopyDependedJarsExclusions.value,
streams.value
),
),
install4jCopyDependedJarsExclusions := Seq(
// Source archives
"""\S*-src\.\S*""",
Expand All @@ -143,16 +144,16 @@ object SBTInstall4J extends sbt.AutoPlugin {
// Scaladoc
"""\S*-scaladoc\.\S*""",
"""\S*_scaladoc_\S*"""
),
),
install4jCopyDependedJarsEnabled := true,
install4jExtraOptions := Seq.empty[String],
install4jHomeDir := file(Defaults.install4jHomeDir()),
install4jcFile := file(Defaults.install4jCompilerFile().getCanonicalPath),
install4jProjectFile := "installer/installer.install4j",
install4jVerbose := false,
install4jRelease := "",
install4jCompilerVariables := Map.empty
)
install4jExtraOptions := Seq.empty[String],
install4jHomeDir := file(Defaults.install4jHomeDir().getCanonicalPath),
install4jcFile := file(Defaults.install4jCompilerFile(install4jHomeDir.value).getCanonicalPath),
install4jProjectFile := "installer/installer.install4j",
install4jVerbose := false,
install4jRelease := "",
install4jCompilerVariables := Map.empty
)

private def prefix = "[sbt-install4j] "

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ class DefaultsTest extends AnyFlatSpec {

val install4jHomeDir = Defaults.install4jHomeDir()

install4jHomeDir should be(path_name)
install4jHomeDir should be(f)
}

it should "determine install4jCompilerFile from environment variable" in {
val f = File.createTempFile("_env_", "_env_")
val path_name = f.getCanonicalPath
System.setProperty(Defaults.INSTALL4JC_FILE_ENV, path_name)

val install4jCompilerFile = Defaults.install4jCompilerFile().getCanonicalPath
val install4jCompilerFile = Defaults.install4jCompilerFile(Defaults.install4jHomeDir()).getCanonicalPath

install4jCompilerFile should be(path_name)
}
Expand Down

0 comments on commit 951b041

Please sign in to comment.