@@ -23,30 +23,12 @@ public abstract class StickyNoteLoader {
2323 public static final Map <String , String > relocations = new HashMap <>();
2424
2525 // name - group
26- public static final Map <String , String > transitiveLoadExclusion = new HashMap <>();
27-
2826 private static final String LIB_FOLDER = "lib" ;
2927
3028 private final List <String > transitiveExcluded = Arrays .asList ("xseries" , "stickynote" );
3129
3230 protected StickyNoteLoader (String projectName ) throws ClassNotFoundException , NoSuchFieldException , IllegalAccessException {
3331 this .projectName = projectName ;
34-
35- transitiveLoadExclusion .put ("kotlinx-coroutines-core-jvm" , "org{}jetbrains{}kotlinx" .replace ("{}" , "." ));
36- transitiveLoadExclusion .put ("kotlinx-coroutines-core" , "org{}jetbrains{}kotlinx" .replace ("{}" , "." ));
37- transitiveLoadExclusion .put ("kotlin-reflect" , "org{}jetbrains{}kotlin" .replace ("{}" , "." ));
38- transitiveLoadExclusion .put ("kotlin-stdlib" , "org{}jetbrains{}kotlin" .replace ("{}" , "." ));
39- transitiveLoadExclusion .put ("kotlin-stdlib-common" , "org{}jetbrains{}kotlin" .replace ("{}" , "." ));
40- transitiveLoadExclusion .put ("kotlin-stdlib-jdk7" , "org{}jetbrains{}kotlin" .replace ("{}" , "." ));
41- transitiveLoadExclusion .put ("kotlin-stdlib-jdk8" , "org{}jetbrains{}kotlin" .replace ("{}" , "." ));
42- transitiveLoadExclusion .put ("annotations" , "org{}jetbrains" .replace ("{}" , "." ));
43- transitiveLoadExclusion .put ("checker-qual" , "org{}checkerframework" .replace ("{}" , "." ));
44- transitiveLoadExclusion .put ("javassist" , "org{}javassist" .replace ("{}" , "." ));
45- transitiveLoadExclusion .put ("snakeyaml" , "org{}yaml" .replace ("{}" , "." ));
46- transitiveLoadExclusion .put ("gson" , "com{}google{}gson" .replace ("{}" , "." ));
47- transitiveLoadExclusion .put ("error_prone_annotations" , "com{}google{}errorprone" .replace ("{}" , "." ));
48- transitiveLoadExclusion .put ("geantyref" , "io{}leangen{}geantyref" .replace ("{}" , "." ));
49- transitiveLoadExclusion .put ("sqlite-jdbc" , "org{}xerial" .replace ("{}" , "." ));
5032 }
5133
5234 protected abstract void onComplete ();
@@ -80,32 +62,16 @@ public void load(String id, File dataDirectory, Logger logger, LibraryManager li
8062 TransitiveDependencyHelper transitiveDependencyHelper = new TransitiveDependencyHelper (libraryManager , libDirectory .toPath ());
8163
8264 relocations .put ("com{}mysql" , relocationTo + "{}lib{}mysql" );
83- // relocations.put("kotlinx{}coroutines", relocationTo + "{}lib{}kotlinx{}coroutines");
84- relocations .put ("org{}jetbrains{}exposed" , relocationTo + "{}lib{}exposed" );
85- // relocations.put("org{}yaml", relocationTo + "{}lib{}yaml");
86- // relocations.put("org{}spongepowered{}configurate", relocationTo + "{}lib{}configurate");
87- // relocations.put("org{}slf4j", relocationTo + "{}lib{}slf4j");
88-
89- boolean hasSQLite = false ;
90- try {
91- Class .forName ("org{}sqlite{}JDBC" .replace ("{}" , "." ));
92- hasSQLite = true ;
93- } catch (Exception ignored ) {}
94-
95- if (hasSQLite ) {
96- dependencies .removeIf (dependency -> dependency .getName ().equals ("sqlite-jdbc" ));
97- }
65+ relocations .put ("kotlinx{}coroutines" , relocationTo + "{}lib{}kotlinx{}coroutines" );
9866
9967 DependencyCache dependencyCache = new DependencyCache (id , libDirectory );
10068 Set <Dependency > cachedDependencies = new HashSet <>(dependencyCache .loadCache ());
10169 Set <Dependency > missingDependencies = new HashSet <>(getMissingDependencies (dependencies , cachedDependencies ));
10270
103- if (hasSQLite ) {
104- cachedDependencies .removeIf (dependency -> dependency .getName ().equals ("sqlite-jdbc" ));
105- missingDependencies .removeIf (dependency -> dependency .getName ().equals ("sqlite-jdbc" ));
106- }
107-
108- for (Dependency cachedDependency : dependencies ) {
71+ List <Dependency > allDependencies = new ArrayList <>();
72+ allDependencies .addAll (dependencies );
73+ allDependencies .addAll (getTransitiveDependencies (stickyNotes ));
74+ for (Dependency cachedDependency : allDependencies ) {
10975 String name = cachedDependency .getName ();
11076 String group = cachedDependency .getGroup ();
11177 if (exclusions .stream ().anyMatch (excluded -> cachedDependency .getName ().contains (excluded ))) continue ;
@@ -135,8 +101,6 @@ public void load(String id, File dataDirectory, Logger logger, LibraryManager li
135101
136102 long endTime = System .currentTimeMillis ();
137103 logger .info ("Loaded " + dependencies .size () + " library in " + (endTime - startTime ) + " ms." );
138- updateDependencyCache (libDirectory , new HashSet <>(dependencies ));
139-
140104 onComplete ();
141105 } catch (Exception e ) {
142106 e .printStackTrace ();
@@ -166,8 +130,6 @@ private Set<Dependency> getMissingDependencies(List<Dependency> dependencies, Se
166130 }
167131
168132 private void loadMissingDependencies (File libDirectory , String id , Logger logger , LibraryManager libraryManager , TransitiveDependencyHelper transitiveDependencyHelper , DependencyCache dependencyCache , List <Dependency > dependencies , Set <Dependency > missingDependencies , String relocationFrom , String relocationTo ) throws InterruptedException , ExecutionException {
169- updateDependencyCache (libDirectory , new HashSet <>(dependencies ));
170-
171133 List <CompletableFuture <Void >> resolveFutures = dependencies .stream ()
172134 .map (dependency -> resolveTransitiveDependenciesAsync (id , transitiveDependencyHelper , dependency ))
173135 .toList ();
@@ -239,6 +201,27 @@ private List<Dependency> getDependencies(Class<?> stickyNotes) {
239201 }).toList ();
240202 }
241203
204+ private List <Dependency > getTransitiveDependencies (Class <?> stickyNotes ) {
205+ return Arrays .stream (stickyNotes .getFields ())
206+ .filter (field -> field .getName ().startsWith ("TRANSITIVE_DEPENDENCY_" ))
207+ .map (field -> {
208+ try {
209+ Object dependencyObject = field .get (null );
210+ Class <?> dependencyFieldClass = dependencyObject .getClass ();
211+ return new Dependency (
212+ (String ) dependencyFieldClass .getMethod ("getGroup" ).invoke (dependencyObject ),
213+ (String ) dependencyFieldClass .getMethod ("getName" ).invoke (dependencyObject ),
214+ (String ) dependencyFieldClass .getMethod ("getVersion" ).invoke (dependencyObject ),
215+ (String ) dependencyFieldClass .getMethod ("getRelocation" ).invoke (dependencyObject ),
216+ (boolean ) dependencyFieldClass .getMethod ("isStickyLoad" ).invoke (dependencyObject )
217+ );
218+ } catch (Exception e ) {
219+ e .printStackTrace ();
220+ return null ;
221+ }
222+ }).toList ();
223+ }
224+
242225 private List <String > getRepositories (Class <?> stickyNotes ) {
243226 return Arrays .stream (stickyNotes .getFields ())
244227 .filter (field -> field .getName ().startsWith ("REPOSITORY_" ))
@@ -291,11 +274,7 @@ private Library.Builder createLibraryBuilder(Dependency dependency) {
291274 .artifactId (dependency .getName ())
292275 .version (dependency .getVersion ())
293276 .resolveTransitiveDependencies (false );
294-
295- for (Map .Entry <String , String > downloadExclusion : transitiveLoadExclusion .entrySet ()) {
296- libraryBuilder .excludeTransitiveDependency (new ExcludedDependency (downloadExclusion .getValue (), downloadExclusion .getKey ()));
297- }
298-
277+
299278 if (relocate ) {
300279 if (dependency .getRelocation () != null || !dependency .isStickyLoad ()) {
301280 for (Map .Entry <String , String > relocation : relocations .entrySet ()) {
@@ -327,98 +306,7 @@ private List<Library> resolveTransitiveLibraries(String id, TransitiveDependency
327306 }
328307 return transitiveDependencies ;
329308 }
330-
331- private void updateDependencyCache (File libDirectory , Set <Dependency > dependencies ) {
332- for (Map .Entry <String , String > downloadExclusions : transitiveLoadExclusion .entrySet ()) {
333- String group = downloadExclusions .getValue ();
334- String name = downloadExclusions .getKey ();
335- List <String > allVersions = getAllVersions (libDirectory , group , name );
336- Dependency stickyNotesDependency = dependencies .stream ().filter (dependency -> dependency .getGroup ().replace ("{}" , "." ).equals (group ) && dependency .getName ().equals (name )).findFirst ().orElse (null );
337- if (stickyNotesDependency != null ) {
338- allVersions .remove (stickyNotesDependency .getVersion ());
339- } else {
340- continue ;
341- }
342- for (String version : allVersions ) {
343- deleteOldVersionDirectory (libDirectory , group , name , version );
344- }
345- }
346-
347- /*List<Dependency> allDependencies = new ArrayList<>();
348- List<Dependency> cachedDependencies = getAllProjectsCachedDependencies(libDirectory, true);
349- for (Dependency dependency : cachedDependencies) {
350- allDependencies.add(dependency);
351- if (dependency.getTransitiveDependencies() != null) {
352- allDependencies.addAll(dependency.getTransitiveDependencies());
353- }
354- }
355-
356- for (Dependency dependency : allDependencies) {
357- String group = dependency.getGroup();
358- String name = dependency.getName();
359- List<String> allVersions = getAllVersions(libDirectory, group, name);
360- if (allVersions.isEmpty()) {
361- continue;
362- }
363- String latestVersion = getLatestVersion(allVersions);
364- allVersions.remove(latestVersion);
365- for (String version : allVersions) {
366- deleteOldVersionDirectory(libDirectory, group, name, version);
367- }
368- }
369-
370- try {
371- for (File subDirectory : Files.walk(libDirectory.toPath(), FileVisitOption.FOLLOW_LINKS).map(Path::toFile).filter(File::isDirectory).collect(Collectors.toList())) {
372- if (!subDirectory.exists()) continue;
373- if (subDirectory.getAbsolutePath().contains("libby")) continue;
374- if (Arrays.stream(subDirectory.listFiles()).anyMatch(file -> file.isDirectory() || file.getName().endsWith(".jar"))) {
375- continue;
376- }
377- System.out.println("deleting directory: " + subDirectory.getAbsolutePath());
378- deleteDirectory(subDirectory);
379- }
380- } catch (Exception e) {
381- e.printStackTrace();
382- }*/
383-
384- /*List<Dependency> cachedDependencies = getAllProjectsCachedDependencies(libDirectory, false);
385- Map<String, Set<String>> inUseDependencyVersions = new HashMap<>();
386-
387- // Map all cached dependencies by their group+name and collect all versions
388- for (Dependency dependency : cachedDependencies) {
389- String key = dependency.getGroup() + ":" + dependency.getName();
390- inUseDependencyVersions.computeIfAbsent(key, k -> new HashSet<>()).add(dependency.getVersion());
391- }
392-
393- // Map all cached dependencies by their group+name and collect all versions
394- for (Dependency dependency : dependencies) {
395- String key = dependency.getGroup() + ":" + dependency.getName();
396- inUseDependencyVersions.computeIfAbsent(key, k -> new HashSet<>()).add(dependency.getVersion());
397- }
398-
399- for (Map.Entry<String, Set<String>> inUseDependencyVersion : inUseDependencyVersions.entrySet()) {
400- String[] groupName = inUseDependencyVersion.getKey().split(":");
401- String group = groupName[0];
402- String name = groupName[1];
403-
404- // Get all versions of the dependency
405- List<String> allVersions = getAllVersions(libDirectory, group, name);
406-
407- // Check if the version is in use
408- for (String version : allVersions) {
409- if (!inUseDependencyVersion.getValue().contains(version)) {
410- deleteOldVersionDirectory(libDirectory, group, name, version);
411- }
412- }
413- }*/
414-
415- /*try {
416- deleteUnusedDependencyDirectory(libDirectory);
417- } catch (IOException e) {
418- throw new RuntimeException(e);
419- }*/
420- }
421-
309+
422310 private String getLatestVersion (List <String > versions ) {
423311 if (versions == null || versions .isEmpty ()) {
424312 return null ;
0 commit comments