Ticket #99: idea.sh

File idea.sh, 6.4 KB (added by Yuri Dario, 11 years ago)
Line 
1#!/bin/sh
2#
3# ---------------------------------------------------------------------
4# IntelliJ IDEA startup script.
5# ---------------------------------------------------------------------
6#
7
8message()
9{
10 TITLE="Cannot start IntelliJ IDEA"
11 if [ -t 1 ]; then
12 echo "ERROR: $TITLE\n$1"
13 elif [ -n `which zenity` ]; then
14 zenity --error --title="$TITLE" --text="$1"
15 elif [ -n `which kdialog` ]; then
16 kdialog --error --title "$TITLE" "$1"
17 elif [ -n `which xmessage` ]; then
18 xmessage -center "ERROR: $TITLE: $1"
19 elif [ -n `which notify-send` ]; then
20 notify-send "ERROR: $TITLE: $1"
21 else
22 echo "ERROR: $TITLE\n$1"
23 fi
24}
25
26UNAME=`which uname`
27GREP=`which egrep`
28GREP_OPTIONS=""
29CUT=`which cut`
30READLINK=`which readlink`
31MKTEMP=`which mktemp`
32RM=`which rm`
33CAT=`which cat`
34TR=`which tr`
35
36if [ -z "$UNAME" -o -z "$GREP" -o -z "$CUT" -o -z "$MKTEMP" -o -z "$RM" -o -z "$CAT" -o -z "$TR" ]; then
37 message "Required tools are missing - check beginning of \"$0\" file for details."
38 exit 1
39fi
40
41OS_TYPE=`"$UNAME" -s`
42
43# ---------------------------------------------------------------------
44# Locate a JDK installation directory which will be used to run the IDE.
45# Try (in order): IDEA_JDK, JDK_HOME, JAVA_HOME, "java" in PATH.
46# ---------------------------------------------------------------------
47if [ -n "$IDEA_JDK" -a -x "$IDEA_JDK/bin/java" ]; then
48 JDK="$IDEA_JDK"
49elif [ -n "$JDK_HOME" -a -x "$JDK_HOME/bin/java" ]; then
50 JDK="$JDK_HOME"
51elif [ -n "$JAVA_HOME" -a -x "$JAVA_HOME/bin/java" ]; then
52 JDK="$JAVA_HOME"
53else
54 JAVA_BIN_PATH=`which java`
55 if [ -n "$JAVA_BIN_PATH" ]; then
56 if [ "$OS_TYPE" = "FreeBSD" ]; then
57 JAVA_LOCATION=`JAVAVM_DRYRUN=yes java | "$GREP" '^JAVA_HOME' | "$CUT" -c11-`
58 if [ -x "$JAVA_LOCATION/bin/java" ]; then
59 JDK="$JAVA_LOCATION"
60 fi
61 elif [ "$OS_TYPE" = "SunOS" ]; then
62 JAVA_LOCATION="/usr/jdk/latest"
63 if [ -x "$JAVA_LOCATION/bin/java" ]; then
64 JDK="$JAVA_LOCATION"
65 fi
66 elif [ "$OS_TYPE" = "Darwin" ]; then
67 JAVA_LOCATION=`/usr/libexec/java_home`
68 if [ -x "$JAVA_LOCATION/bin/java" ]; then
69 JDK="$JAVA_LOCATION"
70 fi
71 fi
72
73 if [ -z "$JDK" -a -x "$READLINK" ]; then
74 JAVA_LOCATION=`"$READLINK" -f "$JAVA_BIN_PATH"`
75 JAVA_LOCATION="$JAVA_BIN_PATH"
76 echo $JAVA_BIN_PATH
77 echo $JAVA_LOCATION
78 case "$JAVA_LOCATION" in
79 */jre/bin/java)
80 JAVA_LOCATION=`echo "$JAVA_LOCATION" | xargs dirname | xargs dirname | xargs dirname` ;;
81 *)
82 JAVA_LOCATION=`echo "$JAVA_LOCATION" | xargs dirname | xargs dirname` ;;
83 esac
84 echo $JAVA_LOCATION
85 if [ -x "$JAVA_LOCATION/bin/java.exe" ]; then
86 JDK="$JAVA_LOCATION"
87 fi
88 fi
89 fi
90fi
91
92if [ -z "$JDK" ]; then
93 message "No JDK found. Please validate either IDEA_JDK, JDK_HOME or JAVA_HOME environment variable points to valid JDK installation."
94 exit 1
95fi
96
97VERSION_LOG=`"$MKTEMP" -t java.version.log.XXXXXX`
98"$JDK/bin/java" -version 2> "$VERSION_LOG"
99"$GREP" 'OpenJDK' "$VERSION_LOG"
100OPEN_JDK=$?
101"$GREP" "64-Bit|x86_64" "$VERSION_LOG"
102BITS=$?
103"$RM" -f "$VERSION_LOG"
104if [ $OPEN_JDK -eq 0 ]; then
105 echo "WARNING: You are launching the IDE using OpenJDK Java runtime."
106 echo
107 echo " ITS KNOWN TO HAVE PERFORMANCE AND GRAPHICS ISSUES!"
108 echo " SWITCH TO THE ORACLE(SUN) JDK BEFORE REPORTING PROBLEMS!"
109 echo
110 echo "NOTE: If you have both Oracle (Sun) JDK and OpenJDK installed"
111 echo " please validate either IDEA_JDK, JDK_HOME, or JAVA_HOME environment variable points to valid Oracle (Sun) JDK installation."
112 echo " See http://ow.ly/6TuKQ for more info on switching default JDK."
113 echo
114 echo "Press Enter to continue."
115# ---------------------------------------------------------------------
116# COMMENT LINE BELOW TO REMOVE PAUSE AFTER OPEN JDK WARNING
117# ---------------------------------------------------------------------
118 read IGNORE
119fi
120if [ $BITS -eq 0 ]; then
121 BITS="64"
122else
123 BITS=""
124fi
125
126# ---------------------------------------------------------------------
127# Ensure IDE_HOME points to the directory where the IDE is installed.
128# ---------------------------------------------------------------------
129SCRIPT_LOCATION=$0
130if [ -x "$READLINK" ]; then
131 while [ -L "$SCRIPT_LOCATION" ]; do
132 SCRIPT_LOCATION=`"$READLINK" -e "$SCRIPT_LOCATION"`
133 done
134fi
135
136IDE_HOME=`dirname "$SCRIPT_LOCATION"`/..
137IDE_BIN_HOME=`dirname "$SCRIPT_LOCATION"`
138
139# ---------------------------------------------------------------------
140# Collect JVM options and properties.
141# ---------------------------------------------------------------------
142if [ -n "$IDEA_PROPERTIES" ]; then
143 IDE_PROPERTIES_PROPERTY="-Didea.properties.file=\"$IDEA_PROPERTIES\""
144fi
145
146MAIN_CLASS_NAME="$IDEA_MAIN_CLASS_NAME"
147if [ -z "$MAIN_CLASS_NAME" ]; then
148 MAIN_CLASS_NAME="com.intellij.idea.Main"
149fi
150
151VM_OPTIONS_FILE="$IDEA_VM_OPTIONS"
152if [ -z "$VM_OPTIONS_FILE" ]; then
153 VM_OPTIONS_FILE="$IDE_BIN_HOME/idea$BITS.vmoptions"
154fi
155
156if [ -r "$VM_OPTIONS_FILE" ]; then
157 VM_OPTIONS=`"$CAT" "$VM_OPTIONS_FILE" | "$GREP" -v "^#.*" | "$TR" '\n' ' '`
158 VM_OPTIONS="$VM_OPTIONS -Djb.vmOptionsFile=\"$VM_OPTIONS_FILE\""
159fi
160
161IS_EAP="false"
162if [ "$IS_EAP" = "true" ]; then
163 OS_NAME=`echo $OS_TYPE | "$TR" '[:upper:]' '[:lower:]'`
164 AGENT_LIB="yjpagent-$OS_NAME$BITS"
165 if [ -r "$IDE_BIN_HOME/lib$AGENT_LIB.so" ]; then
166 AGENT="-agentlib:$AGENT_LIB=disablej2ee,disablealloc,sessionname=IdeaIC12"
167 fi
168fi
169
170COMMON_JVM_ARGS="\"-Xbootclasspath/a:$IDE_HOME/lib/boot.jar\" -Didea.paths.selector=IdeaIC12 $IDE_PROPERTIES_PROPERTY"
171IDE_JVM_ARGS=""
172ALL_JVM_ARGS="$VM_OPTIONS $COMMON_JVM_ARGS $IDE_JVM_ARGS $AGENT $REQUIRED_JVM_ARGS"
173
174CLASSPATH="$IDE_HOME/lib/bootstrap.jar"
175CLASSPATH="$CLASSPATH;$IDE_HOME/lib/extensions.jar"
176CLASSPATH="$CLASSPATH;$IDE_HOME/lib/util.jar"
177CLASSPATH="$CLASSPATH;$IDE_HOME/lib/jdom.jar"
178CLASSPATH="$CLASSPATH;$IDE_HOME/lib/log4j.jar"
179CLASSPATH="$CLASSPATH;$IDE_HOME/lib/trove4j.jar"
180CLASSPATH="$CLASSPATH;$IDE_HOME/lib/jna.jar"
181CLASSPATH="$CLASSPATH;$JDK/lib/tools.jar"
182if [ -n "$IDEA_CLASSPATH" ]; then
183 CLASSPATH="$CLASSPATH;$IDEA_CLASSPATH"
184fi
185export CLASSPATH
186echo $CLASSPATH
187
188LD_LIBRARY_PATH="$IDE_BIN_HOME;$LD_LIBRARY_PATH"
189export LD_LIBRARY_PATH
190
191# ---------------------------------------------------------------------
192# Run the IDE.
193# ---------------------------------------------------------------------
194while true ; do
195 eval "$JDK/bin/java" $ALL_JVM_ARGS -Djb.restart.code=88 $MAIN_CLASS_NAME $*
196 test $? -ne 88 && break
197done