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

Draft
wants to merge 4 commits into
base: dev4
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,10 @@ subprojects {
}

// Append options for unchecked/deprecation
gradle.projectsEvaluated {
tasks.withType(JavaCompile).configureEach {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
options.encoding = 'UTF-8'
options.incremental = true
}
tasks.withType(JavaCompile).configureEach {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
options.encoding = 'UTF-8'
options.incremental = true
}

// Enable automatic generation of null checks on annotated methods
Expand Down
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ gradle-checker-processor = "2.0.2"
javafx-plugin = "0.1.0"
shadow = "8.1.1"
peterabeles-gversion = "1.10.2"
jgrapht = "1.5.2"

[libraries]


asm-core = { module = "org.ow2.asm:asm", version.ref = "asm" }
asm-analysis = { module = "org.ow2.asm:asm-analysis", version.ref = "asm" }
asm-commons = { module = "org.ow2.asm:asm-commons", version.ref = "asm" }
Expand Down Expand Up @@ -124,6 +124,8 @@ vineflower = { module = "org.vineflower:vineflower", version.ref = "vineflower"

wordwrap = { module = "com.github.davidmoten:word-wrap", version.ref = "wordwrap" }

jgrapht = { module = "org.jgrapht:jgrapht-core", version.ref = "jgrapht" }

[bundles]
asm = [
"asm-core",
Expand Down
1 change: 1 addition & 0 deletions recaf-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies {
api(libs.bundles.jasm)
api(libs.vineflower)
api(libs.wordwrap)
api(libs.jgrapht)
}

// Force generation of gversion data class when the version information is not up-to-date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @author xDark
*/
public interface Plugin {

/**
* Called when plugin is being enabled.
*/
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,17 @@
* @see PluginInfo
* @see PluginLoader
*/
public final class PluginContainer<P extends Plugin> {
private final P plugin;
private final PluginInfo information;
private final PluginLoader loader;
public interface PluginContainer<P extends Plugin> {

/**
* @param plugin
* Plugin instance.
* @param information
* Information about plugin.
* @param loader
* Loader of the plugin.
*/
public PluginContainer(@Nonnull P plugin, @Nonnull PluginInfo information, @Nonnull PluginLoader loader) {
this.plugin = plugin;
this.information = information;
this.loader = loader;
}

/**
* @return Plugin instance.
* @return Plugin information.
*/
@Nonnull
public P getPlugin() {
return plugin;
}
PluginInfo info();

/**
* @return Information about plugin.
*/
@Nonnull
public PluginInfo getInformation() {
return information;
}

/**
* @return Loader of the plugin.
* @return Plugin instance.
*/
@Nonnull
public PluginLoader getLoader() {
return loader;
}
P plugin();
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package software.coley.recaf.plugin;

/**
* Exception indicating that a {@link Plugin} could not be loaded.
* Exception thrown when action involving plugins fail.
*
* @author xDark
*/
public final class PluginLoadException extends Exception {
public final class PluginException extends Exception {
/**
* Constructs a new exception.
*/
public PluginLoadException() {
public PluginException() {
}

/**
Expand All @@ -18,7 +18,7 @@ public PluginLoadException() {
* @param message
* The detail message.
*/
public PluginLoadException(String message) {
public PluginException(String message) {
super(message);
}

Expand All @@ -30,7 +30,7 @@ public PluginLoadException(String message) {
* @param cause
* The cause of the exception.
*/
public PluginLoadException(String message, Throwable cause) {
public PluginException(String message, Throwable cause) {
super(message, cause);
}

Expand All @@ -40,7 +40,7 @@ public PluginLoadException(String message, Throwable cause) {
* @param cause
* The cause of the exception.
*/
public PluginLoadException(Throwable cause) {
public PluginException(Throwable cause) {
super(cause);
}
}
105 changes: 38 additions & 67 deletions recaf-core/src/main/java/software/coley/recaf/plugin/PluginInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,97 +2,68 @@

import jakarta.annotation.Nonnull;

import java.util.Set;

/**
* Object containing necessary information about a plugin.
*
* @param id ID of the plugin.
* @param name Name of the plugin.
* @param version Plugin version.
* @param author Author of the plugin.
* @param description Plugin description.
* @param dependencies Plugin dependencies.
* @param softDependencies Plugin soft dependencies.
* @author xDark
* @see PluginInformation Annotation containing this information applied to {@link Plugin} implementations.
*/
public final class PluginInfo {
private final String name;
private final String version;
private final String author;
private final String description;
public record PluginInfo(
@Nonnull String id,
@Nonnull String name,
@Nonnull String version,
@Nonnull String author,
@Nonnull String description,
@Nonnull Set<String> dependencies,
@Nonnull Set<String> softDependencies
) {

/**
* @param name
* Name of the plugin.
* @param version
* Plugin version.
* @param author
* Author of the plugin.
* @param description
* Plugin description.
*/
public PluginInfo(@Nonnull String name, @Nonnull String version,
@Nonnull String author, @Nonnull String description) {
this.name = name;
this.version = version;
this.author = author;
this.description = description;
@Nonnull
public static PluginInfo empty() {
return new PluginInfo("", "", "", "", "", Set.of(), Set.of());
}

/**
* @return Plugin name.
*/
@Nonnull
public String getName() {
return name;
public PluginInfo withId(@Nonnull String id) {
return new PluginInfo(id, name, version, author, description, dependencies, softDependencies);
}

/**
* @return Plugin version.
*/
@Nonnull
public String getVersion() {
return version;
public PluginInfo withName(@Nonnull String name) {
return new PluginInfo(id, name, version, author, description, dependencies, softDependencies);
}

/**
* @return Author of the plugin.
*/
@Nonnull
public String getAuthor() {
return author;
public PluginInfo withVersion(@Nonnull String version) {
return new PluginInfo(id, name, version, author, description, dependencies, softDependencies);
}

/**
* @return Plugin description.
*/
@Nonnull
public String getDescription() {
return description;
public PluginInfo withAuthor(@Nonnull String author) {
return new PluginInfo(id, name, version, author, description, dependencies, softDependencies);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

PluginInfo info = (PluginInfo) o;

if (!name.equals(info.name)) return false;
if (!version.equals(info.version)) return false;
if (!author.equals(info.author)) return false;
return description.equals(info.description);
@Nonnull
public PluginInfo withDescription(@Nonnull String description) {
return new PluginInfo(id, name, version, author, description, dependencies, softDependencies);
}

@Override
public int hashCode() {
int result = name.hashCode();
result = 31 * result + version.hashCode();
result = 31 * result + author.hashCode();
result = 31 * result + description.hashCode();
return result;
@Nonnull
public PluginInfo withDependencies(@Nonnull Set<String> dependencies) {
return new PluginInfo(id, name, version, author, description, dependencies, softDependencies);
}

@Override
public String toString() {
return "PluginInfo{" +
"name='" + name + '\'' +
", version='" + version + '\'' +
", author='" + author + '\'' +
", description='" + description + '\'' +
'}';
@Nonnull
public PluginInfo withSoftDependencies(@Nonnull Set<String> softDependencies) {
return new PluginInfo(id, name, version, author, description, dependencies, softDependencies);
}
}