-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
1 parent
7dc7918
commit 7e86cb6
Showing
38 changed files
with
436 additions
and
152 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
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,77 @@ | ||
import org.gradle.api.tasks.testing.logging.TestLogEvent | ||
|
||
plugins { | ||
java | ||
} | ||
|
||
val testVersion = JavaVersion.toVersion(project.properties["testVersion"] as String) | ||
|
||
java { | ||
sourceCompatibility = testVersion | ||
targetCompatibility = testVersion | ||
toolchain { | ||
languageVersion.set(JavaLanguageVersion.of(testVersion.majorVersion)) | ||
} | ||
} | ||
|
||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
sourceSets { | ||
test { | ||
compileClasspath += rootProject.sourceSets.main.get().compileClasspath + rootProject.sourceSets.main.get().output | ||
runtimeClasspath += rootProject.sourceSets.main.get().runtimeClasspath + rootProject.sourceSets.main.get().output | ||
} | ||
} | ||
|
||
dependencies { | ||
testImplementation("org.junit.jupiter:junit-jupiter:5.10.2") | ||
testRuntimeOnly("org.junit.platform:junit-platform-launcher") | ||
|
||
testImplementation("com.google.code.gson:gson:2.10") | ||
testImplementation("org.apache.commons:commons-compress:1.26.1") | ||
testImplementation("io.github.java-diff-utils:java-diff-utils:4.12") | ||
} | ||
|
||
val testTargetVersion = JavaVersion.toVersion(project.properties["testTargetVersion"] as String) | ||
|
||
tasks.test { | ||
useJUnitPlatform() | ||
|
||
dependsOn( | ||
project(":testing:downgrade").tasks.build, | ||
project(":testing:multi-version").tasks.build, | ||
project(":java-api").tasks.named("testJar") | ||
) | ||
|
||
val versions = listOf( | ||
testVersion, | ||
testTargetVersion, | ||
JavaVersion.VERSION_1_7, | ||
JavaVersion.VERSION_11, | ||
JavaVersion.VERSION_17 | ||
).associateWith { | ||
javaToolchains.launcherFor { | ||
languageVersion.set(JavaLanguageVersion.of(it.majorVersion)) | ||
}.get().executablePath.toString() | ||
} | ||
|
||
jvmArgs( | ||
"-Djvmdg.test.version=$version", | ||
"-Djvmdg.test.originalVersion=$testVersion", | ||
"-Djvmdg.test.javaVersion=${versions.keys.joinToString(File.pathSeparator) { it.majorVersion }}", | ||
"-Djvmdg.test.launcher=${versions.values.joinToString(File.pathSeparator)}", | ||
"-Djvmdg.test.downgradeClasspath=${rootProject.sourceSets["shared"].compileClasspath.joinToString(File.pathSeparator) { it.absolutePath }}", | ||
"-Djvmdg.test.downgradePath=${project(":testing:downgrade").tasks.jar.get().outputs.files.singleFile.absolutePath}", | ||
"-Djvmdg.test.multiVersionPath=${project(":testing:multi-version").tasks.jar.get().outputs.files.singleFile.absolutePath}", | ||
"-Djvmdg.test.javaApiPath=${project(":java-api").tasks.named("testJar").get().outputs.files.singleFile.absolutePath}", | ||
) | ||
|
||
testLogging { | ||
events.add(TestLogEvent.PASSED) | ||
events.add(TestLogEvent.SKIPPED) | ||
events.add(TestLogEvent.FAILED) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,32 @@ | ||
plugins { | ||
java | ||
} | ||
|
||
base { | ||
archivesName = "multi-version" | ||
} | ||
version = "1.0.0" | ||
|
||
val testVersion = JavaVersion.toVersion(project.properties["testVersion"] as String) | ||
|
||
java { | ||
sourceCompatibility = testVersion | ||
targetCompatibility = testVersion | ||
toolchain { | ||
languageVersion.set(JavaLanguageVersion.of(testVersion.majorVersion)) | ||
} | ||
} | ||
|
||
tasks.compileJava { | ||
options.encoding = "UTF-8" | ||
} | ||
|
||
val removeLibs by tasks.registering { | ||
doLast { | ||
delete(fileTree("dir" to "build/libs", "include" to "**/*.jar")) | ||
} | ||
} | ||
|
||
tasks.jar { | ||
dependsOn(removeLibs) | ||
} |
9 changes: 9 additions & 0 deletions
9
testing/multi-version/src/main/java/xyz/wagyourtail/multiversion/MatchExcJ21.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,9 @@ | ||
package xyz.wagyourtail.multiversion; | ||
|
||
public class MatchExcJ21 { | ||
|
||
public static void main(String[] args) { | ||
throw new MatchException("This is a test", null); | ||
} | ||
|
||
} |
File renamed without changes.
84 changes: 84 additions & 0 deletions
84
testing/src/test/java/xyz/wagyourtail/jvmdg/test/integration/BaseIntegrationTests.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,84 @@ | ||
package xyz.wagyourtail.jvmdg.test.integration; | ||
|
||
import xyz.wagyourtail.jvmdg.ClassDowngrader; | ||
import xyz.wagyourtail.jvmdg.cli.Flags; | ||
import xyz.wagyourtail.jvmdg.compile.ZipDowngrader; | ||
import xyz.wagyourtail.jvmdg.test.JavaRunner; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public abstract class BaseIntegrationTests { | ||
private static final String JVMDG_VERSION_KEY = "jvmdg.test.version"; | ||
private static final String ORIGINAL_VERSION_KEY = "jvmdg.test.originalVersion"; | ||
private static final String JAVA_VERSION_KEY = "jvmdg.test.javaVersion"; | ||
private static final String LAUNCHER_KEY = "jvmdg.test.launcher"; | ||
private static final String DOWNGRADE_CLASSPATH = "jvmdg.test.downgradeClasspath"; | ||
|
||
private static final String JAVA_API_PATH = "jvmdg.test.javaApiPath"; | ||
|
||
public static final Path javaApi = Path.of(System.getProperty(JAVA_API_PATH)); | ||
public static final List<Path> downgradeClasspath = Arrays.stream(System.getProperty(DOWNGRADE_CLASSPATH).split(File.pathSeparator)).map(Path::of).toList(); | ||
|
||
public static final Flags flags = new Flags(); | ||
|
||
public static final JavaRunner.JavaVersion originalVersion = JavaRunner.JavaVersion.fromMajor(Integer.parseInt(System.getProperty(ORIGINAL_VERSION_KEY))); | ||
|
||
private static final List<JavaRunner.JavaVersion> javaVersions = Arrays.stream(System.getProperty(JAVA_VERSION_KEY).split(File.pathSeparator)).map(e -> JavaRunner.JavaVersion.fromMajor(Integer.parseInt(e))).toList(); | ||
private static final List<Path> launchers = Arrays.stream(System.getProperty(LAUNCHER_KEY).split(File.pathSeparator)).map(Path::of).toList(); | ||
|
||
public static final Map<JavaRunner.JavaVersion, Path> launchersByVersion = zip(javaVersions.stream(), launchers.stream()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
|
||
static { | ||
flags.api = List.of(javaApi.toFile()); | ||
} | ||
|
||
|
||
private static <T, U> Stream<Map.Entry<T, U>> zip(Stream<T> a, Stream<U> b) { | ||
Iterator<T> aIt = a.iterator(); | ||
Iterator<U> bIt = b.iterator(); | ||
List<Map.Entry<T, U>> out = new ArrayList<>(); | ||
while (aIt.hasNext() && bIt.hasNext()) { | ||
out.add(Map.entry(aIt.next(), bIt.next())); | ||
} | ||
return out.stream(); | ||
} | ||
|
||
private static final Map<FlagsAndRunner, Path> apiPaths = new ConcurrentHashMap<>(); | ||
|
||
public static Path getApiPath(FlagsAndRunner flags) { | ||
String fName = javaApi.getFileName().toString(); | ||
String withoutExt = fName.substring(0, fName.lastIndexOf('.')); | ||
String ext = fName.substring(fName.lastIndexOf('.')); | ||
return Path.of("./build/tmp/test/" + withoutExt + "-downgrade-" + flags.readableSlug() + ext); | ||
} | ||
|
||
public static synchronized Path getApiJar(FlagsAndRunner flags) { | ||
return apiPaths.computeIfAbsent(flags, e -> { | ||
try { | ||
Path target = getApiPath(flags); | ||
ZipDowngrader.downgradeZip( | ||
ClassDowngrader.downgradeTo(flags.flags()), | ||
javaApi, | ||
Set.of(), | ||
target | ||
); | ||
return target; | ||
} catch (IOException ex) { | ||
throw new UncheckedIOException(ex); | ||
} | ||
}); | ||
} | ||
|
||
} |
Oops, something went wrong.