From 709476cd7ba70edd4427ee572d455cf82a896d41 Mon Sep 17 00:00:00 2001 From: Andreas Reichel Date: Tue, 4 Feb 2025 09:32:54 +0700 Subject: [PATCH] build: update gradle syntax Signed-off-by: Andreas Reichel --- build.gradle | 188 ++++++++++++++++++++++++------------------------ settings.gradle | 5 -- 2 files changed, 96 insertions(+), 97 deletions(-) delete mode 100644 settings.gradle diff --git a/build.gradle b/build.gradle index d324266c1..a99fdd33b 100644 --- a/build.gradle +++ b/build.gradle @@ -27,48 +27,41 @@ def getVersion = { boolean considerSnapshot -> Integer minor = 0 Integer patch = null Integer build = null - def commit = null - def snapshot = "" - new ByteArrayOutputStream().withStream { os -> - exec { - args = [ - "--no-pager" - , "describe" - , "--tags" - , "--always" - , "--dirty=-SNAPSHOT" - ] - executable "git" - standardOutput = os - } - def versionStr = os.toString().trim() - def pattern = /(?\d*)\.(?\d*)(\.(?\d*))?(-(?\d*)-(?[a-zA-Z\d]*))?/ - def matcher = versionStr =~ pattern - if (matcher.find()) { - major = matcher.group('major') as Integer - minor = matcher.group('minor') as Integer - patch = matcher.group('patch') as Integer - build = matcher.group('build') as Integer - commit = matcher.group('commit') - } + String commit = null + String snapshot = "" + + def versionStr = providers.exec { + commandLine "git", "--no-pager", "describe", "--tags", "--always", "--dirty=-SNAPSHOT" + }.standardOutput.asText.get().trim() + + def pattern = /(?\d*)\.(?\d*)(\.(?\d*))?(-(?\d*)-(?[a-zA-Z\d]*))?/ + def matcher = versionStr =~ pattern + + if (matcher.find()) { + major = matcher.group('major') as Integer ?: 0 + minor = matcher.group('minor') as Integer ?: 0 + patch = matcher.group('patch') as Integer ?: null + build = matcher.group('build') as Integer ?: null + commit = matcher.group('commit') ?: null + } - if (considerSnapshot && ( versionStr.endsWith('SNAPSHOT') || build!=null) ) { - minor++ - if (patch!=null) patch = 0 - snapshot = "-SNAPSHOT" - } + if (considerSnapshot && (versionStr.endsWith('SNAPSHOT') || build != null)) { + minor++ + if (patch != null) patch = 0 + snapshot = "-SNAPSHOT" } - return patch!=null + + return patch != null ? "${major}.${minor}.${patch}${snapshot}" - : "${major}.${minor}${snapshot}" + : "${major}.${minor}${snapshot}" } + // for publishing a release, call Gradle with Environment Variable RELEASE: // RELEASE=true gradle JSQLParser:publish version = getVersion( !System.getenv("RELEASE") ) group = 'com.github.jsqlparser' description = 'JSQLParser library' -archivesBaseName = "JSQLParser" repositories { gradlePluginPortal() @@ -262,14 +255,13 @@ jacocoTestCoverageVerification { spotbugsMain { reports { - html { - enabled = true - destination = file("build/reports/spotbugs/main/spotbugs.html") - stylesheet = 'fancy-hist.xsl' - } + html.required.set(true) + html.outputLocation.set( layout.buildDirectory.file("reports/spotbugs/main/spotbugs.html").get().asFile ) + html.stylesheet="fancy-hist.xsl" } } + spotbugs { // fail only on P1 and without the net.sf.jsqlparser.parser.* excludeFilter = file("config/spotbugs/spotBugsExcludeFilter.xml") @@ -329,58 +321,58 @@ tasks.withType(Checkstyle).configureEach { tasks.register('renderRR') { dependsOn(compileJavacc) + doLast { - // these WAR files have been provided as a courtesy by Gunther Rademacher - // and belong to the RR - Railroad Diagram Generator Project - // https://github.com/GuntherRademacher/rr - // - // Hosting at manticore-projects.com is temporary until a better solution is found - // Please do not use these files without Gunther's permission + def rrDir = layout.buildDirectory.dir("rr").get().asFile + + // Download convert.war download.run { src 'http://manticore-projects.com/download/convert.war' - dest "$buildDir/rr/convert.war" + dest new File(rrDir, "convert.war") overwrite false onlyIfModified true } + // Download rr.war download.run { src 'http://manticore-projects.com/download/rr.war' - dest "$buildDir/rr/rr.war" + dest new File(rrDir, "rr.war") overwrite false onlyIfModified true tempAndMove true } - javaexec { - standardOutput = new FileOutputStream("${buildDir}/rr/JSqlParserCC.ebnf") - main = "-jar" + // Convert JJ file to EBNF + tasks.register("convertJJ", JavaExec) { + standardOutput = new FileOutputStream(new File(rrDir, "JSqlParserCC.ebnf")) + mainClass = "-jar" args = [ - "$buildDir/rr/convert.war", - "$buildDir/generated/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jj" + new File(rrDir, "convert.war").absolutePath, + layout.buildDirectory.dir("generated/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jj").get().asFile.absolutePath ] - } + }.get().exec() - javaexec { - main = "-jar" + // Generate RR diagrams + tasks.register("generateRR", JavaExec) { + mainClass = "-jar" args = [ - "$buildDir/rr/rr.war", + new File(rrDir, "rr.war").absolutePath, "-noepsilon", "-color:#4D88FF", "-offset:0", "-width:800", - //"-png", - //"-out:${buildDir}/rr/JSqlParserCC.zip", - "-out:${buildDir}/rr/JSqlParserCC.xhtml", - "${buildDir}/rr/JSqlParserCC.ebnf" + "-out:${new File(rrDir, "JSqlParserCC.xhtml")}", + new File(rrDir, "JSqlParserCC.ebnf").absolutePath ] - } + }.get().exec() } } + tasks.register('gitChangelogTask', GitChangelogTask) { fromRepo = file("$projectDir") file = new File("${projectDir}/src/site/sphinx/changelog.rst") - fromRef = "4.0" + fromRevision = "4.0" //toRef = "1.1"; // switch off the formatter since the indentation matters for Mark-down @@ -443,7 +435,7 @@ xslt { ) // Transform every .xml file in the "input" directory. - input "$buildDir/rr/JSqlParserCC.xhtml" + input layout.buildDirectory.file("rr/JSqlParserCC.xhtml") output outFile } @@ -459,11 +451,11 @@ tasks.register('sphinx', Exec) { .. |JSQLPARSER_SNAPSHOT_VERSION| replace:: ${getVersion(true)} .. |JSQLPARSER_STABLE_VERSION_LINK| raw:: html - JSQLParser-${getVersion(false)}.jar + ${project.name}-${getVersion(false)}.jar .. |JSQLPARSER_SNAPSHOT_VERSION_LINK| raw:: html - JSQLParser-${getVersion(true)}.jar + ${project.name}-${getVersion(true)}.jar """ @@ -474,7 +466,7 @@ tasks.register('sphinx', Exec) { , "-Drelease=${getVersion(false)}" , "-Drst_prolog=$PROLOG" , "${projectDir}/src/site/sphinx" - , "${project.buildDir}/sphinx" + , layout.buildDirectory.file("sphinx").get().asFile ] executable "sphinx-build" @@ -494,10 +486,11 @@ publish { publishing { publications { - mavenJava(MavenPublication) { + create("mavenJava", MavenPublication) { artifactId = 'jsqlparser' from components.java + versionMapping { usage('java-api') { fromResolutionOf('runtimeClasspath') @@ -506,54 +499,61 @@ publishing { fromResolutionResult() } } + pom { - name = 'JSQLParser library' - description = 'Parse SQL Statements into Abstract Syntax Trees (AST)' - url = 'https://github.com/JSQLParser/JSqlParser' + name.set('JSQLParser library') + description.set('Parse SQL Statements into Abstract Syntax Trees (AST)') + url.set('https://github.com/JSQLParser/JSqlParser') + licenses { license { - name = 'GNU Library or Lesser General Public License (LGPL) V2.1' - url = 'http://www.gnu.org/licenses/lgpl-2.1.html' + name.set('GNU Library or Lesser General Public License (LGPL) V2.1') + url.set('http://www.gnu.org/licenses/lgpl-2.1.html') } license { - name = 'The Apache Software License, Version 2.0' - url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + name.set('The Apache Software License, Version 2.0') + url.set('http://www.apache.org/licenses/LICENSE-2.0.txt') } } + developers { developer { - id = 'twa' - name = 'Tobias Warneke' - email = 't.warneke@gmx.net' + id.set('twa') + name.set('Tobias Warneke') + email.set('t.warneke@gmx.net') } developer { - id = 'are' - name = 'Andreas Reichel' - email = 'andreas@manticore-projects.com' + id.set('are') + name.set('Andreas Reichel') + email.set('andreas@manticore-projects.com') } } + scm { - connection = 'scm:git:https://github.com/JSQLParser/JSqlParser.git' - developerConnection = 'scm:git:ssh://git@github.com:JSQLParser/JSqlParser.git' - url = 'https://github.com/JSQLParser/JSqlParser.git' + connection.set('scm:git:https://github.com/JSQLParser/JSqlParser.git') + developerConnection.set('scm:git:ssh://git@github.com:JSQLParser/JSqlParser.git') + url.set('https://github.com/JSQLParser/JSqlParser.git') } } } } + repositories { maven { - name "ossrh" + name = "ossrh" def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/" - def snapshotsRepoUrl= "https://oss.sonatype.org/content/repositories/snapshots/" - url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl + def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/" + url(version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl) + credentials { - username = System.getenv("ossrhUsername") - password = System.getenv("ossrhPassword") + username = providers.environmentVariable("ossrhUsername").orNull + password = providers.environmentVariable("ossrhPassword").orNull } } } } + signing { //def signingKey = findProperty("signingKey") //def signingPassword = findProperty("signingPassword") @@ -571,12 +571,13 @@ tasks.withType(JavaCompile).configureEach { remotes { webServer { - host = findProperty("${project.name}.host") - user = findProperty("${project.name}.username") - identity = new File("${System.properties['user.home']}/.ssh/id_rsa") + host = findProperty("${project.name}.host") ?: "defaultHost" // Provide default if not found + user = findProperty("${project.name}.username") ?: "defaultUsername" // Provide default if not found + identity = file("${System.getProperty('user.home')}/.ssh/id_rsa") } } + tasks.register('upload') { doFirst { if (findProperty("${project.name}.host") == null) { @@ -593,13 +594,16 @@ tasks.register('upload') { session(remotes.webServer) { def versionStable = getVersion(false) execute "mkdir -p download/${project.name}-${versionStable}" - for (File file: fileTree(include:['*.jar'], dir:"${project.buildDir}/libs").collect()) { + for (File file: fileTree(include:['*.jar'], dir: layout.buildDirectory.dir("libs").get()).collect()) { put from: file, into: "download/${project.name}-${versionStable}" } } } } + + dependsOn(check, assemble, gitChangelogTask, renderRR, xslt, xmldoc) } -check.dependsOn jacocoTestCoverageVerification -upload.dependsOn(check, assemble, gitChangelogTask, renderRR, xslt, xmldoc) +check { + dependsOn jacocoTestCoverageVerification +} diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 78feb00f5..000000000 --- a/settings.gradle +++ /dev/null @@ -1,5 +0,0 @@ -/* - * This file was generated by the Gradle 'init' task. - */ - -rootProject.name = 'JSQLFormatter'