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

Merged
merged 46 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
29d5e2e
Initial gradle build
midttuna Oct 8, 2024
b7e632b
gradle permission denied fix
midttuna Oct 8, 2024
ac934f1
fix java version complaint
midttuna Oct 8, 2024
bb5685d
fix java version complaint
midttuna Oct 8, 2024
c0e3114
typos, whitespace, number of parallel tests
midttuna Oct 8, 2024
e7cad0e
add target directory for downloaded licenses
midttuna Oct 8, 2024
a97d900
blind infinite typos
midttuna Oct 8, 2024
28c14a9
case sensitive
midttuna Oct 8, 2024
32fe0f1
new line eof
midttuna Oct 11, 2024
58a5a17
Merge branch 'Draegerwerk:main' into sdccc-gradle
midttuna Oct 14, 2024
74b1800
whitespace and test
midttuna Nov 28, 2024
8e2a069
review changes
midttuna Dec 2, 2024
21fb49e
versioning
midttuna Dec 2, 2024
7b650f3
remove unnecessary
midttuna Dec 2, 2024
63c4e1e
permission error revert
midttuna Dec 2, 2024
fd1b39b
bracket
midttuna Dec 2, 2024
1c2cda0
Merge branch 'Draegerwerk:main' into sdccc-gradle
midttuna Dec 2, 2024
8e1caa7
move versions from java-conventions.
midttuna Dec 3, 2024
4b8639e
make writeable
midttuna Dec 3, 2024
e05b749
composite build instead of buildsrc and fix review remarks
midttuna Jan 6, 2025
4d965d8
remove hardcoded versions
midttuna Jan 6, 2025
3bd828d
typos, remove test jar and move versions to catalog
midttuna Jan 8, 2025
1435dea
Make things skipable or optional
midttuna Jan 30, 2025
41a9f1a
reintroduce deleted license download
midttuna Jan 30, 2025
c3a600c
reintroduce deleted tests
midttuna Jan 30, 2025
b1e7b0e
merge main
midttuna Jan 30, 2025
6750c51
test jar
midttuna Jan 30, 2025
2a449af
dynamic executable name
midttuna Jan 31, 2025
a1ff713
executable version
midttuna Jan 31, 2025
ea76982
log4j annotation for custom appender (TriggerOnErrorOrWorseLogAppender)
midttuna Feb 3, 2025
a361be9
mainclass and executable version
midttuna Feb 4, 2025
c9a5b87
unnecessary property
midttuna Feb 4, 2025
51cf8a8
namings
midttuna Feb 5, 2025
7c18f67
jre path for executable fix
midttuna Feb 11, 2025
5f29ce3
move version to separate conventions file
midttuna Feb 11, 2025
e1ff84a
download jre to build/
midttuna Feb 11, 2025
871078f
classpath detekt
midttuna Feb 11, 2025
9cb775d
Merge branch 'main' of https://github.com/midttuna/SDCcc into sdccc-g…
midttuna Feb 11, 2025
5fa2938
tests
midttuna Feb 12, 2025
033a1af
detekt lazy classpath
midttuna Feb 12, 2025
5768fe9
revision changelist check
midttuna Feb 12, 2025
33dc911
typo
midttuna Feb 12, 2025
7b2a13b
tests
midttuna Feb 12, 2025
b1b9258
remove poms and changelog
midttuna Feb 12, 2025
6d88db8
Readme update
midttuna Feb 12, 2025
1b2c4fd
Readme update correct gradle version
midttuna Feb 12, 2025
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
53 changes: 28 additions & 25 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}') | sed "s/-SNAPSHOT//" >> $GITHUB_ENV
echo GIT_HASH_SHORT=$(git rev-parse --short "$GITHUB_SHA") >> $GITHUB_ENV

- name: Remove SNAPSHOT suffix for release
Expand All @@ -34,16 +43,10 @@ jobs:
run: |
echo CHANGELIST=${{ env.CHANGELIST }}#$GITHUB_RUN_NUMBER-${{ env.GIT_HASH_SHORT }} >> $GITHUB_ENV

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

- 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 }} -PexecutableSDCcc
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
41 changes: 41 additions & 0 deletions biceps-model/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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)
}

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)
}

description = "BICEPS model"

val testsJar by tasks.registering(Jar::class) {
archiveClassifier.set("tests")
from(sourceSets["test"].output)
}
36 changes: 36 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
implementation(libs.com.github.jk1.license.report)
implementation(libs.gradleplugins.spotbugs)
implementation(libs.gradleplugins.spotless)
implementation(libs.gradleplugins.kotlin.jvm)
implementation(libs.gradleplugins.download)
implementation(libs.gradleplugins.launch4j)
}
11 changes: 11 additions & 0 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
rootProject.name = "build-logic"

// make libs.versions.toml available
// see https://stackoverflow.com/a/70878181
dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
8 changes: 8 additions & 0 deletions build-logic/src/main/kotlin/Common.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import org.gradle.api.Project
import org.gradle.api.provider.Provider
import org.gradle.kotlin.dsl.the


// workaround for making libs available in build-logic
val Project.libs
get() = the<org.gradle.accessors.dm.LibrariesForLibs>()
96 changes: 96 additions & 0 deletions build-logic/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")
}

}
Loading