Skip to content

GH-945 Fix relocation updates. Support BOM dependency. Improve resolving dependencies #946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 14, 2025

Conversation

Rollczi
Copy link
Member

@Rollczi Rollczi commented Jun 10, 2025

Naprawiłem błąd z tą relokacją
Naprawiłem błąd z tym, że adventure nie mogło być normalnie pobierane
Dodałem wsparcie mavenowego bom
Przyspieszyłem resolwanie zależności z 16 sek do 3 czy coś tam

https://cdn.discordapp.com/attachments/1025826406707507302/1382121165492981922/20250610-2211-11.9157632.mp4?ex=684a0024&is=6848aea4&hm=f2076859e8d79e66203b187cfa3a589a993854040ca1e0e349dfa2fde1f96a3c&

Ta mała przerwa 5 sekund pod koniec nie jest związana z pobieraniem dependency ^

Copy link
Contributor

coderabbitai bot commented Jun 10, 2025

Walkthrough

This update improves how the project handles dependencies and simplifies some code. It updates and removes certain version constants, changes how some libraries are included by using shadowing and relocation, and refactors the dependency loader to work in clearer steps with parallel processing. It adds support for BOM dependencies and enhances property handling in Maven files. Some classes were simplified or rewritten, and new ones were added for managing local repositories and caching relocations. Overall, these changes make dependency management and loading smoother and more efficient.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🔭 Outside diff range comments (2)
eternalcore-plugin/src/main/java/com/eternalcode/core/loader/resource/ResourceLocator.java (1)

36-43: ⚠️ Potential issue

Add error handling for invalid URI format

The URI.create() method can throw IllegalArgumentException for invalid URI strings. Consider catching and wrapping it in a more descriptive exception.

 public static ResourceLocator from(String uri) {
     try {
         return new ResourceLocator(URI.create(uri).toURL());
+    } catch (IllegalArgumentException exception) {
+        throw new RuntimeException("Invalid URI format: " + uri, exception);
     }
     catch (MalformedURLException exception) {
         throw new RuntimeException(exception);
     }
 }
eternalcore-plugin/src/main/java/com/eternalcode/core/loader/dependency/Dependency.java (1)

147-158: ⚠️ Potential issue

Missing isBom in equals/hashCode

The isBom field isn't included in equals() and hashCode(). This means BOM and non-BOM dependencies with the same coordinates are considered equal, which might cause unexpected behavior.

 @Override
 public boolean equals(Object o) {
     if (this == o) return true;
     if (o == null || getClass() != o.getClass()) return false;
     Dependency that = (Dependency) o;
-    return Objects.equals(this.groupId, that.groupId) && Objects.equals(this.artifactId, that.artifactId) && Objects.equals(this.version, that.version);
+    return this.isBom == that.isBom && Objects.equals(this.groupId, that.groupId) && Objects.equals(this.artifactId, that.artifactId) && Objects.equals(this.version, that.version);
 }

 @Override
 public int hashCode() {
-    return Objects.hash(this.groupId, this.artifactId, this.version);
+    return Objects.hash(this.groupId, this.artifactId, this.version, this.isBom);
 }
🧹 Nitpick comments (4)
eternalcore-plugin/src/main/java/com/eternalcode/core/loader/repository/Repository.java (1)

7-8: Constructor visibility opened for subclassing.

Making the constructor protected enables LocalRepository while still preventing external instantiation. Works fine.
Remember to keep the factory method of() as the preferred entry for generic URLs.

eternalcore-plugin/src/main/java/com/eternalcode/core/loader/relocation/RelocationCacheResolver.java (2)

5-6: Remove unused imports

The Gson imports aren't used in this class.

-import com.google.gson.Gson;
-import com.google.gson.reflect.TypeToken;

45-55: Consider logging exceptions

The exception handling here silently swallows errors. Consider at least logging them for debugging purposes.

