-
Notifications
You must be signed in to change notification settings - Fork 102
/
intellij
executable file
·213 lines (203 loc) · 5.9 KB
/
intellij
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/usr/bin/env bash
# autocompletion list
if [ "${1}" = "shortlist" ]
then
if [ -z "${2}" ]
then
echo "--all setup add-plugin run start ws-update ws-reverse ws-reverse-add create-script help"
fi
exit
fi
if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi
# shellcheck source=scripts/functions
source "$(dirname "${0}")"/../functions
cd "${DEVON_IDE_HOME}" || exit 255
function doSetup() {
doDevonCommand java setup silent
if [ "${1}" != "silent" ] || [ ! -d "${IDEA_HOME}" ]
then
local version="${INTELLIJ_VERSION:-2021.3}"
local edition="${INTELLIJ_EDITION_TYPE:-C}"
doInstall "-" "${IDEA_HOME}" "intellij" "${version}" "${edition}"
if [ "${?}" = 0 ] && doIsMacOs
then
echo "Doing workarounds for MacOS quirks..."
if [ "${edition}" = "U" ]
then
mv "${DEVON_IDE_HOME}/software/intellij/IntelliJ IDEA.app" "${DEVON_IDE_HOME}/software/intellij/IntelliJ.app"
else
mv "${DEVON_IDE_HOME}/software/intellij/IntelliJ IDEA CE.app" "${DEVON_IDE_HOME}/software/intellij/IntelliJ.app"
fi
mkdir -p "${IDEA_HOME}/bin"
echo -e "#!/usr/bin/env bash\n'${DEVON_IDE_HOME}/software/intellij/IntelliJ.app/Contents/MacOS/idea' \$@" > "${IDEA_HOME}/bin/idea"
chmod a+x "${IDEA_HOME}/bin/idea"
fi
if [ -f "${IDEA_HOME}/bin/idea.sh" ]
then
ln -s "${IDEA_HOME}/bin/idea.sh" "${IDEA_HOME}/bin/idea"
fi
export PATH="${IDEA_HOME}/bin:${PATH}"
doAddPlugins
fi
if [ "${1}" != "silent" ] && ! doIsQuiet
then
doRunCommand "command -v idea" "verify installation of IntelliJ"
if [ -e "${IDEA_HOME}/product-info.json" ]
then
doRunCommand "cat '${IDEA_HOME}/product-info.json'"
else
doRunCommand "cat '${IDEA_HOME}/IntelliJ.app/Contents/Resources/product-info.json'"
fi
fi
}
function doAddPlugins() {
local file
for file in "${SETTINGS_PATH}"/intellij/plugins/*.properties
do
if [ -f "${file}" ]
then
plugin_id=""
plugin_active="true"
doLoadProperties "${file}"
if [ -z "${plugin_id}" ]
then
doWarning "Invalid intellij plugin config: ${file}"
elif [ "${plugin_active}" = "true" ]
then
doAddPlugin "${plugin_id}"
fi
fi
done
}
function doAddPlugin() {
local intellij_build
local download_dir="${DEVON_DOWNLOAD_DIR}"
local filename
local install_path
if [ -e "${IDEA_HOME}/build.txt" ]
then
intellij_build="$(cat "${IDEA_HOME}/build.txt")"
install_path="${IDEA_HOME}/plugins"
elif [ -e "${IDEA_HOME}/IntelliJ.app/Contents/Resources/build.txt" ]
then
intellij_build="$(cat "${IDEA_HOME}/IntelliJ.app/Contents/Resources/build.txt")"
install_path="${IDEA_HOME}/IntelliJ.app/Contents/plugins"
fi
if [ -n "${1}" ] && [ -n "${intellij_build}" ]
then
local download_url="https://plugins.jetbrains.com/pluginManager?action=download&id=${1}&build=${intellij_build}"
filename=$(curl -sI "${download_url}" | grep -o -E 'location:.*$' | sed -e 's/location://')
filename="${filename##*/}"
filename="${filename%%\?*}"
doDownload "${download_url}" "${filename}" "${download_dir}"
if [ "${filename##*.}" = "zip" ]
then
local extract_name=${filename%.*}
doExtract "${download_dir}/${filename}" "${extract_name}"
cp -r "${DEVON_IDE_HOME}/updates/extracted/${extract_name}/"* "${install_path}/"
rm -r "${DEVON_IDE_HOME}/updates/extracted/${extract_name}/"
else
cp "${download_dir}/${filename}" "${install_path}"
rm "${download_dir}/${filename}"
fi
else
doEcho "No plugins to be installed"
fi
}
function doConfigureIntellij() {
local mode="${1}"
if [ ! -d "${WORKSPACE_PATH}/.idea" ]
then
if [ -z "${mode}" ]
then
mode="-u"
elif [ "${mode}" != "-u" ]
then
doFail "Workspace ${WORKSPACE} is not initialized.\nReverse merge is not possible."
fi
fi
if [ -n "${mode}" ]
then
doConfigureWorkspace "${SETTINGS_PATH}/intellij/workspace" "${WORKSPACE_PATH}" ${mode}
fi
}
function doStartIntellij() {
doConfigureIntellij "-u"
echo "launching IntelliJ..."
local IDEA="${IDEA_HOME}/bin/idea64.exe"
if [ ! -f "${IDEA}" ];
then
IDEA="${IDEA_HOME}/bin/idea"
fi
if [ ! -f "${IDEA}" ];
then
IDEA="${IDEA_HOME}/idea"
fi
if doIsMacOs
then
echo "MacOs command ${IDEA}"
open "${IDEA}" --args "${@}"
else
echo "command ${IDEA}"
"${IDEA}" "${@}" &
fi
}
# CLI
if [ "${1}" = "-h" ] || [ "${1}" = "help" ]
then
echo "Manage IntelliJ IDE and workspace."
echo
echo "Arguments:"
echo " --all if provided as first arg then to command will be invoked for each workspace"
echo " setup setup IntelliJ (install or update)"
echo " add-plugin «id» install an additional plugin"
echo " run | start launch IntelliJ IDE (default if no argument is given)"
echo " ws-up[date] update IntelliJ workspace"
echo " ws-re[verse] reverse merge changes from workspace into settings"
echo " ws-reverse-add reverse merge adding new properties"
echo " create-script create intellij-${WORKSPACE} script if not already exists"
exit
fi
IDEA_HOME="${DEVON_IDE_HOME}/software/intellij"
if [ -z "${1}" ]
then
doSetup silent
doStartIntellij
elif [ "${1}" = "setup" ]
then
doSetup "${2}"
exit
fi
if [ "${1}" = "--all" ]
then
shift
doDevonCommandAllWorkspaces intellij "${@}"
fi
while [ -n "${1}" ]
do
if [ "${1}" = "run" ] || [ "${1}" = "start" ]
then
doSetup silent
shift
doStartIntellij "${@}"
elif [ "${1}" = "ws-up" ] || [ "${1}" = "ws-update" ]
then
doConfigureIntellij "-u"
elif [ "${1}" = "ws-re" ] || [ "${1}" = "ws-reverse" ]
then
doConfigureIntellij "-i"
elif [ "${1}" = "ws-reverse-add" ]
then
doConfigureIntellij "-x"
elif [ "${1}" = "create-script" ]
then
doCreateIdeScript intellij
elif [ "${1}" = "add-plugin" ]
then
shift
doAddPlugin "${@}"
else
doFail "Unknown argument: ${1}"
fi
shift
done