From 943542384437e30ecebbd1e87d48045ca11fe484 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Wed, 17 Jan 2018 19:54:43 -0800 Subject: [PATCH] Build: Automatically add projects under libs, qa, modules and plugins (#28279) This commit lessens the burden on configuring settings.gradle when new projects are added. In particular, this makes it trivial to move a plugin to a module (or vice versa). --- libs/build.gradle | 0 qa/build.gradle | 0 settings.gradle | 156 ++++++++++++++-------------------------------- 3 files changed, 46 insertions(+), 110 deletions(-) create mode 100644 libs/build.gradle create mode 100644 qa/build.gradle diff --git a/libs/build.gradle b/libs/build.gradle new file mode 100644 index 00000000000..e69de29bb2d diff --git a/qa/build.gradle b/qa/build.gradle new file mode 100644 index 00000000000..e69de29bb2d diff --git a/settings.gradle b/settings.gradle index 46ecb3dad1c..c135b431a23 100644 --- a/settings.gradle +++ b/settings.gradle @@ -27,78 +27,56 @@ List projects = [ 'test:fixtures:hdfs-fixture', 'test:fixtures:krb5kdc-fixture', 'test:fixtures:old-elasticsearch', - 'test:logger-usage', - 'libs:elasticsearch-core', - 'libs:elasticsearch-nio', - 'modules:aggs-matrix-stats', - 'modules:analysis-common', - 'modules:ingest-common', - 'modules:lang-expression', - 'modules:lang-mustache', - 'modules:lang-painless', - 'modules:mapper-extras', - 'modules:parent-join', - 'modules:percolator', - 'modules:rank-eval', - 'modules:reindex', - 'modules:repository-url', - 'modules:transport-netty4', - 'modules:tribe', - 'plugins:analysis-icu', - 'plugins:analysis-kuromoji', - 'plugins:analysis-phonetic', - 'plugins:analysis-smartcn', - 'plugins:analysis-stempel', - 'plugins:analysis-ukrainian', - 'plugins:discovery-azure-classic', - 'plugins:discovery-ec2', - 'plugins:discovery-file', - 'plugins:discovery-gce', - 'plugins:ingest-geoip', - 'plugins:ingest-attachment', - 'plugins:ingest-user-agent', - 'plugins:mapper-murmur3', - 'plugins:mapper-size', - 'plugins:repository-azure', - 'plugins:repository-gcs', - 'plugins:repository-hdfs', - 'plugins:repository-s3', - 'plugins:jvm-example', - 'plugins:store-smb', - 'plugins:transport-nio', - 'qa:auto-create-index', - 'qa:ccs-unavailable-clusters', - 'qa:evil-tests', - 'qa:full-cluster-restart', - 'qa:integration-bwc', - 'qa:mixed-cluster', - 'qa:multi-cluster-search', - 'qa:no-bootstrap-tests', - 'qa:reindex-from-old', - 'qa:rolling-upgrade', - 'qa:smoke-test-client', - 'qa:smoke-test-http', - 'qa:smoke-test-ingest-with-all-dependencies', - 'qa:smoke-test-ingest-disabled', - 'qa:smoke-test-multinode', - 'qa:smoke-test-rank-eval-with-mustache', - 'qa:smoke-test-plugins', - 'qa:smoke-test-reindex-with-all-modules', - 'qa:smoke-test-tribe-node', - 'qa:vagrant', - 'qa:verify-version-constants', - 'qa:wildfly', - 'qa:query-builder-bwc' + 'test:logger-usage' ] -projects.add("libs") -File libsDir = new File(rootProject.projectDir, 'libs') -for (File libDir : new File(rootProject.projectDir, 'libs').listFiles()) { - if (libDir.isDirectory() == false) continue; - if (libDir.name.startsWith('build') || libDir.name.startsWith('.')) continue; - projects.add("libs:${libDir.name}".toString()) +/** + * Iterates over sub directories, looking for build.gradle, and adds a project if found + * for that dir with the given path prefix. Note that this requires each level + * of the dir hierarchy to have a build.gradle. Otherwise we would have to iterate + * all files/directories in the source tree to find all projects. + */ +void addSubProjects(String path, File dir, List projects, List branches) { + if (dir.isDirectory() == false) return; + if (dir.name == 'buildSrc') return; + if (new File(dir, 'build.gradle').exists() == false) return; + if (findProject(dir) != null) return; + + final String projectName = "${path}:${dir.name}" + include projectName + + if (dir.name == 'bwc-snapshot-dummy-projects') { + for (final String branch : branches) { + final String snapshotProjectName = "${projectName}:bwc-snapshot-${branch}" + projects.add(snapshotProjectName) + include snapshotProjectName + project("${snapshotProjectName}").projectDir = dir + } + // TODO do we want to assert that there's nothing else in the bwc directory? + } else { + if (path.isEmpty() || path.startsWith(':example-plugins')) { + project(projectName).projectDir = dir + } + for (File subdir : dir.listFiles()) { + addSubProjects(projectName, subdir, projects, branches) + } + } } +// include example plugins first, so adding plugin dirs below won't muck with :example-plugins +File examplePluginsDir = new File(rootProject.projectDir, 'plugins/examples') +for (File example : examplePluginsDir.listFiles()) { + if (example.isDirectory() == false) continue; + if (example.name.startsWith('build') || example.name.startsWith('.')) continue; + addSubProjects(':example-plugins', example, projects, []) +} +project(':example-plugins').projectDir = new File(rootProject.projectDir, 'plugins/examples') + +addSubProjects('', new File(rootProject.projectDir, 'libs'), projects, []) +addSubProjects('', new File(rootProject.projectDir, 'modules'), projects, []) +addSubProjects('', new File(rootProject.projectDir, 'plugins'), projects, []) +addSubProjects('', new File(rootProject.projectDir, 'qa'), projects, []) + /* Create projects for building BWC snapshot distributions from the heads of other branches */ final List branches = ['5.6', '6.0', '6.1', '6.x'] for (final String branch : branches) { @@ -139,47 +117,6 @@ if (isEclipse) { project(":libs:elasticsearch-nio-tests").buildFileName = 'eclipse-build.gradle' } -/** - * Iterates over sub directories, looking for build.gradle, and adds a project if found - * for that dir with the given path prefix. Note that this requires each level - * of the dir hierarchy to have a build.gradle. Otherwise we would have to iterate - * all files/directories in the source tree to find all projects. - */ -void addSubProjects(String path, File dir, List projects, List branches) { - if (dir.isDirectory() == false) return; - if (dir.name == 'buildSrc') return; - if (new File(dir, 'build.gradle').exists() == false) return; - - final String projectName = "${path}:${dir.name}" - include projectName - - if (dir.name == 'bwc-snapshot-dummy-projects') { - for (final String branch : branches) { - final String snapshotProjectName = "${projectName}:bwc-snapshot-${branch}" - projects.add(snapshotProjectName) - include snapshotProjectName - project("${snapshotProjectName}").projectDir = dir - } - // TODO do we want to assert that there's nothing else in the bwc directory? - } else { - if (path.isEmpty() || path.startsWith(':example-plugins')) { - project(projectName).projectDir = dir - } - for (File subdir : dir.listFiles()) { - addSubProjects(projectName, subdir, projects, branches) - } - } -} - -// include example plugins -File examplePluginsDir = new File(rootProject.projectDir, 'plugins/examples') -for (File example : examplePluginsDir.listFiles()) { - if (example.isDirectory() == false) continue; - if (example.name.startsWith('build') || example.name.startsWith('.')) continue; - addSubProjects(':example-plugins', example, projects, []) -} -project(':example-plugins').projectDir = new File(rootProject.projectDir, 'plugins/examples') - // look for extra plugins for elasticsearch File extraProjects = new File(rootProject.projectDir.parentFile, "${dirName}-extra") if (extraProjects.exists()) { @@ -187,5 +124,4 @@ if (extraProjects.exists()) { addSubProjects('', extraProjectDir, projects, branches) } } -include 'libs'