jnlp-impl.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  4. Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
  5. Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  6. Other names may be trademarks of their respective owners.
  7. The contents of this file are subject to the terms of either the GNU
  8. General Public License Version 2 only ("GPL") or the Common
  9. Development and Distribution License("CDDL") (collectively, the
  10. "License"). You may not use this file except in compliance with the
  11. License. You can obtain a copy of the License at
  12. http://www.netbeans.org/cddl-gplv2.html
  13. or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  14. specific language governing permissions and limitations under the
  15. License. When distributing the software, include this License Header
  16. Notice in each file and include the License file at
  17. nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
  18. particular file as subject to the "Classpath" exception as provided
  19. by Oracle in the GPL Version 2 section of the License file that
  20. accompanied this code. If applicable, add the following below the
  21. License Header, with the fields enclosed by brackets [] replaced by
  22. your own identifying information:
  23. "Portions Copyrighted [year] [name of copyright owner]"
  24. Contributor(s):
  25. The Original Software is NetBeans. The Initial Developer of the Original
  26. Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
  27. Microsystems, Inc. All Rights Reserved.
  28. If you wish your version of this file to be governed by only the CDDL
  29. or only the GPL Version 2, indicate your decision by adding
  30. "[Contributor] elects to include this software in this distribution
  31. under the [CDDL or GPL Version 2] license." If you do not indicate a
  32. single choice of license, a recipient has the option to distribute
  33. your version of this file under either the CDDL, the GPL Version 2 or
  34. to extend the choice of license to its licensees as provided above.
  35. However, if you add GPL Version 2 code and therefore, elected the GPL
  36. Version 2 license, then the option applies only if the new code is
  37. made subject to such option by the copyright holder.
  38. -->
  39. <project name="jnlp-impl" default="default" basedir=".." xmlns:jnlp="http://www.netbeans.org/ns/j2se-project/jnlp">
  40. <property name="jnlp.file.name.default" value="launch.jnlp"/>
  41. <property name="jnlp.dest.dir" location="dist"/>
  42. <!-- helper file to create list of arguments, etc. -->
  43. <property name="helper.file" location="helper.txt"/>
  44. <target name="default">
  45. <echo message="Default target is not set, you must specify which target you want to run."/>
  46. </target>
  47. <target name="-init-platform" unless="platform.home">
  48. <property name="platform.home" value="${java.home}"/>
  49. </target>
  50. <!-- Main target -->
  51. <target name="jnlp" depends="-init-filename,-test-jnlp-enabled,-do-jar-jnlp" if="is.jnlp.enabled">
  52. <makeurl property="jnlp.local.codebase.url" file="${basedir}/dist" validate="false"/>
  53. <antcall target="generate-jnlp"/>
  54. <antcall target="generate-html-preview"/>
  55. </target>
  56. <!-- JNLP archiving -->
  57. <target name="-init-macrodef-jnlp-copylibs">
  58. <macrodef name="copylibs" uri="http://www.netbeans.org/ns/j2se-project/jnlp">
  59. <element name="customize" optional="true"/>
  60. <sequential>
  61. <property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
  62. <pathconvert property="run.classpath.without.build.classes.dir">
  63. <path path="${run.classpath}"/>
  64. <map from="${build.classes.dir.resolved}" to=""/>
  65. </pathconvert>
  66. <taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" classpath="${libs.CopyLibs.classpath}" name="copylibs"/>
  67. <copylibs compress="${jar.compress}" index="${jar.index}" jarfile="${dist.jar}" manifest="${tmp.manifest.file}" runtimeclasspath="${run.classpath.without.build.classes.dir}">
  68. <fileset dir="${build.classes.dir}"/>
  69. <manifest>
  70. <customize/>
  71. </manifest>
  72. </copylibs>
  73. </sequential>
  74. </macrodef>
  75. </target>
  76. <target name="-init-macrodef-extend-manifest">
  77. <macrodef name="extend-manifest" uri="http://www.netbeans.org/ns/j2se-project/jnlp">
  78. <element name="customize"/>
  79. <sequential>
  80. <manifest file="${tmp.manifest.file}" mode="update">
  81. <customize/>
  82. </manifest>
  83. </sequential>
  84. </macrodef>
  85. </target>
  86. <target name="-test-jnlp-type" depends="-test-jnlp-enabled" if="is.jnlp.enabled">
  87. <condition property="is.applet">
  88. <equals arg1="${jnlp.descriptor}" arg2="applet" trim="true"/>
  89. </condition>
  90. <condition property="is.application">
  91. <equals arg1="${jnlp.descriptor}" arg2="application" trim="true"/>
  92. </condition>
  93. <condition property="is.component">
  94. <equals arg1="${jnlp.descriptor}" arg2="component" trim="true"/>
  95. </condition>
  96. <condition property="is.applet+mkdist.available">
  97. <and>
  98. <isset property="libs.CopyLibs.classpath"/>
  99. <istrue value="${is.applet}"/>
  100. </and>
  101. </condition>
  102. <condition property="is.application+mkdist.available">
  103. <and>
  104. <isset property="libs.CopyLibs.classpath"/>
  105. <istrue value="${is.application}"/>
  106. </and>
  107. </condition>
  108. <condition property="is.component+mkdist.available">
  109. <and>
  110. <isset property="libs.CopyLibs.classpath"/>
  111. <istrue value="${is.component}"/>
  112. </and>
  113. </condition>
  114. </target>
  115. <target name="-create-tmp-manifest" unless="manifest.file">
  116. <property name="tmp.manifest.file" value="${build.dir}/manifest.mf"/>
  117. <delete file="${tmp.manifest.file}" failonerror="false"/>
  118. <touch file="${tmp.manifest.file}"/>
  119. </target>
  120. <target name="-copy-tmp-manifest" if="manifest.file">
  121. <property name="tmp.manifest.file" value="${build.dir}/manifest.mf"/>
  122. <copy file="${manifest.file}" tofile="${build.dir}/manifest.mf"/>
  123. </target>
  124. <target name="-set-mixed-code-properties" depends="-check-signing-possible" if="jnlp.signed.true+signjars.task.available">
  125. <property name="jnlp.mixed.code" value=""/>
  126. <condition property="mixed.code.trusted.only">
  127. <equals arg1="trusted_only" arg2="${jnlp.mixed.code}"/>
  128. </condition>
  129. <condition property="mixed.code.trusted.library">
  130. <equals arg1="trusted_library" arg2="${jnlp.mixed.code}"/>
  131. </condition>
  132. </target>
  133. <target name="-add-trusted-only-attribute" depends="-set-mixed-code-properties,-init-macrodef-extend-manifest" if="mixed.code.trusted.only">
  134. <jnlp:extend-manifest>
  135. <customize>
  136. <attribute name="Trusted-Only" value="true"/>
  137. </customize>
  138. </jnlp:extend-manifest>
  139. </target>
  140. <target name="-add-trusted-library-attribute" depends="-set-mixed-code-properties,-init-macrodef-extend-manifest" if="mixed.code.trusted.library">
  141. <jnlp:extend-manifest>
  142. <customize>
  143. <attribute name="Trusted-Library" value="true"/>
  144. </customize>
  145. </jnlp:extend-manifest>
  146. </target>
  147. <target name="-do-jar-applet" depends="-test-jnlp-type,-init-macrodef-jnlp-copylibs" if="is.applet+mkdist.available">
  148. <jnlp:copylibs/>
  149. </target>
  150. <target name="-do-jar-jnlp-application" depends="-init-filename,-test-jnlp-type,-init-macrodef-jnlp-copylibs" if="is.application+mkdist.available">
  151. <jnlp:copylibs>
  152. <customize>
  153. <attribute name="Main-Class" value="${main.class}"/>
  154. </customize>
  155. </jnlp:copylibs>
  156. <echo>To run this application from the command line without Ant, try:</echo>
  157. <property location="${jnlp.dest.dir}/${jnlp.file}" name="jnlp.file.resolved"/>
  158. <echo>javaws "${jnlp.file.resolved}"</echo>
  159. </target>
  160. <target name="-do-jar-jnlp-component" depends="-test-jnlp-type,-init-macrodef-jnlp-copylibs" if="is.component+mkdist.available">
  161. <jnlp:copylibs/>
  162. </target>
  163. <target name="-do-jar-jnlp" depends="-create-tmp-manifest,-copy-tmp-manifest,-add-trusted-only-attribute,-add-trusted-library-attribute,-do-jar-applet,-do-jar-jnlp-application,-do-jar-jnlp-component"/>
  164. <!-- Init jnlp filename -->
  165. <target name="-init-filename" depends="-check-filename-prop,-set-jnlp-filename-custom,-set-jnlp-filename-default"/>
  166. <target name="-set-jnlp-filename-custom" if="jnlp.file.name.set">
  167. <property name="jnlp.file" value="${jnlp.file.name}"/>
  168. </target>
  169. <target name="-set-jnlp-filename-default" unless="jnlp.file.name.set">
  170. <property name="jnlp.file" value="${jnlp.file.name.default}"/>
  171. </target>
  172. <target name="-check-filename-prop">
  173. <condition property="jnlp.file.name.set">
  174. <and>
  175. <isset property="jnlp.file.name"/>
  176. <not>
  177. <equals arg1="jnlp.file.name" arg2="" trim="true"/>
  178. </not>
  179. </and>
  180. </condition>
  181. </target>
  182. <!-- Test JNLP enabled-->
  183. <target name="-test-jnlp-enabled">
  184. <condition property="is.jnlp.enabled">
  185. <istrue value="${jnlp.enabled}"/>
  186. </condition>
  187. </target>
  188. <!-- Generating JNLP file -->
  189. <target name="generate-jnlp" depends="sign-jars,-test-generate-task-available,-unavailable-generate-task" if="generate.task.available">
  190. <taskdef name="generate-jnlp" classname="org.netbeans.modules.javawebstart.anttasks.GenerateJnlpFileTask"
  191. classpath="${libs.JWSAntTasks.classpath}"/>
  192. <property name="jnlp.lazy.jars" value=""/>
  193. <generate-jnlp destfile="${jnlp.dest.dir}/${jnlp.file}_" template="master-${jnlp.descriptor}.jnlp" destdir="dist" lazyJars="${jnlp.lazy.jars}"/>
  194. <antcall target="-strip-empty-lines"/>
  195. </target>
  196. <target name="-strip-empty-lines">
  197. <copy file="${jnlp.dest.dir}/${jnlp.file}_" tofile="${jnlp.dest.dir}/${jnlp.file}" overwrite="true" encoding="UTF-8">
  198. <filterchain>
  199. <linecontainsregexp>
  200. <regexp pattern=".+"/>
  201. </linecontainsregexp>
  202. </filterchain>
  203. </copy>
  204. <delete file="${jnlp.dest.dir}/${jnlp.file}_" failonerror="false"/>
  205. </target>
  206. <target name="-test-generate-task-available">
  207. <available property="generate.task.available" classname="org.netbeans.modules.javawebstart.anttasks.GenerateJnlpFileTask"
  208. classpath="${libs.JWSAntTasks.classpath}"/>
  209. </target>
  210. <target name="-unavailable-generate-task" unless="generate.task.available">
  211. <echo message="Task required to generate JNLP file is missing, probably the library 'JWS Ant Tasks' is missing either from shared folder or from IDE installation."/>
  212. <fail/>
  213. </target>
  214. <!-- Codebase processing -->
  215. <target name="-codebase-props-check">
  216. <condition property="local.codebase">
  217. <or>
  218. <not>
  219. <isset property="jnlp.codebase.type"/>
  220. </not>
  221. <equals arg1="${jnlp.codebase.type}" arg2="local" trim="true"/>
  222. </or>
  223. </condition>
  224. <condition property="non.user.codebase">
  225. <or>
  226. <not>
  227. <isset property="jnlp.codebase.type"/>
  228. </not>
  229. <equals arg1="${jnlp.codebase.type}" arg2="local" trim="true"/>
  230. <equals arg1="${jnlp.codebase.type}" arg2="web" trim="true"/>
  231. </or>
  232. </condition>
  233. <condition property="user.codebase">
  234. <equals arg1="${jnlp.codebase.type}" arg2="user" trim="true"/>
  235. </condition>
  236. </target>
  237. <target name="-init-non-user-codebase" if="non.user.codebase">
  238. <property name="jnlp.codebase.value" value="${jnlp.codebase.url}"/>
  239. </target>
  240. <target name="-init-user-codebase" if="user.codebase">
  241. <property name="jnlp.codebase.value" value="${jnlp.codebase.user}"/>
  242. </target>
  243. <!-- Security -->
  244. <target name="-security-props-check">
  245. <condition property="jnlp.signed.true">
  246. <istrue value="${jnlp.signed}"/>
  247. </condition>
  248. </target>
  249. <target name="-jnlp-init-keystore" depends="-jnlp-init-keystore-props,-check-keystore-exists" unless="jnlp.signjar.keystore.exists">
  250. <echo message="${application.vendor}" file="${helper.file}"/>
  251. <loadfile property="application.vendor.filtered" srcfile="${helper.file}">
  252. <filterchain>
  253. <deletecharacters chars=","/>
  254. </filterchain>
  255. </loadfile>
  256. <delete file="${helper.file}"/>
  257. <property name="jnlp.signjar.vendor" value="CN=${application.vendor.filtered}"/>
  258. <echo message="Going to create default keystore in ${jnlp.signjar.keystore}"/>
  259. <genkey dname="${jnlp.signjar.vendor}" alias="${jnlp.signjar.alias}" keystore="${jnlp.signjar.keystore}"
  260. storepass="${jnlp.signjar.storepass}" keypass="${jnlp.signjar.keypass}"/>
  261. </target>
  262. <target name="-check-keystore-exists">
  263. <available property="jnlp.signjar.keystore.exists" file="${jnlp.signjar.keystore}"/>
  264. </target>
  265. <target name="-jnlp-init-keystore-props">
  266. <property name="jnlp.signjar.keystore" value="${basedir}/build/nb-jws.ks"/>
  267. <property name="jnlp.signjar.storepass" value="storepass"/>
  268. <property name="jnlp.signjar.keypass" value="keypass"/>
  269. <property name="jnlp.signjar.alias" value="nb-jws"/>
  270. </target>
  271. <!-- Signing -->
  272. <target name="-test-signjars-task-available">
  273. <available property="signjars.task.available"
  274. classname="org.netbeans.modules.javawebstart.anttasks.SignJarsTask"
  275. classpath="${libs.JWSAntTasks.classpath}"/>
  276. </target>
  277. <target name="-check-signing-possible" depends="-security-props-check,-test-signjars-task-available,-unavailable-signjars-task">
  278. <condition property="jnlp.signed.true+signjars.task.available">
  279. <and>
  280. <isset property="jnlp.signed.true"/>
  281. <isset property="signjars.task.available"/>
  282. </and>
  283. </condition>
  284. </target>
  285. <target name="-unavailable-signjars-task" depends="-test-signjars-task-available" unless="signjars.task.available">
  286. <echo message="Task required to sign JAR file is missing, probably the library 'JWS Ant Tasks' is missing either from shared folder or from IDE installation. JAR files will not be signed."/>
  287. </target>
  288. <target name="sign-jars" depends="-jnlp-init-keystore,-check-signing-possible" if="jnlp.signed.true+signjars.task.available">
  289. <taskdef name="sign-jars" classname="org.netbeans.modules.javawebstart.anttasks.SignJarsTask"
  290. classpath="${libs.JWSAntTasks.classpath}"/>
  291. <sign-jars keystore="${jnlp.signjar.keystore}" storepass="${jnlp.signjar.storepass}"
  292. keypass="${jnlp.signjar.keypass}" alias="${jnlp.signjar.alias}" mainjar="${dist.jar}" destdir="dist"
  293. codebase="${jnlp.codebase.value}" signedjarsprop="jnlp.signed.jars"
  294. componentsprop="jnlp.components">
  295. <fileset dir="dist/lib">
  296. <include name="*.jar"/>
  297. </fileset>
  298. </sign-jars>
  299. </target>
  300. <!-- Running/Debugging -->
  301. <target name="jws-run" depends="jar,-verify-jnlp-enabled,-verify-codebase,-init-platform" description="Start javaws execution">
  302. <exec executable="${platform.home}/bin/javaws">
  303. <arg file="${jnlp.dest.dir}/${jnlp.file}"/>
  304. </exec>
  305. </target>
  306. <target name="jws-debug" if="netbeans.home" depends="jar,-verify-jnlp-enabled,-verify-codebase,-debug-start-debugger,-debug-javaws-debuggee"
  307. description="Debug javaws project in IDE"/>
  308. <target name="-init-debug-args">
  309. <property name="version-output" value="java version &quot;${ant.java.version}"/>
  310. <condition property="have-jdk-older-than-1.4">
  311. <or>
  312. <contains string="${version-output}" substring="java version &quot;1.0"/>
  313. <contains string="${version-output}" substring="java version &quot;1.1"/>
  314. <contains string="${version-output}" substring="java version &quot;1.2"/>
  315. <contains string="${version-output}" substring="java version &quot;1.3"/>
  316. </or>
  317. </condition>
  318. <condition else="-Xdebug" property="debug-args-line" value="-Xdebug -Xnoagent -Djava.compiler=none">
  319. <istrue value="${have-jdk-older-than-1.4}"/>
  320. </condition>
  321. <condition else="dt_socket" property="debug-transport-by-os" value="dt_shmem">
  322. <os family="windows"/>
  323. </condition>
  324. <condition else="${debug-transport-by-os}" property="debug-transport" value="${debug.transport}">
  325. <isset property="debug.transport"/>
  326. </condition>
  327. </target>
  328. <target name="-debug-javaws-debuggee" depends="-init-debug-args">
  329. <exec executable="${java.home}/bin/javaws">
  330. <env key="JAVAWS_VM_ARGS" value="${debug-args-line} -Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/>
  331. <arg file="${jnlp.dest.dir}/${jnlp.file}"/>
  332. </exec>
  333. </target>
  334. <target name="-verify-codebase" depends="-codebase-props-check" unless="local.codebase">
  335. <fail message="Project cannot be run with non-local codebase. Open project properties dialog and set Web Start Codebase to Local Execution."/>
  336. </target>
  337. <target name="-verify-jnlp-enabled" depends="-test-jnlp-enabled" unless="is.jnlp.enabled">
  338. <fail message="Project cannot be run with selected Run Configuration when Java Web Start is disabled."/>
  339. </target>
  340. <!-- Generate simple HTML preview page -->
  341. <target name="-check-html-preview">
  342. <condition property="generate.html.preview">
  343. <or>
  344. <equals arg1="${jnlp.descriptor}" arg2="application"/>
  345. <equals arg1="${jnlp.descriptor}" arg2="applet"/>
  346. </or>
  347. </condition>
  348. </target>
  349. <target name="generate-html-preview" depends="-check-html-preview" if="generate.html.preview">
  350. <taskdef name="copy-template-page" classname="org.netbeans.modules.javawebstart.anttasks.CopyTemplatePageTask"
  351. classpath="${libs.JWSAntTasks.classpath}"/>
  352. <copy-template-page destfile="${jnlp.dest.dir}/launch.html" template="preview-${jnlp.descriptor}.html" destdir="${jnlp.dest.dir}"/>
  353. </target>
  354. </project>