From f75087a09f1914521a19d1cd2ae8341ac1429014 Mon Sep 17 00:00:00 2001 From: Patrick Durand Date: Tue, 20 Dec 2022 11:51:48 +0100 Subject: [PATCH 01/26] update doc --- src/bzh/plealog/dbmirror/main/Annotate.java | 3 ++- src/bzh/plealog/dbmirror/main/AutoCheckDescriptors.java | 1 + src/bzh/plealog/dbmirror/main/CmdLineInstaller.java | 1 + src/bzh/plealog/dbmirror/main/CmdLineQuery.java | 1 + src/bzh/plealog/dbmirror/main/DeleteBank.java | 1 + src/bzh/plealog/dbmirror/main/DumpBankList.java | 1 + 6 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/bzh/plealog/dbmirror/main/Annotate.java b/src/bzh/plealog/dbmirror/main/Annotate.java index d4e67e3..3ab9d58 100755 --- a/src/bzh/plealog/dbmirror/main/Annotate.java +++ b/src/bzh/plealog/dbmirror/main/Annotate.java @@ -41,7 +41,8 @@ * -DKL_DEBUG=true ; if true, if set, log will be in debug mode
* -DKL_WORKING_DIR=an_absolute_path ; if not set, log and working directories are set to java.io.tmp
* -DKL_CONF_DIR=an_absolute_path ; the absolute path to a home-made conf directory. If not set, use ${user.dir}/conf. - * -DKL_LOG_FILE=a_file_name ; if set, creates a log file with that name within KL_WORKING_DIR

+ * -DKL_LOG_FILE=a_file_name ; if set, creates a log file with that name within KL_WORKING_DIR
+ * -DKL_LOG_TYPE=none|console|file(default)

* * @author Patrick G. Durand */ diff --git a/src/bzh/plealog/dbmirror/main/AutoCheckDescriptors.java b/src/bzh/plealog/dbmirror/main/AutoCheckDescriptors.java index 44b801b..e7a985b 100644 --- a/src/bzh/plealog/dbmirror/main/AutoCheckDescriptors.java +++ b/src/bzh/plealog/dbmirror/main/AutoCheckDescriptors.java @@ -61,6 +61,7 @@ * If not set, use ${user.dir}/conf. * -DKL_LOG_FILE=a_file_name ; if set, creates a log file with that name within * KL_WORKING_DIR
+ * -DKL_LOG_TYPE=none|console|file(default)

*
* * @author Patrick G. Durand diff --git a/src/bzh/plealog/dbmirror/main/CmdLineInstaller.java b/src/bzh/plealog/dbmirror/main/CmdLineInstaller.java index 55593e6..6fc7c8c 100755 --- a/src/bzh/plealog/dbmirror/main/CmdLineInstaller.java +++ b/src/bzh/plealog/dbmirror/main/CmdLineInstaller.java @@ -64,6 +64,7 @@ * If not set, use ${user.dir}/conf. * -DKL_LOG_FILE=a_file_name ; if set, creates a log file with that name within * KL_WORKING_DIR
+ * -DKL_LOG_TYPE=none|console|file(default)

*
* * @author Patrick G. Durand diff --git a/src/bzh/plealog/dbmirror/main/CmdLineQuery.java b/src/bzh/plealog/dbmirror/main/CmdLineQuery.java index 7bd2e02..f01811c 100755 --- a/src/bzh/plealog/dbmirror/main/CmdLineQuery.java +++ b/src/bzh/plealog/dbmirror/main/CmdLineQuery.java @@ -50,6 +50,7 @@ * If not set, use ${user.dir}/conf. * -DKL_LOG_FILE=a_file_name ; if set, creates a log file with that name within * KL_WORKING_DIR
+ * -DKL_LOG_TYPE=none|console|file(default)

*
* * @author Patrick G. Durand diff --git a/src/bzh/plealog/dbmirror/main/DeleteBank.java b/src/bzh/plealog/dbmirror/main/DeleteBank.java index f8edbed..e798c12 100644 --- a/src/bzh/plealog/dbmirror/main/DeleteBank.java +++ b/src/bzh/plealog/dbmirror/main/DeleteBank.java @@ -35,6 +35,7 @@ * If not set, use ${user.dir}/conf. * -DKL_LOG_FILE=a_file_name ; if set, creates a log file with that name within * KL_WORKING_DIR
+ * -DKL_LOG_TYPE=none|console|file(default)

*
* * @author Patrick G. Durand diff --git a/src/bzh/plealog/dbmirror/main/DumpBankList.java b/src/bzh/plealog/dbmirror/main/DumpBankList.java index 5b5e80c..33cd5ed 100644 --- a/src/bzh/plealog/dbmirror/main/DumpBankList.java +++ b/src/bzh/plealog/dbmirror/main/DumpBankList.java @@ -68,6 +68,7 @@ * If not set, use ${user.dir}/conf. * -DKL_LOG_FILE=a_file_name ; if set, creates a log file with that name within * KL_WORKING_DIR
+ * -DKL_LOG_TYPE=none|console|file(default)

*
* * @author Patrick G. Durand From 05627802973e25794837db9afdf6b1abbb8da483 Mon Sep 17 00:00:00 2001 From: Patrick Durand Date: Tue, 20 Dec 2022 11:52:42 +0100 Subject: [PATCH 02/26] add master class to run all BeeDeeM commands --- src/bzh/plealog/dbmirror/main/BeeDeeMain.java | 124 ++++++++++++++++++ .../dbmirror/ui/resources/messages.properties | 20 ++- 2 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 src/bzh/plealog/dbmirror/main/BeeDeeMain.java diff --git a/src/bzh/plealog/dbmirror/main/BeeDeeMain.java b/src/bzh/plealog/dbmirror/main/BeeDeeMain.java new file mode 100644 index 0000000..9e1730c --- /dev/null +++ b/src/bzh/plealog/dbmirror/main/BeeDeeMain.java @@ -0,0 +1,124 @@ +/* Copyright (C) 2022 Patrick G. Durand + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/agpl-3.0.txt + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + */ +package bzh.plealog.dbmirror.main; + +import java.util.Arrays; +import java.util.Properties; + +import bzh.plealog.dbmirror.ui.resources.DBMSMessages; + +/** + * This class starts BeeDeeM for all commands. + *

+ * In addition, some parameters can be passed to the JVM for special configuration purposes:
+ * -DKL_HOME=an_absolute_path ; the absolute path to the DBMS installation home dir. If not set, use user.dir java property. + * -DKL_DEBUG=true ; if true, if set, log will be in debug mode
+ * -DKL_WORKING_DIR=an_absolute_path ; if not set, log and working directories are set to java.io.tmp
+ * -DKL_CONF_DIR=an_absolute_path ; the absolute path to a home-made conf directory. If not set, use ${user.dir}/conf. + * -DKL_LOG_FILE=a_file_name ; if set, creates a log file with that name within KL_WORKING_DIR
+ * -DKL_LOG_TYPE=none|console|file(default)

+ * + * @author Patrick G. Durand + */ +public class BeeDeeMain { + + private static final String[] TOOL_LIST= { + "Annotate", + "DeleteBank", + "Dump", + "Install", + "Query", + "UiInstall"}; + + private static void dumpHelp() { + Properties props = StarterUtils.getVersionProperties(); + System.out.print(props.getProperty("prg.app.name")); + System.out.print(" "); + System.out.println(DBMSMessages.getString("Tool.Master.intro")); + for (String tName : TOOL_LIST) { + System.out.print(" bmd "); + System.out.print(DBMSMessages.getString("Tool."+tName+".cmd")); + if (tName.equals("UiInstall")) { + System.out.print(": "); + } + else { + System.out.print(" [options]: "); + } + System.out.println(DBMSMessages.getString("Tool."+tName+".desc")); + } + StringBuffer buf = new StringBuffer(); + System.out.println(DBMSMessages.getString("Tool.Master.more")); + buf.append("--\n"); + buf.append(props.getProperty("prg.app.name")); + buf.append(" "); + buf.append(props.getProperty("prg.version")); + buf.append(" - "); + buf.append(props.getProperty("prg.copyright")); + buf.append("\n"); + buf.append(props.getProperty("prg.license.short")); + buf.append("\n"); + buf.append(props.getProperty("prg.app.name")); + buf.append(" manual: "); + buf.append(props.getProperty("prg.man.url")); + System.out.println(buf.toString()); + } + + public static void main(String[] args) { + /* This code handles strings as "bdm xxx" + * "bdm" or "bdm.bat" is the caller script + * "xxx" can be either: + * - nothing, -h or --help: display help message + * - "ui": start UI Manager + * - everything else: try to run an existing command + */ + String cmd = "help"; + + if (args.length!=0) { + cmd = args[0]; + args = Arrays.copyOfRange(args, 1, args.length); + } + + switch(cmd) { + case "annotate": + Annotate.main(args); + break; + case "delete": + DeleteBank.main(args); + break; + case "help": + dumpHelp(); + break; + case "info": + DumpBankList.main(args); + break; + case "install": + CmdLineInstaller.main(args); + break; + case "query": + CmdLineQuery.main(args); + break; + case "ui": + UiInstaller.main(args); + break; + default: + System.err.print(DBMSMessages.getString("Tool.Master.err.cmd")); + System.err.print(": "); + System.err.println(cmd); + System.exit(1); + } + } +} diff --git a/src/bzh/plealog/dbmirror/ui/resources/messages.properties b/src/bzh/plealog/dbmirror/ui/resources/messages.properties index d80d15a..4769cc5 100755 --- a/src/bzh/plealog/dbmirror/ui/resources/messages.properties +++ b/src/bzh/plealog/dbmirror/ui/resources/messages.properties @@ -308,9 +308,15 @@ SequenceFileRenamerUI.id.prefix=Prefix\: SequenceFileRenamerUI.id.suffix=Suffix\: SequenceFileRenamerUI.subset.label=Number of subsets\: SequenceFileRenamerUI.subset.suffix=subsets -kdms.copy=Copyright (c) Patrick G. Durand / Ludovic Antin 2007-2017 +kdms.copy=Copyright (c) Patrick G. Durand / Ludovic Antin 2007-2022 + +Tool.Master.intro=commands are\: +Tool.Master.more=For more details on use, type: bdm -h +Tool.Master.err.cmd=Command unknown\: Tool.DeleteBank.name=DeleteBank +Tool.DeleteBank.cmd=delete +Tool.DeleteBank.desc=delete a bank Tool.DeleteBank.arg1.lbl=bank-code Tool.DeleteBank.arg1.desc=index code of the bank to delete. Such a code can be obtained using the 'info' tool (use 'code' format). Tool.DeleteBank.arg2.desc=display bank directory to be deleted WITHOUT deleting it! @@ -319,6 +325,8 @@ Tool.DeleteBank.err.msg1=Bank with code: {0}: not found Tool.DeleteBank.info.msg2=Bank: {0}: successfully deleted Tool.Annotate.name=Annotate +Tool.Annotate.cmd=annotate +Tool.Annotate.desc=annotate a BLAST XML formatted file Tool.Annotate.arg1.lbl=type Tool.Annotate.arg1.desc=type of annotation to retrieve. Options: bco or full. Mandatory. Tool.Annotate.arg2.lbl=Blast file @@ -331,6 +339,8 @@ Tool.Annotate.arg5.lbl=include Tool.Annotate.arg5.desc=include Biological Classification data. Use true or false. Default is false. Tool.Query.name=Query +Tool.Query.cmd=query +Tool.Query.desc=query repository to fetch entry(ies) given ID(s) Tool.Query.arg1.lbl=repository Tool.Query.arg1.desc=type of repository to query. Mandatory. One of: nucleotide, protein, dico. When using dico, use one of: dico:taxon, dico:EC, dico:GO, dico:CDD or dico:InterPro. When using dico:taxon, entry ID can be either a TaxID or a Taxonomy Name (e.g. organism, phylum, etc.). In latter case, Query Tool will dump Taxonomy path. Tool.Query.arg2.lbl=entryID @@ -341,6 +351,8 @@ Tool.Query.arg4.lbl=output Tool.Query.arg4.desc=output file to save results of query. Optional, default is stdout. Tool.Dump.name=DumpBankList +Tool.Dump.cmd=info +Tool.Dump.desc=list of installed banks Tool.Dump.arg1.lbl=repository Tool.Dump.arg1.desc=type of repository. One of: n, p, b, all. Default is: all. Tool.Dump.arg2.lbl=format @@ -354,7 +366,13 @@ Tool.Utils.arg1.lbl=directory Tool.Utils.arg1.desc=absolute path to custom conf directory Tool.Utils.info.msg1=print this message +Tool.UiInstall.name=UiInstall +Tool.UiInstall.cmd=ui +Tool.UiInstall.desc=start graphical bank manager interface + Tool.Install.name=Install +Tool.Install.cmd=install +Tool.Install.desc=install bank(s) Tool.Install.arg1.desc=absolute path to custom conf directory Tool.Install.arg2.lbl=descriptor Tool.Install.arg2.desc=comma separated list of descriptor (.dsc) names From 23c92535e157cb1144c8340d8a6e375bc8393eff Mon Sep 17 00:00:00 2001 From: Patrick Durand Date: Tue, 20 Dec 2022 11:53:36 +0100 Subject: [PATCH 03/26] update installers to deploy new BeeDeeM master program: bdm --- conda/build.sh | 8 ++++---- conda/run_test.sh | 2 +- docker/Dockerfile | 4 ++-- singularity/Singularity | 8 ++++---- singularity/test_container.sh | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/conda/build.sh b/conda/build.sh index ceb1296..adfbe77 100755 --- a/conda/build.sh +++ b/conda/build.sh @@ -11,16 +11,16 @@ cp -R ${SRC_DIR}/external $PREFIX cp -R ${SRC_DIR}/license $PREFIX # Copy BeeDeeM scripts and update them with default config -cp ${SRC_DIR}/scripts/*.sh $PREFIX/bin -sed -i 's/@KL_WORKING_DIR@/\/beedeem-wk/g' $PREFIX/bin/*.sh -sed -i 's/@JAVA_ARGS@/-Xms128M -Xmx2048M -Djava.io.tmpdir=\$KL_WORKING_DIR -DKL_LOG_TYPE=console/g' $PREFIX/bin/*.sh +cp ${SRC_DIR}/scripts/bdm.sh $PREFIX/bin/bdm +sed -i 's/@KL_WORKING_DIR@/\/beedeem-wk/g' $PREFIX/bin/bdm +sed -i 's/@JAVA_ARGS@/-Xms128M -Xmx4G -Djava.io.tmpdir=\$KL_WORKING_DIR -DKL_LOG_TYPE=console/g' $PREFIX/bin/bdm # Copy the BeeDeeM master configuration file and update it cp ${SRC_DIR}/scripts/dbms.config $PREFIX/conf sed -i 's/@BIOBASE_ROOTDIR@/\/beedeem-db/g' $PREFIX/conf/dbms.config # Ensure executables have valid exec permission -chmod +x $PREFIX/bin/*.sh +chmod +x $PREFIX/bin/bdm chmod +x $PREFIX/external/bin/linux/* chmod +x $PREFIX/external/bin/macos/* chmod +x $PREFIX/conf/scripts/*.sh diff --git a/conda/run_test.sh b/conda/run_test.sh index 0bc75ed..ae538b2 100755 --- a/conda/run_test.sh +++ b/conda/run_test.sh @@ -17,7 +17,7 @@ mkdir -p $KL_WORKING_DIR # path DESC_LIST="PDB_proteins,SwissProt_human" # Start installation -install.sh -desc $DESC_LIST +bdm install -desc $DESC_LIST # Note: by design of this script, we DO NOT delete # $KL_WORKING_DIR... please, do it yourself. diff --git a/docker/Dockerfile b/docker/Dockerfile index 1db789f..4c2f7f1 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -47,10 +47,10 @@ RUN \ RUN \ cd /opt/beedeem && \ - cp scripts/*.sh . && \ + cp scripts/bdm.sh ./bdm && \ cp scripts/dbms.config conf && \ sed -i 's/@BIOBASE_ROOTDIR@/\/beedeem-db/g' conf/dbms.config && \ - chmod +x *.sh && \ + chmod +x bdm && \ chmod +x /opt/beedeem/external/bin/linux/* && \ chmod +x /opt/beedeem/conf/scripts/*.sh && \ cd /opt/beedeem/external/bin && rm -rf macos windows diff --git a/singularity/Singularity b/singularity/Singularity index 1cb8910..1fd7314 100644 --- a/singularity/Singularity +++ b/singularity/Singularity @@ -42,12 +42,12 @@ From: ubuntu:18.04 rm -rf tmp-install # Do a little configuration - cp scripts/*.sh . - sed -i 's/@KL_WORKING_DIR@/\/beedeem-wk/g' *.sh - sed -i 's/@JAVA_ARGS@/-Xms128M -Xmx2048M -Djava.io.tmpdir=\$KL_WORKING_DIR -DKL_LOG_TYPE=console/g' *.sh + cp scripts/bdm.sh ./bdm + sed -i 's/@KL_WORKING_DIR@/\/beedeem-wk/g' bdm + sed -i 's/@JAVA_ARGS@/-Xms128M -Xmx2048M -Djava.io.tmpdir=\$KL_WORKING_DIR -DKL_LOG_TYPE=console/g' bdm cp scripts/dbms.config conf sed -i 's/@BIOBASE_ROOTDIR@/\/beedeem-db/g' conf/dbms.config - chmod +x *.sh + chmod +x bdm chmod +x /opt/beedeem/external/bin/linux/* chmod +x /opt/beedeem/conf/scripts/*.sh cd /opt/beedeem/external/bin && rm -rf macos windows diff --git a/singularity/test_container.sh b/singularity/test_container.sh index e900c7b..2bc72b6 100755 --- a/singularity/test_container.sh +++ b/singularity/test_container.sh @@ -9,7 +9,7 @@ # b. qsub test_container.sh (PBS Pro) # c. srun test_container.sh (slurm, direct execution) # -# P. Durand (SeBiMER, Ifremer), last update on Nov 2022 +# P. Durand (SeBiMER, Ifremer), last update on Dec 2022 # Sample config for Slurm; adapt partition to your cluster configuration #SBATCH -p fast @@ -140,7 +140,7 @@ echo "tail -f $BDM_WORK_DIR/log" singularity run \ ${BDM_BINDS} \ ${BDM_SINGULITY_IMG} \ - install.sh -desc ${DESCRIPTOR} >& ${BDM_WORK_DIR}/log 2>&1 + bdm install -desc ${DESCRIPTOR} >& ${BDM_WORK_DIR}/log 2>&1 if [ $? -eq 0 ]; then echo "SUCCESS" From 2c44ec9ef31a04db39064f5c6894cc813f1cb9ad Mon Sep 17 00:00:00 2001 From: Patrick Durand Date: Tue, 20 Dec 2022 11:55:12 +0100 Subject: [PATCH 04/26] replace all BeeDeeM commands by a single one: bdm --- scripts/UiInstall.bat | 45 ---------------------- scripts/UiInstall.sh | 62 ------------------------------- scripts/annotate.bat | 41 -------------------- scripts/annotate.sh | 60 ------------------------------ scripts/{install.bat => bdm.bat} | 13 +++++-- scripts/{install.sh => bdm.sh} | 11 ++++-- scripts/check.bat | 37 ------------------ scripts/check.sh | 62 ------------------------------- scripts/delete.bat | 38 ------------------- scripts/delete.sh | 61 ------------------------------ scripts/info.bat | 46 ----------------------- scripts/info.sh | 62 ------------------------------- scripts/install-std.txt | 64 -------------------------------- scripts/query.bat | 45 ---------------------- scripts/query.sh | 62 ------------------------------- 15 files changed, 17 insertions(+), 692 deletions(-) delete mode 100755 scripts/UiInstall.bat delete mode 100755 scripts/UiInstall.sh delete mode 100755 scripts/annotate.bat delete mode 100755 scripts/annotate.sh rename scripts/{install.bat => bdm.bat} (80%) rename scripts/{install.sh => bdm.sh} (87%) delete mode 100755 scripts/check.bat delete mode 100755 scripts/check.sh delete mode 100755 scripts/delete.bat delete mode 100755 scripts/delete.sh delete mode 100755 scripts/info.bat delete mode 100755 scripts/info.sh delete mode 100755 scripts/install-std.txt delete mode 100755 scripts/query.bat delete mode 100755 scripts/query.sh diff --git a/scripts/UiInstall.bat b/scripts/UiInstall.bat deleted file mode 100755 index a6ac031..0000000 --- a/scripts/UiInstall.bat +++ /dev/null @@ -1,45 +0,0 @@ -@echo off - -rem -rem DBMS program to install databanks using the graphical interface ; for Windows -rem Copyright (c) - Patrick G. Durand, 2007-2017 -rem ------------------------------------------------------------------- -rem User manual: -rem https://pgdurand.gitbooks.io/beedeem/ -rem ------------------------------------------------------------------- -rem The program can be used to install some databanks interactively. -rem -rem In addition, some parameters can be passed to the JVM for special -rem configuration purposes: -rem -DKL_DEBUG=true ; if true, if set, log will be in debug mode -rem -DKL_WORKING_DIR=an_absolute_path ; if not set, log and working -rem directories are set to java.io.tmp -rem -DKL_LOG_FILE=a_file_name ; if set, creates a log file with that -rem name within KL_WORKING_DIR -rem -DKL_CONF_DIR=an_absolute_path ; the absolute path to a home-made -rem conf directory. If not set, use ${user.dir}/conf. - -set CUR_DIR=%cd% - -rem *** Application home -set KL_APP_HOME=@KL_INSTALL_DIR@ - -rem *** Working directory -set KL_WORKING_DIR=@KL_WORKING_DIR@ - -rem *** Java VM -set KL_JAVA_ARGS=-Xms128M -Xmx1024M -DKL_HOME="%KL_APP_HOME%" -DKL_WORKING_DIR="%KL_WORKING_DIR%" - -rem *** Create classpath -SETLOCAL ENABLEDELAYEDEXPANSION -set FILES= -set BIN_HOME=%KL_APP_HOME%\\bin -cd %BIN_HOME% -for /F %%f in ('dir /b *.jar') do set FILES=!FILES!;%KL_APP_HOME%\\bin\\%%f - -rem *** Start application -cd %CUR_DIR% -java.exe %KL_JAVA_ARGS% -classpath "%FILES%" bzh.plealog.dbmirror.main.UiInstaller - -rem *** do not leave immediately (to check potential cmd line messages coming from the application) -pause diff --git a/scripts/UiInstall.sh b/scripts/UiInstall.sh deleted file mode 100755 index 6c00cdb..0000000 --- a/scripts/UiInstall.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env bash -# -# -# DBMS program to install databanks using the graphical interface ; for Unix -# Copyright (c) - Patrick G. Durand, 2007-2022 -# ------------------------------------------------------------------- -# User manual: -# https://pgdurand.gitbooks.io/beedeem/ -# ------------------------------------------------------------------- -# The program can be used to install some databanks interactively. -# -# In addition, some parameters can be passed to the JVM for special -# configuration purposes:
-# -DKL_DEBUG=true ; if true, if set, log will be in debug mode
-# -DKL_WORKING_DIR=an_absolute_path ; if not set, log and working -# directories are set to java.io.tmp
-# -DKL_LOG_FILE=a_file_name ; if set, creates a log file with that -# name within KL_WORKING_DIR

