From 3d2b40c1dfed640f6f4e8e19039b4a53d44130ff Mon Sep 17 00:00:00 2001 From: Rostyslav Golda Date: Mon, 19 Jul 2021 12:44:14 +0300 Subject: [PATCH 01/11] Added picocli dependencies, updated bom-ext dependency --- apl-bom/pom.xml | 2 +- apl-db-updater/pom.xml | 2 +- apl-exec/pom.xml | 4 + pom.xml | 2 +- updater/upd | 261 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 268 insertions(+), 3 deletions(-) create mode 100644 updater/upd diff --git a/apl-bom/pom.xml b/apl-bom/pom.xml index 3dbd2863a1..2634249ca0 100644 --- a/apl-bom/pom.xml +++ b/apl-bom/pom.xml @@ -53,7 +53,7 @@ com.apollocurrency apl-bom-ext - 1.0.5 + 1.0.8 pom import diff --git a/apl-db-updater/pom.xml b/apl-db-updater/pom.xml index cf63c8bd52..e40cec992d 100644 --- a/apl-db-updater/pom.xml +++ b/apl-db-updater/pom.xml @@ -16,7 +16,7 @@ com.apollocurrency apl-bom-ext - 1.0.5 + 1.0.8 pom import diff --git a/apl-exec/pom.xml b/apl-exec/pom.xml index 824785c031..91ac208505 100644 --- a/apl-exec/pom.xml +++ b/apl-exec/pom.xml @@ -82,6 +82,10 @@ mockito-junit-jupiter test + + info.picocli + picocli + diff --git a/pom.xml b/pom.xml index c091322c4c..9584d25740 100644 --- a/pom.xml +++ b/pom.xml @@ -64,7 +64,7 @@ 1.1.3 - 1.0.6 + 1.0.8 ApolloWallet/apollo-blockchain 1.9.1 diff --git a/updater/upd b/updater/upd new file mode 100644 index 0000000000..ba906f932a --- /dev/null +++ b/updater/upd @@ -0,0 +1,261 @@ +#!/bin/bash +# This script invoked by update.sh script to detach script process from Java main app +# first parameter is a current directory, where wallet is executing now (directory, which we should update) +# second parameter is a update directory which contains unpacked jar for update +# third parameter is a boolean flag, which indicates desktop mode + +APOLLO_JAR="apl-exec" + +APLCMDLINE=$(cat ~/.apl-blockchain/apl.cmdline 2>/dev/null) + +unamestr=`uname` + + +function notify +{ + if [[ "$unamestr" == 'Darwin' ]]; then + osascript -e "display notification \"$1\" with title \"Apollo\"" + else + echo $1 + fi +} + +function getNetwork() +{ + NETWORK=0 + if [ $(cat ~/.apl-blockchain/apl.cmdline | grep "\-n" | wc -l) -eq 1 ] + then + NETWORK=$(cat ~/.apl-blockchain/apl.cmdline | grep -oE "(\-n|\-\-net)\s{1,}[0-9]{1}" | cut -f2 -d' ') + else + NETWORK=0 + fi + + +} + +function getConfigPath() +{ + getNetwork + if [ ${NETWORK} -eq 0 ] + then + CONFIGDIR=conf + else + CONFIGDIR=conf-tn${NETWORK} + fi + + if [ $3 == "true" ] + then + CONFIGDIR=~/.apl-blockchain/${CONFIGDIR} + else + CONFIGDIR=$1/${CONFIGDIR} + fi +} + +function isSharding() +{ + NOSHARD=false + if [ $(cat ~/.apl-blockchain/apl.cmdline | grep -oE "\--no-shards-create\s{1,}true" | wc -l) -eq 1 ] + then + NOSHARD=true + else + if [ $(cat ${CONFIGDIR}/apl-blockchain.properties | grep apl.noshardcreate | grep -v "#" | wc -l ) -eq 1 ] + then + NOSHARD=$(cat ${CONFIGDIR}/apl-blockchain.properties | grep apl.noshardcreate | grep -v "#" | cut -f2 -d'=') + else + NOSHARD=false + fi + fi +} + + +VERSION=$(head -n1 ${2}/apollo-blockchain/VERSION) + +if [[ -d "${1}" ]] && [[ -d "${2}" ]] && [[ -n "${3}" ]] +then + + notify "Starting Apollo Updater" + notify "Stopping Apollo Wallet" + + NEXT_WAIT_TIME=0 + +# For backwards compatibility + if [ ! -f VERSION ]; then +# echo "Runnung from updater directory...." >>/tmp/updater_ne_tuda + cd .. + fi + + kill $(ps -ef | grep apl-de | awk '{ print $2 }') + $1/bin/apl-stop.sh + until [ $(ps aux | grep ${APOLLO_JAR} | grep -v grep | wc -l) -eq 0 ] || [ $NEXT_WAIT_TIME -eq 10 ]; do + NEXT_WAIT_TIME=`expr $NEXT_WAIT_TIME '+' 1` + sleep $NEXT_WAIT_TIME + notify "Waiting more time to stop Apollo Wallet..." + done + +# it is always good idea to backup everything before removing +#NOW=`date +%Y-%m-%dT%H:%m:%S` +#BKP_NAME=${1}/../ApolloWallet-BKP-${NOW}.tar.gz +#tar -czf ${BKP_NAME} ${1} + +# we sould remove "conf" dir because default configs are in resources now +# and user's configs are in ~/.apl_blockchain + if [ -f $1/conf/apl.properties ]; then + rm -rf $1/conf/apl-default.properties + rm -rf $1/conf/testnet.properties + rm -rf $1/conf/updater.properties + cp $1/conf/apl.properties $1/conf/apl-blockchain.properties + cp $1/conf/apl.properties $1/conf/apl.properties.backup + cat $1/conf/apl.properties | grep -v "#" | grep apl.dbDir= | sed s/dbDir/customDbDir/ >> $1/conf/apl-blockchain.properties + rm $1/conf/apl.properties + fi + + if [ -f $1/conf/chains.json ]; then + cp -f $1/conf/chains.json $1/conf/chains.json.backup + rm -f $1/conf/chains.json + fi + + + notify "Removing old version..." + notify "Removing garbage..." + rm -rfv $1/bin + rm -rfv $1/guilib + rm -rfv $1/html-stub + rm -rfv $1/lib + rm -rfv $1/sbin + rm -rfv $1/updater + rm -rfv $1/webui + rm -rfv $1/3RD-PARTY-LICENSES.txt + rm -rfv $1/VERSION* + rm -rfv $1/LICENSE* + rm -rfv $1/*jar + rm -rfv $1/META-INF + rm -rfv $1/update* + + cd $1/.. + rm -rfv apollo-web-ui + rm -rfv apollo-tools + + chmod 755 $1/../apollo-blockchain/bin/*.sh + + cd $1/.. + chmod 755 $1/../apollo-desktop/bin/*.sh + + notify "Removing old version..." + + notify "Moving extra files..." +# cp -Rfv $1/* $1/.. + cd $1/.. +# rm -rfv $1 + cp -Rfv $2/* . + +# cd $1/ +# cp -vRa conf* apollo-blockchain +# cp -vRa conf/* apollo-blockchain/conf +# ./replace_dbdir.sh + +# notify "Creating symlinks..." +# ln -s apollo-blockchain/bin bin + + + chmod 755 apollo-blockchain/bin/*.sh + chmod 755 apollo-desktop/bin/*.sh + + if [[ "$unamestr" == 'Darwin' ]]; then + + echo "#!/bin/bash" > ApolloWallet.app/Contents/MacOS/apl + echo "" >> ApolloWallet.app/Contents/MacOS/apl + echo "cd \"$1/../apollo-desktop/bin\"" >> ApolloWallet.app/Contents/MacOS/apl + echo "./apl-start-desktop.sh" >> ApolloWallet.app/Contents/MacOS/apl + chmod 755 "ApolloWallet+Secure Transport.app/Contents/MacOS/apl" + chmod 755 "ApolloWallet+Secure Transport.app/secureTransport/securenodexchg" + chmod 755 "ApolloWallet+Secure Transport.app/secureTransport/runClient.sh" + chmod 755 "ApolloWallet+Tor.app/Contents/MacOS/apl" + chmod 755 "ApolloWallet+Tor.app/tor/bin/tor" + chmod 755 "ApolloWallet.app/Contents/MacOS/apl" +# rm -rf "$1/ApolloWallet+Secure Transport.app" +# rm -rf "$1/ApolloWallet+Tor.app" +# rm -rf "$1/ApolloWallet.app" + + fi + + if [[ "$unamestr" == 'Linux' ]]; then + + chmod 755 tor/tor + chmod 755 secureTransport/securenodexchg + chmod 755 secureTransport/runClient.sh + fi + +# rm -rf apollo-wallet-deps-${VERSION}.tar.gz +# rm -rf apollo-wallet-deps-* + echo Version = ${VERSION} +# notify "Downloading deps...." +# Commented downloading deps +# wget https://s3.amazonaws.com/updates.apollowallet.org/libs/apollo-wallet-deps-${VERSION}.tar.gz || curl --retry 100 https://s3.amazonaws.com/updates.apollowallet.org/libs/apollo-wallet-deps-${VERSION}.tar.gz -o apollo-wallet-deps-${VERSION}.tar.gz +# tar -zxvf apollo-wallet-deps-${VERSION}.tar.gz +# cp apollo-wallet-deps-${VERSION}/* $1/lib + +# rm -rf apollo-wallet-deps-${VERSION}* + +# Install JRE +# notify "Installing Java Runtime..." +# bash ./update2.sh $1 + +#determine, if shrding was performed or not + + + + + +# Download db with shards + getNetwork + getConfigPath $1 $2 $3 + isSharding + + case ${NETWORK} in + 0) + NETID=b5d7b6 + ;; + 1) + NETID=a2e9b9 + ;; + 2) + NETID=2f2b61 + ;; + *) + NETID=b5d7b6 + + esac + +# TODO: ! refactor and ncomment that block +# if [ "$#" -eq 3 ] +# then +# if [ ${NOSHARD} == false ] +# then +# bash ./update3.sh $1 $2 $3 true ${NETID} +# fi +# else +# bash ./update3.sh $1 $2 $3 $4 $5 +# fi + + + +# notify "Downloading db shards..." + + if [[ -d conf ]]; then + mv -fv conf apollo-blockchain + fi + APLCMDLINE=$(echo ${APLCMDLINE} | sed s/shards/shard/g) + if [ $3 == true ] + then + notify "Starting desktop application..." + cd apollo-desktop/bin + nohup ./apl-start-desktop.sh ${APLCMDLINE} 2>&1 >/dev/null + else + notify "Starting command line application..." + cd apollo-blockchain/bin + ./apl-start.sh ${APLCMDLINE} + fi + +else + echo Invalid input parameters $1,$2,$3 +fi From c4a06f8cb0d4c88235c3404785f96262f10f4e9b Mon Sep 17 00:00:00 2001 From: Rostyslav Golda Date: Wed, 21 Jul 2021 08:00:52 +0300 Subject: [PATCH 02/11] Replaced JCommander parameters to picoCLI options --- .../aplwallet/apl/exec/CmdLineArgs.java | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/CmdLineArgs.java b/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/CmdLineArgs.java index abf14d5dde..b13a19a718 100644 --- a/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/CmdLineArgs.java +++ b/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/CmdLineArgs.java @@ -1,59 +1,61 @@ package com.apollocurrency.aplwallet.apl.exec; -import com.beust.jcommander.Parameter; +import picocli.CommandLine.Option; -/** +/* + * Copyright © 2018-2021 Apollo Foundation * Command line parameters * * @author alukin@gmail.com + * @author tx_hv@ukr.net */ public class CmdLineArgs { public static int DEFAULT_DEBUG_LEVEL = 2; - @Parameter(names = {"--debug", "-d"}, description = "Debug level [0-4] from ERROR to TRACE") + @Option(names = {"--debug", "-d"}, description = "Debug level [0-4] from ERROR to TRACE") public int debug = DEFAULT_DEBUG_LEVEL; - @Parameter(names = {"--debug-updater", "-du"}, description = "Force updater to use debug certificates for verifying update transactions") + @Option(names = {"--debug-updater", "-du"}, description = "Force updater to use debug certificates for verifying update transactions") public boolean debugUpdater; - @Parameter(names = {"--help", "-h"}, help = true, description = "Print help message") + @Option(names = {"--help", "-h"}, help = true, description = "Print help message") public boolean help; - @Parameter(names = {"--service-mode", "-s"}, help = true, description = "Run in service mode with current system user") + @Option(names = {"--service-mode", "-s"}, help = true, description = "Run in service mode with current system user") public boolean serviceMode; - @Parameter(names = {"--ignore-resources"}, description = "Ignore resources bundled with application jar. Default is false") + @Option(names = {"--ignore-resources"}, description = "Ignore resources bundled with application jar. Default is false") public boolean ingnoreResources = false; - @Parameter(names = {"--config-dir", "-c"}, description = "Load all configuration and resources from specified path. System resources not ignored, standard config search is ignored.") + @Option(names = {"--config-dir", "-c"}, description = "Load all configuration and resources from specified path. System resources not ignored, standard config search is ignored.") public String configDir = ""; - @Parameter(names = {"--log-dir", "-l"}, description = "Save log files to from specified directory.") + @Option(names = {"--log-dir", "-l"}, description = "Save log files to from specified directory.") public String logDir = ""; - @Parameter(names = {"--db-dir"}, description = "Load/Save DB files to from specified directory. Ignored if DB URL is remote.") + @Option(names = {"--db-dir"}, description = "Load/Save DB files to from specified directory. Ignored if DB URL is remote.") public String dbDir = ""; - @Parameter(names = {"--vault-key-dir"}, description = "Load/Save vault wallets keys to/form specified keystore directory.") + @Option(names = {"--vault-key-dir"}, description = "Load/Save vault wallets keys to/form specified keystore directory.") public String vaultKeystoreDir = ""; - @Parameter(names = {"--dex-key-dir"}, description = "Load/Save dex keys to/form specified keystore directory.") + @Option(names = {"--dex-key-dir"}, description = "Load/Save dex keys to/form specified keystore directory.") public String dexKeystoreDir = ""; - @Parameter(names = {"--no-shard-import"}, description = "Start from Genesis block, do not try to import last shard") + @Option(names = {"--no-shard-import"}, description = "Start from Genesis block, do not try to import last shard") public boolean noShardImport = false; - @Parameter(names = {"--no-shard-create"}, description = "Do not create shards even if it configured to do so. Shards require much more resources") + @Option(names = {"--no-shard-create"}, description = "Do not create shards even if it configured to do so. Shards require much more resources") public boolean noShardCreate = false; - @Parameter(names = {"--update-attachment-file", "-u"}, description = "Full path to file which represent json of UpdateAttachment for local updates debug") + @Option(names = {"--update-attachment-file", "-u"}, description = "Full path to file which represent json of UpdateAttachment for local updates debug") public String updateAttachmentFile = ""; // TODO cleanup apl-default.properties - @Parameter(names = {"--2fa-dir"}, description = "Load/Save 2FA keys to/form specified directory. Note that this parameter will not work when you do not set apl.store2FAInFileSystem=true in apl-default.properties") + @Option(names = {"--2fa-dir"}, description = "Load/Save 2FA keys to/form specified directory. Note that this Option will not work when you do not set apl.store2FAInFileSystem=true in apl-default.properties") public String twoFactorAuthDir = ""; - @Parameter(names = {"--dexp-dir"}, description = "Export/Import CSV data to/form specified directory.") + @Option(names = {"--dexp-dir"}, description = "Export/Import CSV data to/form specified directory.") public String dataExportDir = ""; - @Parameter(names = {"--pid-file"}, description = "Save PID to specified file.") + @Option(names = {"--pid-file"}, description = "Save PID to specified file.") public String pidFile = ""; - @Parameter(names = {"--net", "-n"}, help = true, description = "Connect to net [0-4]. 0 means mainnet, 1 - 1st testnet and so on") + @Option(names = {"--net", "-n"}, help = true, description = "Connect to net [0-4]. 0 means mainnet, 1 - 1st testnet and so on") public int netIdx = -1; - @Parameter(names = {"--chain", "-C"}, help = true, description = "Connect to net with given chainID. UUID of chain id may be specified partially, 6 symbos min. Configs must be present.") + @Option(names = {"--chain", "-C"}, help = true, description = "Connect to net with given chainID. UUID of chain id may be specified partially, 6 symbos min. Configs must be present.") public String chainId = ""; - @Parameter(names = {"--testnet"}, help = true, description = "Connect to testent 1. Has higher priority then --net") + @Option(names = {"--testnet"}, help = true, description = "Connect to testent 1. Has higher priority then --net") public boolean isTestnet = false; //--- - @Parameter(names = {"--disable-weld-concurrent-deployment"}, + @Option(names = {"--disable-weld-concurrent-deployment"}, description = "If use it, Weld doesn't use ConcurrentDeployer and ConcurrentValidator to build the container. Default value is true.") public boolean disableWeldConcurrentDeployment = false; From 97b734df8cbeb8a50e78676217e713de2b0cff7a Mon Sep 17 00:00:00 2001 From: Rostyslav Golda Date: Thu, 22 Jul 2021 01:37:31 +0300 Subject: [PATCH 03/11] Replaced JCommander to PicoLCI --- .../aplwallet/apl/exec/Apollo.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/Apollo.java b/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/Apollo.java index 17f9c68ad7..e9796df073 100644 --- a/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/Apollo.java +++ b/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/Apollo.java @@ -33,7 +33,6 @@ import com.apollocurrency.aplwallet.apl.util.env.dirprovider.DirProviderFactory; import com.apollocurrency.aplwallet.apl.util.env.dirprovider.PredefinedDirLocations; import com.apollocurrency.aplwallet.apl.util.injectable.PropertiesHolder; -import com.beust.jcommander.JCommander; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,6 +48,8 @@ import java.util.Properties; import java.util.UUID; +import picocli.CommandLine; + /** * Main Apollo startup class * @@ -178,24 +179,25 @@ public static void main(String[] argv) { //parse command line first CmdLineArgs args = new CmdLineArgs(); - JCommander jc = JCommander.newBuilder() - .addObject(args) - .build(); - jc.setProgramName(Constants.APPLICATION); + CommandLine pc = new CommandLine(args); +// jc = JCommander.newBuilder() +// .addObject(args) +// .build(); +// jc.setProgramName(Constants.APPLICATION); try { - jc.parse(argv); + pc.parseArgs(argv); } catch (RuntimeException ex) { System.err.println("Error parsing command line arguments."); System.err.println(ex.getMessage()); - jc.usage(); + pc.usage(); System.exit(PosixExitCodes.EX_USAGE.exitCode()); } if (args.getNetIdx() >= 0 && !args.chainId.isEmpty()) { System.err.println("--chainId, --testnet and --net parameters are incompatible, please specify only one"); System.exit(PosixExitCodes.EX_USAGE.exitCode()); - } + }*/ if (args.help) { - jc.usage(); + pc.usage(); System.exit(PosixExitCodes.OK.exitCode()); } From b3cc87bfe5a64756bcf46cf6da0eeae580f01e15 Mon Sep 17 00:00:00 2001 From: Rostyslav Golda Date: Thu, 22 Jul 2021 01:40:09 +0300 Subject: [PATCH 04/11] Corrected typo --- .../main/java/com/apollocurrency/aplwallet/apl/exec/Apollo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/Apollo.java b/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/Apollo.java index e9796df073..eebe2a009a 100644 --- a/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/Apollo.java +++ b/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/Apollo.java @@ -195,7 +195,7 @@ public static void main(String[] argv) { if (args.getNetIdx() >= 0 && !args.chainId.isEmpty()) { System.err.println("--chainId, --testnet and --net parameters are incompatible, please specify only one"); System.exit(PosixExitCodes.EX_USAGE.exitCode()); - }*/ + } if (args.help) { pc.usage(); System.exit(PosixExitCodes.OK.exitCode()); From 16ac72dd9baa458c577157acb0caef793757cbcc Mon Sep 17 00:00:00 2001 From: Rostyslav Golda Date: Sat, 24 Jul 2021 02:47:19 +0300 Subject: [PATCH 05/11] Made project compilable --- .../java/com/apollocurrency/aplwallet/apl/exec/Apollo.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/Apollo.java b/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/Apollo.java index eebe2a009a..1ac780c4fe 100644 --- a/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/Apollo.java +++ b/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/Apollo.java @@ -189,7 +189,7 @@ public static void main(String[] argv) { } catch (RuntimeException ex) { System.err.println("Error parsing command line arguments."); System.err.println(ex.getMessage()); - pc.usage(); +// Sуstem.err.print(pc.Help.ColorScheme.toString()); System.exit(PosixExitCodes.EX_USAGE.exitCode()); } if (args.getNetIdx() >= 0 && !args.chainId.isEmpty()) { @@ -197,7 +197,7 @@ public static void main(String[] argv) { System.exit(PosixExitCodes.EX_USAGE.exitCode()); } if (args.help) { - pc.usage(); +// pc.execute(args); System.exit(PosixExitCodes.OK.exitCode()); } From 37bc985149fa710eca871d649a2d845ade67c919 Mon Sep 17 00:00:00 2001 From: Rostyslav Golda Date: Mon, 2 Aug 2021 08:23:07 +0300 Subject: [PATCH 06/11] Added help --- .../main/java/com/apollocurrency/aplwallet/apl/exec/Apollo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/Apollo.java b/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/Apollo.java index 1ac780c4fe..db46665fa8 100644 --- a/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/Apollo.java +++ b/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/Apollo.java @@ -189,7 +189,7 @@ public static void main(String[] argv) { } catch (RuntimeException ex) { System.err.println("Error parsing command line arguments."); System.err.println(ex.getMessage()); -// Sуstem.err.print(pc.Help.ColorScheme.toString()); + System.err.println(pc.getHelp().commandList()); System.exit(PosixExitCodes.EX_USAGE.exitCode()); } if (args.getNetIdx() >= 0 && !args.chainId.isEmpty()) { From 28b0120e620da0d338767dda0b4b7ba804e68296 Mon Sep 17 00:00:00 2001 From: Rostyslav Golda Date: Thu, 5 Aug 2021 09:39:23 +0300 Subject: [PATCH 07/11] Added help --- .../aplwallet/apl/exec/Apollo.java | 16 ++++++---------- .../aplwallet/apl/exec/CmdLineArgs.java | 3 +++ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/Apollo.java b/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/Apollo.java index db46665fa8..38b5469687 100644 --- a/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/Apollo.java +++ b/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/Apollo.java @@ -180,26 +180,22 @@ public static void main(String[] argv) { CmdLineArgs args = new CmdLineArgs(); CommandLine pc = new CommandLine(args); -// jc = JCommander.newBuilder() -// .addObject(args) -// .build(); -// jc.setProgramName(Constants.APPLICATION); try { - pc.parseArgs(argv); + CommandLine.ParseResult parseResult = pc.parseArgs(argv); + if (args.help) { + pc.usage(System.err); + System.exit(PosixExitCodes.OK.exitCode()); + } } catch (RuntimeException ex) { System.err.println("Error parsing command line arguments."); System.err.println(ex.getMessage()); - System.err.println(pc.getHelp().commandList()); + pc.usage(System.err); System.exit(PosixExitCodes.EX_USAGE.exitCode()); } if (args.getNetIdx() >= 0 && !args.chainId.isEmpty()) { System.err.println("--chainId, --testnet and --net parameters are incompatible, please specify only one"); System.exit(PosixExitCodes.EX_USAGE.exitCode()); } - if (args.help) { -// pc.execute(args); - System.exit(PosixExitCodes.OK.exitCode()); - } //set main application class to runtime diff --git a/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/CmdLineArgs.java b/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/CmdLineArgs.java index b13a19a718..b3103f2425 100644 --- a/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/CmdLineArgs.java +++ b/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/CmdLineArgs.java @@ -1,5 +1,7 @@ package com.apollocurrency.aplwallet.apl.exec; +import picocli.CommandLine; +import picocli.CommandLine.Command; import picocli.CommandLine.Option; /* @@ -9,6 +11,7 @@ * @author alukin@gmail.com * @author tx_hv@ukr.net */ +@Command(name = "apollo") public class CmdLineArgs { public static int DEFAULT_DEBUG_LEVEL = 2; From b38014c63818992af5da224c115d2f9e904d6439 Mon Sep 17 00:00:00 2001 From: Rostyslav Golda Date: Thu, 19 Aug 2021 07:54:06 +0300 Subject: [PATCH 08/11] Removing artifacts --- updater/upd | 261 ---------------------------------------------------- 1 file changed, 261 deletions(-) delete mode 100644 updater/upd diff --git a/updater/upd b/updater/upd deleted file mode 100644 index ba906f932a..0000000000 --- a/updater/upd +++ /dev/null @@ -1,261 +0,0 @@ -#!/bin/bash -# This script invoked by update.sh script to detach script process from Java main app -# first parameter is a current directory, where wallet is executing now (directory, which we should update) -# second parameter is a update directory which contains unpacked jar for update -# third parameter is a boolean flag, which indicates desktop mode - -APOLLO_JAR="apl-exec" - -APLCMDLINE=$(cat ~/.apl-blockchain/apl.cmdline 2>/dev/null) - -unamestr=`uname` - - -function notify -{ - if [[ "$unamestr" == 'Darwin' ]]; then - osascript -e "display notification \"$1\" with title \"Apollo\"" - else - echo $1 - fi -} - -function getNetwork() -{ - NETWORK=0 - if [ $(cat ~/.apl-blockchain/apl.cmdline | grep "\-n" | wc -l) -eq 1 ] - then - NETWORK=$(cat ~/.apl-blockchain/apl.cmdline | grep -oE "(\-n|\-\-net)\s{1,}[0-9]{1}" | cut -f2 -d' ') - else - NETWORK=0 - fi - - -} - -function getConfigPath() -{ - getNetwork - if [ ${NETWORK} -eq 0 ] - then - CONFIGDIR=conf - else - CONFIGDIR=conf-tn${NETWORK} - fi - - if [ $3 == "true" ] - then - CONFIGDIR=~/.apl-blockchain/${CONFIGDIR} - else - CONFIGDIR=$1/${CONFIGDIR} - fi -} - -function isSharding() -{ - NOSHARD=false - if [ $(cat ~/.apl-blockchain/apl.cmdline | grep -oE "\--no-shards-create\s{1,}true" | wc -l) -eq 1 ] - then - NOSHARD=true - else - if [ $(cat ${CONFIGDIR}/apl-blockchain.properties | grep apl.noshardcreate | grep -v "#" | wc -l ) -eq 1 ] - then - NOSHARD=$(cat ${CONFIGDIR}/apl-blockchain.properties | grep apl.noshardcreate | grep -v "#" | cut -f2 -d'=') - else - NOSHARD=false - fi - fi -} - - -VERSION=$(head -n1 ${2}/apollo-blockchain/VERSION) - -if [[ -d "${1}" ]] && [[ -d "${2}" ]] && [[ -n "${3}" ]] -then - - notify "Starting Apollo Updater" - notify "Stopping Apollo Wallet" - - NEXT_WAIT_TIME=0 - -# For backwards compatibility - if [ ! -f VERSION ]; then -# echo "Runnung from updater directory...." >>/tmp/updater_ne_tuda - cd .. - fi - - kill $(ps -ef | grep apl-de | awk '{ print $2 }') - $1/bin/apl-stop.sh - until [ $(ps aux | grep ${APOLLO_JAR} | grep -v grep | wc -l) -eq 0 ] || [ $NEXT_WAIT_TIME -eq 10 ]; do - NEXT_WAIT_TIME=`expr $NEXT_WAIT_TIME '+' 1` - sleep $NEXT_WAIT_TIME - notify "Waiting more time to stop Apollo Wallet..." - done - -# it is always good idea to backup everything before removing -#NOW=`date +%Y-%m-%dT%H:%m:%S` -#BKP_NAME=${1}/../ApolloWallet-BKP-${NOW}.tar.gz -#tar -czf ${BKP_NAME} ${1} - -# we sould remove "conf" dir because default configs are in resources now -# and user's configs are in ~/.apl_blockchain - if [ -f $1/conf/apl.properties ]; then - rm -rf $1/conf/apl-default.properties - rm -rf $1/conf/testnet.properties - rm -rf $1/conf/updater.properties - cp $1/conf/apl.properties $1/conf/apl-blockchain.properties - cp $1/conf/apl.properties $1/conf/apl.properties.backup - cat $1/conf/apl.properties | grep -v "#" | grep apl.dbDir= | sed s/dbDir/customDbDir/ >> $1/conf/apl-blockchain.properties - rm $1/conf/apl.properties - fi - - if [ -f $1/conf/chains.json ]; then - cp -f $1/conf/chains.json $1/conf/chains.json.backup - rm -f $1/conf/chains.json - fi - - - notify "Removing old version..." - notify "Removing garbage..." - rm -rfv $1/bin - rm -rfv $1/guilib - rm -rfv $1/html-stub - rm -rfv $1/lib - rm -rfv $1/sbin - rm -rfv $1/updater - rm -rfv $1/webui - rm -rfv $1/3RD-PARTY-LICENSES.txt - rm -rfv $1/VERSION* - rm -rfv $1/LICENSE* - rm -rfv $1/*jar - rm -rfv $1/META-INF - rm -rfv $1/update* - - cd $1/.. - rm -rfv apollo-web-ui - rm -rfv apollo-tools - - chmod 755 $1/../apollo-blockchain/bin/*.sh - - cd $1/.. - chmod 755 $1/../apollo-desktop/bin/*.sh - - notify "Removing old version..." - - notify "Moving extra files..." -# cp -Rfv $1/* $1/.. - cd $1/.. -# rm -rfv $1 - cp -Rfv $2/* . - -# cd $1/ -# cp -vRa conf* apollo-blockchain -# cp -vRa conf/* apollo-blockchain/conf -# ./replace_dbdir.sh - -# notify "Creating symlinks..." -# ln -s apollo-blockchain/bin bin - - - chmod 755 apollo-blockchain/bin/*.sh - chmod 755 apollo-desktop/bin/*.sh - - if [[ "$unamestr" == 'Darwin' ]]; then - - echo "#!/bin/bash" > ApolloWallet.app/Contents/MacOS/apl - echo "" >> ApolloWallet.app/Contents/MacOS/apl - echo "cd \"$1/../apollo-desktop/bin\"" >> ApolloWallet.app/Contents/MacOS/apl - echo "./apl-start-desktop.sh" >> ApolloWallet.app/Contents/MacOS/apl - chmod 755 "ApolloWallet+Secure Transport.app/Contents/MacOS/apl" - chmod 755 "ApolloWallet+Secure Transport.app/secureTransport/securenodexchg" - chmod 755 "ApolloWallet+Secure Transport.app/secureTransport/runClient.sh" - chmod 755 "ApolloWallet+Tor.app/Contents/MacOS/apl" - chmod 755 "ApolloWallet+Tor.app/tor/bin/tor" - chmod 755 "ApolloWallet.app/Contents/MacOS/apl" -# rm -rf "$1/ApolloWallet+Secure Transport.app" -# rm -rf "$1/ApolloWallet+Tor.app" -# rm -rf "$1/ApolloWallet.app" - - fi - - if [[ "$unamestr" == 'Linux' ]]; then - - chmod 755 tor/tor - chmod 755 secureTransport/securenodexchg - chmod 755 secureTransport/runClient.sh - fi - -# rm -rf apollo-wallet-deps-${VERSION}.tar.gz -# rm -rf apollo-wallet-deps-* - echo Version = ${VERSION} -# notify "Downloading deps...." -# Commented downloading deps -# wget https://s3.amazonaws.com/updates.apollowallet.org/libs/apollo-wallet-deps-${VERSION}.tar.gz || curl --retry 100 https://s3.amazonaws.com/updates.apollowallet.org/libs/apollo-wallet-deps-${VERSION}.tar.gz -o apollo-wallet-deps-${VERSION}.tar.gz -# tar -zxvf apollo-wallet-deps-${VERSION}.tar.gz -# cp apollo-wallet-deps-${VERSION}/* $1/lib - -# rm -rf apollo-wallet-deps-${VERSION}* - -# Install JRE -# notify "Installing Java Runtime..." -# bash ./update2.sh $1 - -#determine, if shrding was performed or not - - - - - -# Download db with shards - getNetwork - getConfigPath $1 $2 $3 - isSharding - - case ${NETWORK} in - 0) - NETID=b5d7b6 - ;; - 1) - NETID=a2e9b9 - ;; - 2) - NETID=2f2b61 - ;; - *) - NETID=b5d7b6 - - esac - -# TODO: ! refactor and ncomment that block -# if [ "$#" -eq 3 ] -# then -# if [ ${NOSHARD} == false ] -# then -# bash ./update3.sh $1 $2 $3 true ${NETID} -# fi -# else -# bash ./update3.sh $1 $2 $3 $4 $5 -# fi - - - -# notify "Downloading db shards..." - - if [[ -d conf ]]; then - mv -fv conf apollo-blockchain - fi - APLCMDLINE=$(echo ${APLCMDLINE} | sed s/shards/shard/g) - if [ $3 == true ] - then - notify "Starting desktop application..." - cd apollo-desktop/bin - nohup ./apl-start-desktop.sh ${APLCMDLINE} 2>&1 >/dev/null - else - notify "Starting command line application..." - cd apollo-blockchain/bin - ./apl-start.sh ${APLCMDLINE} - fi - -else - echo Invalid input parameters $1,$2,$3 -fi From 97eebc77c50aac10fe8656b0552a3341e10b1aa0 Mon Sep 17 00:00:00 2001 From: Rostyslav Golda Date: Thu, 13 Jan 2022 17:35:07 +0200 Subject: [PATCH 09/11] Fixed app name, formatting and block aligning --- .../aplwallet/apl/exec/Apollo.java | 6 +++--- .../aplwallet/apl/exec/CmdLineArgs.java | 17 +++++++++-------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/Apollo.java b/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/Apollo.java index 38b5469687..93937c070f 100644 --- a/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/Apollo.java +++ b/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/Apollo.java @@ -183,9 +183,9 @@ public static void main(String[] argv) { try { CommandLine.ParseResult parseResult = pc.parseArgs(argv); if (args.help) { - pc.usage(System.err); - System.exit(PosixExitCodes.OK.exitCode()); - } + pc.usage(System.err); + System.exit(PosixExitCodes.OK.exitCode()); + } } catch (RuntimeException ex) { System.err.println("Error parsing command line arguments."); System.err.println(ex.getMessage()); diff --git a/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/CmdLineArgs.java b/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/CmdLineArgs.java index b3103f2425..8878d40b94 100644 --- a/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/CmdLineArgs.java +++ b/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/CmdLineArgs.java @@ -1,17 +1,18 @@ -package com.apollocurrency.aplwallet.apl.exec; - -import picocli.CommandLine; -import picocli.CommandLine.Command; -import picocli.CommandLine.Option; - /* - * Copyright © 2018-2021 Apollo Foundation + * Copyright © 2018-2022 Apollo Foundation * Command line parameters * * @author alukin@gmail.com * @author tx_hv@ukr.net */ -@Command(name = "apollo") + +package com.apollocurrency.aplwallet.apl.exec; + +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +@Command(name = "apollo-blockchain") public class CmdLineArgs { public static int DEFAULT_DEBUG_LEVEL = 2; From b8f258a6bf6be2eea7f4ba77666ed66976f8e330 Mon Sep 17 00:00:00 2001 From: Yuriy Larin Date: Fri, 5 May 2023 16:14:31 +0300 Subject: [PATCH 10/11] updated command line params, added unit test --- .../aplwallet/apl/exec/CmdLineArgs.java | 25 ++-- .../aplwallet/apl/exec/CmdLineArgsTest.java | 129 ++++++++++++++++-- 2 files changed, 131 insertions(+), 23 deletions(-) diff --git a/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/CmdLineArgs.java b/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/CmdLineArgs.java index ccaf2f4a98..a969dbd2e5 100644 --- a/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/CmdLineArgs.java +++ b/apl-exec/src/main/java/com/apollocurrency/aplwallet/apl/exec/CmdLineArgs.java @@ -16,13 +16,13 @@ public class CmdLineArgs { public static int DEFAULT_DEBUG_LEVEL = 2; - @Option(names = {"--debug", "-d"}, description = "Debug level [0-4] from ERROR to TRACE") + @Option(names = {"--debug", "-d"}, description = "Common debug level [0-4] from ERROR=0, WARN=1, INFO=2, DEBUG=3, TRACE=4") public int debug = DEFAULT_DEBUG_LEVEL; @Option(names = {"--debug-updater", "-du"}, description = "Force updater to use debug certificates for verifying update transactions") public boolean debugUpdater; - @Option(names = {"--help", "-h"}, help = true, description = "Print help message") + @Option(names = {"--help", "-h"}, usageHelp = true, help = true, description = "Print help message") public boolean help; - @Option(names = {"--service-mode", "-s"}, help = true, description = "Run in service mode with current system user") + @Option(names = {"--service-mode", "-s"}, arity = "0..1", defaultValue = "false", fallbackValue = "true", description = "Run in service mode with current system user") public boolean serviceMode; @Option(names = {"--ignore-resources"}, description = "Ignore resources bundled with application jar. Default is false") public boolean ignoreResources = false; @@ -36,12 +36,19 @@ public class CmdLineArgs { public String vaultKeystoreDir = ""; @Option(names = {"--dex-key-dir"}, description = "Load/Save dex keys to/form specified keystore directory.") public String dexKeystoreDir = ""; - @Option(names = {"--no-shard-import"}, description = "Start from Genesis block, do not try to import last shard") + @Option(names = {"--no-shard-import"}, arity = "0..1", defaultValue = "false", fallbackValue = "true", + description = "Empty node starts downloading blocks from Genesis block, does not try to import last shard downloaded from another sharded nodes." + + " Default: ${DEFAULT-VALUE}, if specified without parameter value is: ${FALLBACK-VALUE}." + ) public boolean noShardImport = false; - @Option(names = {"--no-shard-create"}, description = "Do not create shards even if it configured to do so. Shards require much more resources") + @Option(names = {"--no-shard-create"}, arity = "0..1", defaultValue = "false", fallbackValue = "true", + description = "Do not create shards even if it configured to do so, default: ${DEFAULT-VALUE}, " + + "if specified without parameter: ${FALLBACK-VALUE}. Shards are require more OS resources." + ) public boolean noShardCreate = false; - @Option(names = {"--update-attachment-file", "-u"}, description = "Full path to file which represent json of UpdateAttachment for local updates debug") + @Option(names = {"--update-attachment-file", "-u"}, + description = "Full path to file which represent json of UpdateAttachment for local updates with debugging purpose.") public String updateAttachmentFile = ""; // TODO cleanup apl-default.properties @@ -53,13 +60,13 @@ public class CmdLineArgs { public String pidFile = ""; @Option(names = {"--net", "-n"}, help = true, description = "Connect to net [0-4]. 0 means mainnet, 1 - 1st testnet and so on") public int netIdx = -1; - @Option(names = {"--chain", "-C"}, help = true, description = "Connect to net with given chainID. UUID of chain id may be specified partially, 6 symbos min. Configs must be present.") + @Option(names = {"--chain", "-C"}, help = true, description = "Connect to net with given chainID. UUID of chain id may be specified partially, 6 symbols min. Config file must be present.") public String chainId = ""; @Option(names = {"--testnet"}, help = true, description = "Connect to testent 1. Has higher priority then --net") public boolean isTestnet = false; //--- - @Option(names = {"--disable-weld-concurrent-deployment"}, - description = "If use it, Weld doesn't use ConcurrentDeployer and ConcurrentValidator to build the container. Default value is true.") + @Option(names = {"--disable-weld-concurrent-deployment"}, defaultValue = "false", + description = "If use it, Weld doesn't use ConcurrentDeployer and ConcurrentValidator to build the container. Default value is ${DEFAULT-VALUE}.") public boolean disableWeldConcurrentDeployment = false; public boolean isResourceIgnored() { diff --git a/apl-exec/src/test/java/com/apollocurrency/aplwallet/apl/exec/CmdLineArgsTest.java b/apl-exec/src/test/java/com/apollocurrency/aplwallet/apl/exec/CmdLineArgsTest.java index 6f32b69087..7cd6a6ff02 100644 --- a/apl-exec/src/test/java/com/apollocurrency/aplwallet/apl/exec/CmdLineArgsTest.java +++ b/apl-exec/src/test/java/com/apollocurrency/aplwallet/apl/exec/CmdLineArgsTest.java @@ -1,8 +1,9 @@ package com.apollocurrency.aplwallet.apl.exec; -import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import picocli.CommandLine; import java.util.Arrays; @@ -23,20 +24,20 @@ class CmdLineArgsTest { "--db-dir", "/tmp", "--vault-key-dir", "/tmp", "--dex-key-dir", "/tmp", - "--no-shard-import", - "--no-shard-create", + "--no-shard-import", "true", + "--no-shard-create", "true", "--update-attachment-file", "attach-file.bin", "--2fa-dir", "/tmp", "--dexp-dir", "/tmp", "--pid-file", "/tmp/1.pid", "--net", "3", "--chain", "chains-1.json", - "--testnet", "1", + "--testnet", "false", "--disable-weld-concurrent-deployment", "false" }; String[] allArgShortArray = { - "-d", "4", + "-d", "1", "-du", "true", "-h", "true", "-s", "true", @@ -46,15 +47,15 @@ class CmdLineArgsTest { "--db-dir", "/tmp", "--vault-key-dir", "/tmp", "--dex-key-dir", "/tmp", - "--no-shard-import", - "--no-shard-create", + "--no-shard-import", "false", + "--no-shard-create", "false", "-u", "attach-file.bin", "--2fa-dir", "/tmp", "--dexp-dir", "/tmp", "--pid-file", "/tmp/1.pid", "-n", "3", "-C", "chains-1.json", - "--testnet", "1", + "--testnet", "true", "--disable-weld-concurrent-deployment", "false" }; @@ -68,27 +69,24 @@ void testAllArgs_longStringValues() { @Test void testAllArgs_emptyValues() { - CmdLineArgs lineArgs = new CmdLineArgs(); String[] emptyArgs = {}; - CommandLine.ParseResult result = new CommandLine(lineArgs).parseArgs(emptyArgs); + CommandLine.ParseResult result = new CommandLine(new CmdLineArgs()).parseArgs(emptyArgs); log.debug("args = {}, result = {}", allArgStringArray, result); assertEquals(0, result.errors().size()); } @Test void testAllArgs_shortStringValues() { - CmdLineArgs lineArgs = new CmdLineArgs(); - CommandLine.ParseResult result = new CommandLine(lineArgs).parseArgs(allArgShortArray); + CommandLine.ParseResult result = new CommandLine(new CmdLineArgs()).parseArgs(allArgShortArray); log.debug("args = {}, result = {}", allArgStringArray, result); assertEquals(0, result.errors().size()); } @Test void testAllArgs_unknownStringValues() { - CmdLineArgs lineArgs = new CmdLineArgs(); String[] unknownArgsArray = {"--unknown-param", "-UP"}; Exception error = assertThrows(CommandLine.UnmatchedArgumentException.class, - () -> new CommandLine(lineArgs).parseArgs(unknownArgsArray) + () -> new CommandLine(new CmdLineArgs()).parseArgs(unknownArgsArray) ); log.debug("args = {}, error = {}", Arrays.toString(unknownArgsArray), error.getMessage()); assertEquals("Unknown options: " + @@ -96,4 +94,107 @@ void testAllArgs_unknownStringValues() { error.getMessage()); } + @ParameterizedTest + @CsvSource(value = {"--debug-updater", "--help", "--service-mode", "--ignore-resources", "--no-shard-import", + "--no-shard-create", "--testnet", "--disable-weld-concurrent-deployment", + "-du", "-h", "-s" + }) + void test_emptyBooleansEvaluatedToTrue(String paramName) { + CommandLine.ParseResult result = new CommandLine(new CmdLineArgs()).parseArgs(paramName); + log.debug("Parameter = {}, result = {}", paramName, result.errors()); + assertEquals(0, result.errors().size()); + assertTrue((Boolean) result.matchedArgs().get(0).typedValues().get(0)); + } + + @ParameterizedTest + @CsvSource(value = {"--debug-updater=false,false", "--help=false,false", "--service-mode=false,false", "--ignore-resources=false,false", + "--no-shard-import=false,false", "--no-shard-create=false,false", "--testnet=false,false", "--disable-weld-concurrent-deployment=false,false", + "-du,true", "-h,true", "-s,true" + }) + void test_specifiedFalseBooleans(String paramName, String value) { + CommandLine.ParseResult result = new CommandLine(new CmdLineArgs()).parseArgs(paramName); + log.debug("Parameter = {}, result = {}", paramName, result.errors()); + assertEquals(0, result.errors().size()); + assertEquals(Boolean.valueOf(value), result.matchedArgs().get(0).typedValues().get(0)); + } + + @ParameterizedTest + @CsvSource(value = {"--debug-updater=true,true", "--help,true", "--service-mode=true,true", "--ignore-resources=true,true", + "--no-shard-import=true,true", "--no-shard-create=true,true", "--testnet=true,true", "--disable-weld-concurrent-deployment=true,true", + "-du,true", "-h,true", "-s,true" + }) + void test_specifiedTrueBooleans(String paramName, String value) { + CommandLine.ParseResult result = new CommandLine(new CmdLineArgs()).parseArgs(paramName); + log.debug("Parameter = {}, result = {}", paramName, result.errors()); + assertEquals(0, result.errors().size()); + assertEquals(Boolean.valueOf(value), result.matchedArgs().get(0).typedValues().get(0)); + } + + @ParameterizedTest + @CsvSource(value = {"--debug-updater,true", "--help,true", "--service-mode,true", "--ignore-resources,true", + "--no-shard-import,true", "--no-shard-create,true", "--testnet,true", "--disable-weld-concurrent-deployment,true", + "-du,true", "-h,true", "-s,true" + }) + void test_specifiedDefaults(String paramName, String value) { + CommandLine.ParseResult result = new CommandLine(new CmdLineArgs()).parseArgs(paramName); + log.debug("Parameter = {}, result = {}", paramName, result.errors()); + assertEquals(0, result.errors().size()); + assertEquals(Boolean.valueOf(value), result.matchedArgs().get(0).typedValues().get(0)); + } + + @ParameterizedTest + @CsvSource(value = { + "--config-dir=/tmp,/tmp", + "--log-dir=/tmp,/tmp", + "--db-dir=/tmp,/tmp", + "--vault-key-dir=/tmp,/tmp", + "--dex-key-dir=/tmp,/tmp", + "--update-attachment-file=attach-file.bin,attach-file.bin", + "--2fa-dir=/tmp,/tmp", + "--dexp-dir=/tmp,/tmp", + "--pid-file=/tmp/1.pid,/tmp/1.pid", + "--chain=chains-1.json,chains-1.json", + }) + void test_longStringParamsSpecified(String paramName, String value) { + CommandLine.ParseResult result = new CommandLine(new CmdLineArgs()).parseArgs(paramName); + log.debug("Parameter = {}, result = {}", paramName, result.errors()); + assertEquals(0, result.errors().size()); + assertEquals(value, result.matchedArgs().get(0).typedValues().get(0)); + } + + @ParameterizedTest + @CsvSource(value = { + "-c /tmp,/tmp", + "-l /tmp,/tmp", + "-u attach-file.bin,attach-file.bin", + "-C chains-1.json,chains-1.json" + }) + void test_shortStringParamsSpecified(String paramName, String value) { + CommandLine.ParseResult result = new CommandLine(new CmdLineArgs()).parseArgs(paramName); + log.debug("Parameter = {}, result = {}", paramName, result.errors()); + assertEquals(0, result.errors().size()); + assertEquals(value, result.matchedArgs().get(0).typedValues().get(0).toString().trim()); + } + + @ParameterizedTest + @CsvSource(value = { + "--config-dir", + "--log-dir", + "--db-dir", + "--vault-key-dir", + "--dex-key-dir", + "--update-attachment-file", + "--2fa-dir", + "--dexp-dir", + "--pid-file", + "--chain", + }) + void test_errorWhenStringParamsIsNotSpecified(String paramName) { + Exception error = assertThrows(CommandLine.MissingParameterException.class, + () -> new CommandLine(new CmdLineArgs()).parseArgs(paramName) + ); + log.debug("Parameter = {}, error = {}", paramName, error.getMessage()); + assertTrue(error.getMessage().startsWith("Missing required parameter for option '" + paramName + "'")); + } + } \ No newline at end of file From 9026545961a38f62e0ca049c837f20e07e453cd0 Mon Sep 17 00:00:00 2001 From: Yuriy Larin Date: Fri, 5 May 2023 16:14:53 +0300 Subject: [PATCH 11/11] updated poms --- apl-dex/pom.xml | 8 ++++++++ apl-exec/pom.xml | 5 +++++ apl-smc/pom.xml | 8 ++++++++ apl-updater/pom.xml | 2 +- apl-vault-wallet/pom.xml | 10 ++++++++-- 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/apl-dex/pom.xml b/apl-dex/pom.xml index 4e983dae00..83ce19d1c1 100644 --- a/apl-dex/pom.xml +++ b/apl-dex/pom.xml @@ -150,4 +150,12 @@ + + + + maven-surefire-plugin + + + + \ No newline at end of file diff --git a/apl-exec/pom.xml b/apl-exec/pom.xml index 717d5d8ecb..73fbb9dde0 100644 --- a/apl-exec/pom.xml +++ b/apl-exec/pom.xml @@ -92,6 +92,11 @@ mockito-junit-jupiter test + + org.junit.jupiter + junit-jupiter-params + test + diff --git a/apl-smc/pom.xml b/apl-smc/pom.xml index 6b1ca63caa..e20bcc6ad1 100644 --- a/apl-smc/pom.xml +++ b/apl-smc/pom.xml @@ -140,4 +140,12 @@ + + + + maven-surefire-plugin + + + + \ No newline at end of file diff --git a/apl-updater/pom.xml b/apl-updater/pom.xml index 01a7a7ac8a..316d0b0c29 100644 --- a/apl-updater/pom.xml +++ b/apl-updater/pom.xml @@ -105,7 +105,7 @@ maven-surefire-plugin - + diff --git a/apl-vault-wallet/pom.xml b/apl-vault-wallet/pom.xml index 8fdbdd6dbb..c76426fae8 100644 --- a/apl-vault-wallet/pom.xml +++ b/apl-vault-wallet/pom.xml @@ -144,8 +144,14 @@ janino test - - + + + + maven-surefire-plugin + + + + \ No newline at end of file