diff --git a/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/model/DependencyMetadata.java b/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/model/DependencyMetadata.java index 32612f7ce250..57331dac1b7c 100644 --- a/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/model/DependencyMetadata.java +++ b/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/model/DependencyMetadata.java @@ -22,6 +22,7 @@ import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Optional; /** * Defines dependency object fields. The same object will be used to define patches. @@ -56,11 +57,11 @@ public void setVersion(String version) { * @return location of the dependency */ @Nullable - public Path getPath() { + public Optional getPath() { if (PathUtils.getPath(this.path) == null) { - return null; + return Optional.empty(); } - return Paths.get(PathUtils.getPath(this.path)); + return Optional.of(Paths.get(PathUtils.getPath(this.path))); } /** diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/PathBalaRepo.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/PathBalaRepo.java index 71aa4b38f547..519ef93402ae 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/PathBalaRepo.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/PathBalaRepo.java @@ -67,7 +67,7 @@ public Patten calculate(PackageID moduleID) { this.manifest.getDependencies().stream() .filter(dep -> dep.getOrgName().equals(moduleID.orgName.value) && dep.getModuleName().equals(moduleID.name.value) && - null != dep.getMetadata().getPath()) + dep.getMetadata().getPath().isPresent()) .findFirst(); // if dependency is not found in toml @@ -76,18 +76,18 @@ public Patten calculate(PackageID moduleID) { } Dependency dep = tomlDependency.get(); - Path balaPath = dep.getMetadata().getPath(); + Path balaPath = dep.getMetadata().getPath().orElseThrow(); // if bala file does not exists if (Files.notExists(balaPath)) { throw new BLangCompilerException("bala file for dependency [" + dep.getModuleID() + "] does not exists: " + - dep.getMetadata().getPath().toAbsolutePath().normalize()); + dep.getMetadata().getPath().orElseThrow().toAbsolutePath().normalize()); } // if bala file is not a file if (!Files.isRegularFile(balaPath)) { throw new BLangCompilerException("bala file for dependency [" + dep.getModuleID() + "] is not a file: " + - dep.getMetadata().getPath().toAbsolutePath().normalize()); + dep.getMetadata().getPath().orElseThrow().toAbsolutePath().normalize()); } // update version of the dependency from the current(root) project diff --git a/compiler/ballerina-lang/src/test/java/org/ballerinalang/toml/ManifestProcessorTest.java b/compiler/ballerina-lang/src/test/java/org/ballerinalang/toml/ManifestProcessorTest.java index 830636860cb5..1fc861f46319 100644 --- a/compiler/ballerina-lang/src/test/java/org/ballerinalang/toml/ManifestProcessorTest.java +++ b/compiler/ballerina-lang/src/test/java/org/ballerinalang/toml/ManifestProcessorTest.java @@ -147,7 +147,8 @@ public void testSingleDependencies() throws TomlException, IOException { "string-utils = {path = '" + balaPath + "', version = \"1.1.5\"} \n"); Assert.assertEquals(manifest.getDependencies().get(0).getModuleID(), "string-utils"); Assert.assertEquals(manifest.getDependencies().get(0).getMetadata().getVersion(), "1.1.5"); - Assert.assertEquals(manifest.getDependencies().get(0).getMetadata().getPath().toString(), balaPath.toString()); + Assert.assertEquals(manifest.getDependencies().get(0).getMetadata().getPath().orElseThrow().toString(), + balaPath.toString()); Files.delete(balaPath); Files.delete(tmpDir); @@ -168,7 +169,7 @@ public void testDependenciesIrregularPath() throws TomlException, IOException { Manifest manifest = ManifestProcessor.parseTomlContentFromString(this.validProjectBlock + "[dependencies] \n " + "string-utils = {path = '" + balaPath + "', version = \"1.1.5\"} \n"); - Path manifestPath = manifest.getDependencies().get(0).getMetadata().getPath(); + Path manifestPath = manifest.getDependencies().get(0).getMetadata().getPath().orElseThrow(); if (manifestPath.toString().contains("\\")) { manifestPath = Paths.get(manifestPath.toString().replace("\\", "/")); } else { @@ -201,7 +202,8 @@ public void testMultipleDependencies() throws TomlException, IOException { Assert.assertEquals(manifest.getDependencies().get(0).getMetadata().getVersion(), "1.0.5"); Assert.assertEquals(manifest.getDependencies().get(1).getModuleID(), "jquery"); Assert.assertEquals(manifest.getDependencies().get(1).getMetadata().getVersion(), "2.2.3"); - Assert.assertEquals(manifest.getDependencies().get(0).getMetadata().getPath().toString(), balaPath.toString()); + Assert.assertEquals(manifest.getDependencies().get(0).getMetadata().getPath().orElseThrow().toString(), + balaPath.toString()); Files.delete(balaPath); Files.delete(tmpDir); @@ -221,7 +223,7 @@ public void testDependencyWithWindowsAbsolutePath() throws TomlException, IOExce Assert.assertEquals(manifest.getDependencies().get(0).getMetadata().getVersion(), "1.0.5"); Assert.assertEquals(manifest.getDependencies().get(1).getModuleID(), "jquery"); Assert.assertEquals(manifest.getDependencies().get(1).getMetadata().getVersion(), "2.2.3"); - Assert.assertEquals(manifest.getDependencies().get(0).getMetadata().getPath().toString(), + Assert.assertEquals(manifest.getDependencies().get(0).getMetadata().getPath().orElseThrow().toString(), balaPath.toString()); Files.delete(balaPath);