Skip to content

Split internal distribution handling into separate internal plugin (7.x backport) #60270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
/*
* 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

import org.elasticsearch.gradle.fixtures.AbstractGradleFuncTest
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.junit.Rule
import org.junit.rules.TemporaryFolder

import java.lang.management.ManagementFactory

class InternalDistributionDownloadPluginFuncTest extends AbstractGradleFuncTest {

def "plugin application fails on non internal build"() {
given:
buildFile.text = """
plugins {
id 'elasticsearch.internal-distribution-download'
}
"""

when:
def result = gradleRunner("createExtractedTestDistro").buildAndFail()

then:
assertOutputContains(result.output, "Plugin 'elasticsearch.internal-distribution-download' is not supported. " +
"Use 'elasticsearch.distribution-download' plugin instead")
}

def "resolves current version from local build"() {
given:
internalBuild()
localDistroSetup()
def distroVersion = VersionProperties.getElasticsearch()
buildFile << """
apply plugin: 'elasticsearch.internal-distribution-download'

elasticsearch_distributions {
test_distro {
version = "$distroVersion"
type = "archive"
platform = "linux"
architecture = Architecture.current();
}
}
tasks.register("createExtractedTestDistro") {
dependsOn elasticsearch_distributions.test_distro.extracted
}
"""

when:
def result = gradleRunner("createExtractedTestDistro").build()

then:
result.task(":distribution:archives:linux-tar:buildTar").outcome == TaskOutcome.SUCCESS
result.task(":extractElasticsearchLinux$distroVersion").outcome == TaskOutcome.SUCCESS
assertExtractedDistroIsCreated(distroVersion, 'current-marker.txt')
}

def "resolves bwc versions from source"() {
given:
internalBuild()
bwcMinorProjectSetup()
def distroVersion = "8.1.0"
buildFile << """
apply plugin: 'elasticsearch.internal-distribution-download'

elasticsearch_distributions {
test_distro {
version = "8.1.0"
type = "archive"
platform = "linux"
architecture = Architecture.current();
}
}
tasks.register("createExtractedTestDistro") {
dependsOn elasticsearch_distributions.test_distro.extracted
}
"""
when:
def result = gradleRunner("createExtractedTestDistro").build()
then:
result.task(":distribution:bwc:minor:buildBwcTask").outcome == TaskOutcome.SUCCESS
result.task(":extractElasticsearchLinux8.1.0").outcome == TaskOutcome.SUCCESS
assertExtractedDistroIsCreated(distroVersion,'bwc-marker.txt')
}

def "fails on resolving bwc versions with no bundled jdk"() {
given:
internalBuild()
bwcMinorProjectSetup()
def distroVersion = "8.1.0"
buildFile << """
apply plugin: 'elasticsearch.internal-distribution-download'

elasticsearch_distributions {
test_distro {
version = "8.1.0"
type = "archive"
platform = "linux"
architecture = Architecture.current();
bundledJdk = false
}
}
tasks.register("createExtractedTestDistro") {
dependsOn elasticsearch_distributions.test_distro.extracted
}
"""
when:
def result = gradleRunner("createExtractedTestDistro").buildAndFail()
then:
assertOutputContains(result.output, "Configuring a snapshot bwc distribution ('test_distro') " +
"without a bundled JDK is not supported.")
}

private File internalBuild() {
buildFile << """plugins {
id 'elasticsearch.global-build-info'
}
import org.elasticsearch.gradle.Architecture
import org.elasticsearch.gradle.info.BuildParams

BuildParams.init { it.setIsInternal(true) }

import org.elasticsearch.gradle.BwcVersions
import org.elasticsearch.gradle.Version

Version currentVersion = Version.fromString("9.0.0")
BwcVersions versions = new BwcVersions(new TreeSet<>(
Arrays.asList(Version.fromString("8.0.0"), Version.fromString("8.0.1"), Version.fromString("8.1.0"), currentVersion)),
currentVersion)

BuildParams.init { it.setBwcVersions(versions) }
"""
}


private void bwcMinorProjectSetup() {
settingsFile << """
include ':distribution:bwc:minor'
"""
def bwcSubProjectFolder = testProjectDir.newFolder("distribution", "bwc", "minor")
new File(bwcSubProjectFolder, 'bwc-marker.txt') << "bwc=minor"
new File(bwcSubProjectFolder, 'build.gradle') << """
apply plugin:'base'
configurations.create("linux-tar")
tasks.register("buildBwcTask", Tar) {
from('bwc-marker.txt')
archiveExtension = "tar.gz"
compression = Compression.GZIP
}
artifacts {
it.add("linux-tar", buildBwcTask)
}
"""
}

private void localDistroSetup() {
settingsFile << """
include ":distribution:archives:linux-tar"
"""
def bwcSubProjectFolder = testProjectDir.newFolder("distribution", "archives", "linux-tar")
new File(bwcSubProjectFolder, 'current-marker.txt') << "current"
new File(bwcSubProjectFolder, 'build.gradle') << """
apply plugin:'distribution'
tasks.register("buildTar", Tar) {
from('current-marker.txt')
archiveExtension = "tar.gz"
compression = Compression.GZIP
}
artifacts {
it.add("default", buildTar)
}
"""
buildFile << """
"""

}

boolean assertExtractedDistroIsCreated(String version, String markerFileName) {
File extractedFolder = new File(testProjectDir.root, "build/elasticsearch-distros/extracted_elasticsearch_${version}_archive_linux_default")
assert extractedFolder.exists()
assert new File(extractedFolder, markerFileName).exists()
true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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.fixtures

import org.gradle.testkit.runner.GradleRunner
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.Specification

import java.lang.management.ManagementFactory

abstract class AbstractGradleFuncTest extends Specification{

@Rule
TemporaryFolder testProjectDir = new TemporaryFolder()

File settingsFile
File buildFile

def setup() {
settingsFile = testProjectDir.newFile('settings.gradle')
settingsFile << "rootProject.name = 'hello-world'"
buildFile = testProjectDir.newFile('build.gradle')
}

GradleRunner gradleRunner(String... arguments) {
GradleRunner.create()
.withDebug(ManagementFactory.getRuntimeMXBean().getInputArguments().toString().indexOf("-agentlib:jdwp") > 0)
.withProjectDir(testProjectDir.root)
.withArguments(arguments)
.withPluginClasspath()
.forwardOutput()
}

def assertOutputContains(String givenOutput, String expected) {
assert normalizedString(givenOutput).contains(normalizedString(expected))
true
}

String normalizedString(String input) {
return input.readLines().join("\n")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,6 @@ public class DistributionDownloadPluginIT extends GradleIntegrationTestCase {

// TODO: check reuse of root task across projects MOVE TO UNIT TEST
// TODO: future: check integ-test-zip to maven, snapshots to snapshot service for external project

public void testCurrent() throws Exception {
String projectName = ":distribution:archives:linux-tar";
assertExtractedDistro(
VersionProperties.getElasticsearch(),
"archive",
"linux",
null,
null,
"tests.local_distro.config",
"default",
"tests.local_distro.project",
projectName
);
}

public void testCurrentExternal() throws Exception {
checkService(
VersionProperties.getElasticsearch(),
Expand All @@ -70,22 +54,6 @@ public void testCurrentExternal() throws Exception {
);
}

public void testBwc() throws Exception {
assertExtractedDistro(
"8.1.0",
"archive",
"linux",
null,
null,
"tests.local_distro.config",
"linux-tar",
"tests.local_distro.project",
":distribution:bwc:minor",
"tests.current_version",
"8.0.0"
);
}

public void testBwcExternal() throws Exception {
checkService(
"8.1.0-SNAPSHOT",
Expand Down
Loading