Skip to content

Upgrade to Groovy 5 #6220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ allprojects {

// Documentation required libraries
groovyDoc 'org.fusesource.jansi:jansi:2.4.0'
groovyDoc "org.apache.groovy:groovy-groovydoc:4.0.27"
groovyDoc "org.apache.groovy:groovy-ant:4.0.27"
groovyDoc "org.apache.groovy:groovy-groovydoc:5.0.0-beta-1"
groovyDoc "org.apache.groovy:groovy-ant:5.0.0-beta-1"
}

test {
Expand Down
14 changes: 7 additions & 7 deletions modules/nextflow/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ dependencies {
api(project(':nf-commons'))
api(project(':nf-httpfs'))
api(project(':nf-lang'))
api "org.apache.groovy:groovy:4.0.27"
api "org.apache.groovy:groovy-nio:4.0.27"
api "org.apache.groovy:groovy-xml:4.0.27"
api "org.apache.groovy:groovy-json:4.0.27"
api "org.apache.groovy:groovy-templates:4.0.27"
api "org.apache.groovy:groovy-yaml:4.0.27"
api "org.apache.groovy:groovy:5.0.0-beta-1"
api "org.apache.groovy:groovy-nio:5.0.0-beta-1"
api "org.apache.groovy:groovy-xml:5.0.0-beta-1"
api "org.apache.groovy:groovy-json:5.0.0-beta-1"
api "org.apache.groovy:groovy-templates:5.0.0-beta-1"
api "org.apache.groovy:groovy-yaml:5.0.0-beta-1"
api "org.slf4j:jcl-over-slf4j:2.0.16"
api "org.slf4j:jul-to-slf4j:2.0.16"
api "org.slf4j:log4j-over-slf4j:2.0.16"
Expand All @@ -57,7 +57,7 @@ dependencies {
testImplementation 'org.subethamail:subethasmtp:3.1.7'
testImplementation (project(':nf-lineage'))
// test configuration
testFixturesApi ("org.apache.groovy:groovy-test:4.0.27") { exclude group: 'org.apache.groovy' }
testFixturesApi ("org.apache.groovy:groovy-test:5.0.0-beta-1") { exclude group: 'org.apache.groovy' }
testFixturesApi ("org.objenesis:objenesis:3.4")
testFixturesApi ("net.bytebuddy:byte-buddy:1.14.17")
testFixturesApi ("org.spockframework:spock-core:2.3-groovy-4.0") { exclude group: 'org.apache.groovy' }
Expand Down
2 changes: 1 addition & 1 deletion modules/nextflow/src/main/groovy/nextflow/Session.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ class Session implements ISession {
def fetchContainers() {

def result = [:]
if( config.process instanceof Map<String,?> ) {
if( config.process instanceof Map ) {

/*
* look for `container` definition at process level
Expand Down
3 changes: 2 additions & 1 deletion modules/nextflow/src/main/groovy/nextflow/cli/CmdLog.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ class CmdLog extends CmdBase implements CacheBase {
/**
* Wrap a {@link TraceRecord} instance as a {@link Map} or a {@link Binding} object
*/
@Slf4j
private static class TraceAdaptor extends Binding {

static private int MAX_LINES = 100
Expand Down Expand Up @@ -299,7 +300,7 @@ class CmdLog extends CmdBase implements CacheBase {
def result = new StringBuilder()
path.withReader { reader ->
String line
while( (line=reader.readLine()) && c++<MAX_LINES ) {
while( (line=reader.readLine()) && c++ < MAX_LINES ) {
result << line << '\n'
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ class ExecutorFactory {

@PackageScope Map<String, Class<? extends Executor>> executorsMap

private Map<Class<? extends Executor>,? extends Executor> executors = new HashMap<>()
private Map<Class<? extends Executor>,Executor> executors = new HashMap<>()

@PackageScope Map<Class<? extends Executor>,? extends Executor> getExecutors() { executors }
@PackageScope Map<Class<? extends Executor>,Executor> getExecutors() { executors }

ExecutorFactory() {
init0(Collections.<Class<Executor>>emptyList())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class CombineOp {
}

CombineOp setPivot( pivot ) {
this.pivot = (List<Integer>)(pivot instanceof List<Integer> ? pivot : [pivot])
this.pivot = (List<Integer>)(pivot instanceof List ? pivot : [pivot])
return this
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ class DumpOp {
DataflowWriteChannel apply() {

if( !isEnabled() ) {
if( source instanceof DataflowWriteChannel )
return (DataflowWriteChannel)source
if( source instanceof DataflowWriteChannel dwc )
return dwc
throw new IllegalArgumentException("Illegal dump operator source channel")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ class PublishOp {
this.source = source
this.publishOpts = opts
this.path = opts.path as String
if( opts.pathResolver instanceof Closure )
this.pathResolver = opts.pathResolver as Closure
if( opts.index )
this.indexOpts = new IndexOpts(session.outputDir, opts.index as Map)
if( opts.pathResolver instanceof Closure cl )
this.pathResolver = cl
if( opts.index instanceof Map indexOpts )
this.indexOpts = new IndexOpts(session.outputDir, indexOpts)
}

boolean getComplete() { complete }
Expand Down Expand Up @@ -140,7 +140,7 @@ class PublishOp {
// if the closure contained publish statements, use
// the resulting mapping to create a saveAs closure
final mapping = dsl.build()
if( mapping instanceof Map<String,String> )
if( mapping instanceof Map )
return { filename -> outputDir.resolve(mapping[filename]) }

// if the resolved publish path is a string, resolve it
Expand All @@ -160,11 +160,11 @@ class PublishOp {
if( source instanceof Path ) {
publish0(source, target)
}
else if( source instanceof Collection<Path> ) {
else if( source instanceof Collection ) {
if( !target.endsWith('/') )
throw new ScriptRuntimeException("Invalid publish target '${target}' -- should be a directory (end with a `/`) when publishing a collection of files")
for( final path : source )
publish0(path, target)
publish0((Path) path, target)
}
else {
throw new ScriptRuntimeException("Publish source should be a file or collection of files, but received a ${source.class.name}")
Expand Down Expand Up @@ -267,7 +267,7 @@ class PublishOp {
return value.collect { el ->
if( el instanceof Path )
return normalizePath(el, targetResolver)
if( el instanceof Collection<Path> )
if( el instanceof Collection )
return normalizePaths(el, targetResolver)
return el
}
Expand All @@ -279,7 +279,7 @@ class PublishOp {
.collectEntries { k, v ->
if( v instanceof Path )
return Map.entry(k, normalizePath(v, targetResolver))
if( v instanceof Collection<Path> )
if( v instanceof Collection )
return Map.entry(k, normalizePaths(v, targetResolver))
return Map.entry(k, v)
}
Expand All @@ -304,7 +304,7 @@ class PublishOp {

// if the target resolver is a closure, use it to transform
// the source filename to the target path
if( targetResolver instanceof Closure<Path> )
if( targetResolver instanceof Closure )
return (targetResolver.call(path.getName()) as Path).normalize()

// if the target resolver is a directory, resolve the source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class SplitOp {
multiSplit = true
pairedEnd = true
}
if( params.elem instanceof List<Integer> ) {
if( params.elem instanceof List ) {
indexes = params.elem as List<Integer>
multiSplit = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ interface DirListener {
* @param events the list of events to watch
* @return
*/
default WatchEvent.Kind<Path>[] stringToWatchEvents(String events = null){
default WatchEvent.Kind<Path>[] stringToWatchEvents(String events) {
def result = []
if( !events )
result << ENTRY_CREATE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class PublishDir {

void setPath( def value ) {
final resolved = value instanceof Closure ? value.call() : value
if( resolved instanceof String || resolved instanceof GString )
if( resolved instanceof CharSequence )
nullPathWarn = checkNull(resolved.toString())
this.path = FileHelper.toCanonicalPath(resolved)
}
Expand All @@ -169,7 +169,7 @@ class PublishDir {
? tags.call()
: tags

if( result instanceof Map<String,String> )
if( result instanceof Map )
return result

throw new IllegalArgumentException("Invalid publishDir tags attribute: $tags")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ class TaskConfig extends LazyMap implements Cloneable {
this.cache.clear()

// set the binding context for 'ext' map
if( target.ext instanceof LazyMap )
(target.ext as LazyMap).binding = context
if( getTarget().ext instanceof LazyMap ext )
ext.binding = context

// set the this object in the task context in order to allow task properties to be resolved in process script
context.put(TASK_CONTEXT_PROPERTY_NAME, this)
Expand Down Expand Up @@ -133,7 +133,7 @@ class TaskConfig extends LazyMap implements Cloneable {
}

final getRawValue(String key) {
return target.get(key)
return getTarget().get(key)
}

def get( String key ) {
Expand All @@ -142,11 +142,11 @@ class TaskConfig extends LazyMap implements Cloneable {

def result
if( key == 'ext' ) {
if( target.containsKey(key) )
result = target.get(key)
if( getTarget().containsKey(key) )
result = getTarget().get(key)
else {
result = new LazyMap()
target.put(key, result)
getTarget().put(key, result)
}
}
else
Expand All @@ -167,7 +167,7 @@ class TaskConfig extends LazyMap implements Cloneable {
super.setDynamic(flag)
}
}
target.put(key, value)
getTarget().put(key, value)
}
else if( key == 'ext' && value instanceof Map ) {
super.put( key, new LazyMap(value) )
Expand All @@ -181,8 +181,8 @@ class TaskConfig extends LazyMap implements Cloneable {
if( super.isDynamic() )
return true

if( target.ext instanceof LazyMap )
return (target.ext as LazyMap).isDynamic()
if( getTarget().ext instanceof LazyMap ext )
return ext.isDynamic()

return false
}
Expand Down Expand Up @@ -551,7 +551,7 @@ class TaskConfig extends LazyMap implements Cloneable {
*/
protected boolean getWhenGuard(boolean defValue=true) throws FailedGuardException {

final code = target.get(NextflowDSLImpl.PROCESS_WHEN)
final code = getTarget().get(NextflowDSLImpl.PROCESS_WHEN)
if( code == null )
return defValue

Expand All @@ -571,7 +571,7 @@ class TaskConfig extends LazyMap implements Cloneable {


protected TaskClosure getStubBlock() {
final code = target.get(NextflowDSLImpl.PROCESS_STUB)
final code = getTarget().get(NextflowDSLImpl.PROCESS_STUB)
if( !code )
return null
if( code instanceof TaskClosure )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ class TaskProcessor {
if( value instanceof Path ) {
files.add((Path)value)
}
else if( value instanceof Collection<Path> ) {
else if( value instanceof Collection ) {
files.addAll(value)
}
else if( value != null ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ class AssetManager {
return

List<String> filter = []
if( modules instanceof List<String> ) {
if( modules instanceof List ) {
filter.addAll(modules)
}
else if( modules instanceof String ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,17 @@ class ScriptBinding extends WorkflowBinding {
// create and populate args
args = new ArrayList<>()
if( vars.args ) {
if( !(vars.args instanceof List<String>) ) throw new IllegalArgumentException("ScriptBinding 'args' must be a List value")
if( !(vars.args instanceof List) )
throw new IllegalArgumentException("ScriptBinding 'args' must be a List value")
args.addAll((List<String>)vars.args)
}
vars.put('args', args)

// create and populate args
params = new ParamsMap()
if( vars.params ) {
if( !(vars.params instanceof Map) ) throw new IllegalArgumentException("ScriptBinding 'params' must be a Map value")
if( !(vars.params instanceof Map) )
throw new IllegalArgumentException("ScriptBinding 'params' must be a Map value")
params.putAll((Map)vars.params)
}
vars.params = params
Expand Down Expand Up @@ -203,6 +205,7 @@ class ScriptBinding extends WorkflowBinding {
/**
* Implements immutable params map
*/
@Slf4j
@CompileStatic
static class ParamsMap implements Map<String,Object> {

Expand Down Expand Up @@ -237,7 +240,7 @@ class ScriptBinding extends WorkflowBinding {
final msg = "Access to undefined parameter `$key` -- Initialise it to a default value eg. `params.$key = some_value`"
if( NF.isStrictMode() )
throw new AbortOperationException(msg)
log.warn1(msg, firstOnly: true)
log.warn1(msg)
return null
}
return target.get(key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class ResourcesAggregator {
final summary = summaries[process]
summary.names.each { String series ->
// the task execution turn a triple
tasks << { return [ process, series, summary.compute(series)] } as Callable<List>
tasks.add({ -> [process, series, summary.compute(series)] } as Callable<List>)
}
// initialise the result entry
result.put(process, new HashMap(10))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class KryoHelper {
if( v instanceof Class )
kryo.register(k,(Serializer)v.newInstance())

else if( v instanceof Closure<Serializer> )
else if( v instanceof Closure )
kryo.register(k, v.call(kryo))

else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class SimpleAgent<T> {
}
}

@Slf4j
@CompileStatic
private static class RetrieveValueClosure<T> extends Closure {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,12 @@ class ThreadPoolHelper {
}
}

static protected int pending(ExecutorService pool) {
if( pool instanceof ThreadPoolExecutor) {
final p1 = ((ThreadPoolExecutor)pool)
return p1.getTaskCount() - p1.getCompletedTaskCount()
static protected long pending(ExecutorService pool) {
if( pool instanceof ThreadPoolExecutor tpe ) {
return tpe.getTaskCount() - tpe.getCompletedTaskCount()
}
else if( pool instanceof ThreadContainer ) {
return pool.threadCount()
else if( pool instanceof ThreadContainer tc ) {
return tc.threadCount()
}
return -1
}
Expand Down
6 changes: 3 additions & 3 deletions modules/nf-commons/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ sourceSets {

dependencies {
api "ch.qos.logback:logback-classic:1.5.16"
api "org.apache.groovy:groovy:4.0.27"
api "org.apache.groovy:groovy-nio:4.0.27"
api "org.apache.groovy:groovy:5.0.0-beta-1"
api "org.apache.groovy:groovy-nio:5.0.0-beta-1"
api "commons-lang:commons-lang:2.6"
api 'com.google.guava:guava:33.0.0-jre'
api 'org.pf4j:pf4j:3.12.0'
Expand All @@ -40,7 +40,7 @@ dependencies {
testImplementation(testFixtures(project(":nextflow")))
testFixturesImplementation(project(":nextflow"))

testImplementation "org.apache.groovy:groovy-json:4.0.27" // needed by wiremock
testImplementation "org.apache.groovy:groovy-json:5.0.0-beta-1" // needed by wiremock
testImplementation ('com.github.tomakehurst:wiremock:3.0.0-beta-1') { exclude module: 'groovy-all' }
testImplementation ('com.github.tomjankes:wiremock-groovy:0.2.0') { exclude module: 'groovy-all' }
}
Expand Down
Loading
Loading