From 8f16ea0ddc4129ec6ea238a9d9197798c0d8c5ae Mon Sep 17 00:00:00 2001 From: Rafiullah Hamedy Date: Sat, 2 Mar 2019 15:41:12 -0500 Subject: [PATCH 01/13] Convert PluginPropertiesExtension & PluginPropertiesTask Groovy to Java --- .../plugin/PluginPropertiesExtension.groovy | 94 ---------- .../plugin/PluginPropertiesExtension.java | 173 ++++++++++++++++++ .../gradle/plugin/PluginPropertiesTask.java | 125 +++++++++++++ 3 files changed, 298 insertions(+), 94 deletions(-) delete mode 100644 buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.groovy create mode 100644 buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java create mode 100644 buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.groovy deleted file mode 100644 index c250d7695a832..0000000000000 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.groovy +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.gradle.plugin - -import org.gradle.api.Project -import org.gradle.api.tasks.Input -import org.gradle.api.tasks.InputFile - -/** - * A container for plugin properties that will be written to the plugin descriptor, for easy - * manipulation in the gradle DSL. - */ -class PluginPropertiesExtension { - - @Input - String name - - @Input - String version - - @Input - String description - - @Input - String classname - - /** Other plugins this plugin extends through SPI */ - @Input - List extendedPlugins = [] - - @Input - boolean hasNativeController = false - - /** Indicates whether the plugin jar should be made available for the transport client. */ - @Input - boolean hasClientJar = false - - /** True if the plugin requires the elasticsearch keystore to exist, false otherwise. */ - @Input - boolean requiresKeystore = false - - /** A license file that should be included in the built plugin zip. */ - private File licenseFile = null - - /** - * A notice file that should be included in the built plugin zip. This will be - * extended with notices from the {@code licenses/} directory. - */ - private File noticeFile = null - - Project project = null - - PluginPropertiesExtension(Project project) { - name = project.name - version = project.version - this.project = project - } - - @InputFile - File getLicenseFile() { - return licenseFile - } - - void setLicenseFile(File licenseFile) { - project.ext.licenseFile = licenseFile - this.licenseFile = licenseFile - } - - @InputFile - File getNoticeFile() { - return noticeFile - } - - void setNoticeFile(File noticeFile) { - project.ext.noticeFile = noticeFile - this.noticeFile = noticeFile - } -} diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java b/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java new file mode 100644 index 0000000000000..5a694957fe02f --- /dev/null +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java @@ -0,0 +1,173 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.gradle.plugin; + +import org.gradle.api.Project; +import org.gradle.api.tasks.Input; +import org.gradle.api.tasks.InputFile; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +/** + * A container for plugin properties that will be written to the plugin descriptor, for easy + * manipulation in the gradle DSL. + */ +public class PluginPropertiesExtension { + private String name; + + private String version; + + private String description; + + private String classname; + + /** Other plugins this plugin extends through SPI */ + private List extendedPlugins = new ArrayList<>(); + + private boolean hasNativeController; + + /** Indicates whether the plugin jar should be made available for the transport client. */ + private boolean hasClientJar; + + /** True if the plugin requires the elasticsearch keystore to exist, false otherwise. */ + private boolean requiresKeystore; + + /** A license file that should be included in the built plugin zip. */ + private File licenseFile; + + /** + * A notice file that should be included in the built plugin zip. This will be + * extended with notices from the {@code licenses/} directory. + */ + private File noticeFile; + + private Project project; + + public PluginPropertiesExtension(Project project) { + Object version = project.getVersion(); + + this.name = project.getName(); + this.version = (version != null && version instanceof String)? String.valueOf(version) : null; + this.project = project; + } + + @Input + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Input + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + @Input + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @Input + public String getClassname() { + return classname; + } + + public void setClassname(String classname) { + this.classname = classname; + } + + @Input + public List getExtendedPlugins() { + return extendedPlugins; + } + + public void setExtendedPlugins(List extendedPlugins) { + this.extendedPlugins = extendedPlugins; + } + + @Input + public boolean isHasNativeController() { + return hasNativeController; + } + + public void setHasNativeController(boolean hasNativeController) { + this.hasNativeController = hasNativeController; + } + + @Input + public boolean isHasClientJar() { + return hasClientJar; + } + + public void setHasClientJar(boolean hasClientJar) { + this.hasClientJar = hasClientJar; + } + + @Input + public boolean isRequiresKeystore() { + return requiresKeystore; + } + + public void setRequiresKeystore(boolean requiresKeystore) { + this.requiresKeystore = requiresKeystore; + } + + @InputFile + public File getLicenseFile() { + return licenseFile; + } + + public void setLicenseFile(File licenseFile) { + this.project.getExtensions().add("licenseFile", licenseFile); + this.licenseFile = licenseFile; + } + + @InputFile + public File getNoticeFile() { + return noticeFile; + } + + public void setNoticeFile(File noticeFile) { + this.project.getExtensions().add("noticeFile", noticeFile); + this.noticeFile = noticeFile; + } + + @Input + public Project getProject() { + return project; + } + + public void setProject(Project project) { + this.project = project; + } +} diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java b/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java new file mode 100644 index 0000000000000..3bd97b50857e2 --- /dev/null +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java @@ -0,0 +1,125 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.elasticsearch.gradle.plugin; + +import org.elasticsearch.gradle.Version; +import org.elasticsearch.gradle.VersionProperties; +import org.gradle.api.InvalidUserDataException; +import org.gradle.api.Project; +import org.gradle.api.Task; +import org.gradle.api.tasks.Copy; +import org.gradle.api.tasks.Input; +import org.gradle.api.tasks.InputFile; +import org.gradle.api.tasks.OutputFile; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * Creates a plugin descriptor. + */ +public class PluginPropertiesTask extends Copy { + + private PluginPropertiesExtension extension; + + private File descriptorOutput = new File(getProject().getBuildDir(), + "generated-resources/plugin-descriptor.properties"); + + public PluginPropertiesTask() { + Project project = this.getProject(); + + File templateFile = new File(project.getBuildDir(), "templates/" + this.descriptorOutput.getName()); + + Task copyPluginPropertiesTemplate = project.getTasks().create("copyPluginPropertiesTemplate") + .doLast((unused) -> { + InputStream resourceTemplate = PluginPropertiesTask.class.getResourceAsStream("/" + this.descriptorOutput.getName()); + templateFile.getParentFile().mkdirs(); + try { + System.out.println(templateFile); ; + Files.copy(resourceTemplate, templateFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { + throw new RuntimeException(e); + } + }); + dependsOn(copyPluginPropertiesTemplate); + extension = project.getExtensions().create("esplugin", PluginPropertiesExtension.class, project); + project.afterEvaluate((unused) -> { + // check require properties are set + if (this.extension.getName() == null) { + throw new InvalidUserDataException("name is a required setting for esplugin"); + } + if (this.extension.getDescription() == null) { + throw new InvalidUserDataException("description is a required setting for esplugin"); + } + if (this.extension.getClassname() == null) { + throw new InvalidUserDataException("classname is a required setting for esplugin"); + } + + from(templateFile.getParentFile()).include(this.descriptorOutput.getName()); + into(this.descriptorOutput.getParentFile()); + Map properties = this.generateSubstitutions(); + expand(properties); + this.getInputs().properties(properties); + }); + + } + + private Map generateSubstitutions() { + Map substitutions = new HashMap<>(); + substitutions.put("name", this.extension.getName()); + substitutions.put("description", this.extension.getDescription()); + substitutions.put("version", this.extension.getVersion()); + substitutions.put("elasticsearchVersion", Version.fromString(VersionProperties.getElasticsearch()).toString()); + + //TODO (Raf): No getter for project.getTargetCompatibility()? What's the alternative option for below line? + substitutions.put("javaVersion", String.valueOf(this.getProject().getVersion())); + substitutions.put("classname", this.extension.getClassname()); + + //TODO (Raf): Should we worry about possible NPE on getExtendedPlugins() here? + substitutions.put("extendedPlugins", this.extension.getExtendedPlugins().stream().collect(Collectors.joining(","))); + substitutions.put("hasNativeController", String.valueOf(this.extension.isHasNativeController())); + substitutions.put("requiresKeystore", String.valueOf(this.extension.isRequiresKeystore())); + + return substitutions; + } + + @Input + public PluginPropertiesExtension getExtension() { + return extension; + } + + public void setExtension(PluginPropertiesExtension extension) { + this.extension = extension; + } + + @InputFile + public File getDescriptorOutput() { + return descriptorOutput; + } + + public void setDescriptorOutput(File descriptorOutput) { + this.descriptorOutput = descriptorOutput; + } +} From 8874a69cc5738817f8a7a92f84c490ff1e0b45ac Mon Sep 17 00:00:00 2001 From: Rafiullah Hamedy Date: Fri, 8 Mar 2019 02:18:42 -0500 Subject: [PATCH 02/13] Addressed review comments --- .../plugin/PluginPropertiesExtension.java | 37 +++------- .../gradle/plugin/PluginPropertiesTask.java | 69 +++++++++---------- 2 files changed, 42 insertions(+), 64 deletions(-) diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java b/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java index 5a694957fe02f..bd4cd9ce5765a 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java @@ -20,11 +20,11 @@ package org.elasticsearch.gradle.plugin; import org.gradle.api.Project; -import org.gradle.api.tasks.Input; -import org.gradle.api.tasks.InputFile; import java.io.File; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.List; /** @@ -41,7 +41,7 @@ public class PluginPropertiesExtension { private String classname; /** Other plugins this plugin extends through SPI */ - private List extendedPlugins = new ArrayList<>(); + private final List extendedPlugins = new ArrayList<>(); private boolean hasNativeController; @@ -60,17 +60,20 @@ public class PluginPropertiesExtension { */ private File noticeFile; - private Project project; + private final Project project; public PluginPropertiesExtension(Project project) { Object version = project.getVersion(); this.name = project.getName(); - this.version = (version != null && version instanceof String)? String.valueOf(version) : null; + + if(version != null && version instanceof String) { + this.version = String.valueOf(version); + } + this.project = project; } - @Input public String getName() { return name; } @@ -79,7 +82,6 @@ public void setName(String name) { this.name = name; } - @Input public String getVersion() { return version; } @@ -88,7 +90,6 @@ public void setVersion(String version) { this.version = version; } - @Input public String getDescription() { return description; } @@ -97,7 +98,6 @@ public void setDescription(String description) { this.description = description; } - @Input public String getClassname() { return classname; } @@ -106,16 +106,10 @@ public void setClassname(String classname) { this.classname = classname; } - @Input - public List getExtendedPlugins() { - return extendedPlugins; - } - - public void setExtendedPlugins(List extendedPlugins) { - this.extendedPlugins = extendedPlugins; + public Collection getExtendedPlugins() { + return Collections.unmodifiableCollection(extendedPlugins); } - @Input public boolean isHasNativeController() { return hasNativeController; } @@ -124,7 +118,6 @@ public void setHasNativeController(boolean hasNativeController) { this.hasNativeController = hasNativeController; } - @Input public boolean isHasClientJar() { return hasClientJar; } @@ -133,7 +126,6 @@ public void setHasClientJar(boolean hasClientJar) { this.hasClientJar = hasClientJar; } - @Input public boolean isRequiresKeystore() { return requiresKeystore; } @@ -142,7 +134,6 @@ public void setRequiresKeystore(boolean requiresKeystore) { this.requiresKeystore = requiresKeystore; } - @InputFile public File getLicenseFile() { return licenseFile; } @@ -152,7 +143,6 @@ public void setLicenseFile(File licenseFile) { this.licenseFile = licenseFile; } - @InputFile public File getNoticeFile() { return noticeFile; } @@ -162,12 +152,7 @@ public void setNoticeFile(File noticeFile) { this.noticeFile = noticeFile; } - @Input public Project getProject() { return project; } - - public void setProject(Project project) { - this.project = project; - } } diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java b/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java index 3bd97b50857e2..9e2fe54079e65 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java @@ -23,16 +23,13 @@ import org.gradle.api.InvalidUserDataException; import org.gradle.api.Project; import org.gradle.api.Task; +import org.gradle.api.plugins.JavaPluginConvention; import org.gradle.api.tasks.Copy; -import org.gradle.api.tasks.Input; import org.gradle.api.tasks.InputFile; import org.gradle.api.tasks.OutputFile; +import org.gradle.api.tasks.TaskAction; import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.StandardCopyOption; import java.util.HashMap; import java.util.Map; import java.util.stream.Collectors; @@ -52,38 +49,30 @@ public PluginPropertiesTask() { File templateFile = new File(project.getBuildDir(), "templates/" + this.descriptorOutput.getName()); - Task copyPluginPropertiesTemplate = project.getTasks().create("copyPluginPropertiesTemplate") - .doLast((unused) -> { - InputStream resourceTemplate = PluginPropertiesTask.class.getResourceAsStream("/" + this.descriptorOutput.getName()); - templateFile.getParentFile().mkdirs(); - try { - System.out.println(templateFile); ; - Files.copy(resourceTemplate, templateFile.toPath(), StandardCopyOption.REPLACE_EXISTING); - } catch (IOException e) { - throw new RuntimeException(e); - } - }); - dependsOn(copyPluginPropertiesTemplate); extension = project.getExtensions().create("esplugin", PluginPropertiesExtension.class, project); project.afterEvaluate((unused) -> { - // check require properties are set - if (this.extension.getName() == null) { - throw new InvalidUserDataException("name is a required setting for esplugin"); - } - if (this.extension.getDescription() == null) { - throw new InvalidUserDataException("description is a required setting for esplugin"); - } - if (this.extension.getClassname() == null) { - throw new InvalidUserDataException("classname is a required setting for esplugin"); - } - from(templateFile.getParentFile()).include(this.descriptorOutput.getName()); into(this.descriptorOutput.getParentFile()); Map properties = this.generateSubstitutions(); expand(properties); this.getInputs().properties(properties); }); + } + + @TaskAction + public void configurePluginPropertiesTask() { + Project project = this.getProject(); + + File templateFile = new File(project.getBuildDir(), "templates/" + this.descriptorOutput.getName()); + templateFile.getParentFile().mkdirs(); + Task copyPluginPropertiesTemplate = project.getTasks().create("copyPluginPropertiesTemplate") + .doLast((unused) -> { + from("/" + this.descriptorOutput.getName()); + into(templateFile.toPath()); + }); + + dependsOn(copyPluginPropertiesTemplate); } private Map generateSubstitutions() { @@ -92,12 +81,9 @@ private Map generateSubstitutions() { substitutions.put("description", this.extension.getDescription()); substitutions.put("version", this.extension.getVersion()); substitutions.put("elasticsearchVersion", Version.fromString(VersionProperties.getElasticsearch()).toString()); - - //TODO (Raf): No getter for project.getTargetCompatibility()? What's the alternative option for below line? - substitutions.put("javaVersion", String.valueOf(this.getProject().getVersion())); + substitutions.put("javaVersion", getProject().getConvention().getPlugin(JavaPluginConvention.class) + .getTargetCompatibility().toString()); substitutions.put("classname", this.extension.getClassname()); - - //TODO (Raf): Should we worry about possible NPE on getExtendedPlugins() here? substitutions.put("extendedPlugins", this.extension.getExtendedPlugins().stream().collect(Collectors.joining(","))); substitutions.put("hasNativeController", String.valueOf(this.extension.isHasNativeController())); substitutions.put("requiresKeystore", String.valueOf(this.extension.isRequiresKeystore())); @@ -105,13 +91,20 @@ private Map generateSubstitutions() { return substitutions; } - @Input + @OutputFile public PluginPropertiesExtension getExtension() { - return extension; - } + // check require properties are set + if (this.extension.getName() == null) { + throw new InvalidUserDataException("name is a required setting for esplugin"); + } + if (this.extension.getDescription() == null) { + throw new InvalidUserDataException("description is a required setting for esplugin"); + } + if (this.extension.getClassname() == null) { + throw new InvalidUserDataException("classname is a required setting for esplugin"); + } - public void setExtension(PluginPropertiesExtension extension) { - this.extension = extension; + return extension; } @InputFile From d376c1e46e73719c015d19aedbdd46cf8fd2f849 Mon Sep 17 00:00:00 2001 From: Rafiullah Hamedy Date: Tue, 12 Mar 2019 02:16:47 -0400 Subject: [PATCH 03/13] Refactored the code with regards to code review comments --- .../plugin/PluginPropertiesExtension.java | 8 ++++- .../gradle/plugin/PluginPropertiesTask.java | 34 +++++++------------ 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java b/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java index bd4cd9ce5765a..b2ef425fbb2d3 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java @@ -41,7 +41,7 @@ public class PluginPropertiesExtension { private String classname; /** Other plugins this plugin extends through SPI */ - private final List extendedPlugins = new ArrayList<>(); + private List extendedPlugins = new ArrayList<>(); private boolean hasNativeController; @@ -155,4 +155,10 @@ public void setNoticeFile(File noticeFile) { public Project getProject() { return project; } + + public void setExtendedPlugins(List extendedPlugins) { + if(extendedPlugins != null) { + this.extendedPlugins = extendedPlugins; + } + } } diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java b/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java index 9e2fe54079e65..b8bfea12222f3 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java @@ -18,13 +18,15 @@ */ package org.elasticsearch.gradle.plugin; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; import org.elasticsearch.gradle.Version; import org.elasticsearch.gradle.VersionProperties; +import org.gradle.api.DefaultTask; import org.gradle.api.InvalidUserDataException; import org.gradle.api.Project; -import org.gradle.api.Task; +import org.gradle.api.file.CopySpec; import org.gradle.api.plugins.JavaPluginConvention; -import org.gradle.api.tasks.Copy; import org.gradle.api.tasks.InputFile; import org.gradle.api.tasks.OutputFile; import org.gradle.api.tasks.TaskAction; @@ -37,7 +39,7 @@ /** * Creates a plugin descriptor. */ -public class PluginPropertiesTask extends Copy { +public class PluginPropertiesTask extends DefaultTask { private PluginPropertiesExtension extension; @@ -46,33 +48,21 @@ public class PluginPropertiesTask extends Copy { public PluginPropertiesTask() { Project project = this.getProject(); - - File templateFile = new File(project.getBuildDir(), "templates/" + this.descriptorOutput.getName()); - - extension = project.getExtensions().create("esplugin", PluginPropertiesExtension.class, project); - project.afterEvaluate((unused) -> { - from(templateFile.getParentFile()).include(this.descriptorOutput.getName()); - into(this.descriptorOutput.getParentFile()); - Map properties = this.generateSubstitutions(); - expand(properties); - this.getInputs().properties(properties); - }); + this.extension = project.getExtensions().create("esplugin", PluginPropertiesExtension.class, project); } @TaskAction public void configurePluginPropertiesTask() { Project project = this.getProject(); - File templateFile = new File(project.getBuildDir(), "templates/" + this.descriptorOutput.getName()); + File templateFile = new File(project.getBuildDir(), "templates"); templateFile.getParentFile().mkdirs(); - Task copyPluginPropertiesTemplate = project.getTasks().create("copyPluginPropertiesTemplate") - .doLast((unused) -> { - from("/" + this.descriptorOutput.getName()); - into(templateFile.toPath()); - }); - - dependsOn(copyPluginPropertiesTemplate); + project.copy((cp) -> { + cp.from(getClass().getClassLoader().getResource(this.descriptorOutput.getName())).into(templateFile); + cp.expand(this.generateSubstitutions()); + this.getInputs().properties(this.generateSubstitutions()); + }); } private Map generateSubstitutions() { From 66e4a9390b97d856da40515c8a0d3691d80bb09f Mon Sep 17 00:00:00 2001 From: Rafiullah Hamedy Date: Tue, 12 Mar 2019 02:17:35 -0400 Subject: [PATCH 04/13] Added plugin-descriptor.proerties along with unit tests for new java classes --- .../PluginPropertiesExtensionTests.java | 58 ++++++++ .../plugin/PluginPropertiesTaskTests.java | 125 ++++++++++++++++++ .../resources/plugin-descriptor.properties | 45 +++++++ 3 files changed, 228 insertions(+) create mode 100644 buildSrc/src/test/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtensionTests.java create mode 100644 buildSrc/src/test/java/org/elasticsearch/gradle/plugin/PluginPropertiesTaskTests.java create mode 100644 buildSrc/src/test/resources/plugin-descriptor.properties diff --git a/buildSrc/src/test/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtensionTests.java b/buildSrc/src/test/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtensionTests.java new file mode 100644 index 0000000000000..b93d400f3e057 --- /dev/null +++ b/buildSrc/src/test/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtensionTests.java @@ -0,0 +1,58 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.gradle.plugin; + +import org.elasticsearch.gradle.test.GradleUnitTestCase; +import org.gradle.api.Project; +import org.gradle.api.plugins.JavaPlugin; +import org.gradle.testfixtures.ProjectBuilder; + +public class PluginPropertiesExtensionTests extends GradleUnitTestCase { + + public void testCreatingPluginPropertiesExtensionWithNameAndVersion() { + String projectName = "Test"; + String projectVersion = "5.0"; + + PluginPropertiesExtension pluginPropertiesExtension = + new PluginPropertiesExtension(this.createProject(projectName, projectVersion)); + + assertEquals(projectName, pluginPropertiesExtension.getName()); + assertEquals(projectVersion, pluginPropertiesExtension.getVersion()); + } + + public void testCreatingPluginPropertiesExtensionWithNameWithoutVersion() { + String projectName = "Test"; + + PluginPropertiesExtension pluginPropertiesExtension = + new PluginPropertiesExtension(this.createProject(projectName, null)); + + assertEquals(projectName, pluginPropertiesExtension.getName()); + assertEquals("unspecified", pluginPropertiesExtension.getVersion()); + } + + private Project createProject(String projectName, String version) { + Project project = ProjectBuilder.builder().withName(projectName).build(); + project.setVersion(version); + + project.getPlugins().apply(JavaPlugin.class); + + return project; + } +} diff --git a/buildSrc/src/test/java/org/elasticsearch/gradle/plugin/PluginPropertiesTaskTests.java b/buildSrc/src/test/java/org/elasticsearch/gradle/plugin/PluginPropertiesTaskTests.java new file mode 100644 index 0000000000000..297ad8968f639 --- /dev/null +++ b/buildSrc/src/test/java/org/elasticsearch/gradle/plugin/PluginPropertiesTaskTests.java @@ -0,0 +1,125 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.gradle.plugin; + +import org.elasticsearch.gradle.test.GradleUnitTestCase; +import org.gradle.api.InvalidUserDataException; +import org.gradle.api.Project; +import org.gradle.api.plugins.JavaPlugin; +import org.gradle.testfixtures.ProjectBuilder; +import org.junit.Rule; +import org.junit.rules.ExpectedException; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.util.Arrays; +import java.util.List; + +public class PluginPropertiesTaskTests extends GradleUnitTestCase { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + public void testCheckPluginPropertiesExtensionMissingName() { + Project project = createProject(); + + thrown.expect(InvalidUserDataException.class); + thrown.expectMessage("name is a required setting for esplugin"); + createTask(project, null, "desc", "a.b.c").getExtension(); + } + + public void testCheckPluginPropertiesExtensionMissingDescription() { + Project project = createProject(); + + thrown.expect(InvalidUserDataException.class); + thrown.expectMessage("description is a required setting for esplugin"); + createTask(project, "name", null, "a.b.c").getExtension(); + } + + public void testCheckPluginPropertiesExtensionMissingClassname() { + Project project = createProject(); + + thrown.expect(InvalidUserDataException.class); + thrown.expectMessage("classname is a required setting for esplugin"); + createTask(project, "name", "desc", null).getExtension(); + } + + public void testCheckValidPluginPropertiesTaskPropertySubstitution() throws IOException { + Project project = createProject(); + PluginPropertiesTask pluginPropertiesTask = createTask(project, "plugin-name", "plugin-description", + "plugin-classname"); + + String descriptorFilename = pluginPropertiesTask.getDescriptorOutput().getName(); + + File file = new File(getClass().getClassLoader().getResource(descriptorFilename).getPath()); + file.getParentFile().mkdirs(); + file.createNewFile(); + Files.write(file.toPath(), this.builProperties(), StandardCharsets.UTF_8); + + pluginPropertiesTask.configurePluginPropertiesTask(); + + File copiedFile = new File(project.getBuildDir(), "templates/" + descriptorFilename); + + String content = new String(Files.readAllBytes(copiedFile.toPath())); + + assertEquals( + "description=plugin-description\n" + + "version=unspecified\n" + + "name=plugin-name\n" + + "classname=plugin-classname\n" + + "java.version=11\n" + + "elasticsearch.version=8.0.0\n" + + "extended.plugins=\n" + + "has.native.controller=false\n", content); + } + + private List builProperties() { + return Arrays.asList( + "description=${description}", + "version=${version}", + "name=${name}", + "classname=${classname}", + "java.version=${javaVersion}", + "elasticsearch.version=${elasticsearchVersion}", + "extended.plugins=${extendedPlugins}", + "has.native.controller=${hasNativeController}" + ); + } + + private Project createProject() { + Project project = ProjectBuilder.builder().build(); + project.getPlugins().apply(JavaPlugin.class); + return project; + } + + private PluginPropertiesTask createTask(Project project, String name, String description, String classname) { + PluginPropertiesTask task = project.getTasks().create("copyPluginPropertiesTemplate", PluginPropertiesTask.class); + + PluginPropertiesExtension extension = task.getProject().getExtensions().getByType(PluginPropertiesExtension.class); + + extension.setName(name); + extension.setDescription(description); + extension.setClassname(classname); + + return task; + } +} diff --git a/buildSrc/src/test/resources/plugin-descriptor.properties b/buildSrc/src/test/resources/plugin-descriptor.properties new file mode 100644 index 0000000000000..03013e8fed849 --- /dev/null +++ b/buildSrc/src/test/resources/plugin-descriptor.properties @@ -0,0 +1,45 @@ +# Elasticsearch plugin descriptor file +# This file must exist as 'plugin-descriptor.properties' inside a plugin. +# +### example plugin for "foo" +# +# foo.zip <-- zip file for the plugin, with this structure: +# |____ .jar <-- classes, resources, dependencies +# |____ .jar <-- any number of jars +# |____ plugin-descriptor.properties <-- example contents below: +# +# classname=foo.bar.BazPlugin +# description=My cool plugin +# version=6.0 +# elasticsearch.version=6.0 +# java.version=1.8 +# +### mandatory elements for all plugins: +# +# 'description': simple summary of the plugin +description=${description} +# +# 'version': plugin's version +version=${version} +# +# 'name': the plugin name +name=${name} +# +# 'classname': the name of the class to load, fully-qualified. +classname=${classname} +# +# 'java.version': version of java the code is built against +# use the system property java.specification.version +# version string must be a sequence of nonnegative decimal integers +# separated by "."'s and may have leading zeros +java.version=${javaVersion} +# +# 'elasticsearch.version': version of elasticsearch compiled against +elasticsearch.version=${elasticsearchVersion} +### optional elements for plugins: +# +# 'extended.plugins': other plugins this plugin extends through SPI +extended.plugins=${extendedPlugins} +# +# 'has.native.controller': whether or not the plugin has a native controller +has.native.controller=${hasNativeController} From 3b35c9695d434778ada8b2eb649f08eb2d48b5a0 Mon Sep 17 00:00:00 2001 From: Rafiullah Hamedy Date: Wed, 13 Mar 2019 20:49:12 -0400 Subject: [PATCH 05/13] Removed unnecessary properties file --- .../resources/plugin-descriptor.properties | 45 ------------------- 1 file changed, 45 deletions(-) delete mode 100644 buildSrc/src/test/resources/plugin-descriptor.properties diff --git a/buildSrc/src/test/resources/plugin-descriptor.properties b/buildSrc/src/test/resources/plugin-descriptor.properties deleted file mode 100644 index 03013e8fed849..0000000000000 --- a/buildSrc/src/test/resources/plugin-descriptor.properties +++ /dev/null @@ -1,45 +0,0 @@ -# Elasticsearch plugin descriptor file -# This file must exist as 'plugin-descriptor.properties' inside a plugin. -# -### example plugin for "foo" -# -# foo.zip <-- zip file for the plugin, with this structure: -# |____ .jar <-- classes, resources, dependencies -# |____ .jar <-- any number of jars -# |____ plugin-descriptor.properties <-- example contents below: -# -# classname=foo.bar.BazPlugin -# description=My cool plugin -# version=6.0 -# elasticsearch.version=6.0 -# java.version=1.8 -# -### mandatory elements for all plugins: -# -# 'description': simple summary of the plugin -description=${description} -# -# 'version': plugin's version -version=${version} -# -# 'name': the plugin name -name=${name} -# -# 'classname': the name of the class to load, fully-qualified. -classname=${classname} -# -# 'java.version': version of java the code is built against -# use the system property java.specification.version -# version string must be a sequence of nonnegative decimal integers -# separated by "."'s and may have leading zeros -java.version=${javaVersion} -# -# 'elasticsearch.version': version of elasticsearch compiled against -elasticsearch.version=${elasticsearchVersion} -### optional elements for plugins: -# -# 'extended.plugins': other plugins this plugin extends through SPI -extended.plugins=${extendedPlugins} -# -# 'has.native.controller': whether or not the plugin has a native controller -has.native.controller=${hasNativeController} From cdb746a2a6df2f68d2de3b9734ca11932df785dc Mon Sep 17 00:00:00 2001 From: Rafiullah Hamedy Date: Wed, 13 Mar 2019 20:49:48 -0400 Subject: [PATCH 06/13] Changed the implmentation and addressed code review --- .../plugin/PluginPropertiesExtension.java | 20 ++++--------- .../gradle/plugin/PluginPropertiesTask.java | 29 ++++++++++++------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java b/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java index b2ef425fbb2d3..5e7e1b3cf920c 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java @@ -23,8 +23,6 @@ import java.io.File; import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; import java.util.List; /** @@ -63,14 +61,8 @@ public class PluginPropertiesExtension { private final Project project; public PluginPropertiesExtension(Project project) { - Object version = project.getVersion(); - this.name = project.getName(); - - if(version != null && version instanceof String) { - this.version = String.valueOf(version); - } - + this.version = project.getVersion().toString(); this.project = project; } @@ -106,11 +98,11 @@ public void setClassname(String classname) { this.classname = classname; } - public Collection getExtendedPlugins() { - return Collections.unmodifiableCollection(extendedPlugins); + public List getExtendedPlugins() { + return this.extendedPlugins; } - public boolean isHasNativeController() { + public boolean hasNativeController() { return hasNativeController; } @@ -157,8 +149,6 @@ public Project getProject() { } public void setExtendedPlugins(List extendedPlugins) { - if(extendedPlugins != null) { - this.extendedPlugins = extendedPlugins; - } + this.extendedPlugins = extendedPlugins; } } diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java b/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java index b8bfea12222f3..e151f00682c8e 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java @@ -18,20 +18,19 @@ */ package org.elasticsearch.gradle.plugin; -import org.apache.log4j.LogManager; -import org.apache.log4j.Logger; -import org.elasticsearch.gradle.Version; import org.elasticsearch.gradle.VersionProperties; import org.gradle.api.DefaultTask; import org.gradle.api.InvalidUserDataException; import org.gradle.api.Project; -import org.gradle.api.file.CopySpec; import org.gradle.api.plugins.JavaPluginConvention; import org.gradle.api.tasks.InputFile; import org.gradle.api.tasks.OutputFile; import org.gradle.api.tasks.TaskAction; import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; import java.util.HashMap; import java.util.Map; import java.util.stream.Collectors; @@ -52,15 +51,23 @@ public PluginPropertiesTask() { } @TaskAction - public void configurePluginPropertiesTask() { + public void performAction() { Project project = this.getProject(); - File templateFile = new File(project.getBuildDir(), "templates"); + File templateFile = new File(project.getBuildDir(), "templates/" + descriptorOutput.getName()); templateFile.getParentFile().mkdirs(); - project.copy((cp) -> { - cp.from(getClass().getClassLoader().getResource(this.descriptorOutput.getName())).into(templateFile); - cp.expand(this.generateSubstitutions()); + InputStream resourceTemplate = this.getClass().getResourceAsStream("/" + descriptorOutput.getName()); + + try { + Files.copy(resourceTemplate, templateFile.toPath()); + } catch (IOException e) { + throw new RuntimeException(e); + } + + project.copy(copyArg -> { + copyArg.from(templateFile.getParentFile()).include(descriptorOutput.getName()) + .into(descriptorOutput.getParentFile()).expand(this.generateSubstitutions()); this.getInputs().properties(this.generateSubstitutions()); }); } @@ -70,12 +77,12 @@ private Map generateSubstitutions() { substitutions.put("name", this.extension.getName()); substitutions.put("description", this.extension.getDescription()); substitutions.put("version", this.extension.getVersion()); - substitutions.put("elasticsearchVersion", Version.fromString(VersionProperties.getElasticsearch()).toString()); + substitutions.put("elasticsearchVersion", VersionProperties.getElasticsearch()); substitutions.put("javaVersion", getProject().getConvention().getPlugin(JavaPluginConvention.class) .getTargetCompatibility().toString()); substitutions.put("classname", this.extension.getClassname()); substitutions.put("extendedPlugins", this.extension.getExtendedPlugins().stream().collect(Collectors.joining(","))); - substitutions.put("hasNativeController", String.valueOf(this.extension.isHasNativeController())); + substitutions.put("hasNativeController", String.valueOf(this.extension.hasNativeController())); substitutions.put("requiresKeystore", String.valueOf(this.extension.isRequiresKeystore())); return substitutions; From d01e612d54695ba1f44a6f1ea4ea2fa6b2c918d0 Mon Sep 17 00:00:00 2001 From: Rafiullah Hamedy Date: Wed, 13 Mar 2019 20:50:10 -0400 Subject: [PATCH 07/13] Fixed the tests and verified its working --- .../plugin/PluginPropertiesTaskTests.java | 61 +++++++++---------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/buildSrc/src/test/java/org/elasticsearch/gradle/plugin/PluginPropertiesTaskTests.java b/buildSrc/src/test/java/org/elasticsearch/gradle/plugin/PluginPropertiesTaskTests.java index 297ad8968f639..5c0a426786fe6 100644 --- a/buildSrc/src/test/java/org/elasticsearch/gradle/plugin/PluginPropertiesTaskTests.java +++ b/buildSrc/src/test/java/org/elasticsearch/gradle/plugin/PluginPropertiesTaskTests.java @@ -19,20 +19,22 @@ package org.elasticsearch.gradle.plugin; +import org.elasticsearch.gradle.VersionProperties; import org.elasticsearch.gradle.test.GradleUnitTestCase; import org.gradle.api.InvalidUserDataException; import org.gradle.api.Project; import org.gradle.api.plugins.JavaPlugin; +import org.gradle.api.plugins.JavaPluginConvention; import org.gradle.testfixtures.ProjectBuilder; import org.junit.Rule; import org.junit.rules.ExpectedException; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; import java.util.Arrays; -import java.util.List; +import java.util.Properties; +import java.util.stream.Collectors; public class PluginPropertiesTaskTests extends GradleUnitTestCase { @@ -66,43 +68,34 @@ public void testCheckPluginPropertiesExtensionMissingClassname() { public void testCheckValidPluginPropertiesTaskPropertySubstitution() throws IOException { Project project = createProject(); PluginPropertiesTask pluginPropertiesTask = createTask(project, "plugin-name", "plugin-description", - "plugin-classname"); + "PluginClassname"); - String descriptorFilename = pluginPropertiesTask.getDescriptorOutput().getName(); + pluginPropertiesTask.performAction(); - File file = new File(getClass().getClassLoader().getResource(descriptorFilename).getPath()); - file.getParentFile().mkdirs(); - file.createNewFile(); - Files.write(file.toPath(), this.builProperties(), StandardCharsets.UTF_8); + PluginPropertiesExtension pluginPropertiesTaskExtension = pluginPropertiesTask.getProject().getExtensions() + .getByType(PluginPropertiesExtension.class); - pluginPropertiesTask.configurePluginPropertiesTask(); + File generatedPluginDescriptorFile = new File(project.getBuildDir(), "generated-resources/plugin-descriptor.properties"); - File copiedFile = new File(project.getBuildDir(), "templates/" + descriptorFilename); + assertTrue(generatedPluginDescriptorFile.exists()); - String content = new String(Files.readAllBytes(copiedFile.toPath())); + Properties generatedPluginDescriptorProps = new Properties(); + generatedPluginDescriptorProps.load(new FileInputStream(generatedPluginDescriptorFile)); - assertEquals( - "description=plugin-description\n" + - "version=unspecified\n" + - "name=plugin-name\n" + - "classname=plugin-classname\n" + - "java.version=11\n" + - "elasticsearch.version=8.0.0\n" + - "extended.plugins=\n" + - "has.native.controller=false\n", content); - } + assertEquals(pluginPropertiesTaskExtension.getName(), generatedPluginDescriptorProps.getProperty("name")); + assertEquals(pluginPropertiesTaskExtension.getDescription(), generatedPluginDescriptorProps.getProperty("description")); + assertEquals(pluginPropertiesTaskExtension.getClassname(), generatedPluginDescriptorProps.getProperty("classname")); + assertEquals(pluginPropertiesTaskExtension.getVersion(), generatedPluginDescriptorProps.getProperty("version")); + assertEquals(VersionProperties.getElasticsearch(), generatedPluginDescriptorProps.getProperty("elasticsearch.version")); + + assertEquals(pluginPropertiesTaskExtension.getExtendedPlugins().stream().collect(Collectors.joining(",")), + generatedPluginDescriptorProps.getProperty("extended.plugins")); + + assertEquals(project.getConvention().getPlugin(JavaPluginConvention.class).getTargetCompatibility().toString(), + generatedPluginDescriptorProps.getProperty("java.version")); - private List builProperties() { - return Arrays.asList( - "description=${description}", - "version=${version}", - "name=${name}", - "classname=${classname}", - "java.version=${javaVersion}", - "elasticsearch.version=${elasticsearchVersion}", - "extended.plugins=${extendedPlugins}", - "has.native.controller=${hasNativeController}" - ); + assertEquals(String.valueOf(pluginPropertiesTaskExtension.hasNativeController()), + generatedPluginDescriptorProps.getProperty("has.native.controller")); } private Project createProject() { @@ -119,6 +112,8 @@ private PluginPropertiesTask createTask(Project project, String name, String des extension.setName(name); extension.setDescription(description); extension.setClassname(classname); + extension.setVersion("4.2.0"); + extension.setExtendedPlugins(Arrays.asList("plugin1", "plugin2")); return task; } From d144e6a4ce4240bf47a33ad0d149478927fdd7b6 Mon Sep 17 00:00:00 2001 From: Rafiullah Hamedy Date: Thu, 21 Mar 2019 23:24:41 -0400 Subject: [PATCH 08/13] Register extension in PluginBuildPlugin, Refactore PluginPropertiesTask, update the tests --- .../gradle/plugin/PluginBuildPlugin.groovy | 2 + .../gradle/plugin/PluginPropertiesTask.java | 31 +++++----- .../plugin/PluginPropertiesTaskTests.java | 59 ++++++++++--------- 3 files changed, 49 insertions(+), 43 deletions(-) diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy index 9d303fcb78dc0..a2fb7c7889696 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy @@ -52,6 +52,8 @@ class PluginBuildPlugin extends BuildPlugin { super.apply(project) PluginPropertiesExtension extension = project.extensions.create(PLUGIN_EXTENSION_NAME, PluginPropertiesExtension, project) + project.pluginManager.apply('elasticsearch.esplugin') + configureDependencies(project) // this afterEvaluate must happen before the afterEvaluate added by integTest creation, diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java b/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java index e151f00682c8e..23037a0ca7930 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java @@ -23,8 +23,8 @@ import org.gradle.api.InvalidUserDataException; import org.gradle.api.Project; import org.gradle.api.plugins.JavaPluginConvention; +import org.gradle.api.tasks.Input; import org.gradle.api.tasks.InputFile; -import org.gradle.api.tasks.OutputFile; import org.gradle.api.tasks.TaskAction; import java.io.File; @@ -47,7 +47,7 @@ public class PluginPropertiesTask extends DefaultTask { public PluginPropertiesTask() { Project project = this.getProject(); - this.extension = project.getExtensions().create("esplugin", PluginPropertiesExtension.class, project); + this.extension = (PluginPropertiesExtension) project.getExtensions().getByName("esplugin"); } @TaskAction @@ -68,11 +68,22 @@ public void performAction() { project.copy(copyArg -> { copyArg.from(templateFile.getParentFile()).include(descriptorOutput.getName()) .into(descriptorOutput.getParentFile()).expand(this.generateSubstitutions()); - this.getInputs().properties(this.generateSubstitutions()); }); } - private Map generateSubstitutions() { + @Input + public Map generateSubstitutions() { + // check require properties are set + if (this.extension.getName() == null) { + throw new InvalidUserDataException("name is a required setting for esplugin"); + } + if (this.extension.getDescription() == null) { + throw new InvalidUserDataException("description is a required setting for esplugin"); + } + if (this.extension.getClassname() == null) { + throw new InvalidUserDataException("classname is a required setting for esplugin"); + } + Map substitutions = new HashMap<>(); substitutions.put("name", this.extension.getName()); substitutions.put("description", this.extension.getDescription()); @@ -88,19 +99,7 @@ private Map generateSubstitutions() { return substitutions; } - @OutputFile public PluginPropertiesExtension getExtension() { - // check require properties are set - if (this.extension.getName() == null) { - throw new InvalidUserDataException("name is a required setting for esplugin"); - } - if (this.extension.getDescription() == null) { - throw new InvalidUserDataException("description is a required setting for esplugin"); - } - if (this.extension.getClassname() == null) { - throw new InvalidUserDataException("classname is a required setting for esplugin"); - } - return extension; } diff --git a/buildSrc/src/test/java/org/elasticsearch/gradle/plugin/PluginPropertiesTaskTests.java b/buildSrc/src/test/java/org/elasticsearch/gradle/plugin/PluginPropertiesTaskTests.java index 5c0a426786fe6..9e8014796e095 100644 --- a/buildSrc/src/test/java/org/elasticsearch/gradle/plugin/PluginPropertiesTaskTests.java +++ b/buildSrc/src/test/java/org/elasticsearch/gradle/plugin/PluginPropertiesTaskTests.java @@ -41,31 +41,7 @@ public class PluginPropertiesTaskTests extends GradleUnitTestCase { @Rule public ExpectedException thrown = ExpectedException.none(); - public void testCheckPluginPropertiesExtensionMissingName() { - Project project = createProject(); - - thrown.expect(InvalidUserDataException.class); - thrown.expectMessage("name is a required setting for esplugin"); - createTask(project, null, "desc", "a.b.c").getExtension(); - } - - public void testCheckPluginPropertiesExtensionMissingDescription() { - Project project = createProject(); - - thrown.expect(InvalidUserDataException.class); - thrown.expectMessage("description is a required setting for esplugin"); - createTask(project, "name", null, "a.b.c").getExtension(); - } - - public void testCheckPluginPropertiesExtensionMissingClassname() { - Project project = createProject(); - - thrown.expect(InvalidUserDataException.class); - thrown.expectMessage("classname is a required setting for esplugin"); - createTask(project, "name", "desc", null).getExtension(); - } - - public void testCheckValidPluginPropertiesTaskPropertySubstitution() throws IOException { + public void testPluginPropertiesTaskActionExecutesSuccessfully() throws IOException { Project project = createProject(); PluginPropertiesTask pluginPropertiesTask = createTask(project, "plugin-name", "plugin-description", "PluginClassname"); @@ -98,16 +74,45 @@ public void testCheckValidPluginPropertiesTaskPropertySubstitution() throws IOEx generatedPluginDescriptorProps.getProperty("has.native.controller")); } + public void testPluginPropertiesTaskActionThrowExceptionForMissingName() throws IOException { + Project project = createProject(); + PluginPropertiesTask pluginPropertiesTask = createTask(project, null, "plugin-description", + "PluginClassname"); + + thrown.expect(InvalidUserDataException.class); + thrown.expectMessage("name is a required setting for esplugin"); + pluginPropertiesTask.performAction(); + } + + public void testPluginPropertiesTaskActionThrowExceptionForMissingDescription() throws IOException { + Project project = createProject(); + PluginPropertiesTask pluginPropertiesTask = createTask(project, "plugin-name", null, "PluginClassname"); + + thrown.expect(InvalidUserDataException.class); + thrown.expectMessage("description is a required setting for esplugin"); + pluginPropertiesTask.performAction(); + } + + public void testPluginPropertiesTaskActionThrowExceptionForMissingClassname() throws IOException { + Project project = createProject(); + PluginPropertiesTask pluginPropertiesTask = createTask(project, "plugin-name", "plugin-description", null); + + thrown.expect(InvalidUserDataException.class); + thrown.expectMessage("classname is a required setting for esplugin"); + pluginPropertiesTask.performAction(); + } + private Project createProject() { Project project = ProjectBuilder.builder().build(); project.getPlugins().apply(JavaPlugin.class); + project.getExtensions().create("esplugin", PluginPropertiesExtension.class, project); return project; } private PluginPropertiesTask createTask(Project project, String name, String description, String classname) { - PluginPropertiesTask task = project.getTasks().create("copyPluginPropertiesTemplate", PluginPropertiesTask.class); + PluginPropertiesTask task = project.getTasks().create("taskname", PluginPropertiesTask.class); - PluginPropertiesExtension extension = task.getProject().getExtensions().getByType(PluginPropertiesExtension.class); + PluginPropertiesExtension extension = (PluginPropertiesExtension) task.getProject().getExtensions().getByName("esplugin"); extension.setName(name); extension.setDescription(description); From a9aca3b72b673cc51423bb9217c360f4ae7199a8 Mon Sep 17 00:00:00 2001 From: Rafiullah Hamedy Date: Thu, 21 Mar 2019 23:30:44 -0400 Subject: [PATCH 09/13] Wrap the inputstream in try-with-resource --- .../org/elasticsearch/gradle/plugin/PluginPropertiesTask.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java b/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java index 23037a0ca7930..4915cc519eb16 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java @@ -57,9 +57,7 @@ public void performAction() { File templateFile = new File(project.getBuildDir(), "templates/" + descriptorOutput.getName()); templateFile.getParentFile().mkdirs(); - InputStream resourceTemplate = this.getClass().getResourceAsStream("/" + descriptorOutput.getName()); - - try { + try (InputStream resourceTemplate = this.getClass().getResourceAsStream("/" + descriptorOutput.getName())) { Files.copy(resourceTemplate, templateFile.toPath()); } catch (IOException e) { throw new RuntimeException(e); From f00f100e9f8c8bea6f25b47ed2dfe6682312622c Mon Sep 17 00:00:00 2001 From: Rafiullah Hamedy Date: Thu, 28 Mar 2019 22:50:05 -0400 Subject: [PATCH 10/13] Use StandardCopyOption.REPLACE_EXISTING when File.copy, unchain the method calls --- .../gradle/plugin/PluginPropertiesTask.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java b/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java index 4915cc519eb16..0f45db6f67f4c 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java @@ -31,6 +31,7 @@ import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; +import java.nio.file.StandardCopyOption; import java.util.HashMap; import java.util.Map; import java.util.stream.Collectors; @@ -58,14 +59,16 @@ public void performAction() { templateFile.getParentFile().mkdirs(); try (InputStream resourceTemplate = this.getClass().getResourceAsStream("/" + descriptorOutput.getName())) { - Files.copy(resourceTemplate, templateFile.toPath()); + Files.copy(resourceTemplate, templateFile.toPath(), StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { throw new RuntimeException(e); } project.copy(copyArg -> { - copyArg.from(templateFile.getParentFile()).include(descriptorOutput.getName()) - .into(descriptorOutput.getParentFile()).expand(this.generateSubstitutions()); + copyArg.from(templateFile.getParentFile()); + copyArg.include(descriptorOutput.getName()); + copyArg.into(descriptorOutput.getParentFile()); + copyArg.expand(this.generateSubstitutions()); }); } From 03fa92fef31e22ba2665c724ef1016e3efceb77a Mon Sep 17 00:00:00 2001 From: Rafiullah Hamedy Date: Wed, 17 Apr 2019 01:07:06 -0400 Subject: [PATCH 11/13] Delete previously converted PluginPropertiesTask and it's tests, rename hasNativeController to getHasNativeController --- .../plugin/PluginPropertiesExtension.java | 2 +- .../gradle/plugin/PluginPropertiesTask.java | 115 ---------------- .../plugin/PluginPropertiesTaskTests.java | 125 ------------------ 3 files changed, 1 insertion(+), 241 deletions(-) delete mode 100644 buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java delete mode 100644 buildSrc/src/test/java/org/elasticsearch/gradle/plugin/PluginPropertiesTaskTests.java diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java b/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java index 5e7e1b3cf920c..cf8673c01ab92 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java @@ -102,7 +102,7 @@ public List getExtendedPlugins() { return this.extendedPlugins; } - public boolean hasNativeController() { + public boolean getHasNativeController() { return hasNativeController; } diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java b/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java deleted file mode 100644 index 0f45db6f67f4c..0000000000000 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.gradle.plugin; - -import org.elasticsearch.gradle.VersionProperties; -import org.gradle.api.DefaultTask; -import org.gradle.api.InvalidUserDataException; -import org.gradle.api.Project; -import org.gradle.api.plugins.JavaPluginConvention; -import org.gradle.api.tasks.Input; -import org.gradle.api.tasks.InputFile; -import org.gradle.api.tasks.TaskAction; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.StandardCopyOption; -import java.util.HashMap; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * Creates a plugin descriptor. - */ -public class PluginPropertiesTask extends DefaultTask { - - private PluginPropertiesExtension extension; - - private File descriptorOutput = new File(getProject().getBuildDir(), - "generated-resources/plugin-descriptor.properties"); - - public PluginPropertiesTask() { - Project project = this.getProject(); - this.extension = (PluginPropertiesExtension) project.getExtensions().getByName("esplugin"); - } - - @TaskAction - public void performAction() { - Project project = this.getProject(); - - File templateFile = new File(project.getBuildDir(), "templates/" + descriptorOutput.getName()); - templateFile.getParentFile().mkdirs(); - - try (InputStream resourceTemplate = this.getClass().getResourceAsStream("/" + descriptorOutput.getName())) { - Files.copy(resourceTemplate, templateFile.toPath(), StandardCopyOption.REPLACE_EXISTING); - } catch (IOException e) { - throw new RuntimeException(e); - } - - project.copy(copyArg -> { - copyArg.from(templateFile.getParentFile()); - copyArg.include(descriptorOutput.getName()); - copyArg.into(descriptorOutput.getParentFile()); - copyArg.expand(this.generateSubstitutions()); - }); - } - - @Input - public Map generateSubstitutions() { - // check require properties are set - if (this.extension.getName() == null) { - throw new InvalidUserDataException("name is a required setting for esplugin"); - } - if (this.extension.getDescription() == null) { - throw new InvalidUserDataException("description is a required setting for esplugin"); - } - if (this.extension.getClassname() == null) { - throw new InvalidUserDataException("classname is a required setting for esplugin"); - } - - Map substitutions = new HashMap<>(); - substitutions.put("name", this.extension.getName()); - substitutions.put("description", this.extension.getDescription()); - substitutions.put("version", this.extension.getVersion()); - substitutions.put("elasticsearchVersion", VersionProperties.getElasticsearch()); - substitutions.put("javaVersion", getProject().getConvention().getPlugin(JavaPluginConvention.class) - .getTargetCompatibility().toString()); - substitutions.put("classname", this.extension.getClassname()); - substitutions.put("extendedPlugins", this.extension.getExtendedPlugins().stream().collect(Collectors.joining(","))); - substitutions.put("hasNativeController", String.valueOf(this.extension.hasNativeController())); - substitutions.put("requiresKeystore", String.valueOf(this.extension.isRequiresKeystore())); - - return substitutions; - } - - public PluginPropertiesExtension getExtension() { - return extension; - } - - @InputFile - public File getDescriptorOutput() { - return descriptorOutput; - } - - public void setDescriptorOutput(File descriptorOutput) { - this.descriptorOutput = descriptorOutput; - } -} diff --git a/buildSrc/src/test/java/org/elasticsearch/gradle/plugin/PluginPropertiesTaskTests.java b/buildSrc/src/test/java/org/elasticsearch/gradle/plugin/PluginPropertiesTaskTests.java deleted file mode 100644 index 9e8014796e095..0000000000000 --- a/buildSrc/src/test/java/org/elasticsearch/gradle/plugin/PluginPropertiesTaskTests.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.gradle.plugin; - -import org.elasticsearch.gradle.VersionProperties; -import org.elasticsearch.gradle.test.GradleUnitTestCase; -import org.gradle.api.InvalidUserDataException; -import org.gradle.api.Project; -import org.gradle.api.plugins.JavaPlugin; -import org.gradle.api.plugins.JavaPluginConvention; -import org.gradle.testfixtures.ProjectBuilder; -import org.junit.Rule; -import org.junit.rules.ExpectedException; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.Arrays; -import java.util.Properties; -import java.util.stream.Collectors; - -public class PluginPropertiesTaskTests extends GradleUnitTestCase { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - public void testPluginPropertiesTaskActionExecutesSuccessfully() throws IOException { - Project project = createProject(); - PluginPropertiesTask pluginPropertiesTask = createTask(project, "plugin-name", "plugin-description", - "PluginClassname"); - - pluginPropertiesTask.performAction(); - - PluginPropertiesExtension pluginPropertiesTaskExtension = pluginPropertiesTask.getProject().getExtensions() - .getByType(PluginPropertiesExtension.class); - - File generatedPluginDescriptorFile = new File(project.getBuildDir(), "generated-resources/plugin-descriptor.properties"); - - assertTrue(generatedPluginDescriptorFile.exists()); - - Properties generatedPluginDescriptorProps = new Properties(); - generatedPluginDescriptorProps.load(new FileInputStream(generatedPluginDescriptorFile)); - - assertEquals(pluginPropertiesTaskExtension.getName(), generatedPluginDescriptorProps.getProperty("name")); - assertEquals(pluginPropertiesTaskExtension.getDescription(), generatedPluginDescriptorProps.getProperty("description")); - assertEquals(pluginPropertiesTaskExtension.getClassname(), generatedPluginDescriptorProps.getProperty("classname")); - assertEquals(pluginPropertiesTaskExtension.getVersion(), generatedPluginDescriptorProps.getProperty("version")); - assertEquals(VersionProperties.getElasticsearch(), generatedPluginDescriptorProps.getProperty("elasticsearch.version")); - - assertEquals(pluginPropertiesTaskExtension.getExtendedPlugins().stream().collect(Collectors.joining(",")), - generatedPluginDescriptorProps.getProperty("extended.plugins")); - - assertEquals(project.getConvention().getPlugin(JavaPluginConvention.class).getTargetCompatibility().toString(), - generatedPluginDescriptorProps.getProperty("java.version")); - - assertEquals(String.valueOf(pluginPropertiesTaskExtension.hasNativeController()), - generatedPluginDescriptorProps.getProperty("has.native.controller")); - } - - public void testPluginPropertiesTaskActionThrowExceptionForMissingName() throws IOException { - Project project = createProject(); - PluginPropertiesTask pluginPropertiesTask = createTask(project, null, "plugin-description", - "PluginClassname"); - - thrown.expect(InvalidUserDataException.class); - thrown.expectMessage("name is a required setting for esplugin"); - pluginPropertiesTask.performAction(); - } - - public void testPluginPropertiesTaskActionThrowExceptionForMissingDescription() throws IOException { - Project project = createProject(); - PluginPropertiesTask pluginPropertiesTask = createTask(project, "plugin-name", null, "PluginClassname"); - - thrown.expect(InvalidUserDataException.class); - thrown.expectMessage("description is a required setting for esplugin"); - pluginPropertiesTask.performAction(); - } - - public void testPluginPropertiesTaskActionThrowExceptionForMissingClassname() throws IOException { - Project project = createProject(); - PluginPropertiesTask pluginPropertiesTask = createTask(project, "plugin-name", "plugin-description", null); - - thrown.expect(InvalidUserDataException.class); - thrown.expectMessage("classname is a required setting for esplugin"); - pluginPropertiesTask.performAction(); - } - - private Project createProject() { - Project project = ProjectBuilder.builder().build(); - project.getPlugins().apply(JavaPlugin.class); - project.getExtensions().create("esplugin", PluginPropertiesExtension.class, project); - return project; - } - - private PluginPropertiesTask createTask(Project project, String name, String description, String classname) { - PluginPropertiesTask task = project.getTasks().create("taskname", PluginPropertiesTask.class); - - PluginPropertiesExtension extension = (PluginPropertiesExtension) task.getProject().getExtensions().getByName("esplugin"); - - extension.setName(name); - extension.setDescription(description); - extension.setClassname(classname); - extension.setVersion("4.2.0"); - extension.setExtendedPlugins(Arrays.asList("plugin1", "plugin2")); - - return task; - } -} From 8a0c6e3d4e7023c9b83642d95531ef1d602206db Mon Sep 17 00:00:00 2001 From: Rafiullah Hamedy Date: Wed, 17 Apr 2019 09:38:21 -0400 Subject: [PATCH 12/13] removed apply plugin and updated hasNativeController getter name --- .../org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy | 1 - .../elasticsearch/gradle/plugin/PluginPropertiesExtension.java | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy index a2fb7c7889696..365359d084e53 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy @@ -52,7 +52,6 @@ class PluginBuildPlugin extends BuildPlugin { super.apply(project) PluginPropertiesExtension extension = project.extensions.create(PLUGIN_EXTENSION_NAME, PluginPropertiesExtension, project) - project.pluginManager.apply('elasticsearch.esplugin') configureDependencies(project) diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java b/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java index cf8673c01ab92..3bddfb195d8e9 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java @@ -102,7 +102,7 @@ public List getExtendedPlugins() { return this.extendedPlugins; } - public boolean getHasNativeController() { + public boolean isHasNativeController() { return hasNativeController; } From 441680d1fda16a4ea919e7bf83009e02d277239f Mon Sep 17 00:00:00 2001 From: Rafiullah Hamedy Date: Fri, 19 Apr 2019 20:46:33 -0400 Subject: [PATCH 13/13] set license and notice file on extensions extra properties --- .../elasticsearch/gradle/plugin/PluginBuildPlugin.groovy | 1 - .../gradle/plugin/PluginPropertiesExtension.java | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy index 365359d084e53..9d303fcb78dc0 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy @@ -52,7 +52,6 @@ class PluginBuildPlugin extends BuildPlugin { super.apply(project) PluginPropertiesExtension extension = project.extensions.create(PLUGIN_EXTENSION_NAME, PluginPropertiesExtension, project) - configureDependencies(project) // this afterEvaluate must happen before the afterEvaluate added by integTest creation, diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java b/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java index 3bddfb195d8e9..e02907bb0434d 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java @@ -131,7 +131,7 @@ public File getLicenseFile() { } public void setLicenseFile(File licenseFile) { - this.project.getExtensions().add("licenseFile", licenseFile); + this.project.getExtensions().getExtraProperties().set("licenseFile", licenseFile); this.licenseFile = licenseFile; } @@ -140,7 +140,7 @@ public File getNoticeFile() { } public void setNoticeFile(File noticeFile) { - this.project.getExtensions().add("noticeFile", noticeFile); + this.project.getExtensions().getExtraProperties().set("noticeFile", noticeFile); this.noticeFile = noticeFile; } @@ -151,4 +151,4 @@ public Project getProject() { public void setExtendedPlugins(List extendedPlugins) { this.extendedPlugins = extendedPlugins; } -} +} \ No newline at end of file