2016-09-16 12:30:45 -04:00
|
|
|
description = 'Builds the Prelert Engine native binaries and Java classes'
|
|
|
|
|
2016-09-19 09:08:35 -04:00
|
|
|
import org.gradle.internal.os.OperatingSystem
|
2016-10-31 09:05:32 -04:00
|
|
|
import org.gradle.plugins.ide.eclipse.model.SourceFolder
|
2016-11-17 09:07:20 -05:00
|
|
|
import org.elasticsearch.gradle.precommit.LicenseHeadersTask
|
2016-11-22 03:29:13 -05:00
|
|
|
import org.elasticsearch.gradle.VersionProperties
|
2016-12-01 10:48:51 -05:00
|
|
|
import org.elastic.gradle.UploadS3Task
|
2016-11-17 09:07:20 -05:00
|
|
|
|
2016-12-08 04:34:05 -05:00
|
|
|
String envAwsAccessKey = System.env.AWS_ACCESS_KEY_ID
|
2016-12-08 08:05:29 -05:00
|
|
|
print 'BUILD - System.env.AWS_ACCESS_KEY_ID: ' + envAwsAccessKey + '\n'
|
2016-12-05 08:58:18 -05:00
|
|
|
if (envAwsAccessKey != null) {
|
2016-12-08 08:05:29 -05:00
|
|
|
print 'using access key from System.env.AWS_ACCESS_KEY_ID: ' + envAwsAccessKey + '\n'
|
2016-12-05 08:58:18 -05:00
|
|
|
project.ext.awsAccessKey = envAwsAccessKey
|
2016-12-08 04:34:05 -05:00
|
|
|
} else if (project.hasProperty("AWS_ACCESS_KEY_ID")) {
|
2016-12-08 08:05:29 -05:00
|
|
|
print 'using access key from gradle.properties: ' + AWS_ACCESS_KEY_ID + '\n'
|
2016-12-08 04:34:05 -05:00
|
|
|
project.ext.awsAccessKey = AWS_ACCESS_KEY_ID
|
2016-12-01 11:18:29 -05:00
|
|
|
}
|
|
|
|
|
2016-12-08 04:34:05 -05:00
|
|
|
String envAwsSecretKey = System.env.AWS_SECRET_ACCESS_KEY
|
2016-12-08 08:05:29 -05:00
|
|
|
print 'BUILD - System.env.AWS_SECRET_ACCESS_KEY: ' + envAwsSecretKey + '\n'
|
2016-12-05 08:58:18 -05:00
|
|
|
if (envAwsSecretKey != null) {
|
2016-12-08 08:05:29 -05:00
|
|
|
print 'using access key from System.env.AWS_SECRET_ACCESS_KEY: ' + envAwsSecretKey + '\n'
|
2016-12-05 08:58:18 -05:00
|
|
|
project.ext.awsSecretKey = envAwsSecretKey
|
2016-12-08 04:34:05 -05:00
|
|
|
} else if (project.hasProperty("AWS_SECRET_ACCESS_KEY")) {
|
2016-12-08 08:05:29 -05:00
|
|
|
print 'using secret key from gradle.properties: ' + AWS_SECRET_ACCESS_KEY + '\n'
|
2016-12-08 04:34:05 -05:00
|
|
|
project.ext.awsSecretKey = AWS_SECRET_ACCESS_KEY
|
2016-12-01 11:18:29 -05:00
|
|
|
}
|
|
|
|
|
2016-12-02 07:18:51 -05:00
|
|
|
project.ext.isWindows = OperatingSystem.current().isWindows()
|
|
|
|
project.ext.isLinux = OperatingSystem.current().isLinux()
|
|
|
|
project.ext.isMacOsX = OperatingSystem.current().isMacOsX()
|
2016-11-23 06:22:04 -05:00
|
|
|
|
2016-12-02 07:18:51 -05:00
|
|
|
project.ext.bash = project.isWindows ? "C:\\Program Files\\Git\\bin\\bash" : "/bin/bash"
|
2016-11-23 06:22:04 -05:00
|
|
|
|
2016-12-01 10:48:51 -05:00
|
|
|
String uploadEnabledStr = properties.get('upload', 'false')
|
|
|
|
if (['true', 'false'].contains(uploadEnabledStr) == false) {
|
|
|
|
throw new GradleException("upload must be true or false, got ${uploadEnabledStr}")
|
|
|
|
}
|
|
|
|
project.ext.uploadEnabled = uploadEnabledStr == 'true'
|
|
|
|
|
2016-12-01 07:16:06 -05:00
|
|
|
// C++ build can be explicitly enabled or disabled, or if neither is chosen
|
|
|
|
// it will be enabled if the necessary 3rd party dependencies are present
|
|
|
|
String cppEnabledStr = properties.get('xpack.cpp.build', 'auto')
|
|
|
|
if (['true', 'false', 'auto'].contains(cppEnabledStr) == false) {
|
|
|
|
throw new GradleException("xpack.cpp.build must be true or false, got ${cppEnabledStr}")
|
|
|
|
}
|
|
|
|
project.ext.cppEnabled = cppEnabledStr == 'true'
|
|
|
|
if (cppEnabledStr == 'auto') {
|
|
|
|
// Disable the C++ build if the 3rd party tools/libraries aren't available
|
|
|
|
String[] cmdArray = [ project.ext.bash, '-c', 'source cpp/set_env.sh && 3rd_party/3rd_party.sh --check' ]
|
|
|
|
Process checkProcess = Runtime.getRuntime().exec(cmdArray, null, rootDir)
|
|
|
|
StringBuffer checkOutput = new StringBuffer()
|
|
|
|
checkProcess.consumeProcessOutputStream(checkOutput)
|
|
|
|
if (checkProcess.waitFor() == 0) {
|
|
|
|
project.ext.cppEnabled = true
|
|
|
|
} else {
|
|
|
|
println 'C++ dependencies not available - disabling C++ build'
|
|
|
|
println checkOutput
|
|
|
|
project.ext.cppEnabled = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-02 08:12:57 -05:00
|
|
|
allprojects {
|
|
|
|
group = 'org.elasticsearch.prelert'
|
2016-12-02 10:17:40 -05:00
|
|
|
version = VersionProperties.elasticsearch
|
2016-12-02 08:12:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
String packArtifactName = 'prelert'
|
|
|
|
|
2016-11-18 03:34:18 -05:00
|
|
|
configurations.all {
|
|
|
|
// check for updates every build
|
|
|
|
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
|
|
|
|
}
|
|
|
|
|
2016-11-17 09:07:20 -05:00
|
|
|
buildscript {
|
|
|
|
repositories {
|
|
|
|
if (System.getProperty("repos.mavenlocal") != null) {
|
|
|
|
// with -Drepos.mavenlocal=true we can force checking the local .m2 repo which is useful for building against
|
|
|
|
// elasticsearch snapshots
|
|
|
|
mavenLocal()
|
|
|
|
}
|
|
|
|
mavenCentral()
|
|
|
|
maven {
|
|
|
|
name 'sonatype-snapshots'
|
|
|
|
url "https://oss.sonatype.org/content/repositories/snapshots/"
|
|
|
|
}
|
|
|
|
jcenter()
|
|
|
|
}
|
|
|
|
dependencies {
|
2016-11-18 03:34:18 -05:00
|
|
|
classpath group: 'org.elasticsearch.gradle', name: 'build-tools', version: "${elasticsearchVersion}", changing: true
|
2016-11-17 09:07:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
subprojects {
|
|
|
|
// we must not publish to sonatype until we have set up x-plugins to only publish the parts we want to publish!
|
|
|
|
project.afterEvaluate {
|
|
|
|
if (project.plugins.hasPlugin('com.bmuschko.nexus') && project.nexus.repositoryUrl.startsWith('file://') == false) {
|
|
|
|
uploadArchives.enabled = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-16 12:30:45 -04:00
|
|
|
|
2016-11-22 03:29:13 -05:00
|
|
|
task bundlePack(type: Zip) {
|
2016-12-01 10:48:51 -05:00
|
|
|
onlyIf { project('kibana').bundlePlugin.enabled }
|
2016-11-22 03:29:13 -05:00
|
|
|
dependsOn 'elasticsearch:bundlePlugin'
|
|
|
|
dependsOn 'kibana:bundlePlugin'
|
|
|
|
from { zipTree(project('elasticsearch').bundlePlugin.outputs.files.singleFile) }
|
|
|
|
from { zipTree(project('kibana').bundlePlugin.outputs.files.singleFile) }
|
|
|
|
destinationDir file('build/distributions')
|
2016-12-02 08:12:57 -05:00
|
|
|
baseName = packArtifactName
|
2016-12-02 10:17:40 -05:00
|
|
|
version = project.version
|
2016-11-22 03:29:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
task assemble(dependsOn: bundlePack) {
|
|
|
|
group = 'Build'
|
|
|
|
description = 'Assembles the outputs of this project.'
|
|
|
|
}
|
|
|
|
|
2016-12-01 10:48:51 -05:00
|
|
|
task test(dependsOn: [':elasticsearch:test', ':cpp:test', ':kibana:test']) {
|
|
|
|
group = 'Build'
|
|
|
|
description = 'Assembles and tests this project.'
|
|
|
|
}
|
|
|
|
|
|
|
|
task build(dependsOn: [assemble, test]) {
|
2016-11-22 03:29:13 -05:00
|
|
|
group = 'Build'
|
|
|
|
description = 'Assembles and tests this project.'
|
|
|
|
}
|
|
|
|
|
|
|
|
task clean(type: Delete) {
|
|
|
|
group = 'Build'
|
|
|
|
description = 'Deletes the build directory'
|
|
|
|
delete 'build'
|
|
|
|
}
|
|
|
|
|
2016-12-01 10:48:51 -05:00
|
|
|
task uploadPackToS3(type: UploadS3Task, dependsOn: [build]) {
|
|
|
|
enabled project.uploadEnabled
|
|
|
|
description = 'upload pack zip to S3 Bucket'
|
|
|
|
bucket 'prelert-artifacts'
|
2016-12-02 10:17:40 -05:00
|
|
|
upload bundlePack.outputs.files.singleFile, "maven/${project.group}/${packArtifactName}/${project.version}/${bundlePack.outputs.files.singleFile.name}"
|
2016-12-01 10:48:51 -05:00
|
|
|
}
|
2016-11-17 14:34:39 -05:00
|
|
|
|
2016-12-01 10:48:51 -05:00
|
|
|
task deploy(dependsOn: [uploadPackToS3, ':cpp:upload']) {
|
2016-09-16 12:30:45 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
subprojects {
|
2016-11-07 04:27:22 -05:00
|
|
|
apply plugin: 'eclipse'
|
|
|
|
apply plugin: 'idea'
|
2016-11-22 03:29:13 -05:00
|
|
|
|
2016-11-07 04:27:22 -05:00
|
|
|
buildscript {
|
|
|
|
repositories {
|
|
|
|
if (System.getProperty("repos.mavenlocal") != null) {
|
|
|
|
// with -Drepos.mavenlocal=true we can force checking the local .m2 repo which is useful for building against
|
|
|
|
// elasticsearch snapshots
|
|
|
|
mavenLocal()
|
|
|
|
}
|
|
|
|
mavenCentral()
|
|
|
|
maven {
|
|
|
|
name 'sonatype-snapshots'
|
|
|
|
url "https://oss.sonatype.org/content/repositories/snapshots/"
|
|
|
|
}
|
|
|
|
jcenter()
|
|
|
|
}
|
|
|
|
}
|
2016-09-16 12:30:45 -04:00
|
|
|
|
|
|
|
repositories {
|
2016-11-07 04:27:22 -05:00
|
|
|
if (System.getProperty("repos.mavenlocal") != null) {
|
|
|
|
// with -Drepos.mavenlocal=true we can force checking the local .m2 repo which is useful for building against
|
|
|
|
// elasticsearch snapshots
|
|
|
|
mavenLocal()
|
|
|
|
}
|
|
|
|
mavenCentral()
|
|
|
|
maven {
|
|
|
|
name 'sonatype-snapshots'
|
|
|
|
url "https://oss.sonatype.org/content/repositories/snapshots/"
|
|
|
|
}
|
|
|
|
jcenter()
|
2016-09-16 12:30:45 -04:00
|
|
|
}
|
|
|
|
|
2016-11-17 09:07:20 -05:00
|
|
|
tasks.withType(LicenseHeadersTask.class) {
|
|
|
|
approvedLicenses = ['Elasticsearch Confidential']
|
|
|
|
additionalLicense 'ESCON', 'Elasticsearch Confidential', 'ELASTICSEARCH CONFIDENTIAL'
|
2016-09-16 12:30:45 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-31 09:05:32 -04:00
|
|
|
allprojects {
|
|
|
|
// injecting groovy property variables into all projects
|
|
|
|
project.ext {
|
|
|
|
// for ide hacks...
|
|
|
|
isEclipse = System.getProperty("eclipse.launcher") != null || gradle.startParameter.taskNames.contains('eclipse') || gradle.startParameter.taskNames.contains('cleanEclipse')
|
|
|
|
isIdea = System.getProperty("idea.active") != null || gradle.startParameter.taskNames.contains('idea') || gradle.startParameter.taskNames.contains('cleanIdea')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-17 08:12:26 -05:00
|
|
|
// intellij configuration
|
2016-10-31 09:05:32 -04:00
|
|
|
allprojects {
|
|
|
|
apply plugin: 'idea'
|
|
|
|
|
|
|
|
if (isIdea) {
|
|
|
|
project.buildDir = file('build-idea')
|
|
|
|
}
|
|
|
|
idea {
|
|
|
|
module {
|
|
|
|
inheritOutputDirs = false
|
|
|
|
outputDir = file('build-idea/classes/main')
|
|
|
|
testOutputDir = file('build-idea/classes/test')
|
|
|
|
|
|
|
|
// also ignore other possible build dirs
|
|
|
|
excludeDirs += file('build')
|
|
|
|
excludeDirs += file('build-eclipse')
|
|
|
|
|
|
|
|
iml {
|
|
|
|
// fix so that Gradle idea plugin properly generates support for resource folders
|
|
|
|
// see also https://issues.gradle.org/browse/GRADLE-2975
|
|
|
|
withXml {
|
|
|
|
it.asNode().component.content.sourceFolder.findAll { it.@url == 'file://$MODULE_DIR$/src/main/resources' }.each {
|
|
|
|
it.attributes().remove('isTestSource')
|
|
|
|
it.attributes().put('type', 'java-resource')
|
|
|
|
}
|
|
|
|
it.asNode().component.content.sourceFolder.findAll { it.@url == 'file://$MODULE_DIR$/src/test/resources' }.each {
|
|
|
|
it.attributes().remove('isTestSource')
|
|
|
|
it.attributes().put('type', 'java-test-resource')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure gradle idea was run before running anything in intellij (including import).
|
|
|
|
File ideaMarker = new File(projectDir, '.local-idea-is-configured')
|
|
|
|
tasks.idea.doLast {
|
|
|
|
ideaMarker.setText('', 'UTF-8')
|
|
|
|
}
|
|
|
|
if (System.getProperty('idea.active') != null && ideaMarker.exists() == false) {
|
|
|
|
throw new GradleException('You must run gradle idea from the root of elasticsearch before importing into IntelliJ')
|
|
|
|
}
|
|
|
|
|
|
|
|
// eclipse configuration
|
|
|
|
allprojects {
|
|
|
|
apply plugin: 'eclipse'
|
|
|
|
// Name all the non-root projects after their path so that paths get grouped together when imported into eclipse.
|
|
|
|
if (path != ':') {
|
|
|
|
eclipse.project.name = path
|
2016-11-17 08:12:26 -05:00
|
|
|
if (isWindows) {
|
2016-10-31 09:05:32 -04:00
|
|
|
eclipse.project.name = eclipse.project.name.replace(':', '_')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
plugins.withType(JavaBasePlugin) {
|
|
|
|
File eclipseBuild = project.file('build-eclipse')
|
|
|
|
eclipse.classpath.defaultOutputDir = eclipseBuild
|
|
|
|
if (isEclipse) {
|
|
|
|
// set this so generated dirs will be relative to eclipse build
|
|
|
|
project.buildDir = eclipseBuild
|
|
|
|
}
|
|
|
|
eclipse.classpath.file.whenMerged { classpath ->
|
|
|
|
// give each source folder a unique corresponding output folder
|
|
|
|
int i = 0;
|
|
|
|
classpath.entries.findAll { it instanceof SourceFolder }.each { folder ->
|
|
|
|
i++;
|
|
|
|
// this is *NOT* a path or a file.
|
|
|
|
folder.output = "build-eclipse/" + i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
task copyEclipseSettings(type: Copy) {
|
|
|
|
// TODO: "package this up" for external builds
|
|
|
|
from new File(project.rootDir, 'buildSrc/src/main/resources/eclipse.settings')
|
|
|
|
into '.settings'
|
|
|
|
}
|
|
|
|
// otherwise .settings is not nuked entirely
|
|
|
|
task wipeEclipseSettings(type: Delete) {
|
|
|
|
delete '.settings'
|
|
|
|
}
|
|
|
|
tasks.cleanEclipse.dependsOn(wipeEclipseSettings)
|
|
|
|
// otherwise the eclipse merging is *super confusing*
|
|
|
|
tasks.eclipse.dependsOn(cleanEclipse, copyEclipseSettings)
|
|
|
|
}
|