Skip to content

Commit

Permalink
Merge pull request #299 from uhafner/renew-pom
Browse files Browse the repository at this point in the history
Improve support for JDK 11 builds
  • Loading branch information
uhafner authored Feb 15, 2021
2 parents 419aa0e + 77ddc3c commit 331bd4f
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 55 deletions.
8 changes: 3 additions & 5 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
node {
def mvnHome = tool 'mvn-default'

node('java11-agent') {
stage ('Checkout') {
checkout scm
}

stage ('Build, Test, and Static Analysis') {
withMaven(maven: 'mvn-default', mavenLocalRepo: '/var/data/m2repository', mavenOpts: '-Xmx768m -Xms512m') {
withMaven(mavenLocalRepo: '/var/data/m2repository', mavenOpts: '-Xmx768m -Xms512m') {
sh 'mvn -V -e clean verify -Dmaven.test.failure.ignore -Dgpg.skip'
}

Expand All @@ -25,7 +23,7 @@ node {
}

stage ('Mutation Coverage') {
withMaven(maven: 'mvn-default', mavenLocalRepo: '/var/data/m2repository', mavenOpts: '-Xmx768m -Xms512m') {
withMaven(mavenLocalRepo: '/var/data/m2repository', mavenOpts: '-Xmx768m -Xms512m') {
sh "mvn org.pitest:pitest-maven:mutationCoverage"
}
step([$class: 'PitPublisher', mutationStatsFile: 'target/pit-reports/**/mutations.xml'])
Expand Down
22 changes: 22 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
<maven-enforcer-plugin.version>3.0.0-M3</maven-enforcer-plugin.version>
<maven-dependency-plugin.version>3.1.2</maven-dependency-plugin.version>
<depgraph-maven-plugin.version>3.3.0</depgraph-maven-plugin.version>
<animal-sniffer-maven-plugin.version>1.19</animal-sniffer-maven-plugin.version>

<!-- Maven Surefire ArgLine -->
<argLine>-Djava.util.logging.config.file=logging.properties</argLine>
Expand Down Expand Up @@ -235,6 +236,27 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>${animal-sniffer-maven-plugin.version}</version>
<configuration>
<signature>
<groupId>org.codehaus.mojo.signature</groupId>
<artifactId>java18</artifactId>
<version>1.0</version>
</signature>
</configuration>
<executions>
<execution>
<id>animal-sniffer</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
Expand Down
82 changes: 39 additions & 43 deletions src/main/java/edu/hm/hafner/util/Ensure.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ public static BooleanCondition that(final boolean value) {
* the additional values to check
*
* @return an object condition
* @param <T> type to check
*/
@CheckReturnValue
public static ObjectCondition that(@CheckForNull final Object value,
public static <T> ObjectCondition<T> that(@CheckForNull final T value,
@CheckForNull final Object... additionalValues) {
return new ObjectCondition(value, additionalValues);
return new ObjectCondition<>(value, additionalValues);
}

/**
Expand Down Expand Up @@ -193,10 +194,7 @@ private Ensure() {
/**
* Assertions for iterables.
*/
public static class IterableCondition extends ObjectCondition {
@CheckForNull
private final Iterable<?> value;

public static class IterableCondition extends ObjectCondition<Iterable<?>> {
/**
* Creates a new instance of {@code IterableCondition}.
*
Expand All @@ -205,8 +203,6 @@ public static class IterableCondition extends ObjectCondition {
*/
public IterableCondition(@CheckForNull final Iterable<?> value) {
super(value);

this.value = value;
}

/**
Expand Down Expand Up @@ -238,8 +234,8 @@ public void isNotEmpty() {
public void isNotEmpty(final String explanation, final Object... args) {
isNotNull(explanation, args);

if (value.iterator().hasNext()) {
for (Object object : value) {
if (getValue().iterator().hasNext()) {
for (Object object : getValue()) {
if (object == null) {
throwException(explanation, args);
}
Expand All @@ -255,9 +251,6 @@ public void isNotEmpty(final String explanation, final Object... args) {
* Assertions for iterables.
*/
public static class CollectionCondition extends IterableCondition {
@CheckForNull
private final Collection<?> value;

/**
* Creates a new instance of {@code CollectionCondition}.
*
Expand All @@ -267,8 +260,11 @@ public static class CollectionCondition extends IterableCondition {
@SuppressWarnings("AssignmentToCollectionOrArrayFieldFromParameter")
public CollectionCondition(@CheckForNull final Collection<?> value) {
super(value);
}

this.value = value;
@Override
Collection<?> getValue() {
return (Collection<?>) super.getValue();
}

/**
Expand All @@ -281,7 +277,7 @@ public CollectionCondition(@CheckForNull final Collection<?> value) {
* if the collection is {@code null} or if the specified element is not found
*/
public void contains(final Object element) {
contains(element, "Collection %s does not contain element '%s'", value, element);
contains(element, "Collection %s does not contain element '%s'", getValue(), element);
}

/**
Expand All @@ -303,7 +299,7 @@ public void contains(final Object element) {
public void contains(final Object element, final String explanation, final Object... args) {
isNotNull(explanation, args);

if (!value.contains(element)) {
if (!getValue().contains(element)) {
throwException(explanation, args);
}
}
Expand All @@ -318,7 +314,7 @@ public void contains(final Object element, final String explanation, final Objec
* if the collection is {@code null} or if the specified element is part of the collection
*/
public void doesNotContain(final Object element) {
doesNotContain(element, "Collection '%s' contains element '%s'", value, element);
doesNotContain(element, "Collection '%s' contains element '%s'", getValue(), element);
}

/**
Expand All @@ -340,7 +336,7 @@ public void doesNotContain(final Object element) {
public void doesNotContain(final Object element, final String explanation, final Object... args) {
isNotNull(explanation, args);

if (value.contains(element)) {
if (getValue().contains(element)) {
throwException(explanation, args);
}
}
Expand All @@ -349,22 +345,16 @@ public void doesNotContain(final Object element, final String explanation, final
/**
* Assertions for arrays.
*/
public static class ArrayCondition extends ObjectCondition {
@CheckForNull
private final Object[] values;

public static class ArrayCondition extends ObjectCondition<Object[]> {
/**
* Creates a new instance of {@link IterableCondition}.
*
* @param values
* value of the condition
*/
@SuppressWarnings({"AssignmentToCollectionOrArrayFieldFromParameter", "PMD.ArrayIsStoredDirectly", "PMD.UseVarargs"})
@SuppressFBWarnings("EI2")
@SuppressWarnings("PMD.UseVarargs")
public ArrayCondition(@CheckForNull final Object[] values) {
super(values);

this.values = values;
}

/**
Expand Down Expand Up @@ -396,11 +386,11 @@ public void isNotEmpty() {
public void isNotEmpty(final String explanation, final Object... args) {
isNotNull(explanation, args);

if (values.length == 0) {
if (getValue().length == 0) {
throwException(explanation, args);
}
else {
for (Object object : values) {
for (Object object : getValue()) {
if (object == null) {
throwException(explanation, args);
}
Expand All @@ -412,10 +402,7 @@ public void isNotEmpty(final String explanation, final Object... args) {
/**
* Assertions for strings.
*/
public static class StringCondition extends ObjectCondition {
@CheckForNull
private final String value;

public static class StringCondition extends ObjectCondition<String> {
/**
* Creates a new instance of {@code StringCondition}.
*
Expand All @@ -424,8 +411,6 @@ public static class StringCondition extends ObjectCondition {
*/
public StringCondition(@CheckForNull final String value) {
super(value);

this.value = value;
}

/**
Expand Down Expand Up @@ -455,7 +440,7 @@ public void isNotEmpty() {
public void isNotEmpty(final String explanation, final Object... args) {
isNotNull(explanation, args);

if (value.isEmpty()) {
if (getValue().isEmpty()) {
throwException(explanation, args);
}
}
Expand Down Expand Up @@ -493,11 +478,12 @@ public void isNotBlank(final String explanation, final Object... args) {
}

private boolean isBlank() {
if (value.isEmpty()) {
String string = getValue();
if (string.isEmpty()) {
return true;
}
for (int i = 0; i < value.length(); i++) {
if (!Character.isWhitespace(value.charAt(i))) {
for (int i = 0; i < string.length(); i++) {
if (!Character.isWhitespace(string.charAt(i))) {
return false;
}
}
Expand All @@ -507,11 +493,12 @@ private boolean isBlank() {

/**
* Assertions for objects.
*
* @param <T> type to check
*/
public static class ObjectCondition {
@CheckForNull
private final Object value;
public static class ObjectCondition<T> {
@CheckForNull
private final T value;
private final Object[] additionalValues;

/**
Expand All @@ -520,7 +507,7 @@ public static class ObjectCondition {
* @param value
* value of the condition
*/
public ObjectCondition(@CheckForNull final Object value) {
public ObjectCondition(@CheckForNull final T value) {
this(value, new Object[0]);
}

Expand All @@ -534,7 +521,7 @@ public ObjectCondition(@CheckForNull final Object value) {
*/
@SuppressFBWarnings("EI2")
@SuppressWarnings({"AssignmentToCollectionOrArrayFieldFromParameter", "PMD.ArrayIsStoredDirectly"})
public ObjectCondition(@CheckForNull final Object value, @CheckForNull final Object... additionalValues) {
public ObjectCondition(@CheckForNull final T value, final Object... additionalValues) {
this.value = value;
this.additionalValues = additionalValues;
}
Expand Down Expand Up @@ -574,6 +561,15 @@ public void isNotNull(final String explanation, final Object... args) {
}
}

@SuppressFBWarnings("NP")
@SuppressWarnings("PMD.AvoidThrowingNullPointerException")
T getValue() {
if (value == null) {
throw new NullPointerException("Value is null");
}
return value;
}

/**
* Ensures that the given object is {@code null}.
*
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/edu/hm/hafner/util/FilteredLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
public class FilteredLog implements Serializable {
private static final long serialVersionUID = -8552323621953159904L;

private static final String SKIPPED_MESSAGE = " ... skipped logging of %d additional errors ...";
private static final int DEFAULT_MAX_LINES = 20;

private final String title;
Expand Down Expand Up @@ -132,7 +131,7 @@ public int size() {
*/
public void logSummary() {
if (lines > maxLines) {
errorMessages.add(String.format(SKIPPED_MESSAGE, lines - maxLines));
errorMessages.add(String.format(" ... skipped logging of %d additional errors ...", lines - maxLines));
}
}

Expand Down Expand Up @@ -183,4 +182,15 @@ public boolean equals(final Object o) {
public int hashCode() {
return Objects.hash(title, maxLines, lines, infoMessages, errorMessages);
}

@Override @Generated
public String toString() {
return "FilteredLog{"
+ "title='" + title + '\''
+ ", maxLines=" + maxLines
+ ", lines=" + lines
+ ", infoMessages=" + infoMessages
+ ", errorMessages=" + errorMessages
+ '}';
}
}
3 changes: 1 addition & 2 deletions src/main/java/edu/hm/hafner/util/TreeStringBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

/**
* Builds {@link TreeString}s that share common prefixes. Call {@link #intern(String)} and you get the {@link
Expand Down Expand Up @@ -88,7 +87,7 @@ public Child intern(final String string) {
}

makeWritable();
for (Entry<String, Child> entry : children.entrySet()) {
for (Map.Entry<String, Child> entry : children.entrySet()) {
int plen = commonPrefix(entry.getKey(), string);
if (plen > 0) {
if (plen < entry.getKey().length()) {
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/edu/hm/hafner/util/EnsureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*
* @author Ullrich Hafner
*/
@SuppressWarnings("NullArgumentToVariableArgMethod")
class EnsureTest {
private static final String SOME_STRING = "-";
private static final String EMPTY_STRING = "";
Expand Down Expand Up @@ -181,4 +180,4 @@ void shouldThrowExceptionWithCorrectMessage() {
Ensure.that(EMPTY_STRING).isInstanceOf(Integer.class, "This error uses '%s' to print the number %d.", "String.format", 42);
}).isInstanceOf(AssertionError.class).hasMessage("This error uses 'String.format' to print the number 42.");
}
}
}
2 changes: 1 addition & 1 deletion src/test/java/edu/hm/hafner/util/SerializableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected void assertThatSerializableCanBeRestoredFrom(final byte... serializedI
* the byte stream of the serializable
* @return the deserialized instance
*/
@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "BanSerializableRead"})
protected T restore(final byte[] serializedInstance) {
Object object;

Expand Down

0 comments on commit 331bd4f

Please sign in to comment.