Skip to content

Commit e85b993

Browse files
authored
Merge pull request #246 from payara/copilot/support-custom-gradle-build-directory
Support custom Gradle build directory (`buildDir`)
2 parents d6b3f0a + 0e61ae1 commit e85b993

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

src/main/fish/payara/project/Gradle.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,14 @@ export class Gradle implements Build {
235235
}
236236

237237
public getBuildDir(): string {
238-
let buildDir = path.join(this.workspaceFolder.uri.fsPath, 'build', 'libs');
238+
let buildDirValue = 'build';
239+
if (this.buildReader instanceof GradleBuildReader) {
240+
let customDir = this.buildReader.getBuildDirectory();
241+
if (customDir.length > 0) {
242+
buildDirValue = customDir;
243+
}
244+
}
245+
let buildDir = path.resolve(this.workspaceFolder.uri.fsPath, buildDirValue, 'libs');
239246
if (!fs.existsSync(buildDir)) {
240247
throw Error("no build dir found: " + buildDir);
241248
}

src/main/fish/payara/project/GradleBuildReader.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export class GradleBuildReader implements BuildReader {
2828
private artifactId: string = '';
2929
private version: string = '';
3030
private finalName: string = '';
31+
private buildDirectory: string = '';
3132

3233
public constructor(public workspaceFolder: WorkspaceFolder) {
3334
this.parseBuild();
@@ -45,6 +46,12 @@ export class GradleBuildReader implements BuildReader {
4546
let build: any = await g2js.parseFile(buildPath);
4647
reader.groupId = build.group;
4748
reader.version = build.version;
49+
reader.buildDirectory = reader.parseBuildDirectory(buildPath);
50+
}
51+
52+
let buildKtsPath = path.join(this.workspaceFolder.uri.fsPath, 'build.gradle.kts');
53+
if (reader.buildDirectory.length < 1 && fs.existsSync(buildKtsPath)) {
54+
reader.buildDirectory = reader.parseBuildDirectory(buildKtsPath);
4855
}
4956

5057
if (fs.existsSync(settingsPath)) {
@@ -57,6 +64,23 @@ export class GradleBuildReader implements BuildReader {
5764
}
5865
}
5966

67+
private parseBuildDirectory(gradleFilePath: string): string {
68+
try {
69+
const content = fs.readFileSync(gradleFilePath, 'utf8');
70+
const fileMatch = content.match(/buildDir\s*=\s*file\(\s*["']([^"']+)["']\s*\)/);
71+
if (fileMatch) {
72+
return fileMatch[1];
73+
}
74+
const stringMatch = content.match(/buildDir\s*=\s*["']([^"']+)["']/);
75+
if (stringMatch) {
76+
return stringMatch[1];
77+
}
78+
} catch (e) {
79+
// ignore read errors and fall back to default
80+
}
81+
return '';
82+
}
83+
6084
public getGroupId(): string {
6185
return this.groupId;
6286
}
@@ -73,4 +97,8 @@ export class GradleBuildReader implements BuildReader {
7397
return this.finalName;
7498
}
7599

100+
public getBuildDirectory(): string {
101+
return this.buildDirectory;
102+
}
103+
76104
}

0 commit comments

Comments
 (0)