-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
290 additions
and
133 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
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,41 @@ | ||
/* | ||
* Numismatics | ||
* Copyright (c) 2024 The Railways Team | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
plugins { | ||
id("java-gradle-plugin") | ||
kotlin("jvm") version "1.9.23" | ||
`kotlin-dsl` | ||
} | ||
|
||
repositories { | ||
gradlePluginPortal() | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation("org.ow2.asm:asm:${"asm_version"()}") | ||
//implementation("org.ow2.asm:asm-analysis:${"asm_version"()}") | ||
//implementation("org.ow2.asm:asm-commons:${"asm_version"()}") | ||
implementation("org.ow2.asm:asm-tree:${"asm_version"()}") | ||
implementation("org.ow2.asm:asm-util:${"asm_version"()}") | ||
} | ||
|
||
operator fun String.invoke(): String { | ||
return rootProject.ext[this] as? String | ||
?: throw IllegalStateException("Property $this is not defined") | ||
} |
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,19 @@ | ||
# | ||
# Numismatics | ||
# Copyright (c) 2024 The Railways Team | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
# | ||
|
||
asm_version = 9.5 |
44 changes: 44 additions & 0 deletions
44
buildSrc/src/main/kotlin/dev/ithundxr/numismaticsgradle/asm/NumismaticsGradleASM.kt
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,44 @@ | ||
/* | ||
* Numismatics | ||
* Copyright (c) 2024 The Railways Team | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package dev.ithundxr.numismaticsgradle.asm | ||
|
||
import dev.ithundxr.numismaticsgradle.asm.internal.SubprojectType | ||
import dev.ithundxr.numismaticsgradle.asm.transformers.CCCapabilitiesASM | ||
import org.objectweb.asm.ClassReader | ||
import org.objectweb.asm.ClassWriter | ||
import org.objectweb.asm.tree.ClassNode | ||
import org.objectweb.asm.util.CheckClassAdapter | ||
|
||
class NumismaticsGradleASM { | ||
fun transformClass(projectPath: String, bytes: ByteArray): ByteArray { | ||
// Get project type | ||
val project = SubprojectType.getProjectType(projectPath) | ||
|
||
var node = ClassNode() | ||
ClassReader(bytes).accept(node, 0) | ||
|
||
// Transformers | ||
node = CCCapabilitiesASM().transform(project, node) | ||
|
||
// Verify the bytecode is valid | ||
val byteArray = ClassWriter(0).also { node.accept(it) }.toByteArray() | ||
ClassReader(byteArray).accept(CheckClassAdapter(null), 0) | ||
return byteArray | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
buildSrc/src/main/kotlin/dev/ithundxr/numismaticsgradle/asm/internal/SubprojectType.kt
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,34 @@ | ||
/* | ||
* Numismatics | ||
* Copyright (c) 2024 The Railways Team | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package dev.ithundxr.numismaticsgradle.asm.internal | ||
|
||
enum class SubprojectType { | ||
COMMON, FABRIC, FORGE; | ||
|
||
companion object { | ||
fun getProjectType(projectPath: String): SubprojectType { | ||
return when (projectPath) { | ||
":common" -> COMMON | ||
":fabric" -> FABRIC | ||
":forge" -> FORGE | ||
else -> throw IllegalStateException("Invalid Project Type") | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.