-# -DKL_CONF_DIR=an_absolute_path ; the absolute path to a home-made -# conf directory. If not set, use ${user.dir}/conf. -# -# KL_WORKING_DIR, KL_CONF_DIR and KL_LOG_FILE can be defined using -# env variables before calling this script. Additional JRE arguments -# can also be passed in to this script using env variable KL_JRE_ARGS. -# -# Proxy configuration: update configuration file: ${beedeemHome}/conf/system/network.config. - -# *** Application home -KL_APP_HOME=$( cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P ) -# For Conda installation, scripts are in the bin directory, so get correct home -[[ "$KL_APP_HOME" == *bin ]] && KL_APP_HOME=$(dirname "$KL_APP_HOME") - -# *** Working directory -if [ ! "$KL_WORKING_DIR" ]; then - KL_WORKING_DIR=@KL_WORKING_DIR@ -fi - -# *** Configuration directory -if [ ! "$KL_CONF_DIR" ]; then - KL_CONF_DIR=$KL_APP_HOME/conf -fi - -# *** Optional JRE arguments -if [ ! "$KL_JRE_ARGS" ]; then - KL_JRE_ARGS="@JAVA_ARGS@" -fi - -# *** Java VM -KL_JAVA_ARGS="$KL_JRE_ARGS -DKL_HOME=$KL_APP_HOME -DKL_WORKING_DIR=$KL_WORKING_DIR -DKL_CONF_DIR=$KL_CONF_DIR" - -# *** Optional redefinition of log file -if [ ! -z "$KL_LOG_FILE" ]; then - KL_JAVA_ARGS+=" -DKL_LOG_FILE=$KL_LOG_FILE" -fi - -# *** JARs section -KL_JAR_LIST_TMP=`\ls $KL_APP_HOME/bin/*.jar` -KL_JAR_LIST=`echo $KL_JAR_LIST_TMP | sed 's/ /:/g'` - -# *** start application -KL_APP_MAIN_CLASS=bzh.plealog.dbmirror.main.UiInstaller -java $KL_JAVA_ARGS -classpath $KL_JAR_LIST $KL_APP_MAIN_CLASS diff --git a/scripts/annotate.bat b/scripts/annotate.bat deleted file mode 100755 index 1fe7283..0000000 --- a/scripts/annotate.bat +++ /dev/null @@ -1,41 +0,0 @@ -@echo off - -rem DBMS program to annotate Blast results ; for Mac/Linux -rem Copyright (c) - Patrick G. Durand, 2007-2017 -rem ------------------------------------------------------------------- -rem User manual: -rem https://pgdurand.gitbooks.io/beedeem/ -rem ------------------------------------------------------------------- -rem In addition, some parameters can be passed to the JVM for special -rem configuration purposes: -rem -DKL_DEBUG=true ; if true, if set, log will be in debug mode -rem -DKL_WORKING_DIR=an_absolute_path ; if not set, log and working -rem directories are set to java.io.tmp -rem -DKL_LOG_FILE=a_file_name ; if set, creates a log file with that -rem name within KL_WORKING_DIR -rem -DKL_CONF_DIR=an_absolute_path ; the absolute path to a home-made -rem conf directory. If not set, use ${user.dir}/conf. -rem -DKL_LOG_TYPE=none|console|file(default) - -set CUR_DIR=%cd% - -rem *** Application home -set KL_APP_HOME=@KL_INSTALL_DIR@ - -rem *** Working directory -set KL_WORKING_DIR=@KL_WORKING_DIR@ - -rem *** Java VM -set KL_JAVA_ARGS=-Xms128M -Xmx1024M -DKL_HOME="%KL_APP_HOME%" -DKL_WORKING_DIR="%KL_WORKING_DIR%" - -rem *** Create classpath -SETLOCAL ENABLEDELAYEDEXPANSION -set FILES= -set BIN_HOME=%KL_APP_HOME%\\bin -cd %BIN_HOME% -for /F %%f in ('dir /b *.jar') do set FILES=!FILES!;%KL_APP_HOME%\\bin\\%%f - -rem *** Start application -cd %CUR_DIR% -java.exe %KL_JAVA_ARGS% -classpath "%FILES%" bzh.plealog.dbmirror.main.Annotate %* - diff --git a/scripts/annotate.sh b/scripts/annotate.sh deleted file mode 100755 index 83cdb2b..0000000 --- a/scripts/annotate.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env bash -# -# DBMS program to annotate Blast results ; for Mac/Linux -# Copyright (c) - Patrick G. Durand, 2007-2022 -# ------------------------------------------------------------------- -# User manual: -# https://pgdurand.gitbooks.io/beedeem/ -# ------------------------------------------------------------------- -# In addition, some parameters can be passed to the JVM for special -# configuration purposes: -# -DKL_DEBUG=true ; if true, if set, log will be in debug mode -# -DKL_WORKING_DIR=an_absolute_path ; if not set, log and working -# directories are set to java.io.tmp -# -DKL_LOG_FILE=a_file_name ; if set, creates a log file with that -# name within KL_WORKING_DIR -# -DKL_CONF_DIR=an_absolute_path ; the absolute path to a home-made -# conf directory. If not set, use ${user.dir}/conf. -# -DKL_LOG_TYPE=none|console|file(default) -# -# KL_WORKING_DIR, KL_CONF_DIR and KL_LOG_FILE can be defined using -# env variables before calling this script. Additional JRE arguments -# can also be passed in to this script using env variable KL_JRE_ARGS. -# - -# *** Application home -KL_APP_HOME=$( cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P ) -# For Conda installation, scripts are in the bin directory, so get correct home -[[ "$KL_APP_HOME" == *bin ]] && KL_APP_HOME=$(dirname "$KL_APP_HOME") - -# *** Working directory -if [ ! "$KL_WORKING_DIR" ]; then - KL_WORKING_DIR=@KL_WORKING_DIR@ -fi - -# *** Configuration directory -if [ ! "$KL_CONF_DIR" ]; then - KL_CONF_DIR=$KL_APP_HOME/conf -fi - -# *** Optional JRE arguments -if [ ! "$KL_JRE_ARGS" ]; then - KL_JRE_ARGS="@JAVA_ARGS@" -fi - -# *** Java VM -KL_JAVA_ARGS="$KL_JRE_ARGS -DKL_HOME=$KL_APP_HOME -DKL_WORKING_DIR=$KL_WORKING_DIR -DKL_CONF_DIR=$KL_CONF_DIR" - -# *** Optional redefinition of log file -if [ ! -z "$KL_LOG_FILE" ]; then - KL_JAVA_ARGS+=" -DKL_LOG_FILE=$KL_LOG_FILE" -fi - -# *** JARs section -KL_JAR_LIST_TMP=`\ls $KL_APP_HOME/bin/*.jar` -KL_JAR_LIST=`echo $KL_JAR_LIST_TMP | sed 's/ /:/g'` - -# *** start application -KL_APP_MAIN_CLASS=bzh.plealog.dbmirror.main.Annotate -java $KL_JAVA_ARGS -classpath $KL_JAR_LIST $KL_APP_MAIN_CLASS $@ - diff --git a/scripts/install.bat b/scripts/bdm.bat similarity index 80% rename from scripts/install.bat rename to scripts/bdm.bat index 7423659..4497b95 100755 --- a/scripts/install.bat +++ b/scripts/bdm.bat @@ -1,12 +1,16 @@ @echo off rem -rem DBMS program to install databanks ; for Mac/Linux -rem Copyright (c) - Patrick G. Durand, 2007-2017 +rem BeeDeeM starter command for Windows +rem Copyright (c) - Patrick G. Durand, 2007-2022 rem ------------------------------------------------------------------- rem User manual: rem https://pgdurand.gitbooks.io/beedeem/ rem ------------------------------------------------------------------- +rem Command use: +rem bdm.bat -h: to get help +rem bdm.bat [options]: to start a command +rem rem In addition, some parameters can be passed to the JVM for special rem configuration purposes:
rem -DKL_DEBUG=true ; if true, if set, log will be in debug mode
@@ -18,7 +22,8 @@ rem -DKL_CONF_DIR=an_absolute_path ; the absolute path to a home-made rem conf directory. If not set, use ${user.dir}/conf. rem -DKL_LOG_TYPE=none|console|file(default) rem -rem Proxy configuration: update configuration file: ${beedeemHome}/conf/system/network.config. +rem Proxy configuration: update configuration file: +rem ${beedeemHome}/conf/system/network.config. rem *** Application home set KL_APP_HOME=@KL_INSTALL_DIR@ @@ -35,4 +40,4 @@ set FILES= for /F %%f in ('dir /b %KL_APP_HOME%\bin\*.jar') do set FILES=!FILES!;%KL_APP_HOME%\bin\%%f rem *** Start application -java.exe %KL_JAVA_ARGS% -classpath "%FILES%" bzh.plealog.dbmirror.main.CmdLineInstaller %* +java.exe %KL_JAVA_ARGS% -classpath "%FILES%" bzh.plealog.dbmirror.main.BeeDeeMain %* diff --git a/scripts/install.sh b/scripts/bdm.sh similarity index 87% rename from scripts/install.sh rename to scripts/bdm.sh index 5c15c27..a01eed2 100755 --- a/scripts/install.sh +++ b/scripts/bdm.sh @@ -1,12 +1,16 @@ #!/usr/bin/env bash # # ------------------------------------------------------------------- -# DBMS program to install databanks ; for Mac/Linux +# BeeDeeM starter command for macOS/Linux # Copyright (c) - Patrick G. Durand, 2007-2022 # ------------------------------------------------------------------- # User manual: # https://pgdurand.gitbooks.io/beedeem/ # ------------------------------------------------------------------- +# Command use: +# bdm -h: to get help +# bdm [options]: to start a command +# # In addition, some parameters can be passed to the JVM for special # configuration purposes:
# -DKL_DEBUG=true ; if true, if set, log will be in debug mode
@@ -22,7 +26,8 @@ # env variables before calling this script. Additional JRE arguments # can also be passed in to this script using env variable KL_JRE_ARGS. # -# Proxy configuration: update configuration file: ${beedeemHome}/conf/system/network.config. +# Proxy configuration: update configuration file: +# ${beedeemHome}/conf/system/network.config. # *** Application home KL_APP_HOME=$( cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P ) @@ -57,6 +62,6 @@ KL_JAR_LIST_TMP=`\ls $KL_APP_HOME/bin/*.jar` KL_JAR_LIST=`echo $KL_JAR_LIST_TMP | sed 's/ /:/g'` # *** start application -KL_APP_MAIN_CLASS=bzh.plealog.dbmirror.main.CmdLineInstaller +KL_APP_MAIN_CLASS=bzh.plealog.dbmirror.main.BeeDeeMain java $KL_JAVA_ARGS -classpath $KL_JAR_LIST $KL_APP_MAIN_CLASS $@ diff --git a/scripts/check.bat b/scripts/check.bat deleted file mode 100755 index 03377fe..0000000 --- a/scripts/check.bat +++ /dev/null @@ -1,37 +0,0 @@ -@echo off - -rem -rem ------------------------------------------------------------------- -rem DBMS program to check DB descriptors ; for Windows -rem Copyright (c) - Patrick G. Durand, 2017 -rem ------------------------------------------------------------------- -rem User manual: -rem https://pgdurand.gitbooks.io/beedeem/ -rem ------------------------------------------------------------------- -rem In addition, some parameters can be passed to the JVM for special -rem configuration purposes:
-rem -DKL_DEBUG=true ; if true, if set, log will be in debug mode
-rem -DKL_WORKING_DIR=an_absolute_path ; if not set, log and working -rem directories are set to java.io.tmp
-rem -DKL_LOG_FILE=a_file_name ; if set, creates a log file with that -rem name within KL_WORKING_DIR

-rem -DKL_CONF_DIR=an_absolute_path ; the absolute path to a home-made -rem conf directory. If not set, use ${user.dir}/conf. -rem - -rem *** Application home -set KL_APP_HOME=@KL_INSTALL_DIR@ - -rem *** Working directory -set KL_WORKING_DIR=@KL_WORKING_DIR@ - -rem *** Java VM -set KL_JAVA_ARGS=-Xms128M -Xmx1024M -DKL_HOME="%KL_APP_HOME%" -DKL_WORKING_DIR="%KL_WORKING_DIR%" - -rem *** Create classpath -SETLOCAL ENABLEDELAYEDEXPANSION -set FILES= -for /F %%f in ('dir /b %KL_APP_HOME%\bin\*.jar') do set FILES=!FILES!;%KL_APP_HOME%\bin\%%f - -rem *** Start application -java.exe %KL_JAVA_ARGS% -classpath "%FILES%" bzh.plealog.dbmirror.main.AutoCheckDescriptors %* diff --git a/scripts/check.sh b/scripts/check.sh deleted file mode 100755 index 1ec4ce3..0000000 --- a/scripts/check.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env bash -# -# ------------------------------------------------------------------- -# DBMS program to check DB descriptors ; for Mac/Linux -# Copyright (c) - Patrick G. Durand, 2017-2022 -# ------------------------------------------------------------------- -# User manual: -# https://pgdurand.gitbooks.io/beedeem/ -# ------------------------------------------------------------------- -# -# In addition, some parameters can be passed to the JVM for special -# configuration purposes:
-# -DKL_DEBUG=true ; if true, if set, log will be in debug mode
-# -DKL_WORKING_DIR=an_absolute_path ; if not set, log and working -# directories are set to java.io.tmp
-# -DKL_LOG_FILE=a_file_name ; if set, creates a log file with that -# name within KL_WORKING_DIR

-# -DKL_CONF_DIR=an_absolute_path ; the absolute path to a home-made -# conf directory. If not set, use ${user.dir}/conf. -# -DKL_LOG_TYPE=none|console|file(default) -# -# KL_WORKING_DIR, KL_CONF_DIR and KL_LOG_FILE can be defined using -# env variables before calling this script. Additional JRE arguments -# can also be passed in to this script using env variable KL_JRE_ARGS. -# - -# *** Application home -KL_APP_HOME=$( cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P ) -# For Conda installation, scripts are in the bin directory, so get correct home -[[ "$KL_APP_HOME" == *bin ]] && KL_APP_HOME=$(dirname "$KL_APP_HOME") - -# *** Working directory -if [ ! "$KL_WORKING_DIR" ]; then - KL_WORKING_DIR=@KL_WORKING_DIR@ -fi - -# *** Configuration directory -if [ ! "$KL_CONF_DIR" ]; then - KL_CONF_DIR=$KL_APP_HOME/conf -fi - -# *** Optional JRE arguments -if [ ! "$KL_JRE_ARGS" ]; then - KL_JRE_ARGS="@JAVA_ARGS@" -fi - -# *** Java VM -KL_JAVA_ARGS="$KL_JRE_ARGS -DKL_HOME=$KL_APP_HOME -DKL_WORKING_DIR=$KL_WORKING_DIR -DKL_CONF_DIR=$KL_CONF_DIR" - -# *** Optional redefinition of log file -if [ ! -z "$KL_LOG_FILE" ]; then - KL_JAVA_ARGS+=" -DKL_LOG_FILE=$KL_LOG_FILE" -fi - -# *** JARs section -KL_JAR_LIST_TMP=`\ls $KL_APP_HOME/bin/*.jar` -KL_JAR_LIST=`echo $KL_JAR_LIST_TMP | sed 's/ /:/g'` - -# *** start application -KL_APP_MAIN_CLASS=bzh.plealog.dbmirror.main.AutoCheckDescriptors -java $KL_JAVA_ARGS -classpath $KL_JAR_LIST $KL_APP_MAIN_CLASS $@ - diff --git a/scripts/delete.bat b/scripts/delete.bat deleted file mode 100755 index bdb18c6..0000000 --- a/scripts/delete.bat +++ /dev/null @@ -1,38 +0,0 @@ -@echo off - -rem -rem ------------------------------------------------------------------- -rem DBMS program to delete databanks ; for Windows -rem Copyright (c) - Patrick G. Durand, 2017 -rem ------------------------------------------------------------------- -rem User manual: -rem https://pgdurand.gitbooks.io/beedeem/ -rem ------------------------------------------------------------------- -rem In addition, some parameters can be passed to the JVM for special -rem configuration purposes:
-rem -DKL_DEBUG=true ; if true, if set, log will be in debug mode
-rem -DKL_WORKING_DIR=an_absolute_path ; if not set, log and working -rem directories are set to java.io.tmp
-rem -DKL_LOG_FILE=a_file_name ; if set, creates a log file with that -rem name within KL_WORKING_DIR

