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

Add Gradle Plugin #5

Merged
merged 59 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
fb757f7
Increase version number
Nirostar Dec 1, 2022
c614910
Completely restructure project in preparation for the typed dicom gra…
Nirostar Feb 27, 2023
383ec4d
Extract method for java source code generation and use gradle logger
Nirostar Feb 27, 2023
df02488
Combine metamodel into one class
Nirostar Feb 28, 2023
167feee
Introduce metamodel DTOs and Create YAML exporter
Nirostar Feb 28, 2023
048da7a
Restructure to split DICOM standard parsing and Java source generatio…
Nirostar Feb 28, 2023
839e404
Make generated Java code compile clean via the yaml route
Nirostar Mar 2, 2023
b05c23e
Fix the gradle structure to get the task execution dependencies right
Nirostar Mar 3, 2023
870f342
Extract class skeleton to be reusable with the plugin
Nirostar Mar 3, 2023
fd73db4
Add skeleton as dependency via the generator plugin instead of bundli…
Nirostar Mar 6, 2023
c255336
Add javadoc to generated java classes
Nirostar Mar 6, 2023
f45fa3e
Exclude dicom xmls from gradle plugin jar
Nirostar Mar 6, 2023
ef2fe91
Fix github pipeline
Nirostar Mar 7, 2023
3e16833
Fix InformationObjectDefinitionMustacheModel constructor to because t…
Nirostar Apr 5, 2023
a0c6c92
Upgrade gradle version
Nirostar Apr 5, 2023
7636feb
Split into composite gradle build to make a java generator plugin whi…
Nirostar Apr 13, 2023
1954010
Convert everything to Java 11
Nirostar Apr 13, 2023
a6f5fd2
Reconfigure dependencies to be added while applying the plugin
Nirostar Apr 13, 2023
8d033d6
Create default privateDicomMetamodelYamlDirectory
Nirostar Apr 14, 2023
acf2b11
Add clean task
Nirostar Apr 14, 2023
24ddfdf
Make compatible with gradle 5.6.4
Nirostar Apr 14, 2023
cf37a47
Suppress unchecked warnings on SELF casts for the builders
Nirostar Apr 14, 2023
d66519b
Make source sets type safe
Nirostar Apr 14, 2023
3c1a3e5
Fix skeleton dependency version
Nirostar Apr 14, 2023
cabc228
Fix java doc warnings and use lower case at the beginning of @return …
Nirostar Apr 14, 2023
d1e724c
Extract publishing configuration into separate plugin
Nirostar Apr 14, 2023
f9440ee
Migrate other subprojects to publishing plugin and extract parser dto…
Nirostar Apr 14, 2023
5c7ca06
Downgrade jackson to allow usage in ei-monorepo
Nirostar Apr 14, 2023
e98799a
Add private creator tag to the meta model
Nirostar Apr 14, 2023
73902b0
Make Java code generation more resilient against null values
Nirostar Apr 14, 2023
f68e2fa
Add machinet.conf to .gitignore
Nirostar Apr 14, 2023
4cba30d
Revert "Downgrade jackson to allow usage in ei-monorepo"
Nirostar Apr 14, 2023
cf534dd
Change generator plugin to be released as a fat jar and the fasterxml…
Nirostar Apr 17, 2023
4e962b8
Only apply signing plugin if the properties are set
Nirostar Apr 17, 2023
9c826e0
Remove generation of dicom tag constants to be also backwards compati…
Nirostar Apr 18, 2023
2a081f3
Revert "Remove generation of dicom tag constants to be also backwards…
Nirostar Apr 18, 2023
8137fcd
Make the javadocs more dicom version specific to avoid confusion with…
Nirostar Apr 18, 2023
a3e0bbf
Update dicom standard xml to 2022d and dcm4che to 5.29.0
Nirostar Apr 18, 2023
9c86a53
Use https for all the links
Nirostar Apr 18, 2023
f7ab325
Make JDoc prettier
Nirostar Apr 18, 2023
4e9dc5d
Fix github workflows
Nirostar Apr 18, 2023
9520141
Fix repository links
Nirostar Apr 18, 2023
3c707f3
Un-shadow gradle plugin
Nirostar Apr 18, 2023
878d7c4
Create build task for composite build
Nirostar Apr 19, 2023
aed3b64
Let gradle tasks run in parallel
Nirostar Apr 19, 2023
b86806f
Add adaptations yaml file for dcm standard lib to avoid empty resourc…
Nirostar Apr 19, 2023
50e1e8d
Add jdoc for type parameter to satisfy doclint
Nirostar Apr 19, 2023
a6d19e1
Increase github action versions in gradleBuild.yml
Nirostar Apr 19, 2023
c5d5b73
Add github release artifacts for the new released components
Nirostar Apr 19, 2023
fdce6d8
Change uploading of release assets to script
Nirostar Apr 19, 2023
f2adc5e
Remove custom jar names for standard library
Nirostar Apr 19, 2023
906d370
Remove fs declaration because it seems to be already defined in the c…
Nirostar Apr 19, 2023
aa9c123
Update conventions for gradle generator plugin
Nirostar Apr 19, 2023
57404f5
Update README for plugin and new version
Nirostar Apr 19, 2023
0ace00d
Remove await from upload call because it isn't async
Nirostar Apr 19, 2023
49502ef
Automatically add the sources and javadoc jars when applying the publ…
Nirostar Apr 19, 2023
0cd2a89
Enable merging of collections in the metamodel dtos
Nirostar Apr 19, 2023
32d9cd4
Fix publish.yml
Nirostar Apr 19, 2023
b1b48ea
Set to release version number
Nirostar Apr 20, 2023
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
31 changes: 23 additions & 8 deletions .github/workflows/gradleBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,33 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Java
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'
java-version: '11'
distribution: 'temurin'
- name: Build with Gradle
uses: gradle/gradle-build-action@4137be6a8bf7d7133955359dbd952c0ca73b1021
uses: gradle/gradle-build-action@v2
with:
arguments: build
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v3
with:
name: Artifacts
path: dcm4che-typeddicom-lib/build/libs
name: Standard Library
path: dcm4che-typeddicom-lib/dcm4che-typeddicom-lib-std/build/libs
retention-days: 7
- uses: actions/upload-artifact@v3
with:
name: Generator Gradle Plugin
path: dcm4che-typeddicom-generator/dcm4che-typeddicom-java-generator-gradleplugin/build/libs
retention-days: 7
- uses: actions/upload-artifact@v3
with:
name: Library Skeleton
path: dcm4che-typeddicom-skeleton/build/libs
retention-days: 7
- uses: actions/upload-artifact@v3
with:
name: Parser DTOs
path: dcm4che-typeddicom-parser/dcm4che-typeddicom-parser-dtos/build/libs
retention-days: 7
79 changes: 45 additions & 34 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,55 +12,66 @@ jobs:
environment: publishToDcm4cheMaven
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Get release
id: get_release
uses: bruceadams/get-release@v1.2.3
uses: bruceadams/get-release@v1.3.2
env:
GITHUB_TOKEN: ${{ github.token }}

