Skip to content

Commit

Permalink
Merge pull request #12 from rundeck/new-features
Browse files Browse the repository at this point in the history
New Features
  • Loading branch information
sjrd218 authored Apr 25, 2019
2 parents 443a7b5 + e6295f6 commit c1a6b60
Show file tree
Hide file tree
Showing 28 changed files with 606 additions and 62 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Existing service plugins enabled on boostrap-plugin
* LogFilter
* NodeExecutor
* Orchestrator
* Option

#### for Script Plugins:
* ResourceModelSource
Expand All @@ -64,6 +65,7 @@ Existing service plugins enabled on boostrap-plugin
* NodeExecutor
* FileCopier
* NodeExecutorFileCopier: Generate both, Node Executor and File Copier service
* Option

#### for UI plugins
* UI
Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ dependencies {
compile 'com.github.rundeck.cli-toolbelt:toolbelt:0.2.2'
compile 'com.github.rundeck.cli-toolbelt:toolbelt-jewelcli:0.2.2'
compile 'org.apache.commons:commons-text:1.4'
compile 'info.picocli:picocli:4.0.0-alpha-2'


testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
}
Expand Down
65 changes: 33 additions & 32 deletions src/main/groovy/com/rundeck/plugin/Generator.groovy
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.rundeck.plugin

import com.lexicalscope.jewel.cli.Option
import com.rundeck.plugin.template.FilesystemArtifactTemplateGenerator
import com.rundeck.plugin.template.PluginType
import org.rundeck.toolbelt.Command
import org.rundeck.toolbelt.CommandRunFailure
import org.rundeck.toolbelt.SubCommand
import org.rundeck.toolbelt.ToolBelt
import org.rundeck.toolbelt.input.jewelcli.JewelInput
import com.rundeck.plugin.template.ServiceType
import picocli.CommandLine
import picocli.CommandLine.Option
import picocli.CommandLine.Command


import java.util.concurrent.Callable

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

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

private static final List<String> VALID_PLUGIN_TYPES = ["java","script","ui"]

