From 5c3bcc55963738ccb996f61ffff69e74a219b2e9 Mon Sep 17 00:00:00 2001
From: vharseko <vharseko@openam.org.ru>
Date: Tue, 06 Mar 2018 08:52:43 +0000
Subject: [PATCH] allow build MSI on Unix/Mac (wix from wine)

---
 opendj-packages/opendj-msi/opendj-msi-standard/resources/msi/package.wxs |   15 +-
 opendj-packages/opendj-msi/opendj-msi-standard/pom.xml                   |  188 +++++++++++++++++++++++++++++++-----
 .travis.yml                                                              |    2 
 opendj-packages/opendj-msi/pom.xml                                       |   38 +++++++
 4 files changed, 205 insertions(+), 38 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index cf9cf9c..1c9f241 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -33,7 +33,7 @@
         - "opendj-ldap-toolkit/target/*.zip"
         - "opendj-packages/opendj-deb/opendj-deb-standard/target/*.deb"
         - "opendj-packages/opendj-rpm/opendj-rpm-standard/target/rpm/opendj/RPMS/noarch/*.rpm"
-        - "opendj-packages/opendj-msi/opendj-msi-standart/target/*.msi"
+        - "opendj-packages/opendj-msi/opendj-msi-standard/target/*.msi"
         - "opendj-packages/opendj-docker/target/Dockerfile"
         - "opendj-doc-generated-ref/target/*.zip"
         - "opendj-dsml-servlet/target/*.war"
diff --git a/opendj-packages/opendj-msi/opendj-msi-standard/pom.xml b/opendj-packages/opendj-msi/opendj-msi-standard/pom.xml
index 75d3ac3..7847a6c 100644
--- a/opendj-packages/opendj-msi/opendj-msi-standard/pom.xml
+++ b/opendj-packages/opendj-msi/opendj-msi-standard/pom.xml
@@ -13,6 +13,7 @@
   information: "Portions Copyright [year] [name of copyright owner]".
 
   Copyright 2015-2016 ForgeRock AS.
+  Portions Copyright 2018 Open Identity Platform Community
 -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
@@ -20,7 +21,7 @@
     <parent>
         <groupId>org.forgerock.opendj</groupId>
         <artifactId>opendj-msi</artifactId>
-        <version>4.0.0-SNAPSHOT</version>
+        <version>4.1.5-SNAPSHOT</version>
     </parent>
 
     <artifactId>opendj-msi-standard</artifactId>
@@ -36,7 +37,10 @@
         <msi.resources>${basedir}/resources/msi</msi.resources>
         <package.dir>${project.build.directory}/${product.name.lowercase}</package.dir>
     </properties>
+	
+	<dependencies>
 
+	</dependencies>
     <build>
         <plugins>
             <plugin>
@@ -48,21 +52,127 @@
                 <artifactId>maven-dependency-plugin</artifactId>
             </plugin>
 