- name: Set up Java
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'
java-version: '11'
distribution: 'temurin'

- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b
uses: gradle/wrapper-validation-action@v1

- name: Build package
run: gradle build

- name: Publish bin jar to GitHub
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ steps.get_release.outputs.upload_url }}
asset_path: ./dcm4che-typeddicom-lib/build/libs/dcm4che-typeddicom-lib.jar
asset_name: dcm4che-typeddicom-lib-${{ steps.get_release.outputs.tag_name }}.jar
asset_content_type: application/jar

- name: Publish javadoc jar to GitHub
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ steps.get_release.outputs.upload_url }}
asset_path: ./dcm4che-typeddicom-lib/build/libs/dcm4che-typeddicom-lib-javadoc.jar
asset_name: dcm4che-typeddicom-lib-javadoc-${{ steps.get_release.outputs.tag_name }}.jar
asset_content_type: application/jar

- name: Publish sources jar to GitHub
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Upload release assets
uses: actions/github-script@v6
with:
upload_url: ${{ steps.get_release.outputs.upload_url }}
asset_path: ./dcm4che-typeddicom-lib/build/libs/dcm4che-typeddicom-lib-sources.jar
asset_name: dcm4che-typeddicom-lib-sources-${{ steps.get_release.outputs.tag_name }}.jar
asset_content_type: application/jar
script: |
console.log('environment', process.versions);

const fs = require('fs');

const { repo: { owner, repo }, sha } = context;
console.log({ owner, repo, sha });

