fix(gradle): get gradlew path with projectRoot joins workspaceRoot (#22988)
This commit is contained in:
parent
8cd326e71a
commit
cec57c4951
152
packages/gradle/src/plugin/nodes.spec.ts
Normal file
152
packages/gradle/src/plugin/nodes.spec.ts
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
import { CreateNodesContext } from '@nx/devkit';
|
||||||
|
|
||||||
|
import { TempFs } from 'nx/src/internal-testing-utils/temp-fs';
|
||||||
|
import type { GradleReport } from '../utils/get-gradle-report';
|
||||||
|
|
||||||
|
let gradleReport: GradleReport;
|
||||||
|
jest.mock('../utils/get-gradle-report.ts', () => {
|
||||||
|
return {
|
||||||
|
getGradleReport: jest.fn().mockImplementation(() => gradleReport),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
import { createNodes } from './nodes';
|
||||||
|
|
||||||
|
describe('@nx/gradle/plugin', () => {
|
||||||
|
let createNodesFunction = createNodes[1];
|
||||||
|
let context: CreateNodesContext;
|
||||||
|
let tempFs: TempFs;
|
||||||
|
let cwd: string;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
tempFs = new TempFs('test');
|
||||||
|
gradleReport = {
|
||||||
|
gradleFileToGradleProjectMap: new Map<string, string>([
|
||||||
|
['proj/gradle.build', 'proj'],
|
||||||
|
]),
|
||||||
|
buildFileToDepsMap: new Map<string, string>(),
|
||||||
|
gradleFileToOutputDirsMap: new Map<string, Map<string, string>>([
|
||||||
|
['proj/gradle.build', new Map([['build', 'build']])],
|
||||||
|
]),
|
||||||
|
gradleProjectToTasksTypeMap: new Map<string, Map<string, string>>([
|
||||||
|
['proj', new Map([['test', 'Test']])],
|
||||||
|
]),
|
||||||
|
gradleProjectToProjectName: new Map<string, string>([['proj', 'proj']]),
|
||||||
|
};
|
||||||
|
cwd = process.cwd();
|
||||||
|
process.chdir(tempFs.tempDir);
|
||||||
|
context = {
|
||||||
|
nxJsonConfiguration: {
|
||||||
|
namedInputs: {
|
||||||
|
default: ['{projectRoot}/**/*'],
|
||||||
|
production: ['!{projectRoot}/**/*.spec.ts'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
workspaceRoot: tempFs.tempDir,
|
||||||
|
configFiles: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
await tempFs.createFiles({
|
||||||
|
'proj/gradle.build': ``,
|
||||||
|
gradlew: '',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.resetModules();
|
||||||
|
process.chdir(cwd);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create nodes based on gradle', async () => {
|
||||||
|
const nodes = await createNodesFunction(
|
||||||
|
'proj/gradle.build',
|
||||||
|
{
|
||||||
|
buildTargetName: 'build',
|
||||||
|
},
|
||||||
|
context
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(nodes.projects.proj).toMatchInlineSnapshot(`
|
||||||
|
{
|
||||||
|
"metadata": {
|
||||||
|
"technologies": [
|
||||||
|
"gradle",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
"name": "proj",
|
||||||
|
"targets": {
|
||||||
|
"test": {
|
||||||
|
"cache": false,
|
||||||
|
"command": "../gradlew test",
|
||||||
|
"dependsOn": [
|
||||||
|
"classes",
|
||||||
|
],
|
||||||
|
"inputs": [
|
||||||
|
"default",
|
||||||
|
"^production",
|
||||||
|
],
|
||||||
|
"options": {
|
||||||
|
"cwd": "proj",
|
||||||
|
},
|
||||||
|
"outputs": undefined,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create nodes based on gradle for nested project root', async () => {
|
||||||
|
gradleReport = {
|
||||||
|
gradleFileToGradleProjectMap: new Map<string, string>([
|
||||||
|
['nested/nested/proj/gradle.build', 'proj'],
|
||||||
|
]),
|
||||||
|
buildFileToDepsMap: new Map<string, string>(),
|
||||||
|
gradleFileToOutputDirsMap: new Map<string, Map<string, string>>([
|
||||||
|
['nested/nested/proj/gradle.build', new Map([['build', 'build']])],
|
||||||
|
]),
|
||||||
|
gradleProjectToTasksTypeMap: new Map<string, Map<string, string>>([
|
||||||
|
['proj', new Map([['test', 'Test']])],
|
||||||
|
]),
|
||||||
|
gradleProjectToProjectName: new Map<string, string>([['proj', 'proj']]),
|
||||||
|
};
|
||||||
|
await tempFs.createFiles({
|
||||||
|
'nested/nested/proj/gradle.build': ``,
|
||||||
|
});
|
||||||
|
|
||||||
|
const nodes = await createNodesFunction(
|
||||||
|
'nested/nested/proj/gradle.build',
|
||||||
|
{
|
||||||
|
buildTargetName: 'build',
|
||||||
|
},
|
||||||
|
context
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(nodes.projects['nested/nested/proj']).toMatchInlineSnapshot(`
|
||||||
|
{
|
||||||
|
"metadata": {
|
||||||
|
"technologies": [
|
||||||
|
"gradle",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
"name": "proj",
|
||||||
|
"targets": {
|
||||||
|
"test": {
|
||||||
|
"cache": false,
|
||||||
|
"command": "../../../gradlew test",
|
||||||
|
"dependsOn": [
|
||||||
|
"classes",
|
||||||
|
],
|
||||||
|
"inputs": [
|
||||||
|
"default",
|
||||||
|
"^production",
|
||||||
|
],
|
||||||
|
"options": {
|
||||||
|
"cwd": "nested/nested/proj",
|
||||||
|
},
|
||||||
|
"outputs": undefined,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -4,6 +4,7 @@ import {
|
|||||||
ProjectConfiguration,
|
ProjectConfiguration,
|
||||||
TargetConfiguration,
|
TargetConfiguration,
|
||||||
readJsonFile,
|
readJsonFile,
|
||||||
|
workspaceRoot,
|
||||||
writeJsonFile,
|
writeJsonFile,
|
||||||
} from '@nx/devkit';
|
} from '@nx/devkit';
|
||||||
import { calculateHashForCreateNodes } from '@nx/devkit/src/utils/calculate-hash-for-create-nodes';
|
import { calculateHashForCreateNodes } from '@nx/devkit/src/utils/calculate-hash-for-create-nodes';
|
||||||
@ -180,7 +181,10 @@ function createGradleTargets(
|
|||||||
const targetName = options?.[`${task.name}TargetName`] ?? task.name;
|
const targetName = options?.[`${task.name}TargetName`] ?? task.name;
|
||||||
|
|
||||||
const outputs = outputDirs.get(task.name);
|
const outputs = outputDirs.get(task.name);
|
||||||
const path = relative(projectRoot, getGradleBinaryPath());
|
const path = relative(
|
||||||
|
join(context.workspaceRoot, projectRoot),
|
||||||
|
getGradleBinaryPath()
|
||||||
|
);
|
||||||
targets[targetName] = {
|
targets[targetName] = {
|
||||||
command: `${path} ${task.name}`,
|
command: `${path} ${task.name}`,
|
||||||
options: {
|
options: {
|
||||||
|
|||||||
@ -11,7 +11,7 @@ export const fileSeparator = process.platform.startsWith('win')
|
|||||||
|
|
||||||
const newLineSeparator = process.platform.startsWith('win') ? '\r\n' : '\n';
|
const newLineSeparator = process.platform.startsWith('win') ? '\r\n' : '\n';
|
||||||
|
|
||||||
interface GradleReport {
|
export interface GradleReport {
|
||||||
gradleFileToGradleProjectMap: Map<string, string>;
|
gradleFileToGradleProjectMap: Map<string, string>;
|
||||||
buildFileToDepsMap: Map<string, string>;
|
buildFileToDepsMap: Map<string, string>;
|
||||||
gradleFileToOutputDirsMap: Map<string, Map<string, string>>;
|
gradleFileToOutputDirsMap: Map<string, Map<string, string>>;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user