Skip to content

Commit

Permalink
Lotus-ing
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Jun 9, 2024
1 parent 5f47f4a commit 96023f4
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 138 deletions.
3 changes: 1 addition & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ plugins {
id("com.github.johnrengelman.shadow") version "8.1.1" apply false
id("dev.ithundxr.silk") version "0.11.+" // https://github.com/IThundxr/silk
id("dev.ithundxr.numismatics.gradle") apply false
//id("dev.ithundxr.lotus.gradle") version "0.0.2" apply false
}

val isRelease = System.getenv("RELEASE_BUILD")?.toBoolean() ?: false
Expand Down Expand Up @@ -68,7 +67,7 @@ allprojects {
subprojects {
apply(plugin = "dev.architectury.loom")
apply(plugin = "dev.ithundxr.numismatics.gradle")
//apply(plugin = "dev.ithundxr.lotus.gradle")
apply(plugin = "dev.ithundxr.lotus.gradle")

val capitalizedName = project.name.capitalized()

Expand Down
5 changes: 3 additions & 2 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ plugins {
repositories {
gradlePluginPortal()
mavenCentral()
maven("https://maven.ithundxr.dev/releases")
}

gradlePlugin {
Expand All @@ -38,10 +39,10 @@ gradlePlugin {

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"()}")

implementation("dev.ithundxr.lotus:lotus-gradle:${"lotus_gradle_version"()}")
}

operator fun String.invoke(): String {
Expand Down
4 changes: 4 additions & 0 deletions buildSrc/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

# Lotus
# https://maven.ithundxr.dev/#/releases/dev/ithundxr/lotus/lotus-gradle
lotus_gradle_version = 0.0.9

asm_version = 9.5
Original file line number Diff line number Diff line change
Expand Up @@ -18,59 +18,13 @@

package dev.ithundxr.numismaticsgradle

import dev.ithundxr.numismaticsgradle.asm.NumismaticsGradleASM
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import dev.ithundxr.lotus.gradle.api.asm.LotusGradleASM
import dev.ithundxr.numismaticsgradle.transformers.CCCapabilitiesTransformer
import org.gradle.api.Plugin
import org.gradle.api.Project
import java.util.jar.JarEntry
import java.util.jar.JarFile
import java.util.jar.JarOutputStream
import java.util.zip.Deflater

class NumismaticsGradlePlugin : Plugin<Project> {
override fun apply(project: Project) {
project.tasks.named("remapJar").configure {
doLast {
val jar = outputs.files.singleFile

var architecturyInjectableName = project.name
if (project.rootProject != project)
architecturyInjectableName = project.rootProject.name + "_" + architecturyInjectableName

val contents = linkedMapOf<String, ByteArray>()
JarFile(jar).use {
it.entries().asIterator().forEach { entry ->
if (!entry.isDirectory) {
contents[entry.name] = it.getInputStream(entry).readAllBytes()
}
}
}

jar.delete()

JarOutputStream(jar.outputStream()).use { out ->
out.setLevel(Deflater.BEST_COMPRESSION)

contents.forEach { var (name, data) = it
if (name.contains("architectury_inject_${architecturyInjectableName}_common"))
return@forEach

if (name.endsWith(".json") || name.endsWith(".mcmeta")) {
data = (JsonOutput.toJson(JsonSlurper().parse(data)).toByteArray())
} else if (name.endsWith(".class")) {
data = NumismaticsGradleASM().transformClass(project, data)
}

out.putNextEntry(JarEntry(name))
out.write(data)
out.closeEntry()
}

out.finish()
out.close()
}
}
}
LotusGradleASM.addTransformer(CCCapabilitiesTransformer::class)
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package dev.ithundxr.numismaticsgradle.asm.transformers
package dev.ithundxr.numismaticsgradle.transformers

import dev.ithundxr.numismaticsgradle.asm.internal.SubprojectType
import dev.ithundxr.lotus.gradle.api.asm.util.IClassTransformer
import dev.ithundxr.lotus.gradle.api.asm.util.SubprojectType
import org.objectweb.asm.Label
import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.ClassNode

class CCCapabilitiesTransformer {
class CCCapabilitiesTransformer : IClassTransformer {
@Suppress("LocalVariableName")
fun transform(project: SubprojectType, node: ClassNode) {
override fun transform(project: SubprojectType, node: ClassNode) {
if (node.invisibleAnnotations != null && project == SubprojectType.FORGE) {
// Cache the field, so we don't CME the list during the remove
val annotationNodes = node.invisibleAnnotations.toList()
Expand Down
18 changes: 18 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
#
# 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/>.
#

org.gradle.jvmargs = -Xmx4G

# Mod Info
Expand Down

0 comments on commit 96023f4

Please sign in to comment.