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

Adapt to Java 17 and 21 #72

Merged
merged 11 commits into from
Jul 9, 2024
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
10 changes: 3 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ on:
jobs:
matrix-build:
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
fail-fast: true
matrix:
java: [11] # 17 & 21 removed because of https://github.com/itsallcode/junit5-system-extensions/issues/68
java: [11, 17, 21]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-java-${{ matrix.java }}
cancel-in-progress: true
Expand Down Expand Up @@ -46,12 +48,6 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Publish Test Report
uses: scacap/action-surefire-report@v1
if: ${{ always() && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]' }}
with:
report_paths: '**/target/surefire-reports/TEST-*.xml'
github_token: ${{ secrets.GITHUB_TOKEN }}

build:
needs: matrix-build
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/github_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

set -o errexit
set -o nounset
set -o pipefail

base_dir="$( cd "$(dirname "$0")/../.." >/dev/null 2>&1 ; pwd -P )"
readonly base_dir
readonly pom_file="$base_dir/pom.xml"

# Read project version from pom file
project_version=$(grep "<version>" "$pom_file" | sed --regexp-extended 's/\s*<version>(.*)<\/version>\s*/\1/g' | head --lines=1)
readonly project_version
echo "Read project version '$project_version' from $pom_file"

readonly changes_file="$base_dir/doc/changes/changes_${project_version}.md"
notes=$(cat "$changes_file")
readonly notes

readonly title="Release $project_version"
readonly tag="$project_version"
echo "Creating release:"
echo "Git tag : $tag"
echo "Title : $title"
echo "Changes file : $changes_file"

release_url=$(gh release create --latest --title "$title" --notes "$notes" --target main "$tag")
readonly release_url
echo "Release URL: $release_url"
63 changes: 63 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Release

on:
workflow_dispatch:
inputs:
skip-deploy-maven-central:
description: "Skip deployment to Maven Central"
required: true
type: boolean
default: false

jobs:
release:
runs-on: ubuntu-latest
defaults:
run:
shell: "bash"
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false
permissions:
contents: write # Required for creating GitHub release
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Fail if not running on main branch
if: ${{ github.ref != 'refs/heads/main' }}
uses: actions/github-script@v7
with:
script: |
core.setFailed('Not running on main branch, github.ref is ${{ github.ref }}. Please start this workflow only on main')

- name: Set up Maven Central Repository
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: 17
cache: "maven"
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-private-key: ${{ secrets.OSSRH_GPG_SECRET_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE

- name: Build
run: mvn --batch-mode -T 1C clean install

- name: List secret GPG keys
run: gpg --list-secret-keys

- name: Publish to Maven Central Repository
if: ${{ !inputs.skip-deploy-maven-central }}
run: mvn --batch-mode deploy -Possrh -DstagingDescription="Deployed via GitHub workflow release.yml"
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}

- name: Create GitHub Release
run: ./.github/workflows/github_release.sh
env:
GH_TOKEN: ${{ github.token }}
52 changes: 19 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ The `ExitGuard` temporarily replaces the existing security manager.

From version 1.2.0 on if a security guard existed before, it serves as a delegate for all security checks with the exception of the `checkExit`.

**Warning:** The JREs Security Manager used by `ExitGuard` is deprecated and is not supported by Java 21 and later. It still works with Java 17 but logs the following warning:

```
WARNING: A terminally deprecated method in java.lang.System has been called
WARNING: System::setSecurityManager has been called by ...
WARNING: Please consider reporting this to the maintainers of ...
WARNING: System::setSecurityManager will be removed in a future release
```

## Asserting Data Sent to `System.out`

To capture data sent to `System.out`, follow these steps:
Expand Down Expand Up @@ -136,40 +145,17 @@ mvn --update-snapshots versions:display-dependency-updates versions:display-plug
```

### Publishing to MavenCentral

1. Add the following to your `~/.m2/settings.xml`:

```xml
<settings>
<servers>
<server>
<id>ossrh</id>
<username>your-jira-id</username>
<password>your-jira-pwd</password>
</server>
</servers>
<profiles>
<profile>
<id>ossrh</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<gpg.executable>gpg</gpg.executable>
<gpg.passphrase>the_pass_phrase</gpg.passphrase>
</properties>
</profile>
</profiles>
</settings>
```
#### Prepare the Release

1. Checkout the `main` branch.
1. Update version in `pom.xml`, commit and push.
1. Run command
2. Update version in `pom.xml` and changelog.
3. Commit and push changes.
4. Create a new pull request, have it reviewed and merged to `main`.

```bash
mvn -DskipSigningArtifacts=false clean deploy
```
### Perform the Release

1. Create a [release](https://github.com/itsallcode/junit5-system-extensions/releases) of the `main` branch on GitHub.
1. After some time the release will be available at [Maven Central](https://repo1.maven.org/maven2/org/itsallcode/junit5-system-extensions/).
1. Start the release workflow
* Run command `gh workflow run release.yml --repo itsallcode/junit5-system-extensions --ref main`
* or go to [GitHub Actions](https://github.com/itsallcode/junit5-system-extensions/actions/workflows/release.yml) and start the `release.yml` workflow on branch `main`.
2. Update title and description of the newly created [GitHub release](https://github.com/itsallcode/junit5-system-extensions/releases).
3. After some time the release will be available at [Maven Central](https://repo1.maven.org/maven2/org/itsallcode/junit5-system-extensions/).
9 changes: 7 additions & 2 deletions doc/changes/changes_1.2.1.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# JUnit5 System Extensions 1.2.1, released 2022-09-??
# JUnit5 System Extensions 1.2.1, released 2024-07-09

Code name: Sonar smell fixes for 1.2.0

## Summary

Version 1.2.1 is a service release that fixed SONAR code smells.
Version 1.2.1 is a service release that fixed SONAR code smells and adds tests with Java 17 and Java 21.

## Bugfixes

Expand All @@ -14,7 +14,12 @@ Version 1.2.1 is a service release that fixed SONAR code smells.

* [PR #67](https://github.com/itsallcode/junit5-system-extensions/pull/66): Upgrade dependencies
* [PR #69](https://github.com/itsallcode/junit5-system-extensions/pull/69): Remove license header from sources
* [PR #72](https://github.com/itsallcode/junit5-system-extensions/pull/72): Adapt to Java 17 and 21, add JavaDoc

## Development process

* The `develop` branch was renamed to `main`, `master` was deleted.

## Deprecation Warning

The JREs Security Manager used by `ExitGuard` is deprecated and is not supported by Java 21 and later.
34 changes: 22 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</scm>
<properties>
<java.version>11</java.version>
<junit.version>5.10.1</junit.version>
<junit.version>5.10.3</junit.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<skipSigningArtifacts>true</skipSigningArtifacts>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
Expand Down Expand Up @@ -67,7 +67,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.10.0</version>
<version>5.12.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -76,7 +76,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>3.1.0</version>
<version>3.2.0</version>
<executions>
<execution>
<goals>
Expand All @@ -95,16 +95,21 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.12.1</version>
<version>3.13.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<compilerArgs>
<!-- Ignore warnings about removal of SecurityManager -->
<arg>-Xlint:all,-removal</arg>
<arg>-Werror</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.3.0</version>
<version>3.3.1</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -117,7 +122,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.6.3</version>
<version>3.7.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand All @@ -141,7 +146,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.11</version>
<version>0.8.12</version>
<executions>
<execution>
<goals>
Expand All @@ -158,13 +163,18 @@
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<version>3.3.0</version>
<configuration>
<!-- Suppress warning about loading byte-buddy-agent -->
<argLine>-XX:+EnableDynamicAgentLoading ${argLine}</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.1.0</version>
<version>3.2.4</version>
<executions>
<execution>
<id>sign-artifacts</id>
Expand All @@ -181,12 +191,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.1</version>
<version>3.1.2</version>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.13</version>
<version>1.7.0</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
Expand All @@ -197,7 +207,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.4.1</version>
<version>3.5.0</version>
<executions>
<execution>
<id>enforce-maven</id>
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/org/itsallcode/io/Capturable.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
package org.itsallcode.io;

/**
* Interface for classes that can capture output.
*/
public interface Capturable
{
/**
* Activate capturing
*/
public void capture();
void capture();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why remove this? I always found this notation inconsistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sonar complains about this. Interface methods are public by default.


/**
* Activate muted capturing, i.e. don't forward output to the underlying
* output stream. This can be useful to speedup tests.
*/
public void captureMuted();
void captureMuted();

/**
* Get the data that was captured.
*
* @return captured data.
*/
public String getCapturedData();
String getCapturedData();
}
Loading