Skip to content

Commit c1a6b60

Browse files
authored
Merge pull request #12 from rundeck/new-features
New Features
2 parents 443a7b5 + e6295f6 commit c1a6b60

28 files changed

Lines changed: 606 additions & 62 deletions

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Existing service plugins enabled on boostrap-plugin
5656
* LogFilter
5757
* NodeExecutor
5858
* Orchestrator
59+
* Option
5960

6061
#### for Script Plugins:
6162
* ResourceModelSource
@@ -64,6 +65,7 @@ Existing service plugins enabled on boostrap-plugin
6465
* NodeExecutor
6566
* FileCopier
6667
* NodeExecutorFileCopier: Generate both, Node Executor and File Copier service
68+
* Option
6769

6870
#### for UI plugins
6971
* UI

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ dependencies {
2323
compile 'com.github.rundeck.cli-toolbelt:toolbelt:0.2.2'
2424
compile 'com.github.rundeck.cli-toolbelt:toolbelt-jewelcli:0.2.2'
2525
compile 'org.apache.commons:commons-text:1.4'
26+
compile 'info.picocli:picocli:4.0.0-alpha-2'
27+
2628

2729
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
2830
}
Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package com.rundeck.plugin
22

3-
import com.lexicalscope.jewel.cli.Option
43
import com.rundeck.plugin.template.FilesystemArtifactTemplateGenerator
54
import com.rundeck.plugin.template.PluginType
6-
import org.rundeck.toolbelt.Command
7-
import org.rundeck.toolbelt.CommandRunFailure
8-
import org.rundeck.toolbelt.SubCommand
9-
import org.rundeck.toolbelt.ToolBelt
10-
import org.rundeck.toolbelt.input.jewelcli.JewelInput
5+
import com.rundeck.plugin.template.ServiceType
6+
import picocli.CommandLine
7+
import picocli.CommandLine.Option
8+
import picocli.CommandLine.Command
9+
10+
11+
import java.util.concurrent.Callable
1112

1213
/*
1314
* Copyright 2018 Rundeck, Inc. (http://rundeck.com)
@@ -25,36 +26,36 @@ import org.rundeck.toolbelt.input.jewelcli.JewelInput
2526
* limitations under the License.
2627
*/
2728