eternalcore-plugin/src/main/java/com/eternalcode/core/loader/dependency/DependencyLoaderImpl.java (1)

111-119: Consider making timeout configurable

The 60-minute timeout is quite long. Consider making it configurable or reducing it for better user experience.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 47a44b7 and 1aa0042.

📒 Files selected for processing (18)
  • buildSrc/src/main/kotlin/Versions.kt (1 hunks)
  • buildSrc/src/main/kotlin/eternalcode-java-test.gradle.kts (1 hunks)
  • eternalcore-core/build.gradle.kts (3 hunks)
  • eternalcore-plugin/build.gradle.kts (0 hunks)
  • eternalcore-plugin/src/main/java/com/eternalcode/core/loader/EternalCoreLoader.java (1 hunks)
  • eternalcore-plugin/src/main/java/com/eternalcode/core/loader/EternalCoreLoaderConstants.java (1 hunks)
  • eternalcore-plugin/src/main/java/com/eternalcode/core/loader/dependency/Dependency.java (3 hunks)
  • eternalcore-plugin/src/main/java/com/eternalcode/core/loader/dependency/DependencyCollector.java (2 hunks)
  • eternalcore-plugin/src/main/java/com/eternalcode/core/loader/dependency/DependencyLoader.java (0 hunks)
  • eternalcore-plugin/src/main/java/com/eternalcode/core/loader/dependency/DependencyLoaderImpl.java (2 hunks)
  • eternalcore-plugin/src/main/java/com/eternalcode/core/loader/pom/PomXmlProperties.java (1 hunks)
  • eternalcore-plugin/src/main/java/com/eternalcode/core/loader/pom/PomXmlScanner.java (4 hunks)
  • eternalcore-plugin/src/main/java/com/eternalcode/core/loader/relocation/Relocation.java (1 hunks)
  • eternalcore-plugin/src/main/java/com/eternalcode/core/loader/relocation/RelocationCacheResolver.java (1 hunks)
  • eternalcore-plugin/src/main/java/com/eternalcode/core/loader/relocation/RelocationHandler.java (5 hunks)
  • eternalcore-plugin/src/main/java/com/eternalcode/core/loader/repository/LocalRepository.java (1 hunks)
  • eternalcore-plugin/src/main/java/com/eternalcode/core/loader/repository/Repository.java (1 hunks)
  • eternalcore-plugin/src/main/java/com/eternalcode/core/loader/resource/ResourceLocator.java (1 hunks)
💤 Files with no reviewable changes (2)
  • eternalcore-plugin/build.gradle.kts
  • eternalcore-plugin/src/main/java/com/eternalcode/core/loader/dependency/DependencyLoader.java
🧰 Additional context used
🧬 Code Graph Analysis (6)
eternalcore-plugin/src/main/java/com/eternalcode/core/loader/EternalCoreLoader.java (1)
eternalcore-plugin/src/main/java/com/eternalcode/core/loader/EternalCoreLoaderConstants.java (1)
  • EternalCoreLoaderConstants (11-63)
eternalcore-core/build.gradle.kts (1)
buildSrc/src/main/kotlin/EternalShadowExtension.kt (2)
  • library (7-10)
  • libraryRelocate (12-14)
eternalcore-plugin/src/main/java/com/eternalcode/core/loader/relocation/RelocationCacheResolver.java (2)
eternalcore-plugin/src/main/java/com/eternalcode/core/loader/dependency/Dependency.java (1)
  • Dependency (10-179)
eternalcore-plugin/src/main/java/com/eternalcode/core/loader/repository/LocalRepository.java (1)
  • LocalRepository (6-21)
eternalcore-plugin/src/main/java/com/eternalcode/core/loader/dependency/DependencyLoaderImpl.java (4)
eternalcore-plugin/src/main/java/com/eternalcode/core/loader/relocation/RelocationCacheResolver.java (1)
  • RelocationCacheResolver (14-57)
