Skip to content

Commit a27ea08

Browse files
committed
Move PluginExecAware to nextflow module
Signed-off-by: Ben Sherman <bentshermann@gmail.com>
1 parent 3024ae9 commit a27ea08

9 files changed

Lines changed: 31 additions & 30 deletions

File tree

docs/plugins/developing-plugins.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ Plugins can define custom CLI commands that are executable with the `nextflow pl
148148
To implement a plugin-specific command, implement the `PluginExecAware` interface in your plugin entry point (the class that extends `BasePlugin`). Alternatively, implement the `PluginAbstractExec` trait, which provides an abstract implementation with some boilerplate code. This trait requires you to implement the `getCommands()` and `exec()` methods. For example:
149149

150150
```groovy
151-
import nextflow.cli.PluginAbstractExec
151+
import nextflow.plugin.cli.PluginAbstractExec
152152
import nextflow.plugin.BasePlugin
153153
154154
class MyPlugin extends BasePlugin implements PluginAbstractExec {

modules/nf-cli-v1/src/main/groovy/nextflow/cli/PluginAbstractExec.groovy renamed to modules/nextflow/src/main/groovy/nextflow/plugin/cli/PluginAbstractExec.groovy

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@
1414
* limitations under the License.
1515
*/
1616

17-
package nextflow.cli
18-
19-
import java.nio.file.Paths
17+
package nextflow.plugin.cli
2018

2119
import groovy.transform.CompileStatic
2220
import nextflow.Session
23-
import nextflow.config.ConfigCmdAdapter
21+
import nextflow.SysEnv
2422
import nextflow.exception.AbortOperationException
2523
import org.slf4j.Logger
2624
import org.slf4j.LoggerFactory
25+
2726
import static PluginExecAware.CMD_SEP
2827

2928
/**
@@ -37,23 +36,13 @@ trait PluginAbstractExec implements PluginExecAware {
3736
private static Logger log = LoggerFactory.getLogger(PluginAbstractExec)
3837

3938
private Session session
40-
private Launcher launcher
4139

4240
Session getSession() { session }
4341

44-
Launcher getLauncher() { launcher }
45-
4642
abstract List<String> getCommands()
4743

4844
@Override
49-
final int exec(Launcher launcher1, String pluginId, String cmd, List<String> args) {
50-
this.launcher = launcher1
51-
// create the config
52-
final config = new ConfigCmdAdapter()
53-
.setOptions(launcher1.options)
54-
.setBaseDir(Paths.get('.'))
55-
.build()
56-
45+
final int exec(String pluginId, String cmd, List<String> args) {
5746
if( !cmd || cmd !in getCommands() ) {
5847
def msg = cmd ? "Invalid command '$pluginId:$cmd' - usage: nextflow plugin ${pluginId}${CMD_SEP}<command>" : "Usage: nextflow plugin ${pluginId}${CMD_SEP}<command>"
5948
msg += "\nAvailable commands:"
@@ -63,7 +52,8 @@ trait PluginAbstractExec implements PluginExecAware {
6352
}
6453

6554
// create the session object
66-
this.session = new Session(config)
55+
this.session = new Session(getConfig())
56+
6757
// invoke the command
6858
try {
6959
exec(cmd, args)
@@ -77,7 +67,16 @@ trait PluginAbstractExec implements PluginExecAware {
7767
return 0
7868
}
7969

80-
abstract int exec(String cmd, List<String> args)
70+
private Map getConfig() {
71+
final result = [
72+
workDir: SysEnv.get('NXF_WORK') ?: 'work'
73+
]
74+
final cloudCachePath = SysEnv.get('NXF_CLOUDCACHE_PATH')
75+
if( cloudCachePath )
76+
result.cloudcache = [ enabled: true, path: cloudCachePath ]
77+
return result
78+
}
8179

80+
abstract int exec(String cmd, List<String> args)
8281

8382
}

modules/nf-cli-v1/src/main/groovy/nextflow/cli/PluginExecAware.groovy renamed to modules/nextflow/src/main/groovy/nextflow/plugin/cli/PluginExecAware.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package nextflow.cli
17+
package nextflow.plugin.cli
1818

1919
/**
2020
* Define the interface for plugin commands
@@ -25,6 +25,6 @@ interface PluginExecAware {
2525

2626
static final String CMD_SEP = ':'
2727

28-
int exec(Launcher launcher, String pluginId, String cmd, List<String> args)
28+
int exec(String pluginId, String cmd, List<String> args)
2929

3030
}

modules/nf-cli-v1/src/main/groovy/nextflow/cli/CmdPlugin.groovy

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package nextflow.cli
1818

19-
import static nextflow.cli.PluginExecAware.CMD_SEP
20-
2119
import java.nio.file.Path
2220

2321
import com.beust.jcommander.DynamicParameter
@@ -27,8 +25,11 @@ import groovy.transform.CompileStatic
2725
import nextflow.exception.AbortOperationException
2826
import nextflow.plugin.PluginRef
2927
import nextflow.plugin.Plugins
28+
import nextflow.plugin.cli.PluginExecAware
3029
import nextflow.plugin.util.PluginRefactor
3130
import org.eclipse.jgit.api.Git
31+
32+
import static nextflow.plugin.cli.PluginExecAware.CMD_SEP
3233
/**
3334
* Plugin manager command
3435
*
@@ -220,7 +221,7 @@ class CmdPlugin extends CmdBase implements UsageAware {
220221
}
221222
args.addAll(mapped)
222223
// execute plugin command
223-
final ret = plugin.exec(getLauncher(), target, cmd, args)
224+
final ret = plugin.exec(target, cmd, args)
224225
// use explicit exit to invoke the system shutdown hooks
225226
System.exit(ret)
226227
}

plugins/nf-tower/src/main/io/seqera/tower/plugin/CacheCommand.groovy

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package io.seqera.tower.plugin
1919
import groovy.transform.CompileStatic
2020
import groovy.util.logging.Slf4j
2121
import nextflow.SysEnv
22-
import nextflow.cli.PluginAbstractExec
22+
import nextflow.plugin.cli.PluginAbstractExec
2323
/**
2424
* Implements nextflow cache and restore commands
2525
*
@@ -59,10 +59,11 @@ class CacheCommand implements PluginAbstractExec {
5959
}
6060

6161
protected void cacheRestore() {
62-
if( !getSession().cloudCachePath ) {
62+
final env = SysEnv.get()
63+
if( !env.get('NXF_CLOUDCACHE_PATH') ) {
6364
log.debug "Running Nextflow cache restore"
6465
// legacy cache manager
65-
new CacheManager(System.getenv()).restoreCacheFiles()
66+
new CacheManager(env).restoreCacheFiles()
6667
}
6768
else {
6869
// this command is only kept for backward compatibility

plugins/nf-tower/src/main/io/seqera/tower/plugin/TowerPlugin.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import groovy.util.logging.Slf4j
2121
import io.seqera.tower.plugin.fs.SeqeraFileSystemProvider
2222
import nextflow.file.FileHelper
2323
import nextflow.plugin.BasePlugin
24-
import nextflow.cli.PluginExecAware
24+
import nextflow.plugin.cli.PluginExecAware
2525
import org.pf4j.PluginWrapper
2626
/**
2727
* Seqera Platform plugin

plugins/nf-wave/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ configurations {
4949
}
5050

5151
dependencies {
52-
compileOnly project(':nf-cli-v1')
52+
compileOnly project(':nextflow')
5353
compileOnly 'org.slf4j:slf4j-api:2.0.17'
5454
compileOnly 'org.pf4j:pf4j:3.14.1'
5555
compileOnly 'io.seqera:lib-trace:0.1.0'

plugins/nf-wave/src/main/io/seqera/wave/plugin/WavePlugin.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
package io.seqera.wave.plugin
1818

1919
import io.seqera.wave.plugin.cli.WaveCmdEntry
20-
import nextflow.cli.PluginExecAware
2120
import nextflow.plugin.BasePlugin
21+
import nextflow.plugin.cli.PluginExecAware
2222
import org.pf4j.PluginWrapper
2323
/**
2424
* Wave plugin entrypoint

plugins/nf-wave/src/main/io/seqera/wave/plugin/cli/WaveCmdEntry.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import groovy.util.logging.Slf4j
2525
import io.seqera.wave.plugin.ContainerConfig
2626
import io.seqera.wave.plugin.packer.Packer
2727
import io.seqera.wave.plugin.util.BasicCliOpts
28-
import nextflow.cli.PluginAbstractExec
2928
import nextflow.exception.AbortOperationException
3029
import nextflow.io.BucketParser
30+
import nextflow.plugin.cli.PluginAbstractExec
3131
/**
3232
* Implements Wave CLI tool
3333
*

0 commit comments

Comments
 (0)