Skip to content

Commit

Permalink
Merge branch 'master' into upstream_dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Ecdcaeb authored Nov 24, 2024
2 parents 7e95e35 + b8f26d9 commit 81c46ce
Show file tree
Hide file tree
Showing 41 changed files with 877 additions and 270 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/build_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle

name: Build and Release Installer

on:
workflow_dispatch:

jobs:
build:
name: Build and Upload Artifact
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/[email protected]
- name: Grant Execute Permission for gradlew
run: chmod +x ./gradlew
- name: Set up JDK 21
uses: actions/[email protected]
with:
java-version: '21'
distribution: 'temurin'

- name: Build
run: ./gradlew build
- name: Create GitHub Release
uses: KorewaLidesu/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: latest #TODO
commitish: ${{ github.ref.name }}
body: "" #TODO
name: 1.0.0.0 #TODO
prerelease: false
allow_override: true
gzip: false
files: |
build/libs/*.jar
35 changes: 35 additions & 0 deletions .github/workflows/build_snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This workflow will build and upload test artifact
# Simple workflow with ignoring condition to prevent unneccessary build
# To download artifact check on job task

name: Build Test Artifact

on:
push:
branches:
paths-ignore:
- 'docs/**'

jobs:
build:
name: Build and Upload Artifact
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/[email protected]
- name: Grant Execute Permission for gradlew
run: chmod +x ./gradlew
- name: Set up JDK 21
uses: actions/[email protected]
with:
java-version: '21'
distribution: 'temurin'

- name: Build
run: ./gradlew build
- name: Upload Build Artifacts
uses: actions/[email protected]
with:
name: JavaOctetEditor-snapshot-${{ github.run_number}}.jar
path: build/libs
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# JavaOctetEditor

![GitHub all releases](https://img.shields.io/github/downloads/Enaium/JavaOctetEditor/total?style=flat-square)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/Enaium/JavaOctetEditor?style=flat-square)
![GitHub release (latest SemVer including pre-releases)](https://img.shields.io/github/v/release/Enaium/JavaOctetEditor?include_prereleases&style=flat-square)
![GitHub](https://img.shields.io/github/license/Enaium/JavaOctetEditor?style=flat-square)
![GitHub all releases](https://img.shields.io/github/downloads/Ecdcaeb/JavaOctetEditor/total?style=flat-square)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/Ecdcaeb/JavaOctetEditor?style=flat-square)
![GitHub release (latest SemVer including pre-releases)](https://img.shields.io/github/v/release/Ecdcaeb/JavaOctetEditor?include_prereleases&style=flat-square)
![GitHub](https://img.shields.io/github/license/Ecdcaeb/JavaOctetEditor?style=flat-square)

![](https://user-images.githubusercontent.com/32991121/190947407-bbc6642e-2c9d-46f3-921c-6558c74272cf.png)
![](https://user-images.githubusercontent.com/32991121/190947409-9df48d03-e1b7-4c0a-ae1d-08e1ca2bc9aa.png)
Expand Down
36 changes: 19 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import java.text.SimpleDateFormat
import org.gradle.internal.jvm.Jvm

plugins {
id 'java'
id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'idea'
}

group 'cn.enaium'
version '1.4.0-beta.4'

sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
java.toolchain.languageVersion = JavaLanguageVersion.of(21)

jar {
manifest.attributes(
Expand All @@ -33,28 +32,29 @@ repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
maven { url 'https://maven.quiltmc.org/repository/release' }
maven { url 'https://maven.cleanroommc.com'}
}

dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.11.3'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.11.3'

implementation 'com.formdev:flatlaf:2.6'
implementation 'com.formdev:flatlaf-extras:2.6'
implementation 'com.formdev:flatlaf:3.5.2'
implementation 'com.formdev:flatlaf-extras:3.5.2'
//noinspection GradlePackageUpdate
implementation 'com.miglayout:miglayout-swing:5.3'
implementation 'com.github.bobbylight:RSyntaxTextArea:3.2.0'
implementation 'org.ow2.asm:asm-tree:9.4'
implementation 'org.ow2.asm:asm-util:9.4'
implementation 'org.ow2.asm:asm-commons:9.4'
implementation 'com.miglayout:miglayout-swing:11.4.2'
implementation 'com.github.bobbylight:RSyntaxTextArea:3.5.2'
implementation 'org.ow2.asm:asm-tree:9.7.1'
implementation 'org.ow2.asm:asm-util:9.7.1'
implementation 'org.ow2.asm:asm-commons:9.7.1'
implementation 'org.benf:cfr:0.152'
implementation 'com.github.mstrobel.procyon:procyon-decompiler:v0.6.0'
implementation 'org.quiltmc:quiltflower:1.8.1'
implementation 'com.google.code.gson:gson:2.10'
implementation 'org.vineflower:vineflower:1.10.1'
implementation 'org.javassist:javassist:3.30.2-GA'
implementation 'com.google.code.gson:gson:2.11.0'
implementation 'org.tinylog:tinylog:1.3.6'
implementation 'com.github.FabricMC:mapping-io:597f0722d6'

compileOnly files(Jvm.current().getToolsJar())//Must use jdk8
implementation 'zone.rong:imaginebreaker:2.1'
}

test {
Expand All @@ -71,8 +71,10 @@ shadowJar {
include(dependency('com.github.mstrobel.procyon:procyon-decompiler'))
include(dependency('com.google.code.gson:gson'))
include(dependency('org.tinylog:.*'))
include(dependency('org.quiltmc:quiltflower'))
include(dependency('org.vineflower:vineflower'))
include(dependency('com.github.FabricMC:mapping-io'))
include(dependency('com.github.FabricMC:mapping-io'))
include(dependency('zone.rong:imaginebreaker'))
}
archiveClassifier.set('')
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 0 additions & 4 deletions src/main/java/cn/enaium/joe/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@

package cn.enaium.joe;

import cn.enaium.joe.jar.Jar;
import cn.enaium.joe.util.ReflectUtil;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.tree.ClassNode;

import java.io.IOException;
import java.lang.instrument.Instrumentation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/cn/enaium/joe/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@

import cn.enaium.joe.config.extend.ApplicationConfig;
import cn.enaium.joe.jar.Jar;
import cn.enaium.joe.util.IOUtil;
import cn.enaium.joe.util.MessageUtil;
import cn.enaium.joe.util.ReflectUtil;
import cn.enaium.joe.util.TinyLogPrintStream;
import cn.enaium.joe.util.*;
import com.formdev.flatlaf.FlatDarkLaf;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.tree.ClassNode;
Expand Down Expand Up @@ -51,11 +48,11 @@
*/
public final class Main {
public static void main(String[] args) {
ImagineBreakerHelper.boot();
loadTools();
launch();
}


private static void agent(Instrumentation inst) throws IOException {
launch();
Jar jar = new Jar();
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/cn/enaium/joe/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,36 @@

package cn.enaium.joe.config;

import java.util.Collections;
import java.util.Set;
import java.util.function.Consumer;

/**
* @author Enaium
* @since 0.7.0
*/
public class Config {
private final String name;

private transient final Set<Consumer<Config>> listeners;

public Config(String name) {
this(name, Collections.emptySet());
}

public Config(String name, Set<Consumer<Config>> listeners ) {
this.name = name;
this.listeners = listeners;
}

public void update(){
for(Consumer<Config> consumer : listeners){
consumer.accept(this);
}
}

public String getName() {
return name;
}

}
45 changes: 28 additions & 17 deletions src/main/java/cn/enaium/joe/config/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.util.*;
import java.util.stream.Collectors;

/**
* @author Enaium
Expand All @@ -38,11 +38,11 @@ public class ConfigManager {
private final Map<Class<? extends Config>, Config> configMap = new LinkedHashMap<>();

public ConfigManager() {
setByClass(new ApplicationConfig());
setByClass(new CFRConfig());
setByClass(new FernFlowerConfig());
setByClass(new ProcyonConfig());
setByClass(new KeymapConfig());
addByInstance(new ApplicationConfig());
addByInstance(new CFRConfig());
addByInstance(new FernFlowerConfig());
addByInstance(new ProcyonConfig());
addByInstance(new KeymapConfig());
}

@SuppressWarnings("unchecked")
Expand All @@ -54,25 +54,36 @@ public <T> T getByClass(Class<T> klass) {
}
}

public void setByClass(Config config) {
public <T extends Config> void addByClass(Class<T> config) {
try {
configMap.put(config, config.getConstructor().newInstance());
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw MessageUtil.runtimeException("Could not setup Config for " + config, e);
}
}

public void addByInstance(Config config) {
configMap.put(config.getClass(), config);
}

public Map<Class<? extends Config>, Config> getConfig() {
return configMap;
}

public Map<String, String> getConfigMap(Class<? extends Config> config) {
Map<String, String> map = new HashMap<>();
public Map<String, String> getConfigMapStrings(Class<? extends Config> config) {
return getConfigMap(config).entrySet().stream()
.filter(entry -> entry.getValue().getValue() != null)
.collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().getValue().toString()));
}

public Map<String, Value<?>> getConfigMap(Class<? extends Config> config) {
Map<String, Value<?>> map = new HashMap<>();
for (Field declaredField : config.getDeclaredFields()) {
declaredField.setAccessible(true);
try {
Object o = declaredField.get(getByClass(config));
if (o instanceof Value<?>) {
Object value = ((Value<?>) o).getValue();
if (value != null) {
map.put(declaredField.getName(), value.toString());
}
map.put(declaredField.getName(), (Value<?>)o);
}
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
Expand All @@ -93,8 +104,7 @@ public void load() {
try {
File file = new File(System.getProperty("."), config.getName() + ".json");
if (file.exists()) {
JsonObject jsonObject = gson().create().fromJson(new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8), JsonObject.class);

JsonObject jsonObject = gson().create().fromJson(Files.readString(file.toPath()), JsonObject.class);
for (Field configField : klass.getDeclaredFields()) {
configField.setAccessible(true);
if (!jsonObject.has(configField.getName())) {
Expand Down Expand Up @@ -148,7 +158,8 @@ public void load() {
public void save() {
for (Config value : configMap.values()) {
try {
Files.write(new File(System.getProperty("."), value.getName() + ".json").toPath(), gson().registerTypeAdapter(KeyStroke.class, (JsonSerializer<KeyStroke>) (src, typeOfSrc, context) -> new JsonPrimitive(src.toString())).create().toJson(value).getBytes(StandardCharsets.UTF_8));
Files.writeString(new File(System.getProperty("."), value.getName() + ".json").toPath(), gson().toJson(value));
value.update();
} catch (IOException e) {
MessageUtil.error(e);
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/cn/enaium/joe/config/extend/CFRConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
import cn.enaium.joe.config.value.IntegerValue;
import cn.enaium.joe.config.value.ModeValue;
import cn.enaium.joe.config.value.StringValue;
import cn.enaium.joe.service.decompiler.CFRDecompiler;
import org.benf.cfr.reader.state.OsInfo;

import java.util.Set;

/**
* @author Enaium
* @since 0.7.0
Expand Down Expand Up @@ -323,6 +326,6 @@ public class CFRConfig extends Config {
"Propagate bytecode location info.");

public CFRConfig() {
super("CFR");
super("CFR", Set.of((value) -> CFRDecompiler.update()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import cn.enaium.joe.config.value.IntegerValue;
import cn.enaium.joe.config.value.ModeValue;
import cn.enaium.joe.config.value.StringValue;
import cn.enaium.joe.service.decompiler.FernFlowerDecompiler;

import java.util.Arrays;
import java.util.Set;

/**
* @author Enaium
Expand Down Expand Up @@ -86,6 +88,6 @@ public class FernFlowerConfig extends Config {


public FernFlowerConfig() {
super("FernFlower");
super("FernFlower", Set.of((config)-> FernFlowerDecompiler.updateCustomProperties()));
}
}
Loading

0 comments on commit 81c46ce

Please sign in to comment.