Skip to content

Commit bb1e42d

Browse files
committed
Merge remote-tracking branch 'es/6.x' into ccr-6.x
* es/6.x: Fix link to parent join (#28085) Introduce Gradle wrapper Ignore GIT_COMMIT when calculating commit hash Plugins: Add plugin extension capabilities (#27881)
2 parents 564eee0 + c750fdc commit bb1e42d

File tree

43 files changed

+1269
-151
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1269
-151
lines changed

.gitignore

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ nbactions.xml
2020
.gradle/
2121
build/
2222

23-
# gradle wrapper
24-
/gradle/
25-
gradlew
26-
gradlew.bat
27-
2823
# maven stuff (to be removed when trunk becomes 4.x)
2924
*-execution-hints.log
3025
target/

CONTRIBUTING.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,8 @@ Contributing to the Elasticsearch codebase
9292

9393
**Repository:** [https://github.com/elastic/elasticsearch](https://github.com/elastic/elasticsearch)
9494

95-
Make sure you have [Gradle](http://gradle.org) installed, as
96-
Elasticsearch uses it as its build system. Gradle must be at least
97-
version 4.3 in order to build successfully.
95+
Elasticsearch uses the Gradle wrapper for its build. You can execute Gradle
96+
using the wrapper via the `gradlew` script in the root of the repository.
9897

9998
Eclipse users can automatically configure their IDE: `gradle eclipse`
10099
then `File: Import: Existing Projects into Workspace`. Select the

build.gradle

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ import org.elasticsearch.gradle.VersionCollection
2525
import org.elasticsearch.gradle.VersionProperties
2626
import org.gradle.plugins.ide.eclipse.model.SourceFolder
2727

28+
import org.gradle.api.tasks.wrapper.Wrapper
29+
import org.gradle.api.tasks.wrapper.Wrapper.DistributionType
30+
import org.gradle.util.GradleVersion
31+
import org.gradle.util.DistributionLocator
32+
2833
import java.nio.file.Path
34+
import java.security.MessageDigest
2935

3036
// common maven publishing configuration
3137
subprojects {
@@ -401,6 +407,27 @@ task run(type: Run) {
401407
impliesSubProjects = true
402408
}
403409

410+
task wrapper(type: Wrapper)
411+
412+
gradle.projectsEvaluated {
413+
414+
allprojects {
415+
tasks.withType(Wrapper) { Wrapper wrapper ->
416+
wrapper.distributionType = DistributionType.ALL
417+
418+
wrapper.doLast {
419+
final DistributionLocator locator = new DistributionLocator()
420+
final GradleVersion version = GradleVersion.version(wrapper.gradleVersion)
421+
final URI distributionUri = locator.getDistributionFor(version, wrapper.distributionType.name().toLowerCase(Locale.ENGLISH))
422+
final URI sha256Uri = new URI(distributionUri.toString() + ".sha256")
423+
final String sha256Sum = new String(sha256Uri.toURL().bytes)
424+
wrapper.getPropertiesFile() << "distributionSha256Sum=${sha256Sum}\n"
425+
}
426+
}
427+
}
428+
429+
}
430+
404431
/* Remove assemble on all qa projects because we don't need to publish
405432
* artifacts for them. */
406433
gradle.projectsEvaluated {

buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ package org.elasticsearch.gradle
2121
import com.carrotsearch.gradle.junit4.RandomizedTestingTask
2222
import nebula.plugin.extraconfigurations.ProvidedBasePlugin
2323
import org.apache.tools.ant.taskdefs.condition.Os
24+
import org.eclipse.jgit.lib.Constants
25+
import org.eclipse.jgit.lib.RepositoryBuilder
2426
import org.elasticsearch.gradle.precommit.PrecommitTasks
2527
import org.gradle.api.GradleException
2628
import org.gradle.api.InvalidUserDataException
@@ -35,7 +37,6 @@ import org.gradle.api.artifacts.ModuleVersionIdentifier
3537
import org.gradle.api.artifacts.ProjectDependency
3638
import org.gradle.api.artifacts.ResolvedArtifact
3739
import org.gradle.api.artifacts.dsl.RepositoryHandler
38-
import org.gradle.api.file.CopySpec
3940
import org.gradle.api.plugins.JavaPlugin
4041
import org.gradle.api.publish.maven.MavenPublication
4142
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin
@@ -509,6 +510,17 @@ class BuildPlugin implements Plugin<Project> {
509510
if (jarTask.manifest.attributes.containsKey('Change') == false) {
510511
logger.warn('Building without git revision id.')
511512
jarTask.manifest.attributes('Change': 'Unknown')
513+
} else {
514+
/*
515+
* The info-scm plugin assumes that if GIT_COMMIT is set it was set by Jenkins to the commit hash for this build.
516+
* However, that assumption is wrong as this build could be a sub-build of another Jenkins build for which GIT_COMMIT
517+
* is the commit hash for that build. Therefore, if GIT_COMMIT is set we calculate the commit hash ourselves.
518+
*/
519+
if (System.getenv("GIT_COMMIT") != null) {
520+
final String hash = new RepositoryBuilder().findGitDir(project.buildDir).build().resolve(Constants.HEAD).name
521+
final String shortHash = hash?.substring(0, 7)
522+
jarTask.manifest.attributes('Change': shortHash)
523+
}
512524
}
513525
}
514526
// add license/notice files

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ class PluginPropertiesExtension {
3939
@Input
4040
String classname
4141

42+
/** Other plugins this plugin extends through SPI */
43+
@Input
44+
List<String> extendedPlugins = []
45+
4246
@Input
4347
boolean hasNativeController = false
4448

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class PluginPropertiesTask extends Copy {
8080
'elasticsearchVersion': stringSnap(VersionProperties.elasticsearch),
8181
'javaVersion': project.targetCompatibility as String,
8282
'classname': extension.classname,
83+
'extendedPlugins': extension.extendedPlugins.join(','),
8384
'hasNativeController': extension.hasNativeController,
8485
'requiresKeystore': extension.requiresKeystore
8586
]

buildSrc/src/main/resources/plugin-descriptor.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ java.version=${javaVersion}
4040
elasticsearch.version=${elasticsearchVersion}
4141
### optional elements for plugins:
4242
#
43+
# 'extended.plugins': other plugins this plugin extends through SPI
44+
extended.plugins=${extendedPlugins}
45+
#
4346
# 'has.native.controller': whether or not the plugin has a native controller
4447
has.native.controller=${hasNativeController}
4548
#

core/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ archivesBaseName = 'elasticsearch'
3838

3939
dependencies {
4040

41+
compileOnly project(':libs:plugin-classloader')
42+
testRuntime project(':libs:plugin-classloader')
43+
4144
// lucene
4245
compile "org.apache.lucene:lucene-core:${versions.lucene}"
4346
compile "org.apache.lucene:lucene-analyzers-common:${versions.lucene}"

core/src/main/java/org/elasticsearch/bootstrap/ESPolicy.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.security.ProtectionDomain;
3434
import java.util.Collections;
3535
import java.util.Map;
36+
import java.util.Set;
3637
import java.util.function.Predicate;
3738

3839
/** custom policy for union of static and dynamic permissions */
@@ -49,9 +50,9 @@ final class ESPolicy extends Policy {
4950
final PermissionCollection dynamic;
5051
final Map<String,Policy> plugins;
5152

52-
ESPolicy(PermissionCollection dynamic, Map<String,Policy> plugins, boolean filterBadDefaults) {
53-
this.template = Security.readPolicy(getClass().getResource(POLICY_RESOURCE), JarHell.parseClassPath());
54-
this.untrusted = Security.readPolicy(getClass().getResource(UNTRUSTED_RESOURCE), Collections.emptySet());
53+
ESPolicy(Map<String, URL> codebases, PermissionCollection dynamic, Map<String,Policy> plugins, boolean filterBadDefaults) {
54+
this.template = Security.readPolicy(getClass().getResource(POLICY_RESOURCE), codebases);
55+
this.untrusted = Security.readPolicy(getClass().getResource(UNTRUSTED_RESOURCE), Collections.emptyMap());
5556
if (filterBadDefaults) {
5657
this.system = new SystemPolicy(Policy.getPolicy());
5758
} else {

core/src/main/java/org/elasticsearch/bootstrap/Security.java

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,13 @@
4848
import java.util.Collections;
4949
import java.util.HashMap;
5050
import java.util.HashSet;
51+
import java.util.LinkedHashMap;
5152
import java.util.LinkedHashSet;
5253
import java.util.List;
5354
import java.util.Map;
5455
import java.util.Set;
56+
import java.util.function.Function;
57+
import java.util.stream.Collectors;
5558

5659
import static org.elasticsearch.bootstrap.FilePermissionUtils.addDirectoryPath;
5760
import static org.elasticsearch.bootstrap.FilePermissionUtils.addSingleFilePath;
@@ -116,7 +119,8 @@ private Security() {}
116119
static void configure(Environment environment, boolean filterBadDefaults) throws IOException, NoSuchAlgorithmException {
117120

118121
// enable security policy: union of template and environment-based paths, and possibly plugin permissions
119-
Policy.setPolicy(new ESPolicy(createPermissions(environment), getPluginPermissions(environment), filterBadDefaults));
122+
Map<String, URL> codebases = getCodebaseJarMap(JarHell.parseClassPath());
123+
Policy.setPolicy(new ESPolicy(codebases, createPermissions(environment), getPluginPermissions(environment), filterBadDefaults));
120124

121125
// enable security manager
122126
final String[] classesThatCanExit =
@@ -130,6 +134,27 @@ static void configure(Environment environment, boolean filterBadDefaults) throws
130134
selfTest();
131135
}
132136

137+
/**
138+
* Return a map from codebase name to codebase url of jar codebases used by ES core.
139+
*/
140+
@SuppressForbidden(reason = "find URL path")
141+
static Map<String, URL> getCodebaseJarMap(Set<URL> urls) {
142+
Map<String, URL> codebases = new LinkedHashMap<>(); // maintain order
143+
for (URL url : urls) {
144+
try {
145+
String fileName = PathUtils.get(url.toURI()).getFileName().toString();
146+
if (fileName.endsWith(".jar") == false) {
147+
// tests :(
148+
continue;
149+
}
150+
codebases.put(fileName, url);
151+
} catch (URISyntaxException e) {
152+
throw new RuntimeException(e);
153+
}
154+
}
155+
return codebases;
156+
}
157+
133158
/**
134159
* Sets properties (codebase URLs) for policy files.
135160
* we look for matching plugins and set URLs to fit
@@ -174,7 +199,7 @@ static Map<String,Policy> getPluginPermissions(Environment environment) throws I
174199
}
175200

176201
// parse the plugin's policy file into a set of permissions
177-
Policy policy = readPolicy(policyFile.toUri().toURL(), codebases);
202+
Policy policy = readPolicy(policyFile.toUri().toURL(), getCodebaseJarMap(codebases));
178203

179204
// consult this policy for each of the plugin's jars:
180205
for (URL url : codebases) {
@@ -197,21 +222,20 @@ static Map<String,Policy> getPluginPermissions(Environment environment) throws I
197222
* would map to full URL.
198223
*/
199224
@SuppressForbidden(reason = "accesses fully qualified URLs to configure security")
200-
static Policy readPolicy(URL policyFile, Set<URL> codebases) {
225+
static Policy readPolicy(URL policyFile, Map<String, URL> codebases) {
201226
try {
202227
List<String> propertiesSet = new ArrayList<>();
203228
try {
204229
// set codebase properties
205-
for (URL url : codebases) {
206-
String fileName = PathUtils.get(url.toURI()).getFileName().toString();
207-
if (fileName.endsWith(".jar") == false) {
208-
continue; // tests :(
209-
}
230+
for (Map.Entry<String,URL> codebase : codebases.entrySet()) {
231+
String name = codebase.getKey();
232+
URL url = codebase.getValue();
233+
210234
// We attempt to use a versionless identifier for each codebase. This assumes a specific version
211235
// format in the jar filename. While we cannot ensure all jars in all plugins use this format, nonconformity
212236
// only means policy grants would need to include the entire jar filename as they always have before.
213-
String property = "codebase." + fileName;
214-
String aliasProperty = "codebase." + fileName.replaceFirst("-\\d+\\.\\d+.*\\.jar", "");
237+
String property = "codebase." + name;
238+
String aliasProperty = "codebase." + name.replaceFirst("-\\d+\\.\\d+.*\\.jar", "");
215239
if (aliasProperty.equals(property) == false) {
216240
propertiesSet.add(aliasProperty);
217241
String previous = System.setProperty(aliasProperty, url.toString());

0 commit comments

Comments
 (0)