Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial gradle build #212

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 29 additions & 26 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,18 @@ jobs:
# Run `git checkout`
- uses: actions/checkout@v3

- name: Retrieve current version from pom
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Make gradlew executable
run: chmod +x ./gradlew

- name: Retrieve current version from gradle.properties
run: |
echo RELEASE_VERSION=$(cat pom.xml | grep -o -P '(?<=revision\>).*(?=\<\/revision)') >> $GITHUB_ENV
echo RELEASE_VERSION=$(./gradlew properties --no-daemon --console=plain -q | grep "^version:" | awk '{print $2}') >> $GITHUB_ENV
Copy link
Member

@ldeichmann ldeichmann Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo RELEASE_VERSION=$(./gradlew properties --no-daemon --console=plain -q | grep "^version:" | awk '{print $2}') >> $GITHUB_ENV
echo RELEASE_VERSION=$(./gradlew properties --no-daemon --console=plain -q | grep "^version:" | awk '{print $2}') | sed "s/-SNAPSHOT//" >> $GITHUB_ENV

I forgot to remove the SNAPSHOT part in my example, otherwise RELEASE_VERSION would be 9.1.0-SNAPSHOT, but we only care about the actual version numbers here.

Has led to having SDCcc-9.1.0-SNAPSHOT-SNAPSHOT-executable-win64.zip as a file name, which is just a bit odd.

echo GIT_HASH_SHORT=$(git rev-parse --short "$GITHUB_SHA") >> $GITHUB_ENV

- name: Remove SNAPSHOT suffix for release
Expand All @@ -32,18 +41,12 @@ jobs:
- name: Add git hash to snapshot release
if: startsWith(github.ref, 'refs/tags/') && !startsWith(github.ref, 'refs/tags/v')
run: |
echo CHANGELIST=${{ env.CHANGELIST }}.${{ env. GIT_HASH_SHORT }} >> $GITHUB_ENV

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
echo CHANGELIST=${{ env.CHANGELIST }}.${{ env.GIT_HASH_SHORT }} >> $GITHUB_ENV

- name: Run headless test
uses: GabrielBB/xvfb-action@v1
with:
run: mvn verify -Dchangelist=${{ env.CHANGELIST }} -f pom.xml
run: ./gradlew check -Prevision=${{ env.RELEASE_VERSION }} -Pchangelist=${{ env.CHANGELIST }}
working-directory: ./ #optional
options: #optional
env:
Expand All @@ -53,25 +56,25 @@ jobs:
id: jre-cache
uses: actions/cache@v3
with:
path: sdccc/target/jre
path: sdccc/build/jre
key: jre-cache

