diff --git a/.gitignore b/.gitignore index 5b1f14b..ddf0d5e 100644 --- a/.gitignore +++ b/.gitignore @@ -116,3 +116,6 @@ run/ # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) !gradle-wrapper.jar + +# Ignore gradle configuration directory +.gradle/ diff --git a/pdm/src/main/java/me/bristermitten/pdm/DependencyLoader.java b/pdm/src/main/java/me/bristermitten/pdm/DependencyLoader.java index 0c1ceb3..9884ec8 100644 --- a/pdm/src/main/java/me/bristermitten/pdm/DependencyLoader.java +++ b/pdm/src/main/java/me/bristermitten/pdm/DependencyLoader.java @@ -36,6 +36,7 @@ public void loadDependency(@Nullable final File file) { return; } + if (loaded.contains(file)) { return; @@ -46,9 +47,9 @@ public void loadDependency(@Nullable final File file) ClassLoaderReflection.addURL(classLoader, file.toURI().toURL()); loaded.add(file); } - catch (MalformedURLException e) + catch (MalformedURLException exception) { - logger.log(Level.SEVERE, e, () -> "Could not load dependency from file " + file); + logger.log(Level.SEVERE, exception, () -> "Could not load dependency from file " + file); } } } diff --git a/pdm/src/main/java/me/bristermitten/pdm/DependencyManager.java b/pdm/src/main/java/me/bristermitten/pdm/DependencyManager.java index e812eaa..4fe6feb 100644 --- a/pdm/src/main/java/me/bristermitten/pdm/DependencyManager.java +++ b/pdm/src/main/java/me/bristermitten/pdm/DependencyManager.java @@ -1,7 +1,7 @@ package me.bristermitten.pdm; import me.bristermitten.pdm.repository.SpigotRepository; -import me.bristermitten.pdm.util.FileUtil; +import me.bristermitten.pdm.util.FileUtils; import me.bristermitten.pdmlibs.artifact.Artifact; import me.bristermitten.pdmlibs.artifact.ArtifactFactory; import me.bristermitten.pdmlibs.http.HTTPService; @@ -31,14 +31,13 @@ public class DependencyManager public static final String PDM_DIRECTORY_NAME = "PluginLibraries"; - @NotNull - private final PDMSettings settings; + @NotNull private final PDMSettings settings; - private final @NotNull RepositoryManager repositoryManager; - private final @NotNull MavenRepositoryFactory repositoryFactory; - private final @NotNull DependencyLoader loader; + @NotNull private final RepositoryManager repositoryManager; + @NotNull private final MavenRepositoryFactory repositoryFactory; + @NotNull private final DependencyLoader loader; private final ArtifactFactory artifactFactory = new ArtifactFactory(); - private final @NotNull HTTPService httpService; + @NotNull private final HTTPService httpService; /** * A Map that caches download tasks for artifacts. @@ -48,15 +47,16 @@ public class DependencyManager */ private final Map> downloadsInProgress = new ConcurrentHashMap<>(); private final Logger logger; - private final @NotNull DefaultParseProcess parseProcess; + @NotNull private final DefaultParseProcess parseProcess; private File pdmDirectory; - public DependencyManager(@NotNull final PDMSettings settings, @NotNull HTTPService httpService) + public DependencyManager(@NotNull final PDMSettings settings, @NotNull final HTTPService httpService) { this(settings, PDM_DIRECTORY_NAME, httpService); } - public DependencyManager(@NotNull final PDMSettings settings, @NotNull String outputDirectoryName, @NotNull HTTPService httpService) + public DependencyManager(@NotNull final PDMSettings settings, @NotNull final String outputDirectoryName, + @NotNull final HTTPService httpService) { this.settings = settings; this.logger = settings.getLoggerSupplier().apply(getClass().getName()); @@ -65,7 +65,6 @@ public DependencyManager(@NotNull final PDMSettings settings, @NotNull String ou this.repositoryManager = new RepositoryManager(settings.getLoggerSupplier().apply(RepositoryManager.class.getName())); - this.parseProcess = new DefaultParseProcess(artifactFactory, repositoryManager, httpService); this.repositoryFactory = new MavenRepositoryFactory(httpService, parseProcess); @@ -79,15 +78,16 @@ public void setOutputDirectoryName(@NotNull final String outputDirectoryName) try { this.pdmDirectory = new File(settings.getRootDirectory().getCanonicalFile(), outputDirectoryName).getCanonicalFile(); - FileUtil.createDirectoryIfNotPresent(pdmDirectory); + FileUtils.createDirectoryIfNotPresent(pdmDirectory); } - catch (IOException ex) + catch (IOException exception) { - throw new IllegalStateException(ex); + throw new IllegalStateException(exception); } } - public @NotNull RepositoryManager getRepositoryManager() + @NotNull + public RepositoryManager getRepositoryManager() { return repositoryManager; } @@ -99,36 +99,38 @@ SpigotRepository.SPIGOT_ALIAS, new SpigotRepository(httpService, parseProcess) ); } - public @NotNull ArtifactFactory getArtifactFactory() + @NotNull + public ArtifactFactory getArtifactFactory() { return artifactFactory; } - public @NotNull MavenRepositoryFactory getRepositoryFactory() + @NotNull + public MavenRepositoryFactory getRepositoryFactory() { return repositoryFactory; } - public CompletableFuture downloadAndLoad(@NotNull Artifact dependency) + @NotNull + public CompletableFuture downloadAndLoad(@NotNull final Artifact dependency) { - CompletableFuture downloaded = download(dependency); - - return downloaded.thenAccept(loader::loadDependency); + return download(dependency).thenAccept(loader::loadDependency); } - public CompletableFuture download(@NotNull Artifact dependency) + @NotNull + public CompletableFuture download(@NotNull final Artifact dependency) { - CompletableFuture inProgress = downloadsInProgress.get(dependency); + final CompletableFuture inProgress = downloadsInProgress.get(dependency); + if (inProgress != null) { return inProgress; } - File file = new File(pdmDirectory, dependency.getJarName()); - - CompletableFuture downloadingFuture = CompletableFuture.supplyAsync(() -> { - + final File file = new File(pdmDirectory, dependency.getJarName()); + final CompletableFuture downloadingFuture = CompletableFuture.supplyAsync(() -> { @Nullable final Repository containingRepo = getRepositoryFor(dependency); + if (containingRepo == null) { logger.warning(() -> "No repository found for " + dependency + ", it cannot be downloaded. Other plugins may not function properly."); @@ -152,8 +154,8 @@ public CompletableFuture download(@NotNull Artifact dependency) } return file; - }).exceptionally(t -> { - logger.log(Level.SEVERE, t, () -> "Could not download " + dependency); + }).exceptionally(throwable -> { + logger.log(Level.SEVERE, throwable, () -> "Could not download " + dependency); downloadsInProgress.remove(dependency); return file; }); @@ -164,24 +166,31 @@ public CompletableFuture download(@NotNull Artifact dependency) return downloadingFuture; } + @NotNull private Set> downloadTransitiveDependencies(@NotNull final Repository repository, @NotNull final Artifact artifact) { logger.fine(() -> "Downloading Transitive Dependencies for " + artifact); + Set transitiveDependencies = artifact.getTransitiveDependencies(); + if (transitiveDependencies == null) { transitiveDependencies = repository.getTransitiveDependencies(artifact); artifact.setTransitiveDependencies(transitiveDependencies); //To save potential repeated lookups } - return transitiveDependencies.stream().map(this::downloadAndLoad).collect(Collectors.toSet()); + return transitiveDependencies.stream() + .map(this::downloadAndLoad) + .collect(Collectors.toSet()); } + @Nullable private Repository getRepositoryFor(@NotNull final Artifact artifact) { if (artifact.getRepoAlias() != null) { - Repository byURL = repositoryManager.getByAlias(artifact.getRepoAlias()); + final Repository byURL = repositoryManager.getByAlias(artifact.getRepoAlias()); + if (byURL == null) { logger.warning(() -> "No repository configured for " + artifact.getRepoAlias()); @@ -196,14 +205,14 @@ private Repository getRepositoryFor(@NotNull final Artifact artifact) private void writeToFile(@NotNull final InputStream data, @NotNull final File file) { - FileUtil.createDirectoryIfNotPresent(pdmDirectory); + FileUtils.createDirectoryIfNotPresent(pdmDirectory); try { - FileUtil.writeFrom(file, data); + FileUtils.writeFrom(file, data); } - catch (IOException e) + catch (IOException exception) { - logger.log(Level.SEVERE, e, () -> "Could not copy file for " + file); + logger.log(Level.SEVERE, exception, () -> "Could not copy file for " + file); } } } diff --git a/pdm/src/main/java/me/bristermitten/pdm/PDMBuilder.java b/pdm/src/main/java/me/bristermitten/pdm/PDMBuilder.java index 806c5ff..9ffe6c2 100644 --- a/pdm/src/main/java/me/bristermitten/pdm/PDMBuilder.java +++ b/pdm/src/main/java/me/bristermitten/pdm/PDMBuilder.java @@ -19,19 +19,25 @@ /** * @author AlexL */ +@SuppressWarnings("UnusedReturnValue") public final class PDMBuilder { public static final String DEPENDENCIES_RESOURCE_NAME = "dependencies.json"; public static final String PLUGIN_CLASS_LOADER_NAME = "org.bukkit.plugin.java.PluginClassLoader"; private Function loggerFactory = Logger::getLogger; - private @Nullable InputStream dependenciesResource = null; - private @Nullable File rootDirectory = null; - private @Nullable URLClassLoader classLoader = null; - private @Nullable String applicationName = null; - private @Nullable String applicationVersion = null; + @Nullable private InputStream dependenciesResource = null; + @Nullable private File rootDirectory = null; + @Nullable private URLClassLoader classLoader = null; + @Nullable private String applicationName = null; + @Nullable private String applicationVersion = null; private CacheConfiguration cacheConfiguration = CacheConfiguration.builder().build(); + /** + * @deprecated Use one of the static factory methods; the direct replacement for this method is {@link #builder(Plugin)}. + * @param plugin Plugin implementation instance + */ + @Deprecated public PDMBuilder(@NotNull final Plugin plugin) { loggerFactory(clazz -> plugin.getLogger()); @@ -42,6 +48,11 @@ public PDMBuilder(@NotNull final Plugin plugin) applicationVersion(plugin.getDescription().getVersion()); } + /** + * @deprecated Use one of the static factory methods; the direct replacement for this method is {@link #builder(Class)} + * @param plugin Plugin implementation class + */ + @Deprecated public PDMBuilder(@NotNull final Class plugin) { Validate.isTrue(PLUGIN_CLASS_LOADER_NAME.equals(plugin.getClassLoader().getClass().getName()), "Plugin must be loaded with a PluginClassLoader"); @@ -54,48 +65,103 @@ public PDMBuilder(@NotNull final Class plugin) loggerFactory(clazz -> Logger.getLogger(description.getName())); } + /** + * @deprecated Do not construct an instance of this class manually. + */ + @Deprecated public PDMBuilder() { } - public @NotNull PDMBuilder loggerFactory(@NotNull Function loggerFactory) + @NotNull + public static PDMBuilder builder() { + return new PDMBuilder(); + } + + @NotNull + public static PDMBuilder builder(@NotNull final Plugin plugin) { + return new PDMBuilder() + .loggerFactory(clazz -> plugin.getLogger()) + .dependenciesResource(plugin.getResource(DEPENDENCIES_RESOURCE_NAME)) + .rootDirectory(plugin.getDataFolder().getParentFile()) + .classLoader((URLClassLoader) plugin.getClass().getClassLoader()) + .applicationName(plugin.getName()) + .applicationVersion(plugin.getDescription().getVersion()); + } + + @NotNull + public static PDMBuilder builder(@NotNull final Class plugin) { + Validate.isTrue(PLUGIN_CLASS_LOADER_NAME.equals(plugin.getClassLoader().getClass().getName()), "Plugin must be loaded with a PluginClassLoader"); + + final URLClassLoader classLoader = (URLClassLoader) plugin.getClassLoader(); + final PluginDescriptionFile description = Reflection.getFieldValue(classLoader, "description"); + + return builder() + .classLoader((URLClassLoader) plugin.getClassLoader()) + .dependenciesResource(classLoader.getResourceAsStream(DEPENDENCIES_RESOURCE_NAME)) + .rootDirectory(new File("./plugins")) + .applicationName(description.getName()) + .applicationVersion(description.getVersion()) + .loggerFactory(clazz -> Logger.getLogger(description.getName())); + } + + @NotNull + public static PluginDependencyManager of(@NotNull final Plugin plugin) { + return builder(plugin) + .build(); + } + + @NotNull + public static PluginDependencyManager of(@NotNull final Class plugin) { + return builder(plugin) + .build(); + } + + @NotNull + public PDMBuilder loggerFactory(@NotNull final Function loggerFactory) { this.loggerFactory = loggerFactory; return this; } - public @NotNull PDMBuilder dependenciesResource(InputStream dependenciesResource) + @NotNull + public PDMBuilder dependenciesResource(@NotNull final InputStream dependenciesResource) { this.dependenciesResource = dependenciesResource; return this; } - public @NotNull PDMBuilder rootDirectory(@NotNull File rootDirectory) + @NotNull + public PDMBuilder rootDirectory(@NotNull final File rootDirectory) { this.rootDirectory = rootDirectory; return this; } - public @NotNull PDMBuilder classLoader(@NotNull URLClassLoader classLoader) + @NotNull + public PDMBuilder classLoader(@NotNull URLClassLoader classLoader) { this.classLoader = classLoader; return this; } - public @NotNull PDMBuilder applicationName(@NotNull String applicationName) + @NotNull + public PDMBuilder applicationName(@NotNull String applicationName) { this.applicationName = applicationName; return this; } - public @NotNull PDMBuilder applicationVersion(@NotNull String applicationVersion) + @NotNull + public PDMBuilder applicationVersion(@NotNull String applicationVersion) { this.applicationVersion = applicationVersion; return this; } - public @NotNull PDMBuilder caching(@NotNull Consumer configuration) + @NotNull + public PDMBuilder caching(@NotNull Consumer configuration) { final CacheConfiguration.Builder builder = CacheConfiguration.builder(); configuration.accept(builder); diff --git a/pdm/src/main/java/me/bristermitten/pdm/PDMSettings.java b/pdm/src/main/java/me/bristermitten/pdm/PDMSettings.java index 7a2059e..d546ae8 100644 --- a/pdm/src/main/java/me/bristermitten/pdm/PDMSettings.java +++ b/pdm/src/main/java/me/bristermitten/pdm/PDMSettings.java @@ -1,5 +1,7 @@ package me.bristermitten.pdm; +import org.jetbrains.annotations.NotNull; + import java.io.File; import java.net.URLClassLoader; import java.util.function.Function; @@ -12,23 +14,27 @@ public class PDMSettings private final Function loggerSupplier; private final URLClassLoader classLoader; - public PDMSettings(File rootDirectory, Function loggerSupplier, URLClassLoader classLoader) + public PDMSettings(@NotNull final File rootDirectory, @NotNull final Function loggerSupplier, + @NotNull final URLClassLoader classLoader) { this.rootDirectory = rootDirectory; this.loggerSupplier = loggerSupplier; this.classLoader = classLoader; } + @NotNull public URLClassLoader getClassLoader() { return classLoader; } + @NotNull public File getRootDirectory() { return rootDirectory; } + @NotNull public Function getLoggerSupplier() { return loggerSupplier; diff --git a/pdm/src/main/java/me/bristermitten/pdm/PluginDependencyManager.java b/pdm/src/main/java/me/bristermitten/pdm/PluginDependencyManager.java index 46f422c..9403ed6 100644 --- a/pdm/src/main/java/me/bristermitten/pdm/PluginDependencyManager.java +++ b/pdm/src/main/java/me/bristermitten/pdm/PluginDependencyManager.java @@ -34,21 +34,14 @@ public final class PluginDependencyManager @NotNull private final Logger logger; - @NotNull - private final HTTPService httpService; - - - PluginDependencyManager(@NotNull final Function loggerFactory, - @Nullable final InputStream dependenciesResource, - @NotNull final File rootDirectory, - @NotNull final URLClassLoader classLoader, - @NotNull final String applicationName, - @NotNull final String applicationVersion, + PluginDependencyManager(@NotNull final Function loggerFactory, @Nullable final InputStream dependenciesResource, + @NotNull final File rootDirectory, @NotNull final URLClassLoader classLoader, + @NotNull final String applicationName, @NotNull final String applicationVersion, @NotNull final CacheConfiguration cacheConfiguration) { this.logger = loggerFactory.apply(getClass().getName()); - this.httpService = new HTTPService(applicationName, applicationVersion, cacheConfiguration); + final HTTPService httpService = new HTTPService(applicationName, applicationVersion, cacheConfiguration); final PDMSettings settings = new PDMSettings(rootDirectory, loggerFactory, classLoader); this.manager = new DependencyManager(settings, httpService); @@ -72,14 +65,15 @@ public void addRepository(@NotNull final String alias, @NotNull final String rep private void loadDependenciesFromFile(@NotNull final InputStream dependenciesResource) { final JSONDependencies jsonDependencies; - try (Reader reader = new InputStreamReader(dependenciesResource)) + + try (final Reader reader = new InputStreamReader(dependenciesResource)) { jsonDependencies = Constants.GSON.fromJson(reader, JSONDependencies.class); } - catch (@NotNull IOException | JsonParseException e) + catch (IOException | JsonParseException exception) { - logger.log(Level.WARNING, "Could not read dependencies.json", e); - e.printStackTrace(); + logger.log(Level.WARNING, "Could not read dependencies.json", exception); + exception.printStackTrace(); return; } @@ -88,22 +82,23 @@ private void loadDependenciesFromFile(@NotNull final InputStream dependenciesRes logger.log(Level.WARNING, "jsonDependencies was null - Invalid JSON?"); return; } + final Map repositories = jsonDependencies.getRepositories(); - if (repositories != null) - { - repositories.forEach((alias, repo) -> { - final Repository existing = manager.getRepositoryManager().getByAlias(alias); - if (existing != null) - { - logger.fine(() -> "Will not redefine repository " + alias); - return; - } - final Repository repository = manager.getRepositoryFactory().create(repo); - manager.getRepositoryManager().addRepository(alias, repository); - - logger.fine(() -> "Made new repository named " + alias); - }); - } + + repositories.forEach((alias, repo) -> { + final Repository existing = manager.getRepositoryManager().getByAlias(alias); + + if (existing != null) + { + logger.fine(() -> "Will not redefine repository " + alias); + return; + } + + final Repository repository = manager.getRepositoryFactory().create(repo); + manager.getRepositoryManager().addRepository(alias, repository); + + logger.fine(() -> "Made new repository named " + alias); + }); jsonDependencies.getDependencies().forEach(dto -> { final Artifact dependency = manager.getArtifactFactory().toArtifact(dto); @@ -136,6 +131,7 @@ public CompletableFuture loadAllDependencies() { logger.warning("There were no dependencies to load! This might be intentional, but if not, check your dependencies configuration!"); } + return CompletableFuture.allOf(requiredDependencies.stream() .map(manager::downloadAndLoad) .toArray(CompletableFuture[]::new)); @@ -151,12 +147,14 @@ public CompletableFuture loadAllDependencies() * @return a {@link CompletableFuture} that is completed when dependency downloading finishes. * @since 0.0.22 */ - public @NotNull CompletableFuture> downloadAllDependencies() + @NotNull + public CompletableFuture> downloadAllDependencies() { if (requiredDependencies.isEmpty()) { logger.warning("There were no dependencies to download! This might be intentional, but if not, check your dependencies configuration!"); } + return CompletableFuture.supplyAsync( () -> requiredDependencies.stream() .map(manager::download) diff --git a/pdm/src/main/java/me/bristermitten/pdm/dependency/JSONDependencies.java b/pdm/src/main/java/me/bristermitten/pdm/dependency/JSONDependencies.java index 541cf45..6e700fb 100644 --- a/pdm/src/main/java/me/bristermitten/pdm/dependency/JSONDependencies.java +++ b/pdm/src/main/java/me/bristermitten/pdm/dependency/JSONDependencies.java @@ -1,6 +1,7 @@ package me.bristermitten.pdm.dependency; import me.bristermitten.pdmlibs.artifact.ArtifactDTO; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Map; @@ -9,24 +10,29 @@ public class JSONDependencies { + @NotNull private final Map repositories; + @NotNull private final Set dependencies; @Nullable private final String dependenciesDirectory; - public JSONDependencies(Map repositories, Set dependencies, @Nullable String dependenciesDirectory) + public JSONDependencies(@NotNull final Map repositories, @NotNull final Set dependencies, + @Nullable final String dependenciesDirectory) { this.repositories = repositories; this.dependencies = dependencies; this.dependenciesDirectory = dependenciesDirectory; } + @NotNull public Map getRepositories() { return repositories; } + @NotNull public Set getDependencies() { return dependencies; diff --git a/pdm/src/main/java/me/bristermitten/pdm/repository/SpigotRepository.java b/pdm/src/main/java/me/bristermitten/pdm/repository/SpigotRepository.java index a23badc..e356c25 100644 --- a/pdm/src/main/java/me/bristermitten/pdm/repository/SpigotRepository.java +++ b/pdm/src/main/java/me/bristermitten/pdm/repository/SpigotRepository.java @@ -1,11 +1,13 @@ package me.bristermitten.pdm.repository; +import com.google.common.collect.ImmutableSet; import me.bristermitten.pdmlibs.artifact.Artifact; import me.bristermitten.pdmlibs.http.HTTPService; import me.bristermitten.pdmlibs.pom.ParseProcess; import me.bristermitten.pdmlibs.repository.MavenRepository; import org.bukkit.Bukkit; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; import java.util.*; import java.util.logging.Logger; @@ -14,61 +16,59 @@ public final class SpigotRepository extends MavenRepository { public static final String SPIGOT_ALIAS = "spigot-repo"; - private static final Set SPIGOT_DEPENDENCY_GROUPS = Collections.unmodifiableSet( - new HashSet<>( - Arrays.asList( - "net.minecraft", - "org.spigotmc", - "org.bukkit", - "com.destroystokyo.paper" - ) - ) - ); - private static final Set SPIGOT_DEPENDENCY_ARTIFACTS = Collections.unmodifiableSet( - new HashSet<>( - Arrays.asList( - "server", - "spigot", - "spigot-api", - "bukkit", - "craftbukkit", - "paper-api" - ) - ) - ); - @NotNull - private final Logger logger = Logger.getLogger("SpigotRepository"); + @Unmodifiable private static final Set SPIGOT_DEPENDENCY_GROUPS = new ImmutableSet.Builder() + .add( + "net.minecraft", + "org.spigotmc", + "org.bukkit", + "com.destroystokyo.paper" + ).build(); + @Unmodifiable private static final Set SPIGOT_DEPENDENCY_ARTIFACTS = new ImmutableSet.Builder() + .add( + "server", + "spigot", + "spigot-api", + "bukkit", + "craftbukkit", + "paper-api" + ).build(); + private static final Logger LOGGER = Logger.getLogger("SpigotRepository"); - public SpigotRepository(@NotNull HTTPService httpService, @NotNull ParseProcess> parseProcess) + public SpigotRepository(@NotNull final HTTPService httpService, @NotNull final ParseProcess> parseProcess) { super(SPIGOT_ALIAS, httpService, parseProcess); } + @NotNull @Override - public @NotNull Set getTransitiveDependencies(@NotNull Artifact dependency) + public Set getTransitiveDependencies(@NotNull final Artifact dependency) { return Collections.emptySet(); } @Override - public boolean contains(@NotNull Artifact artifact) + public boolean contains(@NotNull final Artifact artifact) { return isSpigotDependency(artifact); } + @NotNull @Override - public byte @NotNull [] download(@NotNull Artifact dependency) + public byte @NotNull [] download(@NotNull final Artifact dependency) { - if (!dependency.getVersion().contains(Bukkit.getVersion())) + final String version = Bukkit.getVersion(); + + if (!dependency.getVersion().contains(version)) { - logger.warning(() -> "Dependency on " + dependency + " does not match server version of " + Bukkit.getVersion() + ". This could cause version problems."); + LOGGER.warning(() -> "Dependency on " + dependency + " does not match server version of " + version + ". This could cause version problems."); } + return new byte[0]; } - private boolean isSpigotDependency(@NotNull Artifact dependency) + private boolean isSpigotDependency(@NotNull final Artifact dependency) { return SPIGOT_DEPENDENCY_GROUPS.contains(dependency.getGroupId().toLowerCase()) && SPIGOT_DEPENDENCY_ARTIFACTS.contains(dependency.getArtifactId().toLowerCase()); @@ -82,12 +82,13 @@ public boolean equals(Object o) if (!(o instanceof SpigotRepository)) return false; if (!super.equals(o)) return false; SpigotRepository that = (SpigotRepository) o; - return logger.equals(that.logger); + //todo: what the fuck is this? + return LOGGER.equals(that.LOGGER); } @Override public int hashCode() { - return Objects.hash(super.hashCode(), logger); + return Objects.hash(super.hashCode(), LOGGER); } } diff --git a/pdm/src/main/java/me/bristermitten/pdm/util/ClassLoaderReflection.java b/pdm/src/main/java/me/bristermitten/pdm/util/ClassLoaderReflection.java index 53e4112..393b4c4 100644 --- a/pdm/src/main/java/me/bristermitten/pdm/util/ClassLoaderReflection.java +++ b/pdm/src/main/java/me/bristermitten/pdm/util/ClassLoaderReflection.java @@ -10,38 +10,39 @@ public class ClassLoaderReflection { - private static final Method addUrlMethod; + private static final Method ADD_URL_METHOD; static { - Method addURL; + final Method addURL; + try { addURL = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); addURL.setAccessible(true); } - catch (NoSuchMethodException e) + catch (NoSuchMethodException exception) { - addURL = null; - e.printStackTrace(); + throw new AssertionError(exception); } - addUrlMethod = addURL; + + ADD_URL_METHOD = addURL; } private ClassLoaderReflection() { - + throw new AssertionError("This class cannot be instantiated."); } - public static void addURL(URLClassLoader classLoader, URL url) + public static void addURL(@NotNull final URLClassLoader classLoader, @NotNull final URL url) { try { - addUrlMethod.invoke(classLoader, url); + ADD_URL_METHOD.invoke(classLoader, url); } - catch (@NotNull IllegalAccessException | InvocationTargetException e) + catch (IllegalAccessException | InvocationTargetException exception) { - throw new IllegalArgumentException(e); + throw new IllegalArgumentException(exception); } } } diff --git a/pdm/src/main/java/me/bristermitten/pdm/util/Constants.java b/pdm/src/main/java/me/bristermitten/pdm/util/Constants.java index f492761..264bcc4 100644 --- a/pdm/src/main/java/me/bristermitten/pdm/util/Constants.java +++ b/pdm/src/main/java/me/bristermitten/pdm/util/Constants.java @@ -5,8 +5,10 @@ public class Constants { - private Constants() { - + private Constants() + { + throw new AssertionError("This class cannot be instantiated."); } + public static final Gson GSON = new Gson(); } diff --git a/pdm/src/main/java/me/bristermitten/pdm/util/FileUtil.java b/pdm/src/main/java/me/bristermitten/pdm/util/FileUtils.java similarity index 88% rename from pdm/src/main/java/me/bristermitten/pdm/util/FileUtil.java rename to pdm/src/main/java/me/bristermitten/pdm/util/FileUtils.java index 6d7d259..fc958e0 100644 --- a/pdm/src/main/java/me/bristermitten/pdm/util/FileUtil.java +++ b/pdm/src/main/java/me/bristermitten/pdm/util/FileUtils.java @@ -9,11 +9,12 @@ import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; -public final class FileUtil +public final class FileUtils { - private FileUtil() + private FileUtils() { + throw new AssertionError("This class cannot be instantiated."); } /**