Skip to content

Commit

Permalink
fix(gradle): fix gradle to work on windows (#22470)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi authored Mar 25, 2024
1 parent 80e6b8e commit e0519d9
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions packages/gradle/src/utils/get-gradle-report.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { readFileSync } from 'node:fs';
import { join, relative } from 'node:path';

import { workspaceRoot } from '@nx/devkit';
import { normalizePath, workspaceRoot } from '@nx/devkit';

import { execGradle } from './exec-gradle';

const fileSeparator = process.platform.startsWith('win')
? 'file:///'
: 'file://';

const newLineSeparator = process.platform.startsWith('win') ? '\r\n' : '\n';

interface GradleReport {
gradleFileToGradleProjectMap: Map<string, string>;
buildFileToDepsMap: Map<string, string>;
Expand All @@ -31,7 +37,7 @@ export function getGradleReport(): GradleReport {
cwd: workspaceRoot,
})
.toString()
.split('\n');
.split(newLineSeparator);
const gradleProjectReportEnd = performance.mark('gradleProjectReport:end');
performance.measure(
'gradleProjectReport',
Expand Down Expand Up @@ -75,16 +81,18 @@ function processProjectReports(projectReportLines: string[]): GradleReport {
'> Task '.length,
line.length - ':dependencyReport'.length
);
const [_, file] = nextLine.split('file://');
const [_, file] = nextLine.split(fileSeparator);
dependenciesMap.set(gradleProject, file);
}
if (line.endsWith('propertyReport')) {
const gradleProject = line.substring(
'> Task '.length,
line.length - ':propertyReport'.length
);
const [_, file] = nextLine.split('file://');
const propertyReportLines = readFileSync(file).toString().split('\n');
const [_, file] = nextLine.split(fileSeparator);
const propertyReportLines = readFileSync(file)
.toString()
.split(newLineSeparator);

let projectName: string,
absBuildFilePath: string,
Expand Down Expand Up @@ -113,7 +121,9 @@ function processProjectReports(projectReportLines: string[]): GradleReport {
if (!projectName || !absBuildFilePath || !absBuildDirPath) {
return;
}
const buildFile = relative(workspaceRoot, absBuildFilePath);
const buildFile = normalizePath(
relative(workspaceRoot, absBuildFilePath)
);
const buildDir = relative(workspaceRoot, absBuildDirPath);
buildFileToDepsMap.set(
buildFile,
Expand All @@ -136,9 +146,11 @@ function processProjectReports(projectReportLines: string[]): GradleReport {
'> Task '.length,
line.length - ':taskReport'.length
);
const [_, file] = nextLine.split('file://');
const [_, file] = nextLine.split(fileSeparator);
const taskTypeMap = new Map<string, string>();
const tasksFileLines = readFileSync(file).toString().split('\n');
const tasksFileLines = readFileSync(file)
.toString()
.split(newLineSeparator);

let i = 0;
while (i < tasksFileLines.length) {
Expand Down

0 comments on commit e0519d9

Please sign in to comment.