From 27203f7c0c2b4971b8e3296642a7f7bbfb36f75b Mon Sep 17 00:00:00 2001 From: dion Date: Tue, 14 Oct 2003 06:33:09 +0000 Subject: [PATCH] Start of nsis plugin. NOT YET FUNCTIONAL. Please help with it!!! git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@114191 13f79535-47bb-0310-9956-ffa450edef68 --- nsis/.cvsignore | 5 + nsis/plugin.jelly | 61 +++++++ nsis/plugin.properties | 30 ++++ nsis/project.properties | 7 + nsis/project.xml | 37 +++++ nsis/src/plugin-resources/BrandingImage.nsh | 10 ++ nsis/src/plugin-resources/Environment.nsh | 139 ++++++++++++++++ nsis/src/plugin-resources/GetJRE.nsh | 38 +++++ nsis/src/plugin-resources/JDK.nsh | 11 ++ .../plugin-resources/templates/project.jelly | 30 ++++ .../plugin-resources/templates/setup.jelly | 157 ++++++++++++++++++ 11 files changed, 525 insertions(+) create mode 100644 nsis/.cvsignore create mode 100644 nsis/plugin.jelly create mode 100644 nsis/plugin.properties create mode 100644 nsis/project.properties create mode 100644 nsis/project.xml create mode 100644 nsis/src/plugin-resources/BrandingImage.nsh create mode 100644 nsis/src/plugin-resources/Environment.nsh create mode 100644 nsis/src/plugin-resources/GetJRE.nsh create mode 100644 nsis/src/plugin-resources/JDK.nsh create mode 100644 nsis/src/plugin-resources/templates/project.jelly create mode 100644 nsis/src/plugin-resources/templates/setup.jelly diff --git a/nsis/.cvsignore b/nsis/.cvsignore new file mode 100644 index 00000000..7244964b --- /dev/null +++ b/nsis/.cvsignore @@ -0,0 +1,5 @@ +target +velocity.log +maven.log +.classpath +.project diff --git a/nsis/plugin.jelly b/nsis/plugin.jelly new file mode 100644 index 00000000..a3978c87 --- /dev/null +++ b/nsis/plugin.jelly @@ -0,0 +1,61 @@ + + + + + + + + + + FIXME: Not Finished + + + + + + + Creating ${generatedFileName} ... + + + + + + + + + + + Creating ${generatedFileName} ... + + + + + + + + + + + + + + + + + + + + + + diff --git a/nsis/plugin.properties b/nsis/plugin.properties new file mode 100644 index 00000000..14a526e9 --- /dev/null +++ b/nsis/plugin.properties @@ -0,0 +1,30 @@ +# ------------------------------------------------------------------- +# P L U G I N P R O P E R I E S +# ------------------------------------------------------------------- +# NSIS plugin. +# ------------------------------------------------------------------- + +# +# This is the jelly template used to create the project.nsh file +# +maven.nsis.project.template=${plugin.resources}/templates/project.jelly + +# +# This is the jelly template used to create the project.nsh file +# +maven.nsis.setup.template=${plugin.resources}/templates/setup.jelly + +# +# FIXME: Should be able to get this from the POM. +# +maven.nsis.license.text=This program is Licensed under The Apache Software License, Version 1.1. + +# +# location of makensis.exe +# +maven.nsis.exe=C:/Program Files/NSIS/makensis.exe + +# +# source of extra files for nsis +# +maven.nsis.src=${basedir}/src/nsis \ No newline at end of file diff --git a/nsis/project.properties b/nsis/project.properties new file mode 100644 index 00000000..b9da0814 --- /dev/null +++ b/nsis/project.properties @@ -0,0 +1,7 @@ +# ------------------------------------------------------------------- +# P R O J E C T P R O P E R T I E S +# ------------------------------------------------------------------- +maven.xdoc.date=left +maven.xdoc.version=${pom.currentVersion} +maven.license.licenseFile=${basedir}/../LICENSE.txt + diff --git a/nsis/project.xml b/nsis/project.xml new file mode 100644 index 00000000..314cc589 --- /dev/null +++ b/nsis/project.xml @@ -0,0 +1,37 @@ + + + + ../project.xml + 3 + maven-nsis-plugin + Maven NSIS Plug-in + 1.0-SNAPSHOT + A plugin to generate Win32 installer programs using NSIS + NSIS Plugin for Maven + http://maven.apache.org/reference/plugins/nsis/ + /www/maven.apache.org/reference/plugins/nsis/ + + scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:maven-plugins/nsis/ + http://cvs.apache.org/viewcvs/maven-plugins/nsis/ + + + + + 1.0 + 1.0 + HEAD + + + + + + dIon Gillard + dion + dion@multitask.com.au + Multitask Consulting + + Java Developer + + + + diff --git a/nsis/src/plugin-resources/BrandingImage.nsh b/nsis/src/plugin-resources/BrandingImage.nsh new file mode 100644 index 00000000..ef9bd91c --- /dev/null +++ b/nsis/src/plugin-resources/BrandingImage.nsh @@ -0,0 +1,10 @@ +; macro for the image on the install screen +!macro BrandingImage IMAGE PARMS + Push $0 + GetTempFileName $0 + File /oname=$0 "${IMAGE}" + SetBrandingImage ${PARMS} $0 + Delete $0 + Pop $0 +!macroend + diff --git a/nsis/src/plugin-resources/Environment.nsh b/nsis/src/plugin-resources/Environment.nsh new file mode 100644 index 00000000..1d99e6ca --- /dev/null +++ b/nsis/src/plugin-resources/Environment.nsh @@ -0,0 +1,139 @@ +; +; From NSISArchives http://nsis.sourceforge.net/archive/nsisweb.php?page=156&instances=0,11 +; +!include WinMessages.nsh + +!ifdef ALL_USERS + !define WriteEnvStr_RegKey \ + 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"' +!else + !define WriteEnvStr_RegKey 'HKCU "Environment"' +!endif + +# +# WriteEnvStr - Writes an environment variable +# Note: Win9x systems requires reboot +# +# Example: +# Push "HOMEDIR" # name +# Push "C:\New Home Dir\" # value +# Call WriteEnvStr +# +Function WriteEnvStr + Exch $1 ; $1 has environment variable value + Exch + Exch $0 ; $0 has environment variable name + Push $2 + + Call IsNT + Pop $2 + StrCmp $2 1 WriteEnvStr_NT + ; Not on NT + StrCpy $2 $WINDIR 2 ; Copy drive of windows (c:) + FileOpen $2 "$2\autoexec.bat" a + FileSeek $2 0 END + FileWrite $2 "$\r$\nSET $0=$1$\r$\n" + FileClose $2 + SetRebootFlag true + Goto WriteEnvStr_done + + WriteEnvStr_NT: + WriteRegExpandStr ${WriteEnvStr_RegKey} $0 $1 + SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} \ + 0 "STR:Environment" /TIMEOUT=5000 + + WriteEnvStr_done: + Pop $2 + Pop $1 + Pop $0 +FunctionEnd + +# +# un.DeleteEnvStr - Removes an environment variable +# Note: Win9x systems requires reboot +# +# Example: +# Push "HOMEDIR" # name +# Call un.DeleteEnvStr +# +Function un.DeleteEnvStr + Exch $0 ; $0 now has the name of the variable + Push $1 + Push $2 + Push $3 + Push $4 + Push $5 + + Call un.IsNT + Pop $1 + StrCmp $1 1 DeleteEnvStr_NT + ; Not on NT + StrCpy $1 $WINDIR 2 + FileOpen $1 "$1\autoexec.bat" r + GetTempFileName $4 + FileOpen $2 $4 w + StrCpy $0 "SET $0=" + SetRebootFlag true + + DeleteEnvStr_dosLoop: + FileRead $1 $3 + StrLen $5 $0 + StrCpy $5 $3 $5 + StrCmp $5 $0 DeleteEnvStr_dosLoop + StrCmp $5 "" DeleteEnvStr_dosLoopEnd + FileWrite $2 $3 + Goto DeleteEnvStr_dosLoop + + DeleteEnvStr_dosLoopEnd: + FileClose $2 + FileClose $1 + StrCpy $1 $WINDIR 2 + Delete "$1\autoexec.bat" + CopyFiles /SILENT $4 "$1\autoexec.bat" + Delete $4 + Goto DeleteEnvStr_done + + DeleteEnvStr_NT: + DeleteRegValue ${WriteEnvStr_RegKey} $0 + SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} \ + 0 "STR:Environment" /TIMEOUT=5000 + + DeleteEnvStr_done: + Pop $5 + Pop $4 + Pop $3 + Pop $2 + Pop $1 + Pop $0 +FunctionEnd + +# +# [un.]IsNT - Pushes 1 if running on NT, 0 if not +# +# Example: +# Call IsNT +# Pop $0 +# StrCmp $0 1 +3 +# MessageBox MB_OK "Not running on NT!" +# Goto +2 +# MessageBox MB_OK "Running on NT!" +# +!macro IsNT UN +Function ${UN}IsNT + Push $0 + ReadRegStr $0 HKLM \ + "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion + StrCmp $0 "" 0 IsNT_yes + ; we are not NT. + Pop $0 + Push 0 + Return + + IsNT_yes: + ; NT!!! + Pop $0 + Push 1 +FunctionEnd +!macroend +!insertmacro IsNT "" +!insertmacro IsNT "un." diff --git a/nsis/src/plugin-resources/GetJRE.nsh b/nsis/src/plugin-resources/GetJRE.nsh new file mode 100644 index 00000000..4d3823c7 --- /dev/null +++ b/nsis/src/plugin-resources/GetJRE.nsh @@ -0,0 +1,38 @@ +; +; Found in the NSIS Archives http://nsis.sourceforge.net/archive/nsisweb.php?page=326&instances=0,64 +; +Function GetJRE +; +; Find JRE (Java.exe) +; 1 - in .\jre directory (JRE Installed with application) +; 2 - in JAVA_HOME environment variable +; 3 - in the registry +; 4 - assume java.exe in current dir or PATH + + Push $R0 + Push $R1 + + ClearErrors + StrCpy $R0 "$EXEDIR\jre\bin\java.exe" + IfFileExists $R0 JreFound + StrCpy $R0 "" + + ClearErrors + ReadEnvStr $R0 "JAVA_HOME" + StrCpy $R0 "$R0\bin\java.exe" + IfErrors 0 JreFound + + ClearErrors + ReadRegStr $R1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" +"CurrentVersion" + ReadRegStr $R0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$R1" +"JavaHome" + StrCpy $R0 "$R0\bin\java.exe" + + IfErrors 0 JreFound + StrCpy $R0 "java.exe" + + JreFound: + Pop $R1 + Exch $R0 +FunctionEnd diff --git a/nsis/src/plugin-resources/JDK.nsh b/nsis/src/plugin-resources/JDK.nsh new file mode 100644 index 00000000..6f5fa057 --- /dev/null +++ b/nsis/src/plugin-resources/JDK.nsh @@ -0,0 +1,11 @@ +Function AssertJavaHome + ClearErrors + ReadEnvStr $0 "JAVA_HOME" + + IfErrors 0 Found + ClearErrors + MessageBox MB_OK|MB_ICONSTOP "The JAVA_HOME environment variable must be set. Please set JAVA_HOME to the location of your JDK and try installing again" + Abort + + Found: +FunctionEnd diff --git a/nsis/src/plugin-resources/templates/project.jelly b/nsis/src/plugin-resources/templates/project.jelly new file mode 100644 index 00000000..46c526c5 --- /dev/null +++ b/nsis/src/plugin-resources/templates/project.jelly @@ -0,0 +1,30 @@ + + + + + + +; template for project details +; generated by ${user.name} from project.xml version ${pom.currentVersion} +; on date ${TODAY}, time ${TSTAMP} + +!define ORGANIZATION "${pom.organization}" +!define PROJECT_BUILD_DIR "${build}" +!define PROJECT_FINAL_NAME "${maven.final.name}" +!define PROJECT_LICENSE_FILE "${license}" +!define PROJECT_LICENSE_TEXT "${maven.nsis.license.text}" +!define PROJECT_NAME "${pom.name}" +!define PROJECT_REG_KEY "SOFTWARE\${pom.organization}\${pom.name}\${pom.currentVersion}" +!define PROJECT_REG_UNINSTALL_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${pom.name} ${pom.version}" +!define PROJECT_STARTMENU_FOLDER "$$SMPROGRAMS\${pom.organization}\${pom.name} ${pom.currentVersion}" +!define PROJECT_VERSION "${pom.currentVersion}" +!define PROJECT_DIST_DIR "${maven.dist.bin.assembly.dir}" + + + \ No newline at end of file diff --git a/nsis/src/plugin-resources/templates/setup.jelly b/nsis/src/plugin-resources/templates/setup.jelly new file mode 100644 index 00000000..e407d8d3 --- /dev/null +++ b/nsis/src/plugin-resources/templates/setup.jelly @@ -0,0 +1,157 @@ + + + +; Author Kristen Gillard +; Author Dion Gillard +; Installation Script for Maven +; http://maven.apache.org/ + +; add directories for the source if it exists, and the plugin + +; add project source onto the include list +!addincludedir "${maven.nsis.src}" + +!addincludedir "${maven.build.dir}" +!addincludedir "${plugin.resources}" + +; macro for the image on the install screen +!include "BrandingImage.nsh" +!include "JDK.nsh" +!include "Environment.nsh" + +; include project specific details +!include "project.nsh" + +; Do a Cyclic Redundancy Check to make sure the installer is not corrupt +CRCCheck on + +; The name of the installer +Name "${PROJECT_NAME}" + +; Maven Setup executable +OutFile "${PROJECT_BUILD_DIR}\${PROJECT_FINAL_NAME}.exe" + +; Adds an XP manifest to the installer +XPStyle on + +; branding with maven logo +AddBrandingImage left 70|267 + +; Sets the font of the installer +SetFont "Arial" 8 + +; License Information +LicenseText "This program is Licensed under The Apache Software License, Version 1.1." +LicenseData "${PROJECT_LICENSE_FILE}" + +; The default installation directory +InstallDir "$PROGRAMFILES\${ORGANIZATION}\${PROJECT_NAME} ${PROJECT_VERSION}" +; Registry key to check for directory (so if you upgrade, it will +; overwrite the old one automatically) +InstallDirRegKey HKLM "${PROJECT_REG_KEY}" "Install_Dir" + +; The text to prompt the user to enter a directory +ComponentText "This will install ${PROJECT_NAME} on your computer." +; The text to prompt the user to enter a directory +DirText "${PROJECT_NAME} Home Directory" + +; -------------------------------------------------------------- Package up the files to be installed +Section "${PROJECT_NAME} v${PROJECT_VERSION} Binaries" + ; Set output path to the installation directory. + SetOutPath $INSTDIR + ; Put files and directories there + ; the script will be run from a directory below Maven + File /r "${PROJECT_DIST_DIR}\*.*" + + ; Write the installation path into the registry + WriteRegStr HKLM "${PROJECT_REG_KEY}" "Install_Dir" "$INSTDIR" + + ; Write the environment variables to the Registry + ; ${MAVEN_HOME} + Push "MAVEN_HOME" + Push "$INSTDIR" + Call WriteEnvStr + + ; TODO - Add MAVEN_HOME to the path + + ; TODO Prompt and write other environment variables to the Registry + ; WriteRegStr HKCU "Environment" "MAVEN_LOCAL_HOME" "$INSTDIR" + + ; Write the uninstall keys for Windows + WriteRegStr HKLM "${PROJECT_REG_UNINSTALL_KEY}" "DisplayName" "${PROJECT_NAME} ${PROJECT_VERSION} (remove only)" + WriteRegStr HKLM "${PROJECT_REG_UNINSTALL_KEY}" "UninstallString" '"$INSTDIR\Uninst.exe"' +SectionEnd + +; -------------------------------------------------------------- Create Shortcuts +Section "Create Start Menu Shortcut(s)" +; it would be nice to get all this from navigation.xml :-) + CreateDirectory "${PROJECT_STARTMENU_FOLDER}" + CreateShortCut "${PROJECT_STARTMENU_FOLDER}\Maven.lnk" "$INSTDIR\bin\maven.bat" "" "$INSTDIR\bin\maven.bat" 0 + CreateShortCut "${PROJECT_STARTMENU_FOLDER}\Install Maven Repository.lnk" "$INSTDIR\bin\install_repo.bat" "" "$INSTDIR\install_repo.bat" 0 + CreateShortCut "${PROJECT_STARTMENU_FOLDER}\Uninstall.lnk" "$INSTDIR\Uninst.exe" "" "$INSTDIR\Uninst.exe" 0 + CreateShortCut "${PROJECT_STARTMENU_FOLDER}\Homepage.lnk" "http://maven.apache.org/" + CreateShortCut "${PROJECT_STARTMENU_FOLDER}\User Guide.lnk" "http://maven.apache.org/reference/user-guide.html" + CreateShortCut "${PROJECT_STARTMENU_FOLDER}\Core Plugins.lnk" "http://maven.apache.org/reference/plugins/core-plugins.html" + CreateShortCut "${PROJECT_STARTMENU_FOLDER}\Optional Plugins.lnk" "http://maven.apache.org/reference/plugins/optional/optional.html" + CreateShortCut "${PROJECT_STARTMENU_FOLDER}\Reference.lnk" "http://maven.apache.org/reference/index.html" + CreateShortCut "${PROJECT_STARTMENU_FOLDER}\Report a Bug.lnk" "http://jira.codehaus.org/secure/BrowseProject.jspa?id=10030" + CreateShortCut "${PROJECT_STARTMENU_FOLDER}\Frequently Asked Questions.lnk" "http://maven.apache.org/faq.html" +SectionEnd + +; OPTIONAL Desktop Shortcut +; Section "Create Desktop Shortcut" +; CreateShortCut "$DESKTOP\Maven.lnk" "$INSTDIR\bin\maven.bat" "" "$INSTDIR\bin\maven.bat" +;SectionEnd + +; -------------------------------------------------------------- Section to Install the Uninstaller +Section "Install Uninstaller" + ; write the uninstaller to the installation directory + WriteUninstaller "$INSTDIR\Uninst.exe" +SectionEnd + +; -------------------------------------------------------------- Maven Uninstaller +Section "Uninstall" + ; remove registry keys + DeleteRegKey HKLM "${PROJECT_REG_UNINSTALL_KEY}" + DeleteRegKey HKLM "${PROJECT_REG_KEY}" + + ; Remove ${MAVEN_HOME} + Push "MAVEN_HOME" + Call un.DeleteEnvStr + + ; remove files + Delete $INSTDIR\*.* + + ; MUST REMOVE UNINSTALLER, too + Delete $INSTDIR\Uninst.exe + + ; remove shortcuts, if any. + Delete "${PROJECT_STARTMENU_FOLDER}\*.*" + RMDir "${PROJECT_STARTMENU_FOLDER}" + ; Delete "$DESKTOP\Maven.lnk" + ; Recursively remove files and directories used + ; this should also take care of the installer + RMDir /r "$INSTDIR" + ; MessageBox MB_OK|MB_ICONEXCLAMATION "Maven has been 'Uninstalled'" +SectionEnd + +; -------------------------------------------------------------- Add Images to the Installer / UnInstaller +Function .onGUIInit + !insertmacro BrandingImage "maven.bmp" "" + ; TODO Check for a JAVA_HOME environment variable + Call AssertJavaHome + +FunctionEnd + +; add the maven logo to the un-installer +Function un.onGUIInit + !insertmacro BrandingImage "maven.bmp" "" +FunctionEnd + +; -------------------------------------------------------------- End of File + \ No newline at end of file