public static void main(String[] args) throws IOException, CommandRunFailure {
ToolBelt.with("plugin-bootstrap", new JewelInput(), new Generator()).runMain(args, true);
static void main(String[] args) throws Exception {
try{
CommandLine.call(new Generator(), args)
}catch(Exception e){
println(e.getMessage())
}
}

@Command(description = "Create a Rundeck plugin artifact")
public void create(CreateOpts createOpts) {
if(!VALID_PLUGIN_TYPES.contains(createOpts.pluginType)) {
println "Artifact type must be one of: ${VALID_PLUGIN_TYPES.join("|")}"
return
}
@Option(names = [ "-n", "--pluginName" ], description = "Plugin Name." , required = true)
String pluginName;
@Option(names = [ "-t", "--pluginType" ] ,description = 'Plugin Type: ${COMPLETION-CANDIDATES}' , required = true)
PluginType pluginType;
@Option(names = [ "-s", "--serviceType" ],description = 'Rundeck Service Type: ${COMPLETION-CANDIDATES}', required = true)
ServiceType serviceType
@Option(names = [ "-d", "--destinationDirectory" ],description = "The directory in which the artifact directory will be generated", required = true)
String destinationDirectory

@Override
Void call() throws Exception {
FilesystemArtifactTemplateGenerator generator = new FilesystemArtifactTemplateGenerator()
println generator.generate(createOpts.pluginName,
PluginType.valueOf(createOpts.pluginType),
createOpts.serviceType,
createOpts.destinationDirectory)
}

interface CreateOpts {
@Option(shortName = "n",description = "Plugin Name")
String getPluginName()
@Option(shortName = "t",description = "Plugin Type")
String getPluginType()
@Option(shortName = "s",description = "Rundeck Service Type")
String getServiceType()
@Option(shortName = "d",description = "The directory in which the artifact directory will be generated")
String getDestinationDirectory()
println generator.generate(this.pluginName,
this.pluginType,
this.serviceType.toString(),
this.destinationDirectory)

return null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class JavaPluginTemplateGenerator extends AbstractTemplateGenerator {
private static final String TEMPLATE_BASE = "templates/java-plugin/"
private static final String JAVA_STRUCTURE = "java-plugin.structure"

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

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

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ScriptPluginTemplateGenerator extends AbstractTemplateGenerator {
private static final String TEMPLATE_BASE = "templates/script-plugin/"
private static final String SCRIPT_STRUCTURE = "script-plugin.structure"

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

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

Expand All @@ -73,6 +73,9 @@ class ScriptPluginTemplateGenerator extends AbstractTemplateGenerator {
case "NodeExecutorFileCopier":
path="nodeexecutor-filecopier"
break
default:
path=providedService.toLowerCase()
break

}

Expand Down
16 changes: 16 additions & 0 deletions src/main/groovy/com/rundeck/plugin/template/ServiceType.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.rundeck.plugin.template

enum ServiceType {
ResourceModelSource,
Notification,
WorkflowStep,
WorkflowNodeStep,
LogFilter,
NodeExecutor,
Orchestrator,
FileCopier,
RemoteScriptNodeStep,
NodeExecutorFileCopier,
Option,
UI
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
plugins {
id 'groovy'
id 'java'
}

version = '0.1.0'
defaultTasks 'clean','build'
apply plugin: 'java'
Expand All @@ -6,31 +11,59 @@ apply plugin: 'idea'
sourceCompatibility = 1.8
ext.rundeckPluginVersion= '2.0'
ext.rundeckVersion= '${rundeckVersion}'
ext.pluginClassNames='com.plugin.${sanitizedPluginName}.${javaPluginClass}'


repositories {
mavenLocal()
mavenCentral()
}

configurations{
//declare custom pluginLibs configuration to include only libs for this plugin
pluginLibs

//declare compile to extend from pluginLibs so it inherits the dependencies
compile{
extendsFrom pluginLibs
}
}

dependencies {
compile 'org.rundeck:rundeck-core:3.0.1+'
compile 'org.rundeck:rundeck-core:3.0.14+'

//use pluginLibs to add dependecies, example:
//pluginLibs group: 'com.google.code.gson', name: 'gson', version: '2.8.2'

testCompile 'junit:junit:4.12'
testCompile "org.codehaus.groovy:groovy-all:2.4.15"
testCompile "org.spockframework:spock-core:1.0-groovy-2.4"
}

ext.pluginClassNames='com.plugin.${sanitizedPluginName}.${javaPluginClass}'
// task to copy plugin libs to output/lib dir
task copyToLib(type: Copy) {
into "\$buildDir/output/lib"
from configurations.pluginLibs
}

jar {
from "\$buildDir/output"
manifest {
def libList = configurations.pluginLibs.collect{'lib/'+it.name}.join(' ')

attributes 'Rundeck-Plugin-Classnames': pluginClassNames
attributes 'Rundeck-Plugin-File-Version': version
attributes 'Rundeck-Plugin-Name': '${pluginName}'
attributes 'Rundeck-Plugin-Description': 'Provide a short description of your plugin here.'
attributes 'Rundeck-Plugin-Rundeck-Compatibility-Version': '3.x'
attributes 'Rundeck-Plugin-Tags': 'java,notification'
attributes 'Rundeck-Plugin-Version': rundeckPluginVersion, 'Rundeck-Plugin-Archive': 'true'
attributes 'Rundeck-Plugin-Tags': 'java,logfilter'
attributes 'Rundeck-Plugin-License': 'Apache 2.0'
attributes 'Rundeck-Plugin-Source-Link': 'Please put the link to your source repo here'
attributes 'Rundeck-Plugin-Target-Host-Compatibility': 'all'
attributes 'Rundeck-Plugin-Version': rundeckPluginVersion
attributes 'Rundeck-Plugin-Archive': 'true'
attributes 'Rundeck-Plugin-Libs': "\${libList}"

}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
plugins {
id 'groovy'
id 'java'
}

version = '0.1.0'
defaultTasks 'clean','build'
apply plugin: 'java'
Expand All @@ -6,15 +11,29 @@ apply plugin: 'idea'
sourceCompatibility = 1.8
ext.rundeckPluginVersion= '2.0'
ext.rundeckVersion= '${rundeckVersion}'
ext.pluginClassNames='com.plugin.${sanitizedPluginName}.${javaPluginClass}'


repositories {
mavenLocal()
mavenCentral()
}

configurations{
//declare custom pluginLibs configuration to include only libs for this plugin
pluginLibs

//declare compile to extend from pluginLibs so it inherits the dependencies
compile{
extendsFrom pluginLibs
}
}

dependencies {
compile 'org.rundeck:rundeck-core:3.0.1+'
compile 'org.rundeck:rundeck-core:3.0.14+'

//use pluginLibs to add dependecies, example:
//pluginLibs group: 'com.google.code.gson', name: 'gson', version: '2.8.2'

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

ext.pluginClassNames='com.plugin.${sanitizedPluginName}.${javaPluginClass}'
// task to copy plugin libs to output/lib dir
task copyToLib(type: Copy) {
into "\$buildDir/output/lib"
from configurations.pluginLibs
}

jar {
from "\$buildDir/output"
manifest {
def libList = configurations.pluginLibs.collect{'lib/'+it.name}.join(' ')

attributes 'Rundeck-Plugin-Classnames': pluginClassNames
attributes 'Rundeck-Plugin-File-Version': version
attributes 'Rundeck-Plugin-Name': '${pluginName}'
attributes 'Rundeck-Plugin-Description': 'Provide a short description of your plugin here.'
attributes 'Rundeck-Plugin-Rundeck-Compatibility-Version': '3.x'
attributes 'Rundeck-Plugin-Tags': 'java,notification'
attributes 'Rundeck-Plugin-Version': rundeckPluginVersion, 'Rundeck-Plugin-Archive': 'true'
attributes 'Rundeck-Plugin-Tags': 'java,executor'
attributes 'Rundeck-Plugin-License': 'Apache 2.0'
attributes 'Rundeck-Plugin-Source-Link': 'Please put the link to your source repo here'
attributes 'Rundeck-Plugin-Target-Host-Compatibility': 'all'
attributes 'Rundeck-Plugin-Version': rundeckPluginVersion
attributes 'Rundeck-Plugin-Archive': 'true'
attributes 'Rundeck-Plugin-Libs': "\${libList}"

}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
plugins {
id 'groovy'
id 'java'
}

version = '0.1.0'
defaultTasks 'clean','build'
apply plugin: 'java'
Expand All @@ -6,31 +11,53 @@ apply plugin: 'idea'
sourceCompatibility = 1.8
ext.rundeckPluginVersion= '2.0'
ext.rundeckVersion= '${rundeckVersion}'
ext.pluginClassNames='com.plugin.${sanitizedPluginName}.${javaPluginClass}'


repositories {
mavenLocal()
mavenCentral()
}

configurations{
//declare custom pluginLibs configuration to include only libs for this plugin
pluginLibs

//declare compile to extend from pluginLibs so it inherits the dependencies
compile{
extendsFrom pluginLibs
}
}

dependencies {
compile 'org.rundeck:rundeck-core:3.0.1+'
compile 'org.rundeck:rundeck-core:3.0.14+'

//use pluginLibs to add dependecies, example:
//pluginLibs group: 'com.google.code.gson', name: 'gson', version: '2.8.2'

testCompile 'junit:junit:4.12'
testCompile "org.codehaus.groovy:groovy-all:2.4.15"
testCompile "org.spockframework:spock-core:1.0-groovy-2.4"
}

ext.pluginClassNames='com.plugin.${sanitizedPluginName}.${javaPluginClass}'
jar {
from "\$buildDir/output"
manifest {
def libList = configurations.pluginLibs.collect{'lib/'+it.name}.join(' ')

attributes 'Rundeck-Plugin-Classnames': pluginClassNames
attributes 'Rundeck-Plugin-File-Version': version
attributes 'Rundeck-Plugin-Name': '${pluginName}'
attributes 'Rundeck-Plugin-Description': 'Provide a short description of your plugin here.'
attributes 'Rundeck-Plugin-Rundeck-Compatibility-Version': '3.x'
attributes 'Rundeck-Plugin-Tags': 'java,notification'
attributes 'Rundeck-Plugin-Version': rundeckPluginVersion, 'Rundeck-Plugin-Archive': 'true'
attributes 'Rundeck-Plugin-License': 'Apache 2.0'
attributes 'Rundeck-Plugin-Source-Link': 'Please put the link to your source repo here'
attributes 'Rundeck-Plugin-Target-Host-Compatibility': 'all'
attributes 'Rundeck-Plugin-Version': rundeckPluginVersion
attributes 'Rundeck-Plugin-Archive': 'true'
attributes 'Rundeck-Plugin-Libs': "\${libList}"

}
}

Expand Down
Loading

0 comments on commit c1a6b60

Please sign in to comment.