diff --git a/modules/nextflow/src/main/groovy/nextflow/cli/CmdPlugin.groovy b/modules/nextflow/src/main/groovy/nextflow/cli/CmdPlugin.groovy index c0751e6aba..f884ce71cb 100644 --- a/modules/nextflow/src/main/groovy/nextflow/cli/CmdPlugin.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/cli/CmdPlugin.groovy @@ -37,6 +37,7 @@ import org.eclipse.jgit.api.Git @CompileStatic @Parameters(commandDescription = "Execute plugin-specific commands") class CmdPlugin extends CmdBase { + private static String DEFAULT_TEMPLATE_TAG='v0.2.1' @Override String getName() { @@ -64,7 +65,7 @@ class CmdPlugin extends CmdBase { Plugins.pull(args[1].tokenize(',')) } else if( args[0] == 'create' ) { - createPlugin(args) + createPlugin(args, params.get('tag', DEFAULT_TEMPLATE_TAG)) } // plugin run command else if( args[0].contains(CMD_SEP) ) { @@ -98,7 +99,7 @@ class CmdPlugin extends CmdBase { } } - static createPlugin(List args) { + static createPlugin(List args, String tag) { if( args != ['create'] && (args[0] != 'create' || !(args.size() in [3, 4])) ) throw new AbortOperationException("Invalid create parameters - usage: nextflow plugin create ") @@ -132,7 +133,7 @@ class CmdPlugin extends CmdBase { final File targetDir = refactor.getPluginDir() // clone the template repo - clonePluginTemplate(targetDir) + clonePluginTemplate(targetDir, tag) // now refactor the template code refactor.apply() // remove git plat @@ -148,14 +149,14 @@ class CmdPlugin extends CmdBase { : new BufferedReader(new InputStreamReader(System.in)).readLine() } - static private void clonePluginTemplate(File targetDir) { + static private void clonePluginTemplate(File targetDir, String tag) { final templateUri = "https://github.com/nextflow-io/nf-plugin-template.git" try { Git.cloneRepository() .setURI(templateUri) .setDirectory(targetDir) - .setBranchesToClone(["refs/tags/v0.2.0"]) - .setBranch("refs/tags/v0.2.0") + .setBranchesToClone(["refs/tags/$tag".toString()]) + .setBranch("refs/tags/$tag") .call() } catch (Exception e) { diff --git a/modules/nextflow/src/test/groovy/nextflow/cli/CmdPluginCreateTest.groovy b/modules/nextflow/src/test/groovy/nextflow/cli/CmdPluginCreateTest.groovy index 23e506c653..0eb6112966 100644 --- a/modules/nextflow/src/test/groovy/nextflow/cli/CmdPluginCreateTest.groovy +++ b/modules/nextflow/src/test/groovy/nextflow/cli/CmdPluginCreateTest.groovy @@ -69,4 +69,29 @@ class CmdPluginCreateTest extends Specification { folder?.deleteDir() } + def 'should clone and create a plugin project for v0.2.0 tag' () { + given: + def folder = Files.createTempDirectory('test') + and: + def args = [ + 'create', + 'hello world plugin', + 'foo', + folder.toAbsolutePath().toString() + '/hello'] + def params = [tag: 'v0.2.0'] + + when: + def cmd = new CmdPlugin(args: args, params: params) + and: + cmd.run() + + then: + //Checks that clone is done from v0.2.0 by checking that gradle plugin version and url is the same as in the tag + Path.of(folder.resolve('hello/build.gradle').toUri()).text.contains("id 'io.nextflow.nextflow-plugin' version '0.0.1-alpha4'") + Path.of(folder.resolve('hello/build.gradle').toUri()).text.contains("url = 'https://nf-plugins-registry.dev-tower.net/api'") + + cleanup: + folder?.deleteDir() + } + }