Skip to content

Commit

Permalink
build/ci: add check-forbidden-classes.sh 🚫
Browse files Browse the repository at this point in the history
  • Loading branch information
oldratlee committed Apr 3, 2024
1 parent 1b9e0fe commit 8b3167d
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 15 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,23 @@ jobs:
distribution: zulu
java-version: ${{ matrix.java }}
cache: maven
- run: ./mvnw -V --no-transfer-progress clean package
- name: Run dev mode test
run: ./mvnw -V --no-transfer-progress clean package
if: matrix.java != 17
- run: ./mvnw -V --no-transfer-progress clean package spotbugs:check git-commit-id:validateRevision -DperformRelease
- name: Run release mode test
run: ./mvnw -V --no-transfer-progress clean package spotbugs:check git-commit-id:validateRevision -DperformRelease
if: matrix.java == 17
# https://github.com/marketplace/actions/codecov
- uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Check forbidden classes
run: scripts/check-forbidden-classes.sh
# https://docs.github.com/en/actions/learn-github-actions/variables#detecting-the-operating-system
if: runner.os != 'Windows'
# https://remarkablemark.org/blog/2017/10/12/check-git-dirty/
- name: Check git dirty
run: |
git status --short
[ -z "$(git status --short)" ]
# https://docs.github.com/en/actions/learn-github-actions/variables#detecting-the-operating-system
if: runner.os != 'Windows'
29 changes: 29 additions & 0 deletions scripts/check-forbidden-classes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
set -eEuo pipefail

# cd to project root dir
cd "${0%/*}"/..

readonly forbidden_classes=(
# use edu.umd.cs.findbugs.annotations.Nullable
javax.annotation.Nullable
org.jetbrains.annotations.Nullable

# use edu.umd.cs.findbugs.annotations.NonNull
javax.annotation.Nonnull
org.jetbrains.annotations.NotNull

# use edu.umd.cs.findbugs.annotations.CheckForNull
javax.annotation.CheckReturnValue
org.jetbrains.annotations.CheckReturnValue

# use @edu.umd.cs.findbugs.annotations.DefaultAnnotationForParameters(NonNull.class)
javax.annotation.ParametersAreNonnullByDefault
)

grep_pattern=$(printf '%s\n' "${forbidden_classes[@]}")

grep_options=("$grep_pattern" -F -n -C2 -r src/)
[[ "${GITHUB_ACTIONS:-}" = true || -t 1 ]] && grep_options=("${grep_options[@]}" --color=always)

! grep "${grep_options[@]}"
4 changes: 2 additions & 2 deletions src/main/java/io/foldright/inspectablewrappers/Inspector.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.foldright.inspectablewrappers;

import edu.umd.cs.findbugs.annotations.DefaultAnnotationForParameters;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;

import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Predicate;
Expand Down Expand Up @@ -49,7 +49,7 @@
* @see Attachable
* @see WrapperAdapter
*/
@ParametersAreNonnullByDefault
@DefaultAnnotationForParameters(NonNull.class)
public final class Inspector {
/**
* Reports whether any instance on the wrapper chain matches the given type.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.foldright.inspectablewrappers.utils;

import edu.umd.cs.findbugs.annotations.DefaultAnnotationForParameters;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import io.foldright.inspectablewrappers.Attachable;
import io.foldright.inspectablewrappers.Wrapper;
import io.foldright.inspectablewrappers.WrapperAdapter;

import javax.annotation.ParametersAreNonnullByDefault;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
Expand All @@ -23,7 +23,7 @@
*
* @author Jerry Lee (oldratlee at gmail dot com)
*/
@ParametersAreNonnullByDefault
@DefaultAnnotationForParameters(NonNull.class)
public final class WrapperAdapterUtils {
/**
* Creates a {@link WrapperAdapter} instance of the given biz interface type by
Expand Down
4 changes: 0 additions & 4 deletions src/test/java/io/foldright/demo/ChattyExecutorWrapper.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package io.foldright.demo;

import edu.umd.cs.findbugs.annotations.ReturnValuesAreNonnullByDefault;
import io.foldright.inspectablewrappers.Wrapper;

import javax.annotation.ParametersAreNonnullByDefault;
import java.util.concurrent.Executor;


@ParametersAreNonnullByDefault
@ReturnValuesAreNonnullByDefault
public class ChattyExecutorWrapper implements Executor, Wrapper<Executor> {
private final Executor executor;

Expand Down
4 changes: 0 additions & 4 deletions src/test/java/io/foldright/demo/LazyExecutorWrapper.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package io.foldright.demo;

import edu.umd.cs.findbugs.annotations.Nullable;
import edu.umd.cs.findbugs.annotations.ReturnValuesAreNonnullByDefault;
import io.foldright.inspectablewrappers.Attachable;
import io.foldright.inspectablewrappers.Wrapper;
import io.foldright.inspectablewrappers.utils.AttachableDelegate;

import javax.annotation.ParametersAreNonnullByDefault;
import java.util.concurrent.Executor;


@ParametersAreNonnullByDefault
@ReturnValuesAreNonnullByDefault
public class LazyExecutorWrapper implements Executor, Wrapper<Executor>, Attachable<String, String> {
private final Executor executor;

Expand Down

0 comments on commit 8b3167d

Please sign in to comment.