From 5a98e1d32296b0a201af52ae92d2218ab73c2901 Mon Sep 17 00:00:00 2001 From: "Dr. Ernie Prabhakar" Date: Mon, 23 Dec 2024 11:41:32 -0800 Subject: [PATCH] 265 2410x causes stackoverflowerror (#284) Replace JSON parser to fix stackoverflow. Fully support groovy4. --------- Co-authored-by: Dr. Ernie Prabhakar <19791+drernie@users.noreply.github.com> --- build.gradle | 10 +++++----- gradle-groovysh-init.gradle | 2 +- groovysh-task.gradle | 6 +++--- plugins/build.gradle | 2 +- plugins/nf-quilt/build.gradle | 16 ++++------------ .../src/main/nextflow/quilt/QuiltProduct.groovy | 3 +-- .../main/nextflow/quilt/jep/QuiltPackage.groovy | 14 ++++++++++++-- 7 files changed, 27 insertions(+), 26 deletions(-) diff --git a/build.gradle b/build.gradle index 51d25bb0..33524617 100644 --- a/build.gradle +++ b/build.gradle @@ -40,7 +40,7 @@ if (groovyVer) { // (Optional) If transitive Groovy dependencies cause conflicts force "org.${groovySource}.groovy:groovy-all:$groovyVer" - if ((details.requested.group == 'org.codehaus.groovy') && details.requested.version != groovyVer) { + if ((details.requested.group == "org.${groovySource}.groovy") && details.requested.version != groovyVer) { if (groovyVer.contains(':')) { details.useTarget(groovyVer) } @@ -82,17 +82,17 @@ allprojects { idea { module.inheritOutputDirs = true } - repositories { mavenCentral() - maven { url 'https://repo.eclipse.org/content/groups/releases' } - maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } + maven { url = 'https://repo.eclipse.org/content/groups/releases' } + maven { url = 'https://oss.sonatype.org/content/repositories/snapshots' } } - configurations { // see https://docs.gradle.org/4.1/userguide/dependency_management.html#sub:exclude_transitive_dependencies all*.exclude group: 'org.codehaus.groovy', module: 'groovy-all' all*.exclude group: 'org.codehaus.groovy', module: 'groovy-cli-picocli' + all*.exclude group: 'org.apache.groovy', module: 'groovy-all' + all*.exclude group: 'org.apache.groovy', module: 'groovy-cli-picocli' // groovydoc libs groovyDoc.extendsFrom runtime } diff --git a/gradle-groovysh-init.gradle b/gradle-groovysh-init.gradle index d568defc..fa47c759 100644 --- a/gradle-groovysh-init.gradle +++ b/gradle-groovysh-init.gradle @@ -14,7 +14,7 @@ gradle.projectsLoaded { project.dependencies { groovyshdependencies("org.${groovySource}.groovy:groovy-groovysh:${GroovySystem.version}") { - exclude group: 'org.codehaus.groovy' + exclude group: "org.${groovySource}.groovy" } } diff --git a/groovysh-task.gradle b/groovysh-task.gradle index 670f876e..64873f26 100644 --- a/groovysh-task.gradle +++ b/groovysh-task.gradle @@ -6,7 +6,7 @@ gradle.projectsLoaded { // To be able to load org.codehaus.groovy:groovy-groovysh and dependencies mavenCentral { content { - includeGroup 'org.codehaus.groovy' + includeGroup "org.${groovySource}.groovy" includeGroup 'jline' includeGroup 'com.github.javaparser' includeGroup 'org.ow2.asm' @@ -22,7 +22,7 @@ gradle.projectsLoaded { project.dependencies { groovyshdependencies "org.${groovySource}.groovy:groovy-groovysh:$groovyVer" { - exclude group: 'org.codehaus.groovy' + exclude group: "org.${groovySource}.groovy" } } @@ -37,7 +37,7 @@ gradle.projectsLoaded { def groovyshClass def groovyShell - groovyshClass = Class.forName('org.codehaus.groovy.groovysh.Groovysh', true, groovyshClassLoader) + groovyshClass = Class.forName("org.${groovySource}.groovy.groovysh.Groovysh", true, groovyshClassLoader) if (groovyshClass) { groovyShell = groovyshClass.newInstance() if (groovyShell) { diff --git a/plugins/build.gradle b/plugins/build.gradle index a2bae1d7..02eeb70a 100644 --- a/plugins/build.gradle +++ b/plugins/build.gradle @@ -117,7 +117,7 @@ subprojects { tasks.register('copyPluginLibs', Sync) { from configurations.runtimeClasspath into 'build/target/libs' - duplicatesStrategy 'exclude' + duplicatesStrategy = 'exclude' } /* diff --git a/plugins/nf-quilt/build.gradle b/plugins/nf-quilt/build.gradle index 1ff648db..1f3ecb3e 100644 --- a/plugins/nf-quilt/build.gradle +++ b/plugins/nf-quilt/build.gradle @@ -72,33 +72,25 @@ dependencies { // This dependency is exported to consumers, that is to say found on their compile classpath. compileOnly "io.nextflow:nextflow:$nextflowVersion" - // compileOnly "io.nextflow:nf-commons:$nextflowVersion" compileOnly 'org.slf4j:slf4j-api:2.1.0-alpha1' - compileOnly 'org.pf4j:pf4j:3.13.0' - // add here plugins depepencies - // compileOnly 'org.slf4j:slf4j-simple:2.1.0-alpha1' - // compileOnly 'black.ninia:jep:4.2.2' - // runtime 'black.ninia:jep:4.2.2' + compileOnly 'org.pf4j:pf4j:3.12.0' runtimeOnly 'org.junit.platform:junit-platform-launcher:1.11.3' implementation 'commons-io:commons-io:2.17.0' - // implementation 'black.ninia:jep:4.2.2' - // testImplementation 'black.ninia:jep:4.2.2' - //testImplementation(testFixtures('black.ninia:jep:4.0.3')) // test configuration testImplementation "io.nextflow:nextflow:$nextflowVersion" // testImplementation "io.nextflow:nf-commons:$nextflowVersion" testImplementation "org.${groovySource}.groovy:groovy:$groovyVersion" testImplementation "org.${groovySource}.groovy:groovy-nio:$groovyVersion" - testImplementation ("org.${groovySource}.groovy:groovy-test:$groovyVersion") { exclude group: 'org.codehaus.groovy' } + testImplementation ("org.${groovySource}.groovy:groovy-test:$groovyVersion") { exclude group: "org.${groovySource}.groovy" } testImplementation('cglib:cglib-nodep:3.3.0') testImplementation('org.objenesis:objenesis:3.4') testImplementation("org.spockframework:spock-core:2.3-$groovyV") { - exclude group: 'org.codehaus.groovy' + exclude group: "org.${groovySource}.groovy" exclude group: 'net.bytebuddy' } testImplementation("org.spockframework:spock-junit4:2.3-$groovyV") { - exclude group: 'org.codehaus.groovy' + exclude group: "org.${groovySource}.groovy" exclude group: 'net.bytebuddy' } testImplementation('com.google.jimfs:jimfs:1.3.0') diff --git a/plugins/nf-quilt/src/main/nextflow/quilt/QuiltProduct.groovy b/plugins/nf-quilt/src/main/nextflow/quilt/QuiltProduct.groovy index 5240bbe1..d8b19870 100644 --- a/plugins/nf-quilt/src/main/nextflow/quilt/QuiltProduct.groovy +++ b/plugins/nf-quilt/src/main/nextflow/quilt/QuiltProduct.groovy @@ -34,7 +34,6 @@ import java.time.LocalDateTime import groovy.transform.CompileStatic import groovy.text.GStringTemplateEngine import groovy.util.logging.Slf4j -import groovy.json.JsonOutput /** * Plugin observer of workflow events @@ -411,7 +410,7 @@ ${nextflow} } try { - String qs_json = JsonOutput.toJson(quilt_summarize) + String qs_json = QuiltPackage.arrayToJson(quilt_summarize) writeString(qs_json, pkg, SUMMARY_FILE) } catch (Exception e) { diff --git a/plugins/nf-quilt/src/main/nextflow/quilt/jep/QuiltPackage.groovy b/plugins/nf-quilt/src/main/nextflow/quilt/jep/QuiltPackage.groovy index abc4ec17..1c19f6c8 100644 --- a/plugins/nf-quilt/src/main/nextflow/quilt/jep/QuiltPackage.groovy +++ b/plugins/nf-quilt/src/main/nextflow/quilt/jep/QuiltPackage.groovy @@ -39,12 +39,15 @@ import com.quiltdata.quiltcore.key.LocalPhysicalKey import com.quiltdata.quiltcore.key.S3PhysicalKey import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.databind.ObjectWriter import com.fasterxml.jackson.databind.node.ObjectNode @Slf4j @CompileStatic class QuiltPackage { + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper() + private static final ObjectWriter OBJECT_WRITER = OBJECT_MAPPER.writerWithDefaultPrettyPrinter() private static final Map PKGS = [:] private static final String INSTALL_PREFIX = 'QuiltPackage' static final Path INSTALL_ROOT = Files.createTempDirectory(INSTALL_PREFIX) @@ -74,13 +77,20 @@ class QuiltPackage { return str.replace('\'', '_') } + static String arrayToJson(List array) { + List entries = array.collect { dict -> + return toJson(dict) + } + return "[${entries.join(',')}]".toString() + } + static String toJson(Map dict) { List entries = dict.collect { key, value -> - String prefix = JsonOutput.toJson(key) + String prefix = OBJECT_WRITER.writeValueAsString(key) log.debug("toJson.${key}: ${value}") String suffix = "toJson.error[${value}]" try { - suffix = JsonOutput.toJson(value) + suffix = OBJECT_WRITER.writeValueAsString(value) } catch (Exception e) { log.error(suffix, e)