diff --git a/faf-commons-data/src/main/java/com/faforever/commons/mod/Mod.java b/faf-commons-data/src/main/java/com/faforever/commons/mod/Mod.java index e78a18eb..54f2df67 100644 --- a/faf-commons-data/src/main/java/com/faforever/commons/mod/Mod.java +++ b/faf-commons-data/src/main/java/com/faforever/commons/mod/Mod.java @@ -16,8 +16,15 @@ public class Mod { private String icon; private String description; private String author; + + /** Used to reference the forums or Github-like URLs */ + private String url; private boolean selectable; private boolean uiOnly; + + /** Used by featured mods */ private final List mountInfos = new ArrayList<>(); + + /** Used by featured mods */ private final List hookDirectories = new ArrayList<>(); } diff --git a/faf-commons-data/src/main/java/com/faforever/commons/mod/ModReader.java b/faf-commons-data/src/main/java/com/faforever/commons/mod/ModReader.java index 05811c44..704e08c3 100644 --- a/faf-commons-data/src/main/java/com/faforever/commons/mod/ModReader.java +++ b/faf-commons-data/src/main/java/com/faforever/commons/mod/ModReader.java @@ -78,6 +78,12 @@ public Mod readModInfo(InputStream inputStream, Path mountBaseDir) { mod.setUiOnly(luaValue.get("ui_only").toboolean()); mod.setIcon(extractIconPath(luaValue)); + // not all mods have and/or need this value + String url = luaValue.get("url").toString(); + if (!("nil".equals(url) || Strings.isNullOrEmpty(url))) { + mod.setUrl(url); + } + ArrayList mountInfos = new ArrayList<>(); LuaTable mountpoints = luaValue.get("mountpoints").opttable(LuaValue.tableOf()); for (LuaValue key : mountpoints.keys()) { diff --git a/faf-commons-data/src/test/java/com/faforever/commons/mod/ModReaderTest.java b/faf-commons-data/src/test/java/com/faforever/commons/mod/ModReaderTest.java index eeae985d..60c73ff9 100644 --- a/faf-commons-data/src/test/java/com/faforever/commons/mod/ModReaderTest.java +++ b/faf-commons-data/src/test/java/com/faforever/commons/mod/ModReaderTest.java @@ -8,13 +8,13 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Objects; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.startsWith; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.*; class ModReaderTest { @@ -28,6 +28,18 @@ public void setUp() { instance = new ModReader(); } + @Test + public void testModReadInfo() throws IOException { + Path modPath = temporaryFolder.resolve("mod-with-url"); + Path modInfoPath = temporaryFolder.resolve("mod-with-url/mod_info.lua"); + Files.createDirectory(modPath); + Files.copy(Objects.requireNonNull(getClass().getResourceAsStream("/mod/mod-with-url.lua")), modInfoPath); + + Mod mod = instance.readDirectory(modPath); + + assertEquals("https://github.com/JeroenDeDauw/NoAirCrashDamage", mod.getUrl()); + } + @Test public void testRegularMod() throws Exception { assertEquals("good", instance.readZip(prepareRegularMod()).getName()); diff --git a/faf-commons-data/src/test/resources/mod/mod-with-url.lua b/faf-commons-data/src/test/resources/mod/mod-with-url.lua new file mode 100644 index 00000000..953efaaa --- /dev/null +++ b/faf-commons-data/src/test/resources/mod/mod-with-url.lua @@ -0,0 +1,11 @@ +name = "50% Air Crash Damage" +uid = "daeafcc2-0bcc-463a-962e-a33e703eacd1" +version = 1 +copyright = "EntropyWins" +description = "Reduces Air Crash damage to 50% of normal. Other versions reduce/increase to 150%, 75%, or 25%. Original mod 'No Air Crash Damage' by EntropyWins, modified by Rama." +author = "EntropyWins + Rama" +selectable = true +ui_only = false +enabled = true +url = "https://github.com/JeroenDeDauw/NoAirCrashDamage" +icon = "/mods/AirCrashDamage50/icon.jpg"