Skip to content

Commit

Permalink
Add support for modpack zips
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRandomLabs committed Feb 14, 2021
1 parent 33ee60f commit deabd42
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 17 deletions.
9 changes: 4 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group = "com.therandomlabs.changeloggenerator"
version = "2.0.0-pre9"
version = "2.0.0-pre10"

ext {
commonGradleBranch = "master"
Expand All @@ -24,12 +24,11 @@ dependencies {
api "com.github.TheRandomLabs:CurseAPI:master-SNAPSHOT"
api "com.github.TheRandomLabs:CurseAPI-Minecraft:master-SNAPSHOT"

implementation "info.picocli:picocli:4.6.1"
annotationProcessor "info.picocli:picocli-codegen:4.6.1"

implementation "org.commonmark:commonmark:0.17.1"
implementation "com.github.TheRandomLabs:TRLUtils-IO:master-SNAPSHOT"

testImplementation "com.github.TheRandomLabs:TRLUtils-IO:master-SNAPSHOT"
implementation "info.picocli:picocli:4.6.1"
annotationProcessor "info.picocli:picocli-codegen:4.6.1"
}

compileJava {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,20 @@ public final class ChangelogGeneratorOptions implements Callable<Integer> {
boolean markdown;

@CommandLine.Option(
names = {"-o", "--old-manifest"},
description = "The old modpack manifest. \"old.json\" by default."
names = {"-o", "--old"},
description = "The old modpack or modpack manifest. " +
"\"old.json\" or \"old.zip\" by default."
)
@Nullable
Path oldManifest;
Path oldModpack;

@CommandLine.Option(
names = {"-n", "--new-manifest"},
description = "The new modpack manifest. \"new.json\" by default."
names = {"-n", "--new"},
description = "The new modpack or modpack manifest. " +
"\"new.json\" or \"new.zip\" by default."
)
@Nullable
Path newManifest;
Path newModpack;

@CommandLine.Option(
names = {"-O", "--output"},
Expand Down
50 changes: 44 additions & 6 deletions src/main/java/com/therandomlabs/changeloggenerator/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@

package com.therandomlabs.changeloggenerator;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import com.therandomlabs.curseapi.minecraft.modpack.CurseModpack;
import com.therandomlabs.utils.io.ZipFile;
import okio.BufferedSink;
import okio.Okio;
import org.checkerframework.checker.nullness.qual.Nullable;
Expand Down Expand Up @@ -55,6 +58,7 @@ public static void main(String[] args) {
System.exit(commandLine.execute(args));
}

@SuppressWarnings({"ConstantConditions", "NullAway"})
private static Integer run() throws Exception {
if (options == null) {
throw new IllegalStateException("options should not be null");
Expand All @@ -74,20 +78,54 @@ private static Integer run() throws Exception {
return 1;
}

if (options.oldManifest == null) {
options.oldManifest = Paths.get("old.json");
if (options.oldModpack == null) {
options.oldModpack = Paths.get("old.json");

if (!Files.exists(options.oldModpack)) {
final Path zip = Paths.get("old.zip");

if (Files.exists(zip)) {
options.oldModpack = zip;
}
}
}

if (options.oldModpack.getFileName().toString().endsWith(".zip")) {
try {
options.oldModpack = new ZipFile(options.oldModpack).getEntry("manifest.json");
} catch (IOException ex) {
System.err.println("Invalid zip file: " + options.oldModpack);
return 1;
}
}

if (options.newModpack == null) {
options.newModpack = Paths.get("new.json");

if (!Files.exists(options.newModpack)) {
final Path zip = Paths.get("new.zip");

if (Files.exists(zip)) {
options.newModpack = zip;
}
}
}

if (options.newManifest == null) {
options.newManifest = Paths.get("new.json");
if (options.newModpack.getFileName().toString().endsWith(".zip")) {
try {
options.newModpack = new ZipFile(options.newModpack).getEntry("manifest.json");
} catch (IOException ex) {
System.err.println("Invalid zip file: " + options.newModpack);
return 1;
}
}

if (options.output == null) {
options.output = Paths.get(options.markdown ? "changelog.md" : "changelog.txt");
}

final CurseModpack oldModpack = CurseModpack.fromJSON(options.oldManifest);
final CurseModpack newModpack = CurseModpack.fromJSON(options.newManifest);
final CurseModpack oldModpack = CurseModpack.fromJSON(options.oldModpack);
final CurseModpack newModpack = CurseModpack.fromJSON(options.newModpack);
final ChangelogGenerator generator = options.markdown ?
new MarkdownChangelogGenerator(options) : new BasicChangelogGenerator(options);
final String changelog = generator.generate(oldModpack, newModpack);
Expand Down

0 comments on commit deabd42

Please sign in to comment.