Skip to content

Commit

Permalink
Document new plugin API classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Col-E committed Jun 16, 2024
1 parent fc51909 commit d9202b2
Show file tree
Hide file tree
Showing 28 changed files with 310 additions and 366 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jlinker = "1.0.7"
jphantom = "1.4.4"
junit = "5.10.2"
jsvg = "1.4.0"
llzip = "2.5.0"
llzip = "2.6.0"
logback-classic = { strictly = "1.4.11" } # newer releases break in jar releases
mapping-io = "0.5.1"
mockito = "5.11.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* @see PluginLoader
*/
public interface PluginContainer<P extends Plugin> {

/**
* @return Plugin information.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
import software.coley.recaf.util.io.ByteSource;

/**
* Plugin source.
* A functional mapping of internal paths <i>(Like paths in a ZIP file)</i> to the contents of the plugin.
*
* @author xDark
*/
public interface PluginSource {

/**
* @param name Resource name.
* @param name
* Resource path name.
*
* @return Resource content or {@code null}, if not found.
*/
@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import software.coley.recaf.cdi.EagerInitialization;
import software.coley.recaf.plugin.ClassAllocator;
import software.coley.recaf.plugin.Plugin;
import software.coley.recaf.plugin.PluginContainer;
import software.coley.recaf.plugin.PluginException;
import software.coley.recaf.plugin.PluginLoader;
import software.coley.recaf.services.plugin.discovery.DiscoveredPlugin;
import software.coley.recaf.plugin.*;
import software.coley.recaf.services.plugin.discovery.DiscoveredPluginSource;
import software.coley.recaf.services.plugin.discovery.PluginDiscoverer;
import software.coley.recaf.services.plugin.zip.ZipPluginLoader;

Expand Down Expand Up @@ -68,10 +64,10 @@ public void registerLoader(@Nonnull PluginLoader loader) {
@Nonnull
@Override
public Collection<PluginContainer<?>> loadPlugins(@Nonnull PluginDiscoverer discoverer) throws PluginException {
List<DiscoveredPlugin> discoveredPlugins = discoverer.findAll();
List<DiscoveredPluginSource> discoveredPlugins = discoverer.findSources();
List<PluginLoader> loaders = this.loaders;
List<PreparedPlugin> prepared = new ArrayList<>(discoveredPlugins.size());
for (DiscoveredPlugin plugin : discoveredPlugins) {
for (DiscoveredPluginSource plugin : discoveredPlugins) {
for (PluginLoader loader : loaders) {
PreparedPlugin preparedPlugin = loader.prepare(plugin.source());
if (preparedPlugin == null)
Expand All @@ -84,8 +80,8 @@ public Collection<PluginContainer<?>> loadPlugins(@Nonnull PluginDiscoverer disc

@Nonnull
@Override
public PluginUnloader unloadPlugin(@Nonnull String id) {
return mainGraph.unload(id);
public PluginUnloader unloaderFor(@Nonnull String id) {
return mainGraph.unloaderFor(id);
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
import jakarta.annotation.Nonnull;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.context.spi.CreationalContext;
import jakarta.enterprise.inject.se.SeContainer;
import jakarta.enterprise.inject.spi.*;
import jakarta.inject.Inject;
import software.coley.recaf.Bootstrap;
import software.coley.recaf.Recaf;
import software.coley.recaf.plugin.AllocationException;
import software.coley.recaf.plugin.ClassAllocator;

Expand All @@ -25,7 +22,7 @@ public class CdiClassAllocator implements ClassAllocator {
private final BeanManager beanManager;

@Inject
public CdiClassAllocator(BeanManager beanManager) {
public CdiClassAllocator(@Nonnull BeanManager beanManager) {
this.beanManager = beanManager;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
package software.coley.recaf.services.plugin;

import jakarta.annotation.Nonnull;

import java.util.HashSet;
import java.util.Set;

final class LoadedPlugin {
final Set<LoadedPlugin> dependencies = HashSet.newHashSet(4);
final PluginContainerImpl<?> container;
private final Set<LoadedPlugin> dependencies = HashSet.newHashSet(4);
private final PluginContainerImpl<?> container;

LoadedPlugin(PluginContainerImpl<?> container) {
LoadedPlugin(@Nonnull PluginContainerImpl<?> container) {
this.container = container;
}

/**
* @return Mutable set of dependencies this plugin relies on.
*/
@Nonnull
public Set<LoadedPlugin> getDependencies() {
return dependencies;
}

/**
* @return
*/
@Nonnull
public PluginContainerImpl<?> getContainer() {
return container;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,22 @@
public interface PluginClassLoader {

/**
* @param name Resource path.
* @param name
* Resource path.
*
* @return Resource source or {@code null} if not found.
*/
@Nullable
ByteSource lookupResource(@Nonnull String name);

/**
* @param name Class name.
* @param name
* Class name.
*
* @return Class.
*
* @throws ClassNotFoundException
* If class was not found.
* If class was not found.
*/
@Nonnull
Class<?> lookupClass(@Nonnull String name) throws ClassNotFoundException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
import java.net.*;

final class PluginClassLoaderImpl extends ClassLoader implements PluginClassLoader {
private final PluginGraph graph;
Expand Down Expand Up @@ -81,9 +76,9 @@ protected Class<?> findClass(String name) throws ClassNotFoundException {
Class<?> cls = lookupClassImpl(name);
if (cls != null)
return cls;
var dependencies = graph.getDependencies(id);
while (dependencies.hasNext()) {
if ((cls = dependencies.next().findClass(name)) != null)
var dependencyLoaders = graph.getDependencyClassloaders(id);
while (dependencyLoaders.hasNext()) {
if ((cls = dependencyLoaders.next().findClass(name)) != null)
return cls;
}
throw new ClassNotFoundException(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@
import software.coley.recaf.plugin.PluginContainer;
import software.coley.recaf.plugin.PluginInfo;

/**
* Plugin container implementation.
*
* @param <P>
* Plugin instance type.
*
* @author xDark
*/
final class PluginContainerImpl<P extends Plugin> implements PluginContainer<P> {
final PreparedPlugin preparedPlugin;
final PluginClassLoader classLoader;
P plugin;

PluginContainerImpl(PreparedPlugin preparedPlugin, PluginClassLoader classLoader) {
PluginContainerImpl(@Nonnull PreparedPlugin preparedPlugin, @Nonnull PluginClassLoader classLoader) {
this.preparedPlugin = preparedPlugin;
this.classLoader = classLoader;
}
Expand Down
Loading

0 comments on commit d9202b2

Please sign in to comment.