Skip to content

Commit

Permalink
refactor: Separated JDK management code into its own module
Browse files Browse the repository at this point in the history
Fixes #1857
  • Loading branch information
quintesse committed Jan 30, 2025
1 parent f80695f commit 4083f67
Show file tree
Hide file tree
Showing 80 changed files with 4,447 additions and 1,895 deletions.
184 changes: 96 additions & 88 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,85 @@ plugins {
id 'maven-publish'
}

javadoc {
options.encoding = 'UTF-8'
//remove this to see all the missing tags/parameters.
options.addStringOption('Xdoclint:none', '-quiet')
}
allprojects {
//apply plugin: "java"
apply plugin: "com.diffplug.spotless"

sourceCompatibility = '8'
targetCompatibility = '8'

spotless {
lineEndings 'UNIX'
format 'misc', {
target '**/*.gradle', '**/*.md', '**/.gitignore'
targetExclude 'CONTRIBUTORS.md', 'src/main/scripts/container/README.md', 'build/**/*', 'out/**/*'
// all-contributor bot adds non-indented code
trimTrailingWhitespace()
indentWithTabs(4) // or spaces. Takes an integer argument if you don't like 4
endWithNewline()
}
java {
importOrder 'java', 'javax', 'org', 'com', 'dev.jbang', ''
removeUnusedImports()
eclipse().configFile new File(rootProject.projectDir, "misc/eclipse_formatting_nowrap.xml")
targetExclude 'build/**/*'
}
format 'xml', {
targetExclude 'build/test-results', fileTree('.idea')
target '**/*.xml', '**/*.nuspec'
}
}

repositories {
mavenCentral()
//maven { url 'https://jitpack.io' }
}
javadoc {
options.encoding = 'UTF-8'
//remove this to see all the missing tags/parameters.
options.addStringOption('Xdoclint:none', '-quiet')
}

repositories {
mavenCentral()
//maven { url 'https://jitpack.io' }
}

java {
withJavadocJar()
withSourcesJar()
java {
withJavadocJar()
withSourcesJar()
}

test {
useJUnitPlatform()
jvmArgs = [
"--add-opens", "java.base/java.lang=ALL-UNNAMED",
"--add-opens", "java.base/java.util=ALL-UNNAMED"
]
//testLogging.showStandardStreams = true

/*testLogging {
events "passed", "skipped", "failed"
exceptionFormat "full"
}*/
//timeout.set(Duration.ofSeconds(60))

jacoco {
enabled = false
}
}

jacoco {
toolVersion = '0.8.7'
}

jacocoTestReport {
afterEvaluate {
executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec")
}

reports {
html.required = true
xml.required = true
csv.required = false
}
}
}

publishing {
Expand Down Expand Up @@ -77,6 +142,22 @@ publishing {
url = layout.buildDirectory.dir('staging-deploy')
}
}

// to enable reproducible builds
tasks.withType(AbstractArchiveTask) {
preserveFileTimestamps = false
reproducibleFileOrder = true
}

compileJava {
options.encoding = 'UTF-8'
options.compilerArgs << "-Xlint:unchecked"
}

compileTestJava {
options.encoding = 'UTF-8'
options.compilerArgs << "-Xlint:unchecked"
}
}