+			<plugin>
+				<groupId>com.savage7.maven.plugins</groupId>
+				<artifactId>maven-external-dependency-plugin</artifactId>
+				<version>0.6-SNAPSHOT</version>
+				<inherited>false</inherited>
+				<configuration>
+					<stagingDirectory>
+						${project.build.directory}/dependencies/
+                    </stagingDirectory>
+					<createChecksum>false</createChecksum>
+					<skipChecksumVerification>true</skipChecksumVerification>
+					<force>false</force>
+					<artifactItems>
+						<artifactItem>
+							<groupId>wixtoolset.org</groupId>
+							<artifactId>wixtoolset</artifactId>
+							<version>3.11.1</version>
+							<packaging>zip</packaging>
+							<install>true</install>
+							<downloadUrl>
+									https://github.com/wixtoolset/wix3/releases/download/wix3111rtm/wix311-binaries.zip
+	                        </downloadUrl>
+						</artifactItem>
+						<artifactItem>
+							<groupId>winetricks</groupId>
+							<artifactId>winetricks</artifactId>
+							<version>LAST</version>
+							<packaging>sh</packaging>
+							<install>true</install>
+							<downloadUrl>
+								https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks
+	                        </downloadUrl>
+						</artifactItem>
+					</artifactItems>
+				</configuration>
+				<executions>
+					<execution>
+						<id>clean-external-dependencies</id>
+						<phase>clean</phase>
+						<goals>
+							<goal>clean-external</goal>
+						</goals>
+					</execution>
+					<execution>
+						<id>resolve-install-external-dependencies</id>
+						<phase>process-resources</phase>
+						<goals>
+							<goal>resolve-external</goal>
+							<goal>install-external</goal>
+						</goals>
+					</execution>
+					<execution>
+						<id>deploy-external-dependencies</id>
+						<phase>deploy</phase>
+						<goals>
+							<goal>deploy-external</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
+			<plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-dependency-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>unpack-wix</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>unpack</goal>
+                        </goals>
+                        <configuration>
+                            <artifactItems>
+			                 	<artifactItem>
+				                   	<groupId>wixtoolset.org</groupId>
+								   	<artifactId>wixtoolset</artifactId>
+								    <version>3.11.1</version>
+									<type>zip</type>
+			                		 </artifactItem>
+			                </artifactItems>
+                            <outputDirectory>
+                                ${project.build.directory}/wix
+                            </outputDirectory>
+                        </configuration>
+                    </execution>
+                    <execution>
+                        <id>unpack-winetricks</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>copy</goal>
+                        </goals>
+                        <configuration>
+                            <artifactItems>
+			                 	<artifactItem>
+				                   	<groupId>winetricks</groupId>
+									<artifactId>winetricks</artifactId>
+									<version>LAST</version>
+									<type>sh</type>
+			                		 </artifactItem>
+			                </artifactItems>
+                            <outputDirectory>
+                                ${project.build.directory}/winetricks
+                            </outputDirectory>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-antrun-plugin</artifactId>
                 <executions>
                     <execution>
-                        <id>build-msi-package</id>
+                        <id>build-msi-package-prepare</id>
                         <phase>package</phase>
                         <goals>
                             <goal>run</goal>
                         </goals>
                         <configuration>
-                            <!-- Package the Directory Server for the MSI distribution. -->
                             <target>
-                                <mkdir dir="${project.build.directory}/msi/files" />
-                                <copy toDir="${project.build.directory}/msi/files">
+                            	   <delete  dir="${user.home}/.msi" />
+                                <mkdir dir="${user.home}/.msi" />
+                                <copy toDir="${user.home}/.msi">
                                     <fileset dir="${package.dir}">
                                         <!-- Exclude Mac apps -->
                                         <exclude name="QuickSetup.app/**" />
@@ -81,29 +191,47 @@
                                 <copy file="${msi.resources}/package.wxs" toDir="${project.build.directory}/msi/build" />
                                 <copy file="${msi.resources}/opendjbanner.bmp" toDir="${project.build.directory}/msi/build" />
                                 <copy file="${msi.resources}/opendjdialog.bmp" toDir="${project.build.directory}/msi/build" />
-                                <mkdir dir="${project.build.directory}/msi/dist" />
-
-                                <!-- Construct a .wxs file from the directory structure -->
-                                <exec executable="heat.exe" dir="${project.build.directory}/msi/files">
-                                    <arg value="dir" />
-                                    <arg value="." />
+								
+								<exec executable="wine" resultproperty="WineExitStatusCode" failifexecutionfails="false">
+									<arg value="wineboot" />
+									<arg value="--init" />
+								</exec>
+								<echo>WineExitStatusCode=${WineExitStatusCode}</echo>
+								
+								<exec executable="sh" resultproperty="WineTricksExitStatusCode"  failifexecutionfails="false">
+									<arg value="${project.build.directory}/winetricks/winetricks-LAST.sh" />
+									<arg value="--unattended" />
+									<arg value="dotnet40" />
+									<arg value="dotnet_verifier" />
+								</exec>
+								<echo>WineTricksExitStatusCode=${WineTricksExitStatusCode}</echo>
+								
+								<property name="exec.heat" value="wine" /><property name="param.heat" value="${project.build.directory}/wix/heat.exe" />
+								<property name="exec.candle" value="wine" /><property name="param.candle" value="${project.build.directory}/wix/candle.exe" />
+								<property name="exec.light" value="wine" /><property name="param.light" value="${project.build.directory}/wix/light.exe" />
+							    
+							    <echo>------------------- ${exec.heat} ${param.heat} -------------------</echo>
+								<exec executable="${exec.heat}" dir="${project.build.directory}/msi" failifexecutionfails="false" resultproperty="heatStatusCode">
+								   <arg value="${param.heat}" />
+                                    <arg value="dir" /> <arg value="${user.home}/.msi" />
                                     <arg value="-nologo" />
