add missing script coming from unlinked artlog toolbox project
not mandatory but consistent to have all code Signed-off-by: philippe lhardy <philippe.lhardy@astrolabe.coop>
This commit is contained in:
@@ -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
|
||||
```
|
||||
|
||||
92
antify.sh
Executable file
92
antify.sh
Executable file
@@ -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 <<EOF
|
||||
<project name="$project_name" default="$project_default" basedir="$project_basedir">
|
||||
<description>
|
||||
$project_name build
|
||||
autogenerated build file by $0 script
|
||||
</description>
|
||||
<!-- set global properties for this build -->
|
||||
<property name="src" location="java"/>
|
||||
<property name="build" location="build"/>
|
||||
<property name="dist" location="dist"/>
|
||||
<!-- Fill me please / todo
|
||||
<property name="artgraphicslib" value="artgaphics-0.1.0"/>
|
||||
<property name="distversion" value="1.0"/>
|
||||
-->
|
||||
|
||||
<target name="init">
|
||||
<!-- Create the time stamp -->
|
||||
<tstamp/>
|
||||
<!-- Create the build directory structure used by compile -->
|
||||
<mkdir dir="\${build}"/>
|
||||
</target>
|
||||
|
||||
<target name="compile" depends="init"
|
||||
description="compile the source " >
|
||||
<!-- Compile the java code from \${src} into \${build} -->
|
||||
EOF
|
||||
|
||||
if [[ -z $java_target ]]
|
||||
then
|
||||
echo ' <javac srcdir="${src}" destdir="${build}">'
|
||||
else
|
||||
echo " <javac target=\"$java_target\" source=\"$java_target\" srcdir=\"\${src}\" destdir=\"\${build}\"><compilerarg value=\"-Xlint:-options\"/>"
|
||||
fi
|
||||
echo "<!-- suggestion "
|
||||
excludes="org/artisanlogiciel/games/javafx/*"
|
||||
for exclude in "$excludes"
|
||||
do
|
||||
echo " <exclude name=\"$exclude\"/>"
|
||||
done
|
||||
echo "-->"
|
||||
echo " </javac>"
|
||||
|
||||
cat <<EOF
|
||||
</target>
|
||||
|
||||
<target name="dist" depends="compile"
|
||||
description="generate the distribution" >
|
||||
<!-- Create the distribution directory -->
|
||||
<mkdir dir="\${dist}/lib"/>
|
||||
|
||||
<!-- Put everything in \${build} into the ${project_name}-${project_version}.jar file ( \${DSTAMP} not used yet )-->
|
||||
<jar jarfile="\${dist}/lib/${project_name}-${project_version}.jar" basedir="\${build}">
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="$project_mainclass"/>
|
||||
<!-- suggestion
|
||||
<attribute name="Class-Path" value="\${artgraphicslib}.jar"/>
|
||||
-->
|
||||
</manifest>
|
||||
</jar>
|
||||
</target>
|
||||
|
||||
<target name="clean"
|
||||
description="clean up" >
|
||||
<!-- Delete the \${build} and \${dist} directory trees -->
|
||||
<delete dir="\${build}"/>
|
||||
<delete dir="\${dist}"/>
|
||||
</target>
|
||||
</project>
|
||||
EOF
|
||||
76
debianize.sh
Executable file
76
debianize.sh
Executable file
@@ -0,0 +1,76 @@
|
||||
#!/bin/bash
|
||||
|
||||
action=$1
|
||||
file=$2
|
||||
|
||||
maintainer="Artlog <pl@artisanlogiciel.net>"
|
||||
|
||||
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 <<EOF
|
||||
Source: ${project_name}-java
|
||||
Priority: extra
|
||||
Maintainer: $maintainer
|
||||
Build-Depends: debhelper (>= 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 <<EOF
|
||||
${project_name}-java (${project_version}) unstable; urgency=low
|
||||
|
||||
* Initial debian package
|
||||
|
||||
-- ${maintainer} $(LANG=C date -R)
|
||||
EOF
|
||||
elif [[ $file = debian/rules ]]
|
||||
then
|
||||
cat <<EOF
|
||||
#!/usr/bin/make -f
|
||||
JAVA_HOME=/usr/lib/jvm/default-java
|
||||
|
||||
%:
|
||||
dh \$@ --with javahelper
|
||||
EOF
|
||||
elif [[ $file = deb/javadoc ]]
|
||||
then
|
||||
echo "api /usr/share/doc/${project_name}-java/api" >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
|
||||
393
doit.sh
Executable file
393
doit.sh
Executable file
@@ -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 <text> <height> <width> <listheight> <tag[1]> <name[1]> ... <tag[n]> <name[n]>
|
||||
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
|
||||
137
eclipse_env.sh
Executable file
137
eclipse_env.sh
Executable file
@@ -0,0 +1,137 @@
|
||||
#!/bin/bash
|
||||
# for the story this comes from a JavaFX training i attended
|
||||
|
||||
usage()
|
||||
{
|
||||
cat <<EOF
|
||||
Usage $0:
|
||||
setup_dev_env: create file devenv_params with reference over jdk and eclipse path
|
||||
|
||||
any other argument is an error
|
||||
no argument => 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 <<EOF
|
||||
DEV_ENV=$DEV_ENV
|
||||
JDK_PATH=$JDK_PATH
|
||||
ECLIPSE_PATH=$ECLIPSE_PATH
|
||||
EOF
|
||||
fi
|
||||
}
|
||||
|
||||
setup_eclipse_dir()
|
||||
{
|
||||
if [[ -e devenv_params ]]
|
||||
then
|
||||
source devenv_params
|
||||
else
|
||||
echo "[WARNING] Use some defaults for devenv_params"
|
||||
echo "[INFO] please adapt them. Current setup should be compatible with 'sudo snap install eclipse --classic' setup"
|
||||
DEV_ENV=~$(pwd)/devel_tools
|
||||
JDK_PATH=/usr/lib/jvm/java-11-openjdk-amd64
|
||||
ECLIPSE_PATH=$(dirname $(which eclipse))
|
||||
fi
|
||||
}
|
||||
|
||||
# Not tested written after install ...
|
||||
setup_eclipse()
|
||||
{
|
||||
# current list of TGZ got from oracle (tm)
|
||||
TGZ_LIST="eclipse-jee-mars-2-linux-gtk-x86_64.tar.gz javafx_scenebuilder-2_0-linux-x64.tar.gz jdk-8u74-linux-x64.tar.gz"
|
||||
}
|
||||
|
||||
check_eclipse()
|
||||
{
|
||||
if [[ -z $JDK_PATH ]]
|
||||
then
|
||||
echo "[ERROR] Missing JDK_PATH, either devenv_params is wrong or missing" >&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
|
||||
|
||||
209
generate_new.sh
Executable file
209
generate_new.sh
Executable file
@@ -0,0 +1,209 @@
|
||||
#!/bin/bash
|
||||
# generate empty templates or add functions given a defined language
|
||||
|
||||
usage()
|
||||
{
|
||||
head -n 2
|
||||
}
|
||||
|
||||
generate_java_class()
|
||||
{
|
||||
cat <<EOF >$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 <<EOF >$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 <<EOF >>$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 <<EOF >>$H_FILE
|
||||
# autogenerated by $TOOLP
|
||||
int $FUNCTION();
|
||||
EOF
|
||||
cat <<EOF >>$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
|
||||
Reference in New Issue
Block a user