Skip to content

Commit

Permalink
Fix Sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-schnell committed Feb 19, 2024
1 parent 41a81c1 commit 07d1580
Show file tree
Hide file tree
Showing 23 changed files with 213 additions and 63 deletions.
11 changes: 6 additions & 5 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<groupId>org.fuin.esc</groupId>
<artifactId>esc-parent</artifactId>
<version>0.8.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>esc-api</artifactId>
Expand Down Expand Up @@ -130,11 +131,6 @@

<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand All @@ -150,6 +146,11 @@
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/org/fuin/esc/api/EnhancedMimeType.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public static EnhancedMimeType create(@NotNull final String primary, @NotNull fi
@NotNull
public static EnhancedMimeType create(@NotNull final String primary, @NotNull final String sub,
final Charset encoding, final String version) {
return create(primary, sub, encoding, version, new HashMap<String, String>());
return create(primary, sub, encoding, version, new HashMap<>());
}

/**
Expand Down
6 changes: 6 additions & 0 deletions client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<groupId>org.fuin.esc</groupId>
<artifactId>esc-parent</artifactId>
<version>0.8.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>esc-client</artifactId>
Expand Down Expand Up @@ -91,6 +92,11 @@
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand Down
6 changes: 6 additions & 0 deletions esgrpc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<groupId>org.fuin.esc</groupId>
<artifactId>esc-parent</artifactId>
<version>0.8.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>esc-esgrpc</artifactId>
Expand Down Expand Up @@ -189,6 +190,11 @@
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/**
* Test for the {@link ESGrpcEventStore} class.
*/
@SuppressWarnings("java:S2187")
@TestOmitted("Tested in the 'test' project")
public class ESGrpcEventStoreTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Tests the {@link GrpcProjectionAdminEventStore} class.
*/
@ArchIgnore
@SuppressWarnings("java:S2187")
class GrpcProjectionAdminEventStoreIT {

private static EventStoreDBProjectionManagementClient client;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/**
* Test for the {@link GrpcProjectionAdminEventStore} class.
*/
@SuppressWarnings("java:S2187")
@TestOmitted("Tested in the 'test' project")
public class GrpcProjectionAdminEventStoreTest {

Expand Down
104 changes: 104 additions & 0 deletions jacoco/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<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/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.fuin.esc</groupId>
<artifactId>esc-parent</artifactId>
<version>0.8.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>esc-jacoco</artifactId>

<dependencies>

<dependency>
<groupId>org.fuin.esc</groupId>
<artifactId>esc-api</artifactId>
</dependency>

<dependency>
<groupId>org.fuin.esc</groupId>
<artifactId>esc-client</artifactId>
</dependency>

<dependency>
<groupId>org.fuin.esc</groupId>
<artifactId>esc-spi</artifactId>
</dependency>

<dependency>
<groupId>org.fuin.esc</groupId>
<artifactId>esc-mem</artifactId>
</dependency>

<dependency>
<groupId>org.fuin.esc</groupId>
<artifactId>esc-jaxb</artifactId>
</dependency>

<dependency>
<groupId>org.fuin.esc</groupId>
<artifactId>esc-jpa</artifactId>
</dependency>

<dependency>
<groupId>org.fuin.esc</groupId>
<artifactId>esc-jsonb</artifactId>
</dependency>

<dependency>
<groupId>org.fuin.esc</groupId>
<artifactId>esc-esgrpc</artifactId>
</dependency>

<dependency>
<groupId>org.fuin.esc</groupId>
<artifactId>esc-test</artifactId>
</dependency>

</dependencies>

<build>

<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>report-aggregate</id>
<phase>verify</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>

</plugins>

</build>

</project>
8 changes: 8 additions & 0 deletions jacoco/src/main/java/org/fuin/esc/jacoco/Dummy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.fuin.esc.jacoco;

/**
* Maven complains about empty JAR if we don't have this class...
*/
@SuppressWarnings("java:S2094")
public class Dummy {
}
6 changes: 6 additions & 0 deletions jaxb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<groupId>org.fuin.esc</groupId>
<artifactId>esc-parent</artifactId>
<version>0.8.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>esc-jaxb</artifactId>
Expand Down Expand Up @@ -147,6 +148,11 @@
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion jaxb/src/main/java/org/fuin/esc/jaxb/EscMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public EscMeta(@NotNull final String dataType, @NotNull final EnhancedMimeType d
*
* @return Data type.
*/
@Nullable
@NotNull
public String getDataType() {
return dataType;
}
Expand Down
6 changes: 6 additions & 0 deletions jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<groupId>org.fuin.esc</groupId>
<artifactId>esc-parent</artifactId>
<version>0.8.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>esc-jpa</artifactId>
Expand Down Expand Up @@ -201,6 +202,11 @@
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand Down
6 changes: 6 additions & 0 deletions jsonb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<groupId>org.fuin.esc</groupId>
<artifactId>esc-parent</artifactId>
<version>0.8.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>esc-jsonb</artifactId>
Expand Down Expand Up @@ -155,6 +156,11 @@
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public EscEvent deserialize(JsonParser parser, DeserializationContext ctx, Type
if (content.containsKey(Base64Data.EL_ROOT_NAME)) {
escEvent.setData(new DataWrapper(new Base64Data(content.getString(Base64Data.EL_ROOT_NAME))));
} else {
if (escEvent.getMeta() == null) {
if (escEvent.getMeta() == null) { //NOSONAR Can unfortunately be null because it's not set above...
throw new IllegalStateException("Expected 'meta' to be set, but was never processed during parse process");
}
if (!(escEvent.getMeta().getObj() instanceof EscMeta escMeta)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.fuin.esc.api.SerializedDataTypeRegistryRequired;

import java.lang.reflect.Type;
import java.util.Objects;

/**
* Adapter to use for JSON-B.
Expand Down Expand Up @@ -62,9 +63,9 @@ public void serialize(EscMeta escMeta, JsonGenerator generator, SerializationCon
generator.writeStartObject();
generator.write(EscMeta.EL_DATA_TYPE, escMeta.getDataType());
generator.write(EscMeta.EL_DATA_CONTENT_TYPE, escMeta.getDataContentType().toString());
if (escMeta.getMeta() != null) {
if (escMeta.getMeta() != null) { //NOSONAR Can unfortunately be null because it's not set above...
generator.write(EscMeta.EL_META_TYPE, escMeta.getMetaType());
generator.write(EscMeta.EL_META_CONTENT_TYPE, escMeta.getMetaContentType().toString());
generator.write(EscMeta.EL_META_CONTENT_TYPE, Objects.requireNonNull(escMeta.getMetaContentType()).toString());
if (escMeta.getMeta() instanceof Base64Data base64data) {
generator.write(Base64Data.EL_ROOT_NAME, base64data.getEncoded());
} else {
Expand Down
50 changes: 29 additions & 21 deletions jsonb/src/main/java/org/fuin/esc/jsonb/JsonbDeSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void init(@NotNull final SerializedDataTypeRegistry typeRegistry) {
* @param serRegistry
* Mapping from type name to serializers.
*/
public void init(@Nullable final SerializedDataTypeRegistry typeRegistry, @Nullable final SerializerRegistry serRegistry) {
public void init(@NotNull final SerializedDataTypeRegistry typeRegistry, @Nullable final SerializerRegistry serRegistry) {
init(typeRegistry, null, serRegistry);
}

Expand All @@ -191,7 +191,7 @@ public void init(@Nullable final SerializedDataTypeRegistry typeRegistry, @Nulla
* @param deserRegistry
* Mapping from type name to deserializers.
*/
public void init(@Nullable final SerializedDataTypeRegistry typeRegistry, @Nullable final DeserializerRegistry deserRegistry) {
public void init(@NotNull final SerializedDataTypeRegistry typeRegistry, @Nullable final DeserializerRegistry deserRegistry) {
init(typeRegistry, deserRegistry, null);
}

Expand All @@ -212,24 +212,12 @@ public void init(@NotNull final SerializedDataTypeRegistry typeRegistry,
throw new IllegalStateException("Instance already initialized - Don't call the init methods more than once");
}
this.typeRegistry = typeRegistry;
for (final JsonbDeserializer<?> deserializer : deserializers) {
if (deserializer instanceof DeserializerRegistryRequired des) {
if (deserRegistry == null) {
throw new IllegalStateException(
"There is at least one deserializer that requires a 'DeserializerRegistry', but you didn't provide one (deserializer="
+ deserializer.getClass().getName() + ")");
}
des.setRegistry(deserRegistry);
}
if (deserializer instanceof SerializedDataTypeRegistryRequired des) {
if (typeRegistry == null) {
throw new IllegalStateException(
"There is at least one deserializer that requires a 'SerializedDataTypeRegistry', but you didn't provide one (deserializer="
+ deserializer.getClass().getName() + ")");
}
des.setRegistry(typeRegistry);
}
}
initDeserializers(typeRegistry, deserRegistry);
initSerializers(typeRegistry, serRegistry);
initialized = true;
}

private void initSerializers(SerializedDataTypeRegistry typeRegistry, SerializerRegistry serRegistry) {
for (final JsonbSerializer<?> serializer : serializers) {
if (serializer instanceof SerializerRegistryRequired ser) {
if (serRegistry == null) {
Expand All @@ -248,7 +236,27 @@ public void init(@NotNull final SerializedDataTypeRegistry typeRegistry,
ser.setRegistry(typeRegistry);
}
}
initialized = true;
}

private void initDeserializers(SerializedDataTypeRegistry typeRegistry, DeserializerRegistry deserRegistry) {
for (final JsonbDeserializer<?> deserializer : deserializers) {
if (deserializer instanceof DeserializerRegistryRequired des) {
if (deserRegistry == null) {
throw new IllegalStateException(
"There is at least one deserializer that requires a 'DeserializerRegistry', but you didn't provide one (deserializer="
+ deserializer.getClass().getName() + ")");
}
des.setRegistry(deserRegistry);
}
if (deserializer instanceof SerializedDataTypeRegistryRequired des) {
if (typeRegistry == null) {
throw new IllegalStateException(
"There is at least one deserializer that requires a 'SerializedDataTypeRegistry', but you didn't provide one (deserializer="
+ deserializer.getClass().getName() + ")");
}
des.setRegistry(typeRegistry);
}
}
}

private void ensureInitialized() {
Expand Down
Loading

0 comments on commit 07d1580

Please sign in to comment.