-                                    <arg value="-cg" /> <arg value="all" />
+                                    <arg value="-cg" /><arg value="all" />
                                     <arg value="-gg" />
                                     <arg value="-sfrag" />
                                     <arg value="-srd" />
                                     <arg value="-ke" />
-                                    <arg value="-dr" /> <arg value="OPENDJ" />
-                                    <arg value="-var" /> <arg value="var.src" />
-                                    <arg value="-template" /> <arg value="fragment" />
-                                    <arg value="-o" /> <arg value="${project.build.directory}/msi/build/payload.wxs" />
+                                    <arg value="-dr" /><arg value="OPENDJ" />
+                                    <arg value="-var" /><arg value="var.src" />
+                                    <arg value="-template" /><arg value="fragment" />
+                                    <arg value="-o" /><arg value="build/payload.wxs" />
+                                    <arg value="-v" />
                                 </exec>
-
-                                <!-- Compile all .wxs files into .wixobj files (fast) -->
-                                <exec executable="candle.exe" dir="${project.build.directory}/msi">
+                                <echo>------------------- ${exec.candle} ${param.candle} -------------------</echo>
+                                <exec executable="${exec.candle}" dir="${project.build.directory}/msi"  resultproperty="candleStatusCode"  >
+                                	   <arg value="${param.candle}" />
                                     <arg value="-nologo" />
-                                    <arg value="-out" /> <arg value="${project.build.directory}/msi/build/" />
-                                    <arg value="-dsrc=files" />
+                                    <arg value="-out" /> <arg value="build/" />
+                                    <arg value="-dsrc=${user.home}/.msi" />
                                     <arg value="-dname=${product.name}" />
                                     <arg value="-dmajor=${parsedVersion.majorVersion}" />
                                     <arg value="-dminor=${parsedVersion.minorVersion}" />
@@ -111,18 +239,20 @@
                                     <arg value="build/package.wxs" />
                                     <arg value="build/payload.wxs" />
                                 </exec>
-
-                                <!-- Build the package (slow) -->
-                                <exec executable="light.exe" dir="${project.build.directory}/msi">
+                                <echo>------------------- ${exec.light} ${param.light} -------------------</echo>
+                                <exec executable="${exec.light}" dir="${project.build.directory}/msi" resultproperty="lightStatusCode" >
+                                	   <arg value="${param.light}" />
                                     <arg value="-nologo" />
                                     <arg value="-ext" /> <arg value="WixUIExtension" />
-                                    <arg value="-out" /> <arg value="dist/${product.name.lowercase}-${project.version}.msi" />
+                                    <arg value="-out" /> <arg value="../${product.name.lowercase}-${project.version}.msi" />
+                                     <arg value="-sval" />
                                     <arg value="build/package.wixobj" />
                                     <arg value="build/payload.wixobj" />
                                 </exec>
-
-                                <!-- Attach msi artifact to the build -->
-                                <attachartifact file="${project.build.directory}/msi/dist/${product.name.lowercase}-${project.version}.msi" />
+                                <echo>lightStatusCode=${lightStatusCode}</echo>
+                                <delete  dir="${user.home}/.msi" />
+                                
+                                <attachartifact file="${project.build.directory}/${product.name.lowercase}-${project.version}.msi" />
                             </target>
                         </configuration>
                     </execution>
@@ -130,4 +260,4 @@
             </plugin>
         </plugins>
     </build>
-</project>
+</project>
\ No newline at end of file
diff --git a/opendj-packages/opendj-msi/opendj-msi-standard/resources/msi/package.wxs b/opendj-packages/opendj-msi/opendj-msi-standard/resources/msi/package.wxs
index beddf44..23f4dd4 100644
--- a/opendj-packages/opendj-msi/opendj-msi-standard/resources/msi/package.wxs
+++ b/opendj-packages/opendj-msi/opendj-msi-standard/resources/msi/package.wxs
@@ -13,19 +13,20 @@
  ! information: "Portions Copyright [year] [name of copyright owner]".
  !
  ! Copyright 2013-2016 ForgeRock AS.
+ ! Portion Copyright 2018 Open Identity Platform Community
  ! -->
 <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
