Skip to content

feat(ci): add MegaLinter GitHub Action for Java projects #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
---
name: Build and Test

on:
push:
branches: [ "main" ]
branches:
- "main"
pull_request:
branches: [ "main" ]
branches:
- "main"

permissions:
contents: read
actions: none

jobs:
build:
Expand All @@ -14,8 +21,8 @@ jobs:
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'corretto'
java-version: "21"
distribution: "corretto"
cache: maven
- name: Build all modules
run: mvn -B package
Expand Down
48 changes: 48 additions & 0 deletions .github/workflows/mega-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
# MegaLinter GitHub Action configuration file
# More info at https://megalinter.io/latest/install-github/
name: MegaLinter

permissions: read-all

on:
push:
branches:
- main
pull_request:

concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true

jobs:
megalinter:
name: MegaLinter
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: "21"
distribution: "corretto"

- name: MegaLinter
uses: oxsecurity/megalinter/flavors/[email protected]
env:
VALIDATE_ALL_CODEBASE: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Archive production artifacts
if: success() || failure()
uses: actions/upload-artifact@v4
with:
name: MegaLinter reports
path: |
megalinter-reports
mega-linter.log
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ JEP*/.idea/
*.iml
*/target/

target
target

megalinter-reports
2 changes: 2 additions & 0 deletions .lycheeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
http://localhost
http://localhost/*
7 changes: 7 additions & 0 deletions .markdown-link-check.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"ignorePatterns": [
{
"pattern": "^http://localhost"
}
]
}
6 changes: 6 additions & 0 deletions .mega-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
DISABLE_LINTERS:
- COPYPASTE_JSCPD
- JAVA_CHECKSTYLE
- JAVA_PMD
- SPELL_CSPELL
20 changes: 10 additions & 10 deletions JEP431/src/main/java/com/jep/JEP431.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ public static void main( String[] args ) {
orderedSet.addLast("two");
orderedSet.addLast("three");

System.out.println(STR."Original set: \{orderedSet}");
System.out.println(STR."First element: \{orderedSet.getFirst()}");
System.out.println(STR."Last element: \{orderedSet.getLast()}");
System.out.println("Original set: " + orderedSet);
System.out.println("First element: " + orderedSet.getFirst());
System.out.println("Last element: " + orderedSet.getLast());

// Reverse the order of the set
System.out.println(STR."Reversed set: \{orderedSet.reversed()}");
System.out.println("Reversed set: " + orderedSet.reversed());

// Move an existing element to the first position
orderedSet.addFirst("two");
System.out.println(STR."Set with 'two' moved to the first position: \{orderedSet}");
System.out.println("Set with 'two' moved to the first position: " + orderedSet);

// Example with SequencedSet using LinkedHashMap
SequencedMap<String, Integer> orderedMap = new LinkedHashMap<>();
Expand All @@ -55,15 +55,15 @@ public static void main( String[] args ) {
orderedMap.putLast("two", 2);
orderedMap.putLast("three", 3);

System.out.println(STR."Original map: \{orderedMap}");
System.out.println(STR."First entry: \{orderedMap.firstEntry()}");
System.out.println(STR."Last entry: \{orderedMap.lastEntry()}");
System.out.println("Original map: " + orderedMap);
System.out.println("First entry: " + orderedMap.firstEntry());
System.out.println("Last entry: " + orderedMap.lastEntry());

// Reverse the order of the map
System.out.println(STR."Reversed map: \{orderedMap.reversed()}");
System.out.println("Reversed map: " + orderedMap.reversed());

// Move an existing entry to the first position
orderedMap.putFirst("two", 2);
System.out.println(STR."Map with 'two' moved to the first position: \{orderedMap}");
System.out.println("Map with 'two' moved to the first position: " + orderedMap);
}
}
2 changes: 0 additions & 2 deletions JEP444/JEP_444/src/main/java/com/jep/PlatformThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import static com.jep.SimulatedIOTask.execute;

/**
* Demonstrates the use of traditional Platform Threads for comparison with Virtual Threads.
*
Expand Down
13 changes: 7 additions & 6 deletions JEP444/VirtualThreadExample/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

## Overview

This project compares the performance of platform threads and virtual threads in Java for making concurrent API requests to a locally hosted PokeAPI instance.
This project compares the performance of platform threads and virtual threads in Java for making concurrent API
requests to a locally hosted PokeAPI instance.

## Setup

- **API**: Locally hosted PokeAPI (http://localhost/api/v2/pokemon/)
- **API**: Locally hosted PokeAPI (<http://localhost/api/v2/pokemon/>)
- **Number of Requests**: 1025
- **Java Version**: Java 21 (for virtual thread support)

Expand All @@ -27,10 +28,10 @@ For detailed setup instructions and troubleshooting, refer to the [official Poke

## Results

| Thread Type | Execution Time |
|-------------|----------------|
| Platform Threads | 1403 ms |
| Virtual Threads | 1017 ms |
| Thread Type | Execution Time |
|------------------|----------------|
| Platform Threads | 1403 ms |
| Virtual Threads | 1017 ms |

Virtual threads showed a performance improvement of approximately 27.5% compared to platform threads.

Expand Down
2 changes: 1 addition & 1 deletion JEP444/VirtualThreadExample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.0</version>
<version>2.18.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public static void main(String[] args) {

executorService.shutdown();
long end = System.currentTimeMillis();
long durationTime = end - start;

LOGGER.info(STR."Time taken: \{end - start}ms");
LOGGER.info(String.format("Time taken: %dms", durationTime));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public static void fetchPokemon(int pokemonId) {

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

LOGGER.info(STR."Fetched Pokemon \{pokemonId}: \{response.body()}");
LOGGER.info(String.format("Fetched Pokemon %s: %s", pokemonId, response.body()));
} catch (Exception e) {
LOGGER.severe(STR."Error fetching Pokemon: \{pokemonId}");
LOGGER.severe(String.format("Error fetching Pokemon: %s", pokemonId));
e.printStackTrace();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static void main( String[] args ) {
}

long endTime = System.currentTimeMillis();
LOGGER.info(STR."Total execution time: \{endTime - startTime} milliseconds");
long durationTime = endTime - startTime;
LOGGER.info(String.format("Total execution time: %d milliseconds", durationTime));
}
}
Loading