Skip to content

Commit 1d133d2

Browse files
committed
refactor: Separated JDK management code into its own module
Fixes #1857
1 parent f80695f commit 1d133d2

File tree

80 files changed

+4514
-1906
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+4514
-1906
lines changed

build.gradle

Lines changed: 96 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,85 @@ plugins {
1818
id 'maven-publish'
1919
}
2020

21-
javadoc {
22-
options.encoding = 'UTF-8'
23-
//remove this to see all the missing tags/parameters.
24-
options.addStringOption('Xdoclint:none', '-quiet')
25-
}
21+
allprojects {
22+
//apply plugin: "java"
23+
apply plugin: "com.diffplug.spotless"
24+
25+
sourceCompatibility = '8'
26+
targetCompatibility = '8'
27+
28+
spotless {
29+
lineEndings 'UNIX'
30+
format 'misc', {
31+
target '**/*.gradle', '**/*.md', '**/.gitignore'
32+
targetExclude 'CONTRIBUTORS.md', 'src/main/scripts/container/README.md', 'build/**/*', 'out/**/*'
33+
// all-contributor bot adds non-indented code
34+
trimTrailingWhitespace()
35+
indentWithTabs(4) // or spaces. Takes an integer argument if you don't like 4
36+
endWithNewline()
37+
}
38+
java {
39+
importOrder 'java', 'javax', 'org', 'com', 'dev.jbang', ''
40+
removeUnusedImports()
41+
eclipse().configFile new File(rootProject.projectDir, "misc/eclipse_formatting_nowrap.xml")
42+
targetExclude 'build/**/*'
43+
}
44+
format 'xml', {
45+
targetExclude 'build/test-results', fileTree('.idea')
46+
target '**/*.xml', '**/*.nuspec'
47+
}
48+
}
2649

27-
repositories {
28-
mavenCentral()
29-
//maven { url 'https://jitpack.io' }
30-
}
50+
javadoc {
51+
options.encoding = 'UTF-8'
52+
//remove this to see all the missing tags/parameters.
53+
options.addStringOption('Xdoclint:none', '-quiet')
54+
}
55+
56+
repositories {
57+
mavenCentral()
58+
//maven { url 'https://jitpack.io' }
59+
}
3160

32-
java {
33-
withJavadocJar()
34-
withSourcesJar()
61+
java {
62+
withJavadocJar()
63+
withSourcesJar()
64+
}
65+
66+
test {
67+
useJUnitPlatform()
68+
jvmArgs = [
69+
"--add-opens", "java.base/java.lang=ALL-UNNAMED",
70+
"--add-opens", "java.base/java.util=ALL-UNNAMED"
71+
]
72+
//testLogging.showStandardStreams = true
73+
74+
/*testLogging {
75+
events "passed", "skipped", "failed"
76+
exceptionFormat "full"
77+
}*/
78+
//timeout.set(Duration.ofSeconds(60))
79+
80+
jacoco {
81+
enabled = false
82+
}
83+
}
84+
85+
jacoco {
86+
toolVersion = '0.8.7'
87+
}
88+
89+
jacocoTestReport {
90+
afterEvaluate {
91+
executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec")
92+
}
93+
94+
reports {
95+
html.required = true
96+
xml.required = true
97+
csv.required = false
98+
}
99+
}
35100
}
36101

37102
publishing {
@@ -77,6 +142,22 @@ publishing {
77142
url = layout.buildDirectory.dir('staging-deploy')
78143
}
79144
}
145+
146+
// to enable reproducible builds
147+
tasks.withType(AbstractArchiveTask) {
148+
preserveFileTimestamps = false
149+
reproducibleFileOrder = true
150+
}
151+
152+
compileJava {
153+
options.encoding = 'UTF-8'
154+
options.compilerArgs << "-Xlint:unchecked"
155+
}
156+
157+
compileTestJava {
158+
options.encoding = 'UTF-8'
159+
options.compilerArgs << "-Xlint:unchecked"
160+
}
80161
}
81162

