Skip to content

Commit

Permalink
close filesystems.
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed May 16, 2024
1 parent 2efa997 commit 8b64448
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 26 deletions.
7 changes: 4 additions & 3 deletions gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import org.gradle.kotlin.dsl.internal.sharedruntime.codegen.licenseHeader
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.util.*

plugins {
kotlin("jvm") version "1.9.22"
`java-gradle-plugin`
`maven-publish`
id("io.github.sgtsilvio.gradle.metadata") version "0.5.0"
}

metadata {
Expand Down Expand Up @@ -33,9 +33,10 @@ dependencies {
// commons compress
implementation("org.apache.commons:commons-compress:1.26.1")

testImplementation(kotlin("test"))
implementation(project(":"))
implementation(rootProject.sourceSets.getByName("shared").output)

implementation("org.ow2.asm:asm:${asmVersion}")
testImplementation(kotlin("test"))
}

tasks.withType<KotlinCompile> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ abstract class ShadeAPI : Jar() {
@get:Optional
var shadePath by FinalizeOnRead(LazyMutable { archiveBaseName.get().replace(Regex("[ -]"), "_") + "/jvmdg/api" })

init {
debugPrint.convention(false)
}

private var configureShade: JavaExecSpec.() -> Unit = {}

Expand Down
41 changes: 36 additions & 5 deletions gradle-plugin/test-downgrade/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,31 @@ import xyz.wagyourtail.jvmdg.gradle.task.DowngradeJar
import xyz.wagyourtail.jvmdg.gradle.task.ShadeAPI
import java.util.*

plugins {
`java`
id("xyz.wagyourtail.jvmdowngrader")
buildscript {
repositories {
flatDir {
dirs("../../build/libs")
}
flatDir {
dirs("../build/libs")
}
}
dependencies {
val props = projectDir.parentFile.parentFile.resolve("gradle.properties").inputStream().use {
val props = java.util.Properties()
props.load(it)
props
}
classpath("xyz.wagyourtail.jvmdowngrader:jvmdowngrader-gradle-plugin:${props.getProperty("version")}")
classpath("xyz.wagyourtail.jvmdowngrader:jvmdowngrader:${props.getProperty("version")}")

classpath("org.apache.commons:commons-compress:1.26.1")

classpath("org.ow2.asm:asm:${props.getProperty("asm_version")}")
classpath("org.ow2.asm:asm-commons:${props.getProperty("asm_version")}")
classpath("org.ow2.asm:asm-tree:${props.getProperty("asm_version")}")
classpath("org.ow2.asm:asm-util:${props.getProperty("asm_version")}")
}
}

val props = projectDir.parentFile.parentFile.resolve("gradle.properties").inputStream().use {
Expand All @@ -13,8 +35,12 @@ val props = projectDir.parentFile.parentFile.resolve("gradle.properties").inputS
props
}

jvmdg.version = props.getProperty("version") as String

plugins {
java
}

apply(plugin = "xyz.wagyourtail.jvmdowngrader")

val testVersion: JavaVersion = JavaVersion.toVersion(props.getProperty("testVersion") as String)

Expand Down Expand Up @@ -58,6 +84,7 @@ val downgradeJar9 by tasks.creating(DowngradeJar::class) {
archiveClassifier.set("downgraded-9")
downgradeTo = JavaVersion.VERSION_1_9
archiveVersion.set(props.getProperty("version") as String)
// destinationDirectory.set(temporaryDir)
}

val shadeDowngradedApi9 by tasks.creating(ShadeAPI::class) {
Expand All @@ -66,5 +93,9 @@ val shadeDowngradedApi9 by tasks.creating(ShadeAPI::class) {
downgradeTo = JavaVersion.VERSION_1_9
}

tasks.build.get().dependsOn(tasks.shadeDowngradedApi)
tasks.getByName<DowngradeJar>("downgradeJar") {
// destinationDirectory.set(temporaryDir)
}

tasks.build.get().dependsOn(tasks.getByName("shadeDowngradedApi"))
tasks.build.get().dependsOn(shadeDowngradedApi9)
2 changes: 0 additions & 2 deletions gradle-plugin/test-downgrade/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ pluginManagement {
}
}

includeBuild("../")

rootProject.name = "test-downgrade"
44 changes: 28 additions & 16 deletions src/main/java/xyz/wagyourtail/jvmdg/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,22 @@ public static Set<File> getClasspath(Map<String, List<String[]>> args) {
public static void downgrade(Map<String, List<String[]>> args) throws IOException {
Map<Path, Path> targets = new HashMap<>();
List<FileSystem> fileSystems = new ArrayList<>();
getTargets(args, targets, fileSystems);
try {
getTargets(args, targets, fileSystems);

List<Path> inputs = new ArrayList<>();
List<Path> outputs = new ArrayList<>();
for (Map.Entry<Path, Path> entry : targets.entrySet()) {
inputs.add(entry.getKey());
outputs.add(entry.getValue());
}
List<Path> inputs = new ArrayList<>();
List<Path> outputs = new ArrayList<>();
for (Map.Entry<Path, Path> entry : targets.entrySet()) {
inputs.add(entry.getKey());
outputs.add(entry.getValue());
}

PathDowngrader.downgradePaths(Flags.classVersion, inputs, outputs, getClasspath(args));
PathDowngrader.downgradePaths(Flags.classVersion, inputs, outputs, getClasspath(args));
} finally {
for (FileSystem fileSystem : fileSystems) {
fileSystem.close();
}
}
}

public static void shade(Map<String, List<String[]>> args) throws IOException {
Expand All @@ -224,16 +230,22 @@ public static void shade(Map<String, List<String[]>> args) throws IOException {

Map<Path, Path> targets = new HashMap<>();
List<FileSystem> fileSystems = new ArrayList<>();
getTargets(args, targets, fileSystems);
try {
getTargets(args, targets, fileSystems);

List<Path> inputs = new ArrayList<>();
List<Path> outputs = new ArrayList<>();
for (Map.Entry<Path, Path> entry : targets.entrySet()) {
inputs.add(entry.getKey());
outputs.add(entry.getValue());
}
List<Path> inputs = new ArrayList<>();
List<Path> outputs = new ArrayList<>();
for (Map.Entry<Path, Path> entry : targets.entrySet()) {
inputs.add(entry.getKey());
outputs.add(entry.getValue());
}

ApiShader.shadeApis(Flags.classVersion, prefix, inputs, outputs, downgradedApi);
ApiShader.shadeApis(Flags.classVersion, prefix, inputs, outputs, downgradedApi);
} finally {
for (FileSystem fileSystem : fileSystems) {
fileSystem.close();
}
}
}

public static void bootstrap(Map<String, List<String[]>> args, List<String> unparsed) throws MalformedURLException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Expand Down

0 comments on commit 8b64448

Please sign in to comment.