-rem -DKL_CONF_DIR=an_absolute_path ; the absolute path to a home-made -rem conf directory. If not set, use ${user.dir}/conf. -rem -DKL_LOG_TYPE=none|console|file(default) -rem - -rem *** Application home -set KL_APP_HOME=@KL_INSTALL_DIR@ - -rem *** Working directory -set KL_WORKING_DIR=@KL_WORKING_DIR@ - -rem *** Java VM -set KL_JAVA_ARGS=-Xms128M -Xmx1024M -DKL_HOME="%KL_APP_HOME%" -DKL_WORKING_DIR="%KL_WORKING_DIR%" - -rem *** Create classpath -SETLOCAL ENABLEDELAYEDEXPANSION -set FILES= -for /F %%f in ('dir /b %KL_APP_HOME%\bin\*.jar') do set FILES=!FILES!;%KL_APP_HOME%\bin\%%f - -rem *** Start application -java.exe %KL_JAVA_ARGS% -classpath "%FILES%" bzh.plealog.dbmirror.main.DeleteBank %* diff --git a/scripts/delete.sh b/scripts/delete.sh deleted file mode 100755 index 4d09925..0000000 --- a/scripts/delete.sh +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env bash -# -# ------------------------------------------------------------------- -# DBMS program to delete databanks ; for Mac/Linux -# Copyright (c) - Patrick G. Durand, 2017-2022 -# ------------------------------------------------------------------- -# User manual: -# https://pgdurand.gitbooks.io/beedeem/ -# ------------------------------------------------------------------- -# In addition, some parameters can be passed to the JVM for special -# configuration purposes:
-# -DKL_DEBUG=true ; if true, if set, log will be in debug mode
-# -DKL_WORKING_DIR=an_absolute_path ; if not set, log and working -# directories are set to java.io.tmp
-# -DKL_LOG_FILE=a_file_name ; if set, creates a log file with that -# name within KL_WORKING_DIR

-# -DKL_CONF_DIR=an_absolute_path ; the absolute path to a home-made -# conf directory. If not set, use ${user.dir}/conf. -# -DKL_LOG_TYPE=none|console|file(default) -# -# KL_WORKING_DIR, KL_CONF_DIR and KL_LOG_FILE can be defined using -# env variables before calling this script. Additional JRE arguments -# can also be passed in to this script using env variable KL_JRE_ARGS. -# - -# *** Application home -KL_APP_HOME=$( cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P ) -# For Conda installation, scripts are in the bin directory, so get correct home -[[ "$KL_APP_HOME" == *bin ]] && KL_APP_HOME=$(dirname "$KL_APP_HOME") - -# *** Working directory -if [ ! "$KL_WORKING_DIR" ]; then - KL_WORKING_DIR=@KL_WORKING_DIR@ -fi - -# *** Configuration directory -if [ ! "$KL_CONF_DIR" ]; then - KL_CONF_DIR=$KL_APP_HOME/conf -fi - -# *** Optional JRE arguments -if [ ! "$KL_JRE_ARGS" ]; then - KL_JRE_ARGS="@JAVA_ARGS@" -fi - -# *** Java VM -KL_JAVA_ARGS="$KL_JRE_ARGS -DKL_HOME=$KL_APP_HOME -DKL_WORKING_DIR=$KL_WORKING_DIR -DKL_CONF_DIR=$KL_CONF_DIR" - -# *** Optional redefinition of log file -if [ ! -z "$KL_LOG_FILE" ]; then - KL_JAVA_ARGS+=" -DKL_LOG_FILE=$KL_LOG_FILE" -fi - -# *** JARs section -KL_JAR_LIST_TMP=`\ls $KL_APP_HOME/bin/*.jar` -KL_JAR_LIST=`echo $KL_JAR_LIST_TMP | sed 's/ /:/g'` - -# *** start application -KL_APP_MAIN_CLASS=bzh.plealog.dbmirror.main.DeleteBank -java $KL_JAVA_ARGS -classpath $KL_JAR_LIST $KL_APP_MAIN_CLASS $@ - diff --git a/scripts/info.bat b/scripts/info.bat deleted file mode 100755 index 596a8a6..0000000 --- a/scripts/info.bat +++ /dev/null @@ -1,46 +0,0 @@ -@echo off - -rem -rem DBMS program to list installed banks ; for Windows -rem Copyright (c) - Patrick G. Durand, 2007-2017 -rem ------------------------------------------------------------------- -rem User manual: -rem https://pgdurand.gitbooks.io/beedeem/ -rem ------------------------------------------------------------------- -rem The program can be used to list installed banks. -rem -rem In addition, some parameters can be passed to the JVM for special -rem configuration purposes: -rem -DKL_DEBUG=true ; if true, if set, log will be in debug mode -rem -DKL_WORKING_DIR=an_absolute_path ; if not set, log and working -rem directories are set to java.io.tmp -rem -DKL_LOG_FILE=a_file_name ; if set, creates a log file with that -rem name within KL_WORKING_DIR -rem -DKL_CONF_DIR=an_absolute_path ; the absolute path to a home-made -rem conf directory. If not set, use ${user.dir}/conf. -rem -DKL_LOG_TYPE=none|console|file(default) - -set CUR_DIR=%cd% - -rem *** Application home -set KL_APP_HOME=@KL_INSTALL_DIR@ - -rem *** Working directory -set KL_WORKING_DIR=@KL_WORKING_DIR@ - -rem *** Java VM -set KL_JAVA_ARGS=-Xms128M -Xmx1024M -DKL_HOME="%KL_APP_HOME%" -DKL_WORKING_DIR="%KL_WORKING_DIR%" - -rem *** Create classpath -SETLOCAL ENABLEDELAYEDEXPANSION -set FILES= -set BIN_HOME=%KL_APP_HOME%\\bin -cd %BIN_HOME% -for /F %%f in ('dir /b *.jar') do set FILES=!FILES!;%KL_APP_HOME%\\bin\\%%f - -rem *** Start application -cd %CUR_DIR% -java.exe %KL_JAVA_ARGS% -classpath "%FILES%" bzh.plealog.dbmirror.main.DumpBankList %* - -rem *** do not leave immediately (to check potential cmd line messages coming from the application) -pause diff --git a/scripts/info.sh b/scripts/info.sh deleted file mode 100755 index 1ca3b52..0000000 --- a/scripts/info.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env bash -# -# -# DBMS program to list installed banks ; for Unix -# Copyright (c) - Patrick G. Durand, 2007-2022 -# ------------------------------------------------------------------- -# User manual: -# https://pgdurand.gitbooks.io/beedeem/ -# ------------------------------------------------------------------- -# The program can be used to list installed banks. -# -# In addition, some parameters can be passed to the JVM for special -# configuration purposes:
-# -DKL_DEBUG=true ; if true, if set, log will be in debug mode
-# -DKL_WORKING_DIR=an_absolute_path ; if not set, log and working -# directories are set to java.io.tmp
-# -DKL_LOG_FILE=a_file_name ; if set, creates a log file with that -# name within KL_WORKING_DIR

-# -DKL_CONF_DIR=an_absolute_path ; the absolute path to a home-made -# conf directory. If not set, use ${user.dir}/conf. -# -DKL_LOG_TYPE=none|console|file(default) -# -# KL_WORKING_DIR, KL_CONF_DIR and KL_LOG_FILE can be defined using -# env variables before calling this script. Additional JRE arguments -# can also be passed in to this script using env variable KL_JRE_ARGS. -# - -# *** Application home -KL_APP_HOME=$( cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P ) -# For Conda installation, scripts are in the bin directory, so get correct home -[[ "$KL_APP_HOME" == *bin ]] && KL_APP_HOME=$(dirname "$KL_APP_HOME") - -# *** Working directory -if [ ! "$KL_WORKING_DIR" ]; then - KL_WORKING_DIR=@KL_WORKING_DIR@ -fi - -# *** Configuration directory -if [ ! "$KL_CONF_DIR" ]; then - KL_CONF_DIR=$KL_APP_HOME/conf -fi - -# *** Optional JRE arguments -if [ ! "$KL_JRE_ARGS" ]; then - KL_JRE_ARGS="@JAVA_ARGS@" -fi - -# *** Java VM -KL_JAVA_ARGS="$KL_JRE_ARGS -DKL_HOME=$KL_APP_HOME -DKL_WORKING_DIR=$KL_WORKING_DIR -DKL_CONF_DIR=$KL_CONF_DIR" - -# *** Optional redefinition of log file -if [ ! -z "$KL_LOG_FILE" ]; then - KL_JAVA_ARGS+=" -DKL_LOG_FILE=$KL_LOG_FILE" -fi - -# *** JARs section -KL_JAR_LIST_TMP=`\ls $KL_APP_HOME/bin/*.jar` -KL_JAR_LIST=`echo $KL_JAR_LIST_TMP | sed 's/ /:/g'` - -# *** start application -KL_APP_MAIN_CLASS=bzh.plealog.dbmirror.main.DumpBankList -java $KL_JAVA_ARGS -classpath $KL_JAR_LIST $KL_APP_MAIN_CLASS $@ diff --git a/scripts/install-std.txt b/scripts/install-std.txt deleted file mode 100755 index d07d601..0000000 --- a/scripts/install-std.txt +++ /dev/null @@ -1,64 +0,0 @@ -BeeDeeM Command-line installer ------------------------------- - -This procedure is also available here: - -https://pgdurand.gitbooks.io/beedeem/ - - -Step 1 - check your system --------------------------- - - To install BeeDeeM you need: - - 1. the Java Runtime from Oracle, release 1.7 or above ; - 2. the Ant system from Apache Foundation, release 1.6 or above - - To check whether or not these dependencies are available on your - system, run the following from the command-line: - - $ java -version - $ ant -version - - If these systems are installed, proceed to step 2. - - If Java is not installed, please proceed to the Oracle Java web site. - - It Ant is not installed, enter the directory 'ant' located in this - distribution, then unzip the file located there. Check the 'ant/bin' - directory and check and/or set 'rx' permissions on the Ant scripts: - 'ant' and 'antRun'. - - When both Java and Ant are available, update the 'envDDMS' file - according to your system. - - Then, do the following on the command-line: - - $ source envDBMS (Mac/linux) - -Step 2 - configure BeeDeeM --------------------------- - - Edit the file 'config.properties', and follow the instructions of - that file. - -Step 3 - install BeeDeeM ------------------------- - - When the file 'config.properties' is updated, do the following on - the command-line: - - If you are root: - $ ant -f deploy.xml install - - Otherwise: - $ sudo ant -f deploy.xml install - - - Step 4 - test BeeDeeM - --------------------- - - Read this: - https://pgdurand.gitbook.io/beedeem/installation/test_install - - diff --git a/scripts/query.bat b/scripts/query.bat deleted file mode 100755 index 97b424e..0000000 --- a/scripts/query.bat +++ /dev/null @@ -1,45 +0,0 @@ -@echo off - -rem DBMS program to query the repository ; for Mac/Windows -rem Copyright (c) - Patrick G. Durand, 2007-2017 -rem ------------------------------------------------------------------- -rem User manual: -rem https://pgdurand.gitbooks.io/beedeem/ -rem ------------------------------------------------------------------- -rem In addition, some parameters can be passed to the JVM for special -rem configuration purposes:
-rem -DKL_DEBUG=true ; if true, if set, log will be in debug mode
-rem -DKL_WORKING_DIR=an_absolute_path ; if not set, log and working -rem directories are set to java.io.tmp
-rem -DKL_LOG_FILE=a_file_name ; if set, creates a log file with that -rem name within KL_WORKING_DIR

-rem -DKL_CONF_DIR=an_absolute_path ; the absolute path to a home-made -rem conf directory. If not set, use ${user.dir}/conf. -rem -DKL_LOG_TYPE=none|console|file(default) -rem -DKL_LOG_TYPE=none|console|file(default) - -set CUR_DIR=%cd% - -rem *** Application home -set KL_APP_HOME=@KL_INSTALL_DIR@ - -rem *** Working directory -set KL_WORKING_DIR=@KL_WORKING_DIR@ - -rem *** Java VM -set KL_JAVA_ARGS=@JAVA_ARGS@ -DKL_HOME="%KL_APP_HOME%" -DKL_WORKING_DIR="%KL_WORKING_DIR%" - -rem *** Create classpath -SETLOCAL ENABLEDELAYEDEXPANSION -set FILES= -set BIN_HOME=%KL_APP_HOME%\\bin -cd %BIN_HOME% -for /F %%f in ('dir /b *.jar') do set FILES=!FILES!;%KL_APP_HOME%\\bin\\%%f - -rem *** Prepare HTML output -rem echo "Content-type: text/html" -rem echo "" - -rem *** Start application -cd %CUR_DIR% -java.exe %KL_JAVA_ARGS% -classpath "%FILES%" bzh.plealog.dbmirror.main.CmdLineQuery %* diff --git a/scripts/query.sh b/scripts/query.sh deleted file mode 100755 index c6bc3ad..0000000 --- a/scripts/query.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env bash -# -# DBMS program to query the repository ; for Mac/Linux -# Copyright (c) - Patrick G. Durand, 2007-2022 -# ------------------------------------------------------------------- -# User manual: -# https://pgdurand.gitbooks.io/beedeem/ -# ------------------------------------------------------------------- -# This is the program to use to query the databanks managed with -# DBMS. -# -# In addition, some parameters can be passed to the JVM for special -# configuration purposes:
-# -DKL_DEBUG=true ; if true, if set, log will be in debug mode
-# -DKL_WORKING_DIR=an_absolute_path ; if not set, log and working -# directories are set to java.io.tmp
-# -DKL_LOG_FILE=a_file_name ; if set, creates a log file with that -# name within KL_WORKING_DIR