eternalcore-plugin/src/main/java/com/eternalcode/core/loader/relocation/RelocationHandler.java (1)
  • RelocationHandler (49-131)
eternalcore-plugin/src/main/java/com/eternalcode/core/loader/repository/LocalRepository.java (1)
  • LocalRepository (6-21)
eternalcore-plugin/src/main/java/com/eternalcode/core/loader/repository/Repository.java (1)
  • Repository (3-28)
eternalcore-plugin/src/main/java/com/eternalcode/core/loader/relocation/RelocationHandler.java (1)
eternalcore-plugin/src/main/java/com/eternalcode/core/loader/dependency/Dependency.java (1)
  • Dependency (10-179)
eternalcore-plugin/src/main/java/com/eternalcode/core/loader/dependency/Dependency.java (1)
eternalcore-plugin/src/main/java/com/eternalcode/core/loader/resource/ResourceLocator.java (1)
  • ResourceLocator (10-45)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (17)
🔇 Additional comments (21)
buildSrc/src/main/kotlin/eternalcode-java-test.gradle.kts (1)

17-19: Looks good – constant aligned.

Switching both adventure-platform artifacts to use the unified Versions.ADVENTURE_PLATFORM keeps things tidy.
Just double-check that Versions.ADVENTURE_PLATFORM now points at the right version for both JARs.

eternalcore-plugin/src/main/java/com/eternalcode/core/loader/EternalCoreLoader.java (1)

18-23: Pure formatting – no action needed.

Indentation was the only change; behaviour stays the same. 👍

eternalcore-plugin/src/main/java/com/eternalcode/core/loader/pom/PomXmlProperties.java (1)

56-58: Nice touch – clearer null contract.

Adding @Nullable on the value parameter matches the return type and helps callers. No further issues spotted.

eternalcore-plugin/src/main/java/com/eternalcode/core/loader/EternalCoreLoaderConstants.java (1)

56-59: Simpler relocation creation.

Swapping the builder for the new record constructor keeps the code short and readable. All good.

eternalcore-core/build.gradle.kts (2)

31-32: Nice work on the dependency management!

Moving the Adventure libraries to the shadow configuration is a good practice. This ensures they're properly isolated and relocated to avoid conflicts with other plugins.


55-58:

❓ Verification inconclusive

Double-check the H2 relocation path

The gitcheck addition looks good. However, the H2 relocation path changed from com.h2database to com.h2. Please verify this matches the actual package structure of the H2 library to avoid relocation issues.

Also applies to: 73-73


🏁 Script executed:

#!/bin/bash
# Check the actual package structure of H2 library
fd -e java . | xargs rg -l "^package com\.h2" | head -10

Length of output: 58


Double-check the H2 relocation path

The gitcheck changes look good. For the H2 relocation (in build.gradle.kts around lines 55–58 and line 73), please confirm that relocating from com.h2database to com.h2 actually matches the H2 library’s package structure. You can inspect the H2 JAR (e.g., via jar tf) or check the source to ensure the new relocation path is correct.

buildSrc/src/main/kotlin/Versions.kt (1)

15-16: Version updates look good!

The Adventure library versions have been bumped appropriately. These updates align with the dependency changes in the build files.

eternalcore-plugin/src/main/java/com/eternalcode/core/loader/repository/LocalRepository.java (1)

8-19: Clean implementation!

Good job extracting the local repository logic into its own class. The error handling is appropriate for this use case.

eternalcore-plugin/src/main/java/com/eternalcode/core/loader/relocation/RelocationCacheResolver.java (1)

24-28: Clever caching approach!

The simple text-based serialization for relocations is a smart choice - it's human-readable and avoids complexity. The cache invalidation logic based on content changes is solid.

Also applies to: 30-37

eternalcore-plugin/src/main/java/com/eternalcode/core/loader/relocation/Relocation.java (1)

30-35: Excellent use of records!

