-
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
29 changed files
with
1,146 additions
and
490 deletions.
There are no files selected for viewing
Binary file not shown.
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.1.0 |
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 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.5-bin.zip | ||
networkTimeout=10000 | ||
validateDistributionUrl=true | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
File renamed without changes.
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,68 @@ | ||
/* | ||
* 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() | ||
} | ||
|
||
testing { | ||
suites { | ||
// Configure the built-in test suite | ||
val test by getting(JvmTestSuite::class) { | ||
// Use Kotlin Test test framework | ||
useKotlinTest("1.9.20") | ||
} | ||
|
||
// Create a new test suite | ||
val functionalTest by registering(JvmTestSuite::class) { | ||
// Use Kotlin Test test framework | ||
useKotlinTest("1.9.20") | ||
|
||
dependencies { | ||
// functionalTest test suite depends on the production code in tests | ||
implementation(project()) | ||
} | ||
|
||
targets { | ||
all { | ||
// This test suite should run after the built-in test suite has run its tests | ||
testTask.configure { shouldRunAfter(test) } | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
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") | ||
} | ||
|
||
// gradlePlugin.testSourceSets.add(sourceSets["functionalTest"]) | ||
|
||
// tasks.named<Task>("check") { | ||
// Include functionalTest as part of the check lifecycle | ||
// dependsOn(testing.suites.named("functionalTest")) | ||
// } |
160 changes: 160 additions & 0 deletions
160
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,160 @@ | ||
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 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>) | ||
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: MutableList<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 | ||
var dependencies = mutableListOf<Dependency>(); | ||
project.getChildProjects().forEach { childProject -> | ||
dependencies.add( | ||
Dependency( | ||
project.getProjectDir().getPath(), | ||
childProject.value.getProjectDir().getPath(), | ||
project.getBuildFile().getPath() | ||
) | ||
) | ||
} | ||
project.getGradle().includedBuilds.forEach { includedBuild -> | ||
dependencies.add( | ||
Dependency( | ||
project.getProjectDir().getPath(), | ||
includedBuild.getProjectDir().getPath(), | ||
project.getBuildFile().getPath() | ||
) | ||
) | ||
} | ||
|
||
val gradleTargets = this.processTargetsForProject(project, workspaceRoot, rootProjectDirectory) | ||
var projectRoot = project.getProjectDir().getPath() | ||
val projectConfig = ProjectConfiguration( | ||
gradleTargets.targets, | ||
Metadata(gradleTargets.targetGroups, arrayOf("Gradle")), | ||
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 -> | ||
var path: String = file.getPath() | ||
path = replaceRootInPath(path, projectRoot, workspaceRoot) | ||
path | ||
}) | ||
} | ||
val outputs = task.getOutputs().getFiles() | ||
if (!outputs.isEmpty()) { | ||
target.put("outputs", outputs.map { file -> | ||
var path: String = file.getPath() | ||
path = replaceRootInPath(path, projectRoot, workspaceRoot) | ||
path | ||
}) | ||
} | ||
target.put("cache", true) | ||
|
||
val dependsOn = task.getTaskDependencies().getDependencies(task) | ||
if (!dependsOn.isEmpty()) { | ||
target.put("dependsOn", dependsOn.map { depTask -> "${depTask.getProject().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}") | ||
} else if (path.startsWith(workspaceRoot)) { | ||
path = path.replace(workspaceRoot, "{workspaceRoot}") | ||
} | ||
return path | ||
} |
21 changes: 21 additions & 0 deletions
21
packages/gradle/native/plugin/src/main/kotlin/io/nx/gradle/plugin/Nodes.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,21 @@ | ||
package io.nx.gradle.plugin | ||
|
||
import org.gradle.api.Project | ||
import org.gradle.api.Plugin | ||
|
||
/** | ||
* A plugin to create nx targets | ||
*/ | ||
class Nodes: Plugin<Project> { | ||
override fun apply(project: Project) { | ||
// Register a task | ||
project.tasks.register("createNodes", CreateNodesTask::class.java) { task -> | ||
task.setDescription("Create nodes and dependencies for Nx") | ||
task.setGroup("Nx Custom") | ||
// Run task for composite builds | ||
project.getGradle().includedBuilds.forEach { includedBuild -> | ||
task.dependsOn(includedBuild.task(":createNodes")) | ||
} | ||
} | ||
} | ||
} |
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,10 @@ | ||
/* | ||
* This file was generated by the Gradle 'init' task. | ||
* | ||
* The settings file is used to specify which projects to include in your build. | ||
* For more detailed information on multi-project builds, please refer to https://docs.gradle.org/8.5/userguide/building_swift_projects.html in the Gradle documentation. | ||
* This project uses @Incubating APIs which are subject to change. | ||
*/ | ||
|
||
rootProject.name = "plugin" | ||
include("plugin") |
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,2 @@ | ||
export { createDependencies } from './src/plugin-v1/dependencies'; | ||
export { createNodes, createNodesV2 } from './src/plugin-v1/nodes'; |
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,2 @@ | ||
export { createDependencies } from './src/plugin/dependencies'; | ||
export { createNodes, createNodesV2 } from './src/plugin/nodes'; | ||
export { createNodesV2 } from './src/plugin/nodes'; |
2 changes: 1 addition & 1 deletion
2
packages/gradle/src/migrations/20-2-0/add-include-subprojects-tasks.ts
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.
Oops, something went wrong.