-
Notifications
You must be signed in to change notification settings - Fork 12
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
base: main
Are you sure you want to change the base?
Initial gradle build #212
Changes from all commits
29d5e2e
b7e632b
ac934f1
bb5685d
c0e3114
e7cad0e
a97d900
28c14a9
32fe0f1
58a5a17
74b1800
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unused |
||
val schemaDir = "src/main" | ||
val xjcOutputDir = "$buildDir/generated/source/xjc/main" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Set via convention plugin |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
allprojects { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
} | ||
} |
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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2.0 is over three years old, current release is 2.9 |
||
} |
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(), "_") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
maven { | ||||||||||
url = uri("https://artifactory.draeger.com:443/artifactory/libs-snapshot") | ||||||||||
} | ||||||||||
Comment on lines
+20
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||||||||||
} |
There was a problem hiding this comment.
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: