Skip to content
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

Introduce new namespace and solve duplicate key issue #802

Merged
merged 9 commits into from
Jun 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/scala/com/typesafe/sbt/packager/windows/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ trait WindowsKeys {
val wixFile = TaskKey[File]("wix-file", "The WIX XML file to package with.")
val candleOptions = SettingKey[Seq[String]]("candle-options", "Options to pass to the candle.exe program.")
val lightOptions = SettingKey[Seq[String]]("light-options", "Options to pass to the light.exe program.")
val wixMajorVersion = SettingKey[Int]("wix-major-version", "Major version of the Wix suit.")

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ object WindowsPlugin extends AutoPlugin {
"-cultures:en-us"),
wixProductId := WixHelper.makeGUID,
wixProductUpgradeId := WixHelper.makeGUID,
wixMajorVersion := 3,
maintainer in Windows <<= maintainer,
packageSummary in Windows <<= packageSummary,
packageDescription in Windows <<= packageDescription,
Expand Down Expand Up @@ -88,8 +89,9 @@ object WindowsPlugin extends AutoPlugin {
wixProductConfig <<= (name in Windows, wixPackageInfo, wixFeatures, wixProductLicense) map { (name, product, features, license) =>
WixHelper.makeWixProductConfig(name, product, features, license)
},
wixConfig <<= (name in Windows, wixPackageInfo, wixProductConfig) map { (name, product, nested) =>
WixHelper.makeWixConfig(name, product, nested)
wixConfig <<= (name in Windows, wixPackageInfo, wixMajorVersion, wixProductConfig) map { (name, product, wmv, nested) =>
val namespaceDefinitions = WixHelper.getNameSpaceDefinitions(wmv)
WixHelper.makeWixConfig(name, product, namespaceDefinitions, nested)
},
wixConfig in Windows <<= wixConfig,
wixProductConfig in Windows <<= wixProductConfig,
Expand Down
41 changes: 38 additions & 3 deletions src/main/scala/com/typesafe/sbt/packager/windows/WixHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ case class ComponentFile(
source: String,
editable: Boolean = false
) extends FeatureComponent
/** Define wix namespace definitions, that depend on the major version of Wix tools **/
case class NamespaceDefinitions(
majorVersionNumber: Int,
namespace: String,
utilExtension: String
)
/**
* Will add the directory to the windows path. NOTE: Only one of these
* per MSI.
Expand Down Expand Up @@ -147,7 +153,6 @@ object WixHelper {
<Shortcut Id={ id + "_SC" + (s"%0${targetSize}d").format(i + 1) } Name={ cleanName } Description={ desc } Target={ "[INSTALLDIR]\\" + target.replaceAll("\\/", "\\\\") } WorkingDirectory="INSTALLDIR"/>
}
}
<RemoveFolder Id="ApplicationProgramsFolderRemove" Directory="ApplicationProgramsFolder" On="uninstall"/>
<RegistryValue Root="HKCU" Key={ "Software\\" + product.maintainer + "\\" + name } Name="installed" Type="integer" Value="1" KeyPath="yes"/>
</Component>
</DirectoryRef>
Expand All @@ -162,11 +167,17 @@ object WixHelper {
f.id -> componentInfos
}).toMap

val removeId = cleanStringForId("ApplicationProgramsFolderRemove").takeRight(67)
<xml:group>
<!-- Define the directories we use -->
<Directory Id='TARGETDIR' Name='SourceDir'>
<Directory Id="ProgramMenuFolder">
<Directory Id="ApplicationProgramsFolder" Name={ name }/>
<Directory Id="ApplicationProgramsFolder" Name={ name }>
<Component Id={ removeId } Guid={ makeGUID }>
<RemoveFolder Id="ApplicationProgramsFolderRemove" On="uninstall"/>
<RegistryValue Root="HKCU" Key={ "Software\\" + product.maintainer + "\\" + name } Name="installed" Type="integer" Value="1" KeyPath="yes"/>
</Component>
</Directory>
</Directory>
<Directory Id='ProgramFilesFolder' Name='PFiles'>
<Directory Id='INSTALLDIR' Name={ name }>
Expand All @@ -183,6 +194,10 @@ object WixHelper {
}
<!-- Now define the features! -->
<Feature Id='Complete' Title={ product.title } Description={ product.description } Display='expand' Level='1' ConfigurableDirectory='INSTALLDIR'>
<!-- Manually added uninstall feautre -->
<Feature Id='Uninstall' Title='Uninstall' Description='Uninstall ApplicationFolder' Level='1' Absent='allow'>
<ComponentRef Id={ removeId }/>
</Feature>
{
for (f <- features)
yield <Feature Id={ f.id } Title={ f.title } Description={ f.desc } Level={ f.level } Absent={ f.absent }>
Expand All @@ -209,9 +224,10 @@ object WixHelper {
def makeWixConfig(
name: String, // package name
product: WindowsProductInfo,
namespaceDefinitions: NamespaceDefinitions,
rest: xml.Node
): xml.Node = {
<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi' xmlns:util='http://schemas.microsoft.com/wix/UtilExtension'>
<Wix xmlns={ namespaceDefinitions.namespace } xmlns:util={ namespaceDefinitions.utilExtension }>
<Product Id={ product.id } Name={ product.title } Language='1033' Version={ product.version } Manufacturer={ product.maintainer } UpgradeCode={ product.upgradeId }>
<Package Description={ product.description } Comments={ product.comments } Manufacturer={ product.maintainer } InstallScope={ product.installScope } InstallerVersion={ product.installerVersion } Compressed={ if (product.compressed) "yes" else "no" }/>
<Media Id='1' Cabinet={ cleanStringForId(name.toLowerCase).takeRight(66) + ".cab" } EmbedCab='yes'/>
Expand All @@ -220,6 +236,25 @@ object WixHelper {
</Wix>
}

/**
* Wix namespace changed from major version 3 to 4.
* TODO: Not sure if schema of 2006 is compatible with major versions < 3
*/
def getNameSpaceDefinitions(majorVersion: Int): NamespaceDefinitions = {
if (majorVersion <= 3)
NamespaceDefinitions(
majorVersion,
namespace = "http://schemas.microsoft.com/wix/2006/wi",
utilExtension = "http://schemas.microsoft.com/wix/UtilExtension"
)
else
NamespaceDefinitions(
majorVersion,
namespace = "http://wixtoolset.org/schemas/v4/wxs",
utilExtension = "http://wixtoolset.org/schemas/v4/wxs/util"
)
}

/**
* Modifies a string to be Wix ID friendly by removing all the bad
* characters and replacing with _. Also limits the width to 70 (rather than
Expand Down
3 changes: 3 additions & 0 deletions src/sphinx/formats/windows.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ Settings
``lightOptions``
the list of options to pass to the ``light.exe`` command. Most likely setting is: ``Seq("-ext", "WixUIExtension", "-cultures:en-us")`` for UI.

``wixMajorVersion``
the major version of the Wix tool-set (e.g. when using Wix 4.0.1, major version is 4). Default is 3.

``wixProductId``
The GUID to use to identify the windows package/product.

Expand Down
37 changes: 37 additions & 0 deletions test-project-windows/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

name := "test-project-windows"
version := "0.2.0"
libraryDependencies ++= Seq(
"com.typesafe" % "config" % "1.2.1"
)

mainClass in Compile := Some("ExampleApp")

enablePlugins(JavaServerAppPackaging, WindowsPlugin, SystemdPlugin, UniversalPlugin)

// import com.typesafe.sbt.packager.Keys._
// import com.typesafe.sbt.packager.windows.WindowsPlugin

maintainer := "some-company <[email protected]>"

packageSummary := "some application"

wixProductId := "ce07be71-510d-414a-92d4-dff47631848b"

wixProductUpgradeId := "4552fb0e-e257-4dbd-9ecb-dba9dbacf425"

lightOptions := Seq("-ext", "WixUiExtension")

wixMajorVersion := 3

version := "0.0.0.0"

packageDescription := """ Some useful description here """

// these settings are conflicting
javaOptions in Universal ++= Seq(
"-J-Xmx64m", "-J-Xms64m",
"-jvm-debug 12345"
)

//bashScriptConfigLocation := Some("${app_home}/../conf/jvmopts")
1 change: 1 addition & 0 deletions test-project-windows/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=0.13.7
5 changes: 5 additions & 0 deletions test-project-windows/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
lazy val root = Project("plugins", file(".")) dependsOn(packager)

lazy val packager = file("..").getAbsoluteFile.toURI

libraryDependencies += "org.vafer" % "jdeb" % "1.3" artifacts (Artifact("jdeb", "jar", "jar"))
22 changes: 22 additions & 0 deletions test-project-windows/src/main/scala/ExampleApp.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import java.util.concurrent._

object ExampleApp extends App {

val executorService = Executors newFixedThreadPool 2

val memory = Runtime.getRuntime.maxMemory() / (1024L * 1024L)
println(s"Memory $memory m")
println(s"Args: ${args mkString " | "}")

while (true) {
for (i <- 0 to 2) executorService execute HelloWorld(i)
Thread sleep 5000
}

}

case class HelloWorld(i: Int) extends Runnable {
def run() {
println(s"[$i] Hello, world!")
}
}
1 change: 1 addition & 0 deletions test-project-windows/src/templates/etc-default-template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# right etc-default template