Great refactoring to a record - much cleaner and simpler. The pattern replacement logic is preserved nicely in the compact constructor.

eternalcore-plugin/src/main/java/com/eternalcode/core/loader/dependency/DependencyCollector.java (1)

10-51: Good thread safety implementation!

The synchronized methods ensure safe concurrent access during parallel dependency scanning. The BOM handling logic is well thought out.

eternalcore-plugin/src/main/java/com/eternalcode/core/loader/pom/PomXmlScanner.java (2)

54-70: Nice stream refactoring!

The functional approach makes the dependency scanning logic cleaner and easier to follow.


211-213: Good consolidation of scope filtering!

Moving the scope check to a helper method improves readability.

eternalcore-plugin/src/main/java/com/eternalcode/core/loader/dependency/DependencyLoaderImpl.java (1)

65-70: Excellent modular design!

Breaking down the loading process into clear phases improves maintainability.

eternalcore-plugin/src/main/java/com/eternalcode/core/loader/dependency/Dependency.java (2)

22-37: Clean BOM support implementation!

The boolean flag and conversion methods provide a simple way to handle BOM dependencies.

Also applies to: 171-178


51-61: Smart refactoring of URL construction!

Extracting the common URL building logic reduces duplication nicely.

eternalcore-plugin/src/main/java/com/eternalcode/core/loader/relocation/RelocationHandler.java (5)

52-54: Dependency updates look good!

The ASM libraries have been updated to version 9.7.1, which is great for keeping dependencies current.


63-69: Nice addition of caching support!

The RelocationCacheResolver integration is properly implemented with the field and constructor updates.


79-83: Smart caching logic!

The code efficiently checks for existing relocated JARs and only relocates when necessary. This should improve performance significantly.


95-101: Good file handling improvements!

Deleting existing files before creating new ones prevents potential conflicts, and marking the cache after successful relocation keeps everything in sync.


107-108: Factory method properly updated!

The static create method correctly accepts and passes the cache resolver to support the new caching feature.

Also applies to: 120-120

@Rollczi Rollczi requested a review from vLuckyyy June 10, 2025 22:17
@Rollczi Rollczi changed the title Fix relocation updates. Support BOM dependency. Improve resolving dependencies GH-945 Fix relocation updates. Support BOM dependency. Improve resolving dependencies Jun 10, 2025
@Rollczi Rollczi requested review from CitralFlo and Jakubk15 June 10, 2025 22:19
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
eternalcore-plugin/src/main/java/com/eternalcode/core/loader/dependency/DependencyLoaderImpl.java (2)

93-97: Dead branch: relocationHandler can’t be null

relocationHandler is always created in the constructor, so this check will never be true. Removing the branch simplifies the code.

-            if (this.relocationHandler == null) {
-                return new DependencyLoadEntry(dependency, downloadedDependencyPath);
-            }

54-56: Thread-pool size could use tuning

repositories.size() * 5 is arbitrary; on large repo lists you may spawn far more threads than CPU cores. Consider Math.min(availableProcessors, repositories.size()*5) or make it configurable.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1aa0042 and 225503e.

