diff --git a/README.md b/README.md index cee9f73..11d0cef 100644 --- a/README.md +++ b/README.md @@ -34,11 +34,11 @@ and output * txt labyrinth as text * we minetest/luanti world edit format -===== BUILD ===== +## BUILD See BUILD.md -===== INSTALL ===== +## INSTALL obtain laby.zip directly build or from you own build ( see BUILD above ). @@ -48,11 +48,10 @@ unzip laby.zip it will create a artloglaby directory. -===== RUN ===== +## RUN run it on a Linux distribution with : - ``` cd artloglaby ; ./laby.sh ``` diff --git a/antify.sh b/antify.sh new file mode 100755 index 0000000..9afbfd7 --- /dev/null +++ b/antify.sh @@ -0,0 +1,92 @@ +#!/bin/bash +# +# Generates to stdout an ant project build.xml content using some parameters from project_params +# +# this is used by 4java.makefile for build.xml target + +usage() +{ + head -n 4 $0 +} + +PROJECT_PARAMS=./project_params +if [[ -f $PROJECT_PARAMS ]] +then + source $PROJECT_PARAMS +else + echo "[ERROR] missing $PROJECT_PARAMS " >&2 + usage + exit 1 +fi + +# TODO reuse internal tsamp ${DSTAMP} ( after review i do't recall what is wanted to do here ) + +cat < + + $project_name build + autogenerated build file by $0 script + + + + + + + + + + + + + + + + +EOF + +if [[ -z $java_target ]] +then + echo ' ' +else + echo " " +fi +echo "" +echo " " + +cat < + + + + + + + + + + + + + + + + + + + + +EOF diff --git a/debianize.sh b/debianize.sh new file mode 100755 index 0000000..38af550 --- /dev/null +++ b/debianize.sh @@ -0,0 +1,76 @@ +#!/bin/bash + +action=$1 +file=$2 + +maintainer="Artlog " + +if [[ $action == getversion ]] +then + source ./project_params + echo $project_version +elif [[ $action == getproject ]] +then + source ./project_params + echo $project_name +elif [[ $action =~ get([_a-z]*)$ ]] +then + getvar=${BASH_REMATCH[1]} + source ./project_params + eval "echo \$$getvar" +elif [[ $action == create ]] +then + source ./project_params + + if [[ $file == debian/control ]] + then + + cat <= 7.0.50~), javahelper (>=0.25) +Build-Depends-Indep: default-jdk, default-jdk-doc, libtrove-java, libtrove-java-doc, ant +Standards-Version: ${project_version} +Section: java + +Package: ${project_name}-java +Architecture: all +Depends: \${java:Depends}, \${misc:Depends} +Recommends: \${java:Recommends} +Description: Labyrinth generator + Labyrinth generator + +Package: ${project_name}-java-doc +Architecture: all +Depends: \${java:Depends}, \${misc:Depends} +Recommends: \${java:Recommends} +Description: Labyrinth generator (documentation) + Labyrinth generator +EOF + elif [[ $file = debian/changelog ]] + then + cat <debian/${project_name}-java-doc.javadoc + elif [[ $file = deb/jlibs ]] + then + echo "dist/lib/${project_name}-${project_version}.jar" >debian/${project_name}-java.jlibs + fi +fi diff --git a/doit.sh b/doit.sh new file mode 100755 index 0000000..b32c6af --- /dev/null +++ b/doit.sh @@ -0,0 +1,393 @@ +#!/bin/bash +# entry point for project building / editing / running + +# this specific_run is intended to be overriden by specific_doit.sh script if any. +function specific_run() +{ + echo "[ERROR] '$1' command is not supported in a generic manner" >&2 +} + +# within a list of files $1 $2 ... find the first that exists and set variable found_best to it. +find_best() +{ + while [[ $# > 0 ]] + do + if [[ -f $1 ]] + then + found_best=$1 + return + fi + shift + done +} + +# $1 variable $2 value +save_parameter() +{ + echo "$1=\"$2\"" >> .params +} + +info() +{ + if [[ -z $NOJAVA ]] + then + echo "DEV_ENV=$DEV_ENV" + echo "JDK_PATH=$JDK_PATH" + echo "ECLIPSE_PATH=$ECLIPSE_PATH" + echo "PATH=$PATH" + java -version + else + echo "NOJAVA is set to $NOJAVA" + fi +} + +setup() +{ + if [[ -z $NOJAVA ]] + then + if [[ ! -d java ]] + then + echo "[INFO] Missing java directory." >&2 + fi + fi +} + +do_code() +{ + if [[ -z $NOJAVA ]] + then + background=$1 + local jd=() + local id=() + local menu=() + index=0 + # find all java source file within current directory and populate jd array with. even if java is a link ( -H option ). + for java_dir in $(find -H java -name '*.java' -exec dirname {} \; | sort -u) + do + index=$((index+1)) + id+=($index) + jd+=("$java_dir") + menu+=($index "$java_dir") + done + echo "found ${#jd[@]} java source directories" + if [[ ${#jd[@]} -gt 1 ]] + then + echo "${jd[@]}" + # menu ... + index_dir=$($DIALOG --menu "Select dir" 20 100 10 ${menu[@]} 3>&1 1>&2 2>&3) + if [[ ! $? ]] + then + echo "[ERROR] $DIALOG --menu did fail when requesting choice over java directories" >&2 + exit 1 + fi + fi + java_dir=${jd[$((index_dir-1))]} + if [[ ! -d $java_dir ]] + then + echo "$java_dir is not a directory" >&2 + return + fi + echo "chose dir $java_dir" + find $java_dir -maxdepth 1 -name '*.java' | + { + local 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 + if [[ $background == codebg ]] + then + ${EDITOR} $java_dir/$javaclass.java & + else + ${EDITOR} $java_dir/$javaclass.java + fi + fi + } + else + echo "NOJAVA set" + 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 + +} + +specific_menus=() + +if [[ -f ./specificdoit.sh ]] +then + source ./specificdoit.sh +fi + +if [[ -f .params ]] +then + source .params + if [[ -n $DIALOG ]] + then + if [[ ! -x $DIALOG ]] + then + echo "[ERROR] DIALOG=$DIALOG dialog tool not executable" >&2 + exit 1 + fi + fi +fi + +LOG_OUTFILE=.log + +if [[ -z $DIALOG ]] +then + echo "[INFO] detecting dialog program" + + possible_console_gui="whiptail dialog" + + for DIALOG in $possible_console_gui + do + DIALOG=$(which $DIALOG) + if [[ -x $DIALOG ]] + then + $DIALOG --menu "Ultra Light IDE" 20 80 2 "select me to validate $DIALOG " justfortest + rc=$? + if [[ $rc != 0 ]] + then + echo "[ERROR] $DIALOG return code $rc : can't use it" >&2 + else + break + fi + fi + done + + if [[ -z $DIALOG ]] + then + echo "[ERROR] no console gui support (no dialog tool found within $possible_console_gui) => no menus " >&2 + echo "[INFO] this can happen under emacs within shell or eshell, please use term then" + exit 1 + fi + + save_parameter DIALOG "$DIALOG" +fi + +possible_editor="emacs vi nano" + +for EDITOR in $possible_editor +do + EDITOR=$(which $EDITOR) + if [[ -x $EDITOR ]] + then + break + fi +done + +if [[ -z $EDITOR ]] +then + echo "[ERROR] no editor found (within $possible_editor) => no editing " >&2 +fi + +setup + +action=initial +# count successives failures. +failed_commands_count=0 + +while [[ $action != quit ]] +do + # should detect that dialog failed + if [[ -z $NOJAVA ]] + then + # should be cleaned up from specific laby project targets. + action=$($DIALOG --menu "Ultra Light IDE" 20 80 12 readme "Read me" clean "Clean All" ant "Ant build" run "Run it" ${specific_menus[@]} test "Test it" code "Code" codebg "Code in background" deb "Debian package" properties "Edit Properties" create "Create a new class" info "Info" logs "Logs" quit "Quit" 3>&1 1>&2 2>&3) + else + action=$($DIALOG --menu "Ultra Light IDE" 20 80 12 readme "Read me" clean "Clean All" run "Run it" test "Test it" ${specific_menus[@]} code "Code" codebg "Code in background" deb "Debian package" properties "Edit Properties" info "Info" logs "Logs" quit "Quit" 3>&1 1>&2 2>&3) + fi + + rc=$? + if [[ $rc == 0 ]] + then + failed_commands_count=0 + else + failed_commands_count=$(( failed_commands_count + 1 )) + fi + if (( $failed_commands_count > 10 )) + then + echo "[ERROR] more than 10 successive failures ( $failed_commands_count > 10 )" >&2 + echo "[INFO] Check if your environment supports $DIALOG" + action=quit + fi + + if [[ $action == run ]] + then + if [[ -z $NOJAVA ]] + then + echo "run it" + { + source ./project_params + javalibs=$(make -f ${JAVA_MAKEFILE} getjavalibs|awk '{ printf "%s:",$1 }') + mainlib=$(make -f ${JAVA_MAKEFILE} getname) + javarun="java -cp $mainlib:$javalibs $project_mainclass" + echo $javarun + $javarun + } + else + make + fi + elif [[ $action == ant ]] + then + make -f ${JAVA_MAKEFILE} clean + make -f ${JAVA_MAKEFILE} + ant compile >>.log 2>&1 + elif [[ $action == clean ]] + then + if [[ -z $NOJAVA ]] + then + make -f ${JAVA_MAKEFILE} clean + pushd java + make clean + popd + else + make clean + fi + elif [[ $action == test ]] + then + if [[ -z $NOJAVA ]] + then + echo "test it" + pushd java + make display + popd + else + make test + fi + elif [[ $action == deb ]] + then + make -f ${JAVA_MAKEFILE} deb + elif [[ $action =~ code ]] + then + do_code $action + elif [[ $action == readme ]] + then + found_best= + find_best README README.md + if [[ -n $found_best ]] + then + $DIALOG --textbox $found_best 40 80 --scrolltext + else + echo "no README or README.md found" >&2 + fi + 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 + MAIN_CLASS=Main PACKAGE=$(./debianize.sh getproject_mainpackage) make -f 4create.makefile work/$newclass + fi + fi + elif [[ $action == info ]] + then + infos=$(mktemp) + info >$infos + $DIALOG --textbox $infos 40 80 --scrolltext + rm $infos + elif [[ $action == logs ]] + then + if [[ -f .log ]] + then + $DIALOG --textbox .log 40 80 --scrolltext + fi + elif [[ $action == quit ]] + then + echo "[INFO] quit requested" + else + specific_run $action + fi +done diff --git a/eclipse_env.sh b/eclipse_env.sh new file mode 100755 index 0000000..4d859af --- /dev/null +++ b/eclipse_env.sh @@ -0,0 +1,137 @@ +#!/bin/bash +# for the story this comes from a JavaFX training i attended + +usage() +{ + cat < launch eclipse +EOF + +} +create_dev_params() +{ + if [[ -e devenv_params ]] + then + echo " devenv_params already exists" + exit 1 + # could update this way + # source devenv_params + else + if [[ -z $DEV_ENV ]] + then + echo "[ERROR] DEV_ENV $DEV_ENV not set, call setup_eclipse_dir from this '$0' script" + exit 1 + fi + cat >devenv_params <&2 + exit 1 + fi + if [[ -z $ECLIPSE_PATH ]] + then + echo "[ERROR] Missing ECLIPSE_PATH, either devenv_params is wrong or missing" >&2 + exit 1 + fi + if [[ ! -d $JDK_PATH ]] + then + echo "[ERROR] Missing JDK_PATH '$JDK_PATH'" >&2 + fi + + if [[ ! -d $ECLIPSE_PATH ]] + then + ls -la ${DEV_ENV} + + echo "[ERROR] Missing ECLIPSE_PATH '$ECLIPSE_PATH'" >&2 + exit 1 + fi + +} + +# not yet used ... +create_sandbox() +{ + mkdir sandbox +} + +check_java_version() { + local expected_version='1.8.0' + if java -version 2>&1 | grep "$expected_version" + then + if javac -version 2>&1 | grep "$expected_version" + then + $* + else + echo "[ERROR] Wrong javac version expected $expected_version" >&2 + fi + else + echo "[ERROR] Wrong java version expected $expected_version" >&2 + fi +} + +# overrides PATH with JDK_PATH ECLIPSE_PATH +# and check java is the right one to launch eclipse +run_in_sandbox() +{ + PATH=$JDK_PATH/bin/:$JDK_PATH/jre/bin/:$ECLIPSE_PATH:$PATH + + export PATH + + [[ -n $check_version ]] && check_java_version +} + +while [[ $# > 0 ]] +do + case $1 in + setup_dev_env) + setup_eclipse_dir + create_dev_params + exit 0 + ;; + *) + echo "[ERROR] Unrecognized argument '$1'" >&2 + usage + exit 1 + ;; + esac + shift 1 +done + +setup_eclipse_dir +check_eclipse +run_in_sandbox eclipse -data $(pwd)/workspace + diff --git a/generate_new.sh b/generate_new.sh new file mode 100755 index 0000000..5a789d0 --- /dev/null +++ b/generate_new.sh @@ -0,0 +1,209 @@ +#!/bin/bash +# generate empty templates or add functions given a defined language + +usage() +{ + head -n 2 +} + +generate_java_class() +{ + cat <$JAVA_FILE +package $PACKAGE; + +/** + $CLASS was autogenerated by $TOOLP + **/ +public $ctype $CLASS +{ + Object param; + + $CLASS(Object param) + { + this.param=param; + } + + void method() + { + System.out.println("Method of $PACKAGE.$CLASS"); + } + + public static void main(String args[]) { + if ( args.length > 1 ) + { + $CLASS instance=new $CLASS(args[1]); + instance.method(); + } + else + { + System.err.println("Missing argument for $CLASS"); + } + } +} +EOF +} + +generate_java_interface() +{ +cat <$JAVA_FILE +package $PACKAGE; + +/** + $CLASS was autogenerated by $TOOLP + **/ +public $ctype $CLASS +{ + /** + @return X + */ + int getX(); + + /** + @return Y + */ + int getY(); +} +EOF +} + +add_new_c_main() +{ + cat <>$C_FILE +# autogenerated by $TOOLP +int main(int argc, char **argv) +{ + todo(\"Code this\"); + return 0; +} +EOF +} + +add_new_c_function() +{ + echo "[INFO] add new c function $FUNCTION in h_file=$H_FILE and c_file=$C_FILE" + if [[ $FUNCTION == main ]] + then + add_new_c_main + else + cat <>$H_FILE +# autogenerated by $TOOLP +int $FUNCTION(); +EOF + cat <>$C_FILE +# autogenerated by $TOOLP +int $FUNCTION(){ + todo(\"Code this $FUNCTION\"); + return -2; +} +EOF + fi +} + +#TODO : support "like=" to copy/renaming an existing class + +TOOLP="$0 $*" + +ctype=class +genlang=java + +while [[ $# > 0 ]] +do + case $1 in + class|interface) + ctype=$1 + ;; + package=*) + PACKAGE=${1/package=/} + ;; + package_dir=*) + PACKAGE_DIR=${1/package=/} + PACKAGE=${PACKAGE//\//\.} + ;; + genlang=*) + genlang=${1/genlang=/} + ;; + class=*) + CLASS=${1/class=/} + ;; + function=*) + FUNCTION=${1/function=/} + ;; + c_file=*) + C_FILE=${1/c_file=} + ;; + h_file=*) + H_FILE=${1/h_file=} + ;; + *) + if [[ -z $CLASS ]] + then + CLASS=${1} + echo "[INFO] setting class=$CLASS" >&2 + else + echo "[ERROR] unrecognized parameter $1" >&2 + fi + ;; + esac + shift 1 +done + + +if [[ $genlang == java ]] +then + + if [[ -z $PACKAGE ]] + then + echo "[INFO] obtain package name from project settings" + PACKAGE=$(./debianize.sh getproject_mainpackage) + if [[ -z $PACKAGE ]] + then + echo "[ERROR] can't find project_mainpackage" >&2 + exit 1 + fi + fi + + if [[ -z $CLASS ]] + then + echo "[ERROR] Missing class" >&2 + exit 1 + fi + + PACKAGE_DIR=${PACKAGE//\./\/} + + if [[ ! -d $PACKAGE_DIR ]] + then + echo "Missing $PACKAGE_DIR" >&2 + exit 1 + fi + + JAVA_FILE=$PACKAGE_DIR/$CLASS.java + if [[ -e $JAVA_FILE ]] + then + echo "[ERROR] $JAVA_FILE already exists" >&2 + exit 1 + else + + if [[ $ctype == class ]] + then + generate_java_class + else + generate_java_interface + fi + fi + + echo "$JAVA_FILE generated" +elif [[ $genlang == c ]] +then + if [[ -z $H_FILE ]] + then + H_FILE=c/genauto.h + fi + if [[ -z $C_FILE ]] + then + C_FILE=c/genauto.c + fi + add_new_c_function +else + echo "[ERROR] language genlang=$genlang NOT supported" >&2 + usage +fi