From 1f90ac642cc8edd18995e6124ab5a5ae210c864f Mon Sep 17 00:00:00 2001 From: Mark DeCrane Date: Thu, 25 Jan 2024 10:26:52 -0500 Subject: [PATCH 1/4] fix: corrected formating for java provider dependencies --- .../@cdktf/cli-core/src/lib/dependencies/package-manager.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/@cdktf/cli-core/src/lib/dependencies/package-manager.ts b/packages/@cdktf/cli-core/src/lib/dependencies/package-manager.ts index da270c1814..fdd288c547 100644 --- a/packages/@cdktf/cli-core/src/lib/dependencies/package-manager.ts +++ b/packages/@cdktf/cli-core/src/lib/dependencies/package-manager.ts @@ -672,7 +672,11 @@ class GradlePackageManager extends JavaPackageManager { buildGradleLines.splice(existingDependency, 1); } - const newPackageDependency = `\timplementation '${packageName}:${packageVersion}'`; + const packageNameElements = packageName.split("."); + const packageNameProvider = packageNameElements.pop(); + const groupName = packageNameElements.join("."); + + const newPackageDependency = `\timplementation '${groupName}:${packageNameProvider}:${packageVersion}'`; buildGradleLines.splice(dependencyBlockStart + 1, 0, newPackageDependency); await fs.writeFile(buildGradlePath, buildGradleLines.join("\n")); From f6bd6fd4aef2ebf5cfe33f59724c3966a27ec0b3 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Fri, 26 Jan 2024 10:25:55 +0100 Subject: [PATCH 2/4] fix: don't double add dependencies --- .../src/lib/dependencies/package-manager.ts | 15 ++++++++------- test/java/provider-list-command/test.ts | 2 ++ test/run-against-dist | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/@cdktf/cli-core/src/lib/dependencies/package-manager.ts b/packages/@cdktf/cli-core/src/lib/dependencies/package-manager.ts index fdd288c547..355c92bc4b 100644 --- a/packages/@cdktf/cli-core/src/lib/dependencies/package-manager.ts +++ b/packages/@cdktf/cli-core/src/lib/dependencies/package-manager.ts @@ -648,7 +648,7 @@ class GradlePackageManager extends JavaPackageManager { } public async addPackage( - packageName: string, + packageFQN: string, packageVersion = "latest.release" ): Promise { const buildGradlePath = path.join(this.workingDirectory, "build.gradle"); @@ -665,18 +665,19 @@ class GradlePackageManager extends JavaPackageManager { ); } + const packageSegments = packageFQN.split("."); + const packageName = packageSegments.pop(); + const groupName = packageSegments.join("."); + const dependencySpecifier = `${groupName}.${packageName}:${packageVersion}`; + const existingDependency = buildGradleLines.findIndex((line) => - line.includes(packageName) + line.includes(dependencySpecifier) ); if (existingDependency !== -1) { buildGradleLines.splice(existingDependency, 1); } - const packageNameElements = packageName.split("."); - const packageNameProvider = packageNameElements.pop(); - const groupName = packageNameElements.join("."); - - const newPackageDependency = `\timplementation '${groupName}:${packageNameProvider}:${packageVersion}'`; + const newPackageDependency = `\timplementation '${dependencySpecifier}'`; buildGradleLines.splice(dependencyBlockStart + 1, 0, newPackageDependency); await fs.writeFile(buildGradlePath, buildGradleLines.join("\n")); diff --git a/test/java/provider-list-command/test.ts b/test/java/provider-list-command/test.ts index 8bd7ffe307..1d1741f214 100644 --- a/test/java/provider-list-command/test.ts +++ b/test/java/provider-list-command/test.ts @@ -34,6 +34,8 @@ describe("provider list command", () => { test("with json output", async () => { const res = await driver.exec("cdktf", ["provider", "list", "--json"]); + console.log(res); + const output = JSON.parse(res.stdout); expect(output).toHaveProperty("local"); diff --git a/test/run-against-dist b/test/run-against-dist index b772beefa7..d9dc97d97f 100755 --- a/test/run-against-dist +++ b/test/run-against-dist @@ -1,5 +1,5 @@ #!/bin/bash -set -euo pipefail +set -euox pipefail scriptdir=$(cd $(dirname $0) && pwd) From c543b90ef916e8d3345f88786db997d6d644c2c4 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Fri, 26 Jan 2024 12:49:35 +0100 Subject: [PATCH 3/4] fix: make sure upgrading removes the correct dependency --- .../cli-core/src/lib/dependencies/package-manager.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/@cdktf/cli-core/src/lib/dependencies/package-manager.ts b/packages/@cdktf/cli-core/src/lib/dependencies/package-manager.ts index 355c92bc4b..3d77fb0e3c 100644 --- a/packages/@cdktf/cli-core/src/lib/dependencies/package-manager.ts +++ b/packages/@cdktf/cli-core/src/lib/dependencies/package-manager.ts @@ -668,7 +668,8 @@ class GradlePackageManager extends JavaPackageManager { const packageSegments = packageFQN.split("."); const packageName = packageSegments.pop(); const groupName = packageSegments.join("."); - const dependencySpecifier = `${groupName}.${packageName}:${packageVersion}`; + const dependencySpecifier = `${groupName}:${packageName}`; + const dependencyAndVersionSpecifier = `${dependencySpecifier}:${packageVersion}`; const existingDependency = buildGradleLines.findIndex((line) => line.includes(dependencySpecifier) @@ -677,7 +678,7 @@ class GradlePackageManager extends JavaPackageManager { buildGradleLines.splice(existingDependency, 1); } - const newPackageDependency = `\timplementation '${dependencySpecifier}'`; + const newPackageDependency = `\timplementation '${dependencyAndVersionSpecifier}'`; buildGradleLines.splice(dependencyBlockStart + 1, 0, newPackageDependency); await fs.writeFile(buildGradlePath, buildGradleLines.join("\n")); @@ -699,7 +700,10 @@ class GradlePackageManager extends JavaPackageManager { } return dep.name.includes("cdktf-provider-"); }) - .map((dep) => ({ name: dep!.name, version: dep!.version })); + .map((dep) => ({ + name: `com.hashicorp.${dep!.name}`, + version: dep!.version, + })); return dependencyList; } From 27c8fa92e0ac8d48007693c08b12c6274f1f62e9 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Fri, 26 Jan 2024 12:50:19 +0100 Subject: [PATCH 4/4] chore: remove debugging helpers --- test/java/provider-list-command/test.ts | 2 -- test/run-against-dist | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/test/java/provider-list-command/test.ts b/test/java/provider-list-command/test.ts index 1d1741f214..8bd7ffe307 100644 --- a/test/java/provider-list-command/test.ts +++ b/test/java/provider-list-command/test.ts @@ -34,8 +34,6 @@ describe("provider list command", () => { test("with json output", async () => { const res = await driver.exec("cdktf", ["provider", "list", "--json"]); - console.log(res); - const output = JSON.parse(res.stdout); expect(output).toHaveProperty("local"); diff --git a/test/run-against-dist b/test/run-against-dist index d9dc97d97f..b772beefa7 100755 --- a/test/run-against-dist +++ b/test/run-against-dist @@ -1,5 +1,5 @@ #!/bin/bash -set -euox pipefail +set -euo pipefail scriptdir=$(cd $(dirname $0) && pwd)