-# -DKL_CONF_DIR=an_absolute_path ; the absolute path to a home-made -# conf directory. If not set, use ${user.dir}/conf. -# -DKL_LOG_TYPE=none|console|file(default) -# -# KL_WORKING_DIR, KL_CONF_DIR and KL_LOG_FILE can be defined using -# env variables before calling this script. Additional JRE arguments -# can also be passed in to this script using env variable KL_JRE_ARGS. - -# *** Application home -KL_APP_HOME=$( cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P ) -# For Conda installation, scripts are in the bin directory, so get correct home -[[ "$KL_APP_HOME" == *bin ]] && KL_APP_HOME=$(dirname "$KL_APP_HOME") - -# *** Working directory -if [ ! "$KL_WORKING_DIR" ]; then - KL_WORKING_DIR=@KL_WORKING_DIR@ -fi - -# *** Configuration directory -if [ ! "$KL_CONF_DIR" ]; then - KL_CONF_DIR=$KL_APP_HOME/conf -fi - -# *** Optional JRE arguments -if [ ! "$KL_JRE_ARGS" ]; then - KL_JRE_ARGS="@JAVA_ARGS@" -fi - -# *** Java VM -KL_JAVA_ARGS="$KL_JRE_ARGS -DKL_HOME=$KL_APP_HOME -DKL_WORKING_DIR=$KL_WORKING_DIR -DKL_CONF_DIR=$KL_CONF_DIR" - -# *** Optional redefinition of log file -if [ ! -z "$KL_LOG_FILE" ]; then - KL_JAVA_ARGS+=" -DKL_LOG_FILE=$KL_LOG_FILE" -fi - -# *** JARs section -KL_JAR_LIST_TMP=`\ls $KL_APP_HOME/bin/*.jar` -KL_JAR_LIST=`echo $KL_JAR_LIST_TMP | sed 's/ /:/g'` - -# *** start application -KL_APP_MAIN_CLASS=bzh.plealog.dbmirror.main.CmdLineQuery -java $KL_JAVA_ARGS -classpath $KL_JAR_LIST $KL_APP_MAIN_CLASS $@ - From 9851930710a45bfe7c8c7641b31c9f8f4223ad76 Mon Sep 17 00:00:00 2001 From: Patrick Durand Date: Tue, 20 Dec 2022 11:57:39 +0100 Subject: [PATCH 05/26] update legacy installer to use new BeeDeeM master command: bdm --- scripts/config-std.properties | 2 +- scripts/deploy-std.xml | 70 ++++------------------------------- 2 files changed, 9 insertions(+), 63 deletions(-) diff --git a/scripts/config-std.properties b/scripts/config-std.properties index 9aaaf9b..68a969b 100755 --- a/scripts/config-std.properties +++ b/scripts/config-std.properties @@ -42,5 +42,5 @@ biobaseRootDir=/biobase #biobaseRootDir=c:\\biobase #Default JRE arguments -javaArgs=-Xms128M -Xmx2048M +javaArgs=-Xms128M -Xmx4G diff --git a/scripts/deploy-std.xml b/scripts/deploy-std.xml index 7ae9b61..38afe5d 100755 --- a/scripts/deploy-std.xml +++ b/scripts/deploy-std.xml @@ -1,10 +1,10 @@ - + @@ -19,7 +19,7 @@ - This is the Ant project file to install DBMS. + This is the Ant project file to install BeeDeeM. Available target is: install @@ -75,14 +75,8 @@ - - - - - - - - + + @@ -109,7 +103,7 @@ - + @@ -118,33 +112,9 @@ - - - - - - - - - - - - - + - - - - - - - - - - - - @@ -162,33 +132,9 @@ - - - - - - - - - - - - - + - - - - - - - - - - - - From f042afbd5c6e9af3c8b69ca6ebf432841663dda3 Mon Sep 17 00:00:00 2001 From: Patrick Durand Date: Tue, 20 Dec 2022 11:58:43 +0100 Subject: [PATCH 06/26] update BeeDeeM Galaxy wrapper to use new master command: bdm --- scripts/beedeem_info.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/beedeem_info.xml b/scripts/beedeem_info.xml index c8be17f..fcf6e8e 100644 --- a/scripts/beedeem_info.xml +++ b/scripts/beedeem_info.xml @@ -8,8 +8,8 @@ beedeem & $my_blastn_db; - info.sh -f galaxy -d p >& $my_blastp_db + bdm info -f galaxy -d n >& $my_blastn_db; + bdm info -f galaxy -d p >& $my_blastp_db ]]> From a419eb317609665a4d3c951038b4ce373fc5299f Mon Sep 17 00:00:00 2001 From: pgdurand Date: Fri, 23 Dec 2022 10:36:20 +0100 Subject: [PATCH 07/26] add utility tool to list available bank descritors --- src/bzh/plealog/dbmirror/main/BeeDeeMain.java | 4 + .../dbmirror/main/GetDescriptorList.java | 126 ++++++++++++++++++ .../dbmirror/ui/resources/messages.properties | 13 +- 3 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 src/bzh/plealog/dbmirror/main/GetDescriptorList.java diff --git a/src/bzh/plealog/dbmirror/main/BeeDeeMain.java b/src/bzh/plealog/dbmirror/main/BeeDeeMain.java index 9e1730c..117bed9 100644 --- a/src/bzh/plealog/dbmirror/main/BeeDeeMain.java +++ b/src/bzh/plealog/dbmirror/main/BeeDeeMain.java @@ -39,6 +39,7 @@ public class BeeDeeMain { private static final String[] TOOL_LIST= { "Annotate", "DeleteBank", + "DscList", "Dump", "Install", "Query", @@ -99,6 +100,9 @@ public static void main(String[] args) { case "delete": DeleteBank.main(args); break; + case "desc": + GetDescriptorList.main(args); + break; case "help": dumpHelp(); break; diff --git a/src/bzh/plealog/dbmirror/main/GetDescriptorList.java b/src/bzh/plealog/dbmirror/main/GetDescriptorList.java new file mode 100644 index 0000000..7772561 --- /dev/null +++ b/src/bzh/plealog/dbmirror/main/GetDescriptorList.java @@ -0,0 +1,126 @@ +/* Copyright (C) 2022 Patrick G. Durand + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/agpl-3.0.txt + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + */package bzh.plealog.dbmirror.main; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.OptionBuilder; +import org.apache.commons.cli.Options; +import org.apache.commons.io.FileUtils; + +import com.plealog.genericapp.api.file.EZFileUtils; + +import bzh.plealog.dbmirror.ui.resources.DBMSMessages; +import bzh.plealog.dbmirror.util.conf.Configuration; +import bzh.plealog.dbmirror.util.conf.DBMSAbstractConfig; + +/** + * Utility tool aims at listing bank descriptors available in default + * conf directory of BeeDeeM. + * + * @author Patrick G. Durand + */ +public class GetDescriptorList { + public static final String LS_ARG = "l"; + public static final String PT_ARG = "p"; + + /** + * Setup the valid command-line of the application. + */ + @SuppressWarnings("static-access") + private static Options getCmdLineOptions() { + Options opts; + + Option list = OptionBuilder + .withArgName( DBMSMessages.getString("Tool.DscList.arg1.lbl") ) + .withDescription( DBMSMessages.getString("Tool.DscList.arg1.desc") ) + .create( LS_ARG ); + + Option print = OptionBuilder + .withArgName( DBMSMessages.getString("Tool.DscList.arg2.lbl") ) + .hasArg() + .withDescription( DBMSMessages.getString("Tool.DscList.arg2.desc") ) + .create( PT_ARG ); + + opts = new Options(); + opts.addOption(list); + opts.addOption(print); + CmdLineUtils.setConfDirOption(opts); + CmdLineUtils.setHelpOption(opts); + return opts; + } + + public static void main(String[] args) { + // Handle command line arguments + CommandLine cmdLine = CmdLineUtils.handleArguments( + args, + getCmdLineOptions(), + DBMSMessages.getString("Tool.DscList.name")); + if (cmdLine==null){ + System.exit(1); + } + // Configure app + StarterUtils.configureApplication( + null, DBMSMessages.getString("Tool.DscList.name"), + true, false, true); + + // Get list of DSC files + String cPath = DBMSAbstractConfig.getConfPath(Configuration.DESCRIPTOR); + + // List descriptors? + if (cmdLine.hasOption(LS_ARG)) { + Collection dscList = FileUtils.listFiles( + new File(cPath), + new String[] { DBMSAbstractConfig.FEXT_DD.substring(1) }, + false); + List listF = new ArrayList(); + for(File f : dscList) { + listF.add(EZFileUtils.getFileName(f)); + } + System.out.println(DBMSMessages.getString("Tool.DscList.msg3") + cPath); + System.out.println(String.valueOf(listF.size()) + " " + DBMSMessages.getString("Tool.DscList.msg4")); + Collections.sort(listF, String.CASE_INSENSITIVE_ORDER); + for(String s : listF) { + System.out.println(s); + } + } + // Print the content of a given descriptor? + else if (cmdLine.hasOption(PT_ARG)) { + String dscName = cmdLine.getOptionValue(PT_ARG); + String sPath = dscName + DBMSAbstractConfig.FEXT_DD; + System.out.println(DBMSMessages.getString("Tool.DscList.msg3") + cPath); + //System.out.println(DBMSMessages.getString("Tool.DscList.msg1") + dscName); + System.out.println(DBMSMessages.getString("Tool.DscList.msg2") + sPath); + try { + System.out.println("----"); + System.out.println(EZFileUtils.getFileContent(new File(cPath+sPath))); + System.out.println("----"); + } catch (IOException e) { + System.err.println(e.getMessage()); + System.exit(1); + } + } + + } + +} diff --git a/src/bzh/plealog/dbmirror/ui/resources/messages.properties b/src/bzh/plealog/dbmirror/ui/resources/messages.properties index 4769cc5..ecc4039 100755 --- a/src/bzh/plealog/dbmirror/ui/resources/messages.properties +++ b/src/bzh/plealog/dbmirror/ui/resources/messages.properties @@ -419,6 +419,15 @@ Tool.AutoChecker.info.msg2=Checking: {0}.dsc Tool.AutoChecker.arg1.lbl=descriptor Tool.AutoChecker.arg1.desc=descriptor name(s) to check. Use all to check all descriptors. - - +Tool.DscList.name=ListDesc +Tool.DscList.cmd=desc +Tool.DscList.desc=get list of descriptors from default conf directory +Tool.DscList.arg1.lbl=list +Tool.DscList.arg1.desc=list descriptors +Tool.DscList.arg2.lbl=name +Tool.DscList.arg2.desc=print the content of a descriptor +Tool.DscList.msg1=Content of descriptor: +Tool.DscList.msg2=Descriptor file name : +Tool.DscList.msg3=Config location : +Tool.DscList.msg4=bank descriptors (.dsc files) From 04dfd2d5697b83e9e9a1037c50f101e5ee186da8 Mon Sep 17 00:00:00 2001 From: pgdurand Date: Sat, 24 Dec 2022 15:09:29 +0100 Subject: [PATCH 08/26] preparing v5 --- src/bzh/plealog/dbmirror/main/version.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bzh/plealog/dbmirror/main/version.properties b/src/bzh/plealog/dbmirror/main/version.properties index 1a6f2c1..0fb3fd8 100644 --- a/src/bzh/plealog/dbmirror/main/version.properties +++ b/src/bzh/plealog/dbmirror/main/version.properties @@ -3,9 +3,9 @@ prg.name=beedeem # UI name prg.app.name=BeeDeeM # releases prior to 4: KoriBlast/ngKLAST suite of software -prg.version=4.7.5 +prg.version=5.0.0 # Who did what and when -prg.copyright=(c) 2007-2022, Patrick G. Durand - Ludovic Antin +prg.copyright=(c) 2007-2022, Patrick G. Durand prg.provider=Plealog # Place of the source code prg.url=https://github.com/pgdurand From 81578021f6caa678a01709c0a4491d66d0845c06 Mon Sep 17 00:00:00 2001 From: pgdurand Date: Sat, 24 Dec 2022 15:10:07 +0100 Subject: [PATCH 09/26] refactor tools using Annotation --- src/bzh/plealog/dbmirror/main/Annotate.java | 14 +-- .../dbmirror/main/AutoCheckDescriptors.java | 1 + src/bzh/plealog/dbmirror/main/BdmTool.java | 37 ++++++ src/bzh/plealog/dbmirror/main/BdmToolApi.java | 33 +++++ src/bzh/plealog/dbmirror/main/BeeDeeMain.java | 117 ++++++++++++------ .../dbmirror/main/CmdLineInstaller.java | 19 +-- .../plealog/dbmirror/main/CmdLineQuery.java | 14 +-- src/bzh/plealog/dbmirror/main/DeleteBank.java | 19 +-- .../plealog/dbmirror/main/DumpBankList.java | 65 +++++----- .../dbmirror/main/GetDescriptorList.java | 18 +-- .../plealog/dbmirror/main/UiInstaller.java | 11 +- .../dbmirror/ui/resources/messages.properties | 17 +-- 12 files changed, 233 insertions(+), 132 deletions(-) create mode 100644 src/bzh/plealog/dbmirror/main/BdmTool.java create mode 100644 src/bzh/plealog/dbmirror/main/BdmToolApi.java diff --git a/src/bzh/plealog/dbmirror/main/Annotate.java b/src/bzh/plealog/dbmirror/main/Annotate.java index 3ab9d58..01774c4 100755 --- a/src/bzh/plealog/dbmirror/main/Annotate.java +++ b/src/bzh/plealog/dbmirror/main/Annotate.java @@ -46,13 +46,14 @@ * * @author Patrick G. Durand */ -public class Annotate { +@BdmTool(command="annotate", description="annotate a BLAST XML formatted file") +public class Annotate implements BdmToolApi { /** * Setup the valid command-line of the application. */ @SuppressWarnings("static-access") - private static Options getCmdLineOptions() { + private Options getCmdLineOptions() { Options opts; Option type = OptionBuilder @@ -95,7 +96,8 @@ private static Options getCmdLineOptions() { return opts; } - public static boolean doJob(String[] args){ + @Override + public boolean execute(String[] args){ PAnnotateBlastResult annotator; CommandLine cmdLine; String input, output, writer, type; @@ -121,10 +123,4 @@ public static boolean doJob(String[] args){ return annotator.annotate(input, output, writer, type, includeBC); } - - public static void main(String[] args) { - if (!doJob(args)){ - System.exit(1);// exit code=1 : do this to report error to calling app - } - } } diff --git a/src/bzh/plealog/dbmirror/main/AutoCheckDescriptors.java b/src/bzh/plealog/dbmirror/main/AutoCheckDescriptors.java index e7a985b..f5d34d9 100644 --- a/src/bzh/plealog/dbmirror/main/AutoCheckDescriptors.java +++ b/src/bzh/plealog/dbmirror/main/AutoCheckDescriptors.java @@ -66,6 +66,7 @@ * * @author Patrick G. Durand */ +@BdmTool(command="check", description="check whether or not a descriptor is still ok (URL not broken, etc)") public class AutoCheckDescriptors { private static final Log LOGGER = LogFactory.getLog( DBMSAbstractConfig.KDMS_ROOTLOG_CATEGORY + ".DSCChecker"); diff --git a/src/bzh/plealog/dbmirror/main/BdmTool.java b/src/bzh/plealog/dbmirror/main/BdmTool.java new file mode 100644 index 0000000..6994d4a --- /dev/null +++ b/src/bzh/plealog/dbmirror/main/BdmTool.java @@ -0,0 +1,37 @@ +/* Copyright (C) 2022 Patrick G. Durand + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/agpl-3.0.txt + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + */ +package bzh.plealog.dbmirror.main; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * Annotation aims at marking a class as a BeeDeeM command-line tool. + * + * @author Patrick G. Durand + */ +@Retention(RetentionPolicy.RUNTIME) +public @interface BdmTool { + /** + * Name of command. + */ + String command(); + /** + * Description of command. + */ + String description(); +} diff --git a/src/bzh/plealog/dbmirror/main/BdmToolApi.java b/src/bzh/plealog/dbmirror/main/BdmToolApi.java new file mode 100644 index 0000000..e119017 --- /dev/null +++ b/src/bzh/plealog/dbmirror/main/BdmToolApi.java @@ -0,0 +1,33 @@ +/* Copyright (C) 2022 Patrick G. Durand + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/agpl-3.0.txt + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + */ +package bzh.plealog.dbmirror.main; + +/** + * Defines API a BeeDeeM command-line tool must implement. + * + * @author Patrick G. Durand + */ +public interface BdmToolApi { + /** + * Execute business logic of a tool. + * + * @param args command-line arguments + * + * @return true whether execution is ok, false otherwise. + */ + public boolean execute(String[] args); +} diff --git a/src/bzh/plealog/dbmirror/main/BeeDeeMain.java b/src/bzh/plealog/dbmirror/main/BeeDeeMain.java index 117bed9..2a357d0 100644 --- a/src/bzh/plealog/dbmirror/main/BeeDeeMain.java +++ b/src/bzh/plealog/dbmirror/main/BeeDeeMain.java @@ -16,8 +16,17 @@ */ package bzh.plealog.dbmirror.main; +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.reflect.Method; import java.util.Arrays; +import java.util.Collections; +import java.util.Hashtable; +import java.util.List; import java.util.Properties; +import java.util.Set; +import java.util.stream.Collectors; import bzh.plealog.dbmirror.ui.resources.DBMSMessages; @@ -35,32 +44,54 @@ * @author Patrick G. Durand */ public class BeeDeeMain { - - private static final String[] TOOL_LIST= { - "Annotate", - "DeleteBank", - "DscList", - "Dump", - "Install", - "Query", - "UiInstall"}; - + + /** Code from: https://www.baeldung.com/java-find-all-classes-in-package*/ + public static Set> findAllClassesUsingClassLoader( + String packageName) { + InputStream stream = ClassLoader.getSystemClassLoader() + .getResourceAsStream(packageName.replaceAll("[.]", "/")); + BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); + return reader.lines().filter(line -> line.endsWith(".class")) + .map(line -> getClass(line, packageName)).collect(Collectors.toSet()); + } + private static Class getClass(String className, String packageName) { + try { + return Class.forName(packageName + "." + + className.substring(0, className.lastIndexOf('.'))); + } catch (ClassNotFoundException e) { + System.err.println(e); + } + return null; + } + /** */ + private static void dumpHelp() { Properties props = StarterUtils.getVersionProperties(); System.out.print(props.getProperty("prg.app.name")); System.out.print(" "); System.out.println(DBMSMessages.getString("Tool.Master.intro")); - for (String tName : TOOL_LIST) { + Hashtable tools = new Hashtable(); + Set> clazz = findAllClassesUsingClassLoader(new BeeDeeMain().getClass().getPackage().getName()); + for(Class c : clazz) { + BdmTool bdmT = c.getAnnotation(BdmTool.class); + if (bdmT != null) { + tools.put(bdmT.command(), bdmT.description()); + } + } + List sortedTools = Collections.list(tools.keys()); + Collections.sort(sortedTools); + for(String tName : sortedTools) { System.out.print(" bmd "); - System.out.print(DBMSMessages.getString("Tool."+tName+".cmd")); - if (tName.equals("UiInstall")) { + System.out.print(tName); + if (tName.equals("ui")) { System.out.print(": "); } else { System.out.print(" [options]: "); } - System.out.println(DBMSMessages.getString("Tool."+tName+".desc")); + System.out.println(tools.get(tName)); } + StringBuffer buf = new StringBuffer(); System.out.println(DBMSMessages.getString("Tool.Master.more")); buf.append("--\n"); @@ -93,36 +124,42 @@ public static void main(String[] args) { args = Arrays.copyOfRange(args, 1, args.length); } - switch(cmd) { - case "annotate": - Annotate.main(args); - break; - case "delete": - DeleteBank.main(args); - break; - case "desc": - GetDescriptorList.main(args); - break; - case "help": - dumpHelp(); - break; - case "info": - DumpBankList.main(args); - break; - case "install": - CmdLineInstaller.main(args); - break; - case "query": - CmdLineQuery.main(args); - break; - case "ui": - UiInstaller.main(args); - break; - default: + if (cmd.equalsIgnoreCase("help") || + cmd.equalsIgnoreCase("-h") || + cmd.equalsIgnoreCase("--help")) { + dumpHelp(); + } + else { + // Get all classes from current package + // to locate ones being annotated as BdmTool classes + boolean cmdOk = false; + Set> clazz = findAllClassesUsingClassLoader(new BeeDeeMain().getClass().getPackage().getName()); + for(Class c : clazz) { + BdmTool bdmT = c.getAnnotation(BdmTool.class); + String bdmTCmd = bdmT != null ? bdmT.command() : "-" ; + if (bdmT != null && cmd.equalsIgnoreCase(bdmTCmd)) { + cmdOk = true; + try { + Method method = c.getDeclaredMethod("execute", String[].class); + Object bRet = method.invoke(c.newInstance(), new Object[] {args}); + if ( ! bRet.toString().equalsIgnoreCase("true") ) { + System.exit(1); + } + } catch (Exception e) { + System.err.print(DBMSMessages.getString("Tool.Master.err2.cmd")); + System.err.println(cmd); + System.err.println(e.getMessage()); + System.exit(1); + } + } + } + // unknown command + if (!cmdOk) { System.err.print(DBMSMessages.getString("Tool.Master.err.cmd")); System.err.print(": "); System.err.println(cmd); System.exit(1); + } } } } diff --git a/src/bzh/plealog/dbmirror/main/CmdLineInstaller.java b/src/bzh/plealog/dbmirror/main/CmdLineInstaller.java index 6fc7c8c..308051c 100755 --- a/src/bzh/plealog/dbmirror/main/CmdLineInstaller.java +++ b/src/bzh/plealog/dbmirror/main/CmdLineInstaller.java @@ -69,17 +69,18 @@ * * @author Patrick G. Durand */ -public class CmdLineInstaller { +@BdmTool(command="install", description="install bank(s)") +public class CmdLineInstaller implements BdmToolApi { private File prepareListOfBanks(String bankListFormat){ File f=null; FileOutputStream fos=null; - + boolean bRet = false; try { f = File.createTempFile("bdm-list-of-banks", ".txt"); fos = new FileOutputStream(f); DumpBankList dbl = new DumpBankList(); - dbl.doJob(fos, "all", bankListFormat, "?"); + bRet=dbl.doJob(fos, "all", bankListFormat, "?"); fos.flush(); fos.close(); if (f.length()==0){ @@ -90,7 +91,7 @@ private File prepareListOfBanks(String bankListFormat){ //for now, hide this msg, not really bad } - return f; + return bRet ? f : null; } private void sendTerminationMail(PFTPLoaderDescriptor fDescriptor, String bankListFormat) { PMailer mailer; @@ -241,13 +242,14 @@ private boolean startApplication( * Options are defined in CmdLineInstallerOptions utility class. Use -h or -help * option to get software command-line description. */ - public static void main(String[] args) { + @Override + public boolean execute(String[] args) { // convert the array of strings into an appropriate object CommandLine cmd = CmdLineInstallerOptions.handleArguments(args); // nothing to do, exit! if (cmd==null){ - return; + return false; } // do we have a global descriptor name? (first and second cases described above) @@ -274,7 +276,10 @@ public static void main(String[] args) { //go, go, go... CmdLineInstaller mirror = new CmdLineInstaller(); if (!mirror.startApplication(globalDesc, fDescCmd, bankListFormat, fof)) { - System.exit(1); + return false; + } + else { + return true; } } diff --git a/src/bzh/plealog/dbmirror/main/CmdLineQuery.java b/src/bzh/plealog/dbmirror/main/CmdLineQuery.java index f01811c..4034639 100755 --- a/src/bzh/plealog/dbmirror/main/CmdLineQuery.java +++ b/src/bzh/plealog/dbmirror/main/CmdLineQuery.java @@ -55,7 +55,8 @@ * * @author Patrick G. Durand */ -public class CmdLineQuery { +@BdmTool(command="query", description="query bank repository to fetch entry(ies) given ID(s)") +public class CmdLineQuery implements BdmToolApi { private static final String DATABASE = "d"; private static final String SEQID = "i"; private static final String FORMAT = "f"; @@ -65,7 +66,7 @@ public class CmdLineQuery { * Setup the valid command-line of the application. */ @SuppressWarnings("static-access") - private static Options getCmdLineOptions() { + private Options getCmdLineOptions() { Options opts; Option repo = OptionBuilder @@ -101,7 +102,8 @@ private static Options getCmdLineOptions() { return opts; } - public static boolean doJob(String[] args) { + @Override + public boolean execute(String[] args) { PQueryMirrorBase qm; Hashtable values; CommandLine cmdLine; @@ -144,10 +146,4 @@ public static boolean doJob(String[] args) { return true; } } - - public static void main(String[] args) { - if (!doJob(args)){ - System.exit(1); - } - } } diff --git a/src/bzh/plealog/dbmirror/main/DeleteBank.java b/src/bzh/plealog/dbmirror/main/DeleteBank.java index e798c12..9756c23 100644 --- a/src/bzh/plealog/dbmirror/main/DeleteBank.java +++ b/src/bzh/plealog/dbmirror/main/DeleteBank.java @@ -40,7 +40,8 @@ * * @author Patrick G. Durand * */ -public class DeleteBank { +@BdmTool(command="delete", description="delete bank(s)") +public class DeleteBank implements BdmToolApi{ private static final String CODE_ARG = "code"; private static final String INFO_ARG = "info"; @@ -49,7 +50,7 @@ public class DeleteBank { * Setup the valid command-line of the application. */ @SuppressWarnings("static-access") - private static Options getCmdLineOptions() { + private Options getCmdLineOptions() { Options opts; Option idx = OptionBuilder @@ -70,7 +71,8 @@ private static Options getCmdLineOptions() { } - public static void main(String[] args) { + @Override + public boolean execute(String[] args) { CommandLine cmdLine; List descriptors; IdxDescriptor desc=null; @@ -91,7 +93,7 @@ public static void main(String[] args) { getCmdLineOptions(), DBMSMessages.getString("Tool.DeleteBank.name")); if (cmdLine==null){ - System.exit(1); + return false; } // Load the banks list @@ -111,7 +113,7 @@ public static void main(String[] args) { String msg = new MessageFormat(DBMSMessages.getString("Tool.DeleteBank.err.msg1")).format( new Object[]{dbCode}); System.err.println(msg); - System.exit(1); + return false; } // Do we have to only display information about bank to be deleted ? @@ -124,22 +126,23 @@ public static void main(String[] args) { } String dbList = DeleteBankUtility.getPotentialyDeletedBanks(descriptors, path, osWin); System.out.println(formatter.format(new Object[] { path, dbList })); - System.exit(0); + return true; } //Otherwise, do the bank deletion! if (!DeleteBankUtility.deleteBank(descriptors, desc, new MyDeleteBankHandler())){ System.err.println(DBMSMessages.getString("InstalledDescriptorList.msg10")); - System.exit(1); + return false; } else{ String msg = new MessageFormat(DBMSMessages.getString("Tool.DeleteBank.info.msg2")).format( new Object[]{desc.getName()}); System.out.println(msg); + return true; } } - private static class MyDeleteBankHandler implements DeleteBankHandler { + private class MyDeleteBankHandler implements DeleteBankHandler { @Override public boolean confirmPersonalBankDeletion() { return true; diff --git a/src/bzh/plealog/dbmirror/main/DumpBankList.java b/src/bzh/plealog/dbmirror/main/DumpBankList.java index 33cd5ed..8b8d20d 100644 --- a/src/bzh/plealog/dbmirror/main/DumpBankList.java +++ b/src/bzh/plealog/dbmirror/main/DumpBankList.java @@ -73,7 +73,8 @@ * * @author Patrick G. Durand */ -public class DumpBankList { +@BdmTool(command="info", description="print out list of installed banks") +public class DumpBankList implements BdmToolApi { public static final String DB_ARG = "d"; public static final String FT_ARG = "f"; public static final String US_ARG = "u"; @@ -86,7 +87,7 @@ public class DumpBankList { * Setup the valid command-line of the application. */ @SuppressWarnings("static-access") - private static Options getCmdLineOptions() { + private Options getCmdLineOptions() { Options opts; Option type = OptionBuilder @@ -119,7 +120,7 @@ private static Options getCmdLineOptions() { /** * Get repository for which we have to report bank list. Default is all. */ - private static String getDatabaseType(CommandLine cmdLine) { + private String getDatabaseType(CommandLine cmdLine) { String val = cmdLine.getOptionValue(DB_ARG); return val == null ? "all" : val; } @@ -127,7 +128,7 @@ private static String getDatabaseType(CommandLine cmdLine) { /** * Get format to use to report bank list. Default is txt. */ - private static String getFormatType(CommandLine cmdLine) { + private String getFormatType(CommandLine cmdLine) { String val = cmdLine.getOptionValue(FT_ARG); return val == null ? "txt" : val; } @@ -135,7 +136,7 @@ private static String getFormatType(CommandLine cmdLine) { /** * Get format to use to report bank list. Default is txt. */ - private static String getUserLoginName(CommandLine cmdLine) { + private String getUserLoginName(CommandLine cmdLine) { String val = cmdLine.getOptionValue(US_ARG); return val == null ? "?" : val; } @@ -143,7 +144,7 @@ private static String getUserLoginName(CommandLine cmdLine) { /** * Prepare the bank list for a given type. */ - private static List getMirrorDBList(DBDescriptor.TYPE type, String overridenUserName) { + private List getMirrorDBList(DBDescriptor.TYPE type, String overridenUserName) { String dbMirrorConfFile = DBMSAbstractConfig.getLocalMirrorConfFile(); DBMirrorConfig conf = DBDescriptorUtils.getDBMirrorConfig(dbMirrorConfFile); List dbList = new ArrayList(); @@ -167,7 +168,7 @@ private static List getMirrorDBList(DBDescriptor.TYPE type, /** * Update annotated status of dbList. */ - private static void setAnnotatedStatus(List dbList, Set annotatedBanks){ + private void setAnnotatedStatus(List dbList, Set annotatedBanks){ for(DatabankDescriptor dd : dbList){ dd.setHasAnnotation(annotatedBanks.contains(dd.getName())); } @@ -200,29 +201,7 @@ private long countSize(long curSize, List dbList){ return curSize; } - /** - * Run job. - */ - private void doJob(String[] args, OutputStream os) { - String db, ft, us; - CommandLine cmdLine; - String toolName = DBMSMessages.getString("Tool.Query.name"); - - // Configure software - StarterUtils.configureApplication(null, toolName, true, false, true); - - // Handle command-line - cmdLine = CmdLineUtils.handleArguments(args, getCmdLineOptions(), toolName); - if (cmdLine==null){ - System.exit(1); - } - db = getDatabaseType(cmdLine); - ft = getFormatType(cmdLine); - us = getUserLoginName(cmdLine); - doJob(os, db, ft, us); - } - - protected void doJob(OutputStream os, String db, String ft, String us){ + protected boolean doJob(OutputStream os, String db, String ft, String us){ VelocityEngine ve; VelocityContext context; Template t; @@ -309,7 +288,7 @@ protected void doJob(OutputStream os, String db, String ft, String us){ } catch(Exception e){ LoggerCentral.warn(LOGGER, "Cannot initialize Velocity Engine"); - return; + return false; } try { // Velocity template is taken from "conf/system" directory. @@ -331,10 +310,30 @@ protected void doJob(OutputStream os, String db, String ft, String us){ outWriter.write(writer.toString()); } catch (Exception e) { LoggerCentral.warn(LOGGER, e.toString()); + return false; } + return true; } - public static void main(String[] args) { - new DumpBankList().doJob(args, System.out); + @Override + public boolean execute(String[] args) { + String db, ft, us; + CommandLine cmdLine; + OutputStream os=System.out; + + String toolName = DBMSMessages.getString("Tool.Query.name"); + + // Configure software + StarterUtils.configureApplication(null, toolName, true, false, true); + + // Handle command-line + cmdLine = CmdLineUtils.handleArguments(args, getCmdLineOptions(), toolName); + if (cmdLine==null){ + System.exit(1); + } + db = getDatabaseType(cmdLine); + ft = getFormatType(cmdLine); + us = getUserLoginName(cmdLine); + return doJob(os, db, ft, us); } } diff --git a/src/bzh/plealog/dbmirror/main/GetDescriptorList.java b/src/bzh/plealog/dbmirror/main/GetDescriptorList.java index 7772561..753cb7c 100644 --- a/src/bzh/plealog/dbmirror/main/GetDescriptorList.java +++ b/src/bzh/plealog/dbmirror/main/GetDescriptorList.java @@ -40,7 +40,8 @@ * * @author Patrick G. Durand */ -public class GetDescriptorList { +@BdmTool(command="desc", description="get list of descriptors from default conf directory") +public class GetDescriptorList implements BdmToolApi { public static final String LS_ARG = "l"; public static final String PT_ARG = "p"; @@ -48,7 +49,7 @@ public class GetDescriptorList { * Setup the valid command-line of the application. */ @SuppressWarnings("static-access") - private static Options getCmdLineOptions() { + private Options getCmdLineOptions() { Options opts; Option list = OptionBuilder @@ -69,15 +70,15 @@ private static Options getCmdLineOptions() { CmdLineUtils.setHelpOption(opts); return opts; } - - public static void main(String[] args) { + @Override + public boolean execute(String[] args) { // Handle command line arguments CommandLine cmdLine = CmdLineUtils.handleArguments( args, getCmdLineOptions(), DBMSMessages.getString("Tool.DscList.name")); if (cmdLine==null){ - System.exit(1); + return false; } // Configure app StarterUtils.configureApplication( @@ -98,7 +99,7 @@ public static void main(String[] args) { listF.add(EZFileUtils.getFileName(f)); } System.out.println(DBMSMessages.getString("Tool.DscList.msg3") + cPath); - System.out.println(String.valueOf(listF.size()) + " " + DBMSMessages.getString("Tool.DscList.msg4")); + System.out.println(String.valueOf(listF.size()) + " " + DBMSMessages.getString("Tool.DscList.msg4")+":"); Collections.sort(listF, String.CASE_INSENSITIVE_ORDER); for(String s : listF) { System.out.println(s); @@ -117,10 +118,9 @@ else if (cmdLine.hasOption(PT_ARG)) { System.out.println("----"); } catch (IOException e) { System.err.println(e.getMessage()); - System.exit(1); + return false; } } - + return true; } - } diff --git a/src/bzh/plealog/dbmirror/main/UiInstaller.java b/src/bzh/plealog/dbmirror/main/UiInstaller.java index 4aadc8b..2b84bfd 100644 --- a/src/bzh/plealog/dbmirror/main/UiInstaller.java +++ b/src/bzh/plealog/dbmirror/main/UiInstaller.java @@ -36,9 +36,11 @@ import bzh.plealog.dbmirror.util.conf.Configuration; import bzh.plealog.dbmirror.util.conf.DBMSAbstractConfig; -public class UiInstaller { +@BdmTool(command="ui", description="start bank manager graphical user interface") +public class UiInstaller implements BdmToolApi { - public static void main(String[] args) { + @Override + public boolean execute(String[] args) { // This has to be done at the very beginning, i.e. first method call within // main(). EZGenericApplication.initialize("DB-Manager"); @@ -80,6 +82,11 @@ public static void main(String[] args) { // Start the application EZGenericApplication.startApplication(args); + return true; + } + + public static void main(String[] args) { + new UiInstaller().execute(args); } private static class MyStarterListener implements EZUIStarterListener { diff --git a/src/bzh/plealog/dbmirror/ui/resources/messages.properties b/src/bzh/plealog/dbmirror/ui/resources/messages.properties index ecc4039..bad24c8 100755 --- a/src/bzh/plealog/dbmirror/ui/resources/messages.properties +++ b/src/bzh/plealog/dbmirror/ui/resources/messages.properties @@ -313,10 +313,9 @@ kdms.copy=Copyright (c) Patrick G. Durand / Ludovic Antin 2007-2022 Tool.Master.intro=commands are\: Tool.Master.more=For more details on use, type: bdm -h Tool.Master.err.cmd=Command unknown\: +Tool.Master.err2.cmd=Unable to execute command\: Tool.DeleteBank.name=DeleteBank -Tool.DeleteBank.cmd=delete -Tool.DeleteBank.desc=delete a bank Tool.DeleteBank.arg1.lbl=bank-code Tool.DeleteBank.arg1.desc=index code of the bank to delete. Such a code can be obtained using the 'info' tool (use 'code' format). Tool.DeleteBank.arg2.desc=display bank directory to be deleted WITHOUT deleting it! @@ -325,8 +324,6 @@ Tool.DeleteBank.err.msg1=Bank with code: {0}: not found Tool.DeleteBank.info.msg2=Bank: {0}: successfully deleted Tool.Annotate.name=Annotate -Tool.Annotate.cmd=annotate -Tool.Annotate.desc=annotate a BLAST XML formatted file Tool.Annotate.arg1.lbl=type Tool.Annotate.arg1.desc=type of annotation to retrieve. Options: bco or full. Mandatory. Tool.Annotate.arg2.lbl=Blast file @@ -339,8 +336,6 @@ Tool.Annotate.arg5.lbl=include Tool.Annotate.arg5.desc=include Biological Classification data. Use true or false. Default is false. Tool.Query.name=Query -Tool.Query.cmd=query -Tool.Query.desc=query repository to fetch entry(ies) given ID(s) Tool.Query.arg1.lbl=repository Tool.Query.arg1.desc=type of repository to query. Mandatory. One of: nucleotide, protein, dico. When using dico, use one of: dico:taxon, dico:EC, dico:GO, dico:CDD or dico:InterPro. When using dico:taxon, entry ID can be either a TaxID or a Taxonomy Name (e.g. organism, phylum, etc.). In latter case, Query Tool will dump Taxonomy path. Tool.Query.arg2.lbl=entryID @@ -351,8 +346,6 @@ Tool.Query.arg4.lbl=output Tool.Query.arg4.desc=output file to save results of query. Optional, default is stdout. Tool.Dump.name=DumpBankList -Tool.Dump.cmd=info -Tool.Dump.desc=list of installed banks Tool.Dump.arg1.lbl=repository Tool.Dump.arg1.desc=type of repository. One of: n, p, b, all. Default is: all. Tool.Dump.arg2.lbl=format @@ -367,12 +360,8 @@ Tool.Utils.arg1.desc=absolute path to custom conf directory Tool.Utils.info.msg1=print this message Tool.UiInstall.name=UiInstall -Tool.UiInstall.cmd=ui -Tool.UiInstall.desc=start graphical bank manager interface Tool.Install.name=Install -Tool.Install.cmd=install -Tool.Install.desc=install bank(s) Tool.Install.arg1.desc=absolute path to custom conf directory Tool.Install.arg2.lbl=descriptor Tool.Install.arg2.desc=comma separated list of descriptor (.dsc) names @@ -420,8 +409,6 @@ Tool.AutoChecker.arg1.lbl=descriptor Tool.AutoChecker.arg1.desc=descriptor name(s) to check. Use all to check all descriptors. Tool.DscList.name=ListDesc -Tool.DscList.cmd=desc -Tool.DscList.desc=get list of descriptors from default conf directory Tool.DscList.arg1.lbl=list Tool.DscList.arg1.desc=list descriptors Tool.DscList.arg2.lbl=name @@ -429,5 +416,5 @@ Tool.DscList.arg2.desc=print the content of a descriptor Tool.DscList.msg1=Content of descriptor: Tool.DscList.msg2=Descriptor file name : Tool.DscList.msg3=Config location : -Tool.DscList.msg4=bank descriptors (.dsc files) +Tool.DscList.msg4=bank descriptors (.dsc files) From 3df944fe350e6abe3e44da47d2bee1911ba99628 Mon Sep 17 00:00:00 2001 From: pgdurand Date: Sat, 24 Dec 2022 15:10:32 +0100 Subject: [PATCH 10/26] fix tests after code refactoring --- src/test/unit/CmdLineQueryTest.java | 6 +++--- src/test/unit/PAnnotateBlastResultTest.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/unit/CmdLineQueryTest.java b/src/test/unit/CmdLineQueryTest.java index be2173f..7bf79cd 100644 --- a/src/test/unit/CmdLineQueryTest.java +++ b/src/test/unit/CmdLineQueryTest.java @@ -128,7 +128,7 @@ public void testCmdLine() { Assert.fail(); } - Assert.assertTrue(CmdLineQuery.doJob(args)); + Assert.assertTrue(new CmdLineQuery().execute(args)); try { Assert.assertTrue(compareTwoFiles(refFile, result)); } catch (IOException e) { @@ -164,7 +164,7 @@ public void testCmdLineFOIDs() { } //AssertFalse because file of IDs contains a fake ID, so we expect an error message - Assert.assertFalse(CmdLineQuery.doJob(args)); + Assert.assertFalse(new CmdLineQuery().execute(args)); try { Assert.assertTrue(compareTwoFiles(refFile, result)); } catch (IOException e) { @@ -299,7 +299,7 @@ public void testCmdLineTaxo() { "-f", "txt", "-o", result.getAbsolutePath()}; - Assert.assertTrue(CmdLineQuery.doJob(args)); + Assert.assertTrue(new CmdLineQuery().execute(args)); try { Assert.assertTrue(compareTwoFiles(refFile, result)); diff --git a/src/test/unit/PAnnotateBlastResultTest.java b/src/test/unit/PAnnotateBlastResultTest.java index c9b674e..890de79 100755 --- a/src/test/unit/PAnnotateBlastResultTest.java +++ b/src/test/unit/PAnnotateBlastResultTest.java @@ -244,6 +244,6 @@ public void testCmdLine() { "-o", result.getAbsolutePath(), "-type", "full", "-writer", "zml"}; - Assert.assertTrue(Annotate.doJob(args)); + Assert.assertTrue(new Annotate().execute(args)); } } From 0d841c6f06711333b830b37806fb9b43042ffa70 Mon Sep 17 00:00:00 2001 From: pgdurand Date: Thu, 5 Jan 2023 19:20:34 +0100 Subject: [PATCH 11/26] update date --- src/bzh/plealog/dbmirror/main/version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bzh/plealog/dbmirror/main/version.properties b/src/bzh/plealog/dbmirror/main/version.properties index 0fb3fd8..d328750 100644 --- a/src/bzh/plealog/dbmirror/main/version.properties +++ b/src/bzh/plealog/dbmirror/main/version.properties @@ -5,7 +5,7 @@ prg.app.name=BeeDeeM # releases prior to 4: KoriBlast/ngKLAST suite of software prg.version=5.0.0 # Who did what and when -prg.copyright=(c) 2007-2022, Patrick G. Durand +prg.copyright=(c) 2007-2023, Patrick G. Durand prg.provider=Plealog # Place of the source code prg.url=https://github.com/pgdurand From e25567fea2152b71558adfca4d914a9cc0e900dc Mon Sep 17 00:00:00 2001 From: pgdurand Date: Thu, 5 Jan 2023 19:21:41 +0100 Subject: [PATCH 12/26] ensure bash 5 is available, export appropriately KL_ variables, simplify script --- scripts/bdm.sh | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/scripts/bdm.sh b/scripts/bdm.sh index a01eed2..0a41c91 100755 --- a/scripts/bdm.sh +++ b/scripts/bdm.sh @@ -2,7 +2,7 @@ # # ------------------------------------------------------------------- # BeeDeeM starter command for macOS/Linux -# Copyright (c) - Patrick G. Durand, 2007-2022 +# Copyright (c) - Patrick G. Durand, 2007-2023 # ------------------------------------------------------------------- # User manual: # https://pgdurand.gitbooks.io/beedeem/ @@ -22,13 +22,20 @@ # conf directory. If not set, use ${user.dir}/conf. # -DKL_LOG_TYPE=none|console|file(default) # -# KL_WORKING_DIR, KL_CONF_DIR and KL_LOG_FILE can be defined using -# env variables before calling this script. Additional JRE arguments +# Alternatively, you can set these special variables as environment +# variables BEFORE calling this script. Additional JRE arguments # can also be passed in to this script using env variable KL_JRE_ARGS. # # Proxy configuration: update configuration file: # ${beedeemHome}/conf/system/network.config. +# *** Bank installation scripts of BeeDeeM (conf/scripts) requires BASH 5 +BASH_VER=$(bash --version | grep ", version" | cut -d' ' -f4 | cut -d'.' -f1) +if [ "$BASH_VER" -lt "5" ]; then + echo "/!\ ERROR: BeeDeeM requires BASH release 5 (yours is: $BASH_VER)" + exit 1 +fi + # *** Application home KL_APP_HOME=$( cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P ) # For Conda installation, scripts are in the bin directory, so get correct home @@ -36,26 +43,21 @@ KL_APP_HOME=$( cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P ) # *** Working directory if [ ! "$KL_WORKING_DIR" ]; then - KL_WORKING_DIR=@KL_WORKING_DIR@ + export KL_WORKING_DIR=@KL_WORKING_DIR@ fi # *** Configuration directory if [ ! "$KL_CONF_DIR" ]; then - KL_CONF_DIR=$KL_APP_HOME/conf + export KL_CONF_DIR=$KL_APP_HOME/conf fi -# *** Optional JRE arguments +# *** Optional JRE arguments (at least RAM specs) if [ ! "$KL_JRE_ARGS" ]; then KL_JRE_ARGS="@JAVA_ARGS@" fi # *** Java VM -KL_JAVA_ARGS="$KL_JRE_ARGS -DKL_HOME=$KL_APP_HOME -DKL_WORKING_DIR=$KL_WORKING_DIR -DKL_CONF_DIR=$KL_CONF_DIR" - -# *** Optional redefinition of log file -if [ ! -z "$KL_LOG_FILE" ]; then - KL_JAVA_ARGS+=" -DKL_LOG_FILE=$KL_LOG_FILE" -fi +KL_JAVA_ARGS="$KL_JRE_ARGS -DKL_HOME=$KL_APP_HOME" # *** JARs section KL_JAR_LIST_TMP=`\ls $KL_APP_HOME/bin/*.jar` From 444a203b807bf0680e14918e18b6b52d013e0c1e Mon Sep 17 00:00:00 2001 From: pgdurand Date: Thu, 5 Jan 2023 19:22:07 +0100 Subject: [PATCH 13/26] simplify by removing JAVA_PATH --- scripts/envDBMS | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/scripts/envDBMS b/scripts/envDBMS index b3b1ad8..1d5f5a3 100755 --- a/scripts/envDBMS +++ b/scripts/envDBMS @@ -1,19 +1,12 @@ -# Provide here the path to the home directory of an -# Oracle JRE release 1.7 or above -# -JAVA_HOME=/usr/local/jre1.7 [update as needed] - -export JAVA_HOME - # Provide here the path to the home directory of a Ant -# 1.6.5 or above. By default, DBMS installer will use its +# 1.9 or above. By default, DBMS installer will use its # own Ant. # ANT_HOME=$PWD/ant export ANT_HOME -PATH=$JAVA_HOME/bin:$ANT_HOME/bin:$PATH +PATH=$ANT_HOME/bin:$PATH export PATH From 32a7bb86a4c1737f7f7effcfda14022b83e0b0d1 Mon Sep 17 00:00:00 2001 From: pgdurand Date: Thu, 5 Jan 2023 19:22:52 +0100 Subject: [PATCH 14/26] update script to use bdm command only, deploy test_bdm for legacy installer --- scripts/deploy-std.xml | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/scripts/deploy-std.xml b/scripts/deploy-std.xml index 38afe5d..d787c4a 100755 --- a/scripts/deploy-std.xml +++ b/scripts/deploy-std.xml @@ -34,7 +34,6 @@ Installation dir: ${installDir} Working dir : ${workingDir} BioBase dir : ${biobaseRootDir} - JVM dir : ${javaDir} Java args : ${javaArgs} If ok, press Return key to start the installation... @@ -46,7 +45,6 @@ - @@ -68,24 +66,26 @@ - + - - - - - - - + + + + + + + + + - + - + @@ -108,7 +108,7 @@ - + @@ -128,13 +128,18 @@ - + + + + + + @@ -143,7 +148,7 @@ - + @@ -160,7 +165,7 @@ - + From 434fad4c854a04c8379e5102041e1c0b581ed5f8 Mon Sep 17 00:00:00 2001 From: pgdurand Date: Thu, 5 Jan 2023 19:23:12 +0100 Subject: [PATCH 15/26] fix toolName --- src/bzh/plealog/dbmirror/main/DumpBankList.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bzh/plealog/dbmirror/main/DumpBankList.java b/src/bzh/plealog/dbmirror/main/DumpBankList.java index 8b8d20d..32f6430 100644 --- a/src/bzh/plealog/dbmirror/main/DumpBankList.java +++ b/src/bzh/plealog/dbmirror/main/DumpBankList.java @@ -321,7 +321,7 @@ public boolean execute(String[] args) { CommandLine cmdLine; OutputStream os=System.out; - String toolName = DBMSMessages.getString("Tool.Query.name"); + String toolName = DBMSMessages.getString("Tool.Dump.name"); // Configure software StarterUtils.configureApplication(null, toolName, true, false, true); From a3556c168f4af39cfb541ef3f11f7a1d85e46e2e Mon Sep 17 00:00:00 2001 From: pgdurand Date: Thu, 5 Jan 2023 19:26:57 +0100 Subject: [PATCH 16/26] fix messages --- src/bzh/plealog/dbmirror/ui/resources/messages.properties | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bzh/plealog/dbmirror/ui/resources/messages.properties b/src/bzh/plealog/dbmirror/ui/resources/messages.properties index bad24c8..e7b11ee 100755 --- a/src/bzh/plealog/dbmirror/ui/resources/messages.properties +++ b/src/bzh/plealog/dbmirror/ui/resources/messages.properties @@ -314,6 +314,8 @@ Tool.Master.intro=commands are\: Tool.Master.more=For more details on use, type: bdm -h Tool.Master.err.cmd=Command unknown\: Tool.Master.err2.cmd=Unable to execute command\: +Tool.Master.err3.cmd=Error while scanning for BeeDeeM main classes\: +Tool.Master.err4.cmd=Class not found\: Tool.DeleteBank.name=DeleteBank Tool.DeleteBank.arg1.lbl=bank-code From 0907bb82b8ea9a6df0dba8873469c21f8e167fa8 Mon Sep 17 00:00:00 2001 From: pgdurand Date: Thu, 5 Jan 2023 19:27:25 +0100 Subject: [PATCH 17/26] add auto-test for legacy installer --- scripts/test_bdm.sh | 62 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 scripts/test_bdm.sh diff --git a/scripts/test_bdm.sh b/scripts/test_bdm.sh new file mode 100755 index 0000000..4fd2dba --- /dev/null +++ b/scripts/test_bdm.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env bash + +# ================================================= +# Test script for BeeDeeM legacy installer. +# To be used directly on the command-line. +# DO NOT use for Singularity/Docker installations. +# +# How to? +# +# Step 1: install BeeDeeM as stated at: +# https://pgdurand.gitbook.io/beedeem/installation/installation#legacy-installation +# +# Step 2: run test as follows: +# ./test_bdm.sh +# -- +# P. Durand (SeBiMER, Ifremer), last updated on Jan 2023 +# ================================================= + +# == TEST 1 =========================================== +echo "*** TEST 1: Start simple bank installation" +# set log mode to console (otherwise default is a log file located in KL_WORKING_DIR +export KL_LOG_TYPE=console +# Set the bank to install +# This is a '.dsc' file located in BeeDeeM installation path at ${beedeem-home}/conf/descriptors +DESCRIPTOR="SwissProt_human" +# start BeeDeeM with 'install' command +./bdm install -desc ${DESCRIPTOR} +# check whether command succeeded or not +if [ $? -eq 0 ]; then + echo "TEST 1: SUCCESS" +else + echo "TEST 1: FAILED." + exit 1 +fi + +# == TEST 2 =========================================== +echo "*** TEST 2: list installed bank" +# reset log mode to file +export KL_LOG_TYPE=file +# start BeeDeeM with 'info' command +./bdm info -d all -f txt +if [ $? -eq 0 ]; then + echo "TEST 2: SUCCESS" +else + echo "TEST 2: FAILED. Review log file in: @KL_WORKING_DIR@" + exit 1 +fi + +# == TEST 3 =========================================== +# Change default log file name to something else +export KL_LOG_FILE=query.log +SW_ENTRY="ZZZ3_HUMAN" +echo "*** TEST 3: query bank for entry: $SW_ENTRY" +# start BeeDeeM with 'query' command +./bdm query -d protein -f txt -i $SW_ENTRY +if [ $? -eq 0 ]; then + echo "TEST 3: SUCCESS" +else + echo "TEST 3: FAILED. Review log file: @KL_WORKING_DIR@" + exit 1 +fi + From 9fd9c4d9ead074e210a31451451f973ba5b8b7d8 Mon Sep 17 00:00:00 2001 From: pgdurand Date: Thu, 5 Jan 2023 19:27:55 +0100 Subject: [PATCH 18/26] add auto-test for legacy installer --- build.xml | 66 +++---------------------------------------------------- 1 file changed, 3 insertions(+), 63 deletions(-) diff --git a/build.xml b/build.xml index b28522a..8f9abe0 100644 --- a/build.xml +++ b/build.xml @@ -217,76 +217,17 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -316,7 +257,6 @@ - From 3fd671686f8954f02cf72c5bf24cf26ea238110b Mon Sep 17 00:00:00 2001 From: pgdurand Date: Thu, 5 Jan 2023 19:31:13 +0100 Subject: [PATCH 19/26] add reflective API capable of scanning dir and jar files --- NOTICE.txt | 5 +- src/bzh/plealog/dbmirror/main/BeeDeeMain.java | 60 +- .../annotation/AnnotationDetector.java | 690 ++++++++++++++++++ .../infomas/annotation/ClassFileBuffer.java | 240 ++++++ .../infomas/annotation/ClassFileIterator.java | 146 ++++ src/eu/infomas/annotation/FileIterator.java | 122 ++++ src/eu/infomas/annotation/README.txt | 7 + .../infomas/annotation/ResourceIterator.java | 43 ++ .../infomas/annotation/ZipFileIterator.java | 99 +++ src/eu/infomas/annotation/package-info.java | 29 + 10 files changed, 1418 insertions(+), 23 deletions(-) create mode 100644 src/eu/infomas/annotation/AnnotationDetector.java create mode 100644 src/eu/infomas/annotation/ClassFileBuffer.java create mode 100644 src/eu/infomas/annotation/ClassFileIterator.java create mode 100644 src/eu/infomas/annotation/FileIterator.java create mode 100644 src/eu/infomas/annotation/README.txt create mode 100644 src/eu/infomas/annotation/ResourceIterator.java create mode 100644 src/eu/infomas/annotation/ZipFileIterator.java create mode 100644 src/eu/infomas/annotation/package-info.java diff --git a/NOTICE.txt b/NOTICE.txt index 27c361e..fdaca5d 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -1,4 +1,4 @@ -This product includes software developed by: +This software includes software developed by: The Plealog Team (http://www.plealog.com) Plealog license 1 is here: http://www.apache.org/licenses/LICENSE-2.0 @@ -34,3 +34,6 @@ This product includes software developed by: Biojava license is here: http://www.gnu.org/copyleft/lesser.html It targets: biojava, bytecode + The Informas Annotation framework + License is here: https://github.com/rmuller/infomas-asl + It targets: eu.informas.annotation package \ No newline at end of file diff --git a/src/bzh/plealog/dbmirror/main/BeeDeeMain.java b/src/bzh/plealog/dbmirror/main/BeeDeeMain.java index 2a357d0..7fe9492 100644 --- a/src/bzh/plealog/dbmirror/main/BeeDeeMain.java +++ b/src/bzh/plealog/dbmirror/main/BeeDeeMain.java @@ -16,19 +16,20 @@ */ package bzh.plealog.dbmirror.main; -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; +import java.io.IOException; +import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.Arrays; import java.util.Collections; +import java.util.HashSet; import java.util.Hashtable; import java.util.List; import java.util.Properties; import java.util.Set; -import java.util.stream.Collectors; import bzh.plealog.dbmirror.ui.resources.DBMSMessages; +import eu.infomas.annotation.AnnotationDetector; +import eu.infomas.annotation.AnnotationDetector.TypeReporter; /** * This class starts BeeDeeM for all commands. @@ -45,23 +46,38 @@ */ public class BeeDeeMain { - /** Code from: https://www.baeldung.com/java-find-all-classes-in-package*/ - public static Set> findAllClassesUsingClassLoader( - String packageName) { - InputStream stream = ClassLoader.getSystemClassLoader() - .getResourceAsStream(packageName.replaceAll("[.]", "/")); - BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); - return reader.lines().filter(line -> line.endsWith(".class")) - .map(line -> getClass(line, packageName)).collect(Collectors.toSet()); + + /** Code from: https://github.com/rmuller/infomas-asl + * Adapted in package eu.informas.annotation available in BeeDeeM; see README.txt, there. + **/ + public static Set> findAllClassesUsingClassLoader(){ + HashSet> classes = new HashSet<>(); + final TypeReporter reporter = new TypeReporter() { + @SuppressWarnings("unchecked") + @Override + public Class[] annotations() { + return new Class[]{BdmTool.class}; + } + @Override + public void reportTypeAnnotation(Class annotation, + String className) { + try { + classes.add(Class.forName(className)); + } catch (ClassNotFoundException e) { + System.err.println(DBMSMessages.getString("Tool.Master.err4.cmd")+" "+e.getMessage()); + System.exit(1);//serious error, should not happen! + } + } + + }; + final AnnotationDetector cf = new AnnotationDetector(reporter); + try { + cf.detect(); + } catch (IOException e) { + System.err.println(DBMSMessages.getString("Tool.Master.err3.cmd")+" "+e.getMessage()); + System.exit(1);//serious error, should not happen! } - private static Class getClass(String className, String packageName) { - try { - return Class.forName(packageName + "." - + className.substring(0, className.lastIndexOf('.'))); - } catch (ClassNotFoundException e) { - System.err.println(e); - } - return null; + return classes; } /** */ @@ -71,7 +87,7 @@ private static void dumpHelp() { System.out.print(" "); System.out.println(DBMSMessages.getString("Tool.Master.intro")); Hashtable tools = new Hashtable(); - Set> clazz = findAllClassesUsingClassLoader(new BeeDeeMain().getClass().getPackage().getName()); + Set> clazz = findAllClassesUsingClassLoader(); for(Class c : clazz) { BdmTool bdmT = c.getAnnotation(BdmTool.class); if (bdmT != null) { @@ -133,7 +149,7 @@ public static void main(String[] args) { // Get all classes from current package // to locate ones being annotated as BdmTool classes boolean cmdOk = false; - Set> clazz = findAllClassesUsingClassLoader(new BeeDeeMain().getClass().getPackage().getName()); + Set> clazz = findAllClassesUsingClassLoader(); for(Class c : clazz) { BdmTool bdmT = c.getAnnotation(BdmTool.class); String bdmTCmd = bdmT != null ? bdmT.command() : "-" ; diff --git a/src/eu/infomas/annotation/AnnotationDetector.java b/src/eu/infomas/annotation/AnnotationDetector.java new file mode 100644 index 0000000..8488e0b --- /dev/null +++ b/src/eu/infomas/annotation/AnnotationDetector.java @@ -0,0 +1,690 @@ +/* AnnotationDetector.java + * + * Created: 2011-10-10 (Year-Month-Day) + * Character encoding: UTF-8 + * + ****************************************** LICENSE ******************************************* + * + * Copyright (c) 2011 - 2016 XIAM Solutions B.V. (http://www.xiam.nl) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package eu.infomas.annotation; + +import java.io.DataInput; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.net.JarURLConnection; +import java.net.URISyntaxException; +import java.net.URL; +import java.net.URLConnection; +import java.util.Arrays; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * {@code AnnotationDetector} reads Java Class File (".class") files and reports the + * encountered annotations via a simple, developer friendly API. + *

