-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve IntelliJ IDE integration (#53747)
This commit makes a number of improvements when importing the Elasticsearch project into IntelliJ IDEA. Specifically: - Contributing documentation has been updated to reflect that the 'idea' task should no long be used and Gradle project import is instead the officially supported way of setting up the project. - Attempts to run the 'idea' task will result in a failure with a message directing folks to our CONTRIBUTING.md document. - The project JDK is explicit set rather that using whatever JAVA_HOME is. - Gradle build operation delegation is disabled, and test execution is configured to 'choose per test'. - Gradle is configured to inherit the project JDK. - Some code style conventions are automatically configured. - File encoding is explicitly set to UTF-8. - Parallel module compilation is enabled and deprecated feature warnings are disabled. - A remote debug run configuration using listen mode is created. - JUnit runner is configured with required system properties. - License headers are configured such that Apache 2 is the default notice added to all source files with exception of source in /x-pack which will use the Elastic license.
- Loading branch information
1 parent
2ec1f6b
commit 2e617c3
Showing
8 changed files
with
198 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
import org.jetbrains.gradle.ext.Remote | ||
import org.jetbrains.gradle.ext.JUnit | ||
|
||
buildscript { | ||
repositories { | ||
maven { | ||
url "https://plugins.gradle.org/m2/" | ||
} | ||
} | ||
dependencies { | ||
classpath "gradle.plugin.org.jetbrains.gradle.plugin.idea-ext:gradle-idea-ext:0.7" | ||
} | ||
} | ||
|
||
apply plugin: org.jetbrains.gradle.ext.IdeaExtPlugin | ||
|
||
allprojects { | ||
apply plugin: 'idea' | ||
|
||
tasks.named('idea') { | ||
doFirst { throw new GradleException("Use of the 'idea' task has been deprecated. For details on importing into IntelliJ see CONTRIBUTING.md.") } | ||
} | ||
} | ||
|
||
tasks.register('configureIdeaGradleJvm') { | ||
group = 'ide' | ||
description = 'Configures the appropriate JVM for Gradle' | ||
|
||
doLast { | ||
modifyXml('.idea/gradle.xml') { xml -> | ||
def gradleSettings = xml.component.find { it.'@name' == 'GradleSettings' }.option[0].GradleProjectSettings | ||
// Remove configured JVM option to force IntelliJ to use the project JDK for Gradle | ||
gradleSettings.option.findAll { it.'@name' == 'gradleJvm' }.each { it.parent().remove(it) } | ||
} | ||
} | ||
} | ||
|
||
tasks.register('configureIdeaRunConfigs') { | ||
group = 'ide' | ||
description = 'Configures default run configuration settings' | ||
|
||
doLast { | ||
modifyXml('.idea/workspace.xml') { xml -> | ||
def runManager = xml.component.find { it.'@name' == 'RunManager' } | ||
if (runManager == null) { | ||
throw new GradleException("IntelliJ 'RunManager' configuration is missing from workspace.xml. You may need to refresh your Gradle project.") | ||
} | ||
|
||
def debugConfig = runManager.configuration.find { it.'@name' == 'Debug Elasticsearch' } | ||
// Enable "auto restart" on remote debug run configuration | ||
if (debugConfig.option.any { it.'@name' == 'AUTO_RESTART' && it.'@value' == 'true'} == false) { | ||
def restart = new NodeBuilder().option(name: 'AUTO_RESTART', value: 'true') | ||
debugConfig.append(restart) | ||
} | ||
} | ||
} | ||
} | ||
|
||
idea { | ||
project { | ||
vcs = 'Git' | ||
jdkName = '13' | ||
|
||
settings { | ||
delegateActions { | ||
delegateBuildRunToGradle = false | ||
testRunner = 'choose_per_test' | ||
} | ||
taskTriggers { | ||
afterSync tasks.named('configureIdeaGradleJvm'), tasks.named('configureIdeaRunConfigs') | ||
} | ||
codeStyle { | ||
java { | ||
classCountToUseImportOnDemand = 999 | ||
} | ||
} | ||
encodings { | ||
encoding = 'UTF-8' | ||
} | ||
compiler { | ||
parallelCompilation = true | ||
javac { | ||
generateDeprecationWarnings = false | ||
} | ||
} | ||
runConfigurations { | ||
'Debug Elasticsearch'(Remote) { | ||
mode = 'listen' | ||
host = 'localhost' | ||
port = 5005 | ||
} | ||
defaults(JUnit) { | ||
vmParameters = '-Djava.locale.providers=SPI,COMPAT' | ||
} | ||
} | ||
copyright { | ||
useDefault = 'Apache' | ||
scopes = ['x-pack': 'Elastic'] | ||
profiles { | ||
Apache { | ||
keyword = 'Licensed to Elasticsearch under one or more contributor' | ||
notice = '''\ | ||
Licensed to Elasticsearch under one or more contributor | ||
license agreements. See the NOTICE file distributed with | ||
this work for additional information regarding copyright | ||
ownership. Elasticsearch licenses this file to you under | ||
the Apache License, Version 2.0 (the "License"); you may | ||
not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License.'''.stripIndent() | ||
} | ||
Elastic { | ||
keyword = 'Licensed under the Elastic License' | ||
notice = '''\ | ||
Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
or more contributor license agreements. Licensed under the Elastic License; | ||
you may not use this file except in compliance with the Elastic License.'''.stripIndent() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Parses a given XML file, applies a set of changes, and writes those changes back to the original file. | ||
* | ||
* @param path Path to existing XML file | ||
* @param action Action to perform on parsed XML document | ||
*/ | ||
void modifyXml(Object path, Action<? super Node> action) { | ||
File xmlFile = project.file(path) | ||
Node xml = new XmlParser().parse(xmlFile) | ||
action.execute(xml) | ||
|
||
xmlFile.withPrintWriter { writer -> | ||
new XmlNodePrinter(writer).print(xml) | ||
} | ||
} |
Oops, something went wrong.