Skip to content

Commit

Permalink
Fixed Exception in DownloadCommand if version not found
Browse files Browse the repository at this point in the history
  • Loading branch information
3arthqu4ke committed Feb 4, 2025
1 parent 5657a4b commit 6246cba
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project_version=2.5.0
project_version=2.5.1
org.gradle.jvmargs=-Xmx2048m
# set to true if you want to run the headlessmc-launcher-wrapper integration tests
hmc_integration_test_enabled=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class HeadlessMcApi {
/**
* The current version of HeadlessMc.
*/
public static final String VERSION = "2.5.0";
public static final String VERSION = "2.5.1";
/**
* The string "HeadlessMC".
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@
public class DownloadCommand extends AbstractLauncherCommand
implements FindByCommand<VersionInfo> {
private final AbstractDownloadingVersionCommand downloadCommand;
private final VersionInfoCache cache = new VersionInfoCache();
private final VersionInfoCache cache;

public DownloadCommand(Launcher ctx) {
this(ctx, new VersionInfoCache());
}

public DownloadCommand(Launcher ctx, VersionInfoCache versionInfoCache) {
super(ctx, "download", "Downloads a version.");
this.cache = versionInfoCache;
this.downloadCommand = new AbstractDownloadingVersionCommand(ctx, "download", "Downloads a version.") {
@Override
public void execute(Version obj, String... args) {
Expand All @@ -36,9 +41,9 @@ public void execute(Version obj, String... args) {
};

args.put("<version/id>", "The name/id of the version to download." +
" If you use the id you also need to use the -id flag.");
" If you use the id you also need to use the -id flag.");
args.put("-id", "If you specified the version via id you" +
" need to add this flag.");
" need to add this flag.");
args.putAll(VersionTypeFilter.getArgs());
}

Expand Down Expand Up @@ -112,7 +117,7 @@ public void execute(String line, String... args) throws CommandException {

@Override
public void onObjectNotFound(boolean byId, boolean byRegex, String objectArg, String... args) throws CommandException {
if (downloadCommand.findObject(byId, byRegex, objectArg, args) == null) {
if (CommandUtil.hasFlag("-norecursivedownload", args) || downloadCommand.findObject(byId, byRegex, objectArg, args) == null) {
FindByCommand.super.onObjectNotFound(byId, byRegex, objectArg, args);
}
}
Expand All @@ -133,7 +138,7 @@ public void getCompletions(String line, List<Map.Entry<String, @Nullable String>

public void download(String version) throws CommandException {
// this is really bad...
execute("download " + version + " -noredownload -norecursivedownload", "download", version, "-noredownload -norecursivedownload");
execute("download " + version + " -noredownload -norecursivedownload", "download", version, "-noredownload", "-norecursivedownload");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.List;

@CustomLog
class VersionInfoCache implements Collection<VersionInfo> {
public class VersionInfoCache implements Collection<VersionInfo> {
private static final List<VersionInfo> EMPTY = new ArrayList<>(0);
private static final URL URL = URLs.url("https://launchermeta.mojang.com/mc/game/version_manifest.json");
@Delegate
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package me.earth.headlessmc.launcher.command.download;

import me.earth.headlessmc.api.command.CommandException;
import me.earth.headlessmc.launcher.Launcher;
import me.earth.headlessmc.launcher.LauncherMock;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertThrows;

public class DownloadCommandTest {
@Test
public void testDownloadCommand() {
Launcher launcher = LauncherMock.INSTANCE;
DummyVersionInfoCache cache = new DummyVersionInfoCache();
DownloadCommand downloadCommand = new DownloadCommand(launcher, cache);
assertThrows(CommandException.class, () -> downloadCommand.download("0"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package me.earth.headlessmc.launcher.command.download;

import java.util.ArrayList;
import java.util.List;

public class DummyVersionInfoCache extends VersionInfoCache {
@Override
public List<VersionInfo> cache(boolean force) {
return new ArrayList<>();
}

}
2 changes: 1 addition & 1 deletion headlessmc-scripts/hmc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env sh
java -jar headlessmc-launcher-wrapper-2.5.0.jar --command $@
java -jar headlessmc-launcher-wrapper-2.5.1.jar --command $@
2 changes: 1 addition & 1 deletion headlessmc-scripts/hmc.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
@echo off
"%JAVA_HOME%\bin\java" -jar headlessmc-launcher-wrapper-2.5.0.jar --command %*
"%JAVA_HOME%\bin\java" -jar headlessmc-launcher-wrapper-2.5.1.jar --command %*
2 changes: 1 addition & 1 deletion headlessmc-scripts/hmw
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
# when running in docker on windows bash seems to be at /bin/bash TODO: can we make this one script?
java -jar headlessmc-launcher-wrapper-2.5.0.jar --command $@
java -jar headlessmc-launcher-wrapper-2.5.1.jar --command $@

0 comments on commit 6246cba

Please sign in to comment.