Skip to content

Commit

Permalink
upgrade to java 21 (#199)
Browse files Browse the repository at this point in the history
* Create maven.yml

upgrade github actions

* adding sonar analysis to action

* upgrade google formatter for java 21

* update formatting for google formatter

* [issue #197] - upgrade to java 21
  • Loading branch information
finnyb authored Apr 14, 2024
1 parent 7c6a072 commit 53c73ac
Show file tree
Hide file tree
Showing 30 changed files with 250 additions and 217 deletions.
36 changes: 0 additions & 36 deletions .github/workflows/build.yml

This file was deleted.

46 changes: 46 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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: [ "develop" ]
pull_request:
branches: [ "develop" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'corretto'
cache: maven

- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Build and Analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar

# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
- name: Update dependency graph
uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6
7 changes: 3 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
</repository>
</distributionManagement>
<properties>
<java.version>17</java.version>
<java.version>21</java.version>
<logback.version>1.5.4</logback.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
Expand Down Expand Up @@ -91,8 +91,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<release>${java.version}</release>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -201,7 +200,7 @@
</formats>
<java>
<googleJavaFormat>
<version>1.15.0</version>
<version>1.22.0</version>
<reflowLongStrings>true</reflowLongStrings>
</googleJavaFormat>
</java>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/bff/javampd/command/CommandExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
public interface CommandExecutor {
String COMMAND_TERMINATION = "OK";

/**
* Sends a command with no parameters to the {@link org.bff.javampd.server.MPD} server returning
* the response as a <CODE>List</CODE> of <CODE>Strings</CODE>.
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/bff/javampd/admin/MPDAdminTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void getSingleOutput() {
when(adminProperties.getOutputs()).thenReturn(realAdminProperties.getOutputs());
when(commandExecutor.sendCommand("outputs")).thenReturn(getOutputSingleResponse());

var output1 = new ArrayList<>(admin.getOutputs()).get(0);
var output1 = new ArrayList<>(admin.getOutputs()).getFirst();

assertAll(
() -> assertThat(output1.getName(), is(equalTo("My ALSA Device"))),
Expand All @@ -64,7 +64,7 @@ void getOutputs() {
when(commandExecutor.sendCommand("outputs")).thenReturn(getOutputMultipleResponse());

var outputs = admin.getOutputs();
var output1 = new ArrayList<>(outputs).get(0);
var output1 = new ArrayList<>(outputs).getFirst();
var output2 = new ArrayList<>(outputs).get(1);

assertAll(
Expand All @@ -82,7 +82,7 @@ void disableOutput() {
when(commandExecutor.sendCommand("outputs")).thenReturn(getOutputMultipleResponse());
when(adminProperties.getOutputDisable()).thenReturn(realAdminProperties.getOutputDisable());

MPDOutput output = new ArrayList<>(admin.getOutputs()).get(0);
MPDOutput output = new ArrayList<>(admin.getOutputs()).getFirst();
admin.disableOutput(output);
verify(commandExecutor)
.sendCommand(commandArgumentCaptor.capture(), integerParamArgumentCaptor.capture());
Expand All @@ -96,7 +96,7 @@ void enableOutput() {
when(commandExecutor.sendCommand("outputs")).thenReturn(getOutputMultipleResponse());
when(adminProperties.getOutputEnable()).thenReturn(realAdminProperties.getOutputEnable());

MPDOutput output = new ArrayList<>(admin.getOutputs()).get(0);
MPDOutput output = new ArrayList<>(admin.getOutputs()).getFirst();
admin.enableOutput(output);
verify(commandExecutor)
.sendCommand(commandArgumentCaptor.capture(), integerParamArgumentCaptor.capture());
Expand Down
26 changes: 13 additions & 13 deletions src/test/java/org/bff/javampd/album/MPDAlbumConverterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ void simpleAlbum() {
"Album: Anthem of the Peaceful Army");

var albums = new ArrayList<>(converter.convertResponseToAlbum(response));
var a = albums.get(0);
var a = albums.getFirst();

assertAll(
() -> assertThat(a.getName(), is(equalTo("Anthem of the Peaceful Army"))),
() -> assertThat(albums.size(), is(equalTo(1))),
() -> assertThat(a.getAlbumArtist(), is(equalTo("Greta Van Fleet"))),
() -> assertThat(a.getArtistNames().size(), is(equalTo(1))),
() -> assertThat(a.getArtistNames().get(0), is(equalTo("Greta Van Fleet"))),
() -> assertThat(a.getArtistNames().getFirst(), is(equalTo("Greta Van Fleet"))),
() -> assertThat(a.getGenres().size(), is(equalTo(1))),
() -> assertThat(a.getGenres().get(0), is(equalTo("Rock"))),
() -> assertThat(a.getGenres().getFirst(), is(equalTo("Rock"))),
() -> assertThat(a.getDates().size(), is(equalTo(1))),
() -> assertThat(a.getDates().get(0), is(equalTo("2018"))));
() -> assertThat(a.getDates().getFirst(), is(equalTo("2018"))));
}

@Test
Expand All @@ -62,18 +62,18 @@ void unknownAttribute() {
"Album: Anthem of the Peaceful Army");

var albums = new ArrayList<>(converter.convertResponseToAlbum(response));
var a = albums.get(0);
var a = albums.getFirst();

assertAll(
() -> assertThat(a.getName(), is(equalTo("Anthem of the Peaceful Army"))),
() -> assertThat(albums.size(), is(equalTo(1))),
() -> assertThat(a.getAlbumArtist(), is(equalTo("Greta Van Fleet"))),
() -> assertThat(a.getArtistNames().size(), is(equalTo(1))),
() -> assertThat(a.getArtistNames().get(0), is(equalTo("Greta Van Fleet"))),
() -> assertThat(a.getArtistNames().getFirst(), is(equalTo("Greta Van Fleet"))),
() -> assertThat(a.getGenres().size(), is(equalTo(1))),
() -> assertThat(a.getGenres().get(0), is(equalTo("Rock"))),
() -> assertThat(a.getGenres().getFirst(), is(equalTo("Rock"))),
() -> assertThat(a.getDates().size(), is(equalTo(1))),
() -> assertThat(a.getDates().get(0), is(equalTo("2018"))));
() -> assertThat(a.getDates().getFirst(), is(equalTo("2018"))));
}

@Test
Expand All @@ -95,7 +95,7 @@ void clearAttributes() {
() -> assertThat(a.getName(), is(equalTo("Lateralus"))),
() -> assertNull(a.getAlbumArtist()),
() -> assertThat(a.getArtistNames().size(), is(equalTo(1))),
() -> assertThat(a.getArtistNames().get(0), is(equalTo("Tool"))),
() -> assertThat(a.getArtistNames().getFirst(), is(equalTo("Tool"))),
() -> assertThat(a.getGenres().size(), is(equalTo(0))),
() -> assertThat(a.getDates().size(), is(equalTo(0))));
}
Expand All @@ -113,18 +113,18 @@ void multipleArtists() {
"Album: Eternal Blue");

var albums = new ArrayList<>(converter.convertResponseToAlbum(response));
var a = albums.get(0);
var a = albums.getFirst();

assertAll(
() -> assertThat(albums.size(), is(equalTo(1))),
() -> assertThat(a.getName(), is(equalTo("Eternal Blue"))),
() -> assertThat(a.getAlbumArtist(), is(equalTo("Spiritbox"))),
() -> assertThat(a.getArtistNames().size(), is(equalTo(2))),
() -> assertThat(a.getArtistNames().get(0), is(equalTo("Spiritbox"))),
() -> assertThat(a.getArtistNames().getFirst(), is(equalTo("Spiritbox"))),
() -> assertThat(a.getArtistNames().get(1), is(equalTo("Spiritbox feat. Sam Carter"))),
() -> assertThat(a.getGenres().size(), is(equalTo(1))),
() -> assertThat(a.getGenres().get(0), is(equalTo("Metal"))),
() -> assertThat(a.getGenres().getFirst(), is(equalTo("Metal"))),
() -> assertThat(a.getDates().size(), is(equalTo(1))),
() -> assertThat(a.getDates().get(0), is(equalTo("2021"))));
() -> assertThat(a.getDates().getFirst(), is(equalTo("2021"))));
}
}
24 changes: 12 additions & 12 deletions src/test/java/org/bff/javampd/album/MPDAlbumDatabaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ void albumsByAlbumArtist() {
groupCaptor.capture());

assertAll(
() -> assertEquals("albumartist", argumentCaptor.getValue().get(0)),
() -> assertEquals("albumartist", argumentCaptor.getValue().getFirst()),
() -> assertEquals(albumArtist, argumentCaptor.getValue().get(1)),
() -> assertEquals(TagLister.GroupType.ARTIST, groupCaptor.getAllValues().get(0)),
() -> assertEquals(TagLister.GroupType.ARTIST, groupCaptor.getAllValues().getFirst()),
() -> assertEquals(TagLister.GroupType.DATE, groupCaptor.getAllValues().get(1)),
() -> assertEquals(TagLister.GroupType.GENRE, groupCaptor.getAllValues().get(2)),
() -> assertEquals(TagLister.GroupType.ALBUM_ARTIST, groupCaptor.getAllValues().get(3)));
Expand All @@ -80,9 +80,9 @@ void albumsByArtist() {
groupCaptor.capture());

assertAll(
() -> assertEquals("artist", argumentCaptor.getValue().get(0)),
() -> assertEquals("artist", argumentCaptor.getValue().getFirst()),
() -> assertEquals(artist, argumentCaptor.getValue().get(1)),
() -> assertEquals(TagLister.GroupType.ARTIST, groupCaptor.getAllValues().get(0)),
() -> assertEquals(TagLister.GroupType.ARTIST, groupCaptor.getAllValues().getFirst()),
() -> assertEquals(TagLister.GroupType.DATE, groupCaptor.getAllValues().get(1)),
() -> assertEquals(TagLister.GroupType.GENRE, groupCaptor.getAllValues().get(2)),
() -> assertEquals(TagLister.GroupType.ALBUM_ARTIST, groupCaptor.getAllValues().get(3)));
Expand All @@ -105,7 +105,7 @@ void allAlbums() {

assertAll(
() -> assertEquals(TagLister.ListType.ALBUM, listCaptor.getValue()),
() -> assertEquals(TagLister.GroupType.ARTIST, groupCaptor.getAllValues().get(0)),
() -> assertEquals(TagLister.GroupType.ARTIST, groupCaptor.getAllValues().getFirst()),
() -> assertEquals(TagLister.GroupType.DATE, groupCaptor.getAllValues().get(1)),
() -> assertEquals(TagLister.GroupType.GENRE, groupCaptor.getAllValues().get(2)),
() -> assertEquals(TagLister.GroupType.ALBUM_ARTIST, groupCaptor.getAllValues().get(3)));
Expand Down Expand Up @@ -135,7 +135,7 @@ void allAlbumNamesParsing() {
var albums = new ArrayList<>(albumDatabase.listAllAlbumNames());

assertAll(
() -> assertEquals("10,000 Days", albums.get(0)),
() -> assertEquals("10,000 Days", albums.getFirst()),
() -> assertEquals("72826", albums.get(1)),
() -> assertEquals("Anthem of the Peaceful Army", albums.get(2)),
() -> assertEquals("Dark Before Dawn", albums.get(3)));
Expand All @@ -160,9 +160,9 @@ void findAlbumsByName() {
groupCaptor.capture());

assertAll(
() -> assertEquals("album", argumentCaptor.getValue().get(0)),
() -> assertEquals("album", argumentCaptor.getValue().getFirst()),
() -> assertEquals(album, argumentCaptor.getValue().get(1)),
() -> assertEquals(TagLister.GroupType.ARTIST, groupCaptor.getAllValues().get(0)),
() -> assertEquals(TagLister.GroupType.ARTIST, groupCaptor.getAllValues().getFirst()),
() -> assertEquals(TagLister.GroupType.DATE, groupCaptor.getAllValues().get(1)),
() -> assertEquals(TagLister.GroupType.GENRE, groupCaptor.getAllValues().get(2)),
() -> assertEquals(TagLister.GroupType.ALBUM_ARTIST, groupCaptor.getAllValues().get(3)));
Expand All @@ -187,9 +187,9 @@ void albumsByGenre() {
groupCaptor.capture());

assertAll(
() -> assertEquals("genre", argumentCaptor.getValue().get(0)),
() -> assertEquals("genre", argumentCaptor.getValue().getFirst()),
() -> assertEquals(genre, argumentCaptor.getValue().get(1)),
() -> assertEquals(TagLister.GroupType.ARTIST, groupCaptor.getAllValues().get(0)),
() -> assertEquals(TagLister.GroupType.ARTIST, groupCaptor.getAllValues().getFirst()),
() -> assertEquals(TagLister.GroupType.DATE, groupCaptor.getAllValues().get(1)),
() -> assertEquals(TagLister.GroupType.GENRE, groupCaptor.getAllValues().get(2)),
() -> assertEquals(TagLister.GroupType.ALBUM_ARTIST, groupCaptor.getAllValues().get(3)));
Expand All @@ -214,9 +214,9 @@ void albumsByYear() {
groupCaptor.capture());

assertAll(
() -> assertEquals("date", argumentCaptor.getValue().get(0)),
() -> assertEquals("date", argumentCaptor.getValue().getFirst()),
() -> assertEquals(year, argumentCaptor.getValue().get(1)),
() -> assertEquals(TagLister.GroupType.ARTIST, groupCaptor.getAllValues().get(0)),
() -> assertEquals(TagLister.GroupType.ARTIST, groupCaptor.getAllValues().getFirst()),
() -> assertEquals(TagLister.GroupType.DATE, groupCaptor.getAllValues().get(1)),
() -> assertEquals(TagLister.GroupType.GENRE, groupCaptor.getAllValues().get(2)),
() -> assertEquals(TagLister.GroupType.ALBUM_ARTIST, groupCaptor.getAllValues().get(3)));
Expand Down
14 changes: 7 additions & 7 deletions src/test/java/org/bff/javampd/album/MPDAlbumTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ void defaultArtistList() {
var artist = "Greta Van Fleet";
var album = MPDAlbum.builder("Anthem of the Peaceful Army").build();
album.addArtist(artist);
assertThat(artist, is(equalTo(album.getArtistNames().get(0))));
assertThat(artist, is(equalTo(album.getArtistNames().getFirst())));
}

@Test
void addArtist() {
var album = MPDAlbum.builder("album").build();
album.addArtist("Tool");
assertThat("Tool", is(equalTo(album.getArtistNames().get(0))));
assertThat("Tool", is(equalTo(album.getArtistNames().getFirst())));
}

@Test
Expand All @@ -38,15 +38,15 @@ void addArtists() {

assertAll(
() -> assertThat(2, is(equalTo(album.getArtistNames().size()))),
() -> assertThat("Tool", is(equalTo(album.getArtistNames().get(0)))),
() -> assertThat("Tool", is(equalTo(album.getArtistNames().getFirst()))),
() -> assertThat("Breaking Benjamin", is(equalTo(album.getArtistNames().get(1)))));
}

@Test
void addGenre() {
var album = MPDAlbum.builder("album").build();
album.addGenre("Rock");
assertThat("Rock", is(equalTo(album.getGenres().get(0))));
assertThat("Rock", is(equalTo(album.getGenres().getFirst())));
}

@Test
Expand All @@ -56,15 +56,15 @@ void addGenres() {

assertAll(
() -> assertThat(2, is(equalTo(album.getGenres().size()))),
() -> assertThat("Rock", is(equalTo(album.getGenres().get(0)))),
() -> assertThat("Rock", is(equalTo(album.getGenres().getFirst()))),
() -> assertThat("Heavy Metal", is(equalTo(album.getGenres().get(1)))));
}

@Test
void addDate() {
var album = MPDAlbum.builder("album").build();
album.addDate("1990");
assertThat("1990", is(equalTo(album.getDates().get(0))));
assertThat("1990", is(equalTo(album.getDates().getFirst())));
}

@Test
Expand All @@ -74,7 +74,7 @@ void addDates() {

assertAll(
() -> assertThat(2, is(equalTo(album.getDates().size()))),
() -> assertThat("1990", is(equalTo(album.getDates().get(0)))),
() -> assertThat("1990", is(equalTo(album.getDates().getFirst()))),
() -> assertThat("2006-05-24", is(equalTo(album.getDates().get(1)))));
}

Expand Down
Loading

0 comments on commit 53c73ac

Please sign in to comment.