-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
1,222 additions
and
607 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
File renamed without changes.
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 @@ | ||
# Ignore Gradle project-specific cache directory | ||
.gradle | ||
|
||
# Ignore Gradle build output directory | ||
build |
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 @@ | ||
# This file was generated by the Gradle 'init' task. | ||
# https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties | ||
|
||
org.gradle.parallel=true | ||
org.gradle.caching=true | ||
version=0.0.1 |
3 changes: 3 additions & 0 deletions
3
e2e/gradle/gradle/libs.versions.toml → ...s/gradle/native/gradle/libs.versions.toml
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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
# This file was generated by the Gradle 'init' task. | ||
# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format | ||
|
||
[plugins] | ||
jvm = { id = "org.jetbrains.kotlin.jvm", version = "1.9.20" } |
Binary file renamed
BIN
+42.4 KB
e2e/gradle/gradle/wrapper/gradle-wrapper.jar → .../native/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 3 additions & 2 deletions
5
.../gradle/wrapper/gradle-wrapper.properties → .../gradle/wrapper/gradle-wrapper.properties
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip | ||
validateDistributionUrl=false | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip | ||
networkTimeout=10000 | ||
validateDistributionUrl=true | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
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,33 @@ | ||
/* | ||
* This file was generated by the Gradle 'init' task. | ||
* | ||
* This generated file contains a sample Gradle plugin project to get you started. | ||
* For more details on writing Custom Plugins, please refer to https://docs.gradle.org/8.5/userguide/custom_plugins.html in the Gradle documentation. | ||
* This project uses @Incubating APIs which are subject to change. | ||
*/ | ||
|
||
plugins { | ||
// Apply the Java Gradle plugin development plugin to add support for developing Gradle plugins | ||
`java-gradle-plugin` | ||
`maven-publish` | ||
|
||
// Apply the Kotlin JVM plugin to add support for Kotlin. | ||
alias(libs.plugins.jvm) | ||
} | ||
|
||
repositories { | ||
// Use Maven Central for resolving dependencies. | ||
mavenCentral() | ||
} | ||
|
||
gradlePlugin { | ||
// Define the plugin | ||
val Nodes by plugins.creating { | ||
id = "io.nx.gradle.plugin.Nodes" | ||
implementationClass = "io.nx.gradle.plugin.Nodes" | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation("com.google.code.gson:gson:2.11.0") | ||
} |
192 changes: 192 additions & 0 deletions
192
packages/gradle/native/plugin/src/main/kotlin/io/nx/gradle/plugin/CreateNodesTask.kt
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,192 @@ | ||
package io.nx.gradle.plugin | ||
|
||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.Project | ||
import java.io.File | ||
import org.gradle.api.tasks.options.Option | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.TaskAction | ||
import org.gradle.api.artifacts.ProjectDependency | ||
import com.google.gson.Gson | ||
import com.google.gson.GsonBuilder | ||
import java.lang.Error | ||
import java.nio.file.Path | ||
|
||
data class GradleTargets(val targets: MutableMap<String, Any>, val targetGroups: MutableMap<String, MutableList<String>>) | ||
data class Metadata(val targetGroups: MutableMap<String, MutableList<String>>, val technologies: Array<String>, val description: String?) | ||
data class ProjectConfiguration(val targets: MutableMap<String, Any>, val metadata: Metadata, val name: String) | ||
data class Dependency(val source: String, val target: String, val sourceFile: String) | ||
data class Node(val project: ProjectConfiguration, val dependencies: MutableSet<Dependency>) | ||
|
||
abstract class CreateNodesTask : DefaultTask() { | ||
@Option(option = "outputDirectory", description = "Output directory, default to {workspaceRoot}/.nx/cache") | ||
@Input | ||
var outputDirectory: String = "" | ||
|
||
@Option(option = "workspaceRoot", description = "Workspace root, default to cwd") | ||
@Input | ||
var workspaceRoot: String = "" | ||
|
||
@TaskAction | ||
fun action() { | ||
val rootProjectDirectory = project.getProjectDir() | ||
if (workspaceRoot == "") { | ||
// assign the workspace root to root project's path | ||
workspaceRoot = System.getProperty("user.dir") | ||
} | ||
if (outputDirectory == "") { | ||
outputDirectory = File(workspaceRoot, ".nx/cache").getPath() | ||
} | ||
|
||
val projectNodes = mutableMapOf<String, Node>() | ||
project.getAllprojects().forEach { project -> | ||
try { | ||
// get dependencies of project | ||
val dependencies = getDependenciesForProject(project) | ||
|
||
val gradleTargets = this.processTargetsForProject(project, workspaceRoot, rootProjectDirectory) | ||
var projectRoot = project.getProjectDir().getPath() | ||
val projectConfig = ProjectConfiguration( | ||
gradleTargets.targets, | ||
Metadata(gradleTargets.targetGroups, arrayOf("Gradle"), project.getDescription()), | ||
project.getName() | ||
) | ||
projectNodes.put(projectRoot, Node(projectConfig, dependencies)) | ||
} catch (e: Error) { | ||
} // ignore errors | ||
} | ||
val gson = Gson() | ||
val json = gson.toJson(projectNodes) | ||
val file = File(outputDirectory, "${project.name}.json") | ||
file.writeText(json) | ||
println(file) | ||
} | ||
|
||
fun processTargetsForProject( | ||
project: Project, | ||
workspaceRoot: String, | ||
rootProjectDirectory: File | ||
): GradleTargets { | ||
val targets = mutableMapOf<String, Any>(); | ||
val targetGroups = mutableMapOf<String, MutableList<String>>(); | ||
val projectRoot = project.getProjectDir().getPath() | ||
|
||
var command: String; | ||
val operSys = System.getProperty("os.name").lowercase(); | ||
if (operSys.contains("win")) { | ||
command = ".\\gradlew.bat " | ||
} else { | ||
command = "./gradlew " | ||
} | ||
command += project.getBuildTreePath() | ||
if (!command.endsWith(":")) { | ||
command += ":" | ||
} | ||
|
||
project.getTasks().forEach { task -> | ||
val target = mutableMapOf<String, Any?>() | ||
val metadata = mutableMapOf<String, Any?>() | ||
var taskCommand = command.toString() | ||
metadata.put("description", task.getDescription()) | ||
metadata.put("technologies", arrayOf("Gradle")) | ||
val group: String? = task.getGroup(); | ||
if (!group.isNullOrBlank()) { | ||
if (targetGroups.contains(group)) { | ||
targetGroups.get(group)?.add(task.name) | ||
} else { | ||
targetGroups.set(group, mutableListOf<String>(task.name)) | ||
} | ||
} | ||
|
||
var inputs = task.getInputs().getSourceFiles() | ||
if (!inputs.isEmpty()) { | ||
target.put("inputs", inputs.mapNotNull { file -> | ||
val path: String = file.getPath() | ||
replaceRootInPath(path, projectRoot, workspaceRoot) | ||
}) | ||
} | ||
val outputs = task.getOutputs().getFiles() | ||
if (!outputs.isEmpty()) { | ||
target.put("outputs", outputs.mapNotNull { file -> | ||
val path: String = file.getPath() | ||
replaceRootInPath(path, projectRoot, workspaceRoot) | ||
}) | ||
} | ||
target.put("cache", true) | ||
|
||
val dependsOn = task.getTaskDependencies().getDependencies(task) | ||
if (!dependsOn.isEmpty()) { | ||
target.put("dependsOn", dependsOn.map { depTask -> | ||
val depProject = depTask.getProject() | ||
if (depProject == project) { | ||
depTask.name | ||
} | ||
"${depProject.name}:${depTask.name}" | ||
}) | ||
} | ||
target.put("metadata", metadata) | ||
|
||
taskCommand += task.name | ||
target.put("command", taskCommand) | ||
target.put("options", mapOf("cwd" to rootProjectDirectory.getPath())) | ||
|
||
targets.put(task.name, target) | ||
} | ||
|
||
return GradleTargets( | ||
targets, | ||
targetGroups | ||
); | ||
} | ||
} | ||
|
||
fun replaceRootInPath(p: String, projectRoot: String, workspaceRoot: String): String? { | ||
var path = p | ||
if (path.startsWith(projectRoot)) { | ||
path = path.replace(projectRoot, "{projectRoot}") | ||
return path | ||
} else if (path.startsWith(workspaceRoot)) { | ||
path = path.replace(workspaceRoot, "{workspaceRoot}") | ||
return path | ||
} | ||
return null | ||
} | ||
|
||
fun getDependenciesForProject(project: Project): MutableSet<Dependency> { | ||
var dependencies = mutableSetOf<Dependency>(); | ||
project.getConfigurations().filter { config -> | ||
val configName = config.name | ||
configName == "compileClasspath" || configName == "implementationDependenciesMetadata" | ||
}.forEach { | ||
it.getAllDependencies().filter { | ||
it is ProjectDependency | ||
}.forEach { | ||
dependencies.add( | ||
Dependency( | ||
project.getProjectDir().getPath(), | ||
it.getName(), | ||
project.getBuildFile().getPath() | ||
) | ||
) | ||
} | ||
} | ||
project.getSubprojects().forEach { childProject -> | ||
dependencies.add( | ||
Dependency( | ||
project.getProjectDir().getPath(), | ||
childProject.getProjectDir().getPath(), | ||
project.getBuildFile().getPath() | ||
) | ||
) | ||
} | ||
project.getGradle().includedBuilds.forEach { includedBuild -> | ||
dependencies.add( | ||
Dependency( | ||
project.getProjectDir().getPath(), | ||
includedBuild.getProjectDir().getPath(), | ||
project.getBuildFile().getPath() | ||
) | ||
) | ||
} | ||
return dependencies | ||
} |
Oops, something went wrong.