Skip to content
Merged
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 build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
val javaVersion = 25

group = "net.hypejet"
version = releaseTag() ?: "1.0.2-SNAPSHOT"
version = releaseTag() ?: "1.0.3-SNAPSHOT"
description = "A Java library making modular programming easier"

repositories {
Expand Down
27 changes: 21 additions & 6 deletions src/main/java/net/hypejet/modules/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,28 @@
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* A module to be loaded with {@link ModuleManager}.
*
* @param <E> the type of environment that this module runs on
* @since 1.0
* @since 1.0.0
* @see ModuleManager
*/
@NullMarked
@AbstractModule
public abstract class Module<E> {

Check warning on line 34 in src/main/java/net/hypejet/modules/Module.java

View workflow job for this annotation

GitHub Actions / build

use of default constructor, which does not provide a comment

private @Nullable ModuleManager<? extends E> moduleManager;
private @Nullable Logger logger;

/**
* Gets whether this module is currently loaded.
*
* @return {@code true} if the module is loaded, {@code false} otherwise
* @since 1.0
* @since 1.0.0
*/
public final boolean isLoaded() {
return this.moduleManager != null;
Expand All @@ -50,7 +53,7 @@
*
* @return the module manager
* @throws IllegalStateException if this module is not loaded
* @since 1.0
* @since 1.0.0
*/
public final ModuleManager<? extends E> getModuleManager() {
if (!this.isLoaded())
Expand All @@ -65,25 +68,37 @@
*
* @return the environment
* @throws IllegalStateException if this module is not loaded
* @since 1.0
* @since 1.0.0
* @see #getModuleManager()
*/
public final E getEnvironment() {
return this.getModuleManager().getEnvironment();
}

/**
* Gets the logger of this module.
*
* @return the logger
* @since 1.0.3
*/
public final Logger getLogger() {
if (this.logger == null)
this.logger = LoggerFactory.getLogger(this.getClass());
return this.logger;
}

/**
* Called when this module becomes loaded.
*
* @since 1.0
* @since 1.0.0
*/
@ApiStatus.OverrideOnly
protected void load() {}

/**
* Called when this module becomes unloaded.
*
* @since 1.0
* @since 1.0.0
*/
@ApiStatus.OverrideOnly
protected void unload() {}
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/net/hypejet/modules/ModuleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* A manager of modules.
*
* @param <E> the type of environment that this module manager runs on
* @since 1.0
* @since 1.0.0
* @see Module
*/
@NullMarked
Expand All @@ -58,7 +58,7 @@ public final class ModuleManager<E> {
*
* @return the environment
* @throws IllegalStateException if this module manager is not loaded
* @since 1.0
* @since 1.0.0
*/
public E getEnvironment() {
this.ensureLoaded();
Expand All @@ -76,7 +76,7 @@ public E getEnvironment() {
* @return the module instance, {@code null} if the module was not loaded
* @param <M> the type of module instance to return
* @throws IllegalStateException if this module manager is not loaded
* @since 1.0
* @since 1.0.0
* @see AbstractModule
*/
public <M extends Module<?>> @Nullable M getModule(Class<M> clazz) {
Expand All @@ -91,7 +91,7 @@ public E getEnvironment() {
* @return the module instance
* @param <M> the type of module instance to return
* @throws IllegalStateException if either this module manager or the specified module is not loaded
* @since 1.0
* @since 1.0.2
* @see #getModule(Class)
*/
public <M extends Module<?>> M getModuleOrThrow(Class<M> clazz) {
Expand All @@ -105,7 +105,7 @@ public <M extends Module<?>> M getModuleOrThrow(Class<M> clazz) {
*
* @return the modules that are currently loaded
* @throws IllegalStateException if this module manager is not loaded
* @since 1.0
* @since 1.0.0
*/
public Collection<? extends Module<? super E>> getModules() {
this.ensureLoaded();
Expand All @@ -122,7 +122,7 @@ public Collection<? extends Module<? super E>> getModules() {
* @param clazz the class of the module to check
* @return {@code true} if the module was loaded, {@code false} otherwise
* @throws IllegalStateException if this module manager is not loaded
* @since 1.0
* @since 1.0.0
* @see AbstractModule
*/
public boolean isModuleLoaded(Class<? extends Module<?>> clazz) {
Expand All @@ -133,7 +133,7 @@ public boolean isModuleLoaded(Class<? extends Module<?>> clazz) {
* Loads all modules created by this module manager.
*
* @throws IllegalStateException if this module manager is unloaded
* @since 1.0
* @since 1.0.0
*/
public void load() {
if (this.state == State.UNLOADED)
Expand All @@ -158,7 +158,7 @@ public void load() {
* Unloads all modules loaded by this module manager.
*
* @throws IllegalStateException if this module manager is not loaded
* @since 1.0
* @since 1.0.0
*/
public void unload() {
this.ensureLoaded();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/hypejet/modules/ModuleRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
* A registry of modules to be created and loaded by a {@link ModuleManager}.
*
* @param <E> the type of environment that the module manager is going to run on
* @since 1.0
* @since 1.0.0
* @see ModuleManager
*/
@NullMarked
public final class ModuleRegistry<E> {

Check warning on line 40 in src/main/java/net/hypejet/modules/ModuleRegistry.java

View workflow job for this annotation

GitHub Actions / build

use of default constructor, which does not provide a comment

private static final Logger LOGGER = LoggerFactory.getLogger(ModuleRegistry.class);

Expand All @@ -54,7 +54,7 @@
* @param supplier the supplier of the module instance
* @return this module registry
* @param <M> the type of module that is being registered
* @since 1.0
* @since 1.0.0
*/
public <M extends Module<? super E>> ModuleRegistry<E> register(Class<M> clazz, Supplier<M> supplier) {
if (this.moduleEntries.containsKey(clazz) || this.superclassModules.containsKey(clazz)) {
Expand Down Expand Up @@ -115,7 +115,7 @@
* @return the created module manager
* @throws CircularModuleDependenciesException if the module manager could not be created
* because circular module dependencies were detected
* @since 1.0
* @since 1.0.0
*/
public ModuleManager<E> createModuleManager(E environment) {
ModuleLoadOrder<E> loadOrder = new ModuleLoadOrder<>(this.moduleEntries, this.superclassModules);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* {@link ModuleManager#getModule(Class)}, as well as {@link ModuleManager#isModuleLoaded(Class)}, though the list
* may be incomplete.</p>
*
* @since 1.0
* @since 1.0.0
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface AbstractModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* required or not can be overridden by subclasses through specifying them again using this annotation.
* It is even possible to remove a dependency by subclasses, see {@link #removed()} for more information.</p>
*
* @since 1.0
* @since 1.0.0
* @see AbstractModule
*/
@NullMarked
Expand All @@ -47,7 +47,7 @@
* The modules that are required by the module annotated with this annotation.
*
* @return the classes of required modules
* @since 1.0
* @since 1.0.0
*/
Class<? extends Module>[] required() default {};

Expand All @@ -56,7 +56,7 @@
* with this annotation if they are present, but are not strictly required.
*
* @return the classes of optional modules
* @since 1.0
* @since 1.0.0
*/
Class<? extends Module>[] optional() default {};

Expand All @@ -67,7 +67,7 @@
* a dependency, while the annotating class does not.</p>
*
* @return the classes of modules that are not dependencies
* @since 1.0
* @since 1.0.0
*/
Class<? extends Module>[] removed() default {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* An exception thrown when the module system detects circular module dependencies.
*
* @since 1.0
* @since 1.0.0
* @see RuntimeException
*/
public final class CircularModuleDependenciesException extends RuntimeException {
Expand All @@ -29,7 +29,7 @@ public final class CircularModuleDependenciesException extends RuntimeException
*
* <p><strong>For internal use only.</strong></p>
*
* @since 1.0
* @since 1.0.0
*/
@ApiStatus.Internal
public CircularModuleDependenciesException() {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/net/hypejet/modules/AbstractModulesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* A test of getting abstract modules, their superclass modules, and modules extending them.
*
* @since 1.0
* @since 1.0.0
* @see AbstractModule
*/
@NullMarked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/**
* A test of creating module managers containing circular module dependencies.
*
* @since 1.0
* @since 1.0.0
* @see ModuleManager
*/
@NullMarked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/**
* A test of loading modules that depend on other modules and order of such loading.
*
* @since 1.0
* @since 1.0.0
* @see Module
*/
@NullMarked
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/net/hypejet/modules/ModuleLoadingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/**
* A test of module manager state after loading modules.
*
* @since 1.0
* @since 1.0.0
* @see Module
* @see ModuleManager
*/
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/net/hypejet/modules/ModuleUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/**
* A test of internal utilities used by the library.
*
* @since 1.0
* @since 1.0.0
*/
@NullMarked
public final class ModuleUtilsTest {
Expand Down
Loading