Skip to content

Commit

Permalink
Replace autovalue with java records, add service tests (#254)
Browse files Browse the repository at this point in the history
* Add build workflow.

* Update readme.

* Replace autovalue with java records, make notarization tool a cdi bean, general cleanup, add service tests.

* Add dependency update workflow for maven.

---------

Signed-off-by: Thomas Neidhart <[email protected]>
  • Loading branch information
netomi authored Oct 25, 2023
1 parent 25564dd commit 79bc673
Show file tree
Hide file tree
Showing 29 changed files with 713 additions and 611 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build
on:
pull_request:
push:
branches:
- main

env:
JAVA_VERSION: '17'
JAVA_DISTRO: 'temurin'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.JAVA_DISTRO }}
cache: maven
- run: ./mvnw -ntp clean verify
19 changes: 19 additions & 0 deletions .github/workflows/dependency-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Dependency Update

on:
push:
branches:
- 'main'
workflow_dispatch:

permissions:
contents: write

jobs:
dependency:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- name: Submit Dependency Snapshot
uses: advanced-security/maven-dependency-submission-action@fcd7eab6b6d22946badc98d1e62665cdee93e0ae # v3.0.3
14 changes: 4 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This is a web service that runs on macOS and offers a REST API to notarize signe

### Requirements

