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

Split into modules #37

Draft
wants to merge 6 commits into
base: master
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
179 changes: 61 additions & 118 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,142 +1,85 @@
plugins {
id 'java-library'
id 'application'
id 'maven-publish'
id "checkstyle"
id 'org.openjfx.javafxplugin'
id 'com.github.johnrengelman.shadow'
id 'org.gradlex.extra-java-module-info'
id 'com.github.johnrengelman.shadow' apply false
id 'org.gradlex.extra-java-module-info' apply false
}

repositories {
mavenCentral()
maven {
name "Fabric"
url 'https://maven.fabricmc.net/'
}
}

archivesBaseName = 'matcher'
group = 'net.fabricmc'

def ENV = System.getenv()

checkstyle {
configFile = project.file("checkstyle.xml")
toolVersion = project.checkstyle_version
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
subprojects {
apply plugin: 'java-library'
apply plugin: 'maven-publish'
apply plugin: 'checkstyle'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'org.gradlex.extra-java-module-info'

if (!JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
repositories {
mavenCentral()
maven {
name "Fabric"
url 'https://maven.fabricmc.net/'
}
}

withSourcesJar()
}

tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
it.options.release = 17
}
group = 'net.fabricmc.matcher'
version = rootProject.version

javafx {
version = javafx_version
modules = [ 'javafx.controls', 'javafx.web' ]
checkstyle {
configFile = rootProject.file("checkstyle.xml")
toolVersion = rootProject.checkstyle_version
}

// Don't include native binaries via the plugin,
// since it will only include those for the current OS.
// The full set of native libraries gets shadowed a few lines beneath.
configuration = 'compileOnly'
}
extraJavaModuleInfo {
failOnMissingModuleInfo.set(false) // because of transitive dependencies

dependencies {
api "org.ow2.asm:asm:${asm_version}"
api "org.ow2.asm:asm-tree:${asm_version}"
api "org.slf4j:slf4j-api:${slf4j_version}"
api "net.fabricmc:mapping-io:${mappingio_version}"
implementation "org.ow2.asm:asm-commons:${asm_version}"
implementation "org.ow2.asm:asm-util:${asm_version}"
implementation "com.github.javaparser:javaparser-core:${javaparser_version}"
implementation "net.fabricmc:cfr:${fabric_cfr_version}"
implementation "org.vineflower:vineflower:${vineflower_version}"
implementation "org.bitbucket.mstrobel:procyon-compilertools:${procyon_version}"
implementation ("io.github.skylot:jadx-core:${jadx_version}") {
exclude group: 'com.android.tools.build', module: 'aapt2-proto'
}
implementation ("io.github.skylot:jadx-java-input:${jadx_version}") {
exclude group: 'io.github.skylot', module: 'raung-disasm'
}
runtimeOnly "org.tinylog:tinylog-impl:${tinylog_version}"
runtimeOnly "org.tinylog:slf4j-tinylog:${tinylog_version}"

// JavaFX for all platforms (needed for cross-platform fat jar)
runtimeOnly "org.openjfx:javafx-base:${javafx_version}:win"
runtimeOnly "org.openjfx:javafx-base:${javafx_version}:mac"
runtimeOnly "org.openjfx:javafx-base:${javafx_version}:linux"
runtimeOnly "org.openjfx:javafx-graphics:${javafx_version}:win"
runtimeOnly "org.openjfx:javafx-graphics:${javafx_version}:mac"
runtimeOnly "org.openjfx:javafx-graphics:${javafx_version}:linux"
runtimeOnly "org.openjfx:javafx-controls:${javafx_version}:win"
runtimeOnly "org.openjfx:javafx-controls:${javafx_version}:mac"
runtimeOnly "org.openjfx:javafx-controls:${javafx_version}:linux"
runtimeOnly "org.openjfx:javafx-web:${javafx_version}:win"
runtimeOnly "org.openjfx:javafx-web:${javafx_version}:mac"
runtimeOnly "org.openjfx:javafx-web:${javafx_version}:linux"
runtimeOnly "org.openjfx:javafx-media:${javafx_version}:win"
runtimeOnly "org.openjfx:javafx-media:${javafx_version}:mac"
runtimeOnly "org.openjfx:javafx-media:${javafx_version}:linux"
}
// JCommander
automaticModule("com.beust:jcommander", "jcommander")

extraJavaModuleInfo {
failOnMissingModuleInfo.set(false) // because of transitive dependencies
// CFR
automaticModule("net.fabricmc:cfr", "cfr")

// CFR
automaticModule("net.fabricmc:cfr", "cfr")
// Vineflower
automaticModule("org.vineflower:vineflower", "org.vineflower.vineflower")

// Vineflower
automaticModule("org.vineflower:vineflower", "org.vineflower.vineflower")
// Procyon
automaticModule("org.bitbucket.mstrobel:procyon-compilertools", "procyon.compilertools")

// Procyon
automaticModule("org.bitbucket.mstrobel:procyon-compilertools", "procyon.compilertools")
// JADX
automaticModule("io.github.skylot:jadx-core", "jadx.core")
automaticModule("io.github.skylot:jadx-plugins-api", "jadx.plugins.api")
automaticModule("io.github.skylot:jadx-java-input", "jadx.plugins.java_input")
}

// JADX
automaticModule("io.github.skylot:jadx-core", "jadx.core")
automaticModule("io.github.skylot:jadx-plugins-api", "jadx.plugins.api")
automaticModule("io.github.skylot:jadx-java-input", "jadx.plugins.java_input")
}
java {
withJavadocJar()
withSourcesJar()
}

application {
mainModule = 'matcher'
mainClass = 'matcher.Main'
}
tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
}