📒 Files selected for processing (1)
  • eternalcore-plugin/src/main/java/com/eternalcode/core/loader/dependency/DependencyLoaderImpl.java (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
eternalcore-plugin/src/main/java/com/eternalcode/core/loader/dependency/DependencyLoaderImpl.java (4)
eternalcore-plugin/src/main/java/com/eternalcode/core/loader/relocation/RelocationCacheResolver.java (1)
  • RelocationCacheResolver (14-57)
eternalcore-plugin/src/main/java/com/eternalcode/core/loader/relocation/RelocationHandler.java (1)
  • RelocationHandler (49-131)
eternalcore-plugin/src/main/java/com/eternalcode/core/loader/repository/LocalRepository.java (1)
  • LocalRepository (6-21)
eternalcore-plugin/src/main/java/com/eternalcode/core/loader/repository/Repository.java (1)
  • Repository (3-28)

Comment on lines 127 to +130
try {
this.executor.shutdown();
this.relocationHandler.close();
}
catch (Exception exception) {
} catch (Exception exception) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Gracefully wait for the pool to finish before exiting

shutdown() only triggers an orderly shutdown; threads may still be alive when relocationHandler.close() runs or when the JVM exits. Add an awaitTermination (with a sensible timeout) to make sure all tasks are done and resources released.

 this.executor.shutdown();
+try {
+    if (!this.executor.awaitTermination(30, TimeUnit.SECONDS)) {
+        this.executor.shutdownNow();
+    }
+} catch (InterruptedException ex) {
+    this.executor.shutdownNow();
+    Thread.currentThread().interrupt();
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
try {
this.executor.shutdown();
this.relocationHandler.close();
}
catch (Exception exception) {
} catch (Exception exception) {
@Override
public void close() {
try {
this.executor.shutdown();
try {
if (!this.executor.awaitTermination(30, TimeUnit.SECONDS)) {
this.executor.shutdownNow();
}
} catch (InterruptedException ex) {
this.executor.shutdownNow();
Thread.currentThread().interrupt();
}
this.relocationHandler.close();
} catch (Exception exception) {
throw new DependencyException("Failed to close relocation handler", exception);
}
}
🤖 Prompt for AI Agents
In
eternalcore-plugin/src/main/java/com/eternalcode/core/loader/dependency/DependencyLoaderImpl.java
around lines 127 to 130, after calling this.executor.shutdown(), add a call to
this.executor.awaitTermination() with a reasonable timeout to wait for all tasks
to complete before proceeding. This ensures the thread pool finishes gracefully
before calling this.relocationHandler.close() and before JVM exit. Handle
InterruptedException properly during awaitTermination.

Copy link
Member

@Jakubk15 Jakubk15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good, however a lot of this keywords are missing. I really like the thread-safe synchronization you've done in DependencyCollector class.

Comment on lines +83 to +84
if (thisMajor != dependencyMajor) {
return thisMajor > dependencyMajor;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change thisMajor to currentMinor, same for the variables below. Up for @Rollczi consideration.

DependencyCollector collector = new DependencyCollector();
this.logger.info("Resolving dependencies...");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to find a way to disable this logger, so it can be enabled only for example in debug mode. LuckPerms, for instance, does not have such logging. It's not like I dislike this, but if we are planning to implement on-the-fly dependency loading to all of our plugins, it would be good to avoid duplicated mess in console.

List<DependencyLoadEntry> dependencyLoadEntries = CompletableFutures.allAsList(futures)
.orTimeout(60, TimeUnit.MINUTES)
.join();
return new DependencyLoadEntry(dependency, relocatedDependency);
Copy link
Member

@Jakubk15 Jakubk15 Jun 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we also log messages to console after dependency downloading? Downloading and loading from disk is not the same, so the numbers could sometimes differ

collector.addScannedDependency(firstChild);
}

subDependencies.get().stream()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you profiled this method to check for performance loss to using simple for loop?

Comment on lines +52 to +53
Dependency.of("org.ow2.asm", "asm", "9.7.1"),
Dependency.of("org.ow2.asm", "asm-commons", "9.7.1"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Dependency.of("org.ow2.asm", "asm", "9.7.1"),
Dependency.of("org.ow2.asm", "asm-commons", "9.7.1"),
Dependency.of("org.ow2.asm", "asm", "9.8"),
Dependency.of("org.ow2.asm", "asm-commons", "9.8"),

@vLuckyyy vLuckyyy merged commit 5e6377f into master Jun 14, 2025
3 checks passed
@vLuckyyy
Copy link
Member

Due to the priority of this task, I was forced to merge it without review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dynamic dependency loading fails on version upgrade due to for e.g. relocation.
3 participants