28-
@SubCommand
29-
class Generator {
29+
@Command(description = "Create a Rundeck plugin artifact.",
30+
name = "plugin-bootstrap", mixinStandardHelpOptions = true, version = "1.1")
31+
class Generator implements Callable<Void>{
3032

31-
private static final List<String> VALID_PLUGIN_TYPES = ["java","script","ui"]
32-
33-
public static void main(String[] args) throws IOException, CommandRunFailure {
34-
ToolBelt.with("plugin-bootstrap", new JewelInput(), new Generator()).runMain(args, true);
33+
static void main(String[] args) throws Exception {
34+
try{
35+
CommandLine.call(new Generator(), args)
36+
}catch(Exception e){
37+
println(e.getMessage())
38+
}
3539
}
3640

37-
@Command(description = "Create a Rundeck plugin artifact")
38-
public void create(CreateOpts createOpts) {
39-
if(!VALID_PLUGIN_TYPES.contains(createOpts.pluginType)) {
40-
println "Artifact type must be one of: ${VALID_PLUGIN_TYPES.join("|")}"
41-
return
42-
}
41+
@Option(names = [ "-n", "--pluginName" ], description = "Plugin Name." , required = true)
42+
String pluginName;
43+
@Option(names = [ "-t", "--pluginType" ] ,description = 'Plugin Type: ${COMPLETION-CANDIDATES}' , required = true)
44+
PluginType pluginType;
45+
@Option(names = [ "-s", "--serviceType" ],description = 'Rundeck Service Type: ${COMPLETION-CANDIDATES}', required = true)
46+
ServiceType serviceType
47+
@Option(names = [ "-d", "--destinationDirectory" ],description = "The directory in which the artifact directory will be generated", required = true)
48+
String destinationDirectory
49+
50+
@Override
51+
Void call() throws Exception {
4352
FilesystemArtifactTemplateGenerator generator = new FilesystemArtifactTemplateGenerator()
44-
println generator.generate(createOpts.pluginName,
45-
PluginType.valueOf(createOpts.pluginType),
46-
createOpts.serviceType,
47-
createOpts.destinationDirectory)
48-
}
4953

50-
interface CreateOpts {
51-
@Option(shortName = "n",description = "Plugin Name")
52-
String getPluginName()
53-
@Option(shortName = "t",description = "Plugin Type")
54-
String getPluginType()
55-
@Option(shortName = "s",description = "Rundeck Service Type")
56-
String getServiceType()
57-
@Option(shortName = "d",description = "The directory in which the artifact directory will be generated")
58-
String getDestinationDirectory()
54+
println generator.generate(this.pluginName,
55+
this.pluginType,
56+
this.serviceType.toString(),
57+
this.destinationDirectory)
58+
59+
return null
5960
}
6061
}

src/main/groovy/com/rundeck/plugin/generator/JavaPluginTemplateGenerator.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class JavaPluginTemplateGenerator extends AbstractTemplateGenerator {
2424
private static final String TEMPLATE_BASE = "templates/java-plugin/"
2525
private static final String JAVA_STRUCTURE = "java-plugin.structure"
2626

27-
private static final List ALLOWED_TEMPLATES = ["ResourceModelSource","Notification","WorkflowStep","WorkflowNodeStep","LogFilter","NodeExecutor","Orchestrator"]
27+
private static final List ALLOWED_TEMPLATES = ["ResourceModelSource","Notification","WorkflowStep","WorkflowNodeStep","LogFilter","NodeExecutor","Orchestrator","Option"]
2828

2929
@Override
3030
Map makeTemplateProperties(final String pluginName, final String providedService) {
@@ -51,7 +51,7 @@ class JavaPluginTemplateGenerator extends AbstractTemplateGenerator {
5151

5252
@Override
5353
void preTemplateValidations(String providedService) {
54-
if(!ALLOWED_TEMPLATES.contains(providedService))throw new Exception("Only "+ALLOWED_TEMPLATES.toString()+" plugins generation are supported at this time")
54+
if(!ALLOWED_TEMPLATES.contains(providedService))throw new Exception("Java plugin does not support this service : ${providedService}. Only "+ALLOWED_TEMPLATES.toString()+" are supported")
5555
}
5656

5757
@Override

src/main/groovy/com/rundeck/plugin/generator/ScriptPluginTemplateGenerator.groovy

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ScriptPluginTemplateGenerator extends AbstractTemplateGenerator {
2424
private static final String TEMPLATE_BASE = "templates/script-plugin/"
2525
private static final String SCRIPT_STRUCTURE = "script-plugin.structure"
2626

27-
private static final List<String> ALLOWED_SERVICE_TYPES = ["NodeExecutor","FileCopier","ResourceModelSource","WorkflowNodeStep","RemoteScriptNodeStep","NodeExecutorFileCopier"]
27+
private static final List<String> ALLOWED_SERVICE_TYPES = ["NodeExecutor","FileCopier","ResourceModelSource","WorkflowNodeStep","RemoteScriptNodeStep","NodeExecutorFileCopier","Option"]
2828

2929
@Override
3030
Map makeTemplateProperties(final String pluginName, final String providedService) {
@@ -51,7 +51,7 @@ class ScriptPluginTemplateGenerator extends AbstractTemplateGenerator {
5151
@Override
5252
void preTemplateValidations(String providedService) {
5353
if(!ALLOWED_SERVICE_TYPES.contains(providedService)) {
54-
throw new Exception("Script plugins do not support serivice: ${providedService}. Allowed types are: ${ALLOWED_SERVICE_TYPES.join(", ")}")
54+
throw new Exception("Script plugin does not support this service: ${providedService}. Allowed types are: ${ALLOWED_SERVICE_TYPES.join(", ")}")
5555
}
5656
}
5757

@@ -73,6 +73,9 @@ class ScriptPluginTemplateGenerator extends AbstractTemplateGenerator {
7373
case "NodeExecutorFileCopier":
7474
path="nodeexecutor-filecopier"
7575
break
76+
default:
77+
path=providedService.toLowerCase()
78+
break
7679

7780
}
7881

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.rundeck.plugin.template
2+
3+
enum ServiceType {
4+
ResourceModelSource,
5+
Notification,
6+
WorkflowStep,
7+
WorkflowNodeStep,
8+
LogFilter,
9+
NodeExecutor,
10+
Orchestrator,
11+
FileCopier,
12+
RemoteScriptNodeStep,
13+
NodeExecutorFileCopier,
14+
Option,
15+
UI
16+
}

src/main/resources/templates/java-plugin/logfilter/build.gradle.template

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
plugins {
2+
id 'groovy'
3+
id 'java'
4+
}
5+
16
version = '0.1.0'
27
defaultTasks 'clean','build'
38
apply plugin: 'java'
@@ -6,31 +11,59 @@ apply plugin: 'idea'
611
sourceCompatibility = 1.8
712
ext.rundeckPluginVersion= '2.0'
813
ext.rundeckVersion= '${rundeckVersion}'
14+
ext.pluginClassNames='com.plugin.${sanitizedPluginName}.${javaPluginClass}'
915

1016

1117
repositories {
1218
mavenLocal()
1319
mavenCentral()
1420
}
1521

22+
configurations{
23+
//declare custom pluginLibs configuration to include only libs for this plugin
24+
pluginLibs
25+
26+
//declare compile to extend from pluginLibs so it inherits the dependencies
27+
compile{
28+
extendsFrom pluginLibs
29+
}
30+
}
31+
1632
dependencies {
17-
compile 'org.rundeck:rundeck-core:3.0.1+'
33+
compile 'org.rundeck:rundeck-core:3.0.14+'
34+
35+
//use pluginLibs to add dependecies, example:
36+
//pluginLibs group: 'com.google.code.gson', name: 'gson', version: '2.8.2'
1837

1938
testCompile 'junit:junit:4.12'
2039
testCompile "org.codehaus.groovy:groovy-all:2.4.15"
2140
testCompile "org.spockframework:spock-core:1.0-groovy-2.4"
2241
}
2342

24-
ext.pluginClassNames='com.plugin.${sanitizedPluginName}.${javaPluginClass}'
43+
// task to copy plugin libs to output/lib dir
44+
task copyToLib(type: Copy) {
45+
into "\$buildDir/output/lib"
46+
from configurations.pluginLibs
47+
}
48+
2549
jar {
50+
from "\$buildDir/output"
2651
manifest {
52+
def libList = configurations.pluginLibs.collect{'lib/'+it.name}.join(' ')
53+
2754
attributes 'Rundeck-Plugin-Classnames': pluginClassNames
2855
attributes 'Rundeck-Plugin-File-Version': version
2956
attributes 'Rundeck-Plugin-Name': '${pluginName}'
3057
attributes 'Rundeck-Plugin-Description': 'Provide a short description of your plugin here.'
3158
attributes 'Rundeck-Plugin-Rundeck-Compatibility-Version': '3.x'
32-
attributes 'Rundeck-Plugin-Tags': 'java,notification'
33-
attributes 'Rundeck-Plugin-Version': rundeckPluginVersion, 'Rundeck-Plugin-Archive': 'true'
59+
attributes 'Rundeck-Plugin-Tags': 'java,logfilter'
60+
attributes 'Rundeck-Plugin-License': 'Apache 2.0'
61+
attributes 'Rundeck-Plugin-Source-Link': 'Please put the link to your source repo here'
62+
attributes 'Rundeck-Plugin-Target-Host-Compatibility': 'all'
63+
attributes 'Rundeck-Plugin-Version': rundeckPluginVersion
64+
attributes 'Rundeck-Plugin-Archive': 'true'
65+
attributes 'Rundeck-Plugin-Libs': "\${libList}"
66+
3467
}
3568
}
3669

src/main/resources/templates/java-plugin/nodeexecutor/build.gradle.template

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
plugins {
2+
id 'groovy'
3+
id 'java'
4+
}
5+
16
version = '0.1.0'
27
defaultTasks 'clean','build'
38
apply plugin: 'java'
@@ -6,15 +11,29 @@ apply plugin: 'idea'
611
sourceCompatibility = 1.8
712
ext.rundeckPluginVersion= '2.0'
813
ext.rundeckVersion= '${rundeckVersion}'
14+
ext.pluginClassNames='com.plugin.${sanitizedPluginName}.${javaPluginClass}'
915

1016

1117
repositories {
1218
mavenLocal()
1319
mavenCentral()
1420
}
1521

22+
configurations{
23+
//declare custom pluginLibs configuration to include only libs for this plugin
24+
pluginLibs
25+
26+
//declare compile to extend from pluginLibs so it inherits the dependencies
27+
compile{
28+
extendsFrom pluginLibs
29+
}
30+
}
31+
1632
dependencies {
17-
compile 'org.rundeck:rundeck-core:3.0.1+'
33+
compile 'org.rundeck:rundeck-core:3.0.14+'
34+
35+
//use pluginLibs to add dependecies, example:
36+
//pluginLibs group: 'com.google.code.gson', name: 'gson', version: '2.8.2'
1837

1938
testCompile 'junit:junit:4.12'
2039
testCompile "org.codehaus.groovy:groovy-all:2.4.15"
@@ -23,16 +42,30 @@ dependencies {
2342
testCompile group: 'org.objenesis', name: 'objenesis', version: '1.2'
2443
}
2544

26-
ext.pluginClassNames='com.plugin.${sanitizedPluginName}.${javaPluginClass}'
45+
// task to copy plugin libs to output/lib dir
46+
task copyToLib(type: Copy) {
47+
into "\$buildDir/output/lib"
48+
from configurations.pluginLibs
49+
}
50+
2751
jar {
52+
from "\$buildDir/output"
2853
manifest {
54+
def libList = configurations.pluginLibs.collect{'lib/'+it.name}.join(' ')
55+
2956
attributes 'Rundeck-Plugin-Classnames': pluginClassNames
3057
attributes 'Rundeck-Plugin-File-Version': version
3158
attributes 'Rundeck-Plugin-Name': '${pluginName}'
3259
attributes 'Rundeck-Plugin-Description': 'Provide a short description of your plugin here.'
3360
attributes 'Rundeck-Plugin-Rundeck-Compatibility-Version': '3.x'
34-
attributes 'Rundeck-Plugin-Tags': 'java,notification'
35-
attributes 'Rundeck-Plugin-Version': rundeckPluginVersion, 'Rundeck-Plugin-Archive': 'true'
61+
attributes 'Rundeck-Plugin-Tags': 'java,executor'
62+
attributes 'Rundeck-Plugin-License': 'Apache 2.0'
63+
attributes 'Rundeck-Plugin-Source-Link': 'Please put the link to your source repo here'
64+
attributes 'Rundeck-Plugin-Target-Host-Compatibility': 'all'
65+
attributes 'Rundeck-Plugin-Version': rundeckPluginVersion
66+
attributes 'Rundeck-Plugin-Archive': 'true'
67+
attributes 'Rundeck-Plugin-Libs': "\${libList}"
68+
3669
}
3770
}
3871

src/main/resources/templates/java-plugin/notification/build.gradle.template

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
plugins {
2+
id 'groovy'
3+
id 'java'
4+
}
5+
16
version = '0.1.0'
27
defaultTasks 'clean','build'
38
apply plugin: 'java'
@@ -6,31 +11,53 @@ apply plugin: 'idea'
611
sourceCompatibility = 1.8
712
ext.rundeckPluginVersion= '2.0'
813
ext.rundeckVersion= '${rundeckVersion}'
14+
ext.pluginClassNames='com.plugin.${sanitizedPluginName}.${javaPluginClass}'
915

1016

1117
repositories {
1218
mavenLocal()
1319
mavenCentral()
1420
}
1521

22+
configurations{
23+
//declare custom pluginLibs configuration to include only libs for this plugin
24+
pluginLibs
25+
26+
//declare compile to extend from pluginLibs so it inherits the dependencies
27+
compile{
28+
extendsFrom pluginLibs
29+
}
30+
}
31+
1632
dependencies {
17-
compile 'org.rundeck:rundeck-core:3.0.1+'
33+
compile 'org.rundeck:rundeck-core:3.0.14+'
34+
35+
//use pluginLibs to add dependecies, example:
36+
//pluginLibs group: 'com.google.code.gson', name: 'gson', version: '2.8.2'
1837

1938
testCompile 'junit:junit:4.12'
2039
testCompile "org.codehaus.groovy:groovy-all:2.4.15"
2140
testCompile "org.spockframework:spock-core:1.0-groovy-2.4"
2241
}
2342

24-
ext.pluginClassNames='com.plugin.${sanitizedPluginName}.${javaPluginClass}'
2543
jar {
44+
from "\$buildDir/output"
2645
manifest {
46+
def libList = configurations.pluginLibs.collect{'lib/'+it.name}.join(' ')
47+
2748
attributes 'Rundeck-Plugin-Classnames': pluginClassNames
2849
attributes 'Rundeck-Plugin-File-Version': version
2950
attributes 'Rundeck-Plugin-Name': '${pluginName}'
3051
attributes 'Rundeck-Plugin-Description': 'Provide a short description of your plugin here.'
3152
attributes 'Rundeck-Plugin-Rundeck-Compatibility-Version': '3.x'
3253
attributes 'Rundeck-Plugin-Tags': 'java,notification'
33-
attributes 'Rundeck-Plugin-Version': rundeckPluginVersion, 'Rundeck-Plugin-Archive': 'true'
54+
attributes 'Rundeck-Plugin-License': 'Apache 2.0'
55+
attributes 'Rundeck-Plugin-Source-Link': 'Please put the link to your source repo here'
56+
attributes 'Rundeck-Plugin-Target-Host-Compatibility': 'all'
57+
attributes 'Rundeck-Plugin-Version': rundeckPluginVersion
58+
attributes 'Rundeck-Plugin-Archive': 'true'
59+
attributes 'Rundeck-Plugin-Libs': "\${libList}"
60+
3461
}
3562
}
3663

0 commit comments

Comments
 (0)