jar {
processResources.exclude('tinylog-dev.properties')
}
tasks.withType(com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar).configureEach {
// https://github.com/johnrengelman/shadow/issues/882#issuecomment-1715703146
// Defer the resolution of 'runtimeClasspath'. This is an issue in the shadow
// plugin that it automatically accesses the files in 'runtimeClasspath' while
// Gradle is building the task graph. The three lines below work around that.
inputs.files(project.configurations.runtimeClasspath)
configurations = Collections.emptyList()

publishing {
publications {
mavenJava(MavenPublication) {
from components.java
doFirst {
configurations = Collections.singletonList(project.configurations.runtimeClasspath)
}
}

repositories {
mavenLocal()

if (ENV.MAVEN_URL) {
repositories.maven {
name "fabric"
url ENV.MAVEN_URL
credentials {
username ENV.MAVEN_USERNAME
password ENV.MAVEN_PASSWORD
}
javadoc {
options.addBooleanOption('html5', true)

// disable 'missing' warnings
options.addStringOption('Xdoclint:all,-missing', '-quiet')
}

publishing {
publications {
"$project.name"(MavenPublication) {
from components.java
}
}
}
Expand Down
12 changes: 8 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@ org.gradle.jvmargs=-Xmx2G

# Gradle Plugins
javafx_plugin_version = 0.1.0
checkstyle_version = 10.12.5
shadow_version = 7.1.2
extra_java_module_info_version = 1.6

# Poject Properties
version = 0.1.0

# Project Dependencies
# Core
slf4j_version = 2.0.12
asm_version = 9.6
mappingio_version = 0.5.0
# CLI
jcommander_version = 1.82
tinylog_version = 2.7.0
# GUI
fabric_cfr_version = 0.2.1
vineflower_version = 1.9.3
procyon_version = 0.6.0
jadx_version = 1.4.7
mappingio_version = 0.5.0
javaparser_version = 3.25.6
javafx_version = 21.0.1
checkstyle_version = 10.12.5
slf4j_version = 2.0.12
tinylog_version = 2.7.0
35 changes: 35 additions & 0 deletions matcher-cli/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
plugins {
id 'application'
}

archivesBaseName = 'matcher-cli'

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

if (!JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
}

tasks.withType(JavaCompile).configureEach {
it.options.release = 17
}

dependencies {
api project(':matcher-core')
api "com.beust:jcommander:${jcommander_version}"
runtimeOnly "org.tinylog:tinylog-impl:${tinylog_version}"
runtimeOnly "org.tinylog:slf4j-tinylog:${tinylog_version}"
}

application {
mainClass = 'matcher.cli.Main'
}

jar {
processResources.exclude('tinylog-dev.properties')
}
23 changes: 23 additions & 0 deletions matcher-cli/src/main/java/matcher/cli/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package matcher.cli;

import matcher.cli.provider.builtin.AdditionalPluginsCliParameterProvider;
import matcher.cli.provider.builtin.AutomatchCliCommandProvider;
import matcher.model.config.Config;

public class Main {
public static void main(String[] args) {
Config.init();

// Instantiate the CLI handler. We don't accept unknown parameters,
// since this is the base implementation where only known
// providers are registered.
MatcherCli matcherCli = new MatcherCli(false);

// Register all default providers.
matcherCli.registerParameterProvider(new AdditionalPluginsCliParameterProvider());
matcherCli.registerCommandProvider(new AutomatchCliCommandProvider());

// Parse, handle errors, delegate to the correct provider.
matcherCli.processArgs(args);
}
}
67 changes: 67 additions & 0 deletions matcher-cli/src/main/java/matcher/cli/MatcherCli.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package matcher.cli;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.beust.jcommander.JCommander;

import matcher.cli.provider.CliCommandProvider;
import matcher.cli.provider.CliParameterProvider;

/**
* Main CLI arg handler.
* You have to first register your {@link CliParameterProvider}s and/or {@link CliCommandProvider}s
* via their respective register methods, and then call {@link #processArgs(String[])}.
* JCommander attempts to parse the passed args into the providers, and if applicable,
* then proceeds to call their own {@code processArgs} methods, from where they're free
* to handle the parsed arguments as needed.
*/
public class MatcherCli {
public MatcherCli(boolean acceptUnknownParams) {
this.acceptUnknownParams = acceptUnknownParams;
}

public void registerParameterProvider(CliParameterProvider paramProvider) {
paramProviders.add(paramProvider);
}

public void registerCommandProvider(CliCommandProvider commandProvider) {
commandProviders.add(commandProvider);
}

public void processArgs(String[] args) {
JCommander.Builder jcBuilder = JCommander.newBuilder();

// Top level parameter providers
for (CliParameterProvider paramProvider : paramProviders) {
jcBuilder.addObject(paramProvider.getDataHolder());
}

// Command providers
for (CliCommandProvider commandProvider : commandProviders) {
jcBuilder.addCommand(commandProvider.getCommandName(), commandProvider.getDataHolder());
}

JCommander jCommander = jcBuilder.build();
jCommander.setAcceptUnknownOptions(acceptUnknownParams);
jCommander.parse(args);

for (CliParameterProvider paramProvider : paramProviders) {
paramProvider.processArgs();
}

for (CliCommandProvider commandProvider : commandProviders) {
if (commandProvider.getCommandName().equals(jCommander.getParsedCommand())) {
commandProvider.processArgs();
break;
}
}
}

public static final Logger LOGGER = LoggerFactory.getLogger("Matcher CLI");
private final List<CliParameterProvider> paramProviders = new ArrayList<>(5);
private final List<CliCommandProvider> commandProviders = new ArrayList<>(5);
private final boolean acceptUnknownParams;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package matcher.cli.provider;

public interface CliCommandProvider extends CliParameterProvider {
String getCommandName();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package matcher.cli.provider;

import com.beust.jcommander.Parameter;

/**
* Top-level parameter provider.
*/
public interface CliParameterProvider {
/**
* Instance of the class containing the {@link Parameter} annotations.
*/
Object getDataHolder();

/**
* Verifies args and handles them.
*/
void processArgs();
}
Loading
Loading