-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Gradle Jdk Automanagement] Generate Gradle Jdks Configuration & setu…
…p Intellij (#360) [Gradle Jdk Automanagement] Generate Gradle Jdks Configuration
- Loading branch information
Showing
74 changed files
with
2,951 additions
and
926 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
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,6 @@ | ||
type: improvement | ||
improvement: | ||
description: '[Gradle Jdk Automanagement] Generate Gradle Jdks Configuration & Intellij | ||
setup' | ||
links: | ||
- https://github.com/palantir/gradle-jdks/pull/360 |
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,5 @@ | ||
apply plugin: 'com.palantir.external-publish-jar' | ||
|
||
dependencies { | ||
implementation project(':gradle-jdks-setup-common') | ||
} |
53 changes: 53 additions & 0 deletions
53
...ks-enablement/src/main/java/com/palantir/gradle/jdks/enablement/GradleJdksEnablement.java
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,53 @@ | ||
/* | ||
* (c) Copyright 2024 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
package com.palantir.gradle.jdks.enablement; | ||
|
||
import com.palantir.gradle.jdks.setup.common.CurrentOs; | ||
import com.palantir.gradle.jdks.setup.common.Os; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.Optional; | ||
import java.util.Properties; | ||
|
||
public class GradleJdksEnablement { | ||
|
||
public static final String MINIMUM_SUPPORTED_GRADLE_VERSION = "7.6"; | ||
|
||
public static boolean isGradleJdkSetupEnabled(Path projectDir) { | ||
return !CurrentOs.get().equals(Os.WINDOWS) && isGradleJdkPropertyEnabled(projectDir); | ||
} | ||
|
||
private static boolean isGradleJdkPropertyEnabled(Path projectDir) { | ||
File gradlePropsFile = projectDir.resolve("gradle.properties").toFile(); | ||
if (!gradlePropsFile.exists()) { | ||
return false; | ||
} | ||
try { | ||
Properties properties = new Properties(); | ||
properties.load(new FileInputStream(gradlePropsFile)); | ||
return Optional.ofNullable(properties.getProperty("palantir.jdk.setup.enabled")) | ||
.map(Boolean::parseBoolean) | ||
.orElse(false); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Failed to read gradle.properties file", e); | ||
} | ||
} | ||
|
||
private GradleJdksEnablement() {} | ||
} |
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,3 @@ | ||
apply plugin: 'java-gradle-plugin' | ||
apply plugin: 'groovy' | ||
apply plugin: 'com.palantir.external-publish-jar' |
36 changes: 36 additions & 0 deletions
36
...le-jdks-groovy/src/main/groovy/com/palantir/gradle/jdks/ConfigureJdksIdeaPluginXml.groovy
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,36 @@ | ||
/* | ||
* (c) Copyright 2024 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
package com.palantir.gradle.jdks | ||
|
||
class ConfigureJdksIdeaPluginXml { | ||
|
||
static void configureExternalDependencies(Node rootNode) { | ||
def externalDependencies = matchOrCreateChild(rootNode, 'component', [name: 'ExternalDependencies']) | ||
matchOrCreateChild(externalDependencies, 'plugin', [id: 'palantir-gradle-jdks']) | ||
} | ||
|
||
private static Node matchOrCreateChild(Node base, String name, Map attributes = [:], Map defaults = [:]) { | ||
matchChild(base, name, attributes).orElseGet { | ||
base.appendNode(name, attributes + defaults) | ||
} | ||
} | ||
|
||
private static Optional<Node> matchChild(Node base, String name, Map attributes = [:]) { | ||
def child = base[name].find { it.attributes().entrySet().containsAll(attributes.entrySet()) } | ||
return Optional.ofNullable(child) | ||
} | ||
} |
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,46 @@ | ||
apply plugin: 'java-gradle-plugin' | ||
apply plugin: 'groovy' | ||
apply plugin: 'com.palantir.external-publish-jar' | ||
apply plugin: 'com.palantir.external-publish-gradle-plugin' | ||
apply plugin: 'com.palantir.shadow-jar' | ||
|
||
dependencies { | ||
// DO NOT ADD directly implementation/api dependencies here. We need to avoid overlapping dependencies between the | ||
// settings classLoader and the build classLoaders. | ||
shadeTransitively project(':gradle-jdks-setup-common') | ||
shadeTransitively project(':gradle-jdks-enablement') | ||
} | ||
|
||
gradlePlugin { | ||
plugins { | ||
patchJdks { | ||
id = 'com.palantir.jdks.settings' | ||
displayName = 'Palantir Gradle JDK Settings Plugin' | ||
description = 'Sets the Gradle properties for the Gradle JDK setup' | ||
implementationClass = 'com.palantir.gradle.jdks.settings.ToolchainJdksSettingsPlugin' | ||
tags.addAll("java", "jdks") | ||
} | ||
} | ||
website = 'https://github.com/palantir/gradle-jdks' | ||
vcsUrl = 'https://github.com/palantir/gradle-jdks' | ||
description = 'Gradle JDK settings plugins' | ||
} | ||
|
||
// When adding the shadeTransitively dependency, the pom file includes `gradle-jdks-root` as a dependency. | ||
// This is broken and it will lead to classpath configuration failures when the settings plugin is applied. As a | ||
// workaround, we are removing the artifact from the pom file. | ||
publishing.publications { | ||
withType(MavenPublication) { | ||
pom.withXml { | ||
var projectDependencyNodes = [] | ||
asNode().depthFirst { node -> | ||
if (node.name().localPart == 'dependency' && node.get("groupId").text() == "com.palantir.gradle.jdks" && node.get("artifactId").text() == "gradle-jdks-root") { | ||
projectDependencyNodes << node | ||
} | ||
} | ||
projectDependencyNodes.each { node -> | ||
node.parent().remove(node) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.