Skip to content

Commit

Permalink
Merge pull request #780 from Col-E/plugin
Browse files Browse the repository at this point in the history
Rework plugin system
  • Loading branch information
Col-E committed Jun 16, 2024
2 parents b5dab0e + 5c44049 commit 45d680a
Show file tree
Hide file tree
Showing 40 changed files with 1,522 additions and 1,037 deletions.
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' << '-g' << '-parameters'
options.encoding = 'UTF-8'
options.incremental = true
}
tasks.withType(JavaCompile).configureEach {
options.compilerArgs << '-Xlint:unchecked' << '-Xlint:deprecation' << '-g' << '-parameters'
options.encoding = 'UTF-8'
options.incremental = true
}

// Enable automatic generation of null checks on annotated methods
Expand Down
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 @@ -2,6 +2,7 @@

/**
* Base interface that all plugins must inherit from.
* Classes that implement this type should also be annotated with {@link PluginInformation}.
*
* @author xDark
*/
Expand Down

This file was deleted.

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

/**
* @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.
*/
@Nonnull
public P getPlugin() {
return plugin;
}

public interface PluginContainer<P extends Plugin> {
/**
* @return Information about plugin.
* @return Plugin information.
*/
@Nonnull
public PluginInfo getInformation() {
return information;
}
PluginInfo info();

/**
* @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);
}
}
Loading

0 comments on commit 45d680a

Please sign in to comment.