Skip to content

Commit

Permalink
Fix some spotbugs errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Shadow-Devil committed Sep 20, 2024
1 parent 870689e commit fb77d66
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -56,11 +57,11 @@ public void setVersion(String version) {
* @return location of the dependency
*/
@Nullable
public Path getPath() {
public Optional<Path> 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)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit fb77d66

Please sign in to comment.