diff --git a/plugins/nf-sqldb/build.gradle b/plugins/nf-sqldb/build.gradle index 3a4dfa8..c88f6fa 100644 --- a/plugins/nf-sqldb/build.gradle +++ b/plugins/nf-sqldb/build.gradle @@ -54,9 +54,12 @@ sourceSets { test.resources.srcDirs = [] } +ext{ + nextflowVersion = '22.08.1-edge' +} dependencies { - compileOnly 'io.nextflow:nextflow:22.04.0' + compileOnly "io.nextflow:nextflow:$nextflowVersion" compileOnly 'org.slf4j:slf4j-api:1.7.10' compileOnly 'org.pf4j:pf4j:3.4.1' @@ -69,7 +72,7 @@ dependencies { api 'org.duckdb:duckdb_jdbc:0.3.0' api files('src/dist/lib/AthenaJDBC42_2.0.25.1001.jar') - testImplementation 'io.nextflow:nextflow:22.06.0-edge' + testImplementation "io.nextflow:nextflow:$nextflowVersion" testImplementation "org.codehaus.groovy:groovy:3.0.10" testImplementation "org.codehaus.groovy:groovy-nio:3.0.10" testImplementation ("org.codehaus.groovy:groovy-test:3.0.10") { exclude group: 'org.codehaus.groovy' } @@ -78,6 +81,9 @@ dependencies { testImplementation ("org.spockframework:spock-core:2.1-groovy-3.0") { exclude group: 'org.codehaus.groovy'; exclude group: 'net.bytebuddy' } testImplementation ('org.spockframework:spock-junit4:2.1-groovy-3.0') { exclude group: 'org.codehaus.groovy'; exclude group: 'net.bytebuddy' } testImplementation ('com.google.jimfs:jimfs:1.1') + + testImplementation(testFixtures("io.nextflow:nextflow:$nextflowVersion")) + testImplementation(testFixtures("io.nextflow:nf-commons:$nextflowVersion")) } test { diff --git a/plugins/nf-sqldb/src/main/nextflow/sql/ChannelSqlExtension.groovy b/plugins/nf-sqldb/src/main/nextflow/sql/ChannelSqlExtension.groovy index f9332bc..8f37470 100644 --- a/plugins/nf-sqldb/src/main/nextflow/sql/ChannelSqlExtension.groovy +++ b/plugins/nf-sqldb/src/main/nextflow/sql/ChannelSqlExtension.groovy @@ -27,9 +27,8 @@ import nextflow.Channel import nextflow.NF import nextflow.Session import nextflow.extension.CH -import nextflow.extension.ChannelExtensionPoint import nextflow.extension.DataflowHelper -import nextflow.plugin.Scoped +import nextflow.plugin.extension.PluginExtensionPoint import nextflow.sql.config.SqlConfig import nextflow.sql.config.SqlDataSource import nextflow.util.CheckHelper @@ -40,8 +39,7 @@ import nextflow.util.CheckHelper */ @Slf4j @CompileStatic -@Scoped('sql') -class ChannelSqlExtension extends ChannelExtensionPoint { +class ChannelSqlExtension extends PluginExtensionPoint { private static final Map QUERY_PARAMS = [ db: CharSequence, diff --git a/plugins/nf-sqldb/src/main/nextflow/sql/InsertHandler.groovy b/plugins/nf-sqldb/src/main/nextflow/sql/InsertHandler.groovy index b3ead8f..b81a200 100644 --- a/plugins/nf-sqldb/src/main/nextflow/sql/InsertHandler.groovy +++ b/plugins/nf-sqldb/src/main/nextflow/sql/InsertHandler.groovy @@ -208,7 +208,7 @@ class InsertHandler implements Closeable { final metaData = conn.getMetaData() final resultSet = metaData.getColumns(null, null, tableName, null); - final result = [] + final result = [] as List while (resultSet.next()){ result.add( resultSet.getString("COLUMN_NAME") ) } diff --git a/plugins/nf-sqldb/src/test/nextflow/sql/SqlDslTest.groovy b/plugins/nf-sqldb/src/test/nextflow/sql/SqlDslTest.groovy index ec01ba1..f67f814 100644 --- a/plugins/nf-sqldb/src/test/nextflow/sql/SqlDslTest.groovy +++ b/plugins/nf-sqldb/src/test/nextflow/sql/SqlDslTest.groovy @@ -19,28 +19,54 @@ package nextflow.sql import groovy.sql.Sql import nextflow.Channel -import nextflow.extension.ChannelExtensionProvider +import nextflow.plugin.Plugins +import nextflow.plugin.TestPluginDescriptorFinder +import nextflow.plugin.TestPluginManager +import nextflow.plugin.extension.PluginExtensionProvider +import org.pf4j.PluginDescriptorFinder +import spock.lang.Shared import spock.lang.Timeout -import test.BaseSpec +import test.Dsl2Spec import test.MockScriptRunner +import java.nio.file.Path + /** * * @author Paolo Di Tommaso */ @Timeout(10) -class SqlDslTest extends BaseSpec { - - def setup () { - new ChannelExtensionProvider() - .install() - .loadPluginExtensionMethods(new ChannelSqlExtension(), ['fromQuery':'fromQuery', sqlInsert:'sqlInsert']) +class SqlDslTest extends Dsl2Spec { + + @Shared String pluginsMode + + def setup() { + // reset previous instances + PluginExtensionProvider.reset() + // this need to be set *before* the plugin manager class is created + pluginsMode = System.getProperty('pf4j.mode') + System.setProperty('pf4j.mode', 'dev') + // the plugin root should + def root = Path.of('.').toAbsolutePath().normalize() + def manager = new TestPluginManager(root){ + @Override + protected PluginDescriptorFinder createPluginDescriptorFinder() { + return new TestPluginDescriptorFinder(){ + @Override + protected Path getManifestPath(Path pluginPath) { + return pluginPath.resolve('build/resources/main/META-INF/MANIFEST.MF') + } + } + } + } + Plugins.init(root, 'dev', manager) } def cleanup() { - ChannelExtensionProvider.reset() + Plugins.stop() + PluginExtensionProvider.reset() + pluginsMode ? System.setProperty('pf4j.mode',pluginsMode) : System.clearProperty('pf4j.mode') } - def 'should perform a query and create a channel' () { given: def JDBC_URL = 'jdbc:h2:mem:test_' + Random.newInstance().nextInt(1_000_000) @@ -55,6 +81,7 @@ class SqlDslTest extends BaseSpec { when: def SCRIPT = ''' + include { fromQuery; sqlInsert } from 'plugin/nf-sqldb' def table = 'FOO' def sql = "select * from $table" channel.fromQuery(sql, db: "test") @@ -80,6 +107,7 @@ class SqlDslTest extends BaseSpec { when: def SCRIPT = ''' + include { fromQuery; sqlInsert } from 'plugin/nf-sqldb' channel .of(100,200,300) .sqlInsert(into:"FOO", columns:'id', db:"ds1") @@ -110,6 +138,7 @@ class SqlDslTest extends BaseSpec { when: def SCRIPT = ''' + include { fromQuery; sqlInsert } from 'plugin/nf-sqldb' channel .of(100,200,300,400,500) .sqlInsert(into:'FOO', columns:'id', db:'ds1', batchSize: 2) @@ -145,6 +174,7 @@ class SqlDslTest extends BaseSpec { when: def SCRIPT = ''' + include { fromQuery; sqlInsert } from 'plugin/nf-sqldb' def table = 'FOO' def sql = "select * from $table" channel.fromQuery(sql, db: "test", emitColumns:true)