From 4dc7fae7f6dff6374e80493b6fe2858b8237481b Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Thu, 23 Jan 2020 08:56:01 +0100 Subject: [PATCH] Added build scripts. Improved logs. --- build-appjar.xml | 2 + build-local.xml | 6 + build-snapshot.xml | 27 +++ build-tagandpush.xml | 6 + build.sh | 168 ++++++++++++++++++ buildandgit.xml | 5 - buildjar.xml | 151 ---------------- resources/conf/agirstatool.cron | 3 + resources/conf/log4j-default.properties | 21 +++ resources/scripts/agirstatool.sh | 10 ++ .../agirstatool/AgirStatoolLauncher.java | 8 +- .../april/agirstatool/cli/AgiStatoolCLI.java | 8 +- .../april/agirstatool/core/AgirStatool.java | 1 + 13 files changed, 255 insertions(+), 161 deletions(-) create mode 100644 build-local.xml create mode 100644 build-snapshot.xml create mode 100644 build-tagandpush.xml create mode 100755 build.sh delete mode 100644 buildandgit.xml delete mode 100644 buildjar.xml create mode 100644 resources/conf/agirstatool.cron create mode 100644 resources/conf/log4j-default.properties create mode 100755 resources/scripts/agirstatool.sh diff --git a/build-appjar.xml b/build-appjar.xml index e66bccc..9f301ee 100644 --- a/build-appjar.xml +++ b/build-appjar.xml @@ -144,10 +144,12 @@ + diff --git a/build-local.xml b/build-local.xml new file mode 100644 index 0000000..42599df --- /dev/null +++ b/build-local.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/build-snapshot.xml b/build-snapshot.xml new file mode 100644 index 0000000..3c68374 --- /dev/null +++ b/build-snapshot.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build-tagandpush.xml b/build-tagandpush.xml new file mode 100644 index 0000000..326d0e4 --- /dev/null +++ b/build-tagandpush.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..4223fb1 --- /dev/null +++ b/build.sh @@ -0,0 +1,168 @@ +#/bin/bash + +# +# Display help. +# +function help +{ + echo "AgirStatool build script." + echo "Usage: build.sh [ -h | -help | --help | -snapshot | -local | -full ]" + echo " -h, -help, --help display this help." + echo " -snapshot, --snapshot build a snapshot." + echo " -local, --local build a new version without tag nor version number commit nor GIT push." + echo " -tagandpush, --tagandpush build a new version with tag, version number commit and GIT push." + echo "" +} + +# +# Build snapshot. +# +function build_snapshot +{ + okCount=0 + + # Ant check. + antCheck=`which ant` + if [[ "$antCheck" =~ ^/.* ]]; then + echo "Ant requirement................ OK" + let "okCount+=1" + else + echo "Ant requirement................ MISSING" + fi + + # Javac check. + javacCheck=`which javac` + if [[ "$javacCheck" =~ ^/.* ]]; then + echo "Javac requirement.............. OK" + let "okCount+=1" + else + echo "Javac requirement.............. MISSING" + fi + + # Java version check. + javaVersionCheck=`javac -version 2>&1` + if [[ "$javaVersionCheck" =~ ^.*\ 1.8 ]]; then + echo "Java 8 version requirement..... OK" + let "okCount+=1" + else + echo "Java 8 version requirement..... MISSING" + fi + + if [ "$okCount" == 3 ]; then + echo "Requirement OK" + ant -f build-snapshot.xml + else + echo "Requirement MISSING, build abort" + fi +} + +# +# Build local. +# +function build_local +{ + okCount=0 + + # Ant check. + antCheck=`which ant` + if [[ "$antCheck" =~ ^/.* ]]; then + echo "Ant requirement................ OK" + let "okCount+=1" + else + echo "Ant requirement................ MISSING" + fi + + # Javac check. + javacCheck=`which javac` + if [[ "$javacCheck" =~ ^/.* ]]; then + echo "Javac requirement.............. OK" + let "okCount+=1" + else + echo "Javac requirement.............. MISSING" + fi + + # Java version check. + javaVersionCheck=`javac -version 2>&1` + if [[ "$javaVersionCheck" =~ ^.*\ 1.8 ]]; then + echo "Java 8 version requirement..... OK" + let "okCount+=1" + else + echo "Java 8 version requirement..... MISSING" + fi + + if [ "$okCount" == 3 ]; then + echo "Requirement OK" + ant -f build-local.xml + else + echo "Requirement MISSING, build abort" + fi +} + +# +# Build tagandpush. +# +function build_tagandpush +{ + okCount=0 + + # Ant check. + antCheck=`which ant` + if [[ "$antCheck" =~ ^/.* ]]; then + echo "Ant requirement................ OK" + let "okCount+=1" + else + echo "Ant requirement................ MISSING" + fi + + # Javac check. + javacCheck=`which javac` + if [[ "$javacCheck" =~ ^/.* ]]; then + echo "Javac requirement.............. OK" + let "okCount+=1" + else + echo "Javac requirement.............. MISSING" + fi + + # Java version check. + javaVersionCheck=`javac -version 2>&1` + if [[ "$javaVersionCheck" =~ ^.*\ 1.8 ]]; then + echo "Java 8 version requirement..... OK" + let "okCount+=1" + else + echo "Java 8 version requirement..... MISSING" + fi + + # Git check. + gitCheck=`which git 2>&1` + if [[ "$gitCheck" =~ ^/.* ]]; then + echo "GIT requirement................ OK" + let "okCount+=1" + else + echo "GIT requirement................ MISSING" + fi + + if [ "$okCount" == 4 ]; then + echo "Requirement OK" + ant -f build-tagandpush.xml + else + echo "Requirement MISSING, build abort" + fi +} + +# +# Main. +# +if [ "$#" -eq 0 ] || [ "$1" == "-h" ] || [ "$1" == "-help" ] || [ "$1" == "--help" ]; then + help +elif [ "$1" == "-snapshot" ] || [ "$1" == "--snapshot" ] ; then + build_snapshot +elif [ "$1" == "-local" ] || [ "$1" == "--local" ] ; then + build_local +elif [ "$1" == "-tagandpush" ] || [ "$1" == "--tagandpush" ] ; then + build_tagandpush +else + echo "Invalid parameters." + help +fi + + diff --git a/buildandgit.xml b/buildandgit.xml deleted file mode 100644 index 4ea4688..0000000 --- a/buildandgit.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/buildjar.xml b/buildjar.xml deleted file mode 100644 index d0303c1..0000000 --- a/buildjar.xml +++ /dev/null @@ -1,151 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Type ant -p - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/resources/conf/agirstatool.cron b/resources/conf/agirstatool.cron new file mode 100644 index 0000000..9cdeeb7 --- /dev/null +++ b/resources/conf/agirstatool.cron @@ -0,0 +1,3 @@ +LANGUAGE=fr_FR.UTF8 +LC_ALL=fr_FR.UTF-8 +/5 * * * * root /srv/agirstatool/bin/agirstatool.sh > /srv/agirstatool/agirstatool-cron.log diff --git a/resources/conf/log4j-default.properties b/resources/conf/log4j-default.properties new file mode 100644 index 0000000..e2e4733 --- /dev/null +++ b/resources/conf/log4j-default.properties @@ -0,0 +1,21 @@ +# Log configuration +# ################# + +# priority setting: DEBUG < INFO < WARN < ERROR +log4j.rootLogger = INFO, stdout, LogWriter +log4j.logger.org.april.agirstatool = INFO +log4j.logger.fr.devinsy.xidyn = INFO + +#-- +log4j.appender.stdout = org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout = org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern = %m%n + + +#-- +log4j.appender.LogWriter = org.apache.log4j.RollingFileAppender +log4j.appender.LogWriter.File = /srv/agirStatool/agirstatool.log +log4j.appender.LogWriter.MaxFileSize = 100000KB +log4j.appender.LogWriter.MaxBackupIndex = 5 +log4j.appender.LogWriter.layout = org.apache.log4j.PatternLayout +log4j.appender.LogWriter.layout.ConversionPattern = %d{ISO8601} - AGIRSTATOOL [%-5p] %34.34c.%-25M - %m%n diff --git a/resources/scripts/agirstatool.sh b/resources/scripts/agirstatool.sh new file mode 100755 index 0000000..26cbbd3 --- /dev/null +++ b/resources/scripts/agirstatool.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# Java check. +javaCheck=`which java` +if [[ "$javaCheck" =~ ^/.* ]]; then + echo "Java requirement............... OK" + java -jar "$(dirname "$0")"/agirstatool.jar $@ +else + echo "Java requirement............... MISSING" +fi diff --git a/src/org/april/agirstatool/AgirStatoolLauncher.java b/src/org/april/agirstatool/AgirStatoolLauncher.java index c64d262..df43213 100644 --- a/src/org/april/agirstatool/AgirStatoolLauncher.java +++ b/src/org/april/agirstatool/AgirStatoolLauncher.java @@ -21,7 +21,6 @@ package org.april.agirstatool; import java.io.File; import org.apache.commons.lang3.ArrayUtils; -import org.apache.log4j.BasicConfigurator; import org.apache.log4j.PropertyConfigurator; import org.april.agirstatool.cli.AgiStatoolCLI; import org.april.agirstatool.demo.AgirStatool; @@ -60,9 +59,10 @@ public final class AgirStatoolLauncher } else { - BasicConfigurator.configure(); - logger.info("Basic log configuration done."); - logger.info("Configuration file was not found in [{}].", loggerConfig.getAbsoluteFile()); + // BasicConfigurator.configure(); + // logger.info("Basic log configuration done."); + // logger.info("Configuration file was not found in [{}].", + // loggerConfig.getAbsoluteFile()); } // Run. diff --git a/src/org/april/agirstatool/cli/AgiStatoolCLI.java b/src/org/april/agirstatool/cli/AgiStatoolCLI.java index 4c9ff5c..36cb667 100644 --- a/src/org/april/agirstatool/cli/AgiStatoolCLI.java +++ b/src/org/april/agirstatool/cli/AgiStatoolCLI.java @@ -20,6 +20,7 @@ package org.april.agirstatool.cli; import java.io.File; import java.sql.Connection; +import java.time.LocalDateTime; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.BasicConfigurator; @@ -126,8 +127,9 @@ public final class AgiStatoolCLI } }); + System.out.println(LocalDateTime.now() + " AgirStatool call: " + new StringList(args).toStringSeparatedBy(" ")); + // logger.info("Single connection opened with [{}].", this.url); - System.out.println("ok"); // This part implements an automate. int parameterCount = args.length; @@ -185,6 +187,7 @@ public final class AgiStatoolCLI case "refresh": case "update": { + System.out.println("Update command…"); AgirStatoolConfigFile config = new AgirStatoolConfigFile(configurationFile); Connection connection = SQLUtils.getConnexion(config.getDabataseUrl(), config.getDabataseName(), config.getDabataseLogin(), config.getDabatasePassword()); AgirStatool statool = new AgirStatool(connection, new File(config.getTargetDirectory())); @@ -194,6 +197,7 @@ public final class AgiStatoolCLI case "projects": { + System.out.println("projects command…"); AgirStatoolConfigFile config = new AgirStatoolConfigFile(configurationFile); Connection connection = SQLUtils.getConnexion(config.getDabataseUrl(), config.getDabataseName(), config.getDabataseLogin(), config.getDabatasePassword()); AgirStatool statool = new AgirStatool(connection, new File(config.getTargetDirectory())); @@ -204,6 +208,7 @@ public final class AgiStatoolCLI case "projects+": { + System.out.println("projects+ command…"); AgirStatoolConfigFile config = new AgirStatoolConfigFile(configurationFile); Connection connection = SQLUtils.getConnexion(config.getDabataseUrl(), config.getDabataseName(), config.getDabataseLogin(), config.getDabatasePassword()); AgirStatool statool = new AgirStatool(connection, new File(config.getTargetDirectory())); @@ -229,6 +234,7 @@ public final class AgiStatoolCLI } logger.info("Finished."); + System.out.println("Finished."); } catch (AgirStatoolException exception) { diff --git a/src/org/april/agirstatool/core/AgirStatool.java b/src/org/april/agirstatool/core/AgirStatool.java index 5d5ab52..a87026e 100644 --- a/src/org/april/agirstatool/core/AgirStatool.java +++ b/src/org/april/agirstatool/core/AgirStatool.java @@ -877,6 +877,7 @@ public class AgirStatool { if (hasToRefresh(project)) { + System.out.println("Refresh project page for " + project.getName()); logger.info("Refresh project page for {}", project.getName()); String page = ProjectPage.build(project); FileUtils.write(new File(this.targetDirectory, project.getIdentifier() + ".xhtml"), page, StandardCharsets.UTF_8);