Skip to content

Commit

Permalink
Use JetBrains annotations instead of JSR 305,
Browse files Browse the repository at this point in the history
  • Loading branch information
Adiras committed Feb 24, 2024
1 parent 8c6bf31 commit 483b1f7
Show file tree
Hide file tree
Showing 30 changed files with 108 additions and 111 deletions.
8 changes: 6 additions & 2 deletions application/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ plugins {
id 'org.beryx.jlink' version '2.23.2'
}

mainClassName = "$moduleName/com.ftprx.application.FtpRxApplication"

dependencies {
implementation project(':server');
implementation group: 'org.jetbrains', name: 'annotations', version: '24.1.0'
}

javafx {
Expand All @@ -22,4 +21,9 @@ jlink {
launcher {
name = 'ftprx'
}
}

application {
mainModule = "$moduleName"
mainClassName = "com.ftprx.application.FtpRxApplication"
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
import javafx.scene.control.ButtonType;
import javafx.scene.control.ListView;
import javafx.stage.Stage;

import javax.annotation.Nonnull;
import org.jetbrains.annotations.NotNull;

public class UserManagerController implements AccountRepositoryChangeListener {

Expand Down Expand Up @@ -113,19 +112,19 @@ public void onCloseRequest() {
}

@Override
public void onInsertAccount(@Nonnull Account account) {
public void onInsertAccount(@NotNull Account account) {
data.add(account);
userList.refresh();
}

@Override
public void onDeleteEvent(@Nonnull Account account) {
public void onDeleteEvent(@NotNull Account account) {
data.remove(account);
userList.refresh();
}

@Override
public void onUpdateEvent(@Nonnull Account account) {
public void onUpdateEvent(@NotNull Account account) {
}

public void setStage(Stage stage) {
Expand Down
2 changes: 1 addition & 1 deletion application/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
requires javafx.controls;
requires javafx.fxml;
requires java.desktop;
requires jsr305;
requires org.jetbrains.annotations;
opens com.ftprx.application to javafx.graphics;
opens com.ftprx.application.controller to javafx.fxml;
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
// Plugin that makes it easy to work with the Java Platform Module System
id 'org.javamodularity.moduleplugin' version '1.7.0' apply false
id 'org.javamodularity.moduleplugin' version '1.8.14' apply false
}

subprojects {
Expand Down
7 changes: 2 additions & 5 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ dependencies {
testImplementation platform("org.spockframework:spock-bom:2.0-M4-groovy-3.0")
testImplementation "org.spockframework:spock-core"
implementation group: 'org.aeonbits.owner', name: 'owner', version: '1.0.12'
implementation group: 'org.jetbrains', name: 'annotations', version: '24.1.0'
}

test {
useJUnitPlatform()
}

//patchModules.config = [
// "annotations=jsr305",
//]
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package com.ftprx.server;

import com.ftprx.server.channel.Client;
import org.jetbrains.annotations.NotNull;
import org.tinylog.Logger;

import javax.annotation.Nonnull;
import java.io.IOException;
import java.net.Socket;

Expand All @@ -44,7 +44,7 @@ public ActiveConnectionMode(String host, int port) {
* The method blocks thread until a connection is made.
*/
@Override
public void openConnection(@Nonnull Client client) {
public void openConnection(@NotNull Client client) {
try {
Socket socket = new Socket(host, port);
client.establishDataConnection(socket);
Expand Down
5 changes: 2 additions & 3 deletions server/src/main/java/com/ftprx/server/CommandDispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

import com.ftprx.server.channel.Client;
import com.ftprx.server.channel.Command;

import javax.annotation.Nonnull;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;

Expand All @@ -31,7 +30,7 @@ public class CommandDispatcher {
* Create a new {@link CommandDispatcher} instance.
* @param client the client that is assigned for this dispatcher
*/
public CommandDispatcher(@Nonnull Client client) {
public CommandDispatcher(@NotNull Client client) {
this.client = Objects.requireNonNull(client, "Client must not be null");
this.commandLookupTable = CommandLookupTable.bootstrap();
}
Expand Down
18 changes: 9 additions & 9 deletions server/src/main/java/com/ftprx/server/CommandLookupTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import com.ftprx.server.channel.Command;
import com.ftprx.server.channel.CommandCode;
import com.ftprx.server.command.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Objects;
import java.util.function.Supplier;
Expand Down Expand Up @@ -65,16 +65,16 @@ public static CommandLookupTable bootstrap() {
/**
* Assign the {@link CommandCode} with given {@link SimpleCommand}.
*/
public void registerCommand(@Nonnull CommandCode code,
@Nonnull Supplier<SimpleCommand> commandSupplier) {
public void registerCommand(@NotNull CommandCode code,
@NotNull Supplier<SimpleCommand> commandSupplier) {
registerCommand(code, commandSupplier.get());
}

/**
* Assign the {@link CommandCode} with given {@link SimpleCommand}.
*/
public void registerCommand(@Nonnull CommandCode code,
@Nonnull SimpleCommand command) {
public void registerCommand(@NotNull CommandCode code,
@NotNull SimpleCommand command) {
put(requireNonNull(code), requireNonNull(command));
}

Expand All @@ -84,7 +84,7 @@ public void registerCommand(@Nonnull CommandCode code,
* or null if the command is not registered.
*/
@Nullable
public SimpleCommand getCommand(@Nonnull Command command) {
public SimpleCommand getCommand(@NotNull Command command) {
Objects.requireNonNull(command, "Command must not be null");
for (Entry<CommandCode, SimpleCommand> entry : entrySet()) {
if (command.equalsCode(entry.getKey())) {
Expand All @@ -99,7 +99,7 @@ public SimpleCommand getCommand(@Nonnull Command command) {
* @param command the command which {@link CommandCode} is looking for.
* @return true if the command is not registered in this {@link CommandLookupTable}.
*/
public boolean isCommandNotRegistered(@Nonnull Command command) {
public boolean isCommandNotRegistered(@NotNull Command command) {
return !isCommandRegistered(command);
}

Expand All @@ -108,7 +108,7 @@ public boolean isCommandNotRegistered(@Nonnull Command command) {
* @param command the command which {@link CommandCode} is looking for.
* @return true if the command is registered in this {@link CommandLookupTable}.
*/
public boolean isCommandRegistered(@Nonnull Command command) {
public boolean isCommandRegistered(@NotNull Command command) {
Objects.requireNonNull(command, "Command must not be null");
for (Entry<CommandCode, SimpleCommand> entry : entrySet()) {
if (command.equalsCode(entry.getKey())) {
Expand Down
4 changes: 2 additions & 2 deletions server/src/main/java/com/ftprx/server/ConnectionMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package com.ftprx.server;

import com.ftprx.server.channel.Client;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import java.net.Socket;
import java.util.concurrent.Future;
import java.util.function.Consumer;
Expand All @@ -28,5 +28,5 @@ public interface ConnectionMode {
* Opens the data connection between client and server.
* The method blocks thread until a connection is made.
*/
void openConnection(@Nonnull Client client);
void openConnection(@NotNull Client client);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package com.ftprx.server;

import com.ftprx.server.channel.Client;
import org.jetbrains.annotations.NotNull;
import org.tinylog.Logger;

import javax.annotation.Nonnull;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.UnknownHostException;
Expand All @@ -42,7 +42,7 @@ public PassiveConnectionMode(int port) {
* The method blocks thread until a connection is made.
*/
@Override
public void openConnection(@Nonnull Client client) {
public void openConnection(@NotNull Client client) {
Thread connectionThread = new Thread(() -> {
try (ServerSocket socket = new ServerSocket(port)) {
client.establishDataConnection(socket.accept());
Expand Down
8 changes: 4 additions & 4 deletions server/src/main/java/com/ftprx/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import com.ftprx.server.thread.ThreadManager;
import com.ftprx.server.util.SocketHelper;
import org.aeonbits.owner.ConfigFactory;
import org.jetbrains.annotations.NotNull;
import org.tinylog.Logger;

import javax.annotation.Nonnull;
import java.io.IOException;
import java.net.*;
import java.time.Instant;
Expand Down Expand Up @@ -116,7 +116,7 @@ public synchronized void pause() {
status = ServerStatus.PAUSED;
}

@Nonnull
@NotNull
public ServerStatus getStatus() {
return status;
}
Expand All @@ -133,7 +133,7 @@ public Optional<ServerSocket> getServer() {
return Optional.ofNullable(server);
}

@Nonnull
@NotNull
public List<Client> getClients() {
return clients;
}
Expand Down Expand Up @@ -173,7 +173,7 @@ private void registerNewClient(Client connection) {
clients.add(connection);
}

@Nonnull
@NotNull
public synchronized static Server getInstance() {
if (instance == null) {
instance = new Server();
Expand Down
8 changes: 4 additions & 4 deletions server/src/main/java/com/ftprx/server/account/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
package com.ftprx.server.account;

import com.ftprx.server.security.PasswordEncoder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.tinylog.Logger;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Objects;
Expand All @@ -36,7 +36,7 @@ public Account() {
// Empty constructor for serialization purpose
}

public Account(@Nonnull String username, @Nonnull String homeDirectory,
public Account(@NotNull String username, @NotNull String homeDirectory,
@Nullable String plainPassword) throws AccountCreateException {

this.username = validateUsername(username);
Expand Down Expand Up @@ -67,7 +67,7 @@ public boolean isPasswordRequired() {
return hashedPassword != null;
}

@Nonnull
@NotNull
public String getUsername() {
return username;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

package com.ftprx.server.account;

import javax.annotation.Nonnull;
import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
Expand All @@ -29,13 +30,13 @@ public interface AccountRepository {
* @param account must not be {@code null}.
* @throws NullPointerException if {@code account} is {@code null}
*/
void update(@Nonnull Account account);
void update(@NotNull Account account);

/**
* Retrieves an account by its username.
* @param username must not be {@code null}
*/
Account findByUsername(@Nonnull String username);
Account findByUsername(@NotNull String username);

/**
* Returns all existing account instances.
Expand All @@ -48,12 +49,12 @@ public interface AccountRepository {
* @param account must not be {@code null}.
* @throws NullPointerException if {@code account} is {@code null}
*/
void insert(@Nonnull Account account) throws AccountInsertException;
void insert(@NotNull Account account) throws AccountInsertException;

/**
* Delete a given account.
* @param account must not be {@code null}.
* @throws NullPointerException if {@code account} is {@code null}
*/
void delete(@Nonnull Account account);
void delete(@NotNull Account account);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

package com.ftprx.server.account;

import javax.annotation.Nonnull;
import org.jetbrains.annotations.NotNull;

/**
* Interface that receives notifications of changes to an {@link AccountRepository}.
*/
public interface AccountRepositoryChangeListener {
void onInsertAccount(@Nonnull Account account);
void onDeleteEvent(@Nonnull Account account);
void onUpdateEvent(@Nonnull Account account);
void onInsertAccount(@NotNull Account account);
void onDeleteEvent(@NotNull Account account);
void onUpdateEvent(@NotNull Account account);
}
Loading

0 comments on commit 483b1f7

Please sign in to comment.