diff --git a/.gitignore b/.gitignore index 714101f98ec2f08de8f4278581ada8bf65412373..93256b38e2d9174dd435eba878f8e93742e1005e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +bin/tokei .checkstyle .classpath logs diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..119da58a6477e8a163a4bfced6e7bd2c92245492 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,59 @@ +variables: + MAVEN_OPTS: -Dmaven.repo.local=.m2/repository + +image: registry.forgemia.inra.fr/agroclim/common/docker-projets-java:latest + +stages: + - build + - test + - checkstyle + - pmd + - cpd + - package + - deploy + +cache: + paths: + - .m2/repository + +build_job: + stage: build + script: + - echo "Maven compile started" + - mvn compile + - ls -lha /usr/bin/tokei + - /usr/bin/tokei --version + +test_job: + stage: test + script: + - echo "Maven test started" + - mvn test + +checkstyle_job: + stage: checkstyle + script: + - mvn checkstyle:checkstyle + +pmd_job: + stage: pmd + script: + - mvn pmd:pmd + +cpd_job: + stage: cpd + script: + - mvn pmd:cpd + +package_job: + stage: package + script: + - echo "Maven packaging started" + - mvn package -DskipTests + +deploy_job: + stage: deploy + only: + - main + script: + - echo "Maven deploy started" diff --git a/bin/sloccount.sh b/bin/sloccount.sh index 17ac45eeca226c5279e58e6c242192df4ec52973..ccca432dc053cf5b45b71b82b0f24e7e4dfde740 100755 --- a/bin/sloccount.sh +++ b/bin/sloccount.sh @@ -1,27 +1,23 @@ #!/bin/bash TOKEI2CLOC=$(dirname $0)/tokei2cloc.py -TOKEITGZ=tokei-v7.0.3-x86_64-unknown-linux-gnu.tar.gz -if [ ! -f bin/tokei ]; then - mkdir -p ~/tmp - if [ ! -f ~/tmp/$TOKEITGZ ]; then - wget "https://github.com/Aaronepower/tokei/releases/download/v7.0.3/$TOKEITGZ" -O ~/tmp/$TOKEITGZ +TOKEI=$(command -v tokei) +if [ ! -x "$TOKEI" ]; then + TOKEITGZ=tokei-x86_64-unknown-linux-gnu.tar.gz + if [ ! -f bin/tokei ]; then + mkdir -p ~/tmp + if [ ! -f ~/tmp/$TOKEITGZ ]; then + wget "https://github.com/Aaronepower/tokei/releases/download/v12.1.2/$TOKEITGZ" -O ~/tmp/$TOKEITGZ + fi + tar zxf ~/tmp/$TOKEITGZ -C bin fi - tar zxf ~/tmp/$TOKEITGZ -C bin + TOKEI=bin/tokei fi -if [ -f bin/tokei ]; then - mkdir -p target - bin/tokei -f -o json src | $TOKEI2CLOC > target/cloc.xml - exit +if [ ! -f $TOKEI ]; then + echo "Strange, $TOKEI does not exist!" + exit 1 fi -SLOCCOUNT=$(which sloccount); -if [ "$SLOCCOUNT" != "" ]; then - DATADIR=$(dirname $0)/.slocdata; - if [ ! -f $DATADIR ]; then - mkdir -p $DATADIR; - fi - mkdir -p target ; - /usr/bin/sloccount --datadir $DATADIR --duplicates --wide --details src > target/sloccount.sc; -else - echo "sloccount not found!"; -fi +echo "tokei is installed at $TOKEI" +$TOKEI --version +mkdir -p target +$TOKEI -f -o json src | $TOKEI2CLOC > target/cloc.xml diff --git a/bin/tokei2cloc.py b/bin/tokei2cloc.py index a6ec899320b0a77ce81fb77518f638069bda96ee..bc41a97876ca9d42b55f6a2aaa1e2590312f3d01 100755 --- a/bin/tokei2cloc.py +++ b/bin/tokei2cloc.py @@ -35,8 +35,10 @@ results = json.loads(sys.stdin.read()) nb_files = 0 nb_lines = 0 for lang in results: - nb_files += len(results[lang]['stats']) - nb_lines += int(results[lang]['lines']) + nb_files += len(results[lang]['reports']) + nb_lines += int(results[lang]['blanks']) + nb_lines += int(results[lang]['code']) + nb_lines += int(results[lang]['comments']) print("""<?xml version="1.0"?><results> <header> @@ -56,10 +58,10 @@ total_blank = 0 total_comment = 0 total_code = 0 for lang in results: - for result in results[lang]['stats']: - blank = int(result['blanks']) - comment = int(result['comments']) - code = int(result['code']) + for result in results[lang]['reports']: + blank = int(result['stats']['blanks']) + comment = int(result['stats']['comments']) + code = int(result['stats']['code']) print(""" <file name="%s" blank="%d" comment="%d" code="%d" language="%s" />""" % (result['name'], blank, comment, code, lang)) total_blank += blank diff --git a/pom.xml b/pom.xml index 3a751a4237ce9adcb9ae87a153a3213aa992e8ee..d6e135a251f84f48b4dc0b27325dfa8a3bb5c8f0 100644 --- a/pom.xml +++ b/pom.xml @@ -83,9 +83,6 @@ along with Indicators. If not, see <https://www.gnu.org/licenses/>. <properties> <build.date>${maven.build.timestamp}</build.date> <checkstyle.config.location>file://${basedir}/config/sun_checks.xml</checkstyle.config.location> - <checkstyle.failsOnError>false</checkstyle.failsOnError> - <checkstyle.includeResources>false</checkstyle.includeResources> - <checkstyle.includeTestResources>false</checkstyle.includeTestResources> <compiler-plugin.version>3.8.1</compiler-plugin.version> <!-- Fix checkstyle version to ensure sun_checks.xml matches. --> <checkstyle.version>3.3.1</checkstyle.version> @@ -408,10 +405,13 @@ along with Indicators. If not, see <https://www.gnu.org/licenses/>. <version>${checkstyle.version}</version> <configuration> <excludes>**/module-info.java</excludes> + <failsOnError>true</failsOnError> + <failOnViolation>true</failOnViolation> <includeResources>false</includeResources> <includeTestResources>false</includeTestResources> <includeTestSourceDirectory>true</includeTestSourceDirectory> <propertyExpansion>basedir=${basedir}</propertyExpansion> + <violationSeverity>warning</violationSeverity> </configuration> </plugin> <plugin>