-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redesign module system with better dependencies
- Loading branch information
1 parent
e69aa43
commit 2da99e4
Showing
18 changed files
with
602 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/dev/emortal/api/modules/annotation/Dependency.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package dev.emortal.api.modules.annotation; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
public @interface Dependency { | ||
|
||
@NotNull String name(); | ||
|
||
boolean required() default true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/dev/emortal/api/modules/env/BasicModuleEnvironment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/dev/emortal/api/modules/extension/ModuleCandidate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package dev.emortal.api.modules.extension; | ||
|
||
import dev.emortal.api.modules.LoadableModule; | ||
import dev.emortal.api.modules.Module; | ||
import dev.emortal.api.modules.annotation.ModuleData; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public record ModuleCandidate(@NotNull Class<? extends Module> clazz, @NotNull LoadableModule.Creator creator, @NotNull ModuleData data) { | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/dev/emortal/api/modules/extension/ModuleCandidateResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package dev.emortal.api.modules.extension; | ||
|
||
import dev.emortal.api.modules.LoadableModule; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
public interface ModuleCandidateResolver { | ||
|
||
@NotNull List<ModuleCandidate> resolveCandidates(@NotNull Collection<LoadableModule> modules); | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/dev/emortal/api/modules/extension/ModuleEnvironmentProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package dev.emortal.api.modules.extension; | ||
|
||
import dev.emortal.api.modules.ModuleProvider; | ||
import dev.emortal.api.modules.annotation.ModuleData; | ||
import dev.emortal.api.modules.env.ModuleEnvironment; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public interface ModuleEnvironmentProvider { | ||
|
||
@NotNull ModuleEnvironment create(@NotNull ModuleData data, @NotNull ModuleProvider provider); | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/dev/emortal/api/modules/extension/ModuleSorter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package dev.emortal.api.modules.extension; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
public interface ModuleSorter { | ||
|
||
@NotNull List<ModuleCandidate> sortModules(@NotNull Collection<ModuleCandidate> modules); | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/dev/emortal/api/modules/internal/DefaultModuleCandidateResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package dev.emortal.api.modules.internal; | ||
|
||
import dev.emortal.api.modules.LoadableModule; | ||
import dev.emortal.api.modules.annotation.ModuleData; | ||
import dev.emortal.api.modules.extension.ModuleCandidate; | ||
import dev.emortal.api.modules.extension.ModuleCandidateResolver; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
public final class DefaultModuleCandidateResolver implements ModuleCandidateResolver { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultModuleCandidateResolver.class); | ||
|
||
@Override | ||
public @NotNull List<ModuleCandidate> resolveCandidates(@NotNull Collection<LoadableModule> modules) { | ||
List<ModuleCandidate> result = new ArrayList<>(); | ||
|
||
for (LoadableModule module : modules) { | ||
ModuleData data = module.clazz().getDeclaredAnnotation(ModuleData.class); | ||
if (data == null) { | ||
LOGGER.error("ModuleData annotation not found on module class {}", module.clazz().getSimpleName()); | ||
continue; | ||
} | ||
|
||
result.add(new ModuleCandidate(module.clazz(), module.creator(), data)); | ||
} | ||
|
||
return result; | ||
} | ||
} |
Oops, something went wrong.