Skip to content

Commit

Permalink
Allow local NeoForm files to be used (#49)
Browse files Browse the repository at this point in the history
Adds a `--neoform-file=<path>` option to pass NFRT a local NeoForm
archive instead of a GAV. Very useful for local testing with custom
NeoForm archives.
  • Loading branch information
shartte authored Dec 14, 2024
1 parent b60cbd6 commit 3e6c450
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ This produces the Vanilla artifacts in build/
| `--dist` [required] | Which distribution type to generate artifacts for. NeoForm defines these and usually `client`, `server` and `joined` are available. |
| `--neoforge=<gav>` | Pass the NeoForge artifact to use as `net.neoforged:neoforge:<version>`. When passing this, the NeoForm version is implied. It can still be overridden by passing `--neoform` as well. |
| `--neoform=<gav>` | Pass the NeoForm artifact to use as `net.neoforged:neoform:<version>@zip`. |
| `--neoform-file=<path>` | As an alternative to `--neoform` you can also pass a path to the NeoForm data archive directly. |
| `--write-result=<id>:<path>` | This option can be passed multiple times. It tells NFRT to write a result of the execution graph to the given path, such as the recompiled Minecraft jar-file, or the sources. If you pass no such option, NFRT will print which results are available. |
| `--access-transformer=<path>` | Adds access transformers which will be applied to the source before recompiling it. |
| `--interface-injection-data=<path>` | Adds [interface injection data](https://github.com/neoforged/JavaSourceTransformer?tab=readme-ov-file#interface-injection) which will be applied to the source before recompiling it. |
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/neoforged/neoform/runtime/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import static picocli.CommandLine.Option;
import static picocli.CommandLine.ScopeType;

@Command(name = "neoform-runtime", subcommands = {RunNeoFormCommand.class, DownloadAssetsCommand.class, CleanCacheCommand.class, CacheMaintenance.class}, mixinStandardHelpOptions = true)
@Command(name = "neoform-runtime", subcommands = {CommandLine.HelpCommand.class, RunNeoFormCommand.class, DownloadAssetsCommand.class, CleanCacheCommand.class, CacheMaintenance.class}, mixinStandardHelpOptions = true)
public class Main {
@Option(names = "--home-dir", scope = ScopeType.INHERIT, description = "Where NFRT should store caches.")
Path homeDir = getDefaultHomeDir();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,19 @@ public class RunNeoFormCommand extends NeoFormEngineCommand {
String parchmentConflictPrefix;

static class SourceArtifacts {
@CommandLine.Option(names = "--neoform")
String neoform;
@CommandLine.ArgGroup(multiplicity = "1")
NeoFormArtifact neoform;
@CommandLine.Option(names = "--neoforge")
String neoforge;
}

static class NeoFormArtifact {
@CommandLine.Option(names = "--neoform")
String artifact;
@CommandLine.Option(names = "--neoform-file")
Path file;
}

@Override
protected void runWithNeoFormEngine(NeoFormEngine engine, List<AutoCloseable> closables) throws IOException, InterruptedException {
var artifactManager = engine.getArtifactManager();
Expand All @@ -83,11 +90,17 @@ protected void runWithNeoFormEngine(NeoFormEngine engine, List<AutoCloseable> cl
var neoforgeArtifact = artifactManager.get(sourceArtifacts.neoforge);
var neoforgeZipFile = engine.addManagedResource(new JarFile(neoforgeArtifact.path().toFile()));
var neoforgeConfig = NeoForgeConfig.from(neoforgeZipFile);
var neoformArtifact = MavenCoordinate.parse(neoforgeConfig.neoformArtifact());
// Allow it to be overridden
if (sourceArtifacts.neoform != null) {
LOG.println("Overriding NeoForm version " + neoformArtifact + " with CLI argument " + sourceArtifacts.neoform);
neoformArtifact = MavenCoordinate.parse(sourceArtifacts.neoform);

// Allow it to be overridden with local or remote data
Path neoformArtifact;
if (sourceArtifacts.neoform.file != null) {
LOG.println("Overriding NeoForm version " + neoforgeConfig.neoformArtifact() + " with NeoForm file " + sourceArtifacts.neoform.file);
neoformArtifact = sourceArtifacts.neoform.file;
} else if (sourceArtifacts.neoform.artifact != null) {
LOG.println("Overriding NeoForm version " + neoforgeConfig.neoformArtifact() + " with CLI argument " + sourceArtifacts.neoform.artifact);
neoformArtifact = artifactManager.get(MavenCoordinate.parse(sourceArtifacts.neoform.artifact)).path();
} else {
neoformArtifact = artifactManager.get(MavenCoordinate.parse(neoforgeConfig.neoformArtifact())).path();
}

engine.loadNeoFormData(neoformArtifact, dist);
Expand Down Expand Up @@ -168,7 +181,14 @@ protected void runWithNeoFormEngine(NeoFormEngine engine, List<AutoCloseable> cl

createSourcesAndCompiledWithNeoForge(engine.getGraph(), compiledWithNeoForgeOutput, sourcesWithNeoForgeOutput);
} else {
engine.loadNeoFormData(MavenCoordinate.parse(sourceArtifacts.neoform), dist);
Path neoFormDataPath;
if (sourceArtifacts.neoform.file != null) {
neoFormDataPath = sourceArtifacts.neoform.file;
} else {
neoFormDataPath = artifactManager.get(MavenCoordinate.parse(sourceArtifacts.neoform.artifact)).path();
}

engine.loadNeoFormData(neoFormDataPath, dist);
}

if (!additionalAccessTransformers.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,8 @@ public void addDataSource(String id, ZipFile zipFile, String sourceFolder) {
dataSources.put(id, new DataSource(zipFile, sourceFolder));
}

public void loadNeoFormData(MavenCoordinate neoFormArtifactId, String dist) throws IOException {
var neoFormArchive = artifactManager.get(Objects.requireNonNull(neoFormArtifactId, "neoFormArtifactId"));
var zipFile = new ZipFile(neoFormArchive.path().toFile());
public void loadNeoFormData(Path neoFormDataPath, String dist) throws IOException {
var zipFile = new ZipFile(neoFormDataPath.toFile());
var config = NeoFormConfig.from(zipFile);
var distConfig = config.getDistConfig(dist);

Expand Down

0 comments on commit 3e6c450

Please sign in to comment.