From 6e18e67d904aea05d60cbad7ad49c8b376fddfa6 Mon Sep 17 00:00:00 2001 From: jamesrdi Date: Tue, 19 Dec 2023 11:11:26 +0100 Subject: [PATCH] Closes #2459: Fix Code Smells --- .github/workflows/continuous-integration.yml | 6 +++++- .../sampledata/SampleDataGenerator.java | 5 +---- .../security/CurrentUserContextImpl.java | 3 +-- .../common/test/security/JaasExtension.java | 18 ++++++++++++------ .../configuration/DbSchemaCreator.java | 6 +++--- .../configuration/parser/SimpleParser.java | 3 +-- .../internal/util/ComparableVersion.java | 4 +++- mvnw | 3 +-- pom.xml | 4 +--- 9 files changed, 28 insertions(+), 24 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 8e74ff6e5c..d263a5957b 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -44,6 +44,8 @@ jobs: with: distribution: adopt java-version: ${{ env.JAVA_VERSION }} + - name: Print Java version + run: java -version - name: Cache maven dependencies id: cache uses: actions/cache@v3 @@ -54,7 +56,9 @@ jobs: - name: Change versions to match tag run: ci/change_version.sh -m . - name: Compile & build - run: ./mvnw -B install -DskipTests -Dasciidoctor.skip -Djacoco.skip + run: ./mvnw clean -B install -DskipTests -Dasciidoctor.skip -Djacoco.skip + - name: Print Compilation Command + run: mvn clean compile -X - name: Populate cache if: steps.cache.outputs.cache-hit != 'true' run: | diff --git a/common/taskana-common-data/src/main/java/pro/taskana/sampledata/SampleDataGenerator.java b/common/taskana-common-data/src/main/java/pro/taskana/sampledata/SampleDataGenerator.java index 46edfaa4ac..cde3aabf44 100644 --- a/common/taskana-common-data/src/main/java/pro/taskana/sampledata/SampleDataGenerator.java +++ b/common/taskana-common-data/src/main/java/pro/taskana/sampledata/SampleDataGenerator.java @@ -13,7 +13,6 @@ import java.util.HashMap; import java.util.List; import java.util.function.Consumer; -import java.util.stream.Collectors; import java.util.stream.Stream; import javax.sql.DataSource; import org.apache.ibatis.jdbc.RuntimeSqlException; @@ -78,9 +77,7 @@ public void dropDb() { private List parseScripts(Stream scripts) { try (Connection connection = dataSource.getConnection()) { DB db = DB.getDB(connection); - return scripts - .map(script -> SqlReplacer.getScriptAsSql(db, now, script)) - .collect(Collectors.toList()); + return scripts.map(script -> SqlReplacer.getScriptAsSql(db, now, script)).toList(); } catch (SQLException e) { throw new RuntimeSqlException("Connection to database failed.", e); } diff --git a/common/taskana-common-security/src/main/java/pro/taskana/common/internal/security/CurrentUserContextImpl.java b/common/taskana-common-security/src/main/java/pro/taskana/common/internal/security/CurrentUserContextImpl.java index d6954f3d86..154e0249bb 100644 --- a/common/taskana-common-security/src/main/java/pro/taskana/common/internal/security/CurrentUserContextImpl.java +++ b/common/taskana-common-security/src/main/java/pro/taskana/common/internal/security/CurrentUserContextImpl.java @@ -10,7 +10,6 @@ import java.util.List; import java.util.Objects; import java.util.Set; -import java.util.stream.Collectors; import javax.security.auth.Subject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -61,7 +60,7 @@ public List getGroupIds() { .map(Principal::getName) .filter(Objects::nonNull) .map(this::convertAccessId) - .collect(Collectors.toList()); + .toList(); } LOGGER.trace("No groupIds found in subject!"); return Collections.emptyList(); diff --git a/common/taskana-common-test/src/main/java/pro/taskana/common/test/security/JaasExtension.java b/common/taskana-common-test/src/main/java/pro/taskana/common/test/security/JaasExtension.java index d5cb35f01d..09655fefad 100644 --- a/common/taskana-common-test/src/main/java/pro/taskana/common/test/security/JaasExtension.java +++ b/common/taskana-common-test/src/main/java/pro/taskana/common/test/security/JaasExtension.java @@ -111,7 +111,7 @@ public T interceptTestFactoryMethod( newChildrenForDynamicContainer = Collections.singleton((DynamicNode) factoryResult); } else if (factoryResult instanceof Stream) { Stream nodes = (Stream) factoryResult; - newChildrenForDynamicContainer = nodes.collect(Collectors.toList()); + newChildrenForDynamicContainer = nodes.toList(); } else if (factoryResult instanceof Iterable) { newChildrenForDynamicContainer = (Iterable) factoryResult; } else if (factoryResult instanceof Iterator) { @@ -142,8 +142,11 @@ public T interceptTestFactoryMethod( Store store = getMethodLevelStore(extensionContext); return (T) Stream.of(annotation.value()) - .peek(a -> store.put(ACCESS_IDS_STORE_KEY, a)) - .map(wrapTestsInDynamicContainer); + .map( + a -> { + store.put(ACCESS_IDS_STORE_KEY, a); + return wrapTestsInDynamicContainer.apply(a); + }); } return extractAccessIdAndPerformInvocation(invocation, invocationContext.getExecutable()); @@ -207,8 +210,11 @@ public Stream provideTestTemplateInvocationContex AnnotationSupport.findRepeatableAnnotations(context.getElement(), WithAccessId.class); Store store = getMethodLevelStore(context); return accessIds.stream() - .peek(a -> store.put(ACCESS_IDS_STORE_KEY, a)) - .map(JaasExtensionInvocationContext::new); + .map( + a -> { + store.put(ACCESS_IDS_STORE_KEY, a); + return new JaasExtensionInvocationContext(a); + }); } // endregion @@ -259,7 +265,7 @@ private static List getPrincipals(WithAccessId withAccessId) { return Stream.concat( Stream.of(withAccessId.user()).map(UserPrincipal::new), Arrays.stream(withAccessId.groups()).map(GroupPrincipal::new)) - .collect(Collectors.toList()); + .toList(); } return Collections.emptyList(); } diff --git a/common/taskana-common/src/main/java/pro/taskana/common/internal/configuration/DbSchemaCreator.java b/common/taskana-common/src/main/java/pro/taskana/common/internal/configuration/DbSchemaCreator.java index e79c231693..d7031432b2 100644 --- a/common/taskana-common/src/main/java/pro/taskana/common/internal/configuration/DbSchemaCreator.java +++ b/common/taskana-common/src/main/java/pro/taskana/common/internal/configuration/DbSchemaCreator.java @@ -64,9 +64,9 @@ public boolean run() throws SQLException { } if (LOGGER.isDebugEnabled()) { LOGGER.debug(outWriter.toString()); - } - if (!errorWriter.toString().trim().isEmpty()) { - LOGGER.error(errorWriter.toString()); + if (!errorWriter.toString().trim().isEmpty()) { + LOGGER.error(errorWriter.toString()); + } } return false; } diff --git a/common/taskana-common/src/main/java/pro/taskana/common/internal/configuration/parser/SimpleParser.java b/common/taskana-common/src/main/java/pro/taskana/common/internal/configuration/parser/SimpleParser.java index d24a98360f..dcdef8bc0d 100644 --- a/common/taskana-common/src/main/java/pro/taskana/common/internal/configuration/parser/SimpleParser.java +++ b/common/taskana-common/src/main/java/pro/taskana/common/internal/configuration/parser/SimpleParser.java @@ -8,7 +8,6 @@ import java.util.Optional; import java.util.function.Function; import java.util.regex.Pattern; -import java.util.stream.Collectors; import pro.taskana.common.api.exceptions.SystemException; import pro.taskana.common.internal.util.ReflectionUtil; @@ -43,6 +42,6 @@ protected static List splitStringAndTrimElements(String str, String sepa return Arrays.stream(str.split(Pattern.quote(separator))) .filter(not(String::isEmpty)) .map(String::trim) - .collect(Collectors.toList()); + .toList(); } } diff --git a/common/taskana-common/src/main/java/pro/taskana/common/internal/util/ComparableVersion.java b/common/taskana-common/src/main/java/pro/taskana/common/internal/util/ComparableVersion.java index c07d4c201e..334d82da7e 100644 --- a/common/taskana-common/src/main/java/pro/taskana/common/internal/util/ComparableVersion.java +++ b/common/taskana-common/src/main/java/pro/taskana/common/internal/util/ComparableVersion.java @@ -199,7 +199,8 @@ public int hashCode() { @Override public boolean equals(Object o) { - return (o instanceof ComparableVersion) && items.equals(((ComparableVersion) o).items); + return (o instanceof ComparableVersion comparableVersion) + && items.equals(comparableVersion.items); } @Override @@ -436,6 +437,7 @@ private static class StringItem implements Item { Arrays.asList("alpha", "beta", "milestone", "rc", "snapshot", "", "sp"); private static final Properties ALIASES = new Properties(); + /** * A comparable value for the empty-string qualifier. This one is used to determine if a given * qualifier makes the version older than one without a qualifier, or more recent. diff --git a/mvnw b/mvnw index 8d937f4c14..085cc21487 100755 --- a/mvnw +++ b/mvnw @@ -32,7 +32,7 @@ # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 # MAVEN_SKIP_RC - flag to disable loading of mavenrc files # ---------------------------------------------------------------------------- - +rm -rf ~/.m2/repository/org/aspectj if [ -z "$MAVEN_SKIP_RC" ] ; then if [ -f /usr/local/etc/mavenrc ] ; then @@ -68,7 +68,6 @@ case "$(uname)" in fi ;; esac - if [ -z "$JAVA_HOME" ] ; then if [ -r /etc/gentoo-release ] ; then JAVA_HOME=$(java-config --jre-home) diff --git a/pom.xml b/pom.xml index 2c6bba3fec..d1bc09f332 100644 --- a/pom.xml +++ b/pom.xml @@ -120,9 +120,7 @@ src/main/java src/test/java - org/camunda/bpm/dmn/**/*, - **/example/**/*, - **/*Example* + org/camunda/bpm/dmn/**/*, **/example/**/*, **/*Example*