Skip to content

Commit 04df52a

Browse files
rhamedyalpar-t
authored andcommitted
Convert PluginPropertiesExtension Groovy to Java (#39605)
1 parent 4757870 commit 04df52a

File tree

3 files changed

+199
-90
lines changed

3 files changed

+199
-90
lines changed

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

Lines changed: 0 additions & 90 deletions
This file was deleted.
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.gradle.plugin;
21+
22+
import org.gradle.api.Project;
23+
24+
import java.io.File;
25+
import java.util.ArrayList;
26+
import java.util.List;
27+
28+
/**
29+
* A container for plugin properties that will be written to the plugin descriptor, for easy
30+
* manipulation in the gradle DSL.
31+
*/
32+
public class PluginPropertiesExtension {
33+
private String name;
34+
35+
private String version;
36+
37+
private String description;
38+
39+
private String classname;
40+
41+
/** Other plugins this plugin extends through SPI */
42+
private List<String> extendedPlugins = new ArrayList<>();
43+
44+
private boolean hasNativeController;
45+
46+
/** True if the plugin requires the elasticsearch keystore to exist, false otherwise. */
47+
private boolean requiresKeystore;
48+
49+
/** A license file that should be included in the built plugin zip. */
50+
private File licenseFile;
51+
52+
/**
53+
* A notice file that should be included in the built plugin zip. This will be
54+
* extended with notices from the {@code licenses/} directory.
55+
*/
56+
private File noticeFile;
57+
58+
private final Project project;
59+
60+
public PluginPropertiesExtension(Project project) {
61+
this.project = project;
62+
}
63+
64+
public String getName() {
65+
return name == null ? project.getName() : name;
66+
}
67+
68+
public void setName(String name) {
69+
this.name = name;
70+
}
71+
72+
public String getVersion() {
73+
return version == null ? project.getVersion().toString() : version;
74+
}
75+
76+
public void setVersion(String version) {
77+
this.version = version;
78+
}
79+
80+
public String getDescription() {
81+
return description;
82+
}
83+
84+
public void setDescription(String description) {
85+
this.description = description;
86+
}
87+
88+
public String getClassname() {
89+
return classname;
90+
}
91+
92+
public void setClassname(String classname) {
93+
this.classname = classname;
94+
}
95+
96+
public List<String> getExtendedPlugins() {
97+
return this.extendedPlugins;
98+
}
99+
100+
public boolean isHasNativeController() {
101+
return hasNativeController;
102+
}
103+
104+
public void setHasNativeController(boolean hasNativeController) {
105+
this.hasNativeController = hasNativeController;
106+
}
107+
108+
public boolean isRequiresKeystore() {
109+
return requiresKeystore;
110+
}
111+
112+
public void setRequiresKeystore(boolean requiresKeystore) {
113+
this.requiresKeystore = requiresKeystore;
114+
}
115+
116+
public File getLicenseFile() {
117+
return licenseFile;
118+
}
119+
120+
public void setLicenseFile(File licenseFile) {
121+
this.project.getExtensions().getExtraProperties().set("licenseFile", licenseFile);
122+
this.licenseFile = licenseFile;
123+
}
124+
125+
public File getNoticeFile() {
126+
return noticeFile;
127+
}
128+
129+
public void setNoticeFile(File noticeFile) {
130+
this.project.getExtensions().getExtraProperties().set("noticeFile", noticeFile);
131+
this.noticeFile = noticeFile;
132+
}
133+
134+
public Project getProject() {
135+
return project;
136+
}
137+
138+
public void setExtendedPlugins(List<String> extendedPlugins) {
139+
this.extendedPlugins = extendedPlugins;
140+
}
141+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.gradle.plugin;
21+
22+
import org.elasticsearch.gradle.test.GradleUnitTestCase;
23+
import org.gradle.api.Project;
24+
import org.gradle.api.plugins.JavaPlugin;
25+
import org.gradle.testfixtures.ProjectBuilder;
26+
27+
public class PluginPropertiesExtensionTests extends GradleUnitTestCase {
28+
29+
public void testCreatingPluginPropertiesExtensionWithNameAndVersion() {
30+
String projectName = "Test";
31+
String projectVersion = "5.0";
32+
33+
PluginPropertiesExtension pluginPropertiesExtension =
34+
new PluginPropertiesExtension(this.createProject(projectName, projectVersion));
35+
36+
assertEquals(projectName, pluginPropertiesExtension.getName());
37+
assertEquals(projectVersion, pluginPropertiesExtension.getVersion());
38+
}
39+
40+
public void testCreatingPluginPropertiesExtensionWithNameWithoutVersion() {
41+
String projectName = "Test";
42+
43+
PluginPropertiesExtension pluginPropertiesExtension =
44+
new PluginPropertiesExtension(this.createProject(projectName, null));
45+
46+
assertEquals(projectName, pluginPropertiesExtension.getName());
47+
assertEquals("unspecified", pluginPropertiesExtension.getVersion());
48+
}
49+
50+
private Project createProject(String projectName, String version) {
51+
Project project = ProjectBuilder.builder().withName(projectName).build();
52+
project.setVersion(version);
53+
54+
project.getPlugins().apply(JavaPlugin.class);
55+
56+
return project;
57+
}
58+
}

0 commit comments

Comments
 (0)