nbexec 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. #!/bin/sh
  2. # Copyright (c) 1992, 2014, Oracle and/or its affiliates. All rights reserved.
  3. # ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  4. PRG=$0
  5. resolve_symlink () {
  6. file="$1"
  7. while [ -h "$file" ]; do
  8. ls=`ls -ld "$file"`
  9. link=`expr "$ls" : '^.*-> \(.*\)$' 2>/dev/null`
  10. if expr "$link" : '^/' 2> /dev/null >/dev/null; then
  11. file="$link"
  12. else
  13. file=`dirname "$1"`"/$link"
  14. fi
  15. done
  16. echo "$file"
  17. }
  18. absolutize_path () {
  19. oldpwd=`pwd`
  20. cd "$1"
  21. abspath=`pwd`
  22. cd "${oldpwd}"
  23. echo "$abspath"
  24. }
  25. PRG=`resolve_symlink "$PRG"`
  26. progdir=`dirname "$PRG"`
  27. plathome=`absolutize_path "$progdir/.."`
  28. jargs=${jreflags}
  29. jargs="$jargs -Dnetbeans.home=\"$plathome\""
  30. args=""
  31. prefixcp=""
  32. postfixcp=""
  33. updater_class=org.netbeans.updater.UpdaterFrame
  34. #
  35. # parse arguments
  36. #
  37. parse_args() {
  38. while [ $# -gt 0 ] ; do
  39. case "$1" in
  40. -h|-\?|-help|--help) cat >&2 <<EOF
  41. Usage: $0 {options} arguments
  42. General options:
  43. --help show this help
  44. --jdkhome <path> path to Java(TM) 2 SDK, Standard Edition
  45. -J<jvm_option> pass <jvm_option> to JVM
  46. --cp:p <classpath> prepend <classpath> to classpath
  47. --cp:a <classpath> append <classpath> to classpath
  48. EOF
  49. # go on and print IDE options as well
  50. args="$args --help"
  51. ;;
  52. --nosplash)
  53. nosplash="nosplash";
  54. args="$args --nosplash"
  55. ;;
  56. --jdkhome) shift; if [ $# -gt 0 ] ; then jdkhome=$1; fi
  57. ;;
  58. # this has to be here for purposes of updater.jar, but it should be
  59. # better to handle this argument inside the java launcher part
  60. --userdir) shift; if [ $# -gt 0 ] ; then userdir="$1"; fi
  61. ;;
  62. --cachedir) shift; if [ $# -gt 0 ] ; then cachedir="$1"; cachedirspecified="specified" ; fi
  63. ;;
  64. -cp|-cp:a|--cp|--cp:a)
  65. shift;
  66. if [ $# -gt 0 ] ; then
  67. if [ ! -z "$postfixcp" ] ; then postfixcp="$postfixcp:" ; fi
  68. postfixcp=$postfixcp$1;
  69. fi
  70. ;;
  71. -cp:p|--cp:p)
  72. shift;
  73. if [ $# -gt 0 ] ; then
  74. if [ ! -z "$prefixcp" ] ; then prefixcp="$prefixcp:" ; fi
  75. prefixcp=$prefixcp$1;
  76. fi
  77. ;;
  78. --clusters)
  79. shift;
  80. if [ $# -gt 0 ] ; then
  81. clusters="$1"
  82. fi
  83. ;;
  84. -psn*)
  85. shift;
  86. ;;
  87. -J*) jopt=`expr "X-$1" : 'X--J\(.*\)'`; jargs="$jargs '$jopt'";;
  88. *) args="$args \"$1\"" ;;
  89. esac
  90. shift
  91. done
  92. } # parse_args()
  93. # Process arguments given on the command line.
  94. parse_args "$@"
  95. #
  96. # check JDK
  97. #
  98. if [ -z "$jdkhome" ] ; then
  99. # try to find JDK
  100. case "`uname`" in
  101. Darwin*)
  102. # read Java Preferences
  103. if [ -x "/usr/libexec/java_home" ]; then
  104. jdkhome=`/usr/libexec/java_home --version 1.7.0_10+ --failfast`
  105. # JDK1.7 Update 10 as a fallback
  106. elif [ -f "/Library/Java/JavaVirtualMachines/jdk1.7.0_10.jdk/Contents/Home/bin/java" ] ; then
  107. jdkhome="/Library/Java/JavaVirtualMachines/jdk1.7.0_10.jdk/Contents/Home"
  108. fi
  109. # JRE fallback
  110. if [ ! -x "${jdkhome}/bin/java" -a -f "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java" ] ; then
  111. jdkhome="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home"
  112. fi
  113. ;;
  114. *) javac=`which javac`
  115. if [ -z "$javac" ] ; then
  116. java=`which java`
  117. if [ ! -z "$java" ] ; then
  118. java=`resolve_symlink "$java"`
  119. jdkhome=`dirname $java`"/.."
  120. fi
  121. else
  122. javac=`resolve_symlink "$javac"`
  123. jdkhome=`dirname $javac`"/.."
  124. fi
  125. ;;
  126. esac
  127. fi
  128. if [ ! -x "${jdkhome}/bin/java" ] ; then
  129. echo "Cannot find java. Please use the --jdkhome switch." >&2
  130. exit 2
  131. fi
  132. # Make sure native code libraries of jdk7 are found
  133. # setting of the LD_LIBRARY_PATH is unnecessary on JDK8, and should be removed when only JDK8 is supported:
  134. case "`uname`" in
  135. SunOS*)
  136. LD_LIBRARY_PATH=${jdkhome}/jre/lib/amd64/client:${jdkhome}/jre/lib/amd64/server:${jdkhome}/jre/lib/i386/client:${jdkhome}/jre/lib/i386/server:${LD_LIBRARY_PATH}
  137. export LD_LIBRARY_PATH
  138. ;;
  139. *)
  140. LD_LIBRARY_PATH=${jdkhome}/jre/lib/amd64:${jdkhome}/jre/lib/i386:${LD_LIBRARY_PATH}
  141. export LD_LIBRARY_PATH
  142. ;;
  143. esac
  144. # fixes 225762: Can't open project from a folder with UTF-8 letters on Mac OS X
  145. if [ `uname` = "Darwin" ] ; then
  146. if [ x${LC_CTYPE} = x ] ; then
  147. export LC_CTYPE=UTF-8;
  148. fi
  149. fi
  150. # if the Java option for heap dump on OOME is supported enable it
  151. if "${jdkhome}/bin/java" -XX:+HeapDumpOnOutOfMemoryError -cp "${progdir}/boot.jar" org.netbeans.NbExecJavaStartTry > /dev/null 2>&1 ; then
  152. jargs="$jargs -XX:+HeapDumpOnOutOfMemoryError"
  153. if [ -z "`echo $jargs | grep -- "-XX:HeapDumpPath="`" ] ; then
  154. jargs="$jargs -XX:HeapDumpPath=\"${userdir}/var/log/heapdump.hprof\""
  155. fi
  156. # rename old heap dump to .old
  157. mv "${userdir}/var/log/heapdump.hprof" "${userdir}/var/log/heapdump.hprof.old" > /dev/null 2>&1
  158. fi
  159. jargs_without_clusters="$jargs"
  160. jargs="-Dnetbeans.dirs=\"${clusters}\" $jargs_without_clusters"
  161. if [ -z "$cachedirspecified" ]; then
  162. cachedir="${userdir}/var/cache"
  163. fi
  164. if [ `uname` != Darwin -a -z "$nosplash" -a -f "${cachedir}/splash.png" -a ! -f "${userdir}/lock" ]; then
  165. jargs="$jargs -splash:\"${cachedir}/splash.png\""
  166. fi
  167. jdkhome=`absolutize_path "$jdkhome"`
  168. args="--userdir \"${userdir}\" $args"
  169. args="--cachedir \"${cachedir}\" $args"
  170. append_jars_to_cp() {
  171. dir="$1"
  172. subpath="$2"
  173. for ex in jar zip ; do
  174. if [ "`echo "${dir}"/*.$ex`" != "${dir}/*.$ex" ] ; then
  175. for x in "${dir}"/*.$ex ; do
  176. subx=`basename "$x"`
  177. if [ -z "`echo "$paths" | egrep "$subpath$subx"`" ] ; then
  178. if [ ! -z "$cp" ] ; then cp="$cp:" ; fi
  179. cp="$cp$x"
  180. if [ ! -z "$paths" ] ; then paths="$paths:" ; fi
  181. paths="$paths$subpath$subx"
  182. fi
  183. done
  184. fi
  185. done
  186. }
  187. construct_cp() {
  188. cp=""
  189. updatercp=""
  190. paths=""
  191. build_cp "${userdir}"
  192. build_cp "${plathome}"
  193. if [ -f "${userdir}/modules/ext/updater.jar" ] ; then
  194. updatercp="${userdir}/modules/ext/updater.jar"
  195. else
  196. if [ -f "${plathome}/modules/ext/updater.jar" ] ; then
  197. updatercp="${plathome}/modules/ext/updater.jar"
  198. fi
  199. fi
  200. # JDK tools
  201. for x in "${jdkhome}/lib/dt.jar" "${jdkhome}/lib/tools.jar"; do
  202. if [ -f "$x" ]; then
  203. if [ ! -z "$cp" ] ; then cp="$cp:" ; fi
  204. cp="${cp}$x"
  205. fi
  206. done
  207. # user-specified prefix and postfix CLASSPATH
  208. if [ ! -z "${prefixcp}" ] ; then
  209. cp="${prefixcp}:$cp"
  210. fi
  211. if [ ! -z "${postfixcp}" ] ; then
  212. cp="$cp:${postfixcp}"
  213. fi
  214. # prepend IDE's classpath to updater's classpath
  215. # (just xml-apis.jar and one XML parser would suffice)
  216. if [ ! -z "$updatercp" ] ; then
  217. updatercp=${cp}:${updatercp}
  218. else
  219. updatercp=${cp}
  220. fi
  221. }
  222. build_cp() {
  223. base="$1"
  224. append_jars_to_cp "${base}/lib/patches" "patches"
  225. append_jars_to_cp "${base}/lib" "lib"
  226. append_jars_to_cp "${base}/lib/locale" "locale"
  227. }
  228. do_run_updater() {
  229. eval "\"$jdkhome/bin/java\"" -classpath "\"${updatercp}\"" "$jargs" "-Dnetbeans.user=\"$userdir\"" $updater_class "$args"
  230. construct_cp
  231. }
  232. look_for_pre_runs() {
  233. base="$1"
  234. install_new_updater "$1"
  235. dir="${base}/update/download"
  236. if [ "`echo "${dir}"/*.nbm`" != "${dir}/*.nbm" -o "`echo "${dir}"/*.jar`" != "${dir}/*.jar" ] ; then
  237. run_updater=yes
  238. else
  239. dir="${base}/update/deactivate"
  240. if [ -f "${dir}/to_disable.txt" -o -f "${dir}/to_uninstall.txt" ] ; then
  241. run_updater=yes
  242. fi
  243. fi
  244. }
  245. look_for_post_runs() {
  246. base="$1"
  247. install_new_updater "$1"
  248. dir="${base}/update/download"
  249. if [ \! -f "${dir}/install_later.xml" ] && [ "`echo "${dir}"/*.nbm`" != "${dir}/*.nbm" -o "`echo "${dir}"/*.jar`" != "${dir}/*.jar" ] ; then
  250. run_updater=yes
  251. else
  252. dir="${base}/update/deactivate"
  253. if [ \! -f "${dir}/deactivate_later.txt" ] ; then
  254. if [ -f "${dir}/to_disable.txt" -o -f "${dir}/to_uninstall.txt" ] ; then
  255. run_updater=yes
  256. fi
  257. fi
  258. fi
  259. }
  260. look_for_new_clusters() {
  261. base="$userdir"
  262. dir="${base}/update/download"
  263. newclusters="${dir}/netbeans.dirs"
  264. if [ -f "${newclusters}" ] ; then
  265. clusters=`cat "${newclusters}"`
  266. jargs="-Dnetbeans.dirs=\"${clusters}\" $jargs_without_clusters"
  267. rm -f "${newclusters}"
  268. fi
  269. }
  270. delete_new_clusters_file() {
  271. base="$userdir"
  272. dir="${base}/update/download"
  273. newclusters="${dir}/netbeans.dirs"
  274. if [ \! -f "${newclusters}" ] ; then
  275. rm -f "${newclusters}"
  276. fi
  277. }
  278. install_new_updater() {
  279. base="$1"
  280. newUpdaterDir="${base}/update/new_updater"
  281. if [ -d "${newUpdaterDir}" ]; then
  282. mkdir -p "${base}/modules/ext/"
  283. if [ -f "${newUpdaterDir}/updater.jar" ]; then
  284. mv -f "${newUpdaterDir}/updater.jar" "${base}/modules/ext/"
  285. fi
  286. for i in "${newUpdaterDir}/locale/"updater_*.jar; do
  287. if [ -f "$i" ]; then
  288. mkdir -p "${base}/modules/ext/locale/"
  289. mv -f "$i" "${base}/modules/ext/locale/"
  290. fi
  291. done
  292. rmdir "${newUpdaterDir}"
  293. fi
  294. }
  295. if [ "$KDE_FULL_SESSION" = "true" ] ; then
  296. jargs="-Dnetbeans.running.environment=kde $jargs"
  297. else
  298. if [ ! -z "$GNOME_DESKTOP_SESSION_ID" ] ; then
  299. jargs="-Dnetbeans.running.environment=gnome $jargs"
  300. fi
  301. fi
  302. if [ ! -z "${DEFAULT_USERDIR_ROOT}" ] ; then
  303. jargs="-Dnetbeans.default_userdir_root=\"${DEFAULT_USERDIR_ROOT}\" $jargs"
  304. unset DEFAULT_USERDIR_ROOT
  305. fi
  306. # http://java.sun.com/j2se/1.5.0/docs/guide/2d/flags.html#pixmaps
  307. J2D_PIXMAPS=shared
  308. export J2D_PIXMAPS
  309. # Check DISPLAY variable on non-Mac
  310. if [ "no$DISPLAY" = "no" -a `uname` != Darwin ]; then
  311. echo "$0: WARNING: environment variable DISPLAY is not set"
  312. fi
  313. # The Startup Notification Protocol Specification [1]
  314. # recommends to unset the DESKTOP_STARTUP_ID environment variable
  315. # to avoid possible reuse by some process started later by this
  316. # process, e.g. when a browser will be launched by the NetBeans [2].
  317. #
  318. # See:
  319. # [1] http://standards.freedesktop.org/startup-notification-spec
  320. # [2] http://netbeans.org/bugzilla/show_bug.cgi?id=76970
  321. if [ ! -z "$DESKTOP_STARTUP_ID" ] ; then
  322. # Save a value for later using
  323. NB_DESKTOP_STARTUP_ID="$DESKTOP_STARTUP_ID"; export NB_DESKTOP_STARTUP_ID
  324. unset DESKTOP_STARTUP_ID
  325. fi
  326. #
  327. # main loop
  328. #
  329. # clear to prevent loop from ending
  330. restart="yes"
  331. first_time_starting="yes"
  332. restart_file="${userdir}/var/restart"
  333. while [ "$restart" ] ; do
  334. #
  335. # build CLASSPATH
  336. #
  337. construct_cp
  338. # First check for pre-run updates.
  339. if [ "$first_time_starting" ] ; then
  340. run_updater=""
  341. look_for_pre_runs "$plathome"
  342. save="$IFS"
  343. IFS=':' ; for oneCls in $clusters ; do
  344. IFS="$save"
  345. look_for_pre_runs "$oneCls"
  346. done
  347. IFS="$save"
  348. look_for_pre_runs "$userdir"
  349. if [ "$run_updater" ] ; then do_run_updater ; fi
  350. # Do not check this after a restart, it makes no sense.
  351. first_time_starting=""
  352. fi
  353. #
  354. # let's go
  355. #
  356. delete_new_clusters_file
  357. rm -f "${restart_file}"
  358. eval ${_NB_PROFILE_CMD} "\"${jdkhome}/bin/java\"" -Djdk.home="\"${jdkhome}\"" -classpath "\"$cp\"" \
  359. "$jargs" org.netbeans.Main "$args" '<&0' '&'
  360. PID=$!
  361. trap "kill $PID" EXIT
  362. wait $PID
  363. exitcode=$?
  364. trap '' EXIT
  365. look_for_new_clusters
  366. # If we should update anything, do it and restart IDE.
  367. run_updater=""
  368. look_for_post_runs "$plathome"
  369. save="$IFS"
  370. IFS=':' ; for oneCls in $clusters ; do
  371. IFS="$save"
  372. look_for_post_runs "$oneCls"
  373. done
  374. IFS="$save"
  375. look_for_post_runs "$userdir"
  376. if [ "$run_updater" ] ; then
  377. do_run_updater
  378. restart="yes"
  379. else
  380. if [ ! -f "${restart_file}" ] ; then
  381. # will fall thru loop and exit
  382. restart=""
  383. fi
  384. fi
  385. done
  386. # and we exit.
  387. exit $exitcode