Skip to content
Merged
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
62 changes: 26 additions & 36 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,67 +1,57 @@
name: Build and deploy

on: [push]


jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ '8', '11' ]

name: build java ${{ matrix.java }}
java: [ '8', '17' ]
name: Build on Java ${{ matrix.java }}
runs-on: ubuntu-latest
env:
MAVEN_ARGS: --show-version --no-transfer-progress
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3.6.0
- uses: actions/setup-java@v3
with:
distribution: temurin
java-version: ${{ matrix.java }}
cache: "maven"
- name: Build with Maven
run: mvn -B clean verify --no-transfer-progress --show-version
run: mvn verify


makeversion:
if: github.ref != 'refs/heads/main'
publishing_parameters:
needs: build
name: Publishing parameters
runs-on: ubuntu-latest
name: Create version
outputs:
is_release: ${{ steps.version.outputs.is_release }}
version: ${{ steps.version.outputs.version }}
steps:
- name: Decide on build version
- name: Determine version
id: version
run: |
if [[ $GITHUB_REF == *"tags"* ]]; then
TAG=${GITHUB_REF#refs/tags/}
is_release=true
version=${GITHUB_REF#refs/tags/}
else
TAG=${GITHUB_REF#refs/heads/}-SNAPSHOT
is_release=false
version=${GITHUB_REF#refs/heads/}-SNAPSHOT
fi
echo ::set-output name=version::${TAG//\//-}
deploy_snapshot:
if: startsWith(github.ref, 'refs/heads/')
needs: makeversion
runs-on: ubuntu-latest
echo "is_release=${is_release//\//-}" >> $GITHUB_OUTPUT
echo "version=${version//\//-}" >> $GITHUB_OUTPUT

name: Deploy snapshot
steps:
- uses: actions/checkout@v1
- uses: digipost/action-maven-publish@1.3.2
with:
sonatype_secrets: ${{ secrets.sonatype_secrets }}
release_version: ${{ needs.makeversion.outputs.version }}
perform_release: false

release:
if: startsWith(github.ref, 'refs/tags/')
publish:
needs: publishing_parameters
name: Publish ${{ needs.publishing_parameters.outputs.version }}
runs-on: ubuntu-latest
needs: makeversion
name: Release to Sonatype
steps:
- name: Check out Git repository
uses: actions/checkout@v1
- name: Release to Central Repository
uses: digipost/action-maven-publish@1.3.2
- uses: actions/checkout@v3
- uses: digipost/action-maven-publish@v1
with:
sonatype_secrets: ${{ secrets.sonatype_secrets }}
release_version: ${{ needs.makeversion.outputs.version }}
perform_release: true
release_version: ${{ needs.publishing_parameters.outputs.version }}
perform_release: ${{ needs.publishing_parameters.outputs.is_release }}
2 changes: 1 addition & 1 deletion .mvn/maven.config
Original file line number Diff line number Diff line change
@@ -1 +1 @@
-P build-sources-and-javadoc
-P build-sources-and-javadoc,dependency-analyze,check-license-header,include-NOTICE
7 changes: 5 additions & 2 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ Licensed under Apache 2 - http://www.apache.org/licenses/LICENSE-2.0.html

This software includes third party software subject to the following licenses:

Jakarta Activation API jar under EDL 1.0
Jakarta XML Binding API under Eclipse Distribution License - v 1.0
Digipost JAXB Resolver - com.sun.xml.bind under The Apache Software License, Version 2.0
JavaBeans Activation Framework API jar under CDDL/GPLv2+CE
jaxb-api under CDDL 1.1 or GPL2 w/ CPE
JAXB2 Basics - Runtime under BSD-Style License
Old JAXB Core under CDDL+GPL License
Old JAXB Runtime under Eclipse Distribution License - v 1.0
Posten signering - API JAXB Classes under The Apache Software License, Version 2.0
Posten signering - API Schema under The Apache Software License, Version 2.0
Posten signering - API Specification under The Apache Software License, Version 2.0
Expand Down
7 changes: 5 additions & 2 deletions jaxb/NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ Licensed under Apache 2 - http://www.apache.org/licenses/LICENSE-2.0.html

This software includes third party software subject to the following licenses:

Jakarta Activation API jar under EDL 1.0
Jakarta XML Binding API under Eclipse Distribution License - v 1.0
Digipost JAXB Resolver - com.sun.xml.bind under The Apache Software License, Version 2.0
JavaBeans Activation Framework API jar under CDDL/GPLv2+CE
jaxb-api under CDDL 1.1 or GPL2 w/ CPE
JAXB2 Basics - Runtime under BSD-Style License
Old JAXB Core under CDDL+GPL License
Old JAXB Runtime under Eclipse Distribution License - v 1.0
Posten signering - API JAXB Classes under The Apache Software License, Version 2.0


86 changes: 35 additions & 51 deletions jaxb/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (C) Posten Norge AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
Expand All @@ -14,7 +31,6 @@

<properties>
<xsd.directory>${project.basedir}/target/generated-resources/xsd</xsd.directory>
<project.previousVersion>set_with_-Dproject.previousVersion=X.Y</project.previousVersion>
</properties>

<dependencyManagement>
Expand All @@ -26,20 +42,25 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>no.digipost</groupId>
<artifactId>jaxb-resolver-com.sun.xml.bind-bom</artifactId>
<version>1.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.3</version>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.8</version>
<scope>test</scope>
<groupId>no.digipost</groupId>
<artifactId>jaxb-resolver-com.sun.xml.bind</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
Expand Down Expand Up @@ -111,6 +132,12 @@
<version>2.0.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>no.digipost</groupId>
<artifactId>jul-to-slf4j-junit-extension</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
Comment on lines +135 to +140
Copy link
Member Author

Choose a reason for hiding this comment

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

</dependencies>

<build>
Expand All @@ -125,59 +152,16 @@
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.5.0</version>
<configuration>
<excludePackageNames>no.digipost.signature.api.xml.*</excludePackageNames>
<detectOfflineLinks>false</detectOfflineLinks>
<doclint>all,-missing,-html</doclint>
</configuration>
</plugin>
<plugin>
<groupId>org.jasig.maven</groupId>
<artifactId>maven-notice-plugin</artifactId>
<configuration>
<noticeTemplate>${project.basedir}/../src/notice/NOTICE.template</noticeTemplate>
</configuration>
</plugin>
<plugin>
<groupId>com.github.siom79.japicmp</groupId>
<artifactId>japicmp-maven-plugin</artifactId>
<version>0.17.1</version>
<configuration>
<oldVersion>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.previousVersion}</version>
</dependency>
</oldVersion>
<newVersion>
<file>
<path>${project.build.directory}/${project.build.finalName}.${project.packaging}</path>
</file>
</newVersion>
<parameter>
<onlyModified>true</onlyModified>
<onlyBinaryIncompatible>true</onlyBinaryIncompatible>
<includes>
<include>no.digipost.signature</include>
</includes>
</parameter>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>analyze-only</goal>
</goals>
<configuration>
<failOnWarning>true</failOnWarning>
<ignoreNonCompile>true</ignoreNonCompile>
</configuration>
</execution>
<execution>
<id>unpack-xsd-resources</id>
<phase>initialize</phase>
Expand Down
42 changes: 32 additions & 10 deletions jaxb/src/main/java/no/digipost/signature/jaxb/JaxbMarshaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package no.digipost.signature.jaxb;

import no.digipost.signature.xsd.SignatureApiSchemas;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

Expand All @@ -27,6 +28,7 @@
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.sax.SAXSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
Expand Down Expand Up @@ -191,11 +193,17 @@ public byte[] marshalToBytes(Object object) {
return marshalToResult(object, ByteArrayOutputStream::toByteArray);
}

@FunctionalInterface
private interface ThrowingFunction<T, R> {
R apply(T t) throws Exception;
public Document marshalToDomDocument(Object object) {
DOMResult domResult = new DOMResult();
doWithMarshaller(object, (o, marshaller) -> marshaller.marshal(o, domResult));
return (Document) domResult.getNode();
}

public void marshal(Object object, OutputStream outputStream) {
doWithMarshaller(object, (o, marshaller) -> marshaller.marshal(o, outputStream));
}


private <R> R marshalToResult(Object object, ThrowingFunction<? super ByteArrayOutputStream, ? extends R> outputStreamMapper) {
try (ByteArrayOutputStream xmlOutputStream = new ByteArrayOutputStream(128)) {
marshal(object, xmlOutputStream);
Expand All @@ -207,29 +215,43 @@ private <R> R marshalToResult(Object object, ThrowingFunction<? super ByteArrayO
}
}

@FunctionalInterface
private interface ThrowingFunction<T, R> {
R apply(T t) throws Exception;
}

public void marshal(Object object, OutputStream outputStream) {
@FunctionalInterface
private interface ThrowingBiConsumer<T, S> {
void accept(T t, S s) throws Exception;
}

private <T> void doWithMarshaller(T object, ThrowingBiConsumer<? super T, ? super Marshaller> operation) {
try {
Marshaller marshaller = jaxbContext.createMarshaller();
schema.ifPresent(marshaller::setSchema);
marshaller.marshal(object, outputStream);
operation.accept(object, marshaller);
} catch (Exception e) {
throw SignatureMarshalException.failedMarshal(object, e);
}
}


public <T> T unmarshal(InputStream inputStream, Class<T> type) {
return unmarshal(unmarshaller -> unmarshaller.unmarshal(inputStream), type);
}

public <T> T unmarshal(byte[] bytes, Class<T> type) {
return unmarshal(new ByteArrayInputStream(bytes), type);
}

private <T> T unmarshal(ThrowingFunction<? super Unmarshaller, ?> operation, Class<T> type) {
try {
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
schema.ifPresent(unmarshaller::setSchema);
return type.cast(unmarshaller.unmarshal(inputStream));
return type.cast(operation.apply(unmarshaller));
} catch (Exception e) {
throw SignatureMarshalException.failedUnmarshal(type, e);
}
}

public <T> T unmarshal(byte[] bytes, Class<T> type) {
return unmarshal(new ByteArrayInputStream(bytes), type);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
/**
* Different sets of classes to be bound by a {@link javax.xml.bind.JAXBContext JAXB context} in order to
* create marshallers and unmarshallers. All the sets are immutable.
* <p>
*/
public final class SignatureMarshalling {

Expand Down
17 changes: 17 additions & 0 deletions jaxb/src/test/resources/junit-platform.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Copyright (C) Posten Norge AS
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

junit.jupiter.extensions.autodetection.enabled=true
2 changes: 1 addition & 1 deletion jaxb/src/test/resources/simplelogger.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
# limitations under the License.
#

org.slf4j.simpleLogger.defaultLogLevel=warn
org.slf4j.simpleLogger.defaultLogLevel=warn
Loading