Skip to content

Commit

Permalink
Make every tool bal version U9
Browse files Browse the repository at this point in the history
  • Loading branch information
gayaldassanayake committed Aug 16, 2024
1 parent 042ff15 commit d0b3fac
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1057,13 +1057,14 @@ private void pushToolPackages(Map<String, String> envVariables) throws IOExcepti
Arrays.asList(SPECIFIC_VERSION, PATCH_VERSION, INCOMPATIBLE_DIST_VERSION, LATEST_VERSION)) {
Path packagePath = tempWorkspaceDirectory.resolve("v" + version).resolve(PACKAGE_NAME);
executePackCommand(DISTRIBUTION_FILE_NAME, packagePath, new LinkedList<>(), envVariables);
if (version.equals(INCOMPATIBLE_DIST_VERSION)) {
Optional<Path> balaPath = getBalaPath(packagePath, version);
if (balaPath.isEmpty()) {
Assert.fail("Bala file " + balaPath + " not found for " + TOOL_ID + ":" + version);
}
updateBallerinaVersionOfBala(balaPath.get());
Optional<Path> balaPath = getBalaPath(packagePath, version);
if (balaPath.isEmpty()) {
Assert.fail("Bala file " + balaPath + " not found for " + TOOL_ID + ":" + version);
}
// This should make the tools incompatible with the current distribution for incompatible version tests,
// and compatible with the current distribution (>=U9) for other versions.
String balVersion = version.equals(INCOMPATIBLE_DIST_VERSION) ? "2201.99.0" : "2201.9.0";
updateBallerinaVersionOfBala(balaPath.get(), balVersion);
Process build = executePushCommand(DISTRIBUTION_FILE_NAME, packagePath, new LinkedList<>(), envVariables);
String buildErrors = getString(build.getErrorStream());
if (!buildErrors.isEmpty()) {
Expand All @@ -1085,11 +1086,11 @@ private Optional<Path> getBalaPath(Path packagePath, String version) {
return Optional.empty();
}

private void updateBallerinaVersionOfBala(Path balaFilePath) throws IOException {
private void updateBallerinaVersionOfBala(Path balaFilePath, String balVersion) throws IOException {
Path tempDir = Files.createTempDirectory(balaFilePath.getFileName().toString());
try {
unzipBalaFile(balaFilePath, tempDir);
updatePackageJsonBallerinaVersion(tempDir);
updatePackageJsonBallerinaVersion(tempDir, balVersion);
zipBalaFile(tempDir, balaFilePath);
} catch (IOException e) {
Assert.fail("Failed to update the ballerina version of the bala file", e);
Expand Down Expand Up @@ -1131,13 +1132,13 @@ private File newFile(File destinationDir, ZipEntry zipEntry) throws IOException
return destFile;
}

private void updatePackageJsonBallerinaVersion(Path packagePath) throws IOException {
private void updatePackageJsonBallerinaVersion(Path packagePath, String balVersion) throws IOException {
Path packageJsonPath = packagePath.resolve("package.json");
String content = Files.readString(packageJsonPath);
JsonObject jsonObject = JsonParser.parseString(content).getAsJsonObject();

// Update the value for the given key
jsonObject.addProperty("ballerina_version", "2201.99.0");
jsonObject.addProperty("ballerina_version", balVersion);
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String formattedJson = gson.toJson(jsonObject);
Files.writeString(packageJsonPath, formattedJson);
Expand Down

0 comments on commit d0b3fac

Please sign in to comment.