Build: Improve behavior and setup for attachment to elasticsearch

Currently, running any task while attached to elasticsearch will also
try to run that task in all elasticsearch projects. This change causes
x-plugins to be moved into a subproject when attached. It does this by
dynamically creating a fake root project, and making this root project
think it is attached to the existing attachments, along with x-plugins
itself.

This also fixes buildSrc so attachment to elasticsearch's buildSrc
actually works.

Original commit: elastic/x-pack-elasticsearch@da0adf1da5
This commit is contained in:
Ryan Ernst 2015-11-06 11:00:27 -08:00
parent 9fc92950c4
commit 33785e5446
6 changed files with 74 additions and 50 deletions

View File

@ -1,21 +1,5 @@
import org.elasticsearch.gradle.ElasticsearchProperties import org.elasticsearch.gradle.ElasticsearchProperties
buildscript {
repositories {
mavenCentral()
maven {
name 'sonatype-snapshots'
url 'http://oss.sonatype.org/content/repositories/snapshots/'
}
jcenter()
}
dependencies {
classpath 'org.elasticsearch.gradle:build-tools:3.0.0-SNAPSHOT'
classpath 'org.elasticsearch.gradle:project-attachment-plugin:1.0.0-SNAPSHOT'
}
}
apply plugin: 'elasticsearch.project-attachment'
allprojects { allprojects {
apply plugin: 'idea' apply plugin: 'idea'
apply plugin: 'eclipse' apply plugin: 'eclipse'
@ -41,6 +25,7 @@ subprojects {
} }
} }
<repository> <repository>
<id>elasticsearch-releases</id> <id>elasticsearch-releases</id>
<url>http://maven.elasticsearch.org/releases</url> <url>http://maven.elasticsearch.org/releases</url>
@ -84,7 +69,6 @@ subprojects {
// ================= Local Elasticsearch attachment =============== // ================= Local Elasticsearch attachment ===============
if ('elasticsearch' in attachments) { if ('elasticsearch' in attachments) {
subprojects { subprojects {
it.ext.projectsPrefix = ':elasticsearch'
configurations { configurations {
all { all {
resolutionStrategy { resolutionStrategy {
@ -93,6 +77,7 @@ if ('elasticsearch' in attachments) {
substitute module("org.elasticsearch:elasticsearch:${version}") with project(":elasticsearch:core") substitute module("org.elasticsearch:elasticsearch:${version}") with project(":elasticsearch:core")
substitute module("org.elasticsearch:test-framework:${version}") with project(":elasticsearch:test-framework") substitute module("org.elasticsearch:test-framework:${version}") with project(":elasticsearch:test-framework")
substitute module("org.elasticsearch.distribution.zip:elasticsearch:${version}") with project(":elasticsearch:distribution:zip") substitute module("org.elasticsearch.distribution.zip:elasticsearch:${version}") with project(":elasticsearch:distribution:zip")
substitute module("org.elasticsearch.distribution.tar:elasticsearch:${version}") with project(":elasticsearch:distribution:tar")
} }
} }
} }

View File

@ -22,9 +22,20 @@ repositories {
jcenter() jcenter()
} }
subprojects { dependencies {
rootProject.dependencies { runtime 'org.elasticsearch.gradle:project-attachment-plugin:1.0.0-SNAPSHOT'
runtime project(path) runtime 'org.elasticsearch.gradle:build-tools:3.0.0-SNAPSHOT'
} }
if ('elasticsearch' in attachments) {
configurations {
all {
resolutionStrategy {
dependencySubstitution {
substitute module('org.elasticsearch.gradle:build-tools') with project(':elasticsearch')
}
}
}
}
} }

View File

@ -12,10 +12,12 @@ configurations {
licensePluginZip licensePluginZip
} }
print "MARVEL: ${dependencies}"
dependencies { dependencies {
licensePluginZip project(path: ':license:plugin') // zip licensePluginZip project(path: "${projectsPrefix}:license:plugin") // zip
provided project(path: ':license:plugin', configuration: 'runtime') provided project(path: "${projectsPrefix}:license:plugin", configuration: 'runtime')
provided project(path: ':shield', configuration: 'runtime') provided project(path: "${projectsPrefix}:shield", configuration: 'runtime')
testCompile 'org.elasticsearch:securemock:1.1' testCompile 'org.elasticsearch:securemock:1.1'
testCompile 'com.squareup.okhttp:mockwebserver:2.3.0' testCompile 'com.squareup.okhttp:mockwebserver:2.3.0'
} }

View File

@ -1,25 +1,51 @@
rootProject.name = 'x-plugins' rootProject.name = 'x-plugins'
buildscript {
repositories {
maven {
name 'sonatype-snapshots'
url 'http://oss.sonatype.org/content/repositories/snapshots/'
}
}
dependencies {
classpath 'org.elasticsearch.gradle:project-attachment-plugin:1.0.0-SNAPSHOT'
}
}
apply plugin: 'elasticsearch.project-settings-attachment' apply plugin: 'elasticsearch.project-settings-attachment'
include 'license:core2' String prefix = ''
project(':license:core2').projectDir = new File(project(':license').projectDir, 'core') if (rootProject.children.isEmpty() == false) {
// we are attached to another project, make a fake root
rootProject.name = 'x-plugins and attachments'
rootProject.projectDir = new File(settingsDir, 'build/fake-root')
if (rootProject.projectDir.exists()) {
rootProject.projectDir.delete()
}
rootProject.projectDir.mkdirs()
// the fake root's build file just needs to know about attachments
File rootBuild = new File(rootProject.projectDir, 'build.gradle')
rootBuild.setText('apply plugin: "elasticsearch.project-attachment"', 'UTF-8')
String attachPrefix = org.elasticsearch.gradle.attachment.ProjectAttachmentPlugin.ATTACHMENT_PREFIX
settingsDir.eachFile { file ->
if (file.getName().startsWith(org.elasticsearch.gradle.attachment.ProjectAttachmentPlugin.ATTACHMENT_PREFIX)) {
new File(rootProject.projectDir, file.getName()).setText(file.getText('UTF-8'), 'UTF-8')
}
}
// add x-plugins as an attachment
File xpluginsAttachment = new File(rootProject.projectDir, "${attachPrefix}x-plugins")
xpluginsAttachment.setText(settingsDir.getPath(), 'UTF-8')
// and add x-plugins root project
prefix = 'x-plugins:'
include 'x-plugins'
project(':x-plugins').projectDir = settingsDir
}
String[] projects = [
'license:core2',
'license:licensor',
'license:plugin-api',
'license:plugin',
'license:found-plugin',
'shield',
'watcher',
'marvel'
]
if (prefix.isEmpty() == false) {
projects = projects.collect { "${prefix}${it}" }
}
include projects
project(":${prefix}license:core2").projectDir = new File(project(":${prefix}license").projectDir, 'core')
include 'license:licensor'
include 'license:plugin-api'
include 'license:plugin'
include 'license:found-plugin'
include 'shield'
include 'watcher'
include 'marvel'

View File

@ -10,9 +10,9 @@ configurations {
} }
dependencies { dependencies {
licensePluginZip project(path: ':license:plugin') // zip licensePluginZip project(path: "${projectsPrefix}:license:plugin") // zip
provided project(path: ':license:plugin', configuration: 'runtime') provided project(path: "${projectsPrefix}:license:plugin", configuration: 'runtime')
compile project(':license:plugin-api') compile project("${projectsPrefix}:license:plugin-api")
compile 'dk.brics.automaton:automaton:1.11-8' compile 'dk.brics.automaton:automaton:1.11-8'
compile 'com.unboundid:unboundid-ldapsdk:2.3.8' compile 'com.unboundid:unboundid-ldapsdk:2.3.8'
testCompile "org.elasticsearch:test-framework:${version}" testCompile "org.elasticsearch:test-framework:${version}"

View File

@ -12,9 +12,9 @@ configurations {
} }
dependencies { dependencies {
licensePluginZip project(path: ':license:plugin') // zip licensePluginZip project(path: "${projectsPrefix}:license:plugin") // zip
provided project(path: ':license:plugin', configuration: 'runtime') provided project(path: "${projectsPrefix}:license:plugin", configuration: 'runtime')
provided project(path: ':shield', configuration: 'runtime') provided project(path: "${projectsPrefix}:shield", configuration: 'runtime')
compile 'com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:r239' compile 'com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:r239'
compile 'com.sun.mail:javax.mail:1.5.3' compile 'com.sun.mail:javax.mail:1.5.3'