Recaf icon indicating copy to clipboard operation
Recaf copied to clipboard

Rework plugin system

Open xxDark opened this issue 1 year ago • 2 comments

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
  • Migrate to JGraphT
  • 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.

xxDark avatar Apr 27 '24 21:04 xxDark

Unit test results

 53 files  ±0   53 suites  ±0   23s :stopwatch: -1s 382 tests +2  376 :white_check_mark: +2  6 :zzz: ±0  0 :x: ±0  393 runs  +2  387 :white_check_mark: +2  6 :zzz: ±0  0 :x: ±0 

Results for commit 5c440492. ± Comparison against base commit b5dab0ec.

:recycle: This comment has been updated with latest results.

github-actions[bot] avatar Apr 27 '24 21:04 github-actions[bot]

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 :warning:
...ley/recaf/services/plugin/zip/ZipPluginLoader.java 61.53% 20 Missing and 10 partials :warning:
...y/recaf/services/plugin/PluginClassLoaderImpl.java 46.51% 18 Missing and 5 partials :warning:
...oley/recaf/services/plugin/zip/ZipArchiveView.java 44.44% 14 Missing and 1 partial :warning:
...are/coley/recaf/services/plugin/zip/ZipSource.java 53.84% 3 Missing and 3 partials :warning:
...y/recaf/services/plugin/zip/ZipPreparedPlugin.java 61.53% 5 Missing :warning:
...coley/recaf/services/plugin/PluginManagerTest.java 97.20% 5 Missing :warning:
...oley/recaf/services/plugin/BasicPluginManager.java 81.25% 2 Missing and 1 partial :warning:
...ley/recaf/services/plugin/PluginContainerImpl.java 77.77% 1 Missing and 1 partial :warning:
...a/software/coley/recaf/util/io/PathByteSource.java 0.00% 2 Missing :warning:
... 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     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Apr 27 '24 21:04 codecov[bot]

 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 avatar Jun 16 '24 18:06 Col-E

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 avatar Jun 16 '24 19:06 Col-E