@nx/gradle 0.0.0-pr-27930-e871993 → 0.0.0-pr-27940-4ec79a3
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/package.json +2 -2
- package/src/generators/init/init.js +7 -0
- package/src/plugin/dependencies.js +2 -4
- package/src/plugin/nodes.js +27 -21
- package/src/utils/exec-gradle.d.ts +2 -21
- package/src/utils/exec-gradle.js +14 -48
- package/src/utils/get-gradle-report.d.ts +7 -11
- package/src/utils/get-gradle-report.js +55 -34
- package/src/utils/get-project-report-lines.d.ts +0 -8
- package/src/utils/get-project-report-lines.js +0 -53
- package/src/utils/split-config-files.d.ts +0 -17
- package/src/utils/split-config-files.js +0 -57
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/gradle",
|
|
3
|
-
"version": "0.0.0-pr-
|
|
3
|
+
"version": "0.0.0-pr-27940-4ec79a3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Nx Plugin for Gradle allows Gradle tasks to be run through Nx",
|
|
6
6
|
"repository": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"migrations": "./migrations.json"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@nx/devkit": "0.0.0-pr-
|
|
37
|
+
"@nx/devkit": "0.0.0-pr-27940-4ec79a3"
|
|
38
38
|
},
|
|
39
39
|
"publishConfig": {
|
|
40
40
|
"access": "public"
|
|
@@ -4,11 +4,18 @@ exports.initGenerator = initGenerator;
|
|
|
4
4
|
exports.addBuildGradleFileNextToSettingsGradle = addBuildGradleFileNextToSettingsGradle;
|
|
5
5
|
exports.updateNxJsonConfiguration = updateNxJsonConfiguration;
|
|
6
6
|
const devkit_1 = require("@nx/devkit");
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
7
8
|
const versions_1 = require("../../utils/versions");
|
|
8
9
|
const has_gradle_plugin_1 = require("../../utils/has-gradle-plugin");
|
|
9
10
|
const path_1 = require("path");
|
|
10
11
|
async function initGenerator(tree, options) {
|
|
11
12
|
const tasks = [];
|
|
13
|
+
if (!tree.exists('settings.gradle') && !tree.exists('settings.gradle.kts')) {
|
|
14
|
+
devkit_1.logger.warn(`Could not find 'settings.gradle' or 'settings.gradle.kts' file in your gradle workspace.
|
|
15
|
+
A Gradle build should contain a 'settings.gradle' or 'settings.gradle.kts' file in its root directory. It may also contain a 'build.gradle' or 'build.gradle.kts' file.
|
|
16
|
+
Running 'gradle init':`);
|
|
17
|
+
(0, child_process_1.execSync)('gradle init', { stdio: 'inherit' });
|
|
18
|
+
}
|
|
12
19
|
if (!options.skipPackageJson && tree.exists('package.json')) {
|
|
13
20
|
tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
|
|
14
21
|
'@nx/gradle': versions_1.nxVersion,
|
|
@@ -6,8 +6,6 @@ const devkit_1 = require("@nx/devkit");
|
|
|
6
6
|
const node_fs_1 = require("node:fs");
|
|
7
7
|
const node_path_1 = require("node:path");
|
|
8
8
|
const get_gradle_report_1 = require("../utils/get-gradle-report");
|
|
9
|
-
const split_config_files_1 = require("../utils/split-config-files");
|
|
10
|
-
const get_project_report_lines_1 = require("../utils/get-project-report-lines");
|
|
11
9
|
const createDependencies = async (_, context) => {
|
|
12
10
|
const gradleFiles = findGradleFiles(context.filesToProcess);
|
|
13
11
|
if (gradleFiles.length === 0) {
|
|
@@ -45,7 +43,7 @@ function findGradleFiles(fileMap) {
|
|
|
45
43
|
const gradleFiles = [];
|
|
46
44
|
for (const [_, files] of Object.entries(fileMap.projectFileMap)) {
|
|
47
45
|
for (const file of files) {
|
|
48
|
-
if (
|
|
46
|
+
if (get_gradle_report_1.GRADLE_BUILD_FILES.has((0, node_path_1.basename)(file.file))) {
|
|
49
47
|
gradleFiles.push(file.file);
|
|
50
48
|
}
|
|
51
49
|
}
|
|
@@ -53,7 +51,7 @@ function findGradleFiles(fileMap) {
|
|
|
53
51
|
return gradleFiles;
|
|
54
52
|
}
|
|
55
53
|
function processGradleDependencies(depsFile, gradleProjectNameToProjectRoot, sourceProjectName, gradleFile, context, dependencies) {
|
|
56
|
-
const lines = (0, node_fs_1.readFileSync)(depsFile).toString().split(
|
|
54
|
+
const lines = (0, node_fs_1.readFileSync)(depsFile).toString().split(get_gradle_report_1.newLineSeparator);
|
|
57
55
|
let inDeps = false;
|
|
58
56
|
for (const line of lines) {
|
|
59
57
|
if (line.startsWith('implementationDependenciesMetadata') ||
|
package/src/plugin/nodes.js
CHANGED
|
@@ -8,10 +8,9 @@ const node_fs_1 = require("node:fs");
|
|
|
8
8
|
const node_path_1 = require("node:path");
|
|
9
9
|
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
|
10
10
|
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
11
|
+
const exec_gradle_1 = require("../utils/exec-gradle");
|
|
11
12
|
const get_gradle_report_1 = require("../utils/get-gradle-report");
|
|
12
13
|
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
14
|
const cacheableTaskType = new Set(['Build', 'Verification']);
|
|
16
15
|
const dependsOnMap = {
|
|
17
16
|
build: ['^build', 'classes'],
|
|
@@ -33,17 +32,17 @@ function writeTargetsToCache(cachePath, results) {
|
|
|
33
32
|
(0, devkit_1.writeJsonFile)(cachePath, results);
|
|
34
33
|
}
|
|
35
34
|
exports.createNodesV2 = [
|
|
36
|
-
|
|
35
|
+
get_gradle_report_1.gradleConfigAndTestGlob,
|
|
37
36
|
async (files, options, context) => {
|
|
38
|
-
const {
|
|
37
|
+
const { configFiles, projectRoots, testFiles } = splitConfigFiles(files);
|
|
39
38
|
const optionsHash = (0, file_hasher_1.hashObject)(options);
|
|
40
39
|
const cachePath = (0, node_path_1.join)(cache_directory_1.workspaceDataDirectory, `gradle-${optionsHash}.hash`);
|
|
41
40
|
const targetsCache = readTargetsCache(cachePath);
|
|
42
|
-
await (0, get_gradle_report_1.populateGradleReport)(context.workspaceRoot
|
|
41
|
+
await (0, get_gradle_report_1.populateGradleReport)(context.workspaceRoot);
|
|
43
42
|
const gradleReport = (0, get_gradle_report_1.getCurrentGradleReport)();
|
|
44
43
|
const gradleProjectRootToTestFilesMap = getGradleProjectRootToTestFilesMap(testFiles, projectRoots);
|
|
45
44
|
try {
|
|
46
|
-
return (0, devkit_1.createNodesFromFiles)((0, exports.makeCreateNodesForGradleConfigFile)(gradleReport, targetsCache, gradleProjectRootToTestFilesMap),
|
|
45
|
+
return (0, devkit_1.createNodesFromFiles)((0, exports.makeCreateNodesForGradleConfigFile)(gradleReport, targetsCache, gradleProjectRootToTestFilesMap), configFiles, options, context);
|
|
47
46
|
}
|
|
48
47
|
finally {
|
|
49
48
|
writeTargetsToCache(cachePath, targetsCache);
|
|
@@ -71,14 +70,13 @@ exports.makeCreateNodesForGradleConfigFile = makeCreateNodesForGradleConfigFile;
|
|
|
71
70
|
This function will change to the v2 function in Nx 20.
|
|
72
71
|
*/
|
|
73
72
|
exports.createNodes = [
|
|
74
|
-
|
|
75
|
-
async (
|
|
73
|
+
get_gradle_report_1.gradleConfigGlob,
|
|
74
|
+
async (configFile, options, context) => {
|
|
76
75
|
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
|
-
|
|
78
|
-
await (0, get_gradle_report_1.populateGradleReport)(context.workspaceRoot, gradlewFiles);
|
|
76
|
+
await (0, get_gradle_report_1.populateGradleReport)(context.workspaceRoot);
|
|
79
77
|
const gradleReport = (0, get_gradle_report_1.getCurrentGradleReport)();
|
|
80
78
|
const internalCreateNodes = (0, exports.makeCreateNodesForGradleConfigFile)(gradleReport);
|
|
81
|
-
return await internalCreateNodes(
|
|
79
|
+
return await internalCreateNodes(configFile, options, context);
|
|
82
80
|
},
|
|
83
81
|
];
|
|
84
82
|
async function createGradleProject(gradleReport, gradleFilePath, options, context, testFiles = []) {
|
|
@@ -114,9 +112,8 @@ async function createGradleProject(gradleReport, gradleFilePath, options, contex
|
|
|
114
112
|
return undefined;
|
|
115
113
|
}
|
|
116
114
|
}
|
|
117
|
-
async function createGradleTargets(tasks, options, context, outputDirs, gradleProject,
|
|
115
|
+
async function createGradleTargets(tasks, options, context, outputDirs, gradleProject, gradleFilePath, testFiles = []) {
|
|
118
116
|
const inputsMap = createInputsMap(context);
|
|
119
|
-
const gradlewFileDirectory = (0, node_path_1.dirname)((0, exec_gradle_1.findGraldewFile)(gradleBuildFilePath, context.workspaceRoot));
|
|
120
117
|
const targets = {};
|
|
121
118
|
const targetGroups = {};
|
|
122
119
|
for (const task of tasks) {
|
|
@@ -127,14 +124,11 @@ async function createGradleTargets(tasks, options, context, outputDirs, gradlePr
|
|
|
127
124
|
outputDirs.get('testReport'),
|
|
128
125
|
outputDirs.get('testResults'),
|
|
129
126
|
].filter(Boolean);
|
|
130
|
-
getTestCiTargets(testFiles, gradleProject, targetName, options.ciTargetName, inputsMap['test'], outputs, task.type, targets, targetGroups
|
|
127
|
+
getTestCiTargets(testFiles, gradleProject, targetName, options.ciTargetName, inputsMap['test'], outputs, task.type, targets, targetGroups);
|
|
131
128
|
}
|
|
132
129
|
const taskCommandToRun = `${gradleProject ? gradleProject + ':' : ''}${task.name}`;
|
|
133
130
|
targets[targetName] = {
|
|
134
131
|
command: `${(0, exec_gradle_1.getGradleExecFile)()} ${taskCommandToRun}`,
|
|
135
|
-
options: {
|
|
136
|
-
cwd: gradlewFileDirectory,
|
|
137
|
-
},
|
|
138
132
|
cache: cacheableTaskType.has(task.type),
|
|
139
133
|
inputs: inputsMap[task.name],
|
|
140
134
|
dependsOn: dependsOnMap[task.name],
|
|
@@ -170,7 +164,7 @@ function createInputsMap(context) {
|
|
|
170
164
|
: ['default', '^default'],
|
|
171
165
|
};
|
|
172
166
|
}
|
|
173
|
-
function getTestCiTargets(testFiles, gradleProject, testTargetName, ciTargetName, inputs, outputs, targetGroupName, targets, targetGroups
|
|
167
|
+
function getTestCiTargets(testFiles, gradleProject, testTargetName, ciTargetName, inputs, outputs, targetGroupName, targets, targetGroups) {
|
|
174
168
|
if (!testFiles || testFiles.length === 0 || !ciTargetName) {
|
|
175
169
|
return;
|
|
176
170
|
}
|
|
@@ -184,9 +178,6 @@ function getTestCiTargets(testFiles, gradleProject, testTargetName, ciTargetName
|
|
|
184
178
|
const targetName = ciTargetName + '--' + testName;
|
|
185
179
|
targets[targetName] = {
|
|
186
180
|
command: `${(0, exec_gradle_1.getGradleExecFile)()} ${taskCommandToRun} --tests ${testName}`,
|
|
187
|
-
options: {
|
|
188
|
-
cwd: gradlewFileDirectory,
|
|
189
|
-
},
|
|
190
181
|
cache: true,
|
|
191
182
|
inputs,
|
|
192
183
|
dependsOn: dependsOnMap['test'],
|
|
@@ -233,6 +224,21 @@ function getTestCiTargets(testFiles, gradleProject, testTargetName, ciTargetName
|
|
|
233
224
|
};
|
|
234
225
|
targetGroups[targetGroupName].push(ciTargetName);
|
|
235
226
|
}
|
|
227
|
+
function splitConfigFiles(files) {
|
|
228
|
+
const configFiles = [];
|
|
229
|
+
const testFiles = [];
|
|
230
|
+
const projectRoots = new Set();
|
|
231
|
+
files.forEach((file) => {
|
|
232
|
+
if (get_gradle_report_1.GRADLE_BUILD_FILES.has((0, node_path_1.basename)(file))) {
|
|
233
|
+
configFiles.push(file);
|
|
234
|
+
projectRoots.add((0, node_path_1.dirname)(file));
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
testFiles.push(file);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
return { configFiles, testFiles, projectRoots: Array.from(projectRoots) };
|
|
241
|
+
}
|
|
236
242
|
function getGradleProjectRootToTestFilesMap(testFiles, projectRoots) {
|
|
237
243
|
if (testFiles.length === 0 || projectRoots.length === 0) {
|
|
238
244
|
return;
|
|
@@ -1,23 +1,4 @@
|
|
|
1
1
|
import { ExecFileOptions } from 'node:child_process';
|
|
2
|
-
|
|
3
|
-
* For gradle command, it needs to be run from the directory of the gradle binary
|
|
4
|
-
* @returns gradle binary file name
|
|
5
|
-
*/
|
|
2
|
+
export declare function getGradleBinaryPath(): string;
|
|
6
3
|
export declare function getGradleExecFile(): string;
|
|
7
|
-
|
|
8
|
-
* This function executes gradle with the given arguments
|
|
9
|
-
* @param gradleBinaryPath absolute path to gradle binary
|
|
10
|
-
* @param args args passed to gradle
|
|
11
|
-
* @param execOptions exec options
|
|
12
|
-
* @returns promise with the stdout buffer
|
|
13
|
-
*/
|
|
14
|
-
export declare function execGradleAsync(gradleBinaryPath: string, args: ReadonlyArray<string>, execOptions?: ExecFileOptions): Promise<Buffer>;
|
|
15
|
-
/**
|
|
16
|
-
* This function recursively finds the nearest gradlew file in the workspace
|
|
17
|
-
* @param originalFileToSearch the original file to search for
|
|
18
|
-
* @param wr workspace root
|
|
19
|
-
* @param currentSearchPath the path to start searching for gradlew file
|
|
20
|
-
* @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
|
|
22
|
-
*/
|
|
23
|
-
export declare function findGraldewFile(originalFileToSearch: string, wr?: string, currentSearchPath?: string): string;
|
|
4
|
+
export declare function execGradleAsync(args: ReadonlyArray<string>, execOptions?: ExecFileOptions): Promise<Buffer>;
|
package/src/utils/exec-gradle.js
CHANGED
|
@@ -1,34 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getGradleBinaryPath = getGradleBinaryPath;
|
|
3
4
|
exports.getGradleExecFile = getGradleExecFile;
|
|
4
5
|
exports.execGradleAsync = execGradleAsync;
|
|
5
|
-
exports.findGraldewFile = findGraldewFile;
|
|
6
6
|
const devkit_1 = require("@nx/devkit");
|
|
7
7
|
const node_child_process_1 = require("node:child_process");
|
|
8
8
|
const node_fs_1 = require("node:fs");
|
|
9
9
|
const node_path_1 = require("node:path");
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
function getGradleBinaryPath() {
|
|
11
|
+
const gradleFile = process.platform.startsWith('win')
|
|
12
|
+
? 'gradlew.bat'
|
|
13
|
+
: 'gradlew';
|
|
14
|
+
const gradleBinaryPath = (0, node_path_1.join)(devkit_1.workspaceRoot, gradleFile);
|
|
15
|
+
if (!(0, node_fs_1.existsSync)(gradleBinaryPath)) {
|
|
16
|
+
throw new Error('Gradle is not setup. Run "gradle init"');
|
|
17
|
+
}
|
|
18
|
+
return gradleBinaryPath;
|
|
19
|
+
}
|
|
14
20
|
function getGradleExecFile() {
|
|
15
21
|
return process.platform.startsWith('win') ? '.\\gradlew.bat' : './gradlew';
|
|
16
22
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* @param gradleBinaryPath absolute path to gradle binary
|
|
20
|
-
* @param args args passed to gradle
|
|
21
|
-
* @param execOptions exec options
|
|
22
|
-
* @returns promise with the stdout buffer
|
|
23
|
-
*/
|
|
24
|
-
function execGradleAsync(gradleBinaryPath, args, execOptions = {}) {
|
|
23
|
+
function execGradleAsync(args, execOptions = {}) {
|
|
24
|
+
const gradleBinaryPath = getGradleBinaryPath();
|
|
25
25
|
return new Promise((res, rej) => {
|
|
26
26
|
const cp = (0, node_child_process_1.execFile)(gradleBinaryPath, args, {
|
|
27
|
-
|
|
27
|
+
...execOptions,
|
|
28
28
|
shell: true,
|
|
29
29
|
windowsHide: true,
|
|
30
30
|
env: process.env,
|
|
31
|
-
...execOptions,
|
|
32
31
|
});
|
|
33
32
|
let stdout = Buffer.from('');
|
|
34
33
|
cp.stdout?.on('data', (data) => {
|
|
@@ -44,36 +43,3 @@ function execGradleAsync(gradleBinaryPath, args, execOptions = {}) {
|
|
|
44
43
|
});
|
|
45
44
|
});
|
|
46
45
|
}
|
|
47
|
-
/**
|
|
48
|
-
* This function recursively finds the nearest gradlew file in the workspace
|
|
49
|
-
* @param originalFileToSearch the original file to search for
|
|
50
|
-
* @param wr workspace root
|
|
51
|
-
* @param currentSearchPath the path to start searching for gradlew file
|
|
52
|
-
* @returns the relative path of the gradlew file to workspace root, throws an error if gradlew file is not found
|
|
53
|
-
* It will return gradlew.bat file on windows and gradlew file on other platforms
|
|
54
|
-
*/
|
|
55
|
-
function findGraldewFile(originalFileToSearch, wr = devkit_1.workspaceRoot, currentSearchPath) {
|
|
56
|
-
currentSearchPath ??= originalFileToSearch;
|
|
57
|
-
const parent = (0, node_path_1.dirname)(currentSearchPath);
|
|
58
|
-
if (currentSearchPath === parent) {
|
|
59
|
-
throw new devkit_1.AggregateCreateNodesError([
|
|
60
|
-
[
|
|
61
|
-
originalFileToSearch,
|
|
62
|
-
new Error('No Gradlew file found. Run "gradle init"'),
|
|
63
|
-
],
|
|
64
|
-
], []);
|
|
65
|
-
}
|
|
66
|
-
const gradlewPath = (0, node_path_1.join)(parent, 'gradlew');
|
|
67
|
-
const gradlewBatPath = (0, node_path_1.join)(parent, 'gradlew.bat');
|
|
68
|
-
if (process.platform.startsWith('win')) {
|
|
69
|
-
if ((0, node_fs_1.existsSync)((0, node_path_1.join)(wr, gradlewBatPath))) {
|
|
70
|
-
return gradlewBatPath;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
if ((0, node_fs_1.existsSync)((0, node_path_1.join)(wr, gradlewPath))) {
|
|
75
|
-
return gradlewPath;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return findGraldewFile(originalFileToSearch, wr, parent);
|
|
79
|
-
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export declare const fileSeparator: string;
|
|
2
|
+
export declare const newLineSeparator: string;
|
|
1
3
|
export interface GradleReport {
|
|
2
4
|
gradleFileToGradleProjectMap: Map<string, string>;
|
|
3
5
|
buildFileToDepsMap: Map<string, string>;
|
|
@@ -7,16 +9,10 @@ export interface GradleReport {
|
|
|
7
9
|
gradleProjectNameToProjectRootMap: Map<string, string>;
|
|
8
10
|
gradleProjectToChildProjects: Map<string, string[]>;
|
|
9
11
|
}
|
|
12
|
+
export declare const GRADLE_BUILD_FILES: Set<string>;
|
|
13
|
+
export declare const GRADLE_TEST_FILES: string[];
|
|
14
|
+
export declare const gradleConfigGlob: string;
|
|
15
|
+
export declare const gradleConfigAndTestGlob: string;
|
|
10
16
|
export declare function getCurrentGradleReport(): GradleReport;
|
|
11
|
-
|
|
12
|
-
* This function populates the gradle report cache.
|
|
13
|
-
* For each gradlew file, it runs the `projectReportAll` task and processes the output.
|
|
14
|
-
* If `projectReportAll` fails, it runs the `projectReport` task instead.
|
|
15
|
-
* It will throw an error if both tasks fail.
|
|
16
|
-
* It will accumulate the output of all gradlew files.
|
|
17
|
-
* @param workspaceRoot
|
|
18
|
-
* @param gradlewFiles absolute paths to all gradlew files in the workspace
|
|
19
|
-
* @returns Promise<void>
|
|
20
|
-
*/
|
|
21
|
-
export declare function populateGradleReport(workspaceRoot: string, gradlewFiles: string[]): Promise<void>;
|
|
17
|
+
export declare function populateGradleReport(workspaceRoot: string): Promise<void>;
|
|
22
18
|
export declare function processProjectReports(projectReportLines: string[]): GradleReport;
|
|
@@ -1,54 +1,75 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.gradleConfigAndTestGlob = exports.gradleConfigGlob = exports.GRADLE_TEST_FILES = exports.GRADLE_BUILD_FILES = exports.newLineSeparator = exports.fileSeparator = void 0;
|
|
3
4
|
exports.getCurrentGradleReport = getCurrentGradleReport;
|
|
4
5
|
exports.populateGradleReport = populateGradleReport;
|
|
5
6
|
exports.processProjectReports = processProjectReports;
|
|
6
7
|
const node_fs_1 = require("node:fs");
|
|
7
8
|
const node_path_1 = require("node:path");
|
|
8
9
|
const devkit_1 = require("@nx/devkit");
|
|
10
|
+
const globs_1 = require("nx/src/utils/globs");
|
|
11
|
+
const exec_gradle_1 = require("./exec-gradle");
|
|
9
12
|
const workspace_context_1 = require("nx/src/utils/workspace-context");
|
|
10
13
|
const path_1 = require("path");
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
exports.fileSeparator = process.platform.startsWith('win')
|
|
15
|
+
? 'file:///'
|
|
16
|
+
: 'file://';
|
|
17
|
+
exports.newLineSeparator = process.platform.startsWith('win')
|
|
18
|
+
? '\r\n'
|
|
19
|
+
: '\n';
|
|
13
20
|
let gradleReportCache;
|
|
14
21
|
let gradleCurrentConfigHash;
|
|
22
|
+
exports.GRADLE_BUILD_FILES = new Set(['build.gradle', 'build.gradle.kts']);
|
|
23
|
+
exports.GRADLE_TEST_FILES = [
|
|
24
|
+
'**/src/test/java/**/*Test.java',
|
|
25
|
+
'**/src/test/kotlin/**/*Test.kt',
|
|
26
|
+
'**/src/test/java/**/*Tests.java',
|
|
27
|
+
'**/src/test/kotlin/**/*Tests.kt',
|
|
28
|
+
];
|
|
29
|
+
exports.gradleConfigGlob = (0, globs_1.combineGlobPatterns)(...Array.from(exports.GRADLE_BUILD_FILES).map((file) => `**/${file}`));
|
|
30
|
+
exports.gradleConfigAndTestGlob = (0, globs_1.combineGlobPatterns)(...Array.from(exports.GRADLE_BUILD_FILES).map((file) => `**/${file}`), ...exports.GRADLE_TEST_FILES);
|
|
15
31
|
function getCurrentGradleReport() {
|
|
16
32
|
if (!gradleReportCache) {
|
|
17
|
-
throw new
|
|
18
|
-
[
|
|
19
|
-
null,
|
|
20
|
-
new Error(`Expected cached gradle report. Please open an issue at https://github.com/nrwl/nx/issues/new/choose`),
|
|
21
|
-
],
|
|
22
|
-
], []);
|
|
33
|
+
throw new Error('Expected cached gradle report. Please open an issue at https://github.com/nrwl/nx/issues/new/choose');
|
|
23
34
|
}
|
|
24
35
|
return gradleReportCache;
|
|
25
36
|
}
|
|
26
|
-
|
|
27
|
-
* This function populates the gradle report cache.
|
|
28
|
-
* For each gradlew file, it runs the `projectReportAll` task and processes the output.
|
|
29
|
-
* If `projectReportAll` fails, it runs the `projectReport` task instead.
|
|
30
|
-
* It will throw an error if both tasks fail.
|
|
31
|
-
* It will accumulate the output of all gradlew files.
|
|
32
|
-
* @param workspaceRoot
|
|
33
|
-
* @param gradlewFiles absolute paths to all gradlew files in the workspace
|
|
34
|
-
* @returns Promise<void>
|
|
35
|
-
*/
|
|
36
|
-
async function populateGradleReport(workspaceRoot, gradlewFiles) {
|
|
37
|
+
async function populateGradleReport(workspaceRoot) {
|
|
37
38
|
const gradleConfigHash = await (0, workspace_context_1.hashWithWorkspaceContext)(workspaceRoot, [
|
|
38
|
-
|
|
39
|
+
exports.gradleConfigGlob,
|
|
39
40
|
]);
|
|
40
41
|
if (gradleReportCache && gradleConfigHash === gradleCurrentConfigHash) {
|
|
41
42
|
return;
|
|
42
43
|
}
|
|
43
44
|
const gradleProjectReportStart = performance.mark('gradleProjectReport:start');
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
let projectReportLines;
|
|
46
|
+
try {
|
|
47
|
+
projectReportLines = await (0, exec_gradle_1.execGradleAsync)(['projectReportAll'], {
|
|
48
|
+
cwd: workspaceRoot,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
try {
|
|
53
|
+
projectReportLines = await (0, exec_gradle_1.execGradleAsync)(['projectReport'], {
|
|
54
|
+
cwd: workspaceRoot,
|
|
55
|
+
});
|
|
56
|
+
devkit_1.logger.warn('Could not run `projectReportAll` task. Ran `projectReport` instead. Please run `nx generate @nx/gradle:init` to generate the necessary tasks.');
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
throw new devkit_1.AggregateCreateNodesError([
|
|
60
|
+
[
|
|
61
|
+
null,
|
|
62
|
+
new Error('Could not run `projectReportAll` or `projectReport` task. Please run `nx generate @nx/gradle:init` to generate the necessary tasks.'),
|
|
63
|
+
],
|
|
64
|
+
], []);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
projectReportLines = projectReportLines
|
|
68
|
+
.toString()
|
|
69
|
+
.split(exports.newLineSeparator)
|
|
70
|
+
.filter((line) => line.trim() !== '');
|
|
49
71
|
const gradleProjectReportEnd = performance.mark('gradleProjectReport:end');
|
|
50
72
|
performance.measure('gradleProjectReport', gradleProjectReportStart.name, gradleProjectReportEnd.name);
|
|
51
|
-
gradleCurrentConfigHash = gradleConfigHash;
|
|
52
73
|
gradleReportCache = processProjectReports(projectReportLines);
|
|
53
74
|
}
|
|
54
75
|
function processProjectReports(projectReportLines) {
|
|
@@ -83,21 +104,21 @@ function processProjectReports(projectReportLines) {
|
|
|
83
104
|
if (line.endsWith(':dependencyReport')) {
|
|
84
105
|
const gradleProject = line.substring('> Task '.length, line.length - ':dependencyReport'.length);
|
|
85
106
|
while (index < projectReportLines.length &&
|
|
86
|
-
!projectReportLines[index].includes(
|
|
107
|
+
!projectReportLines[index].includes(exports.fileSeparator)) {
|
|
87
108
|
index++;
|
|
88
109
|
}
|
|
89
|
-
const [_, file] = projectReportLines[index].split(
|
|
110
|
+
const [_, file] = projectReportLines[index].split(exports.fileSeparator);
|
|
90
111
|
dependenciesMap.set(gradleProject, file);
|
|
91
112
|
}
|
|
92
113
|
if (line.endsWith('propertyReport')) {
|
|
93
114
|
const gradleProject = line.substring('> Task '.length, line.length - ':propertyReport'.length);
|
|
94
115
|
while (index < projectReportLines.length &&
|
|
95
|
-
!projectReportLines[index].includes(
|
|
116
|
+
!projectReportLines[index].includes(exports.fileSeparator)) {
|
|
96
117
|
index++;
|
|
97
118
|
}
|
|
98
|
-
const [_, file] = projectReportLines[index].split(
|
|
119
|
+
const [_, file] = projectReportLines[index].split(exports.fileSeparator);
|
|
99
120
|
const propertyReportLines = (0, node_fs_1.existsSync)(file)
|
|
100
|
-
? (0, node_fs_1.readFileSync)(file).toString().split(
|
|
121
|
+
? (0, node_fs_1.readFileSync)(file).toString().split(exports.newLineSeparator)
|
|
101
122
|
: [];
|
|
102
123
|
let projectName, absBuildFilePath, absBuildDirPath;
|
|
103
124
|
const outputDirMap = new Map();
|
|
@@ -141,13 +162,13 @@ function processProjectReports(projectReportLines) {
|
|
|
141
162
|
if (line.endsWith('taskReport')) {
|
|
142
163
|
const gradleProject = line.substring('> Task '.length, line.length - ':taskReport'.length);
|
|
143
164
|
while (index < projectReportLines.length &&
|
|
144
|
-
!projectReportLines[index].includes(
|
|
165
|
+
!projectReportLines[index].includes(exports.fileSeparator)) {
|
|
145
166
|
index++;
|
|
146
167
|
}
|
|
147
|
-
const [_, file] = projectReportLines[index].split(
|
|
168
|
+
const [_, file] = projectReportLines[index].split(exports.fileSeparator);
|
|
148
169
|
const taskTypeMap = new Map();
|
|
149
170
|
const tasksFileLines = (0, node_fs_1.existsSync)(file)
|
|
150
|
-
? (0, node_fs_1.readFileSync)(file).toString().split(
|
|
171
|
+
? (0, node_fs_1.readFileSync)(file).toString().split(exports.newLineSeparator)
|
|
151
172
|
: [];
|
|
152
173
|
let i = 0;
|
|
153
174
|
while (i < tasksFileLines.length) {
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export declare const fileSeparator: string;
|
|
2
|
-
export declare const newLineSeparator: string;
|
|
3
|
-
/**
|
|
4
|
-
* This function executes the gradle projectReportAll task and returns the output as an array of lines.
|
|
5
|
-
* @param gradlewFile the absolute path to the gradlew file
|
|
6
|
-
* @returns project report lines
|
|
7
|
-
*/
|
|
8
|
-
export declare function getProjectReportLines(gradlewFile: string): Promise<string[]>;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.newLineSeparator = exports.fileSeparator = void 0;
|
|
4
|
-
exports.getProjectReportLines = getProjectReportLines;
|
|
5
|
-
const devkit_1 = require("@nx/devkit");
|
|
6
|
-
const exec_gradle_1 = require("./exec-gradle");
|
|
7
|
-
const fs_1 = require("fs");
|
|
8
|
-
const path_1 = require("path");
|
|
9
|
-
exports.fileSeparator = process.platform.startsWith('win')
|
|
10
|
-
? 'file:///'
|
|
11
|
-
: 'file://';
|
|
12
|
-
exports.newLineSeparator = process.platform.startsWith('win')
|
|
13
|
-
? '\r\n'
|
|
14
|
-
: '\n';
|
|
15
|
-
/**
|
|
16
|
-
* This function executes the gradle projectReportAll task and returns the output as an array of lines.
|
|
17
|
-
* @param gradlewFile the absolute path to the gradlew file
|
|
18
|
-
* @returns project report lines
|
|
19
|
-
*/
|
|
20
|
-
async function getProjectReportLines(gradlewFile) {
|
|
21
|
-
let projectReportBuffer;
|
|
22
|
-
// if there is no build.gradle or build.gradle.kts file, we cannot run the projectReport nor projectReportAll task
|
|
23
|
-
if (!(0, fs_1.existsSync)((0, path_1.join)((0, path_1.dirname)(gradlewFile), 'build.gradle')) &&
|
|
24
|
-
!(0, fs_1.existsSync)((0, path_1.join)((0, path_1.dirname)(gradlewFile), 'build.gradle.kts'))) {
|
|
25
|
-
devkit_1.logger.warn(`Could not find build file near ${gradlewFile}. Please run 'nx generate @nx/gradle:init' to generate the necessary tasks.`);
|
|
26
|
-
return [];
|
|
27
|
-
}
|
|
28
|
-
try {
|
|
29
|
-
projectReportBuffer = await (0, exec_gradle_1.execGradleAsync)(gradlewFile, [
|
|
30
|
-
'projectReportAll',
|
|
31
|
-
]);
|
|
32
|
-
}
|
|
33
|
-
catch (e) {
|
|
34
|
-
try {
|
|
35
|
-
projectReportBuffer = await (0, exec_gradle_1.execGradleAsync)(gradlewFile, [
|
|
36
|
-
'projectReport',
|
|
37
|
-
]);
|
|
38
|
-
devkit_1.logger.warn(`Could not run 'projectReportAll' task. Ran 'projectReport' instead. Please run 'nx generate @nx/gradle:init' to generate the necessary tasks.`);
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
throw new devkit_1.AggregateCreateNodesError([
|
|
42
|
-
[
|
|
43
|
-
gradlewFile,
|
|
44
|
-
new Error(`Could not run 'projectReportAll' or 'projectReport' task. Please run 'nx generate @nx/gradle:init' to generate the necessary tasks.`),
|
|
45
|
-
],
|
|
46
|
-
], []);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return projectReportBuffer
|
|
50
|
-
.toString()
|
|
51
|
-
.split(exports.newLineSeparator)
|
|
52
|
-
.filter((line) => line.trim() !== '');
|
|
53
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export declare const GRADLE_BUILD_FILES: Set<string>;
|
|
2
|
-
export declare const GRALDEW_FILES: Set<string>;
|
|
3
|
-
export declare const GRADLE_TEST_FILES: string[];
|
|
4
|
-
export declare const gradleConfigGlob: string;
|
|
5
|
-
export declare const gradleConfigAndTestGlob: string;
|
|
6
|
-
/**
|
|
7
|
-
* This function split config files into build files, settings files, test files and project roots
|
|
8
|
-
* @param files list of files to split
|
|
9
|
-
* @returns object with buildFiles, gradlewFiles, testFiles and projectRoots
|
|
10
|
-
* For gradlewFiles, it will start with settings files and find the nearest gradlew file in the workspace
|
|
11
|
-
*/
|
|
12
|
-
export declare function splitConfigFiles(files: readonly string[]): {
|
|
13
|
-
buildFiles: string[];
|
|
14
|
-
gradlewFiles: string[];
|
|
15
|
-
testFiles: string[];
|
|
16
|
-
projectRoots: string[];
|
|
17
|
-
};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.gradleConfigAndTestGlob = exports.gradleConfigGlob = exports.GRADLE_TEST_FILES = exports.GRALDEW_FILES = exports.GRADLE_BUILD_FILES = void 0;
|
|
4
|
-
exports.splitConfigFiles = splitConfigFiles;
|
|
5
|
-
const globs_1 = require("nx/src/utils/globs");
|
|
6
|
-
const node_path_1 = require("node:path");
|
|
7
|
-
exports.GRADLE_BUILD_FILES = new Set(['build.gradle', 'build.gradle.kts']);
|
|
8
|
-
exports.GRALDEW_FILES = new Set(['gradlew', 'gradlew.bat']);
|
|
9
|
-
exports.GRADLE_TEST_FILES = [
|
|
10
|
-
'**/src/test/java/**/*Test.java',
|
|
11
|
-
'**/src/test/kotlin/**/*Test.kt',
|
|
12
|
-
'**/src/test/java/**/*Tests.java',
|
|
13
|
-
'**/src/test/kotlin/**/*Tests.kt',
|
|
14
|
-
];
|
|
15
|
-
exports.gradleConfigGlob = (0, globs_1.combineGlobPatterns)(...Array.from(exports.GRADLE_BUILD_FILES).map((file) => `**/${file}`));
|
|
16
|
-
exports.gradleConfigAndTestGlob = (0, globs_1.combineGlobPatterns)(...Array.from(exports.GRADLE_BUILD_FILES).map((file) => `**/${file}`), ...Array.from(exports.GRALDEW_FILES).map((file) => `**/${file}`), ...exports.GRADLE_TEST_FILES);
|
|
17
|
-
/**
|
|
18
|
-
* This function split config files into build files, settings files, test files and project roots
|
|
19
|
-
* @param files list of files to split
|
|
20
|
-
* @returns object with buildFiles, gradlewFiles, testFiles and projectRoots
|
|
21
|
-
* For gradlewFiles, it will start with settings files and find the nearest gradlew file in the workspace
|
|
22
|
-
*/
|
|
23
|
-
function splitConfigFiles(files) {
|
|
24
|
-
const buildFiles = [];
|
|
25
|
-
const testFiles = [];
|
|
26
|
-
const gradlewFiles = [];
|
|
27
|
-
const projectRoots = new Set();
|
|
28
|
-
files.forEach((file) => {
|
|
29
|
-
const filename = (0, node_path_1.basename)(file);
|
|
30
|
-
const fileDirectory = (0, node_path_1.dirname)(file);
|
|
31
|
-
if (exports.GRADLE_BUILD_FILES.has(filename)) {
|
|
32
|
-
buildFiles.push(file);
|
|
33
|
-
projectRoots.add(fileDirectory);
|
|
34
|
-
}
|
|
35
|
-
else if (exports.GRALDEW_FILES.has(filename)) {
|
|
36
|
-
if (process.platform.startsWith('win')) {
|
|
37
|
-
if (filename === 'gradlew.bat') {
|
|
38
|
-
gradlewFiles.push(file);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
if (filename === 'gradlew') {
|
|
43
|
-
gradlewFiles.push(file);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
testFiles.push(file);
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
return {
|
|
52
|
-
buildFiles,
|
|
53
|
-
testFiles,
|
|
54
|
-
gradlewFiles,
|
|
55
|
-
projectRoots: Array.from(projectRoots),
|
|
56
|
-
};
|
|
57
|
-
}
|