-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
c49a82f
commit 7cc384d
Showing
7 changed files
with
241 additions
and
9 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 |
---|---|---|
@@ -1,13 +1,19 @@ | ||
package legacytest; | ||
|
||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import net.minecraft.DetectedVersion; | ||
import net.minecraft.client.main.Main; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.Items; | ||
|
||
public class LegacyTest { | ||
public static void main(String[] args) { | ||
System.out.println(DetectedVersion.tryDetectVersion()); | ||
Main.main(new String[]{ | ||
|
||
}); | ||
|
||
System.out.println(new ItemStack(Items.ACACIA_LEAVES).getCount()); | ||
RenderSystem.disableBlend(); | ||
} | ||
} |
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
122 changes: 122 additions & 0 deletions
122
src/legacy/java/net/neoforged/moddevgradle/legacy/RemapJarTask.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,122 @@ | ||
package net.neoforged.moddevgradle.legacy; | ||
|
||
import net.neoforged.moddevgradle.internal.utils.NetworkSettingPassthrough; | ||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.file.ConfigurableFileCollection; | ||
import org.gradle.api.file.DirectoryProperty; | ||
import org.gradle.api.file.RegularFileProperty; | ||
import org.gradle.api.plugins.JavaPluginExtension; | ||
import org.gradle.api.provider.Property; | ||
import org.gradle.api.tasks.Classpath; | ||
import org.gradle.api.tasks.Input; | ||
import org.gradle.api.tasks.InputFile; | ||
import org.gradle.api.tasks.InputFiles; | ||
import org.gradle.api.tasks.Internal; | ||
import org.gradle.api.tasks.Optional; | ||
import org.gradle.api.tasks.OutputFile; | ||
import org.gradle.api.tasks.TaskAction; | ||
import org.gradle.jvm.toolchain.JavaToolchainService; | ||
import org.gradle.process.ExecOperations; | ||
|
||
import javax.inject.Inject; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.nio.file.Files; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
/** | ||
* Task used to remap a jar using AutoRenamingTool. | ||
*/ | ||
public abstract class RemapJarTask extends DefaultTask { | ||
|
||
@Inject | ||
public RemapJarTask() { | ||
final JavaPluginExtension extension = getProject().getExtensions().findByType(JavaPluginExtension.class); | ||
if (extension != null) { | ||
getJavaExecutable().convention(getToolchainService().launcherFor(extension.getToolchain()) | ||
.map(launcher -> launcher.getExecutablePath().getAsFile().getAbsolutePath())); | ||
} | ||
|
||
getOutput().convention(getProject().provider(() -> { | ||
var path = getArchiveBaseName().get() + getArchiveVersion().map(v -> "-" + v).getOrElse("") + getArchiveClassifier().map(c -> "-" + c).getOrElse("") + ".jar"; | ||
return getDestinationDirectory().file(path); | ||
}).flatMap(regularFileProvider -> regularFileProvider)); | ||
} | ||
|
||
@Input | ||
public abstract Property<String> getJavaExecutable(); | ||
|
||
@Inject | ||
protected abstract ExecOperations getExecOperations(); | ||
|
||
@Inject | ||
protected abstract JavaToolchainService getToolchainService(); | ||
|
||
@Classpath | ||
@InputFiles | ||
protected abstract ConfigurableFileCollection getToolClasspath(); | ||
|
||
@InputFile | ||
public abstract RegularFileProperty getMappings(); | ||
|
||
/** | ||
* The libraries to use for inheritance data during the renaming process. | ||
*/ | ||
@Optional | ||
@InputFiles | ||
public abstract ConfigurableFileCollection getLibraries(); | ||
|
||
@InputFile | ||
public abstract RegularFileProperty getInput(); | ||
|
||
@Internal | ||
public abstract Property<String> getArchiveBaseName(); | ||
|
||
@Internal | ||
public abstract Property<String> getArchiveVersion(); | ||
|
||
@Internal | ||
public abstract Property<String> getArchiveClassifier(); | ||
|
||
@Internal | ||
public abstract DirectoryProperty getDestinationDirectory(); | ||
|
||
@OutputFile | ||
public abstract RegularFileProperty getOutput(); | ||
|
||
@Internal | ||
public abstract RegularFileProperty getLogFile(); | ||
|
||
@TaskAction | ||
public void remap() throws IOException { | ||
final List<String> args = new ArrayList<>(); | ||
|
||
args.addAll(Arrays.asList("--input", getInput().get().getAsFile().getAbsolutePath())); | ||
args.addAll(Arrays.asList("--output", getOutput().get().getAsFile().getAbsolutePath())); | ||
args.addAll(Arrays.asList("--names", getMappings().get().getAsFile().getAbsolutePath())); | ||
getLibraries().forEach(lib -> args.addAll(Arrays.asList("--lib", lib.getAbsolutePath()))); | ||
args.add("--disable-abstract-param"); | ||
|
||
try (var log = getLogFile().isPresent() ? Files.newOutputStream(getLogFile().get().getAsFile().toPath()) : new OutputStream() { | ||
@Override | ||
public void write(int b) { | ||
|
||
} | ||
}) { | ||
getExecOperations().javaexec(execSpec -> { | ||
// Pass through network properties | ||
execSpec.systemProperties(NetworkSettingPassthrough.getNetworkSystemProperties()); | ||
|
||
// See https://github.com/gradle/gradle/issues/28959 | ||
execSpec.jvmArgs("-Dstdout.encoding=UTF-8", "-Dstderr.encoding=UTF-8"); | ||
|
||
execSpec.executable(getJavaExecutable().get()); | ||
execSpec.classpath(getToolClasspath()); | ||
execSpec.args(args); | ||
execSpec.setStandardOutput(log); | ||
}).rethrowFailure().assertNormalExitValue(); | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/legacy/java/net/neoforged/moddevgradle/legacy/Reobfuscation.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,56 @@ | ||
package net.neoforged.moddevgradle.legacy; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.gradle.api.Action; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.artifacts.Configuration; | ||
import org.gradle.api.component.AdhocComponentWithVariants; | ||
import org.gradle.api.file.RegularFile; | ||
import org.gradle.api.plugins.JavaPlugin; | ||
import org.gradle.api.provider.Provider; | ||
import org.gradle.api.tasks.SourceSet; | ||
import org.gradle.api.tasks.TaskProvider; | ||
import org.gradle.api.tasks.bundling.AbstractArchiveTask; | ||
|
||
import javax.inject.Inject; | ||
import java.util.List; | ||
|
||
public abstract class Reobfuscation { | ||
private final Project project; | ||
private final Provider<RegularFile> officialToSrg; | ||
private final Configuration autoRenamingToolRuntime; | ||
|
||
@Inject | ||
public Reobfuscation(Project project, Provider<RegularFile> officialToSrg, Configuration autoRenamingToolRuntime) { | ||
this.project = project; | ||
this.officialToSrg = officialToSrg; | ||
this.autoRenamingToolRuntime = autoRenamingToolRuntime; | ||
} | ||
|
||
public TaskProvider<RemapJarTask> reobfuscate(TaskProvider<? extends AbstractArchiveTask> jar, SourceSet sourceSet, Action<RemapJarTask> configuration) { | ||
var reobf = project.getTasks().register("reobf" + StringUtils.capitalize(jar.getName()), RemapJarTask.class, task -> { | ||
task.getInput().set(jar.flatMap(AbstractArchiveTask::getArchiveFile)); | ||
task.getMappings().set(officialToSrg); | ||
task.getDestinationDirectory().convention(jar.flatMap(AbstractArchiveTask::getDestinationDirectory)); | ||
task.getArchiveBaseName().convention(jar.flatMap(AbstractArchiveTask::getArchiveBaseName)); | ||
task.getArchiveVersion().convention(jar.flatMap(AbstractArchiveTask::getArchiveVersion)); | ||
task.getArchiveClassifier().convention(jar.flatMap(AbstractArchiveTask::getArchiveClassifier).map(c -> c + "-reobf")); | ||
task.getLibraries().from(sourceSet.getCompileClasspath()); | ||
task.getToolClasspath().from(autoRenamingToolRuntime); | ||
configuration.execute(task); | ||
}); | ||
|
||
jar.configure(jarTask -> jarTask.finalizedBy(reobf)); | ||
|
||
var java = (AdhocComponentWithVariants) project.getComponents().getByName("java"); | ||
for (var configurationNames : List.of(JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME, JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME)) { | ||
project.getArtifacts().add(configurationNames, reobf, artifact -> artifact.builtBy(reobf)); | ||
|
||
java.withVariantsFromConfiguration(project.getConfigurations().getByName(configurationNames), variant -> { | ||
variant.getConfigurationVariant().getArtifacts().removeIf(artifact -> artifact.getFile().equals(jar.get().getArchiveFile().get().getAsFile())); | ||
}); | ||
} | ||
|
||
return reobf; | ||
} | ||
} |