82163
sourceSets {
@@ -90,6 +171,8 @@ sourceSets {
90171
sourceSets.main.compileClasspath += sourceSets.java9.output.classesDirs;
91172

92173
dependencies {
174+
implementation project(':jdkmanager')
175+
93176
implementation 'com.offbytwo:docopt:0.6.0.20150202'
94177

95178
implementation 'org.apache.commons:commons-text:1.11.0'
@@ -110,6 +193,7 @@ dependencies {
110193
runtimeOnly "eu.maveniverse.maven.mima.runtime:standalone-static:2.4.20"
111194

112195
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.10.1"
196+
testImplementation project(':jdkmanager')
113197
testImplementation "org.junit.jupiter:junit-jupiter:5.10.1"
114198
testImplementation "com.github.stefanbirkner:system-rules:1.17.2"
115199
testImplementation "org.hamcrest:hamcrest-library:2.2"
@@ -126,12 +210,6 @@ buildConfig {
126210
buildConfigField('String', 'VERSION', provider { "\"${project.version}\"" })
127211
}
128212

129-
// to enable reproducible builds
130-
tasks.withType(AbstractArchiveTask) {
131-
preserveFileTimestamps = false
132-
reproducibleFileOrder = true
133-
}
134-
135213
sonarqube {
136214
properties {
137215
property "sonar.projectKey", "jbangdev_jbang"
@@ -140,28 +218,6 @@ sonarqube {
140218
}
141219
}
142220

143-
spotless {
144-
lineEndings 'UNIX'
145-
format 'misc', {
146-
target '**/*.gradle', '**/*.md', '**/.gitignore'
147-
targetExclude 'CONTRIBUTORS.md', 'src/main/scripts/container/README.md', 'build/**/*', 'out/**/*'
148-
// all-contributor bot adds non-indented code
149-
trimTrailingWhitespace()
150-
indentWithTabs(4) // or spaces. Takes an integer argument if you don't like 4
151-
endWithNewline()
152-
}
153-
java {
154-
importOrder 'java', 'javax', 'org', 'com', 'dev.jbang', ''
155-
removeUnusedImports()
156-
eclipse().configFile "misc/eclipse_formatting_nowrap.xml"
157-
targetExclude 'build/**/*'
158-
}
159-
format 'xml', {
160-
targetExclude 'build/test-results', fileTree('.idea')
161-
target '**/*.xml', '**/*.nuspec'
162-
}
163-
}
164-
165221
task versionTxt() {
166222
doLast {
167223
new File(project.buildDir, "tmp/version.txt").text = project.version
@@ -218,16 +274,6 @@ jar {
218274
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
219275
}
220276

221-
compileJava {
222-
options.encoding = 'UTF-8'
223-
options.compilerArgs << "-Xlint:unchecked"
224-
}
225-
226-
compileTestJava {
227-
options.encoding = 'UTF-8'
228-
options.compilerArgs << "-Xlint:unchecked"
229-
}
230-
231277
compileJava9Java {
232278
sourceCompatibility = 9
233279
targetCompatibility = 9
@@ -251,42 +297,6 @@ shadowJar {
251297
archiveFileName = "${archiveBaseName.get()}.${archiveExtension.get()}"
252298
}
253299

254-
test {
255-
useJUnitPlatform()
256-
jvmArgs = [
257-
"--add-opens", "java.base/java.lang=ALL-UNNAMED",
258-
"--add-opens", "java.base/java.util=ALL-UNNAMED"
259-
]
260-
//testLogging.showStandardStreams = true
261-
262-
/*testLogging {
263-
events "passed", "skipped", "failed"
264-
exceptionFormat "full"
265-
}*/
266-
//timeout.set(Duration.ofSeconds(60))
267-
268-
jacoco {
269-
enabled = false
270-
}
271-
}
272-
273-
jacoco {
274-
toolVersion = '0.8.7'
275-
}
276-
277-
jacocoTestReport {
278-
afterEvaluate {
279-
executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec")
280-
}
281-
282-
reports {
283-
html.required = true
284-
xml.required = true
285-
csv.required = false
286-
}
287-
}
288-
289-
290300
task karateExecute(type: JavaExec) {
291301
classpath = sourceSets.test.runtimeClasspath
292302
mainClass = System.properties.getProperty('mainClass')
@@ -435,5 +445,3 @@ tasks.named("spotlessXml").configure { dependsOn("chocolatey") }
435445
tasks.named("spotlessXml").configure { dependsOn("copyITests") }
436446

437447
group = "dev.jbang"
438-
sourceCompatibility = '8'
439-
targetCompatibility = '8'

itests/javaversion.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ Feature: java version control
22

33
Scenario: java run non existent //java
44
When command('jbang --verbose java4321.java')
5-
Then match err contains "JDK version is not available for installation: 4321"
5+
Then match err contains "No suitable JDK was found for requested version: 4321"
66

77

88
Scenario: java run with explicit java 8
99
When command('jbang --verbose --java 8 java4321.java')
10-
Then match err !contains "JDK version is not available for installation: 4321"
10+
Then match err !contains "No suitable JDK was found for requested version: 4321"

jdkmanager/.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.classpath
2+
.project
3+
.vscode
4+
.settings
5+
target
6+
.idea
7+
*.iml
8+
/build
9+
.gradle
10+
.factorypath
11+
bin
12+
homebrew-tap
13+
RESULTS
14+
*.db
15+
jbang-action
16+
out
17+
node_modules
18+
package-lock.json
19+
*.jfr
20+
itests/hello.java
21+
*.class
22+
CHANGELOG.md

jdkmanager/build.gradle

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
plugins {
2+
id 'java'
3+
}
4+
5+
group = 'dev.jbang.jvm'
6+
version = parent.version
7+
8+
sourceCompatibility = '8'
9+
targetCompatibility = '8'
10+
11+
dependencies {
12+
implementation 'org.apache.commons:commons-compress:1.26.2'
13+
implementation 'org.apache.httpcomponents:httpclient:4.5.14'
14+
implementation 'org.apache.httpcomponents:httpclient-cache:4.5.14'
15+
implementation 'com.google.code.gson:gson:2.11.0'
16+
17+
implementation 'org.slf4j:slf4j-nop:1.7.30'
18+
implementation 'org.slf4j:jcl-over-slf4j:1.7.30'
19+
implementation 'org.jspecify:jspecify:1.0.0'
20+
21+
testImplementation platform('org.junit:junit-bom:5.10.1')
22+
testImplementation 'org.junit.jupiter:junit-jupiter'
23+
testImplementation "org.hamcrest:hamcrest-library:2.2"
24+
testImplementation "com.github.stefanbirkner:system-rules:1.17.2"
25+
}
26+
27+
test {
28+
useJUnitPlatform()
29+
jvmArgs = [
30+
"--add-opens", "java.base/java.lang=ALL-UNNAMED",
31+
"--add-opens", "java.base/java.util=ALL-UNNAMED"
32+
]
33+
}
34+
35+
36+
publishing {
37+
publications {
38+
jdkmanager(MavenPublication) {
39+
groupId = 'dev.jbang'
40+
artifactId = 'jdkmanager'
41+
42+
from components.java
43+
44+
pom {
45+
name = 'JBang JDK Manager'
46+
description = 'Library for managing JDK installations'
47+
url = 'https://jbang.dev'
48+
inceptionYear = '2025'
49+
licenses {
50+
license {
51+
name = 'MIT'
52+
url = 'https://github.com/jbangdev/jbang/blob/main/LICENSE'
53+
}
54+
}
55+
developers {
56+
developer {
57+
id = 'maxandersen'
58+
name = 'Max Rydahl Andersen'
59+
}
60+
developer {
61+
id = 'quintesse'
62+
name = 'Tako Schotanus'
63+
}
64+
}
65+
scm {
66+
connection = 'scm:git:https://github.com/jbangdev/jbang'
67+
developerConnection = 'scm:git:https://github.com/jbangdev/jbang'
68+
url = 'http://github.com/jbangdev/jbang'
69+
}
70+
}
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)