nbexec 12 KB

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