Skip to content
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

upgrade to java 22 #1071

Draft
wants to merge 14 commits into
base: develop
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .github/workflows/basic-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Basic checks
on: [pull_request]

env:
JAVA_VERSION: 21
JAVA_VERSION: 22

jobs:
spotless:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/code-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- cron: '0 20 * * 4'

env:
JAVA_VERSION: 21
JAVA_VERSION: 22

jobs:
sonar:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- 'master'

env:
JAVA_VERSION: 21
JAVA_VERSION: 22

jobs:
docker:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-verify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Docker Verify
on: [pull_request]

env:
JAVA_VERSION: 21
JAVA_VERSION: 22

jobs:
docker:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/releases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defaults:
shell: bash

env:
JAVA_VERSION: 21
JAVA_VERSION: 22

jobs:

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# TJ-Bot

[![codefactor](https://img.shields.io/codefactor/grade/github/together-java/tj-bot)](https://www.codefactor.io/repository/github/together-java/tj-bot)
![Java](https://img.shields.io/badge/Java-21-ff696c)
![Java](https://img.shields.io/badge/Java-22-ff696c)
[![license](https://img.shields.io/github/license/Together-Java/TJ-Bot)](https://github.com/Together-Java/TJ-Bot/blob/master/LICENSE)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/Together-Java/TJ-Bot?label=release)

Expand Down
4 changes: 2 additions & 2 deletions application/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repositories {
var outputImage = 'togetherjava.org:5001/togetherjava/tjbot:' + System.getenv('BRANCH_NAME') ?: 'latest'

jib {
from.image = 'eclipse-temurin:21'
from.image = 'eclipse-temurin:22'
to {
image = outputImage
auth {
Expand Down Expand Up @@ -46,7 +46,7 @@ dependencies {
implementation project(':utils')
implementation project(':formatter')

implementation 'net.dv8tion:JDA:5.0.0-beta.21'
implementation 'net.dv8tion:JDA:5.1.0'

implementation 'org.apache.logging.log4j:log4j-core:2.23.0'
runtimeOnly 'org.apache.logging.log4j:log4j-slf4j18-impl:2.18.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public void onMessageUpdated(MessageUpdateEvent event) {

// Re-apply the current action
return codeReplyMessage.editMessageEmbeds(maybeCodeAction.orElseThrow().apply(code));
}).queue(any -> {
}).queue(_ -> {
}, failure -> logger.warn(
"Attempted to update a code-reply-message ({}), but failed. The original code-message was {}",
codeReplyMessageId, originalMessageId, failure));
Expand Down Expand Up @@ -253,7 +253,7 @@ public void onMessageDeleted(MessageDeleteEvent event) {
// Delete the code reply as well
originalMessageToCodeReply.invalidate(originalMessageId);

event.getChannel().deleteMessageById(codeReplyMessageId).queue(any -> {
event.getChannel().deleteMessageById(codeReplyMessageId).queue(_ -> {
}, failure -> logger.warn(
"Attempted to delete a code-reply-message ({}), but failed. The original code-message was {}",
codeReplyMessageId, originalMessageId, failure));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ Optional<GHIssue> findIssue(int id, String targetIssueTitle) {
if (issue.getTitle().equals(targetIssueTitle)) {
return Optional.of(issue);
}
} catch (FileNotFoundException ignored) {
} catch (FileNotFoundException _) {
return Optional.<GHIssue>empty();
} catch (IOException ex) {
throw new UncheckedIOException(ex);
Expand All @@ -255,7 +255,7 @@ Optional<GHIssue> findIssue(int id, long defaultRepoId) {
issue = repository.getPullRequest(id);
}
return Optional.of(issue);
} catch (FileNotFoundException ignored) {
} catch (FileNotFoundException _) {
return Optional.<GHIssue>empty();
} catch (IOException ex) {
throw new UncheckedIOException(ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void onGuildMemberRemove(GuildMemberRemoveEvent event) {
.filter(thread -> thread.getOwnerIdLong() == event.getUser().getIdLong())
.filter(thread -> thread.getParentChannel().getName().matches(helpForumPattern))
.forEach(thread -> thread.sendMessageEmbeds(embed)
.flatMap(any -> thread.getManager().setArchived(true))
.flatMap(_ -> thread.getManager().setArchived(true))
.queue()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ RestAction<Message> constructChatGptAttempt(ThreadChannel threadChannel,
}

MessageEmbed responseEmbed = generateGptResponseEmbed(answer, selfUser, originalQuestion);
return message.flatMap(any -> threadChannel.sendMessageEmbeds(responseEmbed)
return message.flatMap(_ -> threadChannel.sendMessageEmbeds(responseEmbed)
.addActionRow(
generateDismissButton(componentIdInteractor, idForDismissButton.toString())));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private void triggerArchiveFlow(ThreadChannel threadChannel, long authorId,

return sendEmbedWithMention.apply(authorResults.get());
})
.flatMap(any -> threadChannel.getManager().setArchived(true))
.flatMap(_ -> threadChannel.getManager().setArchived(true))
.queue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public HelpThreadCommand(Config config, HelpSystemHelper helper) {
.collect(Collectors.toMap(Subcommand::getCommandName, Function.identity()));
subcommandToCooldownCache = new EnumMap<>(streamSubcommands()
.filter(Subcommand::hasCooldown)
.collect(Collectors.toMap(Function.identity(), any -> createCooldownCache.get())));
.collect(Collectors.toMap(Function.identity(), _ -> createCooldownCache.get())));
subcommandToEventHandler = new EnumMap<>(Map.of(Subcommand.CHANGE_CATEGORY,
this::changeCategory, Subcommand.CHANGE_TITLE, this::changeTitle, Subcommand.CLOSE,
this::closeThread, Subcommand.RESET_ACTIVITY, this::resetActivity));
Expand Down Expand Up @@ -158,7 +158,7 @@ private void changeCategory(SlashCommandInteractionEvent event, ThreadChannel he
refreshCooldownFor(Subcommand.CHANGE_CATEGORY, helpThread);

helper.changeChannelCategory(helpThread, category)
.flatMap(any -> sendCategoryChangedMessage(helpThread.getGuild(), event.getHook(),
.flatMap(_ -> sendCategoryChangedMessage(helpThread.getGuild(), event.getHook(),
helpThread, category))
.queue();
}
Expand All @@ -185,7 +185,7 @@ private RestAction<Message> sendCategoryChangedMessage(Guild guild, InteractionH
String headsUpPattern = "%s please have a look, thanks.";
String headsUpWithoutRole = headsUpPattern.formatted("");
String headsUpWithRole = headsUpPattern.formatted(helperRole.orElseThrow().getAsMention());
return action.flatMap(any -> helpThread.sendMessage(headsUpWithoutRole)
return action.flatMap(_ -> helpThread.sendMessage(headsUpWithoutRole)
.flatMap(message -> message.editMessage(headsUpWithRole)));
}

Expand All @@ -195,7 +195,7 @@ private void changeTitle(SlashCommandInteractionEvent event, ThreadChannel helpT
refreshCooldownFor(Subcommand.CHANGE_TITLE, helpThread);

helper.renameChannel(helpThread, title)
.flatMap(any -> event.reply("Changed the title to **%s**.".formatted(title)))
.flatMap(_ -> event.reply("Changed the title to **%s**.".formatted(title)))
.queue();
}

Expand All @@ -206,7 +206,7 @@ private void closeThread(SlashCommandInteractionEvent event, ThreadChannel helpT
.setColor(HelpSystemHelper.AMBIENT_COLOR)
.build();

event.replyEmbeds(embed).flatMap(any -> helpThread.getManager().setArchived(true)).queue();
event.replyEmbeds(embed).flatMap(_ -> helpThread.getManager().setArchived(true)).queue();
}

private void resetActivity(SlashCommandInteractionEvent event, ThreadChannel helpThread) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,17 @@ private boolean wasThreadAlreadyHandled(long threadChannelId) {
// the threads we already handled
Instant now = Instant.now();
// NOTE It is necessary to do the "check if exists, otherwise insert" atomic
Instant createdAt = threadIdToCreatedAtCache.get(threadChannelId, any -> now);
Instant createdAt = threadIdToCreatedAtCache.get(threadChannelId, _ -> now);
return createdAt != now;
}

private void handleHelpThreadCreated(ThreadChannel threadChannel) {
threadChannel.retrieveStartMessage().flatMap(message -> {
registerThreadDataInDB(message, threadChannel);
return sendHelperHeadsUp(threadChannel)
.flatMap(any -> HelpThreadCreatedListener.isContextSufficient(message),
any -> createAIResponse(threadChannel, message))
.flatMap(any -> pinOriginalQuestion(message));
.flatMap(_ -> HelpThreadCreatedListener.isContextSufficient(message),
_ -> createAIResponse(threadChannel, message))
.flatMap(_ -> pinOriginalQuestion(message));
}).queue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void onMessageReceived(MessageReceivedEvent event) {
}

if (messageHasNoMediaAttached(message)) {
message.delete().flatMap(any -> dmUser(message)).queue(any -> {
message.delete().flatMap(_ -> dmUser(message)).queue(_ -> {
}, failure -> tempNotifyUserInChannel(message));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void onModalSubmitted(ModalInteractionEvent event, List<String> args) {
// Has been handled if original message was deleted by now.
// Deleted messages cause retrieveMessageById to fail.
Consumer<Message> notHandledAction =
any -> transferFlow(event, channelId, authorId, messageId);
_ -> transferFlow(event, channelId, authorId, messageId);

Consumer<Throwable> handledAction = failure -> {
if (failure instanceof ErrorResponseException errorResponseException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void onMessageReceived(MessageReceivedEvent event) {
}

private void handleBadMessage(Message message) {
message.delete().flatMap(any -> dmUser(message)).queue(any -> warnMods(message));
message.delete().flatMap(_ -> dmUser(message)).queue(_ -> warnMods(message));
}

private RestAction<Message> dmUser(Message message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ private void dmUser(MessageReceivedEvent event) {
}

private void dmUser(Guild guild, long userId, JDA jda) {
jda.openPrivateChannelById(userId).flatMap(channel -> dmUser(guild, channel)).queue(any -> {
jda.openPrivateChannelById(userId).flatMap(channel -> dmUser(guild, channel)).queue(_ -> {
}, failure -> logger.debug(
"Unable to send dm message to user {} in guild {} to inform them about a scam message being blocked",
userId, guild.getId(), failure));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Failed to send a reminder with (authorID '{}') skipping it. This can be due to a

int failureAttempts = pendingReminder.getFailureAttempts() + 1;
Instant remindAt = Instant.now().plus(1, ChronoUnit.MINUTES);
database.write(any -> {
database.write(_ -> {
pendingReminder.setRemindAt(remindAt);
pendingReminder.setFailureAttempts(failureAttempts);
pendingReminder.insert();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static CompletableFuture<List<LinkPreview>> createLinkPreviews(List<Strin
.toList();

var allDoneTask = CompletableFuture.allOf(tasks.toArray(CompletableFuture[]::new));
return allDoneTask.thenApply(any -> extractResults(tasks)).exceptionally(e -> {
return allDoneTask.thenApply(_ -> extractResults(tasks)).exceptionally(e -> {
logger.error("Unknown error during link preview creation", e);
return List.of();
});
Expand Down
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
plugins {
id 'java'
id "com.diffplug.spotless" version "6.25.0"
id "org.sonarqube" version "5.0.0.4638"
id "name.remal.sonarlint" version "4.2.2"
id "org.sonarqube" version "5.1.0.4882"
id "name.remal.sonarlint" version "4.2.8"
}

group 'org.togetherjava'
Expand Down Expand Up @@ -55,16 +55,16 @@ subprojects {
java {
toolchain {
// Nails the Java-Version of every Subproject
languageVersion = JavaLanguageVersion.of(21)
languageVersion = JavaLanguageVersion.of(22)
}
}

// sonarlint configuration, not to be confused with sonarqube/sonarcloud.
sonarLint {
rules {
disable(
'java:S1135' // Disables "Track uses of "TO-DO" tags" rule.
)
disable('java:S1135') // Disables "Track uses of "TO-DO" tags" rule.
disable('java:S1190')
disable('java:S117')
}
}

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
Loading