From 09aa8da57dbda0c82c9fb25c4747cabb28b12f38 Mon Sep 17 00:00:00 2001 From: Konstantin Pavlov <1517853+kpavlov@users.noreply.github.com> Date: Mon, 28 Oct 2024 22:31:31 +0100 Subject: [PATCH] Create maven.yml (#63) * Create maven.yml * Update maven.yml * Update maven.yml * Update maven.yml * Update Maven plugin versions in pom.xml Upgraded various Maven plugins to their latest versions to improve compatibility and leverage new features. The plugins updated include maven-javadoc-plugin, maven-gpg-plugin, maven-release-plugin, maven-surefire-plugin, maven-failsafe-plugin, maven-deploy-plugin, and maven-jar-plugin. * Enhance type checking using instanceof pattern matching Replaced traditional instanceof checks with pattern matching in multiple classes to streamline and modernize type checks. Also updated the GitHub Actions workflow to use JDK 17 instead of JDK 11. These changes improve the readability and efficiency of the codebase. * Update Maven plugin and CI configuration Added the maven-compiler-plugin to pom.xml for better compatibility and upgraded the GitHub Actions workflow to use 'mvn verify'. Removed the now redundant Travis CI configuration file as the build process is fully managed by GitHub Actions. * Add JUnit report publishing and adjust formatting Implemented JUnit report publishing in the Maven workflow to improve test visibility. Adjusted YAML and editor configurations for better consistency and readability. * badge --------- Co-authored-by: Konstantin Pavlov --- .editorconfig | 4 ++ .github/workflows/maven-publish.yml | 30 +++++++-------- .github/workflows/maven.yml | 37 +++++++++++++++++++ .travis.yml | 10 ----- README.md | 2 +- .../fixprotocol/FixMessageBuilderImpl.java | 16 ++++---- .../fixio/fixprotocol/FixMessageImpl.java | 22 +++++------ .../fixio/handlers/FixApplicationAdapter.java | 12 +++--- .../fixio/netty/codec/FixMessageEncoder.java | 14 ++----- .../pipeline/AbstractSessionHandler.java | 11 ++---- .../netty/pipeline/TestRequestHandler.java | 4 +- .../codec/FixMessageDecoderSmokeTest.java | 3 +- pom.xml | 29 +++++++++------ 13 files changed, 108 insertions(+), 86 deletions(-) create mode 100644 .github/workflows/maven.yml delete mode 100644 .travis.yml diff --git a/.editorconfig b/.editorconfig index f2d5cf2..e26e976 100644 --- a/.editorconfig +++ b/.editorconfig @@ -16,6 +16,10 @@ ij_smart_tabs = false ij_visual_guides = ij_wrap_on_typing = false +[{*.yml,*.yaml}] +tab_width = 2 +indent_size = 2 + [*.java] ij_java_align_consecutive_assignments = false ij_java_align_consecutive_variable_declarations = false diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml index 954e6c8..397c1a2 100644 --- a/.github/workflows/maven-publish.yml +++ b/.github/workflows/maven-publish.yml @@ -5,7 +5,7 @@ name: Maven Package on: release: - types: [created] + types: [ created ] jobs: build: @@ -16,19 +16,19 @@ jobs: packages: write steps: - - uses: actions/checkout@v4 - - name: Set up JDK 11 - uses: actions/setup-java@v3 - with: - java-version: '11' - distribution: 'temurin' - server-id: github # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file + - uses: actions/checkout@v4 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + server-id: github # Value of the distributionManagement/repository/id field of the pom.xml + settings-path: ${{ github.workspace }} # location for the settings.xml file - - name: Build with Maven - run: mvn -B package --file pom.xml + - name: Build with Maven + run: mvn -B package --file pom.xml - - name: Publish to GitHub Packages Apache Maven - run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml - env: - GITHUB_TOKEN: ${{ github.token }} + - name: Publish to GitHub Packages Apache Maven + run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml + env: + GITHUB_TOKEN: ${{ github.token }} diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..bdd218e --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,37 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Java CI with Maven + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + - name: Build with Maven + run: mvn -B verify + + - name: Publish Test Report + uses: mikepenz/action-junit-report@v4 + if: success() || failure() + with: + report_paths: '**/TEST-*.xml' diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 13fbd75..0000000 --- a/.travis.yml +++ /dev/null @@ -1,10 +0,0 @@ -language: java -jdk: - - openjdk11 - - openjdk17 - - openjdk18 - -after_success: - - mvn javadoc:javadoc - - echo "ossrh\${env.OSSRH_USER}\${env.OSSRH_PASS}" > ~/settings.xml - - mvn deploy --settings ~/settings.xml diff --git a/README.md b/README.md index bf89c80..6e5986b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -fixio - FIX Protocol Support for Netty [![Build Status](https://travis-ci.org/kpavlov/fixio.png?branch=master)](https://travis-ci.org/kpavlov/fixio) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/7a6c7475813e44c5a96abe915ed60e73)](https://www.codacy.com/app/kpavlov/fixio?utm_source=github.com&utm_medium=referral&utm_content=kpavlov/fixio&utm_campaign=Badge_Grade) +fixio - FIX Protocol Support for Netty [![Java CI with Maven](https://github.com/kpavlov/fixio/actions/workflows/maven.yml/badge.svg)](https://github.com/kpavlov/fixio/actions/workflows/maven.yml) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/7a6c7475813e44c5a96abe915ed60e73)](https://www.codacy.com/app/kpavlov/fixio?utm_source=github.com&utm_medium=referral&utm_content=kpavlov/fixio&utm_campaign=Badge_Grade) ===== # Overview # diff --git a/core/src/main/java/fixio/fixprotocol/FixMessageBuilderImpl.java b/core/src/main/java/fixio/fixprotocol/FixMessageBuilderImpl.java index edc044b..347bb64 100644 --- a/core/src/main/java/fixio/fixprotocol/FixMessageBuilderImpl.java +++ b/core/src/main/java/fixio/fixprotocol/FixMessageBuilderImpl.java @@ -214,8 +214,8 @@ public String getString(int tagNum) { if (item == null) { return null; } - if (item instanceof StringField) { - return ((StringField) item).getValue(); + if (item instanceof StringField stringField) { + return stringField.getValue(); } else { throw new IllegalArgumentException("Tag " + tagNum + " is not a Field."); } @@ -253,8 +253,8 @@ public Character getChar(int tagNum) { if (field == null) { return null; } - if (field instanceof CharField) { - return ((CharField) field).getValue(); + if (field instanceof CharField charField) { + return charField.getValue(); } else { throw new IllegalArgumentException("Tag " + tagNum + " is not a Field."); } @@ -263,8 +263,8 @@ public Character getChar(int tagNum) { @Override public Integer getInt(int tagNum) { FixMessageFragment field = getFirst(tagNum); - if (field instanceof IntField) { - return ((IntField) field).getValue(); + if (field instanceof IntField intField) { + return intField.getValue(); } return null; } @@ -319,8 +319,8 @@ public void setMessageType(String messageType) { public List getGroups(int tagNum) { FixMessageFragment fragment = getFirst(tagNum); - if (fragment instanceof GroupField) { - return ((GroupField) fragment).getGroups(); + if (fragment instanceof GroupField groupField) { + return groupField.getGroups(); } return null; } diff --git a/core/src/main/java/fixio/fixprotocol/FixMessageImpl.java b/core/src/main/java/fixio/fixprotocol/FixMessageImpl.java index eae1b68..07296ad 100644 --- a/core/src/main/java/fixio/fixprotocol/FixMessageImpl.java +++ b/core/src/main/java/fixio/fixprotocol/FixMessageImpl.java @@ -16,11 +16,7 @@ package fixio.fixprotocol; -import fixio.fixprotocol.fields.AbstractField; -import fixio.fixprotocol.fields.CharField; -import fixio.fixprotocol.fields.FieldFactory; -import fixio.fixprotocol.fields.IntField; -import fixio.fixprotocol.fields.StringField; +import fixio.fixprotocol.fields.*; import java.util.ArrayList; import java.util.List; @@ -91,8 +87,8 @@ public String getString(int tagNum) { if (item == null) { return null; } - if (item instanceof StringField) { - return ((StringField) item).getValue(); + if (item instanceof StringField stringField) { + return stringField.getValue(); } else { throw new IllegalArgumentException("Tag " + tagNum + " is not a Field."); } @@ -130,8 +126,8 @@ public Character getChar(int tagNum) { if (field == null) { return null; } - if (field instanceof CharField) { - return ((CharField) field).getValue(); + if (field instanceof CharField charField) { + return charField.getValue(); } else { throw new IllegalArgumentException("Tag " + tagNum + " is not a Field."); } @@ -140,8 +136,8 @@ public Character getChar(int tagNum) { @Override public Integer getInt(int tagNum) { FixMessageFragment field = getFirst(tagNum); - if (field instanceof IntField) { - return ((IntField) field).getValue(); + if (field instanceof IntField intField) { + return intField.getValue(); } return null; } @@ -175,8 +171,8 @@ public int getChecksum() { public List getGroups(int tagNum) { FixMessageFragment fragment = getFirst(tagNum); - if (fragment instanceof GroupField) { - return ((GroupField) fragment).getGroups(); + if (fragment instanceof GroupField groupField) { + return groupField.getGroups(); } return null; } diff --git a/core/src/main/java/fixio/handlers/FixApplicationAdapter.java b/core/src/main/java/fixio/handlers/FixApplicationAdapter.java index 3b0fb82..cdd8dc5 100644 --- a/core/src/main/java/fixio/handlers/FixApplicationAdapter.java +++ b/core/src/main/java/fixio/handlers/FixApplicationAdapter.java @@ -37,12 +37,12 @@ public class FixApplicationAdapter extends MessageToMessageDecoder imple @Override protected void decode(ChannelHandlerContext ctx, Object msg, List out) throws Exception { try { - if (msg instanceof FixMessage) { - onMessage(ctx, (FixMessage) msg, out); - } else if (msg instanceof LogonEvent) { - onLogon(ctx, (LogonEvent) msg); - } else if (msg instanceof LogoutEvent) { - onLogout(ctx, (LogoutEvent) msg); + if (msg instanceof FixMessage message) { + onMessage(ctx, message, out); + } else if (msg instanceof LogonEvent event) { + onLogon(ctx, event); + } else if (msg instanceof LogoutEvent event) { + onLogout(ctx, event); } } finally { ReferenceCountUtil.release(msg); diff --git a/core/src/main/java/fixio/netty/codec/FixMessageEncoder.java b/core/src/main/java/fixio/netty/codec/FixMessageEncoder.java index fd67fc5..313f04e 100644 --- a/core/src/main/java/fixio/netty/codec/FixMessageEncoder.java +++ b/core/src/main/java/fixio/netty/codec/FixMessageEncoder.java @@ -16,12 +16,7 @@ package fixio.netty.codec; -import fixio.fixprotocol.FixConst; -import fixio.fixprotocol.FixMessageBuilder; -import fixio.fixprotocol.FixMessageFragment; -import fixio.fixprotocol.FixMessageHeader; -import fixio.fixprotocol.Group; -import fixio.fixprotocol.GroupField; +import fixio.fixprotocol.*; import fixio.fixprotocol.fields.AbstractField; import fixio.fixprotocol.fields.DateTimeFormatterWrapper; import io.netty.buffer.ByteBuf; @@ -137,10 +132,9 @@ private static int fillBodyBuf(final ByteBuf payloadBuf, private static void encodeMessageFragment(ByteBuf payloadBuf, FixMessageFragment messageFragment) { - if (messageFragment instanceof AbstractField) { - writeField(messageFragment.getTagNum(), (AbstractField) messageFragment, payloadBuf); - } else if (messageFragment instanceof GroupField) { - GroupField groupField = (GroupField) messageFragment; + if (messageFragment instanceof AbstractField field) { + writeField(messageFragment.getTagNum(), field, payloadBuf); + } else if (messageFragment instanceof GroupField groupField) { writeField(groupField.getTagNum(), Integer.toString(groupField.getGroupCount()), payloadBuf); for (Group c : groupField.getValue()) { List contents = c.getContents(); diff --git a/core/src/main/java/fixio/netty/pipeline/AbstractSessionHandler.java b/core/src/main/java/fixio/netty/pipeline/AbstractSessionHandler.java index b43c187..9a77c2f 100644 --- a/core/src/main/java/fixio/netty/pipeline/AbstractSessionHandler.java +++ b/core/src/main/java/fixio/netty/pipeline/AbstractSessionHandler.java @@ -17,12 +17,7 @@ package fixio.netty.pipeline; import fixio.events.LogoutEvent; -import fixio.fixprotocol.FieldType; -import fixio.fixprotocol.FixMessage; -import fixio.fixprotocol.FixMessageBuilder; -import fixio.fixprotocol.FixMessageBuilderImpl; -import fixio.fixprotocol.FixMessageHeader; -import fixio.fixprotocol.MessageTypes; +import fixio.fixprotocol.*; import fixio.fixprotocol.session.FixSession; import fixio.handlers.FixApplication; import fixio.validator.BusinessRejectException; @@ -141,8 +136,8 @@ protected void decode(ChannelHandlerContext ctx, FixMessage msg, List ou @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - if (cause instanceof BusinessRejectException) { - FixMessageBuilderImpl businessMessageReject = createBusinessReject((BusinessRejectException) cause); + if (cause instanceof BusinessRejectException exception) { + FixMessageBuilderImpl businessMessageReject = createBusinessReject(exception); ctx.channel().writeAndFlush(businessMessageReject); } else { super.exceptionCaught(ctx, cause); diff --git a/core/src/main/java/fixio/netty/pipeline/TestRequestHandler.java b/core/src/main/java/fixio/netty/pipeline/TestRequestHandler.java index eda72ac..fb71759 100644 --- a/core/src/main/java/fixio/netty/pipeline/TestRequestHandler.java +++ b/core/src/main/java/fixio/netty/pipeline/TestRequestHandler.java @@ -36,8 +36,8 @@ public class TestRequestHandler extends MessageToMessageDecoder { public boolean acceptInboundMessage(Object msg) { - return (msg instanceof FixMessage - && MessageTypes.TEST_REQUEST.equals(((FixMessage) msg).getMessageType())); + return (msg instanceof FixMessage fm + && MessageTypes.TEST_REQUEST.equals(fm.getMessageType())); } @Override diff --git a/core/src/test/java/fixio/netty/codec/FixMessageDecoderSmokeTest.java b/core/src/test/java/fixio/netty/codec/FixMessageDecoderSmokeTest.java index 3646eb9..1f493e3 100644 --- a/core/src/test/java/fixio/netty/codec/FixMessageDecoderSmokeTest.java +++ b/core/src/test/java/fixio/netty/codec/FixMessageDecoderSmokeTest.java @@ -10,7 +10,6 @@ import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Objects; import static fixio.netty.codec.DecodingTestHelper.decodeOne; @@ -28,7 +27,7 @@ public FixMessageDecoderSmokeTest(String message) { @Parameterized.Parameters(name = "msg: {0}") public static Object[] data() throws IOException, URISyntaxException { - Path path = Paths.get(Objects.requireNonNull(FixMessageDecoderSmokeTest.class.getClassLoader() + Path path = Path.of(Objects.requireNonNull(FixMessageDecoderSmokeTest.class.getClassLoader() .getResource("example-messages.txt")).toURI()); return Files.lines(path) diff --git a/pom.xml b/pom.xml index 2036b31..9f50ef3 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,8 @@ ~ License for the specific language governing permissions and limitations ~ under the License. --> - + 4.0.0 com.github.kpavlov.fixio @@ -45,9 +46,9 @@ ${java.version} UTF-8 - 3.1.0 + 3.1.0 3.13.2 - 8.5.15 + 8.5.15 4.1.114.Final 1.7.36 @@ -97,7 +98,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.1.1 + 3.7.0 attach-javadocs @@ -110,7 +111,7 @@ org.apache.maven.plugins maven-gpg-plugin - 1.6 + 3.2.3 sign-artifacts @@ -128,7 +129,8 @@ - + + org.sonatype.plugins nexus-staging-maven-plugin 1.7.0 @@ -142,7 +144,7 @@ org.apache.maven.plugins maven-release-plugin - 2.5.3 + 3.1.1 true false @@ -155,15 +157,20 @@ + + org.apache.maven.plugins + maven-compiler-plugin + 3.13.0 + org.apache.maven.plugins maven-surefire-plugin - 2.22.2 + 3.5.1 org.apache.maven.plugins maven-failsafe-plugin - 2.22.2 + 3.5.1 maven-javadoc-plugin @@ -194,11 +201,11 @@ maven-deploy-plugin - 2.8.2 + 3.1.3 maven-jar-plugin - 3.4.2 + 3.4.1 maven-resources-plugin