diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..26bdb4e8 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,20 @@ +name: Publish package to the Maven Central Repository +on: + release: + types: [created] +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Java + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Publish package + run: gradle publish + env: + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + SIGNING_KEY: ${{ secrets.SIGNING_KEY }} + SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} diff --git a/build.gradle b/build.gradle index 7bea56d5..ec2bc56d 100644 --- a/build.gradle +++ b/build.gradle @@ -6,20 +6,21 @@ buildscript { } dependencies { - classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:0.3.0' classpath 'pl.allegro.tech.build:axion-release-plugin:1.10.1' } } - -apply plugin: 'java' -apply plugin: 'application' -apply plugin: 'idea' -apply plugin: 'eclipse' -apply plugin: 'jacoco' -apply plugin: 'coveralls' -apply plugin: 'maven' -apply plugin: 'signing' -apply plugin: 'pl.allegro.tech.build.axion-release' +plugins { + id 'java' + id 'java-library' + id 'application' + id 'maven-publish' + id 'signing' + id 'idea' + id 'eclipse' + id 'jacoco' + id 'com.github.kt3k.coveralls' version '2.10.2' + id 'pl.allegro.tech.build.axion-release' version '1.12.1' +} scmVersion { tag { @@ -33,7 +34,7 @@ configurations { } } -project.version = scmVersion.version +project.version = '2.3.1.1' //scmVersion.version sourceCompatibility = 1.8 targetCompatibility = 1.8 @@ -58,32 +59,32 @@ run { repositories { mavenCentral() - maven { url "http://central.maven.org/maven2" } + maven { url "https://central.maven.org/maven2" } jcenter() } //noinspection GroovyAssignabilityCheck dependencies { - compile 'org.apache.httpcomponents:httpclient:4.3.1' - compile 'com.fasterxml.jackson.core:jackson-databind:2.3.0' - compile 'com.intellij:annotations:12.0' - compile 'org.slf4j:slf4j-api:1.7.26' - compile 'org.slf4j:log4j-over-slf4j:1.7.26' - compile 'ch.qos.logback:logback-classic:1.2.3' - compile 'commons-cli:commons-cli:1.2' - compile 'com.jayway.jsonpath:json-path:2.4.0' - compile 'commons-io:commons-io:2.4' - compile 'org.eclipse.jgit:org.eclipse.jgit:5.5.1.201910021850-r' - - compile 'com.urswolfer.gerrit.client.rest:gerrit-rest-java-client:0.9.3' + implementation 'org.apache.httpcomponents:httpclient:4.3.1' + implementation 'com.fasterxml.jackson.core:jackson-databind:2.3.0' + implementation 'com.intellij:annotations:12.0' + implementation 'org.slf4j:slf4j-api:1.7.26' + implementation 'org.slf4j:log4j-over-slf4j:1.7.26' + implementation 'ch.qos.logback:logback-classic:1.2.3' + implementation 'commons-cli:commons-cli:1.2' + implementation 'com.jayway.jsonpath:json-path:2.4.0' + implementation 'commons-io:commons-io:2.4' + implementation 'org.eclipse.jgit:org.eclipse.jgit:5.5.1.201910021850-r' + + implementation 'com.urswolfer.gerrit.client.rest:gerrit-rest-java-client:0.9.3' // Checkstyle dependencies - compile('com.puppycrawl.tools:checkstyle:8.1') { + implementation('com.puppycrawl.tools:checkstyle:8.1') { exclude group: 'com.google.guava' } // PMD dependencies - compile('net.sourceforge.pmd:pmd-java:6.0.0') { + implementation('net.sourceforge.pmd:pmd-java:6.0.0') { exclude group: 'jaxen' exclude group: 'xerces' exclude group: 'junit' @@ -91,59 +92,59 @@ dependencies { exclude group: 'org.ow2.asm' } - compile('jaxen:jaxen:1.1.6') { //1.1.6 in SpotBugs + implementation('jaxen:jaxen:1.1.6') { //1.1.6 in SpotBugs exclude group: 'xerces' exclude group: 'xalan' exclude group: 'com.ibm.icu' } - compile('xerces:xercesImpl:2.9.1') { + implementation('xerces:xercesImpl:2.9.1') { exclude group: 'xml-apis' } // SpotBugs dependencies - compile('com.github.spotbugs:spotbugs:3.1.11') { + implementation('com.github.spotbugs:spotbugs:3.1.11') { exclude group: 'org.slf4j' } // Scalastyle http://www.scalastyle.org/ - compile 'org.scalastyle:scalastyle_2.10:0.4.0' + implementation 'org.scalastyle:scalastyle_2.10:0.4.0' // CodeNarc http://codenarc.sourceforge.net/ - compile('org.codenarc:CodeNarc:1.4') { + implementation('org.codenarc:CodeNarc:1.4') { exclude module: 'groovy' exclude group: 'junit' } - compile 'org.codehaus.groovy:groovy:2.3.4' + implementation 'org.codehaus.groovy:groovy:2.3.4' // JSLint - compile 'com.googlecode.jslint4java:jslint4java:2.0.5' + implementation 'com.googlecode.jslint4java:jslint4java:2.0.5' // JSHint - compile 'pl.touk:jshint4j:2.9.5' + implementation 'pl.touk:jshint4j:2.9.5' // github connector - compile('com.jcabi:jcabi-github:1.0') - compile 'org.glassfish:javax.json:1.0.4' - compile 'com.github.spullara.mustache.java:compiler:0.8.17' + implementation 'com.jcabi:jcabi-github:1.0' + implementation 'org.glassfish:javax.json:1.0.4' + implementation 'com.github.spullara.mustache.java:compiler:0.8.17' // external processes - compile 'org.zeroturnaround:zt-exec:1.8' + implementation 'org.zeroturnaround:zt-exec:1.8' - compile 'org.jetbrains.kotlin:kotlin-stdlib:1.4.10' + implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.4.10' // ktlint https://github.com/shyiko/ktlint - compile 'com.pinterest.ktlint:ktlint-core:0.39.0' - compile 'com.pinterest.ktlint:ktlint-ruleset-standard:0.39.0' + implementation 'com.pinterest.ktlint:ktlint-core:0.39.0' + implementation 'com.pinterest.ktlint:ktlint-ruleset-standard:0.39.0' // detekt - compile 'io.gitlab.arturbosch.detekt:detekt-tooling:1.14.0' + implementation 'io.gitlab.arturbosch.detekt:detekt-tooling:1.14.0' runtimeOnly 'io.gitlab.arturbosch.detekt:detekt-core:1.14.0' runtimeOnly 'io.gitlab.arturbosch.detekt:detekt-rules:1.14.0' // transitive dependency that used non-SSL version of Maven Central // and version 1.74 that was not found - compile 'com.beust:jcommander:1.78' + implementation 'com.beust:jcommander:1.78' compileOnly 'org.projectlombok:lombok:1.18.4' annotationProcessor 'org.projectlombok:lombok:1.18.4' @@ -155,7 +156,7 @@ dependencies { testImplementation "org.junit.jupiter:junit-jupiter-engine:5.4.0" testImplementation "org.junit.jupiter:junit-jupiter-params:5.4.0" testImplementation 'org.junit.platform:junit-platform-launcher:1.1.0' - testImplementation 'org.assertj:assertj-core:3.9.0' + testImplementation 'org.assertj:assertj-core:3.18.1' testImplementation 'org.mockito:mockito-core:2.23.4' testImplementation 'org.mockito:mockito-junit-jupiter:2.28.2' testImplementation('com.github.tomakehurst:wiremock:2.18.0') { @@ -175,31 +176,9 @@ jacocoTestReport { } } -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from 'javadoc' -} - -task sourcesJar(type: Jar) { - classifier = 'sources' - from sourceSets.main.allSource -} - -// quick way to copy all project dependencies (jar files) into one directory -// similar to dependency:copy-dependencies -task copyToLib(type: Copy) { - into "$buildDir/lib" - from configurations.runtime -} - -artifacts { - //Comment this archives jar due to duplicated jar task with Gradle 5 - //https://github.com/gradle/gradle/issues/8213 - //https://discuss.gradle.org/t/apply-plugin-signing-broke-in-gradle-5-1-1-and-prints-out-non-existent-task/31418 - //archives jar - - archives javadocJar - archives sourcesJar +java { + withJavadocJar() + withSourcesJar() } jar { @@ -211,70 +190,52 @@ jar { } } -signing { - required { gradle.taskGraph.hasTask("uploadArchives") } - sign configurations.archives -} - -uploadArchives { - repositories { - mavenDeployer { - beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } +ext.isReleaseVersion = !version.endsWith('SNAPSHOT') - repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { - authentication(userName: sonatypeUsername, password: sonatypePassword) - } - snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") { - authentication(userName: sonatypeUsername, password: sonatypePassword) - } - - pom.project { - name 'Sputnik' - packaging 'jar' - description 'Static code review for your Gerrit and Stash patchsets. Runs Checkstyle, PMD and SpotBugs for you!' - url 'https://github.com/TouK/sputnik/' +tasks.withType(Sign) { + onlyIf { isReleaseVersion } +} +publishing { + publications { + mavenJava(MavenPublication) { + artifactId = 'sputnik' + from components.java + pom { + groupId = 'pl.touk' + name = 'Sputnik' + description = 'Static code review for your Gerrit and Stash patchsets. Runs Checkstyle, PMD and SpotBugs for you!' + url = 'https://github.com/TouK/sputnik/' scm { - url 'scm:git@github.com:TouK/sputnik.git' - connection 'scm:git@github.com:TouK/sputnik.git' - developerConnection 'scm:git@github.com:Touk/sputnik.git' + url = 'scm:git@github.com:TouK/sputnik.git' + connection = 'scm:git@github.com:TouK/sputnik.git' + developerConnection = 'scm:git@github.com:Touk/sputnik.git' } - licenses { license { - name 'The Apache Software License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution 'repo' - } - } - - developers { - developer { - id 'tomasz_kalkosinski' - name 'Tomasz Kalkosinski' - } - developer { - id 'marcin_cylke' - name 'Marcin Cylke' - } - developer { - id 'piotr_jagielski' - name 'Piotr Jagielski' - } - developer { - id 'karol_lassak' - name 'Karol Lassak' - } - developer { - id 'dominik_przybysz' - name 'Dominik Przybysz' - } - developer { - id 'henning_hoefer' - name 'Henning Hoefer' + name = 'The Apache Software License, Version 2.0' + url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + distribution = 'repo' } } } } } + repositories { + maven { + name = "OSSRH" + url = "https://oss.sonatype.org/service/local/staging/deploy/maven2/" + credentials { + username = System.getenv("SONATYPE_USERNAME") + password = System.getenv("SONATYPE_PASSWORD") + } + } + } +} + +signing { + def signingKey = System.getenv('SIGNING_KEY') + def signingPassword = System.getenv('SIGNING_PASSWORD') + useInMemoryPgpKeys(signingKey, signingPassword) + sign publishing.publications.mavenJava } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0d0148cc..4d9ca164 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Thu Jun 13 10:17:54 CEST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip diff --git a/gradlew b/gradlew index 97fac783..b0d6d0ab 100755 --- a/gradlew +++ b/gradlew @@ -1,4 +1,20 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# 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. +# ############################################################################## ## @@ -6,20 +22,38 @@ ## ############################################################################## -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" -warn ( ) { +warn () { echo "$*" } -die ( ) { +die () { echo echo "$*" echo @@ -30,6 +64,7 @@ die ( ) { cygwin=false msys=false darwin=false +nonstop=false case "`uname`" in CYGWIN* ) cygwin=true @@ -40,26 +75,11 @@ case "`uname`" in MINGW* ) msys=true ;; + NONSTOP* ) + nonstop=true + ;; esac -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >&- -APP_HOME="`pwd -P`" -cd "$SAVED" >&- - CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -85,7 +105,7 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then @@ -150,11 +170,19 @@ if $cygwin ; then esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " } -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index aec99730..15e1ee37 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,3 +1,19 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem http://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -8,14 +24,14 @@ @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome @@ -46,10 +62,9 @@ echo location of your Java installation. goto fail :init -@rem Get command-line arguments, handling Windowz variants +@rem Get command-line arguments, handling Windows variants if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args :win9xME_args @rem Slurp the command line arguments. @@ -60,11 +75,6 @@ set _SKIP=2 if "x%~1" == "x" goto execute set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ :execute @rem Setup the command line diff --git a/src/main/java/pl/touk/sputnik/connector/ConnectorFacade.java b/src/main/java/pl/touk/sputnik/connector/ConnectorFacade.java index aefb4027..8d8d9fa0 100644 --- a/src/main/java/pl/touk/sputnik/connector/ConnectorFacade.java +++ b/src/main/java/pl/touk/sputnik/connector/ConnectorFacade.java @@ -17,6 +17,7 @@ public interface ConnectorFacade extends ReviewPublisher { /** * Validates if given options are supported by selected connector. * + * @param configuration a configuration instance * @throws GeneralOptionNotSupportedException * if passed configuration is not valid or not fully supported */ diff --git a/src/main/java/pl/touk/sputnik/connector/gerrit/GerritFacade.java b/src/main/java/pl/touk/sputnik/connector/gerrit/GerritFacade.java index 865f7a7a..5b49208c 100644 --- a/src/main/java/pl/touk/sputnik/connector/gerrit/GerritFacade.java +++ b/src/main/java/pl/touk/sputnik/connector/gerrit/GerritFacade.java @@ -73,7 +73,8 @@ public void publish(@NotNull Review review) { } /** - * This is specific for Gerrit and GerritCommentVisitor + * + * @return RevisionApi revisionApi instance */ public RevisionApi getRevision() { try { diff --git a/src/test/java/pl/touk/sputnik/engine/visitor/comment/GerritFileDiffBuilderTest.java b/src/test/java/pl/touk/sputnik/engine/visitor/comment/GerritFileDiffBuilderTest.java index 1207e4c1..ad317f5a 100644 --- a/src/test/java/pl/touk/sputnik/engine/visitor/comment/GerritFileDiffBuilderTest.java +++ b/src/test/java/pl/touk/sputnik/engine/visitor/comment/GerritFileDiffBuilderTest.java @@ -75,6 +75,7 @@ private DiffInfo.ContentEntry buildContentEntry(int aSize, int abSize, int bSize return diffHunk; } + @SuppressWarnings("unchecked") private List buildListMock(int size) { List list = mock(List.class); when(list.size()).thenReturn(size); @@ -82,4 +83,4 @@ private List buildListMock(int size) { } -} \ No newline at end of file +}