-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Separated JDK management code into its own module
Fixes #1857
- Loading branch information
Showing
43 changed files
with
2,629 additions
and
1,624 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.classpath | ||
.project | ||
.vscode | ||
.settings | ||
target | ||
.idea | ||
*.iml | ||
/build | ||
.gradle | ||
.factorypath | ||
bin | ||
homebrew-tap | ||
RESULTS | ||
*.db | ||
jbang-action | ||
out | ||
node_modules | ||
package-lock.json | ||
*.jfr | ||
itests/hello.java | ||
*.class | ||
CHANGELOG.md |
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,31 @@ | ||
plugins { | ||
id 'java' | ||
} | ||
|
||
group = 'dev.jbang.jvm' | ||
version = '0.1.0' | ||
|
||
sourceCompatibility = '8' | ||
targetCompatibility = '8' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation 'org.apache.commons:commons-compress:1.26.2' | ||
implementation 'org.apache.httpcomponents:httpclient:4.5.14' | ||
implementation 'org.apache.httpcomponents:httpclient-cache:4.5.14' | ||
implementation 'com.google.code.gson:gson:2.11.0' | ||
|
||
implementation "org.slf4j:slf4j-nop:1.7.30" | ||
implementation "org.slf4j:jcl-over-slf4j:1.7.30" | ||
implementation "org.jspecify:jspecify:1.0.0" | ||
|
||
testImplementation platform('org.junit:junit-bom:5.10.1') | ||
testImplementation 'org.junit.jupiter:junit-jupiter' | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
} |
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,122 @@ | ||
package dev.jbang.jvm; | ||
|
||
import java.nio.file.Path; | ||
import java.util.HashSet; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
import dev.jbang.jvm.util.JavaUtils; | ||
import org.jspecify.annotations.NonNull; | ||
import org.jspecify.annotations.Nullable; | ||
|
||
public interface Jdk extends Comparable<Jdk> { | ||
@NonNull JdkProvider getProvider(); | ||
|
||
@NonNull String getId(); | ||
|
||
@NonNull String getVersion(); | ||
|
||
@Nullable Path getHome(); | ||
|
||
int getMajorVersion(); | ||
|
||
@NonNull Jdk install(); | ||
|
||
void uninstall(); | ||
|
||
boolean isInstalled(); | ||
|
||
class Default implements Jdk { | ||
@NonNull private final transient JdkProvider provider; | ||
@NonNull private final String id; | ||
@NonNull private final String version; | ||
@Nullable private final Path home; | ||
@NonNull private final Set<String> tags = new HashSet<>(); | ||
|
||
Default( | ||
@NonNull JdkProvider provider, | ||
@NonNull String id, | ||
@Nullable Path home, | ||
@NonNull String version, | ||
@NonNull String... tags) { | ||
this.provider = provider; | ||
this.id = id; | ||
this.version = version; | ||
this.home = home; | ||
} | ||
|
||
@Override | ||
@NonNull | ||
public JdkProvider getProvider() { | ||
return provider; | ||
} | ||
|
||
/** Returns the id that is used to uniquely identify this JDK across all providers */ | ||
@Override | ||
@NonNull | ||
public String getId() { | ||
return id; | ||
} | ||
|
||
/** Returns the JDK's version */ | ||
@Override | ||
@NonNull | ||
public String getVersion() { | ||
return version; | ||
} | ||
|
||
/** | ||
* The path to where the JDK is installed. Can be <code>null</code> which means the JDK | ||
* isn't currently installed by that provider | ||
*/ | ||
@Override | ||
@Nullable | ||
public Path getHome() { | ||
return home; | ||
} | ||
|
||
@Override | ||
public int getMajorVersion() { | ||
return JavaUtils.parseJavaVersion(getVersion()); | ||
} | ||
|
||
@Override | ||
@NonNull | ||
public Jdk install() { | ||
return provider.install(this); | ||
} | ||
|
||
@Override | ||
public void uninstall() { | ||
provider.uninstall(this); | ||
} | ||
|
||
@Override | ||
public boolean isInstalled() { | ||
return home != null; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Default jdk = (Default) o; | ||
return id.equals(jdk.id) && Objects.equals(home, jdk.home); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(home, id); | ||
} | ||
|
||
@Override | ||
public int compareTo(Jdk o) { | ||
return Integer.compare(getMajorVersion(), o.getMajorVersion()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getMajorVersion() + " (" + version + ", " + id + ", " + home + ")"; | ||
} | ||
} | ||
} |
Oops, something went wrong.