Skip to content
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

feat: refactor gradle graph calculation #839

Merged
merged 44 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
ea2af1a
feat: refactor gradle graph calculation
khalilou88 Feb 1, 2024
0948c8f
feat: work in progress
khalilou88 Feb 1, 2024
bd5ed13
build: work in progress
khalilou88 Feb 1, 2024
0108f44
build: work in progress
khalilou88 Feb 1, 2024
443c418
build: work in progress
khalilou88 Feb 1, 2024
25d8d94
build: work in progress
khalilou88 Feb 1, 2024
4670b3e
build: work in progress
khalilou88 Feb 1, 2024
789644f
build: work in progress
khalilou88 Feb 1, 2024
2534cf5
build: work in progress
khalilou88 Feb 1, 2024
a87eafc
build: work in progress
khalilou88 Feb 1, 2024
9398975
build: work in progress
khalilou88 Feb 1, 2024
99c6682
build: work in progress
khalilou88 Feb 1, 2024
027c60e
build: work in progress
khalilou88 Feb 1, 2024
7e79c50
build: work in progress
khalilou88 Feb 1, 2024
123fdb7
build: work in progress
khalilou88 Feb 1, 2024
847d50f
build: work in progress
khalilou88 Feb 1, 2024
ae4bf15
build: work in progress
khalilou88 Feb 1, 2024
a65cdf4
build: work in progress
khalilou88 Feb 1, 2024
fcfe2ef
build: work in progress
khalilou88 Feb 1, 2024
fba1fad
build: work in progress
khalilou88 Feb 1, 2024
51efb62
build: work in progress
khalilou88 Feb 1, 2024
93026e6
build: work in progress
khalilou88 Feb 1, 2024
4e405d0
build: work in progress
khalilou88 Feb 1, 2024
afba78a
build: work in progress
khalilou88 Feb 1, 2024
fd90ded
build: work in progress
khalilou88 Feb 1, 2024
9b25617
build: work in progress
khalilou88 Feb 1, 2024
2b58b0c
build: work in progress
khalilou88 Feb 1, 2024
d06813c
build: work in progress
khalilou88 Feb 1, 2024
6b65dc4
build: work in progress
khalilou88 Feb 1, 2024
f467fc8
build: work in progress
khalilou88 Feb 1, 2024
e7dead1
build: work in progress
khalilou88 Feb 2, 2024
74fa9a4
build: work in progress
khalilou88 Feb 2, 2024
0f7f95d
build: work in progress
khalilou88 Feb 2, 2024
70e4dc0
build: work in progress
khalilou88 Feb 2, 2024
985ac84
build: work in progress
khalilou88 Feb 2, 2024
f581e0f
build: work in progress
khalilou88 Feb 2, 2024
c5a8e3f
build: work in progress
khalilou88 Feb 2, 2024
dfdca80
build: work in progress
khalilou88 Feb 2, 2024
9c66bde
build: work in progress
khalilou88 Feb 2, 2024
8d18dc6
build: work in progress
khalilou88 Feb 2, 2024
6f4f931
build: work in progress
khalilou88 Feb 2, 2024
80de1f3
build: work in progress
khalilou88 Feb 2, 2024
80d5e86
build: work in progress
khalilou88 Feb 2, 2024
9bba00a
build: work in progress
khalilou88 Feb 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/plugin-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ on:
- nx-gradle quarkus kotlin dsl e2e
- nx-gradle spring-boot e2e
- nx-gradle spring-boot kotlin dsl e2e
- graph should works with optional project.json
- should use specified options to create an sb application
- should create a sb java application
- nx-maven
- nx-maven all bom e2e
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@ Thumbs.db
/packages/gradle-plugin/.idea/
/packages/gradle-plugin/bin/
/packages/gradle-plugin/build/
/packages/gradle-plugin/lib/
/packages/gradle-plugin/dist/

.nx/cache
4 changes: 4 additions & 0 deletions packages/common/src/lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ export type DependencyManagementType =
| 'spring-boot-parent-pom'
| 'micronaut-parent-pom';
export type VersionManagementType = 'properties' | 'version-catalog';
export interface TemplateOptionsType {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[k: string]: any;
}
2 changes: 1 addition & 1 deletion packages/common/src/lib/versions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const kspVersion = '1.9.21-1.0.16';
export const shadowVersion = '8.1.1';

//Jnxplus gradle plugin
export const jnxplusGradlePluginVersion = '0.2.2';
export const jnxplusGradlePluginVersion = '0.3.0';

//Prettier
export const prettierVersion = '^3.1.1';
Expand Down
2 changes: 1 addition & 1 deletion packages/gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ plugins {
}

group = 'io.github.khalilou88.jnxplus'
version = '0.2.2'
version = version

