-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: linuxdistro jdk provider (#1826)
* feat: liunxdistro jdk provider adds `linuxdistro` provider which for now searches `/usr/lib/jvm` for jdks. It is not enabled by default as it is not possible to safely determine the version and build of the jdk present or needed to be installed if mising. Meaning to get it user need to select it `--jdk-provider=linuxdistro` or just enable all providers `--jdk-provider=all` on command line or run `jbang config set jdk-provider linuxdistro` to make it default for all jbang invocations. * fix: check before assuning name is jdkprovider * fix: make sure linux distro JDKs are valid * chore: simplified LinuxDistroJdkProvider name and id --------- Co-authored-by: Tako Schotanus <[email protected]>
- Loading branch information
1 parent
f290976
commit 8c0f8ef
Showing
5 changed files
with
82 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/main/java/dev/jbang/net/jdkproviders/LinuxJdkProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package dev.jbang.net.jdkproviders; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* This JDK provider is intended to detects JDKs that have been installed in | ||
* standard location of the users linux distro. | ||
* | ||
* For now just using `/usr/lib/jvm` as apparently fedora, debian, ubuntu and | ||
* centos/rhel use it. | ||
* | ||
* If need different behavior per linux distro its intended this provider will | ||
* adjust based on identified distro. | ||
* | ||
*/ | ||
public class LinuxJdkProvider extends BaseFoldersJdkProvider { | ||
private static final Path JDKS_ROOT = Paths.get("/usr/lib/jvm"); | ||
|
||
@Nonnull | ||
@Override | ||
protected Path getJdksRoot() { | ||
return JDKS_ROOT; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
protected String jdkId(String name) { | ||
return name + "-linux"; | ||
} | ||
|
||
@Override | ||
public boolean canUse() { | ||
return Files.isDirectory(JDKS_ROOT); | ||
} | ||
|
||
@Override | ||
protected boolean acceptFolder(Path jdkFolder) { | ||
return super.acceptFolder(jdkFolder) && !isSameFolderSymLink(jdkFolder); | ||
} | ||
|
||
// Returns true if a path is a symlink to an entry in the same folder | ||
private boolean isSameFolderSymLink(Path jdkFolder) { | ||
Path absFolder = jdkFolder.toAbsolutePath(); | ||
if (Files.isSymbolicLink(absFolder)) { | ||
try { | ||
Path realPath = absFolder.toRealPath(); | ||
return Files.isSameFile(absFolder.getParent(), realPath.getParent()); | ||
} catch (IOException e) { | ||
/* ignore */ } | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters