From b9ed9b4c4755feb4ae91201c8760730140db06a6 Mon Sep 17 00:00:00 2001 From: Ali Date: Sun, 15 Dec 2024 21:20:22 +0300 Subject: [PATCH] remove LocalMavenRepository.java and replace it with MavenRepository --- api/build.gradle.kts | 2 ++ .../zapper/RuntimeLibPluginConfiguration.java | 14 ++------- .../repository/LocalMavenRepository.java | 31 ------------------- .../zapper/repository/Repository.java | 12 ++++--- 4 files changed, 13 insertions(+), 46 deletions(-) delete mode 100644 api/src/main/java/revxrsal/zapper/repository/LocalMavenRepository.java diff --git a/api/build.gradle.kts b/api/build.gradle.kts index 30438e9..0ec1715 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -15,4 +15,6 @@ repositories { dependencies { compileOnly("org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT") compileOnly("org.jetbrains:annotations:24.1.0") + compileOnly("org.projectlombok:lombok:1.18.36") + annotationProcessor("org.projectlombok:lombok:1.18.36") } diff --git a/api/src/main/java/revxrsal/zapper/RuntimeLibPluginConfiguration.java b/api/src/main/java/revxrsal/zapper/RuntimeLibPluginConfiguration.java index fcecb96..9eb7ccd 100644 --- a/api/src/main/java/revxrsal/zapper/RuntimeLibPluginConfiguration.java +++ b/api/src/main/java/revxrsal/zapper/RuntimeLibPluginConfiguration.java @@ -1,5 +1,6 @@ package revxrsal.zapper; +import lombok.SneakyThrows; import org.jetbrains.annotations.NotNull; import revxrsal.zapper.relocation.Relocation; import revxrsal.zapper.repository.Repository; @@ -83,21 +84,17 @@ public final class RuntimeLibPluginConfiguration { return repos; } - private static @NotNull Properties parseProperties() { + private static @SneakyThrows @NotNull Properties parseProperties() { Properties properties = new Properties(); try (InputStream stream = ClassLoaderReader.getResource("zapper/zapper.properties")) { properties.load(stream); - } catch (IOException e) { - throw sneakyThrow(e); } return properties; } - private static List readAllLines(InputStream inputStream) { + private static @SneakyThrows @NotNull List readAllLines(InputStream inputStream) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { return reader.lines().collect(Collectors.toList()); - } catch (IOException e) { - throw sneakyThrow(e); } } @@ -124,9 +121,4 @@ public List getRelocations() { public String toString() { return "RuntimeLibPluginConfiguration(libsFolder=" + this.getLibsFolder() + ", relocationPrefix=" + this.getRelocationPrefix() + ", dependencies=" + this.getDependencies() + ", repositories=" + this.getRepositories() + ", relocations=" + this.getRelocations() + ")"; } - - @SuppressWarnings("unchecked") - private static RuntimeException sneakyThrow(Throwable t) throws T { - throw (T) t; - } } diff --git a/api/src/main/java/revxrsal/zapper/repository/LocalMavenRepository.java b/api/src/main/java/revxrsal/zapper/repository/LocalMavenRepository.java deleted file mode 100644 index c947d63..0000000 --- a/api/src/main/java/revxrsal/zapper/repository/LocalMavenRepository.java +++ /dev/null @@ -1,31 +0,0 @@ -package revxrsal.zapper.repository; - -import org.jetbrains.annotations.NotNull; -import revxrsal.zapper.Dependency; - -import java.io.File; -import java.net.URL; - -/** - * Represents the local maven repository - */ -final class LocalMavenRepository implements Repository { - - private final @NotNull File directory; - - LocalMavenRepository(@NotNull File directory) { - this.directory = directory; - } - - @Override - public @NotNull URL resolve(@NotNull Dependency dependency) throws Exception { - String systemPath = dependency.getMavenPath().replace('/', File.separatorChar); - File file = new File(directory, systemPath); - return file.toURI().toURL(); - } - - @Override - public String toString() { - return directory.toString(); - } -} diff --git a/api/src/main/java/revxrsal/zapper/repository/Repository.java b/api/src/main/java/revxrsal/zapper/repository/Repository.java index ec68be0..2f5de20 100644 --- a/api/src/main/java/revxrsal/zapper/repository/Repository.java +++ b/api/src/main/java/revxrsal/zapper/repository/Repository.java @@ -1,9 +1,11 @@ package revxrsal.zapper.repository; +import lombok.SneakyThrows; import org.jetbrains.annotations.NotNull; import revxrsal.zapper.Dependency; import java.io.File; +import java.net.MalformedURLException; import java.net.URL; /** @@ -46,10 +48,11 @@ public interface Repository { * * @return the local Maven repository */ + @SneakyThrows static @NotNull Repository mavenLocal() { String userHome = System.getProperty("user.home"); - File m2 = new File(userHome, ".m2"); - return new LocalMavenRepository(m2); + File repository = new File(userHome, ".m2" + File.separator + "repository"); + return maven(repository); } /** @@ -58,8 +61,9 @@ public interface Repository { * @param directory the local Maven directory * @return the local Maven repository */ - static @NotNull Repository mavenLocal(@NotNull File directory) { - return new LocalMavenRepository(directory); + @SneakyThrows + static @NotNull Repository maven(@NotNull File directory) { + return maven(directory.toURI().toURL().toString()); } /**