Added build scripts. Improved logs.

This commit is contained in:
Christian P. MOMON 2020-01-23 08:56:01 +01:00
parent 4085a81f65
commit 4dc7fae7f6
13 changed files with 255 additions and 161 deletions

View file

@ -144,10 +144,12 @@
<copy todir="${dist.dir}/conf">
<fileset dir="${basedir}/resources/conf" includes="*" />
</copy>
<!--
<mkdir dir="${dist.dir}/man"/>
<copy todir="${dist.dir}/man">
<fileset dir="${basedir}/resources/man" includes="*" />
</copy>
-->
<delete file="${build.information.file}" />
</target>

6
build-local.xml Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<project default="dist" name="Build">
<!-- -->
<import file="build-appjar.xml" />
<property name="dist.snapshot" value="" />
</project>

27
build-snapshot.xml Normal file
View file

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<project default="snapshot" name="Build Snapshot">
<!-- -->
<import file="build-appjar.xml" />
<property name="buildnum.file" value="${basedir}/build.num" />
<property name="buildnum.tmpfile" value="${basedir}/build.num.tmp" />
<tstamp>
<format property="dist.snapshot.number" pattern="yyyyMMddHHmmss" />
</tstamp>
<property name="dist.snapshot" value="-SNAPSHOT_${dist.snapshot.number}" />
<!-- ***** Store ***** -->
<target name="store" description="Store the build number version">
<copy file="${buildnum.file}" tofile="${buildnum.tmpfile}" overwrite="true" />
</target>
<!-- ***** Restore ***** -->
<target name="restore" description="Restore the build number version">
<copy file="${buildnum.tmpfile}" tofile="${buildnum.file}" overwrite="true" />
<delete file="${buildnum.tmpfile}" />
</target>
<!-- ***** Snapshot ***** -->
<target name="snapshot" description="Build a snapshot" depends="store,dist,restore">
</target>
</project>

6
build-tagandpush.xml Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<project default="buildandgit" name="BuildAndGit">
<!-- -->
<import file="build-appjar.xml" />
<property name="dist.snapshot" value="" />
</project>

168
build.sh Executable file
View file

@ -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

View file

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<project default="buildandgit" name="agirstatool">
<!-- -->
<import file="buildjar.xml" />
</project>

View file