const publishableSubProjects = [
'dcm4che-typeddicom-skeleton',
'dcm4che-typeddicom-lib/dcm4che-typeddicom-lib-std',
'dcm4che-typeddicom-parser/dcm4che-typeddicom-parser-dtos',
'dcm4che-typeddicom-generator/dcm4che-typeddicom-java-generator-lib',
'dcm4che-typeddicom-generator/dcm4che-typeddicom-java-generator-gradleplugin'
];
for (let project of publishableSubProjects) {
fs.readdir(`./${project}/build/libs`, (err, files) => {
if (err) {
console.log(err);
} else {
files.forEach(file => {
const releaseAssetName = file.replace(/(.*?)(-\d+\.\d+\.\d+(-SNAPSHOT)?)?(-(javadoc|sources))?.jar/, "$1-${{ steps.get_release.outputs.tag_name }}$4.jar");
const filePath = `./${project}/build/libs/${file}`

console.log('uploading ' + filePath + ' > ' + releaseAssetName);

github.rest.repos.uploadReleaseAsset({
owner,
repo,
release_id: "${{ steps.get_release.outputs.id }}",
name: releaseAssetName,
data: fs.readFileSync(filePath)
});
});
}
});
}

- name: Publish package to dcm4che Maven Repository
run: gradle publishAllPublicationsToDcm4cheMavenRepository
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ build

# IntelliJ
.idea/
machinet.conf

# Eclipse
.classpath
Expand Down
68 changes: 53 additions & 15 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ This library creates typed wrappers around dcm4che attributes to make DICOM obje
We tried our best to mimic a lot of the DICOM standard in this library but due to the complexity and openness of the standard we cannot possibly cover everything.
If you encounter unsupported fields you can always use the `getAttributes()` method and use dcm4che means to get whatever you want from the data.

