Skip to content

Commit eb7a99d

Browse files
committed
Improved how we handle dependencies, no longer need to worry about a "sorted-libraries" folder...
1 parent ceeea76 commit eb7a99d

File tree

4 files changed

+45
-17
lines changed

4 files changed

+45
-17
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ apply plugin: 'com.gradleup.shadow'
2828

2929

3030
group = 'org.mangorage'
31-
version = getLatestGitTag() + "." + getLatestGitVersion()
31+
version = getLatestGitTag() + "." + getLatestGitVersion() + "-beta.1"
3232

3333
println("Version -> " + version)
3434

src/main/java/org/mangorage/bootstrap/internal/JarHandler.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,25 @@ public static Result resolveModuleName(Path jarPath) {
5757
);
5858
}
5959

60+
try {
61+
System.out.println("MAYBE!?");
62+
final var found = ModuleFinder.of(jarPath).findAll();
63+
System.out.println(found);
64+
if (found != null) {
65+
final var foundModule = found.stream().findAny();
66+
if (foundModule.isPresent())
67+
System.out.println(foundModule.get());
68+
return new Result(
69+
foundModule.get().descriptor().name(),
70+
ModuleNameOrigin.MODULE_FINDER,
71+
jarPath
72+
);
73+
}
74+
} catch (Exception ignore) {
75+
ignore.printStackTrace();
76+
}
77+
78+
6079
String symbolicName = manifest.getMainAttributes()
6180
.getValue("Bundle-SymbolicName");
6281

@@ -72,10 +91,14 @@ public static Result resolveModuleName(Path jarPath) {
7291

7392
// 3. Fallback: filename heuristic (aka desperation mode)
7493
String filename = jarPath.getFileName().toString();
94+
95+
String cleanedName = filename
96+
.replaceAll("-[\\d\\.]+.*\\.jar$", "") // Remove version and extension
97+
.replaceAll("\\.jar$", "") // Remove extension if no version
98+
.replace('-', '.'); // Convert hyphens to dots
99+
75100
return new Result(
76-
filename
77-
.replaceAll("-[\\d\\.]+.*\\.jar$", "")
78-
.replaceAll("\\.jar$", ""),
101+
cleanedName,
79102
ModuleNameOrigin.GUESSED,
80103
jarPath
81104
);

src/main/java/org/mangorage/bootstrap/internal/MangoBotLaunchTarget.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ public void launch(ModuleLayer parent, String[] args) throws Throwable {
6969
final var librariesPath = Path.of("libraries");
7070
final var pluginsPath = Path.of("plugins");
7171

72-
7372
final Map<String, List<Result>> dependencies = DependencyHandler.scanPackages(pluginsPath.toAbsolutePath(), librariesPath.toAbsolutePath());
7473
final Map<String, Result> finalDependencies = new HashMap<>();
7574

@@ -80,23 +79,28 @@ public void launch(ModuleLayer parent, String[] args) throws Throwable {
8079
finalDependencies.put(bestResult.name(), bestResult);
8180
});
8281

83-
Path sortedLibraries = Path.of("sorted-libraries").toAbsolutePath();
84-
final var list = finalDependencies.entrySet()
85-
.stream()
86-
.map(entry -> entry.getValue().jar())
87-
.toList();
88-
89-
copyFilesToDirectory(list, sortedLibraries);
90-
9182
Set<String> moduleNames = new HashSet<>();
9283
moduleNames.addAll(Util.getModuleNames(pluginsPath));
93-
moduleNames.addAll(Util.getModuleNames(sortedLibraries));
84+
moduleNames.addAll(finalDependencies.keySet());
9485

95-
moduleNames.remove("kotlin-stdlib-common");
86+
System.out.println("Module Info");
87+
System.out.println("----------------------------------------------");
88+
moduleNames.forEach(name -> {
89+
System.out.println("Module Name -> " + name);
90+
});
91+
System.out.println("----------------------------------------------");
92+
System.out.println("Module -> Jar Info");
93+
System.out.println("----------------------------------------------");
94+
finalDependencies.forEach((module, result) -> {
95+
System.out.println("Module -> " + module + " Jar -> " + result.jar() + " Name -> " + result.name() + " Origin -> " + result.origin());
96+
});
97+
System.out.println("----------------------------------------------");
9698

9799
final var moduleCfg = Configuration.resolve(
98100
ModuleFinder.of(
99-
sortedLibraries
101+
finalDependencies.entrySet().stream()
102+
.map(entry -> entry.getValue().jar())
103+
.toArray(Path[]::new)
100104
),
101105
List.of(
102106
parent.configuration()

src/main/java/org/mangorage/bootstrap/internal/util/ModuleNameOrigin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ public enum ModuleNameOrigin {
55
MULTI_RELEASE, // HIGH
66
MANIFEST, // MEDIUM
77
MANIFEST_BUNDLE_SYMBOLIC_NAME, // LOW
8-
GUESSED // LOWEST
8+
MODULE_FINDER, // LOWEST
9+
GUESSED // TOTAL LOWEST
910
}

0 commit comments

Comments
 (0)