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 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
43 changes: 23 additions & 20 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ jobs:
# Run `git checkout`
- uses: actions/checkout@v3

- name: Retrieve current version from pom
- name: Retrieve current version from gradle.properties
run: |
echo RELEASE_VERSION=$(cat pom.xml | grep -o -P '(?<=revision\>).*(?=\<\/revision)') >> $GITHUB_ENV
echo RELEASE_VERSION=$(grep '^revision=' gradle.properties | cut -d'=' -f2) >> $GITHUB_ENV
Copy link
Member

Choose a reason for hiding this comment

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

You can also retrieve this information from gradle directly, which would allow us to not use the gradle.properties and only use a convention plugin.

Example:

./gradlew properties --no-daemon --console=plain -q | grep "^version:" | awk '{printf $2}'

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

- name: Remove SNAPSHOT suffix for release
Expand All @@ -32,18 +32,21 @@ 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
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'

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

- 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
54 changes: 54 additions & 0 deletions biceps-model/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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 jaxbVersion: String = "4.0.0"
Copy link
Member

Choose a reason for hiding this comment

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

unused

val schemaDir = "src/main"
val xjcOutputDir = "$buildDir/generated/source/xjc/main"
Copy link
Member

Choose a reason for hiding this comment

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

unused


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

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

description = "BICEPS model"

val testsJar by tasks.registering(Jar::class) {
archiveClassifier.set("tests")
from(sourceSets["test"].output)
}

(publishing.publications["maven"] as MavenPublication).artifact(testsJar)
Comment on lines +45 to +50
Copy link
Member

Choose a reason for hiding this comment

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

I've seen this block in all the build.gradle.kts, but I don't understand why any of them are present, what do we do with the test jars specifically?


tasks.withType<JavaCompile> {
options.release.set(17)
}
Comment on lines +52 to +54
Copy link
Member

Choose a reason for hiding this comment

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

Set via convention plugin

12 changes: 12 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
allprojects {
Copy link
Member

Choose a reason for hiding this comment

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

Using allprojects/subprojects is considered bad practice by the gradle community and developers now and should be avoided. Move this to the java-conventions plugin

// Access properties defined in gradle.properties
val revision: String by project
val changelist: String by project

group = "com.draeger.medical"
version = "$revision$changelist"

tasks.withType<JavaCompile> {
options.release.set(17)
}
}
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.0")
Copy link
Member

Choose a reason for hiding this comment

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

2.0 is over three years old, current release is 2.9

}
89 changes: 89 additions & 0 deletions buildSrc/src/main/kotlin/LicenseDownloaderRenderer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
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 {

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 safeModuleName = moduleName.replace("[^a-zA-Z0-9.-]".toRegex(), "_")
Copy link
Member

Choose a reason for hiding this comment

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

This is unused


val connection = url.openConnection()
connection.connect()
Comment on lines +66 to +67
Copy link
Member

Choose a reason for hiding this comment

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

This is using the default configuration of indefinite timeouts, which we very likely do not want.


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,45 @@
/*
* 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")
}

maven {
url = uri("https://repo.maven.apache.org/maven2/")
}
Comment on lines +16 to +18
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
maven {
url = uri("https://repo.maven.apache.org/maven2/")
}
mavenCentral()


maven {
url = uri("https://artifactory.draeger.com:443/artifactory/libs-snapshot")
}
Comment on lines +20 to +22
Copy link
Member

Choose a reason for hiding this comment

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

Do not put internals into public code/repositories


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

group = "com.draeger.medical"
version = "9.1.0-SNAPSHOT"
Comment on lines +29 to +30
Copy link
Member

Choose a reason for hiding this comment

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

This is declaring versions which are different from the ones in the gradle properties, something is wrong somewhere. It also appears that this is the version number that ultimately wins. To set the versions here, you could do something like

val defaultVersion = "9.1.0-SNAPSHOT"
val actualVersion = project.findProperty("revision") ?: defaultVersion
val actualRevision = project.findProperty("changelist") ?: ""

group = "com.draeger.medical"
version = "$actualVersion$actualRevision"

java.sourceCompatibility = JavaVersion.VERSION_17

publishing {
publications.create<MavenPublication>("maven") {
from(components["java"])
}
}
Comment on lines +33 to +37
Copy link
Member

Choose a reason for hiding this comment

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

We're not publishing SDCcc to a maven repository, at least until now. What's the point of this?


tasks.withType<JavaCompile>() {
options.encoding = "UTF-8"
}

tasks.withType<Javadoc>() {
options.encoding = "UTF-8"
}
Loading
Loading