Skip to content

Commit

Permalink
Merge pull request #5 from dcm4che/dev
Browse files Browse the repository at this point in the history
Add Gradle Plugin
  • Loading branch information
Nirostar committed Apr 20, 2023
2 parents 6ad92c6 + b1b48ea commit 0583cf3
Show file tree
Hide file tree
Showing 125 changed files with 30,697 additions and 38,156 deletions.
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

0 comments on commit 0583cf3

Please sign in to comment.