Skip to content

Fix projects that failed to build within Intellij #62258

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 12 commits into from
Sep 15, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public static void setupIdeForTestSourceSet(Project project, SourceSet testSourc
project.getPluginManager().withPlugin("idea", p -> {
IdeaModel idea = project.getExtensions().getByType(IdeaModel.class);
idea.getModule().setTestSourceDirs(testSourceSet.getJava().getSrcDirs());
idea.getModule().getScopes().put("TEST", Map.of("plus", List.of(runtimeClasspathConfiguration)));
idea.getModule().getScopes().put(testSourceSet.getName(), Map.of("plus", List.of(runtimeClasspathConfiguration)));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't seem to have any functional impact, just noticed I missed this before and I think it is a bit more correct.

});
project.getPluginManager().withPlugin("eclipse", p -> {
EclipseModel eclipse = project.getExtensions().getByType(EclipseModel.class);
Expand Down Expand Up @@ -196,6 +196,19 @@ public static void extendSourceSet(Project project, String parentSourceSetName,
child.setRuntimeClasspath(project.getObjects().fileCollection().from(child.getRuntimeClasspath(), parent.getOutput()));
}

/**
* Extends one configuration from another and refreshes the classpath of a provided Test.
* The Test parameter is only needed for eagerly defined test tasks.
*/
public static void extendSourceSet(Project project, String parentSourceSetName, String childSourceSetName, Test test) {
extendSourceSet(project, parentSourceSetName, childSourceSetName);
if (test != null) {
SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
SourceSet child = sourceSets.getByName(childSourceSetName);
test.setClasspath(child.getRuntimeClasspath());
}
}

public static Dependency projectDependency(Project project, String projectPath, String projectConfig) {
if (project.findProject(projectPath) == null) {
throw new GradleException("no project [" + projectPath + "], project names: " + project.getRootProject().getAllprojects());
Expand Down
7 changes: 3 additions & 4 deletions qa/die-with-dignity/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import org.elasticsearch.gradle.info.BuildParams
import org.elasticsearch.gradle.util.GradleUtils

apply plugin: 'elasticsearch.java-rest-test'
apply plugin: 'elasticsearch.esplugin'
Expand All @@ -8,10 +9,8 @@ esplugin {
classname 'org.elasticsearch.DieWithDignityPlugin'
}

dependencies {
// let the javaRestTest see the classpath of main
javaRestTestImplementation project.sourceSets.main.runtimeClasspath
}
// let the javaRestTest see the classpath of main
GradleUtils.extendSourceSet(project, "main", "javaRestTest", javaRestTest)

javaRestTest {
systemProperty 'tests.security.manager', 'false'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.elasticsearch.test.rest.yaml.ClientYamlTestClient;
import org.elasticsearch.test.rest.yaml.ClientYamlTestResponse;
import org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestSpec;
import org.elasticsearch.xpack.test.rest.XPackRestIT;
import org.elasticsearch.xpack.test.rest.AbstractXPackRestTest;
import org.junit.After;

import java.util.List;
Expand All @@ -29,7 +29,7 @@
import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
import static org.hamcrest.Matchers.is;

public class XDocsClientYamlTestSuiteIT extends XPackRestIT {
public class XDocsClientYamlTestSuiteIT extends AbstractXPackRestTest {
private static final String USER_TOKEN = basicAuthHeaderValue("test_admin", new SecureString("x-pack-test-password".toCharArray()));

public XDocsClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) {
Expand Down
15 changes: 5 additions & 10 deletions x-pack/plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,23 @@ apply plugin: 'elasticsearch.validate-rest-spec'
archivesBaseName = 'x-pack'

dependencies {
yamlRestTestImplementation project(xpackModule('core')) // this redundant dependency is here to make IntelliJ happy
yamlRestTestImplementation project(path: xpackModule('core'), configuration: 'testArtifacts')
testImplementation project(xpackModule('core'))
testImplementation project(path: xpackModule('core'), configuration: 'testArtifacts')
javaRestTestImplementation project(path: xpackModule('core'), configuration: 'testArtifacts')
// let the yamlRestTest see the classpath of test
yamlRestTestImplementation project.sourceSets.test.runtimeClasspath
}

configurations {
testArtifacts.extendsFrom testRuntime
testArtifacts.extendsFrom testImplementation
testArtifacts.extendsFrom yamlRestTestImplementation
testArtifacts.extendsFrom javaRestTestImplementation
}

restResources {
restApi {
includeCore '*'
includeXpack '*'
}
restTests {
includeXpack '*'
}
}

//The api and tests need to stay at src/test/... since some external tooling depends on that exact file path.
Expand All @@ -37,10 +34,8 @@ artifacts {

def testJar = tasks.register("testJar", Jar) {
appendix 'test'
duplicatesStrategy = DuplicatesStrategy.INCLUDE
from sourceSets.test.output
from sourceSets.yamlRestTest.output
from sourceSets.javaRestTest.output
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pretty sure the only reason we expose this is for the yaml tests and the custom parent runner, both of which are (now) in the test source set...so only expose that in the jar and testArtifact config.


/*
* Stick the license and notice file in the jar. This isn't strictly
* needed because we don't publish it but it makes our super-paranoid
Expand Down
8 changes: 6 additions & 2 deletions x-pack/plugin/deprecation/qa/rest/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.elasticsearch.gradle.util.GradleUtils

apply plugin: 'elasticsearch.esplugin'
apply plugin: 'elasticsearch.java-rest-test'

Expand All @@ -9,10 +11,12 @@ esplugin {
dependencies {
javaRestTestImplementation("com.fasterxml.jackson.core:jackson-annotations:${versions.jackson}")
javaRestTestImplementation("com.fasterxml.jackson.core:jackson-databind:${versions.jackson}")
// let the javaRestTest see the classpath of main
javaRestTestImplementation project.sourceSets.main.runtimeClasspath
}

// let the javaRestTest see the classpath of main
GradleUtils.extendSourceSet(project, "main", "javaRestTest", javaRestTest)


restResources {
restApi {
includeCore '_common', 'indices', 'index'
Expand Down
6 changes: 6 additions & 0 deletions x-pack/plugin/ilm/qa/multi-node/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import org.elasticsearch.gradle.util.GradleUtils

apply plugin: 'elasticsearch.java-rest-test'

dependencies {
javaRestTestImplementation project(path: xpackProject('plugin').path, configuration: 'testArtifacts')
}

// let the javaRestTest see the classpath of main
GradleUtils.extendSourceSet(project, "main", "javaRestTest", javaRestTest)


File repoDir = file("$buildDir/testclusters/repo")

javaRestTest {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugin/ilm/qa/with-security/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apply plugin: 'elasticsearch.java-rest-test'

dependencies {
javaRestTestImplementation project(path: xpackModule('core'))
javaRestTestImplementation project(path: xpackProject('plugin').path, configuration: 'testArtifacts')
}

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugin/ml/qa/ml-with-security/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apply plugin: 'elasticsearch.yaml-rest-test'

dependencies {
yamlRestTestImplementation project(path: xpackModule('core'), configuration: 'testArtifacts')
yamlRestTestImplementation project(path: xpackModule('core'))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wierd dependency ordering thing...likely a subtle in Intellij

yamlRestTestImplementation project(path: xpackModule('core'), configuration: 'testArtifacts')
yamlRestTestImplementation project(path: xpackProject('plugin').path, configuration: 'testArtifacts')
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.test.SecuritySettingsSourceField;
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
import org.elasticsearch.xpack.test.rest.XPackRestIT;
import org.elasticsearch.xpack.test.rest.AbstractXPackRestTest;

import java.util.Collections;
import java.util.Map;

import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;


public class MlWithSecurityIT extends XPackRestIT {
public class MlWithSecurityIT extends AbstractXPackRestTest {

private static final String TEST_ADMIN_USERNAME = "x_pack_rest_user";

Expand Down
1 change: 1 addition & 0 deletions x-pack/plugin/runtime-fields/qa/with-security/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apply plugin: 'elasticsearch.java-rest-test'

dependencies {
javaRestTestImplementation project(path: xpackModule('core'))
javaRestTestImplementation project(path: xpackProject('plugin').path, configuration: 'testArtifacts')
}

Expand Down
Loading