Skip to content

Commit

Permalink
Merge pull request #42857 from ShammiL/2201.8.x
Browse files Browse the repository at this point in the history
[2201.8.x] Change icon path file separator for Windows
  • Loading branch information
ShammiL authored Jun 5, 2024
2 parents 58d5bf5 + 9f1f9d6 commit 98516f9
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public abstract class BalaWriter {
protected static final String PLATFORM = "platform";
protected static final String PATH = "path";
private static final String MAIN_BAL = "main.bal";
private static final String UNIX_FILE_SEPARATOR = "/";

// Set the target as any for default bala.
protected String target = "any";
Expand Down Expand Up @@ -168,14 +169,12 @@ private void addPackageJson(ZipOutputStream balaOutputStream, Optional<JsonArray
packageJson.setLanguageSpecVersion(BALLERINA_SPEC_VERSION);
packageJson.setImplementationVendor(IMPLEMENTATION_VENDOR);

if (!platformLibs.isEmpty()) {
packageJson.setPlatformDependencies(platformLibs.get());
}
platformLibs.ifPresent(packageJson::setPlatformDependencies);

// Set icon in bala path in the package.json
if (packageManifest.icon() != null && !packageManifest.icon().isEmpty()) {
Path iconPath = getIconPath(packageManifest.icon());
packageJson.setIcon(String.valueOf(Paths.get(BALA_DOCS_DIR).resolve(iconPath.getFileName())));
packageJson.setIcon(BALA_DOCS_DIR + UNIX_FILE_SEPARATOR + iconPath.getFileName());
}
// Set graalvmCompatibility property in package.json
setGraalVMCompatibilityProperty(packageJson, packageManifest);
Expand Down Expand Up @@ -310,7 +309,7 @@ private void addPackageSource(ZipOutputStream balaOutputStream) throws IOExcepti
}

// Generate empty bal file for default module in tools
if (module.isDefaultModule() && !packageContext.balToolTomlContext().isEmpty() &&
if (module.isDefaultModule() && packageContext.balToolTomlContext().isPresent() &&
module.documentIds().isEmpty()) {
String emptyBalContent = "// AUTO-GENERATED FILE.\n" +
"\n" +
Expand Down Expand Up @@ -506,12 +505,12 @@ private String convertPathSeperator(Path file) {
return null;
} else {
if (File.separatorChar == '\\') {
String replaced = "";
String replaced;
// Following is to evade spotbug issue if file is null
replaced = Optional.ofNullable(file.getFileName()).orElse(Paths.get("")).toString();
Path parent = file.getParent();
while (parent != null) {
replaced = parent.getFileName() + "/" + replaced;
replaced = parent.getFileName() + UNIX_FILE_SEPARATOR + replaced;
parent = parent.getParent();
}
return replaced;
Expand Down

0 comments on commit 98516f9

Please sign in to comment.