netbeans.sh 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. #!/bin/sh
  2. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  3. #
  4. # Copyright 1997-2016 Oracle and/or its affiliates. All rights reserved.
  5. #
  6. # Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  7. # Other names may be trademarks of their respective owners.
  8. #
  9. # The contents of this file are subject to the terms of either the GNU
  10. # General Public License Version 2 only ("GPL") or the Common
  11. # Development and Distribution License("CDDL") (collectively, the
  12. # "License"). You may not use this file except in compliance with the
  13. # License. You can obtain a copy of the License at
  14. # http://www.netbeans.org/cddl-gplv2.html
  15. # or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  16. # specific language governing permissions and limitations under the
  17. # License. When distributing the software, include this License Header
  18. # Notice in each file and include the License file at
  19. # nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
  20. # particular file as subject to the "Classpath" exception as provided
  21. # by Oracle in the GPL Version 2 section of the License file that
  22. # accompanied this code. If applicable, add the following below the
  23. # License Header, with the fields enclosed by brackets [] replaced by
  24. # your own identifying information:
  25. # "Portions Copyrighted [year] [name of copyright owner]"
  26. #
  27. # Contributor(s):
  28. #
  29. # The Original Software is NetBeans. The Initial Developer of the Original
  30. # Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
  31. # Microsystems, Inc. All Rights Reserved.
  32. #
  33. # If you wish your version of this file to be governed by only the CDDL
  34. # or only the GPL Version 2, indicate your decision by adding
  35. # "[Contributor] elects to include this software in this distribution
  36. # under the [CDDL or GPL Version 2] license." If you do not indicate a
  37. # single choice of license, a recipient has the option to distribute
  38. # your version of this file under either the CDDL, the GPL Version 2 or
  39. # to extend the choice of license to its licensees as provided above.
  40. # However, if you add GPL Version 2 code and therefore, elected the GPL
  41. # Version 2 license, then the option applies only if the new code is
  42. # made subject to such option by the copyright holder.
  43. #
  44. # resolve symlinks
  45. #
  46. PRG=$0
  47. while [ -h "$PRG" ]; do
  48. ls=`ls -ld "$PRG"`
  49. link=`expr "$ls" : '^.*-> \(.*\)$' 2>/dev/null`
  50. if expr "$link" : '^/' 2> /dev/null >/dev/null; then
  51. PRG="$link"
  52. else
  53. PRG="`dirname "$PRG"`/$link"
  54. fi
  55. done
  56. progdir=`dirname "$PRG"`
  57. old=`pwd`
  58. cd "$progdir"/..
  59. basedir=`pwd`
  60. cd "$old"
  61. case "`uname`" in
  62. Darwin*)
  63. # set default userdir and cachedir on Mac OS X
  64. DEFAULT_USERDIR_ROOT="${HOME}/Library/Application Support/NetBeans"
  65. DEFAULT_CACHEDIR_ROOT=${HOME}/Library/Caches/NetBeans
  66. ;;
  67. *)
  68. # set default userdir and cachedir on unix systems
  69. DEFAULT_USERDIR_ROOT=${HOME}/.netbeans
  70. DEFAULT_CACHEDIR_ROOT=${HOME}/.cache/netbeans
  71. ;;
  72. esac
  73. if [ -f "$basedir"/etc/netbeans.conf ] ; then
  74. . "$basedir"/etc/netbeans.conf
  75. fi
  76. # following should be done just in RPM or Solaris Launcher
  77. # if [ -f /etc/netbeans.conf ] ; then
  78. # . /etc/netbeans.conf
  79. # fi
  80. export DEFAULT_USERDIR_ROOT
  81. # #68373: look for userdir, but do not modify "$@"
  82. userdir="${netbeans_default_userdir}"
  83. cachedir="${netbeans_default_cachedir}"
  84. founduserdir=""
  85. for opt in "$@"; do
  86. if [ "${founduserdir}" = "yes" ]; then
  87. userdir="$opt"
  88. break
  89. elif [ "$opt" = "--userdir" ]; then
  90. founduserdir="yes"
  91. fi
  92. done
  93. foundcachedir=""
  94. for opt in "$@"; do
  95. if [ "${foundcachedir}" = "yes" ]; then
  96. cachedir="$opt"
  97. break
  98. elif [ "$opt" = "--cachedir" ]; then
  99. foundcachedir="yes"
  100. fi
  101. done
  102. if [ -f "${userdir}"/etc/netbeans.conf ] ; then
  103. . "${userdir}"/etc/netbeans.conf
  104. fi
  105. if [ ! -f "$basedir"/etc/netbeans.clusters ]; then
  106. echo Cannot read cluster file: "$basedir"/etc/netbeans.clusters 1>&2
  107. exit 1
  108. fi
  109. readClusters() {
  110. grep -v "^#" "$basedir"/etc/netbeans.clusters | grep -v "^$" | grep -v platform | while read X; do
  111. if expr "$X" : "/.*" >/dev/null; then
  112. echo "$X"
  113. else
  114. echo "$basedir/$X"
  115. fi
  116. done
  117. }
  118. absolutize_paths() {
  119. while read path; do
  120. if [ -d "$path" ]; then
  121. (cd "$path" 2>/dev/null && pwd)
  122. else
  123. echo "$path"
  124. fi
  125. done
  126. }
  127. netbeans_clusters=`readClusters | absolutize_paths | tr '\012' ':'`
  128. if [ ! -z "$netbeans_extraclusters" ] ; then
  129. netbeans_clusters="$netbeans_clusters:$netbeans_extraclusters"
  130. fi
  131. heap_size () {
  132. mem=640
  133. case "`uname`" in
  134. Linux*)
  135. mem=`cat /proc/meminfo | grep MemTotal | tr -d [:space:][:alpha:]:`
  136. mem=`expr $mem / 1024`
  137. ;;
  138. SunOS*)
  139. mem=`/usr/sbin/prtconf | grep Memory | /usr/bin/tr -dc '[0-9]'`
  140. ;;
  141. Darwin*)
  142. mem=`/usr/sbin/sysctl hw.memsize | tr -d [:alpha:][:space:].:`
  143. mem=`expr $mem / 1048576`
  144. ;;
  145. *)
  146. ;;
  147. esac
  148. if [ -z "$mem" ] ; then
  149. mem=640
  150. fi
  151. mem=`expr $mem / 5`
  152. if [ $mem -gt 1024 ] ; then
  153. mem=1024
  154. elif [ $mem -lt 96 ] ; then
  155. mem=96
  156. fi
  157. max_heap_size=$mem
  158. return 0
  159. }
  160. if grep -v -- "-J-Xmx" >/dev/null <<EOF ; then
  161. ${netbeans_default_options}
  162. EOF
  163. heap_size
  164. netbeans_default_options="-J-Xmx${max_heap_size}m ${netbeans_default_options}"
  165. fi
  166. launchNbexec() {
  167. nbexec="/usr/share/netbeans/platform/lib/nbexec"
  168. sh="/bin/bash"
  169. #exec $sh "$nbexec"
  170. source /etc/netbeans.conf
  171. exec $sh "$nbexec" $netbeans_default_options --userdir "${userdir}" --cachedir "${cachedir}"
  172. #"$@"
  173. }
  174. # in case of macosx, the apple.laf.useScreenMenuBar property should be ideally in the Info.plist file
  175. # but it doesn't get propagated into the executed java VM.
  176. case "`uname`" in
  177. Darwin*)
  178. eval launchNbexec \
  179. --jdkhome '"$netbeans_jdkhome"' \
  180. -J-Xdock:name=NetBeans \
  181. '"-J-Xdock:icon=$basedir/nb/netbeans.icns"' \
  182. --branding nb \
  183. --clusters '"$netbeans_clusters"' \
  184. -J-Dnetbeans.importclass=org.netbeans.upgrade.AutoUpgrade \
  185. -J-Dnetbeans.accept_license_class=org.netbeans.license.AcceptLicense \
  186. ${netbeans_default_options} \
  187. '"$@"'
  188. ;;
  189. *)
  190. eval launchNbexec \
  191. --jdkhome '"$netbeans_jdkhome"' \
  192. --branding nb \
  193. --clusters '"$netbeans_clusters"' \
  194. -J-Dnetbeans.importclass=org.netbeans.upgrade.AutoUpgrade \
  195. -J-Dnetbeans.accept_license_class=org.netbeans.license.AcceptLicense \
  196. ${netbeans_default_options} \
  197. '"$@"'
  198. ;;
  199. esac