## Dependencies
This library is based on the
* [DICOM Standard Version 2022d](https://dicom.nema.org/medical/dicom/2022d/output/chtml/part01/ps3.1.html).
* [dcm4che version 5.29.0](https://github.com/dcm4che/dcm4che/releases/tag/5.29.0)

## How to add it to your project
### Gradle
#### Groovy
### Standard Library
#### Gradle
##### Groovy
```groovy
repositories {
// Add dicom4che repository
Expand All @@ -19,11 +25,11 @@ repositories {

```groovy
dependencies {
implementation 'org.dcm4che:dcm4che-typeddicom:0.4.3'
implementation 'org.dcm4che:dcm4che-typeddicom-lib-std:0.5.0'
}
```

#### Kotlin
##### Kotlin
```kotlin
repositories {
// Add dicom4che repository
Expand All @@ -35,11 +41,11 @@ repositories {

```kotlin
dependencies {
implementation("org.dcm4che:dcm4che-typeddicom:0.4.3")
implementation("org.dcm4che:dcm4che-typeddicom-lib-std:0.5.0")
}
```

### Maven
#### Maven

```xml
<!-- Add dicom4che repository -->
Expand All @@ -54,18 +60,51 @@ dependencies {
<dependency>
<groupId>org.dcm4che</groupId>
<artifactId>dcm4che-typeddicom</artifactId>
<version>0.4.3</version>
<version>0.5.0</version>
</dependency>
```
### Use private tags with the gradle plugin

## How to build it yourself
Run ```.\gradlew jar```. The JAR-file is then located under ```typeddicom-lib/build/libs/typeddicom-lib.jar```.
In the ```build.gradle``` put:
```groovy
plugins {
id 'java-library'
id 'org.dcm4che.typeddicom-java-generator' version '0.5.0'
}

generateTypeddicomJavaSources {
privateDicomMetamodelYamlDirectory = layout.projectDirectory.dir("src/main/resources") // default - so this is optional when using this directory
generatedJavaOutputDirectory = layout.buildDirectory.dir("typeddicom") // default - so this is optional when using this directory
}
```
or put this into ```build.gradle.kts```:
```kotlin
plugins {
id("java-library")
id("org.dcm4che.typeddicom-java-generator") version "0.5.0"
}
generateTypeddicomJavaSources {
privateDicomMetamodelYamlDirectory.set(layout.projectDirectory.dir("src/main/resources")) // default - so this is optional when using this directory
generatedJavaOutputDirectory.set(layout.buildDirectory.dir("typeddicom")) // default - so this is optional when using this directory
}
```
Put your custom yaml file into the specified ```src/main/resources``` folder and populate it with your custom tags. Examples for this are plenty in ```dcm4che-typeddicom-java-generator-gradleplugin-<version>.jar/std.dicom-meta-model.yaml```.

* ```gradle generateJavaSourceFiles``` will generate the source files in the specified ```build/typeddicom``` folder.
* You can do anything as with the usual `java-library` projects (see https://docs.gradle.org/current/userguide/java_library_plugin.html). The ```generateJavaSourceFiles``` task is properly integrated with them and will run when needed.

You can also run ```.\gradlew publishToMavenLocal``` to install it to your local Maven repository.
## How to build it yourself
Run ```.\gradlew build```. The JAR-files are then located under:
* ```dcm4che-typeddicom-skeleton\build\libs``` for the skeleton java library containing interfaces and abstract classes which are implemented and extended by the generated classes.
* ```dcm4che-typeddicom-lib/dcm4che-typeddicom-lib-std\build\libs``` contains an easily usable library for all standard dicom IODs, Modules and Attributes.
* ```dcm4che-typeddicom-parser/dcm4che-typeddicom-parser-dtos\build\libs``` contains the DTOs which are needed to parse the metadata representation of the dicom standard.
* ```dcm4che-typeddicom-generator/dcm4che-typeddicom-java-generator-lib\build\libs``` contains a library to generate a typeddicom implementation with custom adaptations using additional yaml files.
* ```dcm4che-typeddicom-generator/dcm4che-typeddicom-java-generator-gradleplugin\build\libs``` contains the plugin which generates a typeddicom java implementation from a provided private tags file.
You can also run ```.\gradlew publishToMavenLocal``` to install all packages to your local Maven repository.
## How to use
### Reading fields
Instead of
```
```java
Attributes attributes = readDicomFile("GSPS.dcm");

int[] untypedPixelAspectRatio = attributes.getSequence(Tag.DisplayedAreaSelectionSequence)
Expand All @@ -74,7 +113,7 @@ int[] untypedPixelAspectRatio = attributes.getSequence(Tag.DisplayedAreaSelectio

```
you can now use
```
```java
Attributes attributes = readDicomFile("GSPS.dcm");

GrayscaleSoftcopyPresentationStateIOD gsps = new GrayscaleSoftcopyPresentationStateIOD(attributes);
Expand All @@ -88,7 +127,7 @@ Where everything is checked for type-safety.
### Synthesizing Dicom Attributes
A fluent API was implemented to make DICOM attributes synthesizing easily read and writable.
Instead of
```
```java
Attributes gspsClassic = new Attributes();
gspsClassic.setString(Tag.PatientName, VR.PN, "Niklas");
Sequence referencedSeriesSequence = gspsClassic.newSequence(Tag.ReferencedSeriesSequence, 1);
Expand All @@ -114,7 +153,7 @@ displayedAreaSelectionSequenceItem.setInt(Tag.PresentationPixelAspectRatio, VR.I
displayedAreaSelectionSequence.add(displayedAreaSelectionSequenceItem);
```
you can now use
```
```java
GrayscaleSoftcopyPresentationStateIOD gsps = GrayscaleSoftcopyPresentationStateIOD.builder()
.setPatientName().asString("Niklas")
.setReferencedSeriesSequence(
Expand All @@ -140,4 +179,3 @@ GrayscaleSoftcopyPresentationStateIOD gsps = GrayscaleSoftcopyPresentationStateI
```
### JavaDocs
Check out the javadocs. They should represent the stuff written in the DICOM Standard.

1 change: 0 additions & 1 deletion build.gradle

This file was deleted.

32 changes: 32 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
val releasableProjects = arrayOf(
"dcm4che-typeddicom-parser",
"dcm4che-typeddicom-generator",
"dcm4che-typeddicom-lib",
"dcm4che-typeddicom-skeleton"
)

tasks.register("publishAllPublicationsToDcm4cheMavenRepository") {
dependsOn(gradle.includedBuilds
.filter { it.name in releasableProjects }
.map { it.task(":publishAllPublicationsToDcm4cheMavenRepository") }
)
}

tasks.register("publishToMavenLocal") {
dependsOn(gradle.includedBuilds
.filter { it.name in releasableProjects }
.map { it.task(":publishToMavenLocal") }
)
}

tasks.register("clean") {
dependsOn(gradle.includedBuilds
.map { it.task(":clean") }
)
}

tasks.register("build") {
dependsOn(gradle.includedBuilds
.map { it.task(":build") }
)
}
49 changes: 0 additions & 49 deletions buildSrc/build.gradle.kts

This file was deleted.

Loading