Skip to content

Commit 014e90d

Browse files
authored
Build: Consolidate archives and packages configuration (#28760)
This commit moves the distribution specific tasks into the respective archives and packages builds. The collocation of common and distribution specific tasks make it much easier to reason about what is expected in a particular distribution.
1 parent 3dfb4b8 commit 014e90d

37 files changed

+467
-612
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/vagrant/VagrantTestPlugin.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class VagrantTestPlugin implements Plugin<Project> {
119119
} else {
120120
it = "packages:${it}"
121121
}
122-
project.dependencies.add(BATS, project.dependencies.project(path: ":distribution:${it}", configuration: 'archives'))
122+
project.dependencies.add(BATS, project.dependencies.project(path: ":distribution:${it}", configuration: 'default'))
123123
}
124124

125125
UPGRADE_FROM_ARCHIVES.each {

distribution/archives/build.gradle

Lines changed: 156 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,70 +17,195 @@
1717
* under the License.
1818
*/
1919

20-
import org.apache.tools.ant.filters.FixCrLfFilter
2120
import org.apache.tools.ant.taskdefs.condition.Os
21+
import org.apache.tools.ant.filters.FixCrLfFilter
2222
import org.elasticsearch.gradle.BuildPlugin
2323
import org.elasticsearch.gradle.EmptyDirTask
24-
import org.elasticsearch.gradle.ConcatFilesTask
2524
import org.elasticsearch.gradle.MavenFilteringHack
26-
import org.elasticsearch.gradle.NoticeTask
27-
import org.elasticsearch.gradle.precommit.DependencyLicensesTask
28-
import org.elasticsearch.gradle.precommit.UpdateShasTask
29-
import org.elasticsearch.gradle.test.RunTask
25+
import org.elasticsearch.gradle.plugin.PluginBuildPlugin
3026

31-
subprojects {
32-
// CopySpec does not make it easy to create an empty director so we create the directory that we want, and then point CopySpec to its
33-
// parent to copy to the root of the distribution
34-
File logs = new File(buildDir, 'logs-hack/logs')
35-
task createLogDir(type: EmptyDirTask) {
36-
dir "${logs}"
37-
dirMode 0755
38-
}
39-
File plugins = new File(buildDir, 'plugins-hack/plugins')
40-
task createPluginsDir(type: EmptyDirTask) {
41-
dir "${plugins}"
42-
dirMode 0755
43-
}
44-
project.ext.archivesFiles = copySpec {
27+
// need this so Zip/Tar tasks get basic defaults...
28+
apply plugin: 'base'
29+
30+
// CopySpec does not make it easy to create an empty directory so we
31+
// create the directory that we want, and then point CopySpec to its
32+
// parent to copy to the root of the distribution
33+
ext.logsDir = new File(buildDir, 'logs-hack/logs')
34+
task createLogsDir(type: EmptyDirTask) {
35+
dir "${logsDir}"
36+
dirMode 0755
37+
}
38+
ext.pluginsDir= new File(buildDir, 'plugins-hack/plugins')
39+
task createPluginsDir(type: EmptyDirTask) {
40+
dir "${pluginsDir}"
41+
dirMode 0755
42+
}
43+
44+
CopySpec archiveFiles(CopySpec... innerFiles) {
45+
return copySpec {
4546
into("elasticsearch-${version}") {
4647
with libFiles
4748
into('config') {
4849
dirMode 0750
4950
fileMode 0660
50-
with configFiles
51+
with configFiles('def')
5152
}
5253
into('bin') {
5354
with copySpec {
54-
with binFiles
55-
from('../../src/main/resources/bin') {
55+
with binFiles('def')
56+
from('../src/bin') {
5657
include '*.bat'
5758
filter(FixCrLfFilter, eol: FixCrLfFilter.CrLf.newInstance('crlf'))
5859
}
59-
MavenFilteringHack.filter(it, expansions)
60+
MavenFilteringHack.filter(it, expansionsForDistribution('def'))
6061
}
6162
}
6263
into('') {
6364
from {
6465
dirMode 0755
65-
logs.getParent()
66+
logsDir.getParent()
6667
}
6768
}
6869
into('') {
6970
from {
7071
dirMode 0755
71-
plugins.getParent()
72+
pluginsDir.getParent()
7273
}
7374
}
7475
with commonFiles
7576
with noticeFile
76-
from('../../src/main/resources') {
77+
from('../src') {
7778
include 'bin/*.exe'
7879
}
79-
if (project.name != 'integ-test-zip') {
80-
with modulesFiles
81-
} else {
82-
with transportModulesFiles
80+
for (CopySpec files : innerFiles) {
81+
with files
8382
}
8483
}
8584
}
8685
}
86+
87+
task buildIntegTestZip(type: Zip) {
88+
dependsOn createLogsDir, createPluginsDir
89+
destinationDir = file('integ-test-zip/build/distributions')
90+
baseName = 'elasticsearch'
91+
with archiveFiles(transportModulesFiles)
92+
}
93+
94+
task buildZip(type: Zip) {
95+
dependsOn createLogsDir, createPluginsDir
96+
destinationDir = file('zip/build/distributions')
97+
baseName = 'elasticsearch'
98+
with archiveFiles(modulesFiles)
99+
}
100+
101+
task buildTar(type: Tar) {
102+
dependsOn createLogsDir, createPluginsDir
103+
destinationDir = file('tar/build/distributions')
104+
baseName = 'elasticsearch'
105+
extension = 'tar.gz'
106+
compression = Compression.GZIP
107+
dirMode 0755
108+
fileMode 0644
109+
with archiveFiles(modulesFiles)
110+
}
111+
112+
// This configures the default artifact for the distribution specific
113+
// subprojects. We have subprojects for two reasons:
114+
// 1. Gradle project substitutions can only bind to the default
115+
// configuration of a project
116+
// 2. The integ-test-zip and zip distributions have the exact same
117+
// filename, so they must be placed in different directories.
118+
subprojects {
119+
apply plugin: 'distribution'
120+
121+
archivesBaseName = 'elasticsearch'
122+
123+
String buildTask = "build${it.name.replaceAll(/-[a-z]/) { it.substring(1).toUpperCase() }.capitalize()}"
124+
ext.buildDist = parent.tasks.getByName(buildTask)
125+
artifacts {
126+
'default' buildDist
127+
}
128+
}
129+
130+
/*****************************************************************************
131+
* Rest test config *
132+
*****************************************************************************/
133+
subprojects {
134+
apply plugin: 'elasticsearch.standalone-rest-test'
135+
apply plugin: 'elasticsearch.rest-test'
136+
137+
if (project.name == 'integ-test-zip') {
138+
integTest {
139+
includePackaged true
140+
}
141+
}
142+
143+
integTestCluster {
144+
dependsOn assemble
145+
distribution = project.name
146+
}
147+
integTestRunner {
148+
if (Os.isFamily(Os.FAMILY_WINDOWS) && System.getProperty('tests.timeoutSuite') == null) {
149+
// override the suite timeout to 30 mins for windows, because it has the most inefficient filesystem known to man
150+
systemProperty 'tests.timeoutSuite', '1800000!'
151+
}
152+
}
153+
154+
processTestResources {
155+
inputs.properties(project(':distribution').restTestExpansions)
156+
MavenFilteringHack.filter(it, project(':distribution').restTestExpansions)
157+
}
158+
}
159+
160+
/*****************************************************************************
161+
* Maven config *
162+
*****************************************************************************/
163+
configure(subprojects.findAll { it.name.contains('zip') }) {
164+
// only zip distributions go to maven
165+
BuildPlugin.configurePomGeneration(project)
166+
apply plugin: 'nebula.info-scm'
167+
apply plugin: 'nebula.maven-base-publish'
168+
apply plugin: 'nebula.maven-scm'
169+
170+
// note: the group must be correct before applying the nexus plugin, or
171+
// it will capture the wrong value...
172+
project.group = "org.elasticsearch.distribution.${project.name}"
173+
174+
publishing {
175+
publications {
176+
nebula {
177+
artifactId 'elasticsearch'
178+
artifact buildDist
179+
}
180+
/*
181+
* HUGE HACK: the underlying maven publication library refuses to
182+
* deploy any attached artifacts when the packaging type is set to
183+
* 'pom'. But Sonatype's OSS repositories require source files for
184+
* artifacts that are of type 'zip'. We already publish the source
185+
* and javadoc for Elasticsearch under the various other subprojects.
186+
* So here we create another publication using the same name that
187+
* has the "real" pom, and rely on the fact that gradle will execute
188+
* the publish tasks in alphabetical order. This lets us publish the
189+
* zip file and even though the pom says the type is 'pom' instead of
190+
* 'zip'. We cannot setup a dependency between the tasks because the
191+
* publishing tasks are created *extremely* late in the configuration
192+
* phase, so that we cannot get ahold of the actual task. Furthermore,
193+
* this entire hack only exists so we can make publishing to maven
194+
* local work, since we publish to maven central externally.
195+
*/
196+
nebulaRealPom(MavenPublication) {
197+
artifactId 'elasticsearch'
198+
pom.packaging = 'pom'
199+
pom.withXml { XmlProvider xml ->
200+
Node root = xml.asNode()
201+
root.appendNode('name', 'Elasticsearch')
202+
root.appendNode('description', 'A Distributed RESTful Search Engine')
203+
root.appendNode('url', PluginBuildPlugin.urlFromOrigin(project.scminfo.origin))
204+
Node scmNode = root.appendNode('scm')
205+
scmNode.appendNode('url', project.scminfo.origin)
206+
}
207+
}
208+
}
209+
}
210+
}
211+
Lines changed: 2 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,2 @@
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-
import org.elasticsearch.gradle.plugin.PluginBuildPlugin
21-
import org.apache.tools.ant.taskdefs.condition.Os
22-
23-
task buildZip(type: Zip) {
24-
dependsOn createLogDir, createPluginsDir
25-
baseName = 'elasticsearch'
26-
with archivesFiles
27-
}
28-
29-
artifacts {
30-
'default' buildZip
31-
archives buildZip
32-
}
33-
34-
publishing {
35-
publications {
36-
nebula {
37-
artifactId 'elasticsearch'
38-
artifact buildZip
39-
}
40-
/* HUGE HACK: the underlying maven publication library refuses to deploy any attached artifacts
41-
* when the packaging type is set to 'pom'. But Sonatype's OSS repositories require source files
42-
* for artifacts that are of type 'zip'. We already publish the source and javadoc for Elasticsearch
43-
* under the various other subprojects. So here we create another publication using the same
44-
* name that has the "real" pom, and rely on the fact that gradle will execute the publish tasks
45-
* in alphabetical order. This lets us publish the zip file and even though the pom says the
46-
* type is 'pom' instead of 'zip'. We cannot setup a dependency between the tasks because the
47-
* publishing tasks are created *extremely* late in the configuration phase, so that we cannot get
48-
* ahold of the actual task. Furthermore, this entire hack only exists so we can make publishing to
49-
* maven local work, since we publish to maven central externally. */
50-
nebulaRealPom(MavenPublication) {
51-
artifactId 'elasticsearch'
52-
pom.packaging = 'pom'
53-
pom.withXml { XmlProvider xml ->
54-
Node root = xml.asNode()
55-
root.appendNode('name', 'Elasticsearch')
56-
root.appendNode('description', 'A Distributed RESTful Search Engine')
57-
root.appendNode('url', PluginBuildPlugin.urlFromOrigin(project.scminfo.origin))
58-
Node scmNode = root.appendNode('scm')
59-
scmNode.appendNode('url', project.scminfo.origin)
60-
}
61-
}
62-
}
63-
}
64-
65-
integTestRunner {
66-
if (Os.isFamily(Os.FAMILY_WINDOWS) && System.getProperty('tests.timeoutSuite') == null) {
67-
// override the suite timeout to 30 mins for windows, because it has the most inefficient filesystem known to man
68-
systemProperty 'tests.timeoutSuite', '1800000!'
69-
}
70-
}
71-
72-
integTest.dependsOn buildZip
1+
// This file is intentionally blank. All configuration of the
2+
// distribution is done in the parent project.
Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,2 @@
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-
task buildTar(type: Tar) {
21-
dependsOn createLogDir, createPluginsDir
22-
baseName = 'elasticsearch'
23-
extension = 'tar.gz'
24-
with archivesFiles
25-
compression = Compression.GZIP
26-
dirMode 0755
27-
fileMode 0644
28-
}
29-
30-
artifacts {
31-
'default' buildTar
32-
}
33-
1+
// This file is intentionally blank. All configuration of the
2+
// distribution is done in the parent project.

0 commit comments

Comments
 (0)