- name: Build package and download license information
run: |
mvn package -Dchangelist=${{ env.CHANGELIST }} -DskipTests=true -f pom.xml -Pexecutable
./gradlew build -x test -Prevision=${{ env.RELEASE_VERSION }} -Pchangelist=${{ env.CHANGELIST }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Collect executable artifacts
run: |
mkdir sdccc/target/zip
cp -r sdccc/target/lib sdccc/target/zip/
cp -r sdccc/target/jre sdccc/target/zip/
cp -r sdccc/target/generated-resources/licenses sdccc/target/zip/lib/
cp -r sdccc/target/generated-resources/licenses.xml sdccc/target/zip/lib/
cp -r configuration sdccc/target/zip/
cp sdccc/target/sdccc-*.exe sdccc/target/zip/
cp README.md sdccc/target/zip/
mkdir sdccc/build/zip
cp -r sdccc/build/lib sdccc/build/zip/
cp -r sdccc/build/jre sdccc/build/zip/
cp -r sdccc/build/reports/dependency-license/downloaded-licenses/ sdccc/build/zip/lib/
cp -r sdccc/build/reports/dependency-license/index.xml sdccc/build/zip/lib/
cp -r configuration sdccc/build/zip/
cp sdccc/build/launch4j/SDCcc-*.exe sdccc/build/zip/
cp README.md sdccc/build/zip/

- name: Set zip file name for release
if: startsWith(github.ref, 'refs/tags/')
Expand All @@ -84,23 +87,23 @@ jobs:

- name: Zip executable
if: startsWith(github.ref, 'refs/tags/')
working-directory: sdccc/target/zip
working-directory: sdccc/build/zip
run: |
zip -qq -r ${{ env.ZIP_FILE_NAME }} .

- name: Zip test results
if: startsWith(github.ref, 'refs/tags/')
working-directory: sdccc/target/
working-directory: sdccc/build/
run: |
zip -qq -r test-results.zip failsafe-reports surefire-reports checkstyle-result.xml spotbugsXml.xml detekt.html
zip -qq -r test-results.zip reports/tests reports/checkstyle reports/spotbugs reports/detekt

- name: Attach artifacts to snapshot
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
CHANGELOG.md
sdccc/target/zip/${{ env.ZIP_FILE_NAME }}
sdccc/target/test-results.zip
sdccc/build/zip/${{ env.ZIP_FILE_NAME }}
sdccc/build/test-results.zip
prerelease: ${{ !startsWith(github.ref, 'refs/tags/v') }}
body_path: CHANGELOG.md
body_path: CHANGELOG.md
30 changes: 21 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ sdccc/testruns
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
Expand All @@ -29,8 +38,19 @@ sdccc/testruns
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries
build/
!src/**/build/
.gradle/

# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Avoid ignore Gradle wrappper properties
!gradle-wrapper.properties

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
Expand Down Expand Up @@ -104,14 +124,6 @@ modules.xml
# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
Expand Down
47 changes: 47 additions & 0 deletions biceps-model/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* This file was generated by the Gradle 'init' task.
*/


plugins {
id("com.draeger.medical.java-conventions")
id("org.somda.sdc.xjc")
}

val jaxb: Configuration by configurations.creating
val schemaDir = "src/main"


dependencies {
api(libs.org.glassfish.jaxb.jaxb.core)
api(libs.org.glassfish.jaxb.jaxb.runtime)
api(libs.jakarta.xml.bind.jakarta.xml.bind.api)
api(libs.io.github.threeten.jaxb.threeten.jaxb.core)
api(libs.org.jvnet.jaxb.jaxb.plugins)
api(libs.org.checkerframework.checker.qual)
api(libs.org.jetbrains.annotations)

testImplementation(libs.org.junit.jupiter.junit.jupiter.api)
testImplementation(libs.org.junit.jupiter.junit.jupiter.engine)

jaxb(libs.org.jetbrains.annotations)
jaxb(libs.org.jvnet.jaxb.jaxb.plugin.annotate)
ldeichmann marked this conversation as resolved.
Show resolved Hide resolved
}

description = "SDCri is a set of Java libraries that implements a network communication framework conforming " +
"with the IEEE 11073 SDC specifications. This project implements the model for IEEE 11073-10207."

xjc {
jaxbClasspath = jaxb
schemaLocation = layout.projectDirectory.dir(schemaDir)
args = listOf(
"-Xannotate",
ldeichmann marked this conversation as resolved.
Show resolved Hide resolved
)
}

description = "BICEPS model"

val testsJar by tasks.registering(Jar::class) {
archiveClassifier.set("tests")
from(sourceSets["test"].output)
}
6 changes: 6 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
val defaultVersion = "9.1.0-SNAPSHOT"
val actualVersion = project.findProperty("revision") ?: defaultVersion
val actualRevision = project.findProperty("changelist") ?: ""

group = "com.draeger.medical"
version = "$actualVersion$actualRevision"
30 changes: 30 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* This file was generated by the Gradle 'init' task.
*/

plugins {
// Support convention plugins written in Kotlin. Convention plugins are build scripts in 'src/main' that automatically become available as plugins in the main build.
`kotlin-dsl`
}

repositories {
// Use the plugin portal to apply community plugins in convention plugins.
gradlePluginPortal()
}

gradlePlugin {
plugins {
create("XjcPlugin") {
id = "org.somda.sdc.xjc"
implementationClass = "org.somda.sdc.XjcPlugin"
}
create("licenseReport") {
id = "com.example.license-report"
implementationClass = "LicenseReportPlugin"
}
}
}

dependencies {
implementation("com.github.jk1:gradle-license-report:2.9")
}
96 changes: 96 additions & 0 deletions buildSrc/src/main/kotlin/LicenseDownloaderRenderer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import com.github.jk1.license.LicenseReportExtension
import com.github.jk1.license.ModuleData
import com.github.jk1.license.ProjectData
import com.github.jk1.license.render.ReportRenderer
import org.gradle.api.Project
import java.io.File
import java.net.URL

class LicenseDownloaderRenderer(
private val outputDirName: String = "downloaded-licenses"
) : ReportRenderer {

companion object {
private const val CONNECT_TIMEOUT = 5000 // 5 seconds
private const val READ_TIMEOUT = 10000 // 10 seconds
}

private lateinit var project: Project
private lateinit var outputDir: File
private val downloadedLicenses = mutableSetOf<String>()

override fun render(data: ProjectData) {
project = data.project
val config = project.extensions.getByType(LicenseReportExtension::class.java)
outputDir = File(config.outputDir, outputDirName)
outputDir.mkdirs()

data.allDependencies.forEach { moduleData ->
val moduleName = "${moduleData.group}-${moduleData.name}-${moduleData.version}"
val licenseDetails = extractPomLicenseDetails(moduleData)

if (licenseDetails.isNotEmpty()) {
licenseDetails.forEach { (licenseUrl, fileName) ->
try {
if (downloadedLicenses.add(licenseUrl)) {
downloadLicense(licenseUrl, moduleName, fileName)
} else {
project.logger.lifecycle("Skipping duplicate license download for $licenseUrl")
}
} catch (e: Exception) {
project.logger.warn("Failed to download license from $licenseUrl for $moduleName: ${e.message}")
}
}
} else {
project.logger.warn("No POM license URLs found for $moduleName")
}
}
}

private fun extractPomLicenseDetails(moduleData: ModuleData): List<Pair<String, String>> {
val licenseDetails = mutableListOf<Pair<String, String>>()

moduleData.poms.forEach { pomData ->
pomData.licenses.forEach { license ->
val url = license.url?.trim()
val fileName = license.name ?: "LICENSE"
if (!url.isNullOrEmpty()) {
licenseDetails.add(url to fileName)
}
}
}

return licenseDetails
}

private fun downloadLicense(licenseUrl: String, moduleName: String, fileName: String) {
val sanitizedUrl = licenseUrl.trim()
val url = URL(sanitizedUrl)

val connection = url.openConnection()
connection.connectTimeout = CONNECT_TIMEOUT
connection.readTimeout = READ_TIMEOUT
connection.connect()

val contentType = connection.contentType ?: "application/octet-stream"

val extension = when {
contentType.contains("text/html", ignoreCase = true) -> ".html"
contentType.contains("text/plain", ignoreCase = true) -> ".txt"
contentType.contains("application/pdf", ignoreCase = true) -> ".pdf"
contentType.contains("text/markdown", ignoreCase = true) -> ".md"
else -> ".txt"
}

val file = File(outputDir, "$fileName$extension")

connection.getInputStream().use { input ->
file.outputStream().use { output ->
input.copyTo(output)
}
}

project.logger.lifecycle("Downloaded license for $moduleName from $licenseUrl to $file")
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* This file was generated by the Gradle 'init' task.
*/

plugins {
`java-library`
`maven-publish`
}

repositories {
mavenLocal()

maven {
url = uri("https://maven.pkg.github.com/Draegerwerk/t2iapi")
}

mavenCentral()

maven {
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
}
}

val javaVersion = property("javaVersion").toString()

java {
sourceCompatibility = JavaVersion.toVersion(javaVersion)
targetCompatibility = JavaVersion.toVersion(javaVersion)
}

tasks.withType<JavaCompile>() {
options.release.set(javaVersion.toInt())
ldeichmann marked this conversation as resolved.
Show resolved Hide resolved
options.encoding = "UTF-8"
}

tasks.withType<Javadoc>() {
options.encoding = "UTF-8"
}
13 changes: 13 additions & 0 deletions buildSrc/src/main/kotlin/license-report.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// buildSrc/src/main/kotlin/license-report.gradle.kts

plugins {
id("com.github.jk1.dependency-license-report")
}

licenseReport {
renderers = arrayOf(
com.github.jk1.license.render.XmlReportRenderer(),
com.github.jk1.license.render.SimpleHtmlReportRenderer(),
LicenseDownloaderRenderer(),
)
}
Loading
Loading