@nx/gradle 23.3.0 → 24.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -6
- package/dist/batch-runner/build/libs/gradle-batch-runner-all.jar +0 -0
- package/dist/batch-runner/build/libs/gradle-batch-runner.jar +0 -0
- package/dist/src/migrations/update-24-0-0/migrate-plugin-v1-to-gradle.d.ts +4 -0
- package/dist/src/migrations/update-24-0-0/migrate-plugin-v1-to-gradle.js +38 -0
- package/dist/src/migrations/update-24-0-0/migrate-plugin-v1-to-gradle.md +46 -0
- package/migrations.json +6 -0
- package/package.json +3 -11
- package/readme-template.md +3 -3
- package/dist/plugin-v1.d.ts +0 -4
- package/dist/plugin-v1.js +0 -25
- package/dist/src/plugin-v1/dependencies.d.ts +0 -6
- package/dist/src/plugin-v1/dependencies.js +0 -68
- package/dist/src/plugin-v1/nodes.d.ts +0 -28
- package/dist/src/plugin-v1/nodes.js +0 -265
- package/dist/src/plugin-v1/utils/get-gradle-report.d.ts +0 -36
- package/dist/src/plugin-v1/utils/get-gradle-report.js +0 -279
- package/dist/src/plugin-v1/utils/get-project-report-lines.d.ts +0 -6
- package/dist/src/plugin-v1/utils/get-project-report-lines.js +0 -66
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
<p
|
|
1
|
+
<p align="center">
|
|
2
2
|
<picture>
|
|
3
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-
|
|
4
|
-
<img alt="Nx
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-logo-light.svg">
|
|
4
|
+
<img alt="Nx Logo" src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-logo.svg" width="140">
|
|
5
5
|
</picture>
|
|
6
6
|
</p>
|
|
7
7
|
|
|
@@ -64,6 +64,3 @@ npx nx@latest init
|
|
|
64
64
|
- [Official Nx YouTube Channel](https://www.youtube.com/@NxDevtools)
|
|
65
65
|
- [Blog Posts About Nx](https://nx.dev/blog)
|
|
66
66
|
|
|
67
|
-
<p style="text-align: center;"><a href="https://nx.dev/#learning-materials" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-courses-and-videos.svg"
|
|
68
|
-
width="100%" alt="Nx - Smart Monorepos · Fast Builds"></a></p>
|
|
69
|
-
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = update;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const gradle_project_graph_plugin_utils_1 = require("../../generators/init/gradle-project-graph-plugin-utils");
|
|
6
|
+
// `@nx/gradle` reads the project graph from this Gradle plugin, which v1 never applied.
|
|
7
|
+
const GRADLE_PROJECT_GRAPH_VERSION = '0.1.25';
|
|
8
|
+
async function update(tree) {
|
|
9
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
10
|
+
if (!nxJson?.plugins) {
|
|
11
|
+
return { skipAgentic: true };
|
|
12
|
+
}
|
|
13
|
+
let changed = false;
|
|
14
|
+
nxJson.plugins = nxJson.plugins.map((p) => {
|
|
15
|
+
if (p === '@nx/gradle/plugin-v1') {
|
|
16
|
+
changed = true;
|
|
17
|
+
return '@nx/gradle';
|
|
18
|
+
}
|
|
19
|
+
if (typeof p === 'string' || p.plugin !== '@nx/gradle/plugin-v1') {
|
|
20
|
+
return p;
|
|
21
|
+
}
|
|
22
|
+
changed = true;
|
|
23
|
+
p.plugin = '@nx/gradle';
|
|
24
|
+
const options = p.options;
|
|
25
|
+
if (options?.ciTargetName !== undefined) {
|
|
26
|
+
options.ciTestTargetName ??= options.ciTargetName;
|
|
27
|
+
delete options.ciTargetName;
|
|
28
|
+
}
|
|
29
|
+
delete options?.includeSubprojectsTasks;
|
|
30
|
+
return p;
|
|
31
|
+
});
|
|
32
|
+
if (!changed) {
|
|
33
|
+
return { skipAgentic: true };
|
|
34
|
+
}
|
|
35
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
36
|
+
await (0, gradle_project_graph_plugin_utils_1.addNxProjectGraphPlugin)(tree, GRADLE_PROJECT_GRAPH_VERSION);
|
|
37
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
38
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#### Replace `@nx/gradle/plugin-v1` with `@nx/gradle`
|
|
2
|
+
|
|
3
|
+
Nx 24 removes the `@nx/gradle/plugin-v1` entry point. This migration switches every `@nx/gradle/plugin-v1` registration in `nx.json` to `@nx/gradle`. It keeps each registration's position and its `include` and `exclude` patterns.
|
|
4
|
+
|
|
5
|
+
It also maps the plugin options:
|
|
6
|
+
|
|
7
|
+
- Renames `ciTargetName` to `ciTestTargetName`. An existing `ciTestTargetName` wins.
|
|
8
|
+
- Removes `includeSubprojectsTasks`, which `@nx/gradle` doesn't support.
|
|
9
|
+
- Keeps `testTargetName`, `buildTargetName`, `classesTargetName`, and other `<taskName>TargetName` options.
|
|
10
|
+
|
|
11
|
+
`@nx/gradle` reads the project graph from the `dev.nx.gradle.project-graph` Gradle plugin. The migration applies it in the `build.gradle` or `build.gradle.kts` file next to each `settings.gradle` or `settings.gradle.kts` file.
|
|
12
|
+
|
|
13
|
+
#### Sample code changes
|
|
14
|
+
|
|
15
|
+
##### Before
|
|
16
|
+
|
|
17
|
+
```json title="nx.json"
|
|
18
|
+
{
|
|
19
|
+
"plugins": [
|
|
20
|
+
{
|
|
21
|
+
"plugin": "@nx/gradle/plugin-v1",
|
|
22
|
+
"options": {
|
|
23
|
+
"testTargetName": "test",
|
|
24
|
+
"ciTargetName": "test-ci",
|
|
25
|
+
"includeSubprojectsTasks": false
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
##### After
|
|
33
|
+
|
|
34
|
+
```json title="nx.json"
|
|
35
|
+
{
|
|
36
|
+
"plugins": [
|
|
37
|
+
{
|
|
38
|
+
"plugin": "@nx/gradle",
|
|
39
|
+
"options": {
|
|
40
|
+
"testTargetName": "test",
|
|
41
|
+
"ciTestTargetName": "test-ci"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
```
|
package/migrations.json
CHANGED
|
@@ -186,6 +186,12 @@
|
|
|
186
186
|
"description": "Change dev.nx.gradle.project-graph to version 0.1.25 in build file",
|
|
187
187
|
"implementation": "./dist/src/migrations/23-2-0/change-plugin-version-0-1-25",
|
|
188
188
|
"documentation": "./dist/src/migrations/23-2-0/change-plugin-version-0-1-25.md"
|
|
189
|
+
},
|
|
190
|
+
"update-24-0-0-migrate-plugin-v1-to-gradle": {
|
|
191
|
+
"version": "24.0.0-beta.0",
|
|
192
|
+
"description": "Replace the removed `@nx/gradle/plugin-v1` plugin with `@nx/gradle` in `nx.json`, map its options, and apply the `dev.nx.gradle.project-graph` Gradle plugin.",
|
|
193
|
+
"implementation": "./dist/src/migrations/update-24-0-0/migrate-plugin-v1-to-gradle",
|
|
194
|
+
"documentation": "./dist/src/migrations/update-24-0-0/migrate-plugin-v1-to-gradle.md"
|
|
189
195
|
}
|
|
190
196
|
},
|
|
191
197
|
"packageJsonUpdates": {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/gradle",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "24.0.0-beta.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"files": [
|
|
@@ -27,9 +27,6 @@
|
|
|
27
27
|
"types": "./dist/index.d.ts",
|
|
28
28
|
"typesVersions": {
|
|
29
29
|
"*": {
|
|
30
|
-
"plugin-v1": [
|
|
31
|
-
"dist/plugin-v1.d.ts"
|
|
32
|
-
],
|
|
33
30
|
"src/*": [
|
|
34
31
|
"dist/src/*.d.ts"
|
|
35
32
|
],
|
|
@@ -51,11 +48,6 @@
|
|
|
51
48
|
"types": "./dist/index.d.ts",
|
|
52
49
|
"default": "./dist/index.js"
|
|
53
50
|
},
|
|
54
|
-
"./plugin-v1": {
|
|
55
|
-
"@nx/nx-source": "./plugin-v1.ts",
|
|
56
|
-
"types": "./dist/plugin-v1.d.ts",
|
|
57
|
-
"default": "./dist/plugin-v1.js"
|
|
58
|
-
},
|
|
59
51
|
"./package.json": "./package.json",
|
|
60
52
|
"./migrations.json": "./migrations.json",
|
|
61
53
|
"./generators.json": "./generators.json",
|
|
@@ -75,12 +67,12 @@
|
|
|
75
67
|
"supportsOptionalMigrations": true
|
|
76
68
|
},
|
|
77
69
|
"dependencies": {
|
|
78
|
-
"@nx/devkit": "
|
|
70
|
+
"@nx/devkit": "24.0.0-beta.0",
|
|
79
71
|
"toml-eslint-parser": "^0.10.0",
|
|
80
72
|
"tslib": "^2.3.0"
|
|
81
73
|
},
|
|
82
74
|
"devDependencies": {
|
|
83
|
-
"nx": "
|
|
75
|
+
"nx": "24.0.0-beta.0"
|
|
84
76
|
},
|
|
85
77
|
"publishConfig": {
|
|
86
78
|
"access": "public"
|
package/readme-template.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
<p
|
|
1
|
+
<p align="center">
|
|
2
2
|
<picture>
|
|
3
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-
|
|
4
|
-
<img alt="Nx
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-logo-light.svg">
|
|
4
|
+
<img alt="Nx Logo" src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-logo.svg" width="140">
|
|
5
5
|
</picture>
|
|
6
6
|
</p>
|
|
7
7
|
|
package/dist/plugin-v1.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
/** @deprecated Use `@nx/gradle` instead. This entry will be removed in Nx 24. */
|
|
2
|
-
export { createDependencies } from './src/plugin-v1/dependencies';
|
|
3
|
-
/** @deprecated Use `@nx/gradle` instead. This entry will be removed in Nx 24. */
|
|
4
|
-
export { createNodes, createNodesV2 } from './src/plugin-v1/nodes';
|
package/dist/plugin-v1.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createNodesV2 = exports.createNodes = exports.createDependencies = void 0;
|
|
4
|
-
const internal_1 = require("@nx/devkit/internal");
|
|
5
|
-
// TODO(v24): remove `@nx/gradle/plugin-v1` entirely. Users should be migrated
|
|
6
|
-
// to `@nx/gradle` (the atomized v2 plugin) via the removal migration shipped
|
|
7
|
-
// alongside the deletion.
|
|
8
|
-
//
|
|
9
|
-
// Use emitPluginWorkerLog so the warning surfaces to the user even when the
|
|
10
|
-
// daemon is enabled — `logger.warn` would route to the daemon log file and
|
|
11
|
-
// be silently swallowed. Guard against older nx versions (< 22.7) where this
|
|
12
|
-
// helper may not exist; @nx/devkit supports nx at +/-1 major.
|
|
13
|
-
if (typeof internal_1.emitPluginWorkerLog === 'function') {
|
|
14
|
-
(0, internal_1.emitPluginWorkerLog)('warn', '`@nx/gradle/plugin-v1` is deprecated and will be removed in Nx 24. ' +
|
|
15
|
-
'Switch your `nx.json` plugins entry from `@nx/gradle/plugin-v1` to `@nx/gradle`. ' +
|
|
16
|
-
'Note that the default `@nx/gradle` plugin generates atomized targets — ' +
|
|
17
|
-
'see https://nx.dev/nx-api/gradle for configuration options.');
|
|
18
|
-
}
|
|
19
|
-
/** @deprecated Use `@nx/gradle` instead. This entry will be removed in Nx 24. */
|
|
20
|
-
var dependencies_1 = require("./src/plugin-v1/dependencies");
|
|
21
|
-
Object.defineProperty(exports, "createDependencies", { enumerable: true, get: function () { return dependencies_1.createDependencies; } });
|
|
22
|
-
/** @deprecated Use `@nx/gradle` instead. This entry will be removed in Nx 24. */
|
|
23
|
-
var nodes_1 = require("./src/plugin-v1/nodes");
|
|
24
|
-
Object.defineProperty(exports, "createNodes", { enumerable: true, get: function () { return nodes_1.createNodes; } });
|
|
25
|
-
Object.defineProperty(exports, "createNodesV2", { enumerable: true, get: function () { return nodes_1.createNodesV2; } });
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createDependencies = void 0;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const node_path_1 = require("node:path");
|
|
6
|
-
const get_gradle_report_1 = require("./utils/get-gradle-report");
|
|
7
|
-
const split_config_files_1 = require("../utils/split-config-files");
|
|
8
|
-
/**
|
|
9
|
-
* @deprecated The `@nx/gradle/plugin-v1` entry is deprecated and will be removed in Nx 24.
|
|
10
|
-
* Switch to the default `@nx/gradle` plugin.
|
|
11
|
-
*/
|
|
12
|
-
const createDependencies = async (_, context) => {
|
|
13
|
-
const gradleFiles = findGradleFiles(context.filesToProcess);
|
|
14
|
-
if (gradleFiles.length === 0) {
|
|
15
|
-
return [];
|
|
16
|
-
}
|
|
17
|
-
const gradleDependenciesStart = performance.mark('gradleDependencies:start');
|
|
18
|
-
const { gradleFileToGradleProjectMap, gradleProjectNameToProjectRootMap, gradleProjectToDepsMap, gradleProjectToChildProjects, } = (0, get_gradle_report_1.getCurrentGradleReport)();
|
|
19
|
-
const dependencies = new Set();
|
|
20
|
-
for (const gradleFile of gradleFiles) {
|
|
21
|
-
const gradleProject = gradleFileToGradleProjectMap.get(gradleFile);
|
|
22
|
-
const projectName = Object.values(context.projects).find((project) => project.root === (0, node_path_1.dirname)(gradleFile))?.name;
|
|
23
|
-
const dependedProjects = gradleProjectToDepsMap.get(gradleProject);
|
|
24
|
-
if (projectName && dependedProjects?.size) {
|
|
25
|
-
dependedProjects?.forEach((dependedProject) => {
|
|
26
|
-
const targetProjectRoot = gradleProjectNameToProjectRootMap.get(dependedProject);
|
|
27
|
-
const targetProjectName = Object.values(context.projects).find((project) => project.root === targetProjectRoot)?.name;
|
|
28
|
-
if (targetProjectName) {
|
|
29
|
-
const dependency = {
|
|
30
|
-
source: projectName,
|
|
31
|
-
target: targetProjectName,
|
|
32
|
-
type: devkit_1.DependencyType.static,
|
|
33
|
-
sourceFile: gradleFile,
|
|
34
|
-
};
|
|
35
|
-
(0, devkit_1.validateDependency)(dependency, context);
|
|
36
|
-
dependencies.add(dependency);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
gradleProjectToChildProjects.get(gradleProject)?.forEach((childProject) => {
|
|
41
|
-
if (childProject) {
|
|
42
|
-
const dependency = {
|
|
43
|
-
source: projectName,
|
|
44
|
-
target: childProject,
|
|
45
|
-
type: devkit_1.DependencyType.static,
|
|
46
|
-
sourceFile: gradleFile,
|
|
47
|
-
};
|
|
48
|
-
(0, devkit_1.validateDependency)(dependency, context);
|
|
49
|
-
dependencies.add(dependency);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
const gradleDependenciesEnd = performance.mark('gradleDependencies:end');
|
|
54
|
-
performance.measure('gradleDependencies', gradleDependenciesStart.name, gradleDependenciesEnd.name);
|
|
55
|
-
return Array.from(dependencies);
|
|
56
|
-
};
|
|
57
|
-
exports.createDependencies = createDependencies;
|
|
58
|
-
function findGradleFiles(fileMap) {
|
|
59
|
-
const gradleFiles = [];
|
|
60
|
-
for (const [_, files] of Object.entries(fileMap.projectFileMap)) {
|
|
61
|
-
for (const file of files) {
|
|
62
|
-
if (split_config_files_1.GRADLE_BUILD_FILES.has((0, node_path_1.basename)(file.file))) {
|
|
63
|
-
gradleFiles.push(file.file);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return gradleFiles;
|
|
68
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { PluginCache } from '@nx/devkit/internal';
|
|
2
|
-
import { CreateNodes, CreateNodesContext, ProjectConfiguration } from '@nx/devkit';
|
|
3
|
-
import { GradleReport } from './utils/get-gradle-report';
|
|
4
|
-
export interface GradlePluginOptions {
|
|
5
|
-
includeSubprojectsTasks?: boolean;
|
|
6
|
-
ciTargetName?: string;
|
|
7
|
-
testTargetName?: string;
|
|
8
|
-
classesTargetName?: string;
|
|
9
|
-
buildTargetName?: string;
|
|
10
|
-
[taskTargetName: string]: string | undefined | boolean;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* @deprecated The `@nx/gradle/plugin-v1` entry is deprecated and will be removed in Nx 24.
|
|
14
|
-
* Switch to the default `@nx/gradle` plugin.
|
|
15
|
-
*/
|
|
16
|
-
export declare const createNodesV2: CreateNodes<GradlePluginOptions>;
|
|
17
|
-
export declare const makeCreateNodesForGradleConfigFile: (gradleReport: GradleReport, pluginCache: PluginCache<Partial<ProjectConfiguration>>, gradleProjectRootToTestFilesMap?: Record<string, string[]>, hashes?: string[]) => (gradleFilePath: any, options: GradlePluginOptions | undefined, context: CreateNodesContext, idx?: number) => Promise<{
|
|
18
|
-
projects?: undefined;
|
|
19
|
-
} | {
|
|
20
|
-
projects: {
|
|
21
|
-
[x: string]: Partial<ProjectConfiguration>;
|
|
22
|
-
};
|
|
23
|
-
}>;
|
|
24
|
-
/**
|
|
25
|
-
@deprecated This is replaced with {@link createNodesV2}. Update your plugin to export its own `createNodesV2` function that wraps this one instead.
|
|
26
|
-
This function will change to the v2 function in Nx 20.
|
|
27
|
-
*/
|
|
28
|
-
export declare const createNodes: CreateNodes<GradlePluginOptions>;
|
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createNodes = exports.makeCreateNodesForGradleConfigFile = exports.createNodesV2 = void 0;
|
|
4
|
-
const internal_1 = require("@nx/devkit/internal");
|
|
5
|
-
const devkit_1 = require("@nx/devkit");
|
|
6
|
-
const node_path_1 = require("node:path");
|
|
7
|
-
const get_gradle_report_1 = require("./utils/get-gradle-report");
|
|
8
|
-
const split_config_files_1 = require("../utils/split-config-files");
|
|
9
|
-
const exec_gradle_1 = require("../utils/exec-gradle");
|
|
10
|
-
const cacheableTaskType = new Set(['Build', 'Verification']);
|
|
11
|
-
const dependsOnMap = {
|
|
12
|
-
build: ['^build', 'classes', 'test'],
|
|
13
|
-
testClasses: ['classes'],
|
|
14
|
-
test: ['testClasses'],
|
|
15
|
-
classes: ['^classes'],
|
|
16
|
-
};
|
|
17
|
-
function normalizeOptions(options) {
|
|
18
|
-
options ??= {};
|
|
19
|
-
options.testTargetName ??= 'test';
|
|
20
|
-
options.classesTargetName ??= 'classes';
|
|
21
|
-
options.buildTargetName ??= 'build';
|
|
22
|
-
return options;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* @deprecated The `@nx/gradle/plugin-v1` entry is deprecated and will be removed in Nx 24.
|
|
26
|
-
* Switch to the default `@nx/gradle` plugin.
|
|
27
|
-
*/
|
|
28
|
-
exports.createNodesV2 = [
|
|
29
|
-
split_config_files_1.gradleConfigAndTestGlob,
|
|
30
|
-
async (files, options, context) => {
|
|
31
|
-
const { buildFiles, projectRoots, gradlewFiles, testFiles } = (0, split_config_files_1.splitConfigFiles)(files);
|
|
32
|
-
const optionsHash = (0, internal_1.hashObject)(options);
|
|
33
|
-
const cachePath = (0, node_path_1.join)(internal_1.workspaceDataDirectory, `gradle-${optionsHash}.hash`);
|
|
34
|
-
const pluginCache = new internal_1.PluginCache(cachePath);
|
|
35
|
-
await (0, get_gradle_report_1.populateGradleReport)(context.workspaceRoot, gradlewFiles.map((f) => (0, node_path_1.join)(context.workspaceRoot, f)));
|
|
36
|
-
const gradleReport = (0, get_gradle_report_1.getCurrentGradleReport)();
|
|
37
|
-
const gradleProjectRootToTestFilesMap = getGradleProjectRootToTestFilesMap(testFiles, projectRoots);
|
|
38
|
-
try {
|
|
39
|
-
const buildFileProjectRoots = buildFiles.map((f) => (0, node_path_1.dirname)(f));
|
|
40
|
-
const buildFileHashes = await (0, internal_1.calculateHashesForCreateNodes)(buildFileProjectRoots, normalizeOptions(options) ?? {}, context);
|
|
41
|
-
return (0, devkit_1.createNodesFromFiles)((0, exports.makeCreateNodesForGradleConfigFile)(gradleReport, pluginCache, gradleProjectRootToTestFilesMap, buildFileHashes), buildFiles, options, context);
|
|
42
|
-
}
|
|
43
|
-
finally {
|
|
44
|
-
pluginCache.writeToDisk();
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
];
|
|
48
|
-
const makeCreateNodesForGradleConfigFile = (gradleReport, pluginCache, gradleProjectRootToTestFilesMap = {}, hashes) => async (gradleFilePath, options, context, idx) => {
|
|
49
|
-
const projectRoot = (0, node_path_1.dirname)(gradleFilePath);
|
|
50
|
-
options = normalizeOptions(options);
|
|
51
|
-
let hash;
|
|
52
|
-
if (hashes && idx !== undefined) {
|
|
53
|
-
hash = hashes[idx];
|
|
54
|
-
if (hash === undefined) {
|
|
55
|
-
throw new Error(`Failed to compute hash for gradle project at ${projectRoot}`);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
const [computed] = await (0, internal_1.calculateHashesForCreateNodes)([projectRoot], options ?? {}, context);
|
|
60
|
-
if (computed === undefined) {
|
|
61
|
-
throw new Error(`Failed to compute hash for gradle project at ${projectRoot}`);
|
|
62
|
-
}
|
|
63
|
-
hash = computed;
|
|
64
|
-
}
|
|
65
|
-
if (!pluginCache.has(hash)) {
|
|
66
|
-
pluginCache.set(hash, await createGradleProject(gradleReport, gradleFilePath, options, context, gradleProjectRootToTestFilesMap[projectRoot]));
|
|
67
|
-
}
|
|
68
|
-
const project = pluginCache.get(hash);
|
|
69
|
-
if (!project) {
|
|
70
|
-
return {};
|
|
71
|
-
}
|
|
72
|
-
return {
|
|
73
|
-
projects: {
|
|
74
|
-
[projectRoot]: project,
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
};
|
|
78
|
-
exports.makeCreateNodesForGradleConfigFile = makeCreateNodesForGradleConfigFile;
|
|
79
|
-
/**
|
|
80
|
-
@deprecated This is replaced with {@link createNodesV2}. Update your plugin to export its own `createNodesV2` function that wraps this one instead.
|
|
81
|
-
This function will change to the v2 function in Nx 20.
|
|
82
|
-
*/
|
|
83
|
-
exports.createNodes = exports.createNodesV2;
|
|
84
|
-
async function createGradleProject(gradleReport, gradleFilePath, options, context, testFiles = []) {
|
|
85
|
-
try {
|
|
86
|
-
const { gradleProjectToTasksTypeMap, gradleProjectToTasksMap, gradleFileToOutputDirsMap, gradleFileToGradleProjectMap, gradleProjectToProjectName, } = gradleReport;
|
|
87
|
-
const gradleProject = gradleFileToGradleProjectMap.get(gradleFilePath);
|
|
88
|
-
const projectName = gradleProjectToProjectName.get(gradleProject);
|
|
89
|
-
if (!projectName) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
const tasksTypeMap = gradleProjectToTasksTypeMap.get(gradleProject);
|
|
93
|
-
const tasksSet = gradleProjectToTasksMap.get(gradleProject);
|
|
94
|
-
let tasks = [];
|
|
95
|
-
tasksSet.forEach((taskName) => {
|
|
96
|
-
tasks.push({
|
|
97
|
-
type: tasksTypeMap?.get(taskName),
|
|
98
|
-
name: taskName,
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
if (options.includeSubprojectsTasks) {
|
|
102
|
-
tasksTypeMap.forEach((taskType, taskName) => {
|
|
103
|
-
if (!tasksSet.has(taskName)) {
|
|
104
|
-
tasks.push({
|
|
105
|
-
type: taskType,
|
|
106
|
-
name: taskName,
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
const outputDirs = gradleFileToOutputDirsMap.get(gradleFilePath);
|
|
112
|
-
const { targets, targetGroups } = await createGradleTargets(tasks, options, context, outputDirs, gradleProject, gradleFilePath, testFiles);
|
|
113
|
-
const project = {
|
|
114
|
-
name: projectName,
|
|
115
|
-
projectType: 'application',
|
|
116
|
-
targets,
|
|
117
|
-
metadata: {
|
|
118
|
-
targetGroups,
|
|
119
|
-
technologies: ['gradle'],
|
|
120
|
-
},
|
|
121
|
-
};
|
|
122
|
-
return project;
|
|
123
|
-
}
|
|
124
|
-
catch (e) {
|
|
125
|
-
console.error(e);
|
|
126
|
-
return undefined;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
async function createGradleTargets(tasks, options, context, outputDirs, gradleProject, gradleBuildFilePath, testFiles = []) {
|
|
130
|
-
const inputsMap = createInputsMap(context);
|
|
131
|
-
const gradlewFileDirectory = (0, node_path_1.dirname)((0, exec_gradle_1.findGradlewFile)(gradleBuildFilePath, context.workspaceRoot));
|
|
132
|
-
const targets = {};
|
|
133
|
-
const targetGroups = {};
|
|
134
|
-
for (const task of tasks) {
|
|
135
|
-
const targetName = options?.[`${task.name}TargetName`] ?? task.name;
|
|
136
|
-
let outputs = [outputDirs.get(task.name)].filter(Boolean);
|
|
137
|
-
if (task.name === 'test') {
|
|
138
|
-
outputs = [
|
|
139
|
-
outputDirs.get('testReport'),
|
|
140
|
-
outputDirs.get('testResults'),
|
|
141
|
-
].filter(Boolean);
|
|
142
|
-
getTestCiTargets(testFiles, gradleProject, targetName, options.ciTargetName, inputsMap['test'], outputs, task.type, targets, targetGroups, gradlewFileDirectory);
|
|
143
|
-
}
|
|
144
|
-
const taskCommandToRun = `${gradleProject ? gradleProject + ':' : ''}${task.name}`;
|
|
145
|
-
targets[targetName] = {
|
|
146
|
-
command: `${(0, exec_gradle_1.getGradleExecFile)()} ${taskCommandToRun}`,
|
|
147
|
-
options: {
|
|
148
|
-
cwd: gradlewFileDirectory,
|
|
149
|
-
},
|
|
150
|
-
cache: cacheableTaskType.has(task.type),
|
|
151
|
-
inputs: inputsMap[task.name],
|
|
152
|
-
dependsOn: dependsOnMap[task.name],
|
|
153
|
-
metadata: {
|
|
154
|
-
technologies: ['gradle'],
|
|
155
|
-
help: {
|
|
156
|
-
command: `${(0, exec_gradle_1.getGradleExecFile)()} help --task ${taskCommandToRun}`,
|
|
157
|
-
example: {
|
|
158
|
-
options: {
|
|
159
|
-
args: ['--rerun'],
|
|
160
|
-
},
|
|
161
|
-
},
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
...(outputs && outputs.length ? { outputs } : {}),
|
|
165
|
-
};
|
|
166
|
-
if (task.type) {
|
|
167
|
-
if (!targetGroups[task.type]) {
|
|
168
|
-
targetGroups[task.type] = [];
|
|
169
|
-
}
|
|
170
|
-
targetGroups[task.type].push(targetName);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return { targetGroups, targets };
|
|
174
|
-
}
|
|
175
|
-
function createInputsMap(context) {
|
|
176
|
-
const namedInputs = context.nxJsonConfiguration.namedInputs;
|
|
177
|
-
return {
|
|
178
|
-
build: namedInputs?.production
|
|
179
|
-
? ['production', '^production']
|
|
180
|
-
: ['default', '^default'],
|
|
181
|
-
test: ['default', namedInputs?.production ? '^production' : '^default'],
|
|
182
|
-
classes: namedInputs?.production
|
|
183
|
-
? ['production', '^production']
|
|
184
|
-
: ['default', '^default'],
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
function getTestCiTargets(testFiles, gradleProject, testTargetName, ciTargetName, inputs, outputs, targetGroupName, targets, targetGroups, gradlewFileDirectory) {
|
|
188
|
-
if (!testFiles || testFiles.length === 0 || !ciTargetName) {
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
const taskCommandToRun = `${gradleProject ? gradleProject + ':' : ''}test`;
|
|
192
|
-
if (!targetGroups[targetGroupName]) {
|
|
193
|
-
targetGroups[targetGroupName] = [];
|
|
194
|
-
}
|
|
195
|
-
const dependsOn = [];
|
|
196
|
-
testFiles.forEach((testFile) => {
|
|
197
|
-
const testName = (0, node_path_1.basename)(testFile).split('.')[0];
|
|
198
|
-
const targetName = ciTargetName + '--' + testName;
|
|
199
|
-
targets[targetName] = {
|
|
200
|
-
command: `${(0, exec_gradle_1.getGradleExecFile)()} ${taskCommandToRun} --tests ${testName}`,
|
|
201
|
-
options: {
|
|
202
|
-
cwd: gradlewFileDirectory,
|
|
203
|
-
},
|
|
204
|
-
cache: true,
|
|
205
|
-
inputs,
|
|
206
|
-
dependsOn: dependsOnMap['test'],
|
|
207
|
-
metadata: {
|
|
208
|
-
technologies: ['gradle'],
|
|
209
|
-
description: `Runs Gradle test ${testFile} in CI`,
|
|
210
|
-
help: {
|
|
211
|
-
command: `${(0, exec_gradle_1.getGradleExecFile)()} help --task ${taskCommandToRun}`,
|
|
212
|
-
example: {
|
|
213
|
-
options: {
|
|
214
|
-
args: ['--rerun'],
|
|
215
|
-
},
|
|
216
|
-
},
|
|
217
|
-
},
|
|
218
|
-
},
|
|
219
|
-
...(outputs && outputs.length > 0 ? { outputs } : {}),
|
|
220
|
-
};
|
|
221
|
-
targetGroups[targetGroupName].push(targetName);
|
|
222
|
-
dependsOn.push({
|
|
223
|
-
target: targetName,
|
|
224
|
-
params: 'forward',
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
targets[ciTargetName] = {
|
|
228
|
-
executor: 'nx:noop',
|
|
229
|
-
cache: true,
|
|
230
|
-
inputs,
|
|
231
|
-
dependsOn: dependsOn,
|
|
232
|
-
...(outputs && outputs.length > 0 ? { outputs } : {}),
|
|
233
|
-
metadata: {
|
|
234
|
-
technologies: ['gradle'],
|
|
235
|
-
description: 'Runs Gradle Tests in CI',
|
|
236
|
-
nonAtomizedTarget: testTargetName,
|
|
237
|
-
help: {
|
|
238
|
-
command: `${(0, exec_gradle_1.getGradleExecFile)()} help --task ${taskCommandToRun}`,
|
|
239
|
-
example: {
|
|
240
|
-
options: {
|
|
241
|
-
args: ['--rerun'],
|
|
242
|
-
},
|
|
243
|
-
},
|
|
244
|
-
},
|
|
245
|
-
},
|
|
246
|
-
};
|
|
247
|
-
targetGroups[targetGroupName].push(ciTargetName);
|
|
248
|
-
}
|
|
249
|
-
function getGradleProjectRootToTestFilesMap(testFiles, projectRoots) {
|
|
250
|
-
if (testFiles.length === 0 || projectRoots.length === 0) {
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
const roots = new Map(projectRoots.map((root) => [root, root]));
|
|
254
|
-
const testFilesToGradleProjectMap = {};
|
|
255
|
-
testFiles.forEach((testFile) => {
|
|
256
|
-
const projectRoot = (0, internal_1.findProjectForPath)(testFile, roots);
|
|
257
|
-
if (projectRoot) {
|
|
258
|
-
if (!testFilesToGradleProjectMap[projectRoot]) {
|
|
259
|
-
testFilesToGradleProjectMap[projectRoot] = [];
|
|
260
|
-
}
|
|
261
|
-
testFilesToGradleProjectMap[projectRoot].push(testFile);
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
return testFilesToGradleProjectMap;
|
|
265
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export interface GradleReport {
|
|
2
|
-
gradleFileToGradleProjectMap: Map<string, string>;
|
|
3
|
-
gradleFileToOutputDirsMap: Map<string, Map<string, string>>;
|
|
4
|
-
gradleProjectToDepsMap: Map<string, Set<string>>;
|
|
5
|
-
gradleProjectToTasksTypeMap: Map<string, Map<string, string>>;
|
|
6
|
-
gradleProjectToTasksMap: Map<string, Set<string>>;
|
|
7
|
-
gradleProjectToProjectName: Map<string, string>;
|
|
8
|
-
gradleProjectNameToProjectRootMap: Map<string, string>;
|
|
9
|
-
gradleProjectToChildProjects: Map<string, string[]>;
|
|
10
|
-
}
|
|
11
|
-
export interface GradleReportJSON {
|
|
12
|
-
hash: string;
|
|
13
|
-
gradleFileToGradleProjectMap: Record<string, string>;
|
|
14
|
-
gradleProjectToDepsMap: Record<string, Array<string>>;
|
|
15
|
-
gradleFileToOutputDirsMap: Record<string, Record<string, string>>;
|
|
16
|
-
gradleProjectToTasksTypeMap: Record<string, Record<string, string>>;
|
|
17
|
-
gradleProjectToTasksMap: Record<string, Array<string>>;
|
|
18
|
-
gradleProjectToProjectName: Record<string, string>;
|
|
19
|
-
gradleProjectNameToProjectRootMap: Record<string, string>;
|
|
20
|
-
gradleProjectToChildProjects: Record<string, string[]>;
|
|
21
|
-
}
|
|
22
|
-
export declare function writeGradleReportToCache(cachePath: string, results: GradleReport, hash: string): void;
|
|
23
|
-
export declare function getCurrentGradleReport(): GradleReport;
|
|
24
|
-
/**
|
|
25
|
-
* This function populates the gradle report cache.
|
|
26
|
-
* For each gradlew file, it runs the `projectReportAll` task and processes the output.
|
|
27
|
-
* If `projectReportAll` fails, it runs the `projectReport` task instead.
|
|
28
|
-
* It will throw an error if both tasks fail.
|
|
29
|
-
* It will accumulate the output of all gradlew files.
|
|
30
|
-
* @param workspaceRoot
|
|
31
|
-
* @param gradlewFiles absolute paths to all gradlew files in the workspace
|
|
32
|
-
* @returns Promise<void>
|
|
33
|
-
*/
|
|
34
|
-
export declare function populateGradleReport(workspaceRoot: string, gradlewFiles: string[]): Promise<void>;
|
|
35
|
-
export declare function processProjectReports(projectReportLines: string[]): GradleReport;
|
|
36
|
-
export declare function processGradleDependencies(depsFile: string): Set<string>;
|
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.writeGradleReportToCache = writeGradleReportToCache;
|
|
4
|
-
exports.getCurrentGradleReport = getCurrentGradleReport;
|
|
5
|
-
exports.populateGradleReport = populateGradleReport;
|
|
6
|
-
exports.processProjectReports = processProjectReports;
|
|
7
|
-
exports.processGradleDependencies = processGradleDependencies;
|
|
8
|
-
const node_fs_1 = require("node:fs");
|
|
9
|
-
const node_path_1 = require("node:path");
|
|
10
|
-
const devkit_1 = require("@nx/devkit");
|
|
11
|
-
const path_1 = require("path");
|
|
12
|
-
const split_config_files_1 = require("../../utils/split-config-files");
|
|
13
|
-
const get_project_report_lines_1 = require("./get-project-report-lines");
|
|
14
|
-
const exec_gradle_1 = require("../../utils/exec-gradle");
|
|
15
|
-
const internal_1 = require("@nx/devkit/internal");
|
|
16
|
-
function readGradleReportCache(cachePath, hash) {
|
|
17
|
-
const gradleReportJson = (0, node_fs_1.existsSync)(cachePath)
|
|
18
|
-
? (0, devkit_1.readJsonFile)(cachePath)
|
|
19
|
-
: undefined;
|
|
20
|
-
if (!gradleReportJson || gradleReportJson.hash !== hash) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
let results = {
|
|
24
|
-
gradleFileToGradleProjectMap: new Map(Object.entries(gradleReportJson['gradleFileToGradleProjectMap'])),
|
|
25
|
-
gradleProjectToDepsMap: new Map(Object.entries(gradleReportJson['gradleProjectToDepsMap']).map(([key, value]) => [key, new Set(value)])),
|
|
26
|
-
gradleFileToOutputDirsMap: new Map(Object.entries(gradleReportJson['gradleFileToOutputDirsMap']).map(([key, value]) => [key, new Map(Object.entries(value))])),
|
|
27
|
-
gradleProjectToTasksTypeMap: new Map(Object.entries(gradleReportJson['gradleProjectToTasksTypeMap']).map(([key, value]) => [key, new Map(Object.entries(value))])),
|
|
28
|
-
gradleProjectToTasksMap: new Map(Object.entries(gradleReportJson['gradleProjectToTasksMap']).map(([key, value]) => [key, new Set(value)])),
|
|
29
|
-
gradleProjectToProjectName: new Map(Object.entries(gradleReportJson['gradleProjectToProjectName'])),
|
|
30
|
-
gradleProjectNameToProjectRootMap: new Map(Object.entries(gradleReportJson['gradleProjectNameToProjectRootMap'])),
|
|
31
|
-
gradleProjectToChildProjects: new Map(Object.entries(gradleReportJson['gradleProjectToChildProjects'])),
|
|
32
|
-
};
|
|
33
|
-
return results;
|
|
34
|
-
}
|
|
35
|
-
function writeGradleReportToCache(cachePath, results, hash) {
|
|
36
|
-
let gradleReportJson = {
|
|
37
|
-
hash,
|
|
38
|
-
gradleFileToGradleProjectMap: Object.fromEntries(results.gradleFileToGradleProjectMap),
|
|
39
|
-
gradleProjectToDepsMap: Object.fromEntries(Array.from(results.gradleProjectToDepsMap).map(([key, value]) => [
|
|
40
|
-
key,
|
|
41
|
-
Array.from(value),
|
|
42
|
-
])),
|
|
43
|
-
gradleFileToOutputDirsMap: Object.fromEntries(Array.from(results.gradleFileToOutputDirsMap).map(([key, value]) => [
|
|
44
|
-
key,
|
|
45
|
-
Object.fromEntries(value),
|
|
46
|
-
])),
|
|
47
|
-
gradleProjectToTasksTypeMap: Object.fromEntries(Array.from(results.gradleProjectToTasksTypeMap).map(([key, value]) => [
|
|
48
|
-
key,
|
|
49
|
-
Object.fromEntries(value),
|
|
50
|
-
])),
|
|
51
|
-
gradleProjectToTasksMap: Object.fromEntries(Array.from(results.gradleProjectToTasksMap).map(([key, value]) => [
|
|
52
|
-
key,
|
|
53
|
-
Array.from(value),
|
|
54
|
-
])),
|
|
55
|
-
gradleProjectToProjectName: Object.fromEntries(results.gradleProjectToProjectName),
|
|
56
|
-
gradleProjectNameToProjectRootMap: Object.fromEntries(results.gradleProjectNameToProjectRootMap),
|
|
57
|
-
gradleProjectToChildProjects: Object.fromEntries(results.gradleProjectToChildProjects),
|
|
58
|
-
};
|
|
59
|
-
try {
|
|
60
|
-
(0, devkit_1.writeJsonFile)(cachePath, gradleReportJson);
|
|
61
|
-
}
|
|
62
|
-
catch (e) {
|
|
63
|
-
devkit_1.logger.warn(`Failed to write Gradle report cache to ${cachePath}: ${e instanceof Error ? e.message : 'unknown error'}`);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
let gradleReportCache;
|
|
67
|
-
let gradleReportCachePath = (0, node_path_1.join)(internal_1.workspaceDataDirectory, 'gradle-report-v1.hash');
|
|
68
|
-
function getCurrentGradleReport() {
|
|
69
|
-
if (!gradleReportCache) {
|
|
70
|
-
throw new devkit_1.AggregateCreateNodesError([
|
|
71
|
-
[
|
|
72
|
-
null,
|
|
73
|
-
new Error(`Expected cached gradle report. Please open an issue at https://github.com/nrwl/nx/issues/new/choose`),
|
|
74
|
-
],
|
|
75
|
-
], []);
|
|
76
|
-
}
|
|
77
|
-
return gradleReportCache;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* This function populates the gradle report cache.
|
|
81
|
-
* For each gradlew file, it runs the `projectReportAll` task and processes the output.
|
|
82
|
-
* If `projectReportAll` fails, it runs the `projectReport` task instead.
|
|
83
|
-
* It will throw an error if both tasks fail.
|
|
84
|
-
* It will accumulate the output of all gradlew files.
|
|
85
|
-
* @param workspaceRoot
|
|
86
|
-
* @param gradlewFiles absolute paths to all gradlew files in the workspace
|
|
87
|
-
* @returns Promise<void>
|
|
88
|
-
*/
|
|
89
|
-
async function populateGradleReport(workspaceRoot, gradlewFiles) {
|
|
90
|
-
const gradleConfigHash = await (0, internal_1.hashWithWorkspaceContext)(workspaceRoot, [
|
|
91
|
-
split_config_files_1.gradleConfigAndTestGlob,
|
|
92
|
-
]);
|
|
93
|
-
const cached = readGradleReportCache(gradleReportCachePath, gradleConfigHash);
|
|
94
|
-
if (cached) {
|
|
95
|
-
gradleReportCache = cached;
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
const gradleProjectReportStart = performance.mark('gradleProjectReport:start');
|
|
99
|
-
const projectReportLines = await gradlewFiles.reduce(async (projectReportLines, gradlewFile) => {
|
|
100
|
-
const allLines = await projectReportLines;
|
|
101
|
-
const currentLines = await (0, get_project_report_lines_1.getProjectReportLines)(gradlewFile);
|
|
102
|
-
return [...allLines, ...currentLines];
|
|
103
|
-
}, Promise.resolve([]));
|
|
104
|
-
const gradleProjectReportEnd = performance.mark('gradleProjectReport:end');
|
|
105
|
-
performance.measure('gradleProjectReport', gradleProjectReportStart.name, gradleProjectReportEnd.name);
|
|
106
|
-
gradleReportCache = processProjectReports(projectReportLines);
|
|
107
|
-
writeGradleReportToCache(gradleReportCachePath, gradleReportCache, gradleConfigHash);
|
|
108
|
-
}
|
|
109
|
-
function processProjectReports(projectReportLines) {
|
|
110
|
-
/**
|
|
111
|
-
* Map of Gradle File path to Gradle Project Name
|
|
112
|
-
*/
|
|
113
|
-
const gradleFileToGradleProjectMap = new Map();
|
|
114
|
-
const gradleProjectToDepsMap = new Map();
|
|
115
|
-
/**
|
|
116
|
-
* Map of Gradle Build File to tasks type map
|
|
117
|
-
*/
|
|
118
|
-
const gradleProjectToTasksTypeMap = new Map();
|
|
119
|
-
const gradleProjectToTasksMap = new Map();
|
|
120
|
-
const gradleProjectToProjectName = new Map();
|
|
121
|
-
const gradleProjectNameToProjectRootMap = new Map();
|
|
122
|
-
/**
|
|
123
|
-
* Map fo possible output files of each gradle file
|
|
124
|
-
* e.g. {build.gradle.kts: { projectReportDir: '' testReportDir: '' }}
|
|
125
|
-
*/
|
|
126
|
-
const gradleFileToOutputDirsMap = new Map();
|
|
127
|
-
/**
|
|
128
|
-
* Map of Gradle Project to its child projects
|
|
129
|
-
*/
|
|
130
|
-
const gradleProjectToChildProjects = new Map();
|
|
131
|
-
let index = 0;
|
|
132
|
-
while (index < projectReportLines.length) {
|
|
133
|
-
const line = projectReportLines[index].trim();
|
|
134
|
-
if (line.startsWith('> Task ')) {
|
|
135
|
-
if (line.endsWith(':dependencyReport')) {
|
|
136
|
-
const gradleProject = line.substring('> Task '.length, line.length - ':dependencyReport'.length);
|
|
137
|
-
while (index < projectReportLines.length &&
|
|
138
|
-
!projectReportLines[index].includes(exec_gradle_1.fileSeparator)) {
|
|
139
|
-
index++;
|
|
140
|
-
}
|
|
141
|
-
const [_, file] = projectReportLines[index].split(exec_gradle_1.fileSeparator);
|
|
142
|
-
gradleProjectToDepsMap.set(gradleProject, processGradleDependencies(file));
|
|
143
|
-
}
|
|
144
|
-
if (line.endsWith('propertyReport')) {
|
|
145
|
-
const gradleProject = line.substring('> Task '.length, line.length - ':propertyReport'.length);
|
|
146
|
-
while (index < projectReportLines.length &&
|
|
147
|
-
!projectReportLines[index].includes(exec_gradle_1.fileSeparator)) {
|
|
148
|
-
index++;
|
|
149
|
-
}
|
|
150
|
-
const [_, file] = projectReportLines[index].split(exec_gradle_1.fileSeparator);
|
|
151
|
-
const propertyReportLines = (0, node_fs_1.existsSync)(file)
|
|
152
|
-
? (0, node_fs_1.readFileSync)(file).toString().split(exec_gradle_1.newLineSeparator)
|
|
153
|
-
: [];
|
|
154
|
-
let projectName, absBuildFilePath, absBuildDirPath;
|
|
155
|
-
const outputDirMap = new Map();
|
|
156
|
-
const tasks = new Set();
|
|
157
|
-
for (const line of propertyReportLines) {
|
|
158
|
-
if (line.startsWith('name: ')) {
|
|
159
|
-
projectName = line.substring('name: '.length);
|
|
160
|
-
}
|
|
161
|
-
if (line.startsWith('buildFile: ')) {
|
|
162
|
-
absBuildFilePath = line.substring('buildFile: '.length);
|
|
163
|
-
}
|
|
164
|
-
if (line.startsWith('buildDir: ')) {
|
|
165
|
-
absBuildDirPath = line.substring('buildDir: '.length);
|
|
166
|
-
}
|
|
167
|
-
if (line.startsWith('childProjects: ')) {
|
|
168
|
-
const childProjects = line.substring('childProjects: {'.length, line.length - 1); // remove curly braces {} around childProjects
|
|
169
|
-
gradleProjectToChildProjects.set(gradleProject, childProjects
|
|
170
|
-
.split(',')
|
|
171
|
-
.map((c) => c.trim().split('=')[0])
|
|
172
|
-
.filter(Boolean) // e.g. get project name from text like "app=project ':app', mylibrary=project ':mylibrary'"
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
if (line.includes('Dir: ')) {
|
|
176
|
-
const [dirName, dirPath] = line.split(': ');
|
|
177
|
-
const taskName = dirName.replace('Dir', '');
|
|
178
|
-
outputDirMap.set(taskName, `{workspaceRoot}/${(0, devkit_1.normalizePath)((0, node_path_1.relative)(devkit_1.workspaceRoot, dirPath))}`);
|
|
179
|
-
}
|
|
180
|
-
if (line.includes(': task ')) {
|
|
181
|
-
const [task] = line.split(': task ');
|
|
182
|
-
tasks.add(task);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
if (!projectName || !absBuildFilePath || !absBuildDirPath) {
|
|
186
|
-
continue;
|
|
187
|
-
}
|
|
188
|
-
const buildFile = (0, devkit_1.normalizePath)((0, node_path_1.relative)(devkit_1.workspaceRoot, absBuildFilePath));
|
|
189
|
-
const buildDir = (0, devkit_1.normalizePath)((0, node_path_1.relative)(devkit_1.workspaceRoot, absBuildDirPath));
|
|
190
|
-
outputDirMap.set('build', `{workspaceRoot}/${buildDir}`);
|
|
191
|
-
outputDirMap.set('classes', `{workspaceRoot}/${buildDir}/classes`);
|
|
192
|
-
gradleFileToOutputDirsMap.set(buildFile, outputDirMap);
|
|
193
|
-
gradleFileToGradleProjectMap.set(buildFile, gradleProject);
|
|
194
|
-
gradleProjectToProjectName.set(gradleProject, projectName);
|
|
195
|
-
gradleProjectNameToProjectRootMap.set(gradleProject, (0, path_1.dirname)(buildFile));
|
|
196
|
-
gradleProjectToTasksMap.set(gradleProject, tasks);
|
|
197
|
-
}
|
|
198
|
-
if (line.endsWith('taskReport')) {
|
|
199
|
-
const gradleProject = line.substring('> Task '.length, line.length - ':taskReport'.length);
|
|
200
|
-
while (index < projectReportLines.length &&
|
|
201
|
-
!projectReportLines[index].includes(exec_gradle_1.fileSeparator)) {
|
|
202
|
-
index++;
|
|
203
|
-
}
|
|
204
|
-
const [_, file] = projectReportLines[index].split(exec_gradle_1.fileSeparator);
|
|
205
|
-
const taskTypeMap = new Map();
|
|
206
|
-
const tasksFileLines = (0, node_fs_1.existsSync)(file)
|
|
207
|
-
? (0, node_fs_1.readFileSync)(file).toString().split(exec_gradle_1.newLineSeparator)
|
|
208
|
-
: [];
|
|
209
|
-
let i = 0;
|
|
210
|
-
while (i < tasksFileLines.length) {
|
|
211
|
-
const line = tasksFileLines[i];
|
|
212
|
-
if (line.endsWith('tasks')) {
|
|
213
|
-
const dashes = new Array(line.length + 1).join('-');
|
|
214
|
-
if (tasksFileLines[i + 1] === dashes) {
|
|
215
|
-
const type = line.substring(0, line.length - ' tasks'.length);
|
|
216
|
-
i++;
|
|
217
|
-
while (tasksFileLines[++i] !== '' &&
|
|
218
|
-
i < tasksFileLines.length &&
|
|
219
|
-
tasksFileLines[i]?.includes(' - ')) {
|
|
220
|
-
const [taskName] = tasksFileLines[i].split(' - ');
|
|
221
|
-
taskTypeMap.set(taskName, type);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
i++;
|
|
226
|
-
}
|
|
227
|
-
gradleProjectToTasksTypeMap.set(gradleProject, taskTypeMap);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
index++;
|
|
231
|
-
}
|
|
232
|
-
return {
|
|
233
|
-
gradleFileToGradleProjectMap,
|
|
234
|
-
gradleFileToOutputDirsMap,
|
|
235
|
-
gradleProjectToTasksTypeMap,
|
|
236
|
-
gradleProjectToDepsMap,
|
|
237
|
-
gradleProjectToTasksMap,
|
|
238
|
-
gradleProjectToProjectName,
|
|
239
|
-
gradleProjectNameToProjectRootMap,
|
|
240
|
-
gradleProjectToChildProjects,
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
function processGradleDependencies(depsFile) {
|
|
244
|
-
const dependedProjects = new Set();
|
|
245
|
-
const lines = (0, node_fs_1.readFileSync)(depsFile).toString().split(exec_gradle_1.newLineSeparator);
|
|
246
|
-
let inDeps = false;
|
|
247
|
-
for (const line of lines) {
|
|
248
|
-
if (line.startsWith('implementationDependenciesMetadata') ||
|
|
249
|
-
line.startsWith('compileClasspath')) {
|
|
250
|
-
inDeps = true;
|
|
251
|
-
continue;
|
|
252
|
-
}
|
|
253
|
-
if (inDeps) {
|
|
254
|
-
if (line === '') {
|
|
255
|
-
inDeps = false;
|
|
256
|
-
continue;
|
|
257
|
-
}
|
|
258
|
-
const [indents, dep] = line.split('--- ');
|
|
259
|
-
if (indents === '\\' || indents === '+') {
|
|
260
|
-
let targetProjectName;
|
|
261
|
-
if (dep.startsWith('project ')) {
|
|
262
|
-
targetProjectName = dep
|
|
263
|
-
.substring('project '.length)
|
|
264
|
-
.replace(/ \(n\)$/, '')
|
|
265
|
-
.trim()
|
|
266
|
-
.split(' ')?.[0];
|
|
267
|
-
}
|
|
268
|
-
else if (dep.includes('-> project')) {
|
|
269
|
-
const [_, projectName] = dep.split('-> project');
|
|
270
|
-
targetProjectName = projectName.trim().split(' ')?.[0];
|
|
271
|
-
}
|
|
272
|
-
if (targetProjectName) {
|
|
273
|
-
dependedProjects.add(targetProjectName);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
return dependedProjects;
|
|
279
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This function executes the gradle projectReportAll task and returns the output as an array of lines.
|
|
3
|
-
* @param gradlewFile the absolute path to the gradlew file
|
|
4
|
-
* @returns project report lines
|
|
5
|
-
*/
|
|
6
|
-
export declare function getProjectReportLines(gradlewFile: string): Promise<string[]>;
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getProjectReportLines = getProjectReportLines;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const exec_gradle_1 = require("../../utils/exec-gradle");
|
|
6
|
-
/**
|
|
7
|
-
* This function executes the gradle projectReportAll task and returns the output as an array of lines.
|
|
8
|
-
* @param gradlewFile the absolute path to the gradlew file
|
|
9
|
-
* @returns project report lines
|
|
10
|
-
*/
|
|
11
|
-
async function getProjectReportLines(gradlewFile) {
|
|
12
|
-
let projectReportBuffer;
|
|
13
|
-
try {
|
|
14
|
-
projectReportBuffer = await (0, exec_gradle_1.execGradleAsync)(gradlewFile, [
|
|
15
|
-
'projectReportAll',
|
|
16
|
-
process.env.NX_VERBOSE_LOGGING === 'true' ? '--info' : '',
|
|
17
|
-
'--exclude-task',
|
|
18
|
-
'htmlDependencyReport',
|
|
19
|
-
]);
|
|
20
|
-
}
|
|
21
|
-
catch (e) {
|
|
22
|
-
if (e.toString()?.includes('ERROR: JAVA_HOME')) {
|
|
23
|
-
throw new devkit_1.AggregateCreateNodesError([
|
|
24
|
-
[
|
|
25
|
-
gradlewFile,
|
|
26
|
-
new Error(`Could not find Java. Please install Java and try again: https://www.java.com/en/download/help/index_installing.html.\n\r${e.toString()}`),
|
|
27
|
-
],
|
|
28
|
-
], []);
|
|
29
|
-
}
|
|
30
|
-
else if (e.toString()?.includes(`Task 'projectReportAll' not found`)) {
|
|
31
|
-
try {
|
|
32
|
-
projectReportBuffer = await (0, exec_gradle_1.execGradleAsync)(gradlewFile, [
|
|
33
|
-
'projectReport',
|
|
34
|
-
]);
|
|
35
|
-
devkit_1.logger.warn(`Could not run 'projectReportAll' task. Ran 'projectReport' instead. Please run 'nx generate @nx/gradle:init' to generate the necessary tasks.\n\r${e.toString()}`);
|
|
36
|
-
}
|
|
37
|
-
catch (e) {
|
|
38
|
-
throw new devkit_1.AggregateCreateNodesError([
|
|
39
|
-
[
|
|
40
|
-
gradlewFile,
|
|
41
|
-
new Error(`Could not run 'projectReportAll' or 'projectReport' task. Please run 'nx generate @nx/gradle:init' to generate the necessary tasks.\n\r${e.toString()}`),
|
|
42
|
-
],
|
|
43
|
-
], []);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
throw new devkit_1.AggregateCreateNodesError([
|
|
48
|
-
[
|
|
49
|
-
gradlewFile,
|
|
50
|
-
new Error(`Could not run 'projectReportAll' or 'projectReport' Gradle task. Please install Gradle and try again: https://gradle.org/install/.\r\n${e.toString()}`),
|
|
51
|
-
],
|
|
52
|
-
], []);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
const projectReportLines = projectReportBuffer
|
|
56
|
-
.toString()
|
|
57
|
-
.split(exec_gradle_1.newLineSeparator)
|
|
58
|
-
.filter((line) => line.trim() !== '');
|
|
59
|
-
if (process.env.NX_VERBOSE_LOGGING === 'true') {
|
|
60
|
-
devkit_1.output.log({
|
|
61
|
-
title: `Successfully ran projectReportAll or projectRerport task using ${gradlewFile}`,
|
|
62
|
-
bodyLines: projectReportLines,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
return projectReportLines;
|
|
66
|
-
}
|