Skip to content
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

Rework plugin system #780

Merged
merged 9 commits into from
Jun 16, 2024
Merged

Rework plugin system #780

merged 9 commits into from
Jun 16, 2024

Conversation

xxDark
Copy link
Collaborator

@xxDark xxDark commented Apr 27, 2024

What's new

Plugin system is now reworked to act as a graph with dependencies.
Each plugin is loaded in its own class loader controlled by plugin manager.
Plugin loaders no longer participate in plugin loading, but only prepare plugins to be loaded.
To load plugins from a directory or any arbitrary source, PluginDiscoverer may be implemented.

TBD

  • Plugin unloading
  • Load plugins from the directory when Recaf starts. IMO the code to do that should be moved to main class and not be in @PostConstruct with test env hack.
  • Think if we should even have the concept of "startup" plugins. There probably needs work to be done to properly cleanup plugins when they are unloaded.
  • Migrate to JGraphT (not important)

Copy link

github-actions bot commented Apr 27, 2024

Unit test results

 53 files  ±0   53 suites  ±0   23s ⏱️ -1s
382 tests +2  376 ✅ +2  6 💤 ±0  0 ❌ ±0 
393 runs  +2  387 ✅ +2  6 💤 ±0  0 ❌ ±0 

Results for commit 5c44049. ± Comparison against base commit b5dab0e.

♻️ This comment has been updated with latest results.

Copy link

codecov bot commented Apr 27, 2024

Codecov Report

Attention: Patch coverage is 71.62162% with 147 lines in your changes missing coverage. Please review.

Project coverage is 70.24%. Comparing base (b5dab0e) to head (5c44049).

Files Patch % Lines
...tware/coley/recaf/services/plugin/PluginGraph.java 55.55% 43 Missing and 9 partials ⚠️
...ley/recaf/services/plugin/zip/ZipPluginLoader.java 61.53% 20 Missing and 10 partials ⚠️
...y/recaf/services/plugin/PluginClassLoaderImpl.java 46.51% 18 Missing and 5 partials ⚠️
...oley/recaf/services/plugin/zip/ZipArchiveView.java 44.44% 14 Missing and 1 partial ⚠️
...are/coley/recaf/services/plugin/zip/ZipSource.java 53.84% 3 Missing and 3 partials ⚠️
...y/recaf/services/plugin/zip/ZipPreparedPlugin.java 61.53% 5 Missing ⚠️
...coley/recaf/services/plugin/PluginManagerTest.java 97.20% 5 Missing ⚠️
...oley/recaf/services/plugin/BasicPluginManager.java 81.25% 2 Missing and 1 partial ⚠️
...ley/recaf/services/plugin/PluginContainerImpl.java 77.77% 1 Missing and 1 partial ⚠️
...a/software/coley/recaf/util/io/PathByteSource.java 0.00% 2 Missing ⚠️
... and 4 more
Additional details and impacted files
@@             Coverage Diff              @@
##               dev4     #780      +/-   ##
============================================
+ Coverage     70.01%   70.24%   +0.23%     
- Complexity     3106     3149      +43     
============================================
  Files           354      358       +4     
  Lines         16252    16527     +275     
  Branches       1872     1899      +27     
============================================
+ Hits          11379    11610     +231     
- Misses         3961     3992      +31     
- Partials        912      925      +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Col-E
Copy link
Owner

Col-E commented Jun 16, 2024

 PhantomGeneratorTest > test() FAILED
    org.opentest4j.AssertionFailedError at PhantomGeneratorTest.java:67

14:44:33.537 [JPhantomGenerator/main] ERROR: Phantom analysis encountered an exception.
java.lang.NoClassDefFoundError: org/jgrapht/DirectedGraph
	at org.clyze.jphantom.JPhantom.run(JPhantom.java:73)
	at software.coley.recaf.services.phantom.JPhantomGenerator.generate(JPhantomGenerator.java:177)
	at software.coley.recaf.services.phantom.JPhantomGenerator.createPhantomsForClasses(JPhantomGenerator.java:102)
	at software.coley.recaf.services.phantom.JPhantomGenerator$Proxy$_$$_WeldClientProxy.createPhantomsForClasses(Unknown Source)
	at software.coley.recaf.services.phantom.PhantomGeneratorTest.lambda$test$0(PhantomGeneratorTest.java:63)
	at org.junit.jupiter.api.AssertDoesNotThrow.assertDoesNotThrow(AssertDoesNotThrow.java:71)
	at org.junit.jupiter.api.AssertDoesNotThrow.assertDoesNotThrow(AssertDoesNotThrow.java:58)
	at org.junit.jupiter.api.Assertions.assertDoesNotThrow(Assertions.java:3228)
	at software.coley.recaf.services.phantom.PhantomGeneratorTest.test(PhantomGeneratorTest.java:63)
Caused by: java.lang.ClassNotFoundException: org.jgrapht.DirectedGraph
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
	... 77 common frames omitted

Adding JGraphT 1.5.2 breaks JPhantom

If you look at the JPhantom fork we have:

    <dependency>
      <groupId>org.jgrapht</groupId>
      <artifactId>jgrapht-core</artifactId>
      <version>1.0.1</version> <!-- After 1.1.0 are major api incompatibilities -->
    </dependency>

🤦

@Col-E
Copy link
Owner

Col-E commented Jun 16, 2024

Think if we should even have the concept of "startup" plugins.

I made it so that plugins are only loaded from the path discoverer if they have .jar as a suffix. We can thus handle this concept by changing the extension.

@Col-E Col-E marked this pull request as ready for review June 16, 2024 19:31
@Col-E Col-E removed the Discussion label Jun 16, 2024
@Col-E Col-E merged commit 45d680a into dev4 Jun 16, 2024
6 checks passed
@Col-E Col-E deleted the plugin branch August 14, 2024 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants