Skip to content

Commit a8e9403

Browse files
committed
added gradle checks for modules configuration, and ability to add
modules to integ test cluster
1 parent 763747d commit a8e9403

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import org.elasticsearch.gradle.test.RestIntegTestTask
2323
import org.elasticsearch.gradle.test.RunTask
2424
import org.gradle.api.Project
2525
import org.gradle.api.Task
26+
import org.gradle.api.file.FileCollection
2627
import org.gradle.api.tasks.bundling.Zip
2728

2829
/**
@@ -40,10 +41,16 @@ class PluginBuildPlugin extends BuildPlugin {
4041
String name = project.pluginProperties.extension.name
4142
project.jar.baseName = name
4243
project.bundlePlugin.baseName = name
44+
4345
project.integTest.dependsOn(project.bundlePlugin)
44-
project.integTest.clusterConfig.plugin(name, project.bundlePlugin.outputs.files)
4546
project.tasks.run.dependsOn(project.bundlePlugin)
46-
project.tasks.run.clusterConfig.plugin(name, project.bundlePlugin.outputs.files)
47+
if (project.path.startsWith(':modules:')) {
48+
project.integTest.clusterConfig.module(project)
49+
project.tasks.run.clusterConfig.module(project)
50+
} else {
51+
project.integTest.clusterConfig.plugin(name, project.bundlePlugin.outputs.files)
52+
project.tasks.run.clusterConfig.plugin(name, project.bundlePlugin.outputs.files)
53+
}
4754
}
4855
RestIntegTestTask.configure(project)
4956
RunTask.configure(project)

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterConfiguration.groovy

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class ClusterConfiguration {
7171

7272
LinkedHashMap<String, Object> plugins = new LinkedHashMap<>()
7373

74+
List<Project> modules = new ArrayList<>()
75+
7476
LinkedHashMap<String, Object[]> setupCommands = new LinkedHashMap<>()
7577

7678
@Input
@@ -93,6 +95,12 @@ class ClusterConfiguration {
9395
plugins.put(name, pluginProject)
9496
}
9597

98+
/** Add a module to the cluster. The project must be an esplugin and have a single zip default artifact. */
99+
@Input
100+
void module(Project moduleProject) {
101+
modules.add(moduleProject)
102+
}
103+
96104
@Input
97105
void setupCommand(String name, Object... args) {
98106
setupCommands.put(name, args)

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ class ClusterFormationTasks {
108108
setup = configureExtraConfigFilesTask(taskName(task, node, 'extraConfig'), project, setup, node)
109109
setup = configureCopyPluginsTask(taskName(task, node, 'copyPlugins'), project, setup, node)
110110

111+
// install modules
112+
for (Project module : node.config.modules) {
113+
String actionName = pluginTaskName('install', module.name, 'Module')
114+
setup = configureInstallModuleTask(taskName(task, node, actionName), project, setup, node, module)
115+
}
116+
111117
// install plugins
112118
for (Map.Entry<String, Object> plugin : node.config.plugins.entrySet()) {
113119
String actionName = pluginTaskName('install', plugin.getKey(), 'Plugin')
@@ -292,6 +298,20 @@ class ClusterFormationTasks {
292298
return copyPlugins
293299
}
294300

301+
static Task configureInstallModuleTask(String name, Project project, Task setup, NodeInfo node, Project module) {
302+
if (node.config.distribution != 'integ-test-zip') {
303+
throw new GradleException("Module ${module.path} cannot be installed in cluster which is not using integ-test-zip")
304+
}
305+
if (module.plugins.hasPlugin(PluginBuildPlugin) == false) {
306+
throw new GradleException("Task ${name} cannot include module ${module.path} which is not an esplugin")
307+
}
308+
Copy installModule = project.tasks.create(name, Copy.class)
309+
installModule.dependsOn(setup)
310+
installModule.into(new File(node.homeDir, "modules/${module.name}"))
311+
installModule.from({ project.zipTree(module.tasks.bundlePlugin.outputs.files.singleFile) })
312+
return installModule
313+
}
314+
295315
static Task configureInstallPluginTask(String name, Project project, Task setup, NodeInfo node, Object plugin) {
296316
FileCollection pluginZip
297317
if (plugin instanceof Project) {

modules/build.gradle

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,23 @@ subprojects {
2424
// for local ES plugins, the name of the plugin is the same as the directory
2525
name project.name
2626
}
27+
28+
if (project.file('src/main/packaging').exists()) {
29+
throw new InvalidModelException("Modules cannot contain packaging files")
30+
}
31+
if (project.file('src/main/bin').exists()) {
32+
throw new InvalidModelException("Modules cannot contain bin files")
33+
}
34+
if (project.file('src/main/config').exists()) {
35+
throw new InvalidModelException("Modules cannot contain config files")
36+
}
37+
38+
project.afterEvaluate {
39+
if (esplugin.isolated == false) {
40+
throw new InvalidModelException("Modules cannot disable isolation")
41+
}
42+
if (esplugin.jvm == false) {
43+
throw new InvalidModelException("Modules must be jvm plugins")
44+
}
45+
}
2746
}

0 commit comments

Comments
 (0)