repositories {
// Use Maven Central for resolving dependencies.
Expand Down
1 change: 1 addition & 0 deletions packages/gradle-plugin/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version=0.3.0
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package io.github.khalilou88.jnxplus

import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import org.gradle.api.DefaultTask
import org.gradle.api.Project
import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.options.Option


abstract class ProjectDependencyTask extends DefaultTask {

@Option(option = "outputFile", description = "Output file")
Expand All @@ -19,44 +23,93 @@ abstract class ProjectDependencyTask extends DefaultTask {
println("Task ran for projectDependencyTask")
def projects = []

addProjects(project, projects, '', project)
addProjects(projects, '', project)


def result = [
pluginVersion: "0.3.0",
projects : projects
]

def json_str = JsonOutput.toJson(projects)
def json_str = JsonOutput.toJson(result)
def json_pretty = JsonOutput.prettyPrint(json_str)

//write file
def file = new File(getOutputFile().get())
file.write(json_pretty)
}

def addProjects(rootProject, projects, parentProjectName, project) {

def dependencies = project.configurations
.findAll { it.allDependencies }
.collectMany { it.dependencies }
.findAll { it instanceof ProjectDependency }
.collect { element ->
return [name : element.name,
relativePath : rootProject.relativePath(element.dependencyProject.projectDir),
isProjectJsonExists: element.dependencyProject.file('project.json').exists(),
isBuildGradleExists: element.dependencyProject.file('build.gradle').exists()]
def addProjects(projects, String parentProjectName, Project currentProject) {


boolean isBuildGradleExists = currentProject.file('build.gradle').exists()
boolean isBuildGradleKtsExists = currentProject.file('build.gradle.kts').exists()


if (isBuildGradleExists || isBuildGradleKtsExists) {
String projectName = currentProject.name

boolean isSettingsGradleExists = currentProject.file('settings.gradle').exists()
boolean isSettingsGradleKtsExists = currentProject.file('settings.gradle.kts').exists()
File projectJsonFile = currentProject.file('project.json')

boolean isProjectJsonExists = projectJsonFile.exists()
if (isProjectJsonExists) {
def projectJson = new JsonSlurper().parse(projectJsonFile)
projectName = projectJson.name
}

projects.add([name : project.name,
isProjectJsonExists : project.file('project.json').exists(),
isBuildGradleExists : project.file('build.gradle').exists(),
isBuildGradleKtsExists : project.file('build.gradle.kts').exists(),
isSettingsGradleExists : project.file('settings.gradle').exists(),
isSettingsGradleKtsExists: project.file('settings.gradle.kts').exists(),
isGradlePropertiesExists : project.file('gradle.properties').exists(),
relativePath : rootProject.relativePath(project.projectDir),
parentProjectName : parentProjectName,
dependencies : dependencies]);

project.childProjects.each { name, childProject ->

def dependencies = currentProject.configurations
.findAll { it.allDependencies }
.collectMany { it.dependencies }
.findAll { it instanceof ProjectDependency }
.findAll{it.name <=> currentProject.name}
.collect { Dependency element ->
{
element = (ProjectDependency) element

String projectDependencyName = element.name
File projectDependencyJsonFile = element.dependencyProject.file('project.json')
boolean isProjectDependencyJsonExists = projectDependencyJsonFile.exists()

if (isProjectDependencyJsonExists) {
def projectDependencyJson = new JsonSlurper().parse(projectDependencyJsonFile)
projectDependencyName = projectDependencyJson.name
}

return [relativePath : currentProject.rootProject.relativePath(element.dependencyProject.projectDir),
name : projectDependencyName,
isProjectJsonExists: isProjectDependencyJsonExists,
isBuildGradleExists: element.dependencyProject.file('build.gradle').exists()]
}
}


projects.add([relativePath : currentProject.rootProject.relativePath(currentProject.projectDir),
name : projectName,
isProjectJsonExists : isProjectJsonExists,
isBuildGradleExists : isBuildGradleExists,
isBuildGradleKtsExists : isBuildGradleKtsExists,
isSettingsGradleExists : isSettingsGradleExists,
isSettingsGradleKtsExists: isSettingsGradleKtsExists,
isGradlePropertiesExists : currentProject.file('gradle.properties').exists(),
parentProjectName : parentProjectName,
dependencies : dependencies])


if (isSettingsGradleExists || isSettingsGradleKtsExists) {
parentProjectName = projectName
}

}

currentProject.childProjects.each { name, childProject ->
{
addProjects(rootProject, projects, project.name, childProject)
addProjects(projects, parentProjectName, childProject)
}
}
}


}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { getProjectRoot } from '@jnxplus/common';
import { ExecutorContext, workspaceRoot } from '@nx/devkit';
import { execSync } from 'child_process';
import { SetVersionExecutorSchema } from './schema';

import * as fs from 'fs';
import * as path from 'path';
import { SetVersionExecutorSchema } from './schema';

export default async function runExecutor(
options: SetVersionExecutorSchema,
Expand Down
64 changes: 32 additions & 32 deletions packages/nx-gradle/src/generators/application/generator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
DSLType,
TemplateOptionsType,
VersionManagementType,
clearEmpties,
generateAppClassName,
Expand Down Expand Up @@ -131,30 +132,35 @@ function normalizeOptions(
}

function addFiles(tree: Tree, options: NormalizedSchema) {
const templateOptions = {
...options,
...names(options.name),
offsetFromRoot: offsetFromRoot(options.projectRoot),
template: '',
};

if (options.framework === 'spring-boot') {
addSpringBootFiles(tree, options);
addSpringBootFiles(tree, options, templateOptions);
}

if (options.framework === 'quarkus') {
addQuarkusFiles(tree, options);
addQuarkusFiles(tree, options, templateOptions);
}

if (options.framework === 'micronaut') {
addMicronautFiles(tree, options);
addMicronautFiles(tree, options, templateOptions);
}

if (options.framework === 'none') {
addNoneFiles(tree, options);
addNoneFiles(tree, options, templateOptions);
}
}

function addNoneFiles(tree: Tree, options: NormalizedSchema) {
const templateOptions = {
...options,
...names(options.name),
offsetFromRoot: offsetFromRoot(options.projectRoot),
template: '',
};
function addNoneFiles(
tree: Tree,
options: NormalizedSchema,
templateOptions: TemplateOptionsType,
) {
generateFiles(
tree,
path.join(__dirname, 'files', 'none', options.language),
Expand Down Expand Up @@ -188,13 +194,11 @@ function addNoneFiles(tree: Tree, options: NormalizedSchema) {
}
}

function addSpringBootFiles(tree: Tree, options: NormalizedSchema) {
const templateOptions = {
...options,
...names(options.name),
offsetFromRoot: offsetFromRoot(options.projectRoot),
template: '',
};
function addSpringBootFiles(
tree: Tree,
options: NormalizedSchema,
templateOptions: TemplateOptionsType,
) {
generateFiles(
tree,
path.join(__dirname, 'files', 'spring-boot', options.language),
Expand Down Expand Up @@ -246,13 +250,11 @@ function addSpringBootFiles(tree: Tree, options: NormalizedSchema) {
}
}

function addQuarkusFiles(tree: Tree, options: NormalizedSchema) {
const templateOptions = {
...options,
...names(options.name),
offsetFromRoot: offsetFromRoot(options.projectRoot),
template: '',
};
function addQuarkusFiles(
tree: Tree,
options: NormalizedSchema,
templateOptions: TemplateOptionsType,
) {
generateFiles(
tree,
path.join(__dirname, 'files', 'quarkus', options.language),
Expand Down Expand Up @@ -292,13 +294,11 @@ function addQuarkusFiles(tree: Tree, options: NormalizedSchema) {
}
}

function addMicronautFiles(tree: Tree, options: NormalizedSchema) {
const templateOptions = {
...options,
...names(options.name),
offsetFromRoot: offsetFromRoot(options.projectRoot),
template: '',
};
function addMicronautFiles(
tree: Tree,
options: NormalizedSchema,
templateOptions: TemplateOptionsType,
) {
generateFiles(
tree,
path.join(__dirname, 'files', 'micronaut', options.language),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ pluginManagement {
gradlePluginPortal()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
google()
<% if(generateRepositories) { -%>
mavenLocal()
<% } -%>
}

plugins {
Expand Down Expand Up @@ -34,4 +37,4 @@ dependencyResolutionManagement {
}

rootProject.name = "<%= rootProjectName %>"
<% } -%>
<% } -%>
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,22 @@ rootProject.name = "<%= rootProjectName %>"
<% } -%>
<% } -%>
<% if(versionManagement === 'version-catalog') { -%>
<% if(dsl === 'groovy') { -%>
pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
}
repositories {
mavenCentral()
gradlePluginPortal()
<% if(generateRepositories) { -%>
mavenLocal()
<% } -%>
}
}
<% if(dsl === 'groovy') { -%>
plugins {
id 'io.micronaut.platform.catalog' version "4.2.1"
}
rootProject.name = '<%= rootProjectName %>'
<% } -%>
<% if(dsl === 'kotlin') { -%>
pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
}
}
plugins {
id("io.micronaut.platform.catalog") version "4.2.1"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ rootProject.name = "<%= rootProjectName %>"
<% } -%>
<% } -%>
<% if(versionManagement === 'version-catalog') { -%>
<% if(generateRepositories) { -%>
pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
mavenLocal()
}
}
<% } -%>
<% if(dsl === 'groovy') { -%>
rootProject.name = '<%= rootProjectName %>'
<% } -%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ rootProject.name = "<%= rootProjectName %>"
<% } -%>
<% } -%>
<% if(versionManagement === 'version-catalog') { -%>
<% if(generateRepositories) { -%>
pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
mavenLocal()
}
}
<% } -%>
<% if(dsl === 'groovy') { -%>
rootProject.name = '<%= rootProjectName %>'
<% } -%>
Expand Down
Loading
Loading