* Java 17+. We advise you use the [Temurin](https://adoptium.net/) binaries via [homebrew](https://brew.sh)
* Java 17+. We advise to use the [Temurin](https://adoptium.net/) binaries via [homebrew](https://brew.sh)

```bash
brew install temurin17
Expand All @@ -20,21 +20,15 @@ This is a web service that runs on macOS and offers a REST API to notarize signe

./mvnw clean package

It produces 2 jar files in `/target`:
It produces the self-contained application in `/target/quarkus-app`.

* `macos-notarization-service-1.0-SNAPSHOT.jar` - containing just the classes and resources of the projects, it’s the regular artifact produced by the Maven build;

* `macos-notarization-service-1.0-SNAPSHOT-runner.jar` - being an executable jar. Be aware that it’s not an über-jar as the dependencies are copied into the target/lib directory.

You can run the application using: `java -jar target/macos-notarization-service-1.0-SNAPSHOT-runner.jar`

The Class-Path entry of the `MANIFEST.MF` from the runner jar explicitly lists the jars from the lib directory. So if you want to deploy your application somewhere, you need to copy the runner jar as well as the lib directory.
You can run the application using: `java -jar target/quarkus-app/quarkus-run.jar`

See below for advanced startup method.

### Run

Configure `NOTARIZATION_APPLEID_USERNAME` and `NOTARIZATION_APPLEID_PASSWORD` with the proper values for your Apple developer ID account in file `start.sh`. Then, just run
Configure `NOTARIZATION_APPLEID_USERNAME`, `NOTARIZATION_APPLEID_PASSWORD` and `NOTARIZATION_APPLEID_TEAMID` with the proper values for your Apple developer ID account in file `start.sh`. Then, just run

./start.sh

Expand Down
50 changes: 17 additions & 33 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
<quarkus.native.additional-build-args>--initialize-at-run-time=com.google.common.cache</quarkus.native.additional-build-args>
<quarkus.native.compression.level>5</quarkus.native.compression.level>

<io.soabase.record-builder.version>37</io.soabase.record-builder.version>
<surefire-plugin.version>3.1.2</surefire-plugin.version>
<compiler-plugin.version>3.11.0</compiler-plugin.version>

<com.google.auto.value.auto-value.version>1.10.4</com.google.auto.value.auto-value.version>
<com.ryanharter.auto.value.auto-value-moshi.version>1.1.0</com.ryanharter.auto.value.auto-value-moshi.version>
</properties>

<repositories>
Expand Down Expand Up @@ -55,21 +53,6 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.squareup.moshi</groupId>
<artifactId>moshi</artifactId>
<version>1.15.0</version>
</dependency>
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value-annotations</artifactId>
<version>${com.google.auto.value.auto-value.version}</version>
</dependency>
<dependency>
<groupId>com.ryanharter.auto.value</groupId>
<artifactId>auto-value-moshi-runtime</artifactId>
<version>${com.ryanharter.auto.value.auto-value-moshi.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down Expand Up @@ -107,24 +90,17 @@
<artifactId>quarkus-rest-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-multipart</artifactId>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-multipart</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jsonb</artifactId>
</dependency>
<dependency>
<groupId>com.squareup.moshi</groupId>
<artifactId>moshi</artifactId>
</dependency>
<dependency>
<groupId>com.ryanharter.auto.value</groupId>
<artifactId>auto-value-moshi-runtime</artifactId>
</dependency>
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value-annotations</artifactId>
<groupId>io.soabase.record-builder</groupId>
<artifactId>record-builder-core</artifactId>
<version>${io.soabase.record-builder.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
Expand Down Expand Up @@ -152,6 +128,14 @@
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<!-- Needed for json serialization in test classes using rest-assured,
jsonb-3.0 is not yet supported, see https://github.com/rest-assured/rest-assured/issues/1651 -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand All @@ -163,9 +147,9 @@
<parameters>${maven.compiler.parameters}</parameters>
<annotationProcessorPaths>
<path>
<groupId>com.ryanharter.auto.value</groupId>
<artifactId>auto-value-moshi-extension</artifactId>
<version>${com.ryanharter.auto.value.auto-value-moshi.version}</version>
<groupId>io.soabase.record-builder</groupId>
<artifactId>record-builder-processor</artifactId>
<version>${io.soabase.record-builder.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.squareup.moshi.Moshi;

import jakarta.ws.rs.core.GenericType;
import org.jboss.resteasy.plugins.providers.multipart.InputPart;
import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;

Expand Down Expand Up @@ -92,25 +92,12 @@ <T> Optional<T> partBodyAs(String partName, Class<T> type, Type genericType) thr
return Optional.empty();
}

static class WithMoshi extends MultipartFormDataInputWrapper {
private final Moshi moshi;

WithMoshi(MultipartFormDataInput input, Moshi moshi) {
super(input);
this.moshi = moshi;
}

<T> Optional<T> partJsonBodyAs(String partName, Class<T> type) throws IOException {
if (moshi != null) {
Optional<BufferedSource> source = partBodyAsBufferedSource(partName);
if (source.isPresent()) {
try (BufferedSource actualSource = source.get()) {
return Optional.of(moshi.adapter(type).fromJson(actualSource));
}
}
}
return Optional.empty();
<T> Optional<T> partBodyAs(String partName, GenericType<T> genericType) throws IOException {
Optional<InputPart> part = partWithName(partName);
if (part.isPresent()) {
return Optional.of(part.get().getBody(genericType));
}
return Optional.empty();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public class NotarizationCache {
@Inject
NotarizationCache(
@ConfigProperty(name = "notarization.cache.expireAfterWrite", defaultValue = "P1D") String cacheExpireAfterWrite) {
cache = CacheBuilder.newBuilder()
cache =
CacheBuilder.newBuilder()
.expireAfterWrite(Duration.parse(cacheExpireAfterWrite))
.recordStats()
.removalListener(RemovalListeners.asynchronous((RemovalNotification<UUID, NotarizationRequest> notification) -> {
Expand All @@ -50,7 +51,9 @@ public class NotarizationCache {
try {
Files.deleteIfExists(request.fileToNotarize());
} catch (IOException e) {
LOGGER.warn(String.format("Unable to delete user uploaded file '%s' to notarize after cache eviction of\n%s", request.fileToNotarize(), request), e);
LOGGER.warn(String.format("Unable to delete user uploaded file '%s' to notarize after cache eviction of\n%s",
request.fileToNotarize(), request),
e);
}
}, Executors.newSingleThreadExecutor()))
.build();
Expand Down
Loading

0 comments on commit 79bc673

Please sign in to comment.