diff --git a/build.gradle b/build.gradle index 8ff53dd..34f02e8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,26 +1,31 @@ +plugins { + id "de.marcphilipp.nexus-publish" version "0.4.0" + id "io.codearte.nexus-staging" version "0.21.1" +} + +wrapper { + gradleVersion = "${project.property('gradle.wrapper.version')}" + distributionType = Wrapper.DistributionType.ALL +} ext { user = 'xbib' name = 'jacc' description = 'A Java implementation of yacc (yet another compiler-compiler)' + inceptionYear = '2016' + url = 'https://github.com/' + user + '/' + name scmUrl = 'https://github.com/' + user + '/' + name scmConnection = 'scm:git:git://github.com/' + user + '/' + name + '.git' - scmDeveloperConnection = 'scm:git:git://github.com/' + user + '/' + name + '.git' + scmDeveloperConnection = 'scm:git:ssh://git@github.com:' + user + '/' + name + '.git' + issueManagementSystem = 'Github' + issueManagementUrl = ext.scmUrl + '/issues' + licenseName = 'BSD 3-Clause License' + licenseUrl = 'https://opensource.org/licenses/BSD-3-Clause' } apply plugin: 'java-library' -repositories { - mavenCentral() -} - -dependencies { - testImplementation "junit:junit:${project.property('junit.version')}" -} - -test { - testLogging { - showStandardStreams = true - exceptionFormat = 'full' - } -} +apply from: rootProject.file('gradle/ide/idea.gradle') +apply from: rootProject.file('gradle/compile/java.gradle') +apply from: rootProject.file('gradle/test/junit5.gradle') +apply from: rootProject.file('gradle/publishing/sonatype.gradle') diff --git a/gradle.properties b/gradle.properties index ed50e49..9bdce55 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,4 +2,4 @@ group = org.xbib name = jacc version = 2.2.0 -junit.version = 4.13 \ No newline at end of file +gradle.wrapper.version = 6.4.1 diff --git a/gradle/codequality/checkstyle.gradle b/gradle/codequality/checkstyle.gradle new file mode 100644 index 0000000..790f9a5 --- /dev/null +++ b/gradle/codequality/checkstyle.gradle @@ -0,0 +1,15 @@ +apply plugin: 'checkstyle' + +tasks.withType(Checkstyle) { + ignoreFailures = true + reports { + xml.enabled = true + html.enabled = true + } +} + +checkstyle { + //configFile = rootProject.file('config/checkstyle/checkstyle.xml') + ignoreFailures = true + showViolations = true +} diff --git a/gradle/codequality/pmd.gradle b/gradle/codequality/pmd.gradle new file mode 100644 index 0000000..ae0b5f4 --- /dev/null +++ b/gradle/codequality/pmd.gradle @@ -0,0 +1,9 @@ +apply plugin: 'pmd' + +tasks.withType(Pmd) { + ignoreFailures = true + reports { + xml.enabled = true + html.enabled = true + } +} diff --git a/gradle/codequality/sonarqube.gradle b/gradle/codequality/sonarqube.gradle new file mode 100644 index 0000000..d8eddd0 --- /dev/null +++ b/gradle/codequality/sonarqube.gradle @@ -0,0 +1,10 @@ + +sonarqube { + properties { + property "sonar.projectName", "${project.group} ${project.name}" + property "sonar.sourceEncoding", "UTF-8" + property "sonar.tests", "src/test/java" + property "sonar.scm.provider", "git" + property "sonar.junit.reportsPath", "build/test-results/test/" + } +} diff --git a/gradle/codequality/spotbugs.gradle b/gradle/codequality/spotbugs.gradle new file mode 100644 index 0000000..d0b3d56 --- /dev/null +++ b/gradle/codequality/spotbugs.gradle @@ -0,0 +1,18 @@ + +apply plugin: "com.github.spotbugs" + +spotbugs { + effort = "max" + reportLevel = "low" + //includeFilter = file("findbugs-exclude.xml") +} + +/* +tasks.withType(com.github.spotbugs.SpotBugsTask) { + ignoreFailures = true + reports { + xml.enabled = false + html.enabled = true + } +} +*/ \ No newline at end of file diff --git a/gradle/compile/java.gradle b/gradle/compile/java.gradle new file mode 100644 index 0000000..a9d76ce --- /dev/null +++ b/gradle/compile/java.gradle @@ -0,0 +1,35 @@ + +apply plugin: 'java-library' + +java { + modularity.inferModulePath.set(true) +} + +compileJava { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 +} + +compileTestJava { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 +} + +jar { + manifest { + attributes('Implementation-Version': project.version) + } +} + +task sourcesJar(type: Jar, dependsOn: classes) { + classifier 'sources' + from sourceSets.main.allSource +} + +task javadocJar(type: Jar, dependsOn: javadoc) { + classifier 'javadoc' +} + +artifacts { + archives sourcesJar, javadocJar +} \ No newline at end of file diff --git a/gradle/documentation/asciidoc.gradle b/gradle/documentation/asciidoc.gradle new file mode 100644 index 0000000..34ace12 --- /dev/null +++ b/gradle/documentation/asciidoc.gradle @@ -0,0 +1,36 @@ +apply plugin: 'org.xbib.gradle.plugin.asciidoctor' + +configurations { + asciidoclet +} + +dependencies { + asciidoclet "org.asciidoctor:asciidoclet:${project.property('asciidoclet.version')}" +} + +subprojects { + + /*javadoc { + options.docletpath = configurations.asciidoclet.files.asType(List) + options.doclet = 'org.asciidoctor.Asciidoclet' + //options.overview = "src/docs/asciidoclet/overview.adoc" + options.addStringOption "-base-dir", "${projectDir}" + options.addStringOption "-attribute", + "name=${project.name},version=${project.version},title-link=https://github.com/xbib/${project.name}" + configure(options) { + noTimestamp = true + } +}*/ + + asciidoctor { + attributes 'source-highlighter': 'coderay', + toc: 'left', + doctype: 'book', + icons: 'font', + encoding: 'utf-8', + sectlink: true, + sectanchors: true, + linkattrs: true, + imagesdir: 'img' + } +} \ No newline at end of file diff --git a/gradle/ide/idea.gradle b/gradle/ide/idea.gradle new file mode 100644 index 0000000..64e2167 --- /dev/null +++ b/gradle/ide/idea.gradle @@ -0,0 +1,13 @@ +apply plugin: 'idea' + +idea { + module { + outputDir file('build/classes/java/main') + testOutputDir file('build/classes/java/test') + } +} + +if (project.convention.findPlugin(JavaPluginConvention)) { + //sourceSets.main.output.classesDirs = file("build/classes/java/main") + //sourceSets.test.output.classesDirs = file("build/classes/java/test") +} diff --git a/gradle/publish.gradle b/gradle/publish.gradle deleted file mode 100644 index 31de0f2..0000000 --- a/gradle/publish.gradle +++ /dev/null @@ -1,51 +0,0 @@ - -task sonaTypeUpload(type: Upload) { - configuration = configurations.archives - uploadDescriptor = true - repositories { - if (project.hasProperty('ossrhUsername')) { - mavenDeployer { - beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } - repository(url: 'https://oss.sonatype.org/service/local/staging/deploy/maven2') { - authentication(userName: ossrhUsername, password: ossrhPassword) - } - snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots') { - authentication(userName: ossrhUsername, password: ossrhPassword) - } - pom.project { - groupId project.group - artifactId project.name - version project.version - name project.name - description description - packaging 'jar' - inceptionYear '2016' - url scmUrl - organization { - name 'xbib' - url 'http://xbib.org' - } - developers { - developer { - id user - name 'Jörg Prante' - email 'joergprante@gmail.com' - url 'https://github.com/jprante' - } - } - scm { - url scmUrl - connection scmConnection - developerConnection scmDeveloperConnection - } - licenses { - license { - name 'BSD 3-Clause License' - url 'https://opensource.org/licenses/BSD-3-Clause' - } - } - } - } - } - } -} diff --git a/gradle/publishing/sonatype.gradle b/gradle/publishing/sonatype.gradle new file mode 100644 index 0000000..74dbd48 --- /dev/null +++ b/gradle/publishing/sonatype.gradle @@ -0,0 +1,83 @@ + +if (project.hasProperty('ossrhUsername') && project.hasProperty('ossrhPassword')) { + + apply plugin: 'io.codearte.nexus-staging' + apply plugin: "de.marcphilipp.nexus-publish" + + publishing { + publications { + mavenJava(MavenPublication) { + from components.java + artifact sourcesJar + artifact javadocJar + pom { + name = project.name + description = project.ext.description + url = project.ext.url + inceptionYear = project.ext.inceptionYear + packaging = 'jar' + organization { + name = 'xbib' + url = 'https://xbib.org' + } + developers { + developer { + id = 'jprante' + name = 'Jörg Prante' + email = 'joergprante@gmail.com' + url = 'https://github.com/jprante' + } + } + scm { + url = project.ext.scmUrl + connection = project.ext.scmConnection + developerConnection = project.ext.scmDeveloperConnection + } + issueManagement { + system = project.ext.issueManagementSystem + url = project.ext.issueManagementUrl + } + licenses { + license { + name = project.ext.licenseName + url = project.ext.licenseUrl + distribution = 'repo' + } + } + } + } + } + repositories { + maven { + url 'https://oss.sonatype.org/service/local/staging/deploy/maven2/' + credentials { + username = project.property('ossrhUsername') + password = project.property('ossrhPassword') + } + } + } + } + + if (project.hasProperty("signing.keyId")) { + apply plugin: 'signing' + signing { + sign publishing.publications.mavenJava + } + } + + nexusPublishing { + repositories { + sonatype { + username = project.property('ossrhUsername') + password = project.property('ossrhPassword') + packageGroup = "org.xbib" + } + } + } + + nexusStaging { + username = project.property('ossrhUsername') + password = project.property('ossrhPassword') + packageGroup = "org.xbib" + } +} diff --git a/gradle/test/junit5.gradle b/gradle/test/junit5.gradle new file mode 100644 index 0000000..667547c --- /dev/null +++ b/gradle/test/junit5.gradle @@ -0,0 +1,27 @@ + +def junitVersion = project.hasProperty('junit.version')?project.property('junit.property'):'5.6.2' +def hamcrestVersion = project.hasProperty('hamcrest.version')?project.property('hamcrest.property'):'2.2' + +dependencies { + testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}" + testImplementation "org.junit.jupiter:junit-jupiter-params:${junitVersion}" + testImplementation "org.hamcrest:hamcrest-library:${hamcrestVersion}" + testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}" +} + +test { + useJUnitPlatform() + failFast = true + testLogging { + events 'STARTED', 'PASSED', 'FAILED', 'SKIPPED' + } + afterSuite { desc, result -> + if (!desc.parent) { + println "\nTest result: ${result.resultType}" + println "Test summary: ${result.testCount} tests, " + + "${result.successfulTestCount} succeeded, " + + "${result.failedTestCount} failed, " + + "${result.skippedTestCount} skipped" + } + } +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 5c2d1cf..62d4c05 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4c5803d..da676f7 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Tue May 19 09:37:57 CEST 2020 +distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-all.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.4-bin.zip -zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index 83f2acf..fbd7c51 100755 --- a/gradlew +++ b/gradlew @@ -82,6 +82,7 @@ esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then @@ -129,6 +130,7 @@ fi if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath @@ -154,19 +156,19 @@ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then else eval `echo args$i`="\"$arg\"" fi - i=$((i+1)) + i=`expr $i + 1` done case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi @@ -175,14 +177,9 @@ save () { for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done echo " " } -APP_ARGS=$(save "$@") +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" "$@" diff --git a/gradlew.bat b/gradlew.bat index 24467a1..a9f778a 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -29,6 +29,9 @@ if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @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" @@ -81,6 +84,7 @@ set CMD_LINE_ARGS=%* set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% diff --git a/src/test/java/org/xbib/jacc/test/JaccMainTest.java b/src/test/java/org/xbib/jacc/test/JaccMainTest.java index 5d26455..f3bab80 100644 --- a/src/test/java/org/xbib/jacc/test/JaccMainTest.java +++ b/src/test/java/org/xbib/jacc/test/JaccMainTest.java @@ -1,6 +1,6 @@ package org.xbib.jacc.test; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xbib.jacc.Jacc; public class JaccMainTest { diff --git a/src/test/java/org/xbib/jacc/test/JaccTest.java b/src/test/java/org/xbib/jacc/test/JaccTest.java index 6f715dd..049c6aa 100644 --- a/src/test/java/org/xbib/jacc/test/JaccTest.java +++ b/src/test/java/org/xbib/jacc/test/JaccTest.java @@ -1,6 +1,6 @@ package org.xbib.jacc.test; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xbib.jacc.Jacc; import org.xbib.jacc.MachineType; diff --git a/src/test/java/org/xbib/jacc/test/StreamMatcher.java b/src/test/java/org/xbib/jacc/test/StreamMatcher.java index 08a2576..baa630e 100644 --- a/src/test/java/org/xbib/jacc/test/StreamMatcher.java +++ b/src/test/java/org/xbib/jacc/test/StreamMatcher.java @@ -1,7 +1,6 @@ package org.xbib.jacc.test; -import org.junit.Assert; - +import org.junit.jupiter.api.Assertions; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -10,7 +9,7 @@ import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; import java.nio.charset.StandardCharsets; -public class StreamMatcher extends Assert { +public class StreamMatcher { public static void assertStream(String name, InputStream expected, String actual) throws IOException { assertStream(name, expected, new ByteArrayInputStream(actual.getBytes(StandardCharsets.UTF_8))); @@ -22,13 +21,13 @@ public class StreamMatcher extends Assert { ReadableByteChannel ch2 = Channels.newChannel(actual); ByteBuffer buf1 = ByteBuffer.allocateDirect(4096); ByteBuffer buf2 = ByteBuffer.allocateDirect(4096); - try { + try (expected; actual) { while (true) { int n1 = ch1.read(buf1); int n2 = ch2.read(buf2); if (n1 == -1 || n2 == -1) { if (n1 != n2) { - fail(name + ": stream length mismatch: " + n1 + " != " + n2 + " offset=" + offset); + Assertions.fail(name + ": stream length mismatch: " + n1 + " != " + n2 + " offset=" + offset); } else { return; } @@ -39,7 +38,7 @@ public class StreamMatcher extends Assert { int b1 = buf1.get() & 0xFF; int b2 = buf2.get() & 0xFF; if (b1 != b2) { - fail(name + ": mismatch at offset " + (offset + i) + Assertions.fail(name + ": mismatch at offset " + (offset + i) + " (" + Integer.toHexString(b1) + " != " + Integer.toHexString(b2) + ")" ); @@ -49,9 +48,6 @@ public class StreamMatcher extends Assert { buf2.compact(); offset += Math.min(n1, n2); } - } finally { - expected.close(); - actual.close(); } } }