-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework how the Java and Gradle version trampolines work since Kotlin …
…build-scripts have trouble with multi-release jars (#4)
- Loading branch information
Showing
37 changed files
with
122 additions
and
119 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
26 changes: 0 additions & 26 deletions
26
src/java17/java/net/neoforged/moddevgradle/JUnitPlugin.java
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
src/java17/java/net/neoforged/moddevgradle/ModDevPlugin.java
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
src/java17/java/net/neoforged/moddevgradle/internal/JUnitPluginImpl.java
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
src/java8/java/net/neoforged/moddevgradle/boot/JUnitPlugin.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,13 @@ | ||
package net.neoforged.moddevgradle.boot; | ||
|
||
import org.gradle.api.Plugin; | ||
import org.gradle.api.Project; | ||
|
||
/** | ||
* This is just a trampoline to perform the Java and Gradle version check, and is compiled for Java 8 in the real Jar. | ||
*/ | ||
public class JUnitPlugin extends TrampolinePlugin<Project> { | ||
public JUnitPlugin() { | ||
super("net.neoforged.moddevgradle.internal.JUnitPlugin"); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/java8/java/net/neoforged/moddevgradle/boot/ModDevPlugin.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 net.neoforged.moddevgradle.boot; | ||
|
||
import org.gradle.api.Project; | ||
|
||
public class ModDevPlugin extends TrampolinePlugin<Project> { | ||
public ModDevPlugin() { | ||
super("net.neoforged.moddevgradle.internal.ModDevPlugin"); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/java8/java/net/neoforged/moddevgradle/boot/TrampolinePlugin.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,65 @@ | ||
package net.neoforged.moddevgradle.boot; | ||
|
||
import org.gradle.api.GradleException; | ||
import org.gradle.api.Plugin; | ||
import org.gradle.api.plugins.PluginAware; | ||
import org.gradle.util.GradleVersion; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* This is just a trampoline to perform the Java and Gradle version check, and is compiled for Java 8 in the real Jar. | ||
*/ | ||
public abstract class TrampolinePlugin<T extends PluginAware> implements Plugin<T> { | ||
private static final int MIN_JAVA_VERSION = 17; | ||
private static final GradleVersion MIN_GRADLE_VERSION = GradleVersion.version("8.7"); | ||
|
||
private final String pluginClassName; | ||
|
||
TrampolinePlugin(String pluginClassName) { | ||
this.pluginClassName = pluginClassName; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public final void apply(T target) { | ||
int javaMajorVersion = getJavaMajorVersion(); | ||
|
||
if (javaMajorVersion < MIN_JAVA_VERSION) { | ||
throw new GradleException("To use the NeoForge plugin, please run Gradle with Java " + MIN_JAVA_VERSION + " or newer. You are currently running on Java " + javaMajorVersion + " (" + System.getProperty("java.specification.version") + ")."); | ||
} | ||
|
||
if (GradleVersion.current().compareTo(MIN_GRADLE_VERSION) < 0) { | ||
throw new GradleException("To use the NeoForge plugin, please use at least " + MIN_GRADLE_VERSION | ||
+ ". You are currently using " + GradleVersion.current() + "."); | ||
} | ||
|
||
try { | ||
Class<? extends Plugin<?>> pluginClass = (Class<? extends Plugin<?>>) Class.forName(pluginClassName); | ||
target.getPlugins().apply(pluginClass); | ||
} catch (ClassNotFoundException e) { | ||
throw new GradleException("Failed to find main plugin class.", e); | ||
} | ||
} | ||
|
||
private int getJavaMajorVersion() { | ||
String specVersion = System.getProperty("java.specification.version"); | ||
if (specVersion == null) { | ||
return 0; | ||
} | ||
|
||
Pattern firstNumber = Pattern.compile("^(\\d+)\\D*"); | ||
Matcher matcher = firstNumber.matcher(specVersion); | ||
if (!matcher.find()) { | ||
return 0; | ||
} | ||
|
||
return Integer.parseInt(matcher.group(1)); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Trampoline for " + pluginClassName; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
src/main/java/net/neoforged/moddevgradle/ModDevPlugin.java
This file was deleted.
Oops, something went wrong.
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.
10 changes: 10 additions & 0 deletions
10
src/main/java/net/neoforged/moddevgradle/internal/JUnitPlugin.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,10 @@ | ||
package net.neoforged.moddevgradle.internal; | ||
|
||
import org.gradle.api.Plugin; | ||
import org.gradle.api.Project; | ||
|
||
public class JUnitPlugin implements Plugin<Project> { | ||
public void apply(Project project) { | ||
|
||
} | ||
} |
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
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.
4 changes: 4 additions & 0 deletions
4
src/main/resources/META-INF/trick-gradle-into-thinking-loom-is-signed.SF
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,4 @@ | ||
Trick gradle into thinking that loom is signed to skip over transforming all classes in the jar. | ||
This is required to get the bootstrap to well bootstrap on older gradle versions that dont support java 16. | ||
|
||
See https://github.com/gradle/gradle/blob/master/subprojects/core/src/main/java/org/gradle/internal/classpath/InstrumentingClasspathFileTransformer.java#L129 |