Files
artloglaby/doit.sh
philippe lhardy 7d8ce42c15 create lab directory in parent
abstract MazeParams to be able to set them easily
doit.sh support new class creation
updated README

Signed-off-by: philippe lhardy <philippe@pavilionartlogiciel>
2015-02-18 21:06:37 +01:00

203 lines
4.0 KiB
Bash
Executable File

#!/bin/bash
setup()
{
if [[ ! -d java ]]
then
echo "[FATAL] this tools $0 is intended to be run within laby project. Missing java directory." >&2
exit 1
fi
if [[ ! -d lab ]]
then
echo "[INFO] Creating directory lab to save default lab created"
mkdir lab
fi
}
do_code()
{
background=$1
find java/org/artisanlogiciel/games/ -name "*.java" |
{
s=()
while read codeline
do
javafile=$(basename "$codeline")
javaclass=${javafile/.java/}
echo "$javafile $javaclass"
s+=("$javaclass" "$codeline")
done
javaclass=$($DIALOG --menu "Edit it" 20 100 10 ${s[@]} 3>&1 1>&2 2>&3)
if [[ -n $javaclass ]]
then
pushd java
if [[ $background == codebg ]]
then
nohup make work/$javaclass &
else
make work/$javaclass
fi
popd
fi
}
}
edit_properties()
{
local property_file=$1
if [[ -f $property_file ]]
then
modified=0
s=()
properties=()
values=()
{
while read codeline
do
if [[ $codeline =~ (^[a-zA-Z_]*)=(.*) ]]
then
property=${BASH_REMATCH[1]}
value=${BASH_REMATCH[2]}
s+=("$property" "$value")
properties+=("$property")
values+=("$value")
fi
done
s+=(exit "Exit")
} < $property_file
while true
do
property=$($DIALOG --menu "Edit '$property_file'" 20 100 10 ${s[@]} 3>&1 1>&2 2>&3)
if [[ $? = 0 ]]
then
if [[ -n $property ]]
then
if [[ $property == exit ]]
then
return 1
elif [[ $property == save ]]
then
for (( i=0; i<${prop_len}; i++ ));
do
echo "${properties[$i]}=${values[$i]}"
done >$property_file
return 0
fi
prop_len="${#properties[@]}"
for (( i=0; i<${prop_len}; i++ ));
do
if [[ ${properties[$i]} == $property ]]
then
init_value=${values[$i]}
fi
done
value=$($DIALOG --inputbox "Enter $property value" 10 80 "$init_value" 3>&1 1>&2 2>&3)
if [[ $? = 0 ]]
then
prop_len="${#properties[@]}"
s=()
if [[ "$value" != "$init_value" ]]
then
modified=$(( modified + 1 ))
fi
for (( i=0; i<${prop_len}; i++ ));
do
if [[ ${properties[$i]} == $property ]]
then
values[$i]=$value
fi
s+=("${properties[$i]}" "${values[$i]}")
echo "${properties[$i]}=${values[$i]}"
done
s+=(exit "Exit")
if [[ $modified != 0 ]]
then
s+=(save "Save")
fi
fi
fi
else
return 2
fi
done
else
echo "[ERROR] property_file '$propertyfile' not found" >&2
fi
}
possible_console_gui="whiptail dialog"
for DIALOG in $possible_console_gui
do
DIALOG=$(which $DIALOG)
if [[ -n $DIALOG ]]
then
break
fi
done
if [[ -z $DIALOG ]]
then
echo "[ERROR] no console gui support (no dialog tool found within $possible_console_gui) => no menus " >&2
exit 1
fi
setup
action=initial
while [[ $action != quit ]]
do
action=$($DIALOG --menu "Ultra Light IDE" 20 80 12 run "Run it" clean "Clean All" ant "Ant build" test "Test it" readme "Read me" code "Code" codebg "Code in background" deb "Debian package" properties "Edit Properties" create "Create a new class" quit "Quit" 3>&1 1>&2 2>&3)
if [[ $action == run ]]
then
echo "run it"
java -jar $(make getname)
elif [[ $action == ant ]]
then
make clean
make
ant compile
elif [[ $action == clean ]]
then
make clean
pushd java
make clean
popd
elif [[ $action == test ]]
then
echo "test it"
pushd java
make display
popd
elif [[ $action == deb ]]
then
make deb
elif [[ $action =~ code ]]
then
do_code $action
elif [[ $action == readme ]]
then
$DIALOG --textbox README 40 80 --scrolltext
elif [[ $action == properties ]]
then
edit_properties project_params
elif [[ $action == create ]]
then
newclass=$($DIALOG --inputbox "Enter new class name" 10 80 "NewClass" 3>&1 1>&2 2>&3)
if [[ $? = 0 ]]
then
if [[ -n $newclass ]]
then
pushd java
make work/$newclass
popd
fi
fi
fi
done