-
Notifications
You must be signed in to change notification settings - Fork 6
/
create
executable file
·226 lines (197 loc) · 8.14 KB
/
create
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
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/bin/bash
## A simple script to generate the skeleton for a new BukkitMod plugin.
## Written by: Pezmc
# OS Detection
## Check if we're running windows. If so, clear the
## "bash: warning: could not find /tmp, please create!
## error that likely occurred when bash was started.
if [ $_OS -a $_OS == "NT" ]; then
_OS='nt'
else
# Get the OS name and lowercase it.
_OS=`uname -s | tr '[A-Z]' '[a-z]'`
# Now test if it's Linux or Mac OSX
if [[ $_OS == *linux* ]]; then
_OS='linux'
elif [[ $_OS == *cygwin* ]]; then
_OS='nt'
elif [[ $_OS == *darwin* ]]; then
_OS='mac'
fi
fi
# Set up the ANSI escape colors depending on OS.
if [[ $_OS == 'linux' || $_OS == 'nt' ]]; then
# Standard ANSI escape codes.
c_default='\e[0;37m'
c_white='\e[1;37m'
c_cyan='\e[1;36m'
c_green='\e[1;32m'
c_red='\e[0;31m'
c_blue='\e[1;34m'
c_yellow='\e[1;33m'
elif [[ $_OS == 'mac' ]]; then
# For Mac OS X, we have to do it slightly
# different.
c_default='\033[0;37m'
c_white='\033[1;37m'
c_cyan='\033[1;36m'
c_green='\033[1;32m'
c_red='\033[0;31m'
c_blue='\033[1;34m'
c_yellow='\033[1;33m'
fi
# Pause (Getch)
function pause(){
read -p "Press any key to continue..."
}
# Read Configuration Files
function read_config(){
local cfgPath="$(pwd)/settings.cfg"
if [ -a $cfgPath ]; then
echo -e "\n${c_cyan}Reading ${c_green}config${c_cyan}...${c_default}" >&2
source $cfgPath
return
else
echo -e "\n${c_cyan}Creating ${c_green}default config${c_cyan}...${c_default}" >&2
echo -ne "# General Settings\noutput_folder=\".\"\n\n# Project File Generation\ngen_intellij=0\ngen_eclipse=0\ngen_netbeans=0\ngen_ant=0" > $cfgPath
source $cfgPath
return
fi
}
# Input validation.
function validate_input(){
local _true=1; local _false=0
# Get the input.
local _input=${1}
# Same as above, but with
# dashes and underscores.
local _symbols=${2:-$_true}
# Unless stated otherwise,
# numbers will be allowed.
local _numbers=${3:-$_true}
# Finally, anything
local _anything=${4:-$_false}
if [ $_anything == $_true ]; then
is_valid=1
return
fi
# Escape some characters in the actual value.
local _action=${_input//\$/\\\$}
_action=${_action/\"/}
# Begin assembling the expression.
local _expr="sed -e 's/[a-zA-Z"
## If we allow numbers, add them in.
if [ $_numbers == 1 ]; then
_expr="${_expr}0-9"
fi
## If we allow symbols, add them in.
if [ $_symbols == 1 ]; then
_expr="${_expr}_-"
fi
# Finish it off.
_expr="${_expr}]//g'"
# Now put it all together.
local _result=""
eval "_result=\$(echo -ne \"${_action}\" | ${_expr})"
is_valid=$(( ${#_result} == 0 ? 1 : 0 ))
return
}
# Our banner.
echo -ne "${c_cyan} ___ _ _ _ _ _____ \n| |_) | | | | |_/ | |_/ | | | | \n|_|_) \\_\\_/ |_| \\ |_| \\ |_| |_| \n\n"
echo -ne "${c_white} __ ____ _ ____ ___ __ _____ ___ ___ \n/ /\`_ | |_ | |\\ | | |_ | |_) / /\\ | | / / \\ | |_) \n\\_\\_/ |_|__ |_| \\| |_|__ |_| \\ /_/--\\ |_| \\_\\_/ |_| \\ \n\n"
# Read in our configuration.
read_config
# Questions.
echo -ne "${c_cyan}Author's name:${c_default} "; read USERNAME
echo -ne "${c_cyan}Plugin's name:${c_default} "; read PLUGINNAME
echo -ne "${c_cyan}Plugin Version (${c_default}0.1${c_cyan} by default):${c_default} "; read PLUGINVERSION
PLUGINVERSION=${PLUGINVERSION:-0.1}
# Validate the input.
## First user name.
validate_input "$USERNAME" 0 # No underscores or slashes allowed.
if [ $is_valid == 0 ]; then
echo -e "${c_red}Error: ${c_white}The author's name can only be made up of letters and numbers.${c_default}"
echo "Now exiting.."
exit
fi
## Next plugin name.
validate_input "$PLUGINNAME" 0 0 # Nothing but letters here.
if [ $is_valid == 0 ]; then
echo -e "${c_red}Error: ${c_white}The plugin's name can only be made up of letters.${c_default}"
echo "Now exiting.."
exit
fi
## Finally, the version.
validate_input "$PLUGINVERSION" 1 1 1 # Put whatever you want here.
if [ $is_valid == 0 ]; then
PLUGINVERSION="0.1"
fi
# Set the filenames and paths.
echo -e "${c_cyan}Generating ${c_green}manifest${c_cyan}..\n\n${c_white}Plugin: ${c_green}${PLUGINNAME}\n${c_white}Version: ${c_blue}${PLUGINVERSION}\n${c_white}Author: ${c_yellow}${USERNAME}${c_default}\n"
BLOCKLISTENER=BlockListener.java
YBLOCKLISTENER=${PLUGINNAME}BlockListener.java
PLAYERLISTENER=PlayerListener.java
YPLAYERLISTENER=${PLUGINNAME}PlayerListener.java
PLUGIN=YPlugin.java
YPLUGIN="${PLUGINNAME}.java"
ENDPATH="${output_folder}/${PLUGINNAME}/src/${USERNAME}/${PLUGINNAME}"
BINPATH="${output_folder}/${PLUGINNAME}/bin"
# Create the output directories.
mkdir -p "${ENDPATH}"
mkdir -p "${BINPATH}"
# Store our current path, then enter the output area.
SCRIPTROOT=`pwd`
cd "${ENDPATH}"
# Create our plugin's YAML file.
cd ../../../
echo "name: $PLUGINNAME
main: $USERNAME.$PLUGINNAME
version: $PLUGINVERSION" > plugin.yml
# Inform USERNAME on status.
echo -e "${c_cyan}Generating ${c_green}Source Files${c_cyan}..${c_default}"
# Copy the rest of the template files.
cd "${SCRIPTROOT}"
sed -e "s/<yourname>/$USERNAME/g" -e "s/<pluginname>/$PLUGINNAME/g" "${SCRIPTROOT}/files/${BLOCKLISTENER}" > "${ENDPATH}/$YBLOCKLISTENER"
sed -e "s/<yourname>/$USERNAME/g" -e "s/<pluginname>/$PLUGINNAME/g" "${SCRIPTROOT}/files/${PLAYERLISTENER}" > "${ENDPATH}/$YPLAYERLISTENER"
sed -e "s/<yourname>/$USERNAME/g" -e "s/<pluginname>/$PLUGINNAME/g" "${SCRIPTROOT}/files/${PLUGIN}" > "${ENDPATH}/${PLUGINNAME}.java"
# Project file generation.
## Eclipse
if [ $gen_eclipse == 1 ]; then
echo -e "${c_cyan}Generating ${c_green}Eclipse Project Files${c_cyan}..${c_default}"
sed -e "s/{{PLUGINNAME}}/$PLUGINNAME/g" "${SCRIPTROOT}/projects/eclipse/.project" > "${output_folder}/${PLUGINNAME}/.project"
cp "${SCRIPTROOT}/projects/eclipse/.classpath" "${output_folder}/${PLUGINNAME}/.classpath"
fi
## IntelliJ
if [ $gen_intellij == 1 ]; then
echo -e "${c_cyan}Generating ${c_green}Intelli-J Project Files${c_cyan}..${c_default}"
mkdir -p "${output_folder}/${PLUGINNAME}/.idea"
echo -n "${PLUGINNAME}" > "${output_folder}/${PLUGINNAME}/.idea/.name"
cp "${SCRIPTROOT}/projects/intellij/compiler.xml" "${output_folder}/${PLUGINNAME}/.idea/compiler.xml"
cp "${SCRIPTROOT}/projects/intellij/encodings.xml" "${output_folder}/${PLUGINNAME}/.idea/encodings.xml"
cp "${SCRIPTROOT}/projects/intellij/vcs.xml" "${output_folder}/${PLUGINNAME}/.idea/vcs.xml"
cp "${SCRIPTROOT}/projects/intellij/project.iml" "${output_folder}/${PLUGINNAME}/${PLUGINNAME}.iml"
sed -e "s/{{PLUGINNAME}}/$PLUGINNAME/g" "${SCRIPTROOT}/projects/intellij/modules.xml" > "${output_folder}/${PLUGINNAME}/.idea/modules.xml"
sed -e "s/{{PLUGINNAME}}/$PLUGINNAME/g" "${SCRIPTROOT}/projects/intellij/workspace.xml" > "${output_folder}/${PLUGINNAME}/.idea/workspace.xml"
fi
## NetBeans
if [ $gen_netbeans == 1 ]; then
echo -e "${c_cyan}Generating ${c_green}Netbeans Project Files${c_cyan}..${c_default}"
mkdir -p "${output_folder}/${PLUGINNAME}/nbproject"
mkdir -p "${output_folder}/${PLUGINNAME}/nbproject/private"
cp "${SCRIPTROOT}/projects/netbeans/genfiles.properties" "${output_folder}/${PLUGINNAME}/nbproject/genfiles.properties"
cp "${SCRIPTROOT}/projects/netbeans/private/private.properties" "${output_folder}/${PLUGINNAME}/nbproject/private/private.properties"
sed -e "s/{{USERNAME}}/$USERNAME/g" -e "s/{{PLUGINNAME}}/$PLUGINNAME/g" "${SCRIPTROOT}/projects/netbeans/project.properties" > "${output_folder}/${PLUGINNAME}/nbproject/project.properties"
sed -e "s/{{PLUGINNAME}}/$PLUGINNAME/g" "${SCRIPTROOT}/projects/netbeans/build-impl.xml" > "${output_folder}/${PLUGINNAME}/nbproject/build-impl.xml"
sed -e "s/{{PLUGINNAME}}/$PLUGINNAME/g" "${SCRIPTROOT}/projects/netbeans/project.xml" > "${output_folder}/${PLUGINNAME}/nbproject/project.xml"
fi
## Apache Ant
if [ $gen_ant == 1 ]; then
echo -e "${c_cyan}Generating ${c_green}Ant Build File${c_cyan}..${c_default}"
sed -e "s/{{PLUGINNAME}}/$PLUGINNAME/g" "${SCRIPTROOT}/projects/ant/build.xml" > "${output_folder}/${PLUGINNAME}/build.xml"
fi
# Done
echo -e "\n${c_cyan}~~~${c_green} Done! ${c_cyan}~~~${c_default}"
echo -e "\n\n${c_yellow}NOTE: ${c_white}You will need to add a reference to wherever you keep Bukkit's jar file if you decided to generate an IDE project/build file. Look for this integrated into this script later.${c_default}\n"
if [ $_OS -a $_OS != 'nt' ]; then
pause
fi