+ * A Java Class File consists of a stream of 8-bit bytes. All 16-bit, 32-bit, and 64-bit + * quantities are constructed by reading in two, four, and eight consecutive 8-bit + * bytes, respectively. Multi byte data items are always stored in big-endian order, + * where the high bytes come first. In the Java and Java 2 platforms, this format is + * supported by interfaces {@link java.io.DataInput} and {@link java.io.DataOutput}. + *

+ * A class file consists of a single ClassFile structure: + *

+ * ClassFile {
+ *   u4 magic;
+ *   u2 minor_version;
+ *   u2 major_version;
+ *   u2 constant_pool_count;
+ *   cp_info constant_pool[constant_pool_count-1];
+ *   u2 access_flags;
+ *   u2 this_class;
+ *   u2 super_class;
+ *   u2 interfaces_count;
+ *   u2 interfaces[interfaces_count];
+ *   u2 fields_count;
+ *   field_info fields[fields_count];
+ *   u2 methods_count;
+ *   method_info methods[methods_count];
+ *   u2 attributes_count;
+ *   attribute_info attributes[attributes_count];
+ * }
+ *
+ * Where:
+ * u1 unsigned byte {@link java.io.DataInput#readUnsignedByte()}
+ * u2 unsigned short {@link java.io.DataInput#readUnsignedShort()}
+ * u4 unsigned int {@link java.io.DataInput#readInt()}
+ *
+ * Annotations are stored as Attributes (i.e. "RuntimeVisibleAnnotations" and
+ * "RuntimeInvisibleAnnotations").
+ * 
+ * References: + * + *

+ * Similar projects / libraries: + *

+ *

+ * All above mentioned projects make use of a byte code manipulation library (like BCEL, + * ASM or Javassist). + * + * @author Ronald K. Muller + * @since annotation-detector 3.0.0 + */ +public final class AnnotationDetector { + + /** + * {@code Reporter} is the base interface, used to report the detected annotations. + * Every category of annotations (i.e. Type, Field and Method) has its own specialized + * interface. This enables an efficient way of reporting the detected annotations. + */ + public interface Reporter { + + /** + * Return the {@code Annotation} classes which must be reported (all other + * annotations are skipped). + */ + Class[] annotations(); + + } + + /** + * A {@code Reporter} for type annotations. + */ + public interface TypeReporter extends Reporter { + + /** + * This call back method is used to report an type level {@code Annotation}. + * Only {@code Annotation}s, specified by {@link #annotations()} are reported! + */ + void reportTypeAnnotation(Class annotation, String className); + + } + + /** + * A {@code Reporter} for field annotations. + */ + public interface FieldReporter extends Reporter { + + /** + * This call back method is used to report an field level {@code Annotation}. + * Only {@code Annotation}s, specified by {@link #annotations()} are reported! + */ + void reportFieldAnnotation(Class annotation, String className, + String fieldName); + + } + + /** + * A {@code Reporter} for method annotations. + */ + public interface MethodReporter extends Reporter { + + /** + * This call back method is used to report an method level {@code Annotation}. + * Only {@code Annotation}s, specified by {@link #annotations()} are reported! + */ + void reportMethodAnnotation(Class annotation, String className, + String methodName); + + } + + // Only used during development. If set to "true" debug messages are displayed. + private static final boolean DEBUG = false; + + // Constant Pool type tags + private static final int CP_UTF8 = 1; + private static final int CP_INTEGER = 3; + private static final int CP_FLOAT = 4; + private static final int CP_LONG = 5; + private static final int CP_DOUBLE = 6; + private static final int CP_CLASS = 7; + private static final int CP_STRING = 8; + private static final int CP_REF_FIELD = 9; + private static final int CP_REF_METHOD = 10; + private static final int CP_REF_INTERFACE = 11; + private static final int CP_NAME_AND_TYPE = 12; + private static final int CP_METHOD_HANDLE = 15; + private static final int CP_METHOD_TYPE = 16; + private static final int CP_INVOKE_DYNAMIC = 18; + + // AnnotationElementValue + private static final int BYTE = 'B'; + private static final int CHAR = 'C'; + private static final int DOUBLE = 'D'; + private static final int FLOAT = 'F'; + private static final int INT = 'I'; + private static final int LONG = 'J'; + private static final int SHORT = 'S'; + private static final int BOOLEAN = 'Z'; + // used for AnnotationElement only + private static final int STRING = 's'; + private static final int ENUM = 'e'; + private static final int CLASS = 'c'; + private static final int ANNOTATION = '@'; + private static final int ARRAY = '['; + + // The buffer is reused during the life cycle of this AnnotationDetector instance + private final ClassFileBuffer cpBuffer = new ClassFileBuffer(); + // the annotation types to report, see {@link #annotations()} + private final Map> annotations; + + private TypeReporter typeReporter; + private FieldReporter fieldReporter; + private MethodReporter methodReporter; + + // the 'raw' name of this interface or class (using '/' instead of '.' in package name) + private String typeName; + // Reusing the constantPool is not needed for better performance + private Object[] constantPool; + private String memberName; + + /** + * Create a new {@code AnnotationDetector}, reporting the detected annotations + * to the specified {@code Reporter}. + */ + public AnnotationDetector(final Reporter reporter) { + final Class[] a = reporter.annotations(); + annotations = new HashMap>(a.length); + // map "raw" type names to Class object + for (int i = 0; i < a.length; ++i) { + annotations.put("L" + a[i].getName().replace('.', '/') + ";", a[i]); + } + if (reporter instanceof TypeReporter) { + typeReporter = (TypeReporter)reporter; + } + if (reporter instanceof FieldReporter) { + fieldReporter = (FieldReporter)reporter; + } + if (reporter instanceof MethodReporter) { + methodReporter = (MethodReporter)reporter; + } + if (typeReporter == null && fieldReporter == null && methodReporter == null) { + throw new AssertionError("No reporter defined"); + } + } + + /** + * Report all Java ClassFile files available on the class path. + * + * @see #detect(File...) + */ + public void detect() throws IOException { + detect(new ClassFileIterator()); + } + + /** + * Report all Java ClassFile files available on the class path within + * the specified packages and sub packages. + * + * @see #detect(File...) + */ + public void detect(final String... packageNames) throws IOException { + final String[] pkgNameFilter = new String[packageNames.length]; + for (int i = 0; i < pkgNameFilter.length; ++i) { + pkgNameFilter[i] = packageNames[i].replace('.', '/'); + if (!pkgNameFilter[i].endsWith("/")) { + pkgNameFilter[i] = pkgNameFilter[i].concat("/"); + } + } + final Set files = new HashSet(); + final ClassLoader loader = Thread.currentThread().getContextClassLoader(); + for (final String packageName : pkgNameFilter) { + final Enumeration resourceEnum = loader.getResources(packageName); + while (resourceEnum.hasMoreElements()) { + final URL url = resourceEnum.nextElement(); + if ("file".equals(url.getProtocol())) { + final File dir = toFile(url); + if (dir.isDirectory()) { + files.add(dir); + } else { + throw new AssertionError("Not a recognized file URL: " + url); + } + } /*else if (url.getProtocol().startsWith("vfs")) {//Requires JBoss stuff, not used in BeeDeeM + detect(new VfsResourceIterator(url)); + } */else { + final File jarFile = toFile(openJarURLConnection(url).getJarFileURL()); + if (jarFile.isFile()) { + files.add(jarFile); + } else { + throw new AssertionError("Not a File: " + jarFile); + } + } + } + } + if (DEBUG) { + print("Files to scan: %s", files); + } + if (!files.isEmpty()) { + // see http://shipilev.net/blog/2016/arrays-wisdom-ancients/#_conclusion + detect(new ClassFileIterator(files.toArray(new File[0]), pkgNameFilter)); + } + } + + /** + * Scan all Java ClassFile ({@code *.class}) files available in the specified files + * and/or directories. + *

+ * In Java, the + * + * Class path contains directories (top level directory as package root) and/or + * jar files (including zip files). + *

+ * Note that non-class files (files, not starting with the magic number + * {@code CAFEBABE} are silently ignored. + * + * @param filesOrDirectories Valid files are: jar files, Java *.class files (all other + * files are silently ignored) and directories which are package root directories + */ + public void detect(final File... filesOrDirectories) throws IOException { + if (DEBUG) { + print("detectFilesOrDirectories: %s", (Object)filesOrDirectories); + } + detect(new ClassFileIterator(filesOrDirectories, null)); + } + + // private + + private File toFile(final URL url) { + // only correct way to convert the URL to a File object, also see issue #16 + // Do not use URLDecoder + try { + return new File(url.toURI()); + } catch (URISyntaxException ex) { + // we do not expect an URISyntaxException here + throw new AssertionError("Unable to convert URI to File: " + url); + } + } + + private JarURLConnection openJarURLConnection(final URL url) throws IOException { + final URL checkedUrl; + if ("zip".equals(url.getProtocol())) { + // WebLogic returns URL with "zip" protocol, returning a + // weblogic.utils.zip.ZipURLConnection when opened + // Easy fix is to convert this URL to jar URL + checkedUrl = new URL(url.toExternalForm().replace("zip:/", "jar:file:/")); + } else { + checkedUrl = url; + } + URLConnection urlConnection = checkedUrl.openConnection(); + // GlassFish 4.1.1 is providing a URLConnection of type: + // http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/ + // apache/felix/framework/URLHandlersBundleURLConnection.java?view=markup + // Which does _not_ extend JarURLConnection. + // This bit of reflection allows us to call the getLocalURL method which + // actually returns a URL to a jar file. + if (checkedUrl.getProtocol().startsWith("bundle")) { + try { + final Method m = urlConnection.getClass().getDeclaredMethod("getLocalURL"); + if (!m.isAccessible()) { + m.setAccessible(true); + } + final URL jarUrl = (URL)m.invoke(urlConnection); + urlConnection = jarUrl.openConnection(); + } catch (Exception ex) { + throw new AssertionError("Couldn't read jar file URL from bundle: " + ex); + } + } + if (urlConnection instanceof JarURLConnection) { + return (JarURLConnection)urlConnection; + } else { + throw new AssertionError( + "Unknown URLConnection type: " + urlConnection.getClass().getName()); + } + } + + public void detect(final ResourceIterator iterator) throws IOException { + InputStream stream; + while ((stream = iterator.next()) != null) { + try { + cpBuffer.readFrom(stream); + if (hasCafebabe(cpBuffer)) { + detect(cpBuffer); + } // else ignore + } catch (Throwable t) { + // catch all errors + if (!(stream instanceof FileInputStream)) { + // in case of an error we close the ZIP File here + stream.close(); + } + } finally { + // closing InputStream from ZIP Entry is handled by ZipFileIterator + if (stream instanceof FileInputStream) { + stream.close(); + } + } + } + } + + private boolean hasCafebabe(final ClassFileBuffer buffer) throws IOException { + return buffer.size() > 4 && buffer.readInt() == 0xCAFEBABE; + } + + /** + * Inspect the given (Java) class file in streaming mode. + */ + private void detect(final DataInput di) throws IOException { + readVersion(di); + readConstantPoolEntries(di); + readAccessFlags(di); + readThisClass(di); + readSuperClass(di); + readInterfaces(di); + readFields(di); + readMethods(di); + readAttributes(di, 'T', typeReporter == null); + } + + private void readVersion(final DataInput di) throws IOException { + // sequence: minor version, major version (argument_index is 1-based) + if (DEBUG) { + print("Java Class version %2$d.%1$d", + di.readUnsignedShort(), di.readUnsignedShort()); + } else { + di.skipBytes(4); + } + } + + private void readConstantPoolEntries(final DataInput di) throws IOException { + final int count = di.readUnsignedShort(); + constantPool = new Object[count]; + for (int i = 1; i < count; ++i) { + if (readConstantPoolEntry(di, i)) { + // double slot + ++i; + } + } + } + + /** + * Return {@code true} if a double slot is read (in case of Double or Long constant). + */ + private boolean readConstantPoolEntry(final DataInput di, final int index) + throws IOException { + + final int tag = di.readUnsignedByte(); + switch (tag) { + case CP_METHOD_TYPE: + di.skipBytes(2); // readUnsignedShort() + return false; + case CP_METHOD_HANDLE: + di.skipBytes(3); + return false; + case CP_INTEGER: + case CP_FLOAT: + case CP_REF_FIELD: + case CP_REF_METHOD: + case CP_REF_INTERFACE: + case CP_NAME_AND_TYPE: + case CP_INVOKE_DYNAMIC: + di.skipBytes(4); // readInt() / readFloat() / readUnsignedShort() * 2 + return false; + case CP_LONG: + case CP_DOUBLE: + di.skipBytes(8); // readLong() / readDouble() + return true; + case CP_UTF8: + constantPool[index] = di.readUTF(); + return false; + case CP_CLASS: + case CP_STRING: + // reference to CP_UTF8 entry. The referenced index can have a higher number! + constantPool[index] = di.readUnsignedShort(); + return false; + default: + throw new ClassFormatError( + "Unkown tag value for constant pool entry: " + tag); + } + } + + private void readAccessFlags(final DataInput di) throws IOException { + di.skipBytes(2); // u2 + } + + private void readThisClass(final DataInput di) throws IOException { + typeName = resolveUtf8(di); + if (DEBUG) { + print("read type '%s'", typeName); + } + } + + private void readSuperClass(final DataInput di) throws IOException { + di.skipBytes(2); // u2 + } + + private void readInterfaces(final DataInput di) throws IOException { + final int count = di.readUnsignedShort(); + di.skipBytes(count * 2); // count * u2 + } + + private void readFields(final DataInput di) throws IOException { + final int count = di.readUnsignedShort(); + if (DEBUG) { + print("field count = %d", count); + } + for (int i = 0; i < count; ++i) { + readAccessFlags(di); + memberName = resolveUtf8(di); + final String descriptor = resolveUtf8(di); + readAttributes(di, 'F', fieldReporter == null); + if (DEBUG) { + print("Field: %s, descriptor: %s", memberName, descriptor); + } + } + } + + private void readMethods(final DataInput di) throws IOException { + final int count = di.readUnsignedShort(); + if (DEBUG) { + print("method count = %d", count); + } + for (int i = 0; i < count; ++i) { + readAccessFlags(di); + memberName = resolveUtf8(di); + final String descriptor = resolveUtf8(di); + readAttributes(di, 'M', methodReporter == null); + if (DEBUG) { + print("Method: %s, descriptor: %s", memberName, descriptor); + } + } + } + + private void readAttributes(final DataInput di, final char reporterType, + final boolean skipReporting) throws IOException { + + final int count = di.readUnsignedShort(); + if (DEBUG) { + print("attribute count (%s) = %d", reporterType, count); + } + for (int i = 0; i < count; ++i) { + final String name = resolveUtf8(di); + // in bytes, use this to skip the attribute info block + final int length = di.readInt(); + if (!skipReporting && + ("RuntimeVisibleAnnotations".equals(name) || + "RuntimeInvisibleAnnotations".equals(name))) { + readAnnotations(di, reporterType); + } else { + if (DEBUG) { + print("skip attribute %s", name); + } + di.skipBytes(length); + } + } + } + + private void readAnnotations(final DataInput di, final char reporterType) + throws IOException { + + // the number of Runtime(In)VisibleAnnotations + final int count = di.readUnsignedShort(); + if (DEBUG) { + print("annotation count (%s) = %d", reporterType, count); + } + for (int i = 0; i < count; ++i) { + final String rawTypeName = readAnnotation(di); + final Class type = annotations.get(rawTypeName); + if (type == null) { + continue; + } + final String externalTypeName = typeName.replace('/', '.'); + switch (reporterType) { + case 'T': + typeReporter.reportTypeAnnotation(type, externalTypeName); + break; + case 'F': + fieldReporter.reportFieldAnnotation(type, externalTypeName, memberName); + break; + case 'M': + methodReporter.reportMethodAnnotation(type, externalTypeName, memberName); + break; + default: + throw new AssertionError("reporterType=" + reporterType); + } + } + } + + private String readAnnotation(final DataInput di) throws IOException { + final String rawTypeName = resolveUtf8(di); + // num_element_value_pairs + final int count = di.readUnsignedShort(); + if (DEBUG) { + print("annotation elements count: %d", count); + } + for (int i = 0; i < count; ++i) { + if (DEBUG) { + print("element '%s'", resolveUtf8(di)); + } else { + di.skipBytes(2); + } + readAnnotationElementValue(di); + } + return rawTypeName; + } + + + private void readAnnotationElementValue(final DataInput di) throws IOException { + final int tag = di.readUnsignedByte(); + if (DEBUG) { + print("tag='%c'", (char)tag); + } + switch (tag) { + case BYTE: + case CHAR: + case DOUBLE: + case FLOAT: + case INT: + case LONG: + case SHORT: + case BOOLEAN: + case STRING: + di.skipBytes(2); + break; + case ENUM: + di.skipBytes(4); // 2 * u2 + break; + case CLASS: + di.skipBytes(2); + break; + case ANNOTATION: + readAnnotation(di); + break; + case ARRAY: + final int count = di.readUnsignedShort(); + for (int i = 0; i < count; ++i) { + readAnnotationElementValue(di); + } + break; + default: + throw new ClassFormatError("Not a valid annotation element type tag: 0x" + + Integer.toHexString(tag)); + } + } + + /** + * Look up the String value, identified by the u2 index value from constant pool + * (direct or indirect). + */ + private String resolveUtf8(final DataInput di) throws IOException { + final int index = di.readUnsignedShort(); + final Object value = constantPool[index]; + final String s; + if (value instanceof Integer) { + s = (String)constantPool[(Integer)value]; + if (DEBUG) { + print("resolveUtf8(%d): %d --> %s", index, value, s); + } + } else { + s = (String)value; + if (DEBUG) { + print("resolveUtf8(%d): %s", index, s); + } + } + + return s; + } + + /** + * Helper method for simple (debug) logging. + */ + private static void print(final String message, final Object... args) { + if (DEBUG) { + final String logMessage; + if (args.length == 0) { + logMessage = message; + } else { + for (int i = 0; i < args.length; ++i) { + // arguments may be null + if (args[i] == null) { + continue; + } + if (args[i].getClass().isArray()) { + // cast back to array! Note that primitive arrays are not supported + args[i] = Arrays.toString((Object[])args[i]); + } else if (args[i] == Class.class) { + args[i] = ((Class)args[i]).getName(); + } + } + logMessage = String.format(message, args); + } + System.out.println(logMessage); + } + } + +} diff --git a/src/eu/infomas/annotation/ClassFileBuffer.java b/src/eu/infomas/annotation/ClassFileBuffer.java new file mode 100644 index 0000000..f6020a8 --- /dev/null +++ b/src/eu/infomas/annotation/ClassFileBuffer.java @@ -0,0 +1,240 @@ +/* ClassFileBuffer.java + * + * Created: 2011-10-10 (Year-Month-Day) + * Character encoding: UTF-8 + * + ****************************************** LICENSE ******************************************* + * + * Copyright (c) 2011 - 2013 XIAM Solutions B.V. (http://www.xiam.nl) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package eu.infomas.annotation; + +import java.io.DataInput; +import java.io.DataInputStream; +import java.io.EOFException; +import java.io.IOException; +import java.io.InputStream; + +/** + * {@code ClassFileBuffer} is used by {@link AnnotationDetector} to efficiently read Java + * ClassFile files from an {@link InputStream} and parse the content via the {@link DataInput} + * interface. + *

+ * Note that Java ClassFile files can grow really big, + * {@code com.sun.corba.se.impl.logging.ORBUtilSystemException} is 128.2 kb! + * + * @author Ronald K. Muller + * @since annotation-detector 3.0.0 + */ +final class ClassFileBuffer implements DataInput { + + private byte[] buffer; + private int size; // the number of significant bytes read + private int pointer; // the "read pointer" + + /** + * Create a new, empty {@code ClassFileBuffer} with the default initial capacity (8 kb). + */ + ClassFileBuffer() { + this(8 * 1024); + } + + /** + * Create a new, empty {@code ClassFileBuffer} with the specified initial capacity. + * The initial capacity must be greater than zero. The internal buffer will grow + * automatically when a higher capacity is required. However, buffer resizing occurs + * extra overhead. So in good initial capacity is important in performance critical + * situations. + */ + ClassFileBuffer(final int initialCapacity) { + if (initialCapacity < 1) { + throw new IllegalArgumentException("initialCapacity < 1: " + initialCapacity); + } + this.buffer = new byte[initialCapacity]; + } + + /** + * Clear and fill the buffer of this {@code ClassFileBuffer} with the + * supplied byte stream. + * The read pointer is reset to the start of the byte array. + */ + public void readFrom(final InputStream in) throws IOException { + pointer = 0; + size = 0; + int n; + do { + n = in.read(buffer, size, buffer.length - size); + if (n > 0) { + size += n; + } + resizeIfNeeded(); + } while (n >= 0); + } + + /** + * Sets the file-pointer offset, measured from the beginning of this file, + * at which the next read or write occurs. + */ + public void seek(final int position) throws IOException { + if (position < 0) { + throw new IllegalArgumentException("position < 0: " + position); + } + if (position > size) { + throw new EOFException(); + } + this.pointer = position; + } + + /** + * Return the size (in bytes) of this Java ClassFile file. + */ + public int size() { + return size; + } + + // DataInput + + @Override + public void readFully(final byte[] bytes) throws IOException { + readFully(bytes, 0, bytes.length); + } + + @Override + public void readFully(final byte[] bytes, final int offset, final int length) + throws IOException { + + if (length < 0 || offset < 0 || offset + length > bytes.length) { + throw new IndexOutOfBoundsException(); + } + if (pointer + length > size) { + throw new EOFException(); + } + System.arraycopy(buffer, pointer, bytes, offset, length); + pointer += length; + } + + @Override + public int skipBytes(final int n) throws IOException { + seek(pointer + n); + return n; + } + + @Override + public byte readByte() throws IOException { + if (pointer >= size) { + throw new EOFException(); + } + return buffer[pointer++]; + } + + @Override + public boolean readBoolean() throws IOException { + return readByte() != 0; + } + + @Override + public int readUnsignedByte() throws IOException { + if (pointer >= size) { + throw new EOFException(); + } + return read(); + } + + @Override + public int readUnsignedShort() throws IOException { + if (pointer + 2 > size) { + throw new EOFException(); + } + return (read() << 8) + read(); + } + + @Override + public short readShort() throws IOException { + return (short)readUnsignedShort(); + } + + @Override + public char readChar() throws IOException { + return (char)readUnsignedShort(); + } + + @Override + public int readInt() throws IOException { + if (pointer + 4 > size) { + throw new EOFException(); + } + return (read() << 24) + + (read() << 16) + + (read() << 8) + + read(); + } + + @Override + public long readLong() throws IOException { + if (pointer + 8 > size) { + throw new EOFException(); + } + return ((long)read() << 56) + + ((long)read() << 48) + + ((long)read() << 40) + + ((long)read() << 32) + + (read() << 24) + + (read() << 16) + + (read() << 8) + + read(); + } + + @Override + public float readFloat() throws IOException { + return Float.intBitsToFloat(readInt()); + } + + @Override + public double readDouble() throws IOException { + return Double.longBitsToDouble(readLong()); + } + + /** + * This methods throws an {@link UnsupportedOperationException} because the method + * is deprecated and not used in the context of this implementation. + * + * @deprecated Does not support UTF-8, use readUTF() instead + */ + @Override + @Deprecated + public String readLine() throws IOException { + throw new UnsupportedOperationException("readLine() is deprecated and not supported"); + } + + @Override + public String readUTF() throws IOException { + return DataInputStream.readUTF(this); + } + + // private + + private int read() { + return buffer[pointer++] & 0xff; + } + + private void resizeIfNeeded() { + if (size >= buffer.length) { + final byte[] newBuffer = new byte[buffer.length * 2]; + System.arraycopy(buffer, 0, newBuffer, 0, buffer.length); + buffer = newBuffer; + } + } + +} diff --git a/src/eu/infomas/annotation/ClassFileIterator.java b/src/eu/infomas/annotation/ClassFileIterator.java new file mode 100644 index 0000000..efa9936 --- /dev/null +++ b/src/eu/infomas/annotation/ClassFileIterator.java @@ -0,0 +1,146 @@ +/* ClassFileIterator.java + * + * Created: 2011-10-10 (Year-Month-Day) + * Character encoding: UTF-8 + * + ****************************************** LICENSE ******************************************* + * + * Copyright (c) 2011 - 2013 XIAM Solutions B.V. (http://www.xiam.nl) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package eu.infomas.annotation; + +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.zip.ZipFile; + +/** + * {@code ClassFileIterator} is used to iterate over all Java ClassFile files available within + * a specific context. + *

+ * For every Java ClassFile ({@code .class}) an {@link InputStream} is returned. + * + * @author Ronald K. Muller + * @since annotation-detector 3.0.0 + */ +public final class ClassFileIterator extends ResourceIterator { + + private final FileIterator fileIterator; + private final String[] pkgNameFilter; + private ZipFileIterator zipIterator; + + /** + * Create a new {@code ClassFileIterator} returning all Java ClassFile files available + * from the class path ({@code System.getProperty("java.class.path")}). + */ + ClassFileIterator() { + this(classPath(), null); + } + + /** + * Create a new {@code ClassFileIterator} returning all Java ClassFile files available + * from the specified files and/or directories, including sub directories. + *

+ * If the (optional) package filter is defined, only class files staring with one of the + * defined package names are returned. + * NOTE: package names must be defined in the native format (using '/' instead of '.'). + */ + public ClassFileIterator(final File[] filesOrDirectories, final String[] pkgNameFilter) { + this.fileIterator = new FileIterator(filesOrDirectories); + this.pkgNameFilter = pkgNameFilter; + } + + /** + * Return the name of the Java ClassFile returned from the last call to {@link #next()}. + * The name is either the path name of a file or the name of an ZIP/JAR file entry. + */ + public String getName() { + // Both getPath() and getName() are very light weight method calls + return zipIterator == null ? + fileIterator.getFile().getPath() : + zipIterator.getEntry().getName(); + } + + @Override + public InputStream next() throws IOException { + while (true) { + if (zipIterator == null) { + final File file = fileIterator.next(); + // not all specified Files exists! + if (file == null || !file.isFile()) { + return null; + } else { + final String name = file.getName(); + if (name.endsWith(".class")) { + return new FileInputStream(file); + } else if (fileIterator.isRootFile() && + (endsWithIgnoreCase(name, ".jar") || isZipFile(file))) { + zipIterator = new ZipFileIterator(new ZipFile(file), pkgNameFilter); + } // else just ignore + } + } else { + final InputStream is = zipIterator.next(); + if (is == null) { + zipIterator = null; + } else { + return is; + } + } + } + } + + // private + + private boolean isZipFile(final File file) { + DataInputStream in = null; + try { + in = new DataInputStream(new FileInputStream(file)); + final int n = in.readInt(); + return n == 0x504b0304; + } catch (IOException ex) { + // silently ignore read exceptions + return false; + } finally { + if (in != null) { + try { + in.close(); + } catch (IOException ex) { + // ignore + } + } + } + } + + /** + * Returns the class path of the current JVM instance as an array of {@link File} objects. + */ + private static File[] classPath() { + final String[] fileNames = + System.getProperty("java.class.path").split(File.pathSeparator); + final File[] files = new File[fileNames.length]; + for (int i = 0; i < files.length; ++i) { + files[i] = new File(fileNames[i]); + } + return files; + } + + private static boolean endsWithIgnoreCase(final String value, final String suffix) { + final int n = suffix.length(); + return value.regionMatches(true, value.length() - n, suffix, 0, n); + } + +} diff --git a/src/eu/infomas/annotation/FileIterator.java b/src/eu/infomas/annotation/FileIterator.java new file mode 100644 index 0000000..aa9bc22 --- /dev/null +++ b/src/eu/infomas/annotation/FileIterator.java @@ -0,0 +1,122 @@ +/* FileIterator.java + * + * Created: 2011-10-10 (Year-Month-Day) + * Character encoding: UTF-8 + * + ****************************************** LICENSE ******************************************* + * + * Copyright (c) 2011 - 2013 XIAM Solutions B.V. (http://www.xiam.nl) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package eu.infomas.annotation; + +import java.io.File; +import java.io.IOException; +import java.util.Deque; +import java.util.LinkedList; +import java.util.NoSuchElementException; + +/** + * {@code FileIterator} enables iteration over all files in a directory and all its sub + * directories. + *

+ * Usage: + *

+ * FileIterator iter = new FileIterator(new File("./src"));
+ * File f;
+ * while ((f = iter.next()) != null) {
+ *     // do something with f
+ *     assert f == iter.getCurrent();
+ * }
+ * 
+ * + * @author Ronald K. Muller + * @since annotation-detector 3.0.0 + */ +final class FileIterator { + + private final Deque stack = new LinkedList(); + private int rootCount; + private File current; + + /** + * Create a new {@code FileIterator} using the specified 'filesOrDirectories' as root. + *

+ * If 'filesOrDirectories' contains a file, the iterator just returns that single file. + * If 'filesOrDirectories' contains a directory, all files in that directory + * and its sub directories are returned (depth first). + * + * @param filesOrDirectories Zero or more {@link File} objects, which are iterated + * in the specified order (depth first) + */ + FileIterator(final File... filesOrDirectories) { + addReverse(filesOrDirectories); + rootCount = stack.size(); + } + + /** + * Return the last returned file or {@code null} if no more files are available. + * + * @see #next() + */ + public File getFile() { + return current; + } + + /** + * Return {@code true} if the current file is one of the files originally + * specified as one of the constructor file parameters, i.e. is a root file + * or directory. + */ + public boolean isRootFile() { + if (current == null) { + throw new NoSuchElementException(); + } + return stack.size() < rootCount; + } + + /** + * Return the next {@link File} object or {@code null} if no more files are + * available. + * + * @see #getFile() + */ + public File next() throws IOException { + if (stack.isEmpty()) { + current = null; + return null; + } else { + current = stack.removeLast(); + if (current.isDirectory()) { + if (stack.size() < rootCount) { + rootCount = stack.size(); + } + addReverse(current.listFiles()); + return next(); + } else { + return current; + } + } + } + + /** + * Add the specified files in reverse order. + */ + private void addReverse(final File[] files) { + for (int i = files.length - 1; i >= 0; --i) { + stack.add(files[i]); + } + } + +} diff --git a/src/eu/infomas/annotation/README.txt b/src/eu/infomas/annotation/README.txt new file mode 100644 index 0000000..317120d --- /dev/null +++ b/src/eu/infomas/annotation/README.txt @@ -0,0 +1,7 @@ +Code adapted from master branch of: +https://github.com/rmuller/infomas-asl + +Cannot be included as is, even with a JAR since this package includes a class requiring a JBoss dependency. +Since this JBoss stuff is not used in BeeDeeM, simply remove the class VfsResourceIterator.java + +P. Durand, Jan 2023 \ No newline at end of file diff --git a/src/eu/infomas/annotation/ResourceIterator.java b/src/eu/infomas/annotation/ResourceIterator.java new file mode 100644 index 0000000..56ddb34 --- /dev/null +++ b/src/eu/infomas/annotation/ResourceIterator.java @@ -0,0 +1,43 @@ +/* ResourceIterator.java + * + * Created: 2015-10-17 (Year-Month-Day) + * Character encoding: UTF-8 + * + ****************************************** LICENSE ******************************************* + * + * Copyright (c) 2015 XIAM Solutions B.V. (http://www.xiam.nl) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package eu.infomas.annotation; + +import java.io.IOException; +import java.io.InputStream; + +/** + * {@code ResourceIterator} is an abstraction for an iterator of (Java) Class Files, provided + * as {@link InputStream}. + * + * @author Ronald K. Muller + * @since INFOMAS NG 3.0 + */ +public abstract class ResourceIterator { + + /** + * Return the next Java ClassFile as an {@code InputStream}. + *

+ * NOTICE: Client code MUST close the returned {@code InputStream}! + */ + public abstract InputStream next() throws IOException; + +} diff --git a/src/eu/infomas/annotation/ZipFileIterator.java b/src/eu/infomas/annotation/ZipFileIterator.java new file mode 100644 index 0000000..29d7051 --- /dev/null +++ b/src/eu/infomas/annotation/ZipFileIterator.java @@ -0,0 +1,99 @@ +/* ZipFileIterator.java + * + * Created: 2011-10-10 (Year-Month-Day) + * Character encoding: UTF-8 + * + ****************************************** LICENSE ******************************************* + * + * Copyright (c) 2011 - 2013 XIAM Solutions B.V. (http://www.xiam.nl) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package eu.infomas.annotation; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Enumeration; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +/** + * {@code ZipFileIterator} is used to iterate over all entries in a given {@code zip} or + * {@code jar} file and returning the {@link InputStream} of these entries. + *

+ * It is possible to specify an (optional) entry name filter. + *

+ * The most efficient way of iterating is used, see benchmark in test classes. + * + * @author Ronald K. Muller + * @since annotation-detector 3.0.0 + */ +final class ZipFileIterator { + + private final ZipFile zipFile; + private final String[] entryNameFilter; + private final Enumeration entries; + + private ZipEntry current; + + /** + * Create a new {@code ZipFileIterator} instance. + * + * @param zipFile The ZIP file used to iterate over all entries + * @param entryNameFilter (optional) file name filter. Only entry names starting with + * one of the specified names in the filter are returned + */ + ZipFileIterator(final ZipFile zipFile, final String[] entryNameFilter) throws IOException { + this.zipFile = zipFile; + this.entryNameFilter = entryNameFilter; + + this.entries = zipFile.entries(); + } + + public ZipEntry getEntry() { + return current; + } + + public InputStream next() throws IOException { + while (entries.hasMoreElements()) { + current = entries.nextElement(); + if (accept(current)) { + return zipFile.getInputStream(current); + } + } + // no more entries in this ZipFile, so close ZipFile + try { + // zipFile is never null here + zipFile.close(); + } catch (IOException ex) { + // suppress IOException, otherwise close() is called twice + } + return null; + } + + private boolean accept(final ZipEntry entry) { + if (entry.isDirectory()) { + return false; + } + if (entryNameFilter == null) { + return true; + } + for (final String filter : entryNameFilter) { + if (entry.getName().startsWith(filter)) { + return true; + } + } + return false; + } + +} diff --git a/src/eu/infomas/annotation/package-info.java b/src/eu/infomas/annotation/package-info.java new file mode 100644 index 0000000..46e9638 --- /dev/null +++ b/src/eu/infomas/annotation/package-info.java @@ -0,0 +1,29 @@ +/* package-info.java + * + * Created: 2013-07-09 (Year-Month-Day) + * Character encoding: UTF-8 + * + ****************************************** LICENSE ******************************************* + * + * Copyright (c) 2013 XIAM Solutions B.V. (http://www.xiam.nl) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * This library can be used to scan (part of) the class path for annotated classes, + * methods or instance variables. + *

+ * For more information see + * Github site. + */ +package eu.infomas.annotation; From 8189dca35c0296f10e474d9988e426875a935641 Mon Sep 17 00:00:00 2001 From: pgdurand Date: Thu, 5 Jan 2023 19:31:53 +0100 Subject: [PATCH 20/26] fix log init to take into account new reflective API --- src/bzh/plealog/dbmirror/util/log/LoggerCentral.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bzh/plealog/dbmirror/util/log/LoggerCentral.java b/src/bzh/plealog/dbmirror/util/log/LoggerCentral.java index 60f1186..0fc2202 100755 --- a/src/bzh/plealog/dbmirror/util/log/LoggerCentral.java +++ b/src/bzh/plealog/dbmirror/util/log/LoggerCentral.java @@ -294,7 +294,7 @@ private static void initLoggers(ConfigurationBuilder builder builder.newAppenderRef(refAppender)).addAttribute("additivity", false)); builder.add(builder.newRootLogger(aLevel).add(builder.newAppenderRef(refAppender))); - Configurator.initialize(builder.build()); + Configurator.reconfigure(builder.build()); } /** @@ -336,7 +336,7 @@ private static void configureRollingFileLogger(Level aLevel, String logName) { userPath = getLogAppPath(); szLogFileName = userPath + _logAppFile; szLogFilePattern = userPath + "%d{MM-dd-yy}-" + _logAppFile; - + System.out.println("**** LogFile: "+szLogFileName); try { cleanSystemLogs(userPath, _logAppFile); } catch (Exception e) { From 42bb82c42f0febf918fc8fee252d63d8f02cb004 Mon Sep 17 00:00:00 2001 From: pgdurand Date: Fri, 6 Jan 2023 15:05:03 +0100 Subject: [PATCH 21/26] update legacy installer and test script --- build.xml | 23 +++++------------------ scripts/test_bdm.sh | 33 ++++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/build.xml b/build.xml index 8f9abe0..29979f6 100644 --- a/build.xml +++ b/build.xml @@ -38,13 +38,8 @@ - - - - - - - + + @@ -217,16 +212,8 @@ - - - - - - - - - - + + @@ -266,7 +253,7 @@ - + diff --git a/scripts/test_bdm.sh b/scripts/test_bdm.sh index 4fd2dba..a990cb7 100755 --- a/scripts/test_bdm.sh +++ b/scripts/test_bdm.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # ================================================= -# Test script for BeeDeeM legacy installer. +# Test script for BeeDeeM legacy installer or Conda. # To be used directly on the command-line. # DO NOT use for Singularity/Docker installations. # @@ -10,21 +10,28 @@ # Step 1: install BeeDeeM as stated at: # https://pgdurand.gitbook.io/beedeem/installation/installation#legacy-installation # -# Step 2: run test as follows: -# ./test_bdm.sh +# Step 2: run test as follows: +# cd /path/to/beedeem +# export PATH=$PWD:$PATH +# ./test_bdm # -- # P. Durand (SeBiMER, Ifremer), last updated on Jan 2023 # ================================================= + # == TEST 1 =========================================== echo "*** TEST 1: Start simple bank installation" -# set log mode to console (otherwise default is a log file located in KL_WORKING_DIR + +# set BeeDeeM log mode to console (otherwise default is a log file located in KL_WORKING_DIR) export KL_LOG_TYPE=console + # Set the bank to install # This is a '.dsc' file located in BeeDeeM installation path at ${beedeem-home}/conf/descriptors DESCRIPTOR="SwissProt_human" + # start BeeDeeM with 'install' command -./bdm install -desc ${DESCRIPTOR} +bdm install -desc ${DESCRIPTOR} + # check whether command succeeded or not if [ $? -eq 0 ]; then echo "TEST 1: SUCCESS" @@ -33,12 +40,16 @@ else exit 1 fi + # == TEST 2 =========================================== echo "*** TEST 2: list installed bank" -# reset log mode to file + +# reset BeeDeeM log mode to file (default) export KL_LOG_TYPE=file + # start BeeDeeM with 'info' command -./bdm info -d all -f txt +bdm info -d all -f txt + if [ $? -eq 0 ]; then echo "TEST 2: SUCCESS" else @@ -46,13 +57,17 @@ else exit 1 fi + # == TEST 3 =========================================== -# Change default log file name to something else +# Change default BeeDeeM log file name to something else export KL_LOG_FILE=query.log + SW_ENTRY="ZZZ3_HUMAN" echo "*** TEST 3: query bank for entry: $SW_ENTRY" + # start BeeDeeM with 'query' command -./bdm query -d protein -f txt -i $SW_ENTRY +bdm query -d protein -f txt -i $SW_ENTRY + if [ $? -eq 0 ]; then echo "TEST 3: SUCCESS" else From 4785119f661648401076f6ac75a8eddb488d70db Mon Sep 17 00:00:00 2001 From: pgdurand Date: Fri, 6 Jan 2023 15:27:38 +0100 Subject: [PATCH 22/26] check availability of realpath command --- scripts/bdm.bat | 43 ------------------------------------------- scripts/bdm.sh | 12 ++++++++---- 2 files changed, 8 insertions(+), 47 deletions(-) delete mode 100755 scripts/bdm.bat diff --git a/scripts/bdm.bat b/scripts/bdm.bat deleted file mode 100755 index 4497b95..0000000 --- a/scripts/bdm.bat +++ /dev/null @@ -1,43 +0,0 @@ -@echo off - -rem -rem BeeDeeM starter command for Windows -rem Copyright (c) - Patrick G. Durand, 2007-2022 -rem ------------------------------------------------------------------- -rem User manual: -rem https://pgdurand.gitbooks.io/beedeem/ -rem ------------------------------------------------------------------- -rem Command use: -rem bdm.bat -h: to get help -rem bdm.bat [options]: to start a command -rem -rem In addition, some parameters can be passed to the JVM for special -rem configuration purposes:
-rem -DKL_DEBUG=true ; if true, if set, log will be in debug mode
-rem -DKL_WORKING_DIR=an_absolute_path ; if not set, log and working -rem directories are set to java.io.tmp
-rem -DKL_LOG_FILE=a_file_name ; if set, creates a log file with that -rem name within KL_WORKING_DIR

-rem -DKL_CONF_DIR=an_absolute_path ; the absolute path to a home-made -rem conf directory. If not set, use ${user.dir}/conf. -rem -DKL_LOG_TYPE=none|console|file(default) -rem -rem Proxy configuration: update configuration file: -rem ${beedeemHome}/conf/system/network.config. - -rem *** Application home -set KL_APP_HOME=@KL_INSTALL_DIR@ - -rem *** Working directory -set KL_WORKING_DIR=@KL_WORKING_DIR@ - -rem *** Java VM -set KL_JAVA_ARGS=-Xms128M -Xmx1024M -DKL_HOME="%KL_APP_HOME%" -DKL_WORKING_DIR="%KL_WORKING_DIR%" - -rem *** Create classpath -SETLOCAL ENABLEDELAYEDEXPANSION -set FILES= -for /F %%f in ('dir /b %KL_APP_HOME%\bin\*.jar') do set FILES=!FILES!;%KL_APP_HOME%\bin\%%f - -rem *** Start application -java.exe %KL_JAVA_ARGS% -classpath "%FILES%" bzh.plealog.dbmirror.main.BeeDeeMain %* diff --git a/scripts/bdm.sh b/scripts/bdm.sh index 0a41c91..654495a 100755 --- a/scripts/bdm.sh +++ b/scripts/bdm.sh @@ -29,10 +29,14 @@ # Proxy configuration: update configuration file: # ${beedeemHome}/conf/system/network.config. -# *** Bank installation scripts of BeeDeeM (conf/scripts) requires BASH 5 -BASH_VER=$(bash --version | grep ", version" | cut -d' ' -f4 | cut -d'.' -f1) -if [ "$BASH_VER" -lt "5" ]; then - echo "/!\ ERROR: BeeDeeM requires BASH release 5 (yours is: $BASH_VER)" +# *** Bank installation scripts of BeeDeeM (conf/scripts) requires realpath: +# available in BASH 5 for macOS +# or available from Linux:coreutils +which realpath +if [ ! $? -eq 0 ]; then + echo "/!\ ERROR: realpath command not found" + echo " macOS: install bash 5" + echo " Linux: install coreutils" exit 1 fi From 655fcc1a031cc594b6be8844335a73bb32ee87c1 Mon Sep 17 00:00:00 2001 From: pgdurand Date: Fri, 6 Jan 2023 15:27:57 +0100 Subject: [PATCH 23/26] fic comments --- TODOs.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/TODOs.txt b/TODOs.txt index 355bf24..09b7cd2 100755 --- a/TODOs.txt +++ b/TODOs.txt @@ -1,6 +1,3 @@ -- MaJ descripteurs avec dépendances ; temporairement virer pfam (marche plus ?) -- MaJ doc: formatdb->makeblastdb - remote: warning: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com. remote: warning: See http://git.io/iEPt8g for more information. remote: warning: File tests/junit/databank/fasta_multi2/fasta4.faa is 64.63 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB From a1a9157642b56f0d928305d27a89a5718f077546 Mon Sep 17 00:00:00 2001 From: pgdurand Date: Fri, 6 Jan 2023 15:28:44 +0100 Subject: [PATCH 24/26] drop native support of Windows; Windows users should rely on Windows Linux Subsystem --- scripts/deploy-std.xml | 52 ++++-------------------------------------- 1 file changed, 5 insertions(+), 47 deletions(-) diff --git a/scripts/deploy-std.xml b/scripts/deploy-std.xml index d787c4a..d896786 100755 --- a/scripts/deploy-std.xml +++ b/scripts/deploy-std.xml @@ -1,7 +1,11 @@ @@ -13,10 +17,6 @@ - - - - This is the Ant project file to install BeeDeeM. @@ -81,7 +81,6 @@ - @@ -97,10 +96,6 @@
- - - - @@ -108,26 +103,6 @@
- - - - - - - - - - - - - - - - - - - - @@ -148,23 +123,6 @@ - - - - - - - - - - - - - - - From dfb778a9a5ef17bad60a6f16a583dc3af1b3a1a2 Mon Sep 17 00:00:00 2001 From: pgdurand Date: Fri, 6 Jan 2023 19:12:05 +0100 Subject: [PATCH 25/26] drop support of Windows; use WLS instead on windows --- build.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build.xml b/build.xml index 29979f6..23189b5 100644 --- a/build.xml +++ b/build.xml @@ -211,9 +211,8 @@ - + - From ed32b72b02e6e3c1c19bafebf52dffe654ad6dad Mon Sep 17 00:00:00 2001 From: pgdurand Date: Fri, 6 Jan 2023 19:12:29 +0100 Subject: [PATCH 26/26] remove debug log message --- src/bzh/plealog/dbmirror/util/log/LoggerCentral.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/bzh/plealog/dbmirror/util/log/LoggerCentral.java b/src/bzh/plealog/dbmirror/util/log/LoggerCentral.java index 0fc2202..c3524c6 100755 --- a/src/bzh/plealog/dbmirror/util/log/LoggerCentral.java +++ b/src/bzh/plealog/dbmirror/util/log/LoggerCentral.java @@ -336,7 +336,6 @@ private static void configureRollingFileLogger(Level aLevel, String logName) { userPath = getLogAppPath(); szLogFileName = userPath + _logAppFile; szLogFilePattern = userPath + "%d{MM-dd-yy}-" + _logAppFile; - System.out.println("**** LogFile: "+szLogFileName); try { cleanSystemLogs(userPath, _logAppFile); } catch (Exception e) {