diff --git a/application/build.gradle b/application/build.gradle index 64c3864..269489f 100644 --- a/application/build.gradle +++ b/application/build.gradle @@ -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 { @@ -22,4 +21,9 @@ jlink { launcher { name = 'ftprx' } +} + +application { + mainModule = "$moduleName" + mainClassName = "com.ftprx.application.FtpRxApplication" } \ No newline at end of file diff --git a/application/src/main/java/com/ftprx/application/controller/UserManagerController.java b/application/src/main/java/com/ftprx/application/controller/UserManagerController.java index c58fcc6..aa1a38e 100644 --- a/application/src/main/java/com/ftprx/application/controller/UserManagerController.java +++ b/application/src/main/java/com/ftprx/application/controller/UserManagerController.java @@ -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 { @@ -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) { diff --git a/application/src/main/java/module-info.java b/application/src/main/java/module-info.java index 1574a01..755c6a6 100644 --- a/application/src/main/java/module-info.java +++ b/application/src/main/java/module-info.java @@ -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; } \ No newline at end of file diff --git a/build.gradle b/build.gradle index 4d30660..c5c9ec0 100644 --- a/build.gradle +++ b/build.gradle @@ -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 { diff --git a/server/build.gradle b/server/build.gradle index 292e97f..0becb97 100644 --- a/server/build.gradle +++ b/server/build.gradle @@ -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", -//] \ No newline at end of file +} \ No newline at end of file diff --git a/server/src/main/java/com/ftprx/server/ActiveConnectionMode.java b/server/src/main/java/com/ftprx/server/ActiveConnectionMode.java index 1fe9243..0022d35 100644 --- a/server/src/main/java/com/ftprx/server/ActiveConnectionMode.java +++ b/server/src/main/java/com/ftprx/server/ActiveConnectionMode.java @@ -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; @@ -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); diff --git a/server/src/main/java/com/ftprx/server/CommandDispatcher.java b/server/src/main/java/com/ftprx/server/CommandDispatcher.java index 187f938..72dc6bf 100644 --- a/server/src/main/java/com/ftprx/server/CommandDispatcher.java +++ b/server/src/main/java/com/ftprx/server/CommandDispatcher.java @@ -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; @@ -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(); } diff --git a/server/src/main/java/com/ftprx/server/CommandLookupTable.java b/server/src/main/java/com/ftprx/server/CommandLookupTable.java index 89a26e9..bcbd5bd 100644 --- a/server/src/main/java/com/ftprx/server/CommandLookupTable.java +++ b/server/src/main/java/com/ftprx/server/CommandLookupTable.java @@ -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; @@ -65,16 +65,16 @@ public static CommandLookupTable bootstrap() { /** * Assign the {@link CommandCode} with given {@link SimpleCommand}. */ - public void registerCommand(@Nonnull CommandCode code, - @Nonnull Supplier commandSupplier) { + public void registerCommand(@NotNull CommandCode code, + @NotNull Supplier 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)); } @@ -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 entry : entrySet()) { if (command.equalsCode(entry.getKey())) { @@ -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); } @@ -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 entry : entrySet()) { if (command.equalsCode(entry.getKey())) { diff --git a/server/src/main/java/com/ftprx/server/ConnectionMode.java b/server/src/main/java/com/ftprx/server/ConnectionMode.java index 245e8e6..8845565 100644 --- a/server/src/main/java/com/ftprx/server/ConnectionMode.java +++ b/server/src/main/java/com/ftprx/server/ConnectionMode.java @@ -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; @@ -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); } diff --git a/server/src/main/java/com/ftprx/server/PassiveConnectionMode.java b/server/src/main/java/com/ftprx/server/PassiveConnectionMode.java index 938dadf..4df1785 100644 --- a/server/src/main/java/com/ftprx/server/PassiveConnectionMode.java +++ b/server/src/main/java/com/ftprx/server/PassiveConnectionMode.java @@ -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; @@ -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()); diff --git a/server/src/main/java/com/ftprx/server/Server.java b/server/src/main/java/com/ftprx/server/Server.java index 14a2ef1..c40de95 100644 --- a/server/src/main/java/com/ftprx/server/Server.java +++ b/server/src/main/java/com/ftprx/server/Server.java @@ -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; @@ -116,7 +116,7 @@ public synchronized void pause() { status = ServerStatus.PAUSED; } - @Nonnull + @NotNull public ServerStatus getStatus() { return status; } @@ -133,7 +133,7 @@ public Optional getServer() { return Optional.ofNullable(server); } - @Nonnull + @NotNull public List getClients() { return clients; } @@ -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(); diff --git a/server/src/main/java/com/ftprx/server/account/Account.java b/server/src/main/java/com/ftprx/server/account/Account.java index 8410613..55ec0b0 100644 --- a/server/src/main/java/com/ftprx/server/account/Account.java +++ b/server/src/main/java/com/ftprx/server/account/Account.java @@ -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; @@ -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); @@ -67,7 +67,7 @@ public boolean isPasswordRequired() { return hashedPassword != null; } - @Nonnull + @NotNull public String getUsername() { return username; } diff --git a/server/src/main/java/com/ftprx/server/account/AccountRepository.java b/server/src/main/java/com/ftprx/server/account/AccountRepository.java index 379f80f..e94dc49 100644 --- a/server/src/main/java/com/ftprx/server/account/AccountRepository.java +++ b/server/src/main/java/com/ftprx/server/account/AccountRepository.java @@ -16,7 +16,8 @@ package com.ftprx.server.account; -import javax.annotation.Nonnull; +import org.jetbrains.annotations.NotNull; + import java.util.List; /** @@ -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. @@ -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); } diff --git a/server/src/main/java/com/ftprx/server/account/AccountRepositoryChangeListener.java b/server/src/main/java/com/ftprx/server/account/AccountRepositoryChangeListener.java index 51ceba7..b981e58 100644 --- a/server/src/main/java/com/ftprx/server/account/AccountRepositoryChangeListener.java +++ b/server/src/main/java/com/ftprx/server/account/AccountRepositoryChangeListener.java @@ -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); } diff --git a/server/src/main/java/com/ftprx/server/account/FileAccountRepository.java b/server/src/main/java/com/ftprx/server/account/FileAccountRepository.java index 18dc992..ad4879f 100644 --- a/server/src/main/java/com/ftprx/server/account/FileAccountRepository.java +++ b/server/src/main/java/com/ftprx/server/account/FileAccountRepository.java @@ -18,10 +18,10 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.tinylog.Logger; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import java.io.Reader; import java.io.Writer; import java.nio.file.Path; @@ -54,12 +54,12 @@ public FileAccountRepository(String filename) { } @Override - public void update(@Nonnull Account account) { + public void update(@NotNull Account account) { Objects.requireNonNull(account, "Account must not be null"); } @Override - public Account findByUsername(@Nonnull String username) { + public Account findByUsername(@NotNull String username) { return findAll() .stream() .filter(account -> username.equals(account.getUsername())) @@ -73,7 +73,7 @@ public List findAll() { } @Override - public void insert(@Nonnull Account account) throws AccountInsertException { + public void insert(@NotNull Account account) throws AccountInsertException { Objects.requireNonNull(account, "Account must not be null"); if (isAccountExists(account)) { throw new AccountInsertException(ACCOUNT_ALREADY_EXISTS); @@ -95,7 +95,7 @@ public boolean isAccountExists(Account account) { } @Override - public void delete(@Nonnull Account account) { + public void delete(@NotNull Account account) { Objects.requireNonNull(account, "Account must not be null"); delete(account.getUsername()); notifyDeleteAccount(account); diff --git a/server/src/main/java/com/ftprx/server/account/ObservableAccountRepository.java b/server/src/main/java/com/ftprx/server/account/ObservableAccountRepository.java index 515562e..e5517af 100644 --- a/server/src/main/java/com/ftprx/server/account/ObservableAccountRepository.java +++ b/server/src/main/java/com/ftprx/server/account/ObservableAccountRepository.java @@ -16,7 +16,7 @@ package com.ftprx.server.account; -import javax.annotation.Nullable; +import org.jetbrains.annotations.Nullable; /** * A repository that allows listeners to track changes when they occur. diff --git a/server/src/main/java/com/ftprx/server/channel/Client.java b/server/src/main/java/com/ftprx/server/channel/Client.java index a593a23..be57b74 100644 --- a/server/src/main/java/com/ftprx/server/channel/Client.java +++ b/server/src/main/java/com/ftprx/server/channel/Client.java @@ -19,10 +19,9 @@ import com.ftprx.server.ConnectionMode; import com.ftprx.server.account.Account; import com.ftprx.server.util.SocketHelper; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -67,13 +66,13 @@ public class Client { private Path workingDirectory; private String selectedUsername; - public Client(@Nonnull Socket controlConnection) { + public Client(@NotNull Socket controlConnection) { this.controlConnection = requireNonNull(controlConnection); commandBuffer = new ConcurrentLinkedQueue<>(); replyBuffer = new ConcurrentLinkedQueue<>(); } - public void login(@Nonnull Account account) { + public void login(@NotNull Account account) { Objects.requireNonNull(account, "Account must not be null"); this.account = account; workingDirectory = Paths.get(account.getHomeDirectory()); @@ -109,12 +108,12 @@ public void changeWorkingDirectory(@Nullable Path workingDirectory) throws Worki this.workingDirectory = workingDirectory.normalize(); } - @CheckForNull + @Nullable public Path getWorkingDirectory() { return workingDirectory; } - @CheckForNull + @Nullable public Account getAccount() { return account; } @@ -154,11 +153,11 @@ public OutputStream getOutputStream() throws IOException { return controlConnection.getOutputStream(); } - public void establishDataConnection(@Nonnull Socket dataConnection) { + public void establishDataConnection(@NotNull Socket dataConnection) { this.dataConnection = Objects.requireNonNull(dataConnection); } - public void openDataConnection(@Nonnull ConnectionMode mode) { + public void openDataConnection(@NotNull ConnectionMode mode) { mode.openConnection(this); } @@ -171,7 +170,7 @@ public void closeDataConnection() throws IOException { dataConnection.close(); } - @Nonnull + @NotNull public Socket getControlConnection() { return controlConnection; } @@ -180,12 +179,12 @@ public void closeControlConnection() throws IOException { controlConnection.close(); } - @Nonnull + @NotNull public ConcurrentLinkedQueue getBufferedCommands() { return commandBuffer; } - @Nonnull + @NotNull public ConcurrentLinkedQueue getBufferedReplies() { return replyBuffer; } diff --git a/server/src/main/java/com/ftprx/server/channel/Command.java b/server/src/main/java/com/ftprx/server/channel/Command.java index 550bec1..669ca15 100644 --- a/server/src/main/java/com/ftprx/server/channel/Command.java +++ b/server/src/main/java/com/ftprx/server/channel/Command.java @@ -17,10 +17,8 @@ package com.ftprx.server.channel; import com.ftprx.server.util.ControlCharacters; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Objects; @@ -41,20 +39,20 @@ public class Command { */ private final String argument; - public Command(@Nonnull String code) { + public Command(@NotNull String code) { this(code, null); } - public Command(@Nonnull String code, @Nullable String arguments) { + public Command(@NotNull String code, @Nullable String arguments) { this.code = Objects.requireNonNull(code); this.argument = arguments; } - public @Nonnull String getCode() { + public @NotNull String getCode() { return code; } - public @Nonnull String getArgument() { + public @NotNull String getArgument() { return argument == null ? ControlCharacters.EMPTY : argument; } diff --git a/server/src/main/java/com/ftprx/server/channel/Reply.java b/server/src/main/java/com/ftprx/server/channel/Reply.java index 5e9221b..5616292 100644 --- a/server/src/main/java/com/ftprx/server/channel/Reply.java +++ b/server/src/main/java/com/ftprx/server/channel/Reply.java @@ -17,9 +17,9 @@ package com.ftprx.server.channel; import com.ftprx.server.util.ControlCharacters; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import java.util.Objects; import java.util.Optional; @@ -39,17 +39,17 @@ public class Reply { */ private final String text; - public Reply(@Nonnull String code, @Nullable String text) { + public Reply(@NotNull String code, @Nullable String text) { this.code = Objects.requireNonNull(code, "Code must not be null"); this.text = Optional.ofNullable(text).orElse(ControlCharacters.EMPTY); } - @Nonnull + @NotNull public String getCode() { return code; } - @Nonnull + @NotNull public String getText() { return text; } diff --git a/server/src/main/java/com/ftprx/server/process/DataTransferProcess.java b/server/src/main/java/com/ftprx/server/process/DataTransferProcess.java index e555424..722725d 100644 --- a/server/src/main/java/com/ftprx/server/process/DataTransferProcess.java +++ b/server/src/main/java/com/ftprx/server/process/DataTransferProcess.java @@ -17,9 +17,9 @@ package com.ftprx.server.process; 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; import java.util.Objects; @@ -37,7 +37,7 @@ public abstract class DataTransferProcess implements Runnable { private static final long CONNECTION_TIMEOUT = 2_000; // ms protected final Client client; - public DataTransferProcess(@Nonnull Client client) { + public DataTransferProcess(@NotNull Client client) { Objects.requireNonNull(client, "Client must not be null"); this.client = client; } diff --git a/server/src/main/java/com/ftprx/server/process/DownloadFileProcess.java b/server/src/main/java/com/ftprx/server/process/DownloadFileProcess.java index e5eb91b..e90dd78 100644 --- a/server/src/main/java/com/ftprx/server/process/DownloadFileProcess.java +++ b/server/src/main/java/com/ftprx/server/process/DownloadFileProcess.java @@ -1,16 +1,16 @@ package com.ftprx.server.process; import com.ftprx.server.channel.Client; +import org.jetbrains.annotations.NotNull; import org.tinylog.Logger; -import javax.annotation.Nonnull; import java.io.*; import java.util.Objects; public class DownloadFileProcess extends DataTransferProcess { private final File file; - public DownloadFileProcess(@Nonnull Client client, @Nonnull File file) { + public DownloadFileProcess(@NotNull Client client, @NotNull File file) { super(client); this.file = Objects.requireNonNull(file, "File must not be null"); } diff --git a/server/src/main/java/com/ftprx/server/process/ListingProcess.java b/server/src/main/java/com/ftprx/server/process/ListingProcess.java index 9fbf369..2581344 100644 --- a/server/src/main/java/com/ftprx/server/process/ListingProcess.java +++ b/server/src/main/java/com/ftprx/server/process/ListingProcess.java @@ -17,10 +17,9 @@ package com.ftprx.server.process; import com.ftprx.server.channel.Client; +import org.jetbrains.annotations.NotNull; import org.tinylog.Logger; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import java.io.File; import java.io.IOException; import java.io.PrintWriter; @@ -35,7 +34,7 @@ public class ListingProcess extends DataTransferProcess { private DirectoryListFormat format = new DosDirectoryListFormat(); private final File directory; - public ListingProcess(@Nonnull Client client, @Nonnull File directory) { + public ListingProcess(@NotNull Client client, @NotNull File directory) { super(client); this.directory = directory; } diff --git a/server/src/main/java/com/ftprx/server/process/UploadFileProcess.java b/server/src/main/java/com/ftprx/server/process/UploadFileProcess.java index 5a100d2..3a28434 100644 --- a/server/src/main/java/com/ftprx/server/process/UploadFileProcess.java +++ b/server/src/main/java/com/ftprx/server/process/UploadFileProcess.java @@ -1,9 +1,9 @@ package com.ftprx.server.process; import com.ftprx.server.channel.Client; +import org.jetbrains.annotations.NotNull; import org.tinylog.Logger; -import javax.annotation.Nonnull; import java.io.*; import java.nio.file.Files; import java.util.Objects; @@ -12,7 +12,7 @@ public class UploadFileProcess extends DataTransferProcess { public static final int DEFAULT_BUFFER_SIZE = 8192; private final File file; - public UploadFileProcess(@Nonnull Client client, @Nonnull File file) { + public UploadFileProcess(@NotNull Client client, @NotNull File file) { super(client); this.file = Objects.requireNonNull(file, "File must not be null"); } diff --git a/server/src/main/java/com/ftprx/server/process/WorkerThread.java b/server/src/main/java/com/ftprx/server/process/WorkerThread.java index d8c9566..2807190 100644 --- a/server/src/main/java/com/ftprx/server/process/WorkerThread.java +++ b/server/src/main/java/com/ftprx/server/process/WorkerThread.java @@ -20,9 +20,9 @@ import com.ftprx.server.channel.Command; import com.ftprx.server.channel.Reply; import com.ftprx.server.CommandDispatcher; +import org.jetbrains.annotations.NotNull; import org.tinylog.Logger; -import javax.annotation.Nonnull; import java.io.*; import java.net.Socket; import java.util.Objects; @@ -33,7 +33,7 @@ public class WorkerThread implements Runnable { private final Socket connection; private final CommandDispatcher dispatcher; - public WorkerThread(@Nonnull Client client) { + public WorkerThread(@NotNull Client client) { this.client = Objects.requireNonNull(client); this.connection = client.getControlConnection(); this.dispatcher = new CommandDispatcher(client); diff --git a/server/src/main/java/com/ftprx/server/repository/FileAccountRepository.java b/server/src/main/java/com/ftprx/server/repository/FileAccountRepository.java index bbb044f..5bbd518 100644 --- a/server/src/main/java/com/ftprx/server/repository/FileAccountRepository.java +++ b/server/src/main/java/com/ftprx/server/repository/FileAccountRepository.java @@ -19,10 +19,10 @@ import com.ftprx.server.account.*; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.tinylog.Logger; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import java.io.*; import java.nio.file.Path; import java.nio.file.Paths; @@ -56,12 +56,12 @@ public FileAccountRepository(String filename) { } @Override - public void update(@Nonnull Account account) { + public void update(@NotNull Account account) { Objects.requireNonNull(account, "Account must not be null"); } @Override - public Account findByUsername(@Nonnull String username) { + public Account findByUsername(@NotNull String username) { return findAll() .stream() .filter(account -> username.equals(account.getUsername())) @@ -75,7 +75,7 @@ public List findAll() { } @Override - public void insert(@Nonnull Account account) throws AccountInsertException { + public void insert(@NotNull Account account) throws AccountInsertException { Objects.requireNonNull(account, "Account must not be null"); if (isAccountExists(account)) { throw new AccountInsertException(ACCOUNT_ALREADY_EXISTS); @@ -97,7 +97,7 @@ public boolean isAccountExists(Account account) { } @Override - public void delete(@Nonnull Account account) { + public void delete(@NotNull Account account) { Objects.requireNonNull(account, "Account must not be null"); delete(account.getUsername()); notifyDeleteAccount(account); diff --git a/server/src/main/java/com/ftprx/server/repository/InMemoryAccountRepository.java b/server/src/main/java/com/ftprx/server/repository/InMemoryAccountRepository.java index f7e0dce..63b06c0 100644 --- a/server/src/main/java/com/ftprx/server/repository/InMemoryAccountRepository.java +++ b/server/src/main/java/com/ftprx/server/repository/InMemoryAccountRepository.java @@ -3,8 +3,8 @@ import com.ftprx.server.account.Account; import com.ftprx.server.account.AccountCreateException; import com.ftprx.server.account.AccountRepository; +import org.jetbrains.annotations.NotNull; -import javax.annotation.Nonnull; import java.util.ArrayList; import java.util.List; @@ -21,12 +21,12 @@ public InMemoryAccountRepository() { } @Override - public void update(@Nonnull Account account) { + public void update(@NotNull Account account) { } @Override - public Account findByUsername(@Nonnull String username) { + public Account findByUsername(@NotNull String username) { for (Account account : accounts) { if (username.equals(account.getUsername())) { return account; @@ -41,12 +41,12 @@ public List findAll() { } @Override - public void insert(@Nonnull Account account) { + public void insert(@NotNull Account account) { accounts.add(account); } @Override - public void delete(@Nonnull Account account) { + public void delete(@NotNull Account account) { delete(account.getUsername()); } diff --git a/server/src/main/java/com/ftprx/server/security/PasswordEncoder.java b/server/src/main/java/com/ftprx/server/security/PasswordEncoder.java index b37061c..bb320a4 100644 --- a/server/src/main/java/com/ftprx/server/security/PasswordEncoder.java +++ b/server/src/main/java/com/ftprx/server/security/PasswordEncoder.java @@ -16,9 +16,9 @@ package com.ftprx.server.security; +import org.jetbrains.annotations.NotNull; import org.tinylog.Logger; -import javax.annotation.Nonnull; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -33,7 +33,7 @@ public static boolean matches(String plainPassword, String encodedPassword) { return encodedPassword.equals(generateHash(plainPassword)); } - private static String generateHash(@Nonnull String input) { + private static String generateHash(@NotNull String input) { StringBuilder hash = new StringBuilder(); try { MessageDigest sha = MessageDigest.getInstance(ALGORITHM); diff --git a/server/src/main/java/com/ftprx/server/thread/ListenerThread.java b/server/src/main/java/com/ftprx/server/thread/ListenerThread.java index b1fe234..fe662dd 100644 --- a/server/src/main/java/com/ftprx/server/thread/ListenerThread.java +++ b/server/src/main/java/com/ftprx/server/thread/ListenerThread.java @@ -17,10 +17,10 @@ package com.ftprx.server.thread; import com.ftprx.server.util.SocketHelper; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.tinylog.Logger; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; @@ -36,7 +36,7 @@ public class ListenerThread extends Thread { private final Set observers; private final ServerSocket server; - public ListenerThread(@Nonnull ServerSocket server) { + public ListenerThread(@NotNull ServerSocket server) { this.server = Objects.requireNonNull(server, "Server must not be null"); this.observers = Collections.newSetFromMap(new ConcurrentHashMap<>()); setName(THREAD_NAME); @@ -66,7 +66,7 @@ public void unregisterClientConnectObserver(@Nullable ClientConnectObserver obse Optional.ofNullable(observer).ifPresent(observers::remove); } - private void notifyObservers(@Nonnull Socket client) { + private void notifyObservers(@NotNull Socket client) { for (ClientConnectObserver observer : observers) { observer.onClientConnected(client); } diff --git a/server/src/main/java/com/ftprx/server/util/SocketHelper.java b/server/src/main/java/com/ftprx/server/util/SocketHelper.java index fdfa1d9..cbf1b6b 100644 --- a/server/src/main/java/com/ftprx/server/util/SocketHelper.java +++ b/server/src/main/java/com/ftprx/server/util/SocketHelper.java @@ -16,7 +16,8 @@ package com.ftprx.server.util; -import javax.annotation.Nullable; +import org.jetbrains.annotations.Nullable; + import javax.net.ServerSocketFactory; import java.net.DatagramSocket; import java.net.InetAddress; diff --git a/server/src/main/java/module-info.java b/server/src/main/java/module-info.java index 55a0c71..8eb4232 100644 --- a/server/src/main/java/module-info.java +++ b/server/src/main/java/module-info.java @@ -2,8 +2,8 @@ requires org.tinylog.api; requires com.google.guice; requires com.google.gson; - requires jsr305; requires owner; + requires org.jetbrains.annotations; exports com.ftprx.server; exports com.ftprx.server.account; opens com.ftprx.server.account to com.google.gson;