sourceSets {
Expand All @@ -90,6 +171,8 @@ sourceSets {
sourceSets.main.compileClasspath += sourceSets.java9.output.classesDirs;

dependencies {
implementation project(':jdkmanager')

implementation 'com.offbytwo:docopt:0.6.0.20150202'

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

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

// to enable reproducible builds
tasks.withType(AbstractArchiveTask) {
preserveFileTimestamps = false
reproducibleFileOrder = true
}

sonarqube {
properties {
property "sonar.projectKey", "jbangdev_jbang"
Expand All @@ -140,28 +218,6 @@ sonarqube {
}
}

spotless {
lineEndings 'UNIX'
format 'misc', {
target '**/*.gradle', '**/*.md', '**/.gitignore'
targetExclude 'CONTRIBUTORS.md', 'src/main/scripts/container/README.md', 'build/**/*', 'out/**/*'
// all-contributor bot adds non-indented code
trimTrailingWhitespace()
indentWithTabs(4) // or spaces. Takes an integer argument if you don't like 4
endWithNewline()
}
java {
importOrder 'java', 'javax', 'org', 'com', 'dev.jbang', ''
removeUnusedImports()
eclipse().configFile "misc/eclipse_formatting_nowrap.xml"
targetExclude 'build/**/*'
}
format 'xml', {
targetExclude 'build/test-results', fileTree('.idea')
target '**/*.xml', '**/*.nuspec'
}
}

task versionTxt() {
doLast {
new File(project.buildDir, "tmp/version.txt").text = project.version
Expand Down Expand Up @@ -218,16 +274,6 @@ jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

compileJava {
options.encoding = 'UTF-8'
options.compilerArgs << "-Xlint:unchecked"
}

compileTestJava {
options.encoding = 'UTF-8'
options.compilerArgs << "-Xlint:unchecked"
}

compileJava9Java {
sourceCompatibility = 9
targetCompatibility = 9
Expand All @@ -251,42 +297,6 @@ shadowJar {
archiveFileName = "${archiveBaseName.get()}.${archiveExtension.get()}"
}

test {
useJUnitPlatform()
jvmArgs = [
"--add-opens", "java.base/java.lang=ALL-UNNAMED",
"--add-opens", "java.base/java.util=ALL-UNNAMED"
]
//testLogging.showStandardStreams = true

/*testLogging {
events "passed", "skipped", "failed"
exceptionFormat "full"
}*/
//timeout.set(Duration.ofSeconds(60))

jacoco {
enabled = false
}
}

jacoco {
toolVersion = '0.8.7'
}

jacocoTestReport {
afterEvaluate {
executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec")
}

reports {
html.required = true
xml.required = true
csv.required = false
}
}


task karateExecute(type: JavaExec) {
classpath = sourceSets.test.runtimeClasspath
mainClass = System.properties.getProperty('mainClass')
Expand Down Expand Up @@ -435,5 +445,3 @@ tasks.named("spotlessXml").configure { dependsOn("chocolatey") }
tasks.named("spotlessXml").configure { dependsOn("copyITests") }

group = "dev.jbang"
sourceCompatibility = '8'
targetCompatibility = '8'
4 changes: 2 additions & 2 deletions itests/javaversion.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ Feature: java version control

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


Scenario: java run with explicit java 8
When command('jbang --verbose --java 8 java4321.java')
Then match err !contains "JDK version is not available for installation: 4321"
Then match err !contains "No suitable JDK was found for requested version: 4321"
22 changes: 22 additions & 0 deletions jdkmanager/.gitignore
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
73 changes: 73 additions & 0 deletions jdkmanager/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
plugins {
id 'java'
}

group = 'dev.jbang.jvm'
version = parent.version

sourceCompatibility = '8'
targetCompatibility = '8'

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'
testImplementation "org.hamcrest:hamcrest-library:2.2"
testImplementation "com.github.stefanbirkner:system-rules:1.17.2"
}

test {
useJUnitPlatform()
jvmArgs = [
"--add-opens", "java.base/java.lang=ALL-UNNAMED",
"--add-opens", "java.base/java.util=ALL-UNNAMED"
]
}


publishing {
publications {
jdkmanager(MavenPublication) {
groupId = 'dev.jbang'
artifactId = 'jdkmanager'

from components.java

pom {
name = 'JBang JDK Manager'
description = 'Library for managing JDK installations'
url = 'https://jbang.dev'
inceptionYear = '2025'
licenses {
license {
name = 'MIT'
url = 'https://github.com/jbangdev/jbang/blob/main/LICENSE'
}
}
developers {
developer {
id = 'maxandersen'
name = 'Max Rydahl Andersen'
}
developer {
id = 'quintesse'
name = 'Tako Schotanus'
}
}
scm {
connection = 'scm:git:https://github.com/jbangdev/jbang'
developerConnection = 'scm:git:https://github.com/jbangdev/jbang'
url = 'http://github.com/jbangdev/jbang'
}
}
}
}
}
Loading

0 comments on commit 4083f67

Please sign in to comment.