@ -1,151 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<project default="dist" name="jarbuild">
<!--ANT 1.7 is required -->
<property name="buildjar.version" value="1.4" />
<property file="build.properties" />
<property name="build.dir" value="${basedir}/build" />
<property name="build.src" value="${basedir}/src" />
<property name="build.classes" value="${build.dir}/classes" />
<property name="build.javadoc" value="${build.dir}/javadoc" />
<property name="test.src" value="${basedir}/test" />
<property name="test.classes" value="${build.dir}/test-classes" />
<property name="debug" value="on" />
<path id="build.classpath">
<fileset dir="lib" includes="**/*.jar" />
</path>
<path id="test.classpath.compile">
<path refid="build.classpath" />
<pathelement path="${build.classes}" />
</path>
<path id="test.classpath.run">
<path refid="test.classpath.compile" />
<pathelement path="${test.classes}" />
</path>
<!-- ***** Help ***** -->
<target name="help" description="Display detailed usage information">
<echo>Type ant -p</echo>
</target>
<!-- ***** Clean ***** -->
<target name="clean" description="Clean temporary directories">
<delete dir="${build.dir}" />
</target>
<!-- ***** Compile ***** -->
<target name="compile" description="Compile main code">
<mkdir dir="${build.dir}/classes" />
<javac srcdir="${build.src}" destdir="${build.classes}" debug="${debug}" deprecation="on" includeantruntime="false">
<classpath refid="test.classpath.compile" />
</javac>
</target>
<!-- ***** Compile test ***** -->
<target name="compile-test" description="Compile test code">
<mkdir dir="${test.classes}" />
<javac srcdir="${test.src}" destdir="${test.classes}" debug="${debug}" deprecation="on" includeantruntime="false">
<classpath refid="test.classpath.compile" />
</javac>
</target>
<!-- ***** Test ***** -->
<target name="test" description="Run unit tests" depends="clean,compile,compile-test">
<mkdir dir="${build.dir}/test-reports" />
<junit printsummary="yes" haltonfailure="no">
<classpath refid="test.classpath.run" />
<formatter type="plain" usefile="true" />
<batchtest fork="yes" todir="${build.dir}/test-reports/">
<fileset dir="test">
<include name="**/*Test.java" />
</fileset>
</batchtest>
</junit>
</target>
<!-- ***** JavaDoc ***** -->
<target name="javadoc" description="Javadoc construction">
<javadoc sourcepath="${build.src}" destdir="${build.javadoc}">
<classpath>
<fileset dir="lib" includes="**/*.jar" />
</classpath>
</javadoc>
</target>
<!-- ***** Dist ***** -->
<target name="dist" description="Build distribution" depends="clean,compile,javadoc">
<!-- -->
<buildnumber file="build.num" description="Id of the build" />
<!-- AUTOMATIC MANAGEMENT -->
<property name="dist.version" value="${product.revision.major}.${product.revision.minor}.${build.number}" />
<property name="dist.name" value="${product.name}-${dist.version}" />
<property name="dist.dir" value="${basedir}/dist/${dist.name}" />
<!-- -->
<mkdir dir="${dist.dir}" />
<!-- -->
<copy file="LICENSE" todir="${dist.dir}/" overwrite="true" />
<!-- Package main -->
<property name="dist.jar" value="${dist.dir}/${dist.name}.jar" />
<tstamp>
<format property="dist.time" pattern="dd/MM/yyyy HH:mm:ss" />
<!-- TODAY -->
</tstamp>
<jar destfile="${dist.jar}">
<manifest>
<attribute name="Built-By" value="${user.name} using ant" />
<attribute name="Built-Date" value="${dist.time}" />
</manifest>
<fileset dir="${build.classes}" />
<zipfileset dir="${basedir}/" includes="LICENSE" />
</jar>
<!-- Package sources -->
<property name="dist.srczip" value="${dist.dir}/${dist.name}-sources.zip" />
<zip destfile="${dist.srczip}" update="true" preserve0permissions="true">
<fileset dir="${basedir}/src" />
<zipfileset dir="${basedir}/" includes="LICENSE" />
</zip>
<!-- Package Javadoc -->
<property name="dist.javadoc.zip" value="${dist.dir}/${dist.name}-javadoc.zip" />
<zip destfile="${dist.javadoc.zip}" update="true" preserve0permissions="true">
<fileset dir="${build.javadoc}" />
<zipfileset dir="${basedir}/" includes="LICENSE" />
</zip>
<!-- Package lib -->
<copy todir="${dist.dir}/lib" overwrite="true">
<fileset dir="lib" excludes="hamcrest-core*,junit*" />
</copy>
</target>
<!-- ***** Dist ***** -->
<target name="buildandgit" depends="dist">
<!-- GIT actions-->
<echo message="Commit build.num"/>
<exec executable="git" outputproperty="git.commit.out" failifexecutionfails="true">
<arg line="commit -m 'Build ${dist.version}' build.num"/>
</exec>
<echo message="${git.commit.out}" />
<echo message="Tag"/>
<exec executable="git" outputproperty="git.tag.out" failifexecutionfails="true">
<arg line="tag -a ${dist.version} -m 'Build ${dist.version}'"/>
</exec>
<echo message="${git.tag.out}" />
<echo message="Push"/>
<exec executable="git" outputproperty="git.push.out" failifexecutionfails="true">
<arg line="push --follow-tags"/>
</exec>
<echo message="${git.push.out}" />
</target>
</project>

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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.

View file

@ -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)
{

View file

@ -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);