@nx/gradle 21.0.0-canary.20250423-16fc551 → 21.0.0-canary.20250424-e23b25f
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/executors.json +3 -0
- package/migrations.json +6 -0
- package/package.json +4 -2
- package/plugin-v1.d.ts +2 -0
- package/plugin-v1.js +8 -0
- package/plugin.d.ts +1 -1
- package/plugin.js +1 -2
- package/project-graph/project.json +43 -0
- package/project-graph/publish-maven.d.ts +1 -0
- package/project-graph/publish-maven.js +103 -0
- package/src/generators/ci-workflow/files/circleci/.circleci/config.yml.template +1 -1
- package/src/generators/ci-workflow/files/github/.github/workflows/__workflowFileName__.yml.template +3 -3
- package/src/generators/init/init.js +28 -44
- package/src/migrations/19-4-0/add-project-report-all.d.ts +4 -0
- package/src/migrations/19-4-0/add-project-report-all.js +83 -2
- package/src/migrations/21-0-0/change-plugin-to-v1.d.ts +2 -0
- package/src/migrations/21-0-0/change-plugin-to-v1.js +26 -0
- package/src/plugin/dependencies.d.ts +2 -1
- package/src/plugin/dependencies.js +30 -55
- package/src/plugin/nodes.d.ts +3 -16
- package/src/plugin/nodes.js +17 -228
- package/src/plugin/utils/__mocks__/gradle_composite.json +38 -0
- package/src/plugin/utils/__mocks__/gradle_nx_list.json +590 -0
- package/src/plugin/utils/__mocks__/gradle_tutorial.json +344 -0
- package/src/plugin/utils/get-project-graph-from-gradle-plugin.d.ts +25 -0
- package/src/plugin/utils/get-project-graph-from-gradle-plugin.js +113 -0
- package/src/plugin/utils/get-project-graph-lines.d.ts +2 -0
- package/src/plugin/utils/get-project-graph-lines.js +66 -0
- package/src/plugin/utils/gradle-plugin-options.d.ts +6 -0
- package/src/plugin/utils/gradle-plugin-options.js +8 -0
- package/src/plugin-v1/dependencies.d.ts +2 -0
- package/src/plugin-v1/dependencies.js +64 -0
- package/src/plugin-v1/nodes.d.ts +20 -0
- package/src/plugin-v1/nodes.js +266 -0
- package/src/{utils → plugin-v1/utils}/get-gradle-report.d.ts +2 -2
- package/src/{utils → plugin-v1/utils}/get-gradle-report.js +19 -23
- package/src/{utils → plugin-v1/utils}/get-project-report-lines.d.ts +0 -2
- package/src/{utils → plugin-v1/utils}/get-project-report-lines.js +2 -10
- package/src/utils/exec-gradle.d.ts +5 -3
- package/src/utils/exec-gradle.js +12 -5
- package/src/utils/split-config-files.js +2 -0
- package/src/utils/versions.d.ts +2 -0
- package/src/utils/versions.js +3 -1
@@ -0,0 +1,266 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.createNodes = exports.makeCreateNodesForGradleConfigFile = exports.createNodesV2 = void 0;
|
4
|
+
exports.writeTargetsToCache = writeTargetsToCache;
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
6
|
+
const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
|
7
|
+
const node_fs_1 = require("node:fs");
|
8
|
+
const node_path_1 = require("node:path");
|
9
|
+
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
10
|
+
const devkit_internals_1 = require("nx/src/devkit-internals");
|
11
|
+
const get_gradle_report_1 = require("./utils/get-gradle-report");
|
12
|
+
const file_hasher_1 = require("nx/src/hasher/file-hasher");
|
13
|
+
const split_config_files_1 = require("../utils/split-config-files");
|
14
|
+
const exec_gradle_1 = require("../utils/exec-gradle");
|
15
|
+
const cacheableTaskType = new Set(['Build', 'Verification']);
|
16
|
+
const dependsOnMap = {
|
17
|
+
build: ['^build', 'classes', 'test'],
|
18
|
+
testClasses: ['classes'],
|
19
|
+
test: ['testClasses'],
|
20
|
+
classes: ['^classes'],
|
21
|
+
};
|
22
|
+
function normalizeOptions(options) {
|
23
|
+
options ??= {};
|
24
|
+
options.testTargetName ??= 'test';
|
25
|
+
options.classesTargetName ??= 'classes';
|
26
|
+
options.buildTargetName ??= 'build';
|
27
|
+
return options;
|
28
|
+
}
|
29
|
+
function readTargetsCache(cachePath) {
|
30
|
+
return (0, node_fs_1.existsSync)(cachePath) ? (0, devkit_1.readJsonFile)(cachePath) : {};
|
31
|
+
}
|
32
|
+
function writeTargetsToCache(cachePath, results) {
|
33
|
+
(0, devkit_1.writeJsonFile)(cachePath, results);
|
34
|
+
}
|
35
|
+
exports.createNodesV2 = [
|
36
|
+
split_config_files_1.gradleConfigAndTestGlob,
|
37
|
+
async (files, options, context) => {
|
38
|
+
const { buildFiles, projectRoots, gradlewFiles, testFiles } = (0, split_config_files_1.splitConfigFiles)(files);
|
39
|
+
const optionsHash = (0, file_hasher_1.hashObject)(options);
|
40
|
+
const cachePath = (0, node_path_1.join)(cache_directory_1.workspaceDataDirectory, `gradle-${optionsHash}.hash`);
|
41
|
+
const targetsCache = readTargetsCache(cachePath);
|
42
|
+
await (0, get_gradle_report_1.populateGradleReport)(context.workspaceRoot, gradlewFiles.map((f) => (0, node_path_1.join)(context.workspaceRoot, f)));
|
43
|
+
const gradleReport = (0, get_gradle_report_1.getCurrentGradleReport)();
|
44
|
+
const gradleProjectRootToTestFilesMap = getGradleProjectRootToTestFilesMap(testFiles, projectRoots);
|
45
|
+
try {
|
46
|
+
return (0, devkit_1.createNodesFromFiles)((0, exports.makeCreateNodesForGradleConfigFile)(gradleReport, targetsCache, gradleProjectRootToTestFilesMap), buildFiles, options, context);
|
47
|
+
}
|
48
|
+
finally {
|
49
|
+
writeTargetsToCache(cachePath, targetsCache);
|
50
|
+
}
|
51
|
+
},
|
52
|
+
];
|
53
|
+
const makeCreateNodesForGradleConfigFile = (gradleReport, targetsCache = {}, gradleProjectRootToTestFilesMap = {}) => async (gradleFilePath, options, context) => {
|
54
|
+
const projectRoot = (0, node_path_1.dirname)(gradleFilePath);
|
55
|
+
options = normalizeOptions(options);
|
56
|
+
const hash = await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options ?? {}, context);
|
57
|
+
targetsCache[hash] ??= await createGradleProject(gradleReport, gradleFilePath, options, context, gradleProjectRootToTestFilesMap[projectRoot]);
|
58
|
+
const project = targetsCache[hash];
|
59
|
+
if (!project) {
|
60
|
+
return {};
|
61
|
+
}
|
62
|
+
return {
|
63
|
+
projects: {
|
64
|
+
[projectRoot]: project,
|
65
|
+
},
|
66
|
+
};
|
67
|
+
};
|
68
|
+
exports.makeCreateNodesForGradleConfigFile = makeCreateNodesForGradleConfigFile;
|
69
|
+
/**
|
70
|
+
@deprecated This is replaced with {@link createNodesV2}. Update your plugin to export its own `createNodesV2` function that wraps this one instead.
|
71
|
+
This function will change to the v2 function in Nx 20.
|
72
|
+
*/
|
73
|
+
exports.createNodes = [
|
74
|
+
split_config_files_1.gradleConfigGlob,
|
75
|
+
async (buildFile, options, context) => {
|
76
|
+
devkit_1.logger.warn('`createNodes` is deprecated. Update your plugin to utilize createNodesV2 instead. In Nx 20, this will change to the createNodesV2 API.');
|
77
|
+
const { gradlewFiles } = (0, split_config_files_1.splitConfigFiles)(context.configFiles);
|
78
|
+
await (0, get_gradle_report_1.populateGradleReport)(context.workspaceRoot, gradlewFiles);
|
79
|
+
const gradleReport = (0, get_gradle_report_1.getCurrentGradleReport)();
|
80
|
+
const internalCreateNodes = (0, exports.makeCreateNodesForGradleConfigFile)(gradleReport);
|
81
|
+
return await internalCreateNodes(buildFile, options, context);
|
82
|
+
},
|
83
|
+
];
|
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
|
+
projects: 'self',
|
225
|
+
params: 'forward',
|
226
|
+
});
|
227
|
+
});
|
228
|
+
targets[ciTargetName] = {
|
229
|
+
executor: 'nx:noop',
|
230
|
+
cache: true,
|
231
|
+
inputs,
|
232
|
+
dependsOn: dependsOn,
|
233
|
+
...(outputs && outputs.length > 0 ? { outputs } : {}),
|
234
|
+
metadata: {
|
235
|
+
technologies: ['gradle'],
|
236
|
+
description: 'Runs Gradle Tests in CI',
|
237
|
+
nonAtomizedTarget: testTargetName,
|
238
|
+
help: {
|
239
|
+
command: `${(0, exec_gradle_1.getGradleExecFile)()} help --task ${taskCommandToRun}`,
|
240
|
+
example: {
|
241
|
+
options: {
|
242
|
+
args: ['--rerun'],
|
243
|
+
},
|
244
|
+
},
|
245
|
+
},
|
246
|
+
},
|
247
|
+
};
|
248
|
+
targetGroups[targetGroupName].push(ciTargetName);
|
249
|
+
}
|
250
|
+
function getGradleProjectRootToTestFilesMap(testFiles, projectRoots) {
|
251
|
+
if (testFiles.length === 0 || projectRoots.length === 0) {
|
252
|
+
return;
|
253
|
+
}
|
254
|
+
const roots = new Map(projectRoots.map((root) => [root, root]));
|
255
|
+
const testFilesToGradleProjectMap = {};
|
256
|
+
testFiles.forEach((testFile) => {
|
257
|
+
const projectRoot = (0, devkit_internals_1.findProjectForPath)(testFile, roots);
|
258
|
+
if (projectRoot) {
|
259
|
+
if (!testFilesToGradleProjectMap[projectRoot]) {
|
260
|
+
testFilesToGradleProjectMap[projectRoot] = [];
|
261
|
+
}
|
262
|
+
testFilesToGradleProjectMap[projectRoot].push(testFile);
|
263
|
+
}
|
264
|
+
});
|
265
|
+
return testFilesToGradleProjectMap;
|
266
|
+
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
export interface GradleReport {
|
2
2
|
gradleFileToGradleProjectMap: Map<string, string>;
|
3
|
-
buildFileToDepsMap: Map<string, Set<string>>;
|
4
3
|
gradleFileToOutputDirsMap: Map<string, Map<string, string>>;
|
4
|
+
gradleProjectToDepsMap: Map<string, Set<string>>;
|
5
5
|
gradleProjectToTasksTypeMap: Map<string, Map<string, string>>;
|
6
6
|
gradleProjectToTasksMap: Map<string, Set<string>>;
|
7
7
|
gradleProjectToProjectName: Map<string, string>;
|
@@ -11,7 +11,7 @@ export interface GradleReport {
|
|
11
11
|
export interface GradleReportJSON {
|
12
12
|
hash: string;
|
13
13
|
gradleFileToGradleProjectMap: Record<string, string>;
|
14
|
-
|
14
|
+
gradleProjectToDepsMap: Record<string, Array<string>>;
|
15
15
|
gradleFileToOutputDirsMap: Record<string, Record<string, string>>;
|
16
16
|
gradleProjectToTasksTypeMap: Record<string, Record<string, string>>;
|
17
17
|
gradleProjectToTasksMap: Record<string, Array<string>>;
|
@@ -10,9 +10,10 @@ const node_path_1 = require("node:path");
|
|
10
10
|
const devkit_1 = require("@nx/devkit");
|
11
11
|
const workspace_context_1 = require("nx/src/utils/workspace-context");
|
12
12
|
const path_1 = require("path");
|
13
|
-
const split_config_files_1 = require("
|
13
|
+
const split_config_files_1 = require("../../utils/split-config-files");
|
14
14
|
const get_project_report_lines_1 = require("./get-project-report-lines");
|
15
15
|
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
16
|
+
const exec_gradle_1 = require("../../utils/exec-gradle");
|
16
17
|
function readGradleReportCache(cachePath, hash) {
|
17
18
|
const gradleReportJson = (0, node_fs_1.existsSync)(cachePath)
|
18
19
|
? (0, devkit_1.readJsonFile)(cachePath)
|
@@ -22,7 +23,7 @@ function readGradleReportCache(cachePath, hash) {
|
|
22
23
|
}
|
23
24
|
let results = {
|
24
25
|
gradleFileToGradleProjectMap: new Map(Object.entries(gradleReportJson['gradleFileToGradleProjectMap'])),
|
25
|
-
|
26
|
+
gradleProjectToDepsMap: new Map(Object.entries(gradleReportJson['gradleProjectToDepsMap']).map(([key, value]) => [key, new Set(value)])),
|
26
27
|
gradleFileToOutputDirsMap: new Map(Object.entries(gradleReportJson['gradleFileToOutputDirsMap']).map(([key, value]) => [key, new Map(Object.entries(value))])),
|
27
28
|
gradleProjectToTasksTypeMap: new Map(Object.entries(gradleReportJson['gradleProjectToTasksTypeMap']).map(([key, value]) => [key, new Map(Object.entries(value))])),
|
28
29
|
gradleProjectToTasksMap: new Map(Object.entries(gradleReportJson['gradleProjectToTasksMap']).map(([key, value]) => [key, new Set(value)])),
|
@@ -36,7 +37,10 @@ function writeGradleReportToCache(cachePath, results) {
|
|
36
37
|
let gradleReportJson = {
|
37
38
|
hash: gradleCurrentConfigHash,
|
38
39
|
gradleFileToGradleProjectMap: Object.fromEntries(results.gradleFileToGradleProjectMap),
|
39
|
-
|
40
|
+
gradleProjectToDepsMap: Object.fromEntries(Array.from(results.gradleProjectToDepsMap).map(([key, value]) => [
|
41
|
+
key,
|
42
|
+
Array.from(value),
|
43
|
+
])),
|
40
44
|
gradleFileToOutputDirsMap: Object.fromEntries(Array.from(results.gradleFileToOutputDirsMap).map(([key, value]) => [
|
41
45
|
key,
|
42
46
|
Object.fromEntries(value),
|
@@ -105,7 +109,7 @@ function processProjectReports(projectReportLines) {
|
|
105
109
|
* Map of Gradle File path to Gradle Project Name
|
106
110
|
*/
|
107
111
|
const gradleFileToGradleProjectMap = new Map();
|
108
|
-
const
|
112
|
+
const gradleProjectToDepsMap = new Map();
|
109
113
|
/**
|
110
114
|
* Map of Gradle Build File to tasks type map
|
111
115
|
*/
|
@@ -113,10 +117,6 @@ function processProjectReports(projectReportLines) {
|
|
113
117
|
const gradleProjectToTasksMap = new Map();
|
114
118
|
const gradleProjectToProjectName = new Map();
|
115
119
|
const gradleProjectNameToProjectRootMap = new Map();
|
116
|
-
/**
|
117
|
-
* Map of buildFile to dependencies report path
|
118
|
-
*/
|
119
|
-
const buildFileToDepsMap = new Map();
|
120
120
|
/**
|
121
121
|
* Map fo possible output files of each gradle file
|
122
122
|
* e.g. {build.gradle.kts: { projectReportDir: '' testReportDir: '' }}
|
@@ -133,21 +133,21 @@ function processProjectReports(projectReportLines) {
|
|
133
133
|
if (line.endsWith(':dependencyReport')) {
|
134
134
|
const gradleProject = line.substring('> Task '.length, line.length - ':dependencyReport'.length);
|
135
135
|
while (index < projectReportLines.length &&
|
136
|
-
!projectReportLines[index].includes(
|
136
|
+
!projectReportLines[index].includes(exec_gradle_1.fileSeparator)) {
|
137
137
|
index++;
|
138
138
|
}
|
139
|
-
const [_, file] = projectReportLines[index].split(
|
140
|
-
|
139
|
+
const [_, file] = projectReportLines[index].split(exec_gradle_1.fileSeparator);
|
140
|
+
gradleProjectToDepsMap.set(gradleProject, processGradleDependencies(file));
|
141
141
|
}
|
142
142
|
if (line.endsWith('propertyReport')) {
|
143
143
|
const gradleProject = line.substring('> Task '.length, line.length - ':propertyReport'.length);
|
144
144
|
while (index < projectReportLines.length &&
|
145
|
-
!projectReportLines[index].includes(
|
145
|
+
!projectReportLines[index].includes(exec_gradle_1.fileSeparator)) {
|
146
146
|
index++;
|
147
147
|
}
|
148
|
-
const [_, file] = projectReportLines[index].split(
|
148
|
+
const [_, file] = projectReportLines[index].split(exec_gradle_1.fileSeparator);
|
149
149
|
const propertyReportLines = (0, node_fs_1.existsSync)(file)
|
150
|
-
? (0, node_fs_1.readFileSync)(file).toString().split(
|
150
|
+
? (0, node_fs_1.readFileSync)(file).toString().split(exec_gradle_1.newLineSeparator)
|
151
151
|
: [];
|
152
152
|
let projectName, absBuildFilePath, absBuildDirPath;
|
153
153
|
const outputDirMap = new Map();
|
@@ -185,10 +185,6 @@ function processProjectReports(projectReportLines) {
|
|
185
185
|
}
|
186
186
|
const buildFile = (0, devkit_1.normalizePath)((0, node_path_1.relative)(devkit_1.workspaceRoot, absBuildFilePath));
|
187
187
|
const buildDir = (0, node_path_1.relative)(devkit_1.workspaceRoot, absBuildDirPath);
|
188
|
-
const depsFile = dependenciesMap.get(gradleProject);
|
189
|
-
if (depsFile) {
|
190
|
-
buildFileToDepsMap.set(buildFile, processGradleDependencies(depsFile));
|
191
|
-
}
|
192
188
|
outputDirMap.set('build', `{workspaceRoot}/${buildDir}`);
|
193
189
|
outputDirMap.set('classes', `{workspaceRoot}/${(0, node_path_1.join)(buildDir, 'classes')}`);
|
194
190
|
gradleFileToOutputDirsMap.set(buildFile, outputDirMap);
|
@@ -200,13 +196,13 @@ function processProjectReports(projectReportLines) {
|
|
200
196
|
if (line.endsWith('taskReport')) {
|
201
197
|
const gradleProject = line.substring('> Task '.length, line.length - ':taskReport'.length);
|
202
198
|
while (index < projectReportLines.length &&
|
203
|
-
!projectReportLines[index].includes(
|
199
|
+
!projectReportLines[index].includes(exec_gradle_1.fileSeparator)) {
|
204
200
|
index++;
|
205
201
|
}
|
206
|
-
const [_, file] = projectReportLines[index].split(
|
202
|
+
const [_, file] = projectReportLines[index].split(exec_gradle_1.fileSeparator);
|
207
203
|
const taskTypeMap = new Map();
|
208
204
|
const tasksFileLines = (0, node_fs_1.existsSync)(file)
|
209
|
-
? (0, node_fs_1.readFileSync)(file).toString().split(
|
205
|
+
? (0, node_fs_1.readFileSync)(file).toString().split(exec_gradle_1.newLineSeparator)
|
210
206
|
: [];
|
211
207
|
let i = 0;
|
212
208
|
while (i < tasksFileLines.length) {
|
@@ -233,9 +229,9 @@ function processProjectReports(projectReportLines) {
|
|
233
229
|
}
|
234
230
|
return {
|
235
231
|
gradleFileToGradleProjectMap,
|
236
|
-
buildFileToDepsMap,
|
237
232
|
gradleFileToOutputDirsMap,
|
238
233
|
gradleProjectToTasksTypeMap,
|
234
|
+
gradleProjectToDepsMap,
|
239
235
|
gradleProjectToTasksMap,
|
240
236
|
gradleProjectToProjectName,
|
241
237
|
gradleProjectNameToProjectRootMap,
|
@@ -244,7 +240,7 @@ function processProjectReports(projectReportLines) {
|
|
244
240
|
}
|
245
241
|
function processGradleDependencies(depsFile) {
|
246
242
|
const dependedProjects = new Set();
|
247
|
-
const lines = (0, node_fs_1.readFileSync)(depsFile).toString().split(
|
243
|
+
const lines = (0, node_fs_1.readFileSync)(depsFile).toString().split(exec_gradle_1.newLineSeparator);
|
248
244
|
let inDeps = false;
|
249
245
|
for (const line of lines) {
|
250
246
|
if (line.startsWith('implementationDependenciesMetadata') ||
|
@@ -1,15 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.newLineSeparator = exports.fileSeparator = void 0;
|
4
3
|
exports.getProjectReportLines = getProjectReportLines;
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
6
|
-
const exec_gradle_1 = require("
|
7
|
-
exports.fileSeparator = process.platform.startsWith('win')
|
8
|
-
? 'file:///'
|
9
|
-
: 'file://';
|
10
|
-
exports.newLineSeparator = process.platform.startsWith('win')
|
11
|
-
? '\r\n'
|
12
|
-
: '\n';
|
5
|
+
const exec_gradle_1 = require("../../utils/exec-gradle");
|
13
6
|
/**
|
14
7
|
* This function executes the gradle projectReportAll task and returns the output as an array of lines.
|
15
8
|
* @param gradlewFile the absolute path to the gradlew file
|
@@ -17,7 +10,6 @@ exports.newLineSeparator = process.platform.startsWith('win')
|
|
17
10
|
*/
|
18
11
|
async function getProjectReportLines(gradlewFile) {
|
19
12
|
let projectReportBuffer;
|
20
|
-
// Attempt to run projectReport or projectReportAll task, regardless of build.gradle or build.gradle.kts location
|
21
13
|
try {
|
22
14
|
projectReportBuffer = await (0, exec_gradle_1.execGradleAsync)(gradlewFile, [
|
23
15
|
'projectReportAll',
|
@@ -62,7 +54,7 @@ async function getProjectReportLines(gradlewFile) {
|
|
62
54
|
}
|
63
55
|
const projectReportLines = projectReportBuffer
|
64
56
|
.toString()
|
65
|
-
.split(
|
57
|
+
.split(exec_gradle_1.newLineSeparator)
|
66
58
|
.filter((line) => line.trim() !== '');
|
67
59
|
if (process.env.NX_VERBOSE_LOGGING === 'true') {
|
68
60
|
devkit_1.output.log({
|
@@ -1,4 +1,6 @@
|
|
1
1
|
import { ExecFileOptions } from 'node:child_process';
|
2
|
+
export declare const fileSeparator: string;
|
3
|
+
export declare const newLineSeparator: string;
|
2
4
|
/**
|
3
5
|
* For gradle command, it needs to be run from the directory of the gradle binary
|
4
6
|
* @returns gradle binary file name
|
@@ -14,10 +16,10 @@ export declare function getGradleExecFile(): string;
|
|
14
16
|
export declare function execGradleAsync(gradleBinaryPath: string, args: ReadonlyArray<string>, execOptions?: ExecFileOptions): Promise<Buffer>;
|
15
17
|
/**
|
16
18
|
* This function recursively finds the nearest gradlew file in the workspace
|
17
|
-
* @param originalFileToSearch the original file to search for
|
19
|
+
* @param originalFileToSearch the original file to search for, relative to workspace root, file path not directory path
|
18
20
|
* @param wr workspace root
|
19
21
|
* @param currentSearchPath the path to start searching for gradlew file
|
20
22
|
* @returns the relative path of the gradlew file to workspace root, throws an error if gradlew file is not found
|
21
|
-
* It will return gradlew.bat file on windows and gradlew file on other platforms
|
23
|
+
* It will return relative path to workspace root of gradlew.bat file on windows and gradlew file on other platforms
|
22
24
|
*/
|
23
|
-
export declare function
|
25
|
+
export declare function findGradlewFile(originalFileToSearch: string, wr?: string, currentSearchPath?: string): string;
|
package/src/utils/exec-gradle.js
CHANGED
@@ -1,13 +1,20 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.newLineSeparator = exports.fileSeparator = void 0;
|
3
4
|
exports.getGradleExecFile = getGradleExecFile;
|
4
5
|
exports.execGradleAsync = execGradleAsync;
|
5
|
-
exports.
|
6
|
+
exports.findGradlewFile = findGradlewFile;
|
6
7
|
const devkit_1 = require("@nx/devkit");
|
7
8
|
const node_child_process_1 = require("node:child_process");
|
8
9
|
const node_fs_1 = require("node:fs");
|
9
10
|
const node_path_1 = require("node:path");
|
10
11
|
const run_commands_impl_1 = require("nx/src/executors/run-commands/run-commands.impl");
|
12
|
+
exports.fileSeparator = process.platform.startsWith('win')
|
13
|
+
? 'file:///'
|
14
|
+
: 'file://';
|
15
|
+
exports.newLineSeparator = process.platform.startsWith('win')
|
16
|
+
? '\r\n'
|
17
|
+
: '\n';
|
11
18
|
/**
|
12
19
|
* For gradle command, it needs to be run from the directory of the gradle binary
|
13
20
|
* @returns gradle binary file name
|
@@ -51,13 +58,13 @@ function execGradleAsync(gradleBinaryPath, args, execOptions = {}) {
|
|
51
58
|
}
|
52
59
|
/**
|
53
60
|
* This function recursively finds the nearest gradlew file in the workspace
|
54
|
-
* @param originalFileToSearch the original file to search for
|
61
|
+
* @param originalFileToSearch the original file to search for, relative to workspace root, file path not directory path
|
55
62
|
* @param wr workspace root
|
56
63
|
* @param currentSearchPath the path to start searching for gradlew file
|
57
64
|
* @returns the relative path of the gradlew file to workspace root, throws an error if gradlew file is not found
|
58
|
-
* It will return gradlew.bat file on windows and gradlew file on other platforms
|
65
|
+
* It will return relative path to workspace root of gradlew.bat file on windows and gradlew file on other platforms
|
59
66
|
*/
|
60
|
-
function
|
67
|
+
function findGradlewFile(originalFileToSearch, wr = devkit_1.workspaceRoot, currentSearchPath) {
|
61
68
|
currentSearchPath ??= originalFileToSearch;
|
62
69
|
const parent = (0, node_path_1.dirname)(currentSearchPath);
|
63
70
|
if (currentSearchPath === parent) {
|
@@ -80,5 +87,5 @@ function findGraldewFile(originalFileToSearch, wr = devkit_1.workspaceRoot, curr
|
|
80
87
|
return gradlewPath;
|
81
88
|
}
|
82
89
|
}
|
83
|
-
return
|
90
|
+
return findGradlewFile(originalFileToSearch, wr, parent);
|
84
91
|
}
|
@@ -11,6 +11,8 @@ exports.GRADLE_TEST_FILES = [
|
|
11
11
|
'**/src/test/kotlin/**/*Test.kt',
|
12
12
|
'**/src/test/java/**/*Tests.java',
|
13
13
|
'**/src/test/kotlin/**/*Tests.kt',
|
14
|
+
'**/src/test/groovy/**/*Test.groovy',
|
15
|
+
'**/src/test/groovy/**/*Tests.groovy',
|
14
16
|
];
|
15
17
|
exports.gradleConfigGlob = (0, globs_1.combineGlobPatterns)(...Array.from(exports.GRADLE_BUILD_FILES).map((file) => `**/${file}`));
|
16
18
|
exports.gradleConfigAndTestGlob = (0, globs_1.combineGlobPatterns)(...Array.from(exports.GRADLE_BUILD_FILES), ...Array.from(exports.GRALDEW_FILES), ...Array.from(exports.GRADLE_BUILD_FILES).map((file) => `**/${file}`), ...Array.from(exports.GRALDEW_FILES).map((file) => `**/${file}`), ...exports.GRADLE_TEST_FILES);
|
package/src/utils/versions.d.ts
CHANGED
package/src/utils/versions.js
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.nxVersion = void 0;
|
3
|
+
exports.gradleProjectGraphVersion = exports.gradleProjectGraphPluginName = exports.nxVersion = void 0;
|
4
4
|
exports.nxVersion = require('../../package.json').version;
|
5
|
+
exports.gradleProjectGraphPluginName = 'dev.nx.gradle.project-graph';
|
6
|
+
exports.gradleProjectGraphVersion = '0.0.2';
|