-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): detect gradle plugin for any settings.gradle
- Loading branch information
Showing
17 changed files
with
876 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
import { | ||
checkFilesExist, | ||
cleanupProject, | ||
getSelectedPackageManager, | ||
newProject, | ||
runCLI, | ||
updateJson, | ||
updateFile, | ||
e2eCwd, | ||
readJson, | ||
} from '@nx/e2e/utils'; | ||
import { mkdirSync, rmdirSync, writeFileSync } from 'fs'; | ||
import { execSync } from 'node:child_process'; | ||
import { join } from 'path'; | ||
import { createGradleProject } from './utils/create-gradle-project'; | ||
import { createFileSync } from 'fs-extra'; | ||
|
||
describe('Nx Import Gradle', () => { | ||
let proj: string; | ||
const tempImportE2ERoot = join(e2eCwd, 'nx-import'); | ||
beforeAll(() => { | ||
proj = newProject({ | ||
packages: ['@nx/js'], | ||
unsetProjectNameAndRootFormat: false, | ||
}); | ||
|
||
if (getSelectedPackageManager() === 'pnpm') { | ||
updateFile( | ||
'pnpm-workspace.yaml', | ||
`packages: | ||
- 'projects/*' | ||
` | ||
); | ||
} else { | ||
updateJson('package.json', (json) => { | ||
json.workspaces = ['projects/*']; | ||
return json; | ||
}); | ||
} | ||
|
||
try { | ||
rmdirSync(tempImportE2ERoot); | ||
} catch {} | ||
mkdirSync(tempImportE2ERoot, { recursive: true }); | ||
}); | ||
afterAll(() => cleanupProject()); | ||
|
||
it('should be able to import a kotlin gradle app', () => { | ||
const tempGradleProjectName = 'created-gradle-app-kotlin'; | ||
const tempGraldeProjectPath = join( | ||
tempImportE2ERoot, | ||
tempGradleProjectName | ||
); | ||
try { | ||
rmdirSync(tempGraldeProjectPath); | ||
} catch {} | ||
mkdirSync(tempGraldeProjectPath, { recursive: true }); | ||
createGradleProject( | ||
tempGradleProjectName, | ||
'kotlin', | ||
tempGraldeProjectPath, | ||
'gradleProjectKotlin', | ||
'kotlin-' | ||
); | ||
// Add project.json files to the gradle project to avoid duplicate project names | ||
createFileSync(join(tempGraldeProjectPath, 'project.json')); | ||
writeFileSync( | ||
join(tempGraldeProjectPath, 'project.json'), | ||
`{"name": "${tempGradleProjectName}"}` | ||
); | ||
|
||
execSync(`git init`, { | ||
cwd: tempGraldeProjectPath, | ||
}); | ||
execSync(`git add .`, { | ||
cwd: tempGraldeProjectPath, | ||
}); | ||
execSync(`git commit -am "initial commit"`, { | ||
cwd: tempGraldeProjectPath, | ||
}); | ||
execSync(`git checkout -b main`, { | ||
cwd: tempGraldeProjectPath, | ||
}); | ||
|
||
const remote = tempGraldeProjectPath; | ||
const ref = 'main'; | ||
const source = '.'; | ||
const directory = 'projects/gradle-app-kotlin'; | ||
|
||
runCLI( | ||
`import ${remote} ${directory} --ref ${ref} --source ${source} --no-interactive`, | ||
{ | ||
verbose: true, | ||
} | ||
); | ||
|
||
checkFilesExist( | ||
`${directory}/settings.gradle.kts`, | ||
`${directory}/build.gradle.kts`, | ||
`${directory}/gradlew`, | ||
`${directory}/gradlew.bat` | ||
); | ||
const nxJson = readJson('nx.json'); | ||
const gradlePlugin = nxJson.plugins.find( | ||
(plugin) => plugin.plugin === '@nx/gradle' | ||
); | ||
expect(gradlePlugin).toBeDefined(); | ||
expect(() => { | ||
runCLI(`show projects`); | ||
runCLI('build kotlin-app'); | ||
}).not.toThrow(); | ||
}); | ||
|
||
it('should be able to import a groovy gradle app', () => { | ||
const tempGradleProjectName = 'created-gradle-app-groovy'; | ||
const tempGraldeProjectPath = join( | ||
tempImportE2ERoot, | ||
tempGradleProjectName | ||
); | ||
try { | ||
rmdirSync(tempGraldeProjectPath); | ||
} catch {} | ||
mkdirSync(tempGraldeProjectPath, { recursive: true }); | ||
createGradleProject( | ||
tempGradleProjectName, | ||
'groovy', | ||
tempGraldeProjectPath, | ||
'gradleProjectGroovy', | ||
'groovy-' | ||
); | ||
// Add project.json files to the gradle project to avoid duplicate project names | ||
createFileSync(join(tempGraldeProjectPath, 'project.json')); | ||
writeFileSync( | ||
join(tempGraldeProjectPath, 'project.json'), | ||
`{"name": "${tempGradleProjectName}"}` | ||
); | ||
|
||
execSync(`git init`, { | ||
cwd: tempGraldeProjectPath, | ||
}); | ||
execSync(`git add .`, { | ||
cwd: tempGraldeProjectPath, | ||
}); | ||
execSync(`git commit -am "initial commit"`, { | ||
cwd: tempGraldeProjectPath, | ||
}); | ||
execSync(`git checkout -b main`, { | ||
cwd: tempGraldeProjectPath, | ||
}); | ||
|
||
const remote = tempGraldeProjectPath; | ||
const ref = 'main'; | ||
const source = '.'; | ||
const directory = 'projects/gradle-app-groovy'; | ||
|
||
runCLI( | ||
`import ${remote} ${directory} --ref ${ref} --source ${source} --no-interactive`, | ||
{ | ||
verbose: true, | ||
} | ||
); | ||
runCLI(`g @nx/gradle:init --no-interactive`); | ||
|
||
checkFilesExist( | ||
`${directory}/build.gradle`, | ||
`${directory}/settings.gradle`, | ||
`${directory}/gradlew`, | ||
`${directory}/gradlew.bat` | ||
); | ||
expect(() => { | ||
runCLI(`show projects`); | ||
runCLI('build groovy-app'); | ||
}).not.toThrow(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { | ||
e2eConsoleLogger, | ||
isWindows, | ||
runCommand, | ||
tmpProjPath, | ||
} from '@nx/e2e/utils'; | ||
import { execSync } from 'child_process'; | ||
import { createFileSync, writeFileSync } from 'fs-extra'; | ||
import { join, resolve } from 'path'; | ||
|
||
export function createGradleProject( | ||
projectName: string, | ||
type: 'kotlin' | 'groovy' = 'kotlin', | ||
cwd: string = tmpProjPath(), | ||
packageName: string = 'gradleProject', | ||
addProjectJsonNamePrefix: string = '' | ||
) { | ||
e2eConsoleLogger(`Using java version: ${execSync('java -version')}`); | ||
const gradleCommand = isWindows() | ||
? resolve(`${__dirname}/../../gradlew.bat`) | ||
: resolve(`${__dirname}/../../gradlew`); | ||
e2eConsoleLogger( | ||
'Using gradle version: ' + | ||
execSync(`${gradleCommand} --version`, { | ||
cwd, | ||
}) | ||
); | ||
e2eConsoleLogger( | ||
execSync(`${gradleCommand} help --task :init`, { | ||
cwd, | ||
}).toString() | ||
); | ||
e2eConsoleLogger( | ||
runCommand( | ||
`${gradleCommand} init --type ${type}-application --dsl ${type} --project-name ${projectName} --package ${packageName} --no-incubating --split-project`, | ||
{ | ||
cwd, | ||
} | ||
) | ||
); | ||
|
||
if (addProjectJsonNamePrefix) { | ||
createFileSync(join(cwd, 'app/project.json')); | ||
writeFileSync( | ||
join(cwd, 'app/project.json'), | ||
`{"name": "${addProjectJsonNamePrefix}app"}` | ||
); | ||
createFileSync(join(cwd, 'list/project.json')); | ||
writeFileSync( | ||
join(cwd, 'list/project.json'), | ||
`{"name": "${addProjectJsonNamePrefix}list"}` | ||
); | ||
createFileSync(join(cwd, 'utilities/project.json')); | ||
writeFileSync( | ||
join(cwd, 'utilities/project.json'), | ||
`{"name": "${addProjectJsonNamePrefix}utilities"}` | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.