-  <Product Id="*" Codepage="1252" Language="1033" Manufacturer="ForgeRock"
-           Name="ForgeRock $(var.name) $(var.major).$(var.minor).$(var.point)" Version="$(var.major).$(var.minor).$(var.point)"
+  <Product Id="*" Codepage="1252" Language="1033" Manufacturer="Open Identity Platform Community"
+           Name="$(var.name) $(var.major).$(var.minor).$(var.point)" Version="$(var.major).$(var.minor).$(var.point)"
            UpgradeCode="A3E82AC0-88E6-4DEE-9D8C-5AE3B7853274">
-    <Package Id="*" Comments="This package contains ForgeRock $(var.name) $(var.major).$(var.minor).$(var.point)."
-             Description="ForgeRock products" InstallerVersion="300" Languages="1033" Manufacturer="ForgeRock"
+    <Package Id="*" Comments="This package contains $(var.name) $(var.major).$(var.minor).$(var.point)."
+             Description="Open Identity Platform Community products" InstallerVersion="300" Languages="1033" Manufacturer="Open Identity Platform Community"
              Platform="x86" Compressed="yes"/>
-    <Media Id="1" Cabinet="opendj.cab" DiskPrompt="Disk 1" EmbedCab="yes" CompressionLevel="high"/>
-    <Property Id="DiskPrompt" Value="ForgeRock $(var.name) $(var.major).$(var.minor).$(var.point) Installation"/>
+    <Media Id="1" Cabinet="opendj.cab" DiskPrompt="Disk 1" EmbedCab="yes" CompressionLevel="none"/>
+    <Property Id="DiskPrompt" Value="$(var.name) $(var.major).$(var.minor).$(var.point) Installation"/>
 
     <Property Id="ALLUSERS" Value="1"/>
-    <Property Id="ARPHELPLINK" Value="http://forgerock.com"/>
+    <Property Id="ARPHELPLINK" Value="https://github.com/OpenIdentityPlatform/OpenDJ/wiki"/>
 
     <!-- UI customization -->
     <WixVariable Id="WixUIBannerBmp" Value="opendjbanner.bmp" />
diff --git a/opendj-packages/opendj-msi/pom.xml b/opendj-packages/opendj-msi/pom.xml
index d908733..9281873 100644
--- a/opendj-packages/opendj-msi/pom.xml
+++ b/opendj-packages/opendj-msi/pom.xml
@@ -34,10 +34,46 @@
 
     <profiles>
         <profile>
-            <id>packages</id>
+            <id>/usr/bin/wine</id>
+            <activation>
+            		<os><family>unix</family></os>
+            		<file><exists>/usr/bin/wine</exists></file>
+            	</activation>
             <modules>
                 <module>opendj-msi-standard</module>
             </modules>
+            <properties>
+            		<exec.heat>/usr/bin/wine</exec.heat><param.heat>${project.build.directory}/wix/heat.exe</param.heat>
+		        <exec.candle>/usr/bin/wine</exec.candle><param.candle>${project.build.directory}/wix/candle.exe</param.candle>
+		        <exec.light>/usr/bin/wine</exec.light><param.light>${project.build.directory}/wix/light.exe</param.light>
+            </properties>
+        </profile>
+        <profile>
+            <id>/opt/local/bin/wine</id>
+            <activation>
+            		<os><family>unix</family></os>
+            		<file><exists>/opt/local/bin/wine</exists></file>
+            	</activation>
+            <modules>
+                <module>opendj-msi-standard</module>
+            </modules>
+            <properties>
+            		<exec.heat>/opt/local/bin/wine</exec.heat><param.heat>${project.build.directory}/wix/heat.exe</param.heat>
+		        <exec.candle>/opt/local/bin/wine</exec.candle><param.candle>${project.build.directory}/wix/candle.exe</param.candle>
+		        <exec.light>/opt/local/bin/wine</exec.light><param.light>${project.build.directory}/wix/light.exe</param.light>
+            </properties>
+        </profile>
+         <profile>
+            <id>windows</id>
+            <activation><os><family>windows</family></os></activation>
+            <modules>
+                <module>opendj-msi-standard</module>
+            </modules>
+            <properties>
+                <exec.heat>${project.build.directory}/wix/heat.exe</exec.heat><param.heat></param.heat>
+		        <exec.candle>${project.build.directory}/wix/candle.exe</exec.candle><param.candle></param.candle>
+		        <exec.light>${project.build.directory}/wix/light.exe</exec.light><param.light></param.light>
+            </properties>
         </profile>
     </profiles>
 </project>

--
Gitblit v1.10.0