Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gradle): fix gradle to work on windows #22470

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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