This repository has been archived by the owner on Dec 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from Diruptio/feature/plugin/classtransformer
Class Transformers
- Loading branch information
Showing
18 changed files
with
377 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ plugins { | |
} | ||
|
||
group = "diruptio" | ||
version = "0.2.0" | ||
version = "0.3.0" | ||
|
||
repositories { | ||
mavenCentral() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
plugins { | ||
id("java") | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation(project(":node:loader")) | ||
implementation(project(":node")) | ||
} | ||
|
||
tasks { | ||
compileJava { | ||
options.encoding = "UTF-8" | ||
options.release = 17 | ||
} | ||
|
||
jar { | ||
from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) }) | ||
duplicatesStrategy = DuplicatesStrategy.INCLUDE | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
plugins { | ||
id("java") | ||
id("application") | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation(project(":common")) | ||
implementation(project(":node:plugin-api")) | ||
compileOnly("org.jetbrains:annotations:25.0.0") | ||
implementation("net.lenni0451.classtransform:core:1.14.0") | ||
implementation("net.lenni0451.classtransform:additionalclassprovider:1.14.0") | ||
implementation("net.lenni0451.classtransform:mixinstranslator:1.14.0") | ||
implementation("net.lenni0451.classtransform:mixinsdummy:1.14.0") | ||
} | ||
|
||
val addJars = | ||
tasks.register<Copy>("addJars") { | ||
val nodeTask = project(":node").tasks.named("jar").get() | ||
dependsOn(nodeTask) | ||
from(nodeTask.outputs) | ||
into(layout.buildDirectory.dir("generated/sources/resources")) | ||
} | ||
sourceSets.main.get().resources.srcDirs(addJars.map { it.outputs }) | ||
|
||
tasks { | ||
compileJava { | ||
dependsOn(addJars) | ||
options.encoding = "UTF-8" | ||
options.release = 17 | ||
} | ||
|
||
jar { | ||
from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) }) | ||
duplicatesStrategy = DuplicatesStrategy.INCLUDE | ||
archiveBaseName = "OCNode" | ||
manifest.attributes["Implementation-Title"] = "ObsidianCloud" | ||
manifest.attributes["Implementation-Version"] = version | ||
manifest.attributes["Main-Class"] = "de.obsidiancloud.node.ObsidianCloudNodeLoader" | ||
} | ||
|
||
named<JavaExec>("run") { | ||
workingDir = rootProject.file("run") | ||
workingDir.mkdirs() | ||
standardOutput = System.out | ||
standardInput = System.`in` | ||
} | ||
} | ||
|
||
application { | ||
mainClass = "de.obsidiancloud.node.ObsidianCloudNodeLoader" | ||
} |
64 changes: 64 additions & 0 deletions
64
node/loader/src/main/java/de/obsidiancloud/node/ObsidianCloudNodeLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package de.obsidiancloud.node; | ||
|
||
import de.obsidiancloud.node.plugin.DefaultPluginLoader; | ||
import de.obsidiancloud.node.plugin.PluginLoader; | ||
import de.obsidiancloud.node.util.SharedClassLoader; | ||
import java.io.InputStream; | ||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Method; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.StandardCopyOption; | ||
import java.util.Objects; | ||
import java.util.logging.Level; | ||
import java.util.logging.LogManager; | ||
import java.util.logging.Logger; | ||
import net.lenni0451.classtransform.TransformerManager; | ||
import net.lenni0451.classtransform.additionalclassprovider.MutableBasicClassProvider; | ||
import net.lenni0451.classtransform.mixinstranslator.MixinsTranslator; | ||
import net.lenni0451.classtransform.utils.FailStrategy; | ||
import net.lenni0451.classtransform.utils.loader.InjectionClassLoader; | ||
import net.lenni0451.classtransform.utils.tree.IClassProvider; | ||
|
||
public class ObsidianCloudNodeLoader { | ||
private static final Logger logger = Logger.getLogger("loader"); | ||
|
||
public static void main(String[] args) { | ||
try { | ||
Files.createDirectories(Path.of("logs")); | ||
LogManager.getLogManager() | ||
.readConfiguration( | ||
ObsidianCloudNodeLoader.class.getClassLoader().getResourceAsStream("logging.properties")); | ||
logger.info("Loading the Node..."); | ||
|
||
InputStream inputStream = ObsidianCloudNodeLoader.class.getResourceAsStream("/OCNode.jar"); | ||
Path tempFile = Files.createTempFile("OCNode", ".jar"); | ||
tempFile.toFile().deleteOnExit(); | ||
Files.copy(Objects.requireNonNull(inputStream), tempFile, StandardCopyOption.REPLACE_EXISTING); | ||
inputStream.close(); | ||
|
||
IClassProvider classProvider = new MutableBasicClassProvider(new SharedClassLoader()); | ||
TransformerManager transformerManager = new TransformerManager(classProvider); | ||
transformerManager.setFailStrategy(FailStrategy.CONTINUE); | ||
transformerManager.addTransformerPreprocessor(new MixinsTranslator()); | ||
InjectionClassLoader nodeClassLoader = new InjectionClassLoader( | ||
transformerManager, | ||
new SharedClassLoader(), | ||
tempFile.toUri().toURL()); | ||
|
||
PluginLoader pluginLoader = new DefaultPluginLoader(transformerManager); | ||
pluginLoader.loadPlugins(); | ||
|
||
Class<?> clazz = nodeClassLoader.loadClass("de.obsidiancloud.node.ObsidianCloudNode"); | ||
Field field = clazz.getDeclaredField("pluginLoader"); | ||
field.setAccessible(true); | ||
field.set(null, pluginLoader); | ||
|
||
logger.info("Launching the Node..."); | ||
Method method = clazz.getDeclaredMethod("main", String[].class); | ||
method.invoke(null, (Object) args); | ||
} catch (Throwable exception) { | ||
logger.log(Level.SEVERE, "Failed to load the Node", exception); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
handlers=java.util.logging.ConsoleHandler,java.util.logging.FileHandler | ||
|
||
java.util.logging.ConsoleHandler.level=ALL | ||
java.util.logging.ConsoleHandler.formatter=de.obsidiancloud.common.logging.ConsoleFormatter | ||
java.util.logging.ConsoleHandler.encoding=UTF-8 | ||
|
||
java.util.logging.FileHandler.level=INFO | ||
java.util.logging.FileHandler.formatter=de.obsidiancloud.common.logging.FileFormatter | ||
java.util.logging.FileHandler.encoding=UTF-8 | ||
java.util.logging.FileHandler.pattern=logs/node.log | ||
java.util.logging.FileHandler.limit=50000 | ||
java.util.logging.FileHandler.count=50000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
plugins { | ||
id("java") | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
compileOnly(project(":common")) | ||
compileOnly("org.jetbrains:annotations:25.0.0") | ||
compileOnly("net.lenni0451.classtransform:core:1.14.0") | ||
} | ||
|
||
tasks { | ||
compileJava { | ||
options.encoding = "UTF-8" | ||
options.release = 17 | ||
} | ||
|
||
jar { | ||
from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) }) | ||
duplicatesStrategy = DuplicatesStrategy.INCLUDE | ||
} | ||
} |
Oops, something went wrong.