From 548430072f811ec3d912894debbb082eb21aead8 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Wed, 4 Nov 2015 22:28:57 -0800 Subject: [PATCH] Build: Fix eclipse generation to add a core-tests projects Eclipse does not have the ability to differentiate test dependencies from main dependencies. This causes what looks like a circular dependency through test-framework. This change sets up an additional core-tests project for eclipse only, which removes this problem. --- build.gradle | 12 +++---- core/build.gradle | 51 ++++++++++++++++++++---------- core/src/main/eclipse-build.gradle | 3 ++ core/src/test/eclipse-build.gradle | 7 ++++ settings.gradle | 26 ++++++++++++--- 5 files changed, 69 insertions(+), 30 deletions(-) create mode 100644 core/src/main/eclipse-build.gradle create mode 100644 core/src/test/eclipse-build.gradle diff --git a/build.gradle b/build.gradle index 77b619ec391..712e8b5837c 100644 --- a/build.gradle +++ b/build.gradle @@ -97,13 +97,14 @@ allprojects { randomizedrunner: '2.2.0', httpclient: '4.3.6' ] + + // for eclipse hacks... + isEclipse = System.getProperty("eclipse.launcher") != null || gradle.startParameter.taskNames.contains('eclipse') || gradle.startParameter.taskNames.contains('cleanEclipse') } } subprojects { repositories { - // Uncomment the following line to first resolve against the maven local repo. This is useful for eclipse users who want to work on test-framework. - // mavenLocal() mavenCentral() maven { name 'sonatype-snapshots' @@ -137,12 +138,7 @@ subprojects { dependencySubstitution { substitute module("org.elasticsearch:rest-api-spec:${version}") with project("${projectsPrefix}:rest-api-spec") substitute module("org.elasticsearch:elasticsearch:${version}") with project("${projectsPrefix}:core") - // so that eclipse doesn't have circular references - // the downside is, if you hack on test-framework, you have to gradle install - // the first prop detects eclipse itself, the second detects eclipse from commandline - if (System.getProperty("eclipse.launcher") == null && gradle.startParameter.taskNames.contains('eclipse') == false) { - substitute module("org.elasticsearch:test-framework:${version}") with project("${projectsPrefix}:test-framework") - } + substitute module("org.elasticsearch:test-framework:${version}") with project("${projectsPrefix}:test-framework") substitute module("org.elasticsearch.distribution.zip:elasticsearch:${version}") with project("${projectsPrefix}:distribution:zip") substitute module("org.elasticsearch.distribution.tar:elasticsearch:${version}") with project("${projectsPrefix}:distribution:tar") } diff --git a/core/build.gradle b/core/build.gradle index 01134f372bd..101f555374b 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -89,9 +89,24 @@ dependencies { compile 'net.java.dev.jna:jna:4.1.0', optional - testCompile("org.elasticsearch:test-framework:${version}") { - // tests use the locally compiled version of core - exclude group: 'org.elasticsearch', module: 'elasticsearch' + if (isEclipse == false || project.path == "${projectsPrefix}:core-tests") { + testCompile("org.elasticsearch:test-framework:${version}") { + // tests use the locally compiled version of core + exclude group: 'org.elasticsearch', module: 'elasticsearch' + } + } +} + +if (isEclipse) { + // in eclipse the project is under a fake root, we need to change around the source sets + sourceSets { + if (project.path == "${projectsPrefix}:core") { + main.java.srcDirs = ['java'] + main.resources.srcDirs = ['resources'] + } else { + test.java.srcDirs = ['java'] + test.resources.srcDirs = ['resources'] + } } } @@ -104,19 +119,21 @@ forbiddenPatterns { exclude '**/org/elasticsearch/cluster/routing/shard_routes.txt' } -task integTest(type: RandomizedTestingTask, - group: JavaBasePlugin.VERIFICATION_GROUP, - description: 'Multi-node tests', - dependsOn: test.dependsOn) { - configure(BuildPlugin.commonTestConfig(project)) - classpath = project.test.classpath - testClassesDir = project.test.testClassesDir - include '**/*IT.class' +if (isEclipse == false || project.path == "${projectsPrefix}:core-tests") { + task integTest(type: RandomizedTestingTask, + group: JavaBasePlugin.VERIFICATION_GROUP, + description: 'Multi-node tests', + dependsOn: test.dependsOn) { + configure(BuildPlugin.commonTestConfig(project)) + classpath = project.test.classpath + testClassesDir = project.test.testClassesDir + include '**/*IT.class' + } + check.dependsOn integTest + integTest.mustRunAfter test + + RestSpecHack.configureDependencies(project) + Task copyRestSpec = RestSpecHack.configureTask(project, true) + integTest.dependsOn copyRestSpec } -check.dependsOn integTest -integTest.mustRunAfter test - -RestSpecHack.configureDependencies(project) -Task copyRestSpec = RestSpecHack.configureTask(project, true) -integTest.dependsOn copyRestSpec diff --git a/core/src/main/eclipse-build.gradle b/core/src/main/eclipse-build.gradle new file mode 100644 index 00000000000..e46e7134456 --- /dev/null +++ b/core/src/main/eclipse-build.gradle @@ -0,0 +1,3 @@ + +// this is just shell gradle file for eclipse to have separate projects for core src and tests +apply from: '../../build.gradle' diff --git a/core/src/test/eclipse-build.gradle b/core/src/test/eclipse-build.gradle new file mode 100644 index 00000000000..8ce3eb20eec --- /dev/null +++ b/core/src/test/eclipse-build.gradle @@ -0,0 +1,7 @@ + +// this is just shell gradle file for eclipse to have separate projects for core src and tests +apply from: '../../build.gradle' + +dependencies { + testCompile project("${projectsPrefix}:core") +} diff --git a/settings.gradle b/settings.gradle index 447d1626fcf..0bf31a1bb65 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,6 @@ rootProject.name = 'elasticsearch' -String[] projects = [ +List projects = [ 'rest-api-spec', 'core', 'distribution:zip', @@ -35,9 +35,25 @@ String[] projects = [ 'qa:vagrant', ] -if (hasProperty('elasticsearch.projectsPrefix')) { - String prefix = getProperty('elasticsearch.projectsPrefix') - projects = projects.collect { "${prefix}:${it}" } +boolean isEclipse = System.getProperty("eclipse.launcher") != null || gradle.startParameter.taskNames.contains('eclipse') || gradle.startParameter.taskNames.contains('cleanEclipse') +if (isEclipse) { + // eclipse cannot handle an intermediate dependency between main and test, so we must create separate projects + // for core-src and core-tests + projects << 'core-tests' +} + +String prefix = '' +if (hasProperty('elasticsearch.projectsPrefix')) { + prefix = "${getProperty('elasticsearch.projectsPrefix')}:" + projects = projects.collect { "${prefix}${it}" } +} + +include projects.toArray(new String[0]) + +if (isEclipse) { + project(":${prefix}core").projectDir = new File(rootProject.projectDir, 'core/src/main') + project(":${prefix}core").buildFileName = 'eclipse-build.gradle' + project(":${prefix}core-tests").projectDir = new File(rootProject.projectDir, 'core/src/test') + project(":${prefix}core-tests").buildFileName = 'eclipse-build.gradle' } -include projects