Skip to content

Commit

Permalink
feat(#5): take care about binary extension
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Nov 22, 2023
1 parent e12ae61 commit 072d3c5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
21 changes: 17 additions & 4 deletions src/main/java/com/yegor256/Jhome.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public Jhome() {

/**
* Find the file inside {@code JAVA_HOME}.
* @param loc Location, e.g. {@code "bin/java"}
* @param loc Location, e.g. {@code "bin/java"} relative to {@code JAVA_HOME}.
* @return The path of it
*/
public Path path(final String... loc) {
Expand All @@ -72,7 +72,7 @@ public Path path(final String... loc) {
* @return The path of it
*/
public Path java() {
return this.path("bin/java");
return this.path("bin/java").resolve(Jhome.extension());
}

/**
Expand All @@ -84,7 +84,21 @@ public Path java() {
* {@code Optional<Path>} is also a solution here.
*/
public Path javac() {
return this.path("bin/javac");
return this.path("bin/javac").resolve(Jhome.extension());
}

/**
* Find the extension of the executable file.
* - On Windows it is ".exe".
* - On Unix it is empty string.
* @return The extension.
*/
private static String extension() {
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
return ".exe";
} else {
return "";
}
}

/**
Expand All @@ -107,5 +121,4 @@ private static Path base() {
}
return base;
}

}
5 changes: 2 additions & 3 deletions src/test/java/com/yegor256/JhomeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@
*/
package com.yegor256;

import java.nio.file.Path;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hamcrest.io.FileMatchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledForJreRange;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.EnabledForJreRange;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.condition.OS;

/**
Expand Down

0 comments on commit 072d3c5

Please sign in to comment.