From ca633f24058ca24758b12d28b0d5d866e5b2ca21 Mon Sep 17 00:00:00 2001 From: Tommy Ettinger Date: Sat, 10 Aug 2024 01:06:52 -0700 Subject: [PATCH] Fix #191 . Groovy 4.0.22 should be the default now, and should download correctly. This also fixes a somewhat-related bug where languages could become mismatched from their versions, and languages could also be added more than once (but versions only once). --- src/main/java/gdx/liftoff/Main.java | 21 +++++++++++-------- src/main/java/gdx/liftoff/ui/UserData.java | 2 +- .../liftoff/ui/dialogs/LanguagesDialog.java | 16 ++++++++++++-- .../gdx/liftoff/data/languages/Groovy.kt | 4 ++-- .../resources/ui-data/defaults.properties | 2 +- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/main/java/gdx/liftoff/Main.java b/src/main/java/gdx/liftoff/Main.java index acad9f4e..a0bb6518 100644 --- a/src/main/java/gdx/liftoff/Main.java +++ b/src/main/java/gdx/liftoff/Main.java @@ -500,11 +500,12 @@ public static void setDefaultUserData() { UserData.mainClassName = pref.getString("MainClass", prop.getProperty("mainClassNameDefault")); UserData.platforms = splitCSV(pref.getString("Platforms", prop.getProperty("platformsDefaultNames"))); - UserData.languages = splitCSV(pref.getString("Languages", prop.getProperty("languagesDefaultNames"))); + UserData.languages = splitCSVSet(pref.getString("Languages", prop.getProperty("languagesDefaultNames"))); ArrayList languageVersions = splitCSV(pref.getString("LanguageVersions", prop.getProperty("languagesDefaultVersions"))); UserData.languageVersions = new LinkedHashMap<>(); - for (int i = 0; i < UserData.languages.size(); i++) { - UserData.languageVersions.put(UserData.languages.get(i), languageVersions.get(i)); + int languageIndex = 0; + for(String language : languages){ + UserData.languageVersions.put(language, languageVersions.get(languageIndex++)); } extensions = splitCSV(pref.getString("Extensions", prop.getProperty("extensionsDefaultNames"))); @@ -531,11 +532,12 @@ public static void resetUserData() { UserData.mainClassName = prop.getProperty("mainClassNameDefault"); UserData.platforms = splitCSV(prop.getProperty("platformsDefaultNames")); - UserData.languages = splitCSV(prop.getProperty("languagesDefaultNames")); + UserData.languages = splitCSVSet(prop.getProperty("languagesDefaultNames")); ArrayList languageVersions = splitCSV(prop.getProperty("languagesDefaultVersions")); UserData.languageVersions = new LinkedHashMap<>(); - for (int i = 0; i < UserData.languages.size(); i++) { - UserData.languageVersions.put(UserData.languages.get(i), languageVersions.get(i)); + int languageIndex = 0; + for(String language : languages){ + UserData.languageVersions.put(language, languageVersions.get(languageIndex++)); } extensions = splitCSV(prop.getProperty("extensionsDefaultNames")); @@ -572,11 +574,12 @@ public static void resetUserData() { public static void setQuickProjectDefaultUserData() { UserData.platforms = splitCSV(prop.getProperty("qp_platformsDefaultNames")); - UserData.languages = splitCSV(prop.getProperty("languagesDefaultNames")); + UserData.languages = splitCSVSet(prop.getProperty("languagesDefaultNames")); ArrayList languageVersions = splitCSV(prop.getProperty("languagesDefaultVersions")); UserData.languageVersions = new LinkedHashMap<>(); - for (int i = 0; i < UserData.languages.size(); i++) { - UserData.languageVersions.put(UserData.languages.get(i), languageVersions.get(i)); + int languageIndex = 0; + for(String language : languages){ + UserData.languageVersions.put(language, languageVersions.get(languageIndex++)); } extensions = splitCSV(prop.getProperty("extensionsDefaultNames")); diff --git a/src/main/java/gdx/liftoff/ui/UserData.java b/src/main/java/gdx/liftoff/ui/UserData.java index b0162211..4e13f252 100644 --- a/src/main/java/gdx/liftoff/ui/UserData.java +++ b/src/main/java/gdx/liftoff/ui/UserData.java @@ -9,7 +9,7 @@ public class UserData { public static String packageName; public static String mainClassName; public static ArrayList platforms; - public static ArrayList languages; + public static LinkedHashSet languages; public static LinkedHashMap languageVersions; public static ArrayList extensions; public static String template; diff --git a/src/main/java/gdx/liftoff/ui/dialogs/LanguagesDialog.java b/src/main/java/gdx/liftoff/ui/dialogs/LanguagesDialog.java index 61d7d89c..77b99ece 100644 --- a/src/main/java/gdx/liftoff/ui/dialogs/LanguagesDialog.java +++ b/src/main/java/gdx/liftoff/ui/dialogs/LanguagesDialog.java @@ -158,7 +158,10 @@ private void addLanguage(Table table, String languageName, String defaultVersion if (checkBox.isChecked()) { UserData.languages.add(languageName); UserData.languageVersions.put(languageName, textField.getText()); - } else UserData.languages.remove(languageName); + } else { + UserData.languages.remove(languageName); + UserData.languageVersions.remove(languageName); + } pref.putString("Languages", String.join(",", UserData.languages)); pref.putString("LanguageVersions", String.join(",", UserData.languageVersions.values())); pref.flush(); @@ -166,7 +169,16 @@ private void addLanguage(Table table, String languageName, String defaultVersion }); onChange(textField, () -> { - UserData.languageVersions.put(languageName, textField.getText()); + if (checkBox.isChecked()) { + UserData.languages.add(languageName); + UserData.languageVersions.put(languageName, textField.getText()); + } else { + UserData.languages.remove(languageName); + UserData.languageVersions.remove(languageName); + } + pref.putString("Languages", String.join(",", UserData.languages)); + pref.putString("LanguageVersions", String.join(",", UserData.languageVersions.values())); + pref.flush(); }); Button button = new Button(skin, "external-link"); diff --git a/src/main/kotlin/gdx/liftoff/data/languages/Groovy.kt b/src/main/kotlin/gdx/liftoff/data/languages/Groovy.kt index ac6b2aac..2e483138 100644 --- a/src/main/kotlin/gdx/liftoff/data/languages/Groovy.kt +++ b/src/main/kotlin/gdx/liftoff/data/languages/Groovy.kt @@ -14,7 +14,7 @@ import gdx.liftoff.views.JvmLanguage @Suppress("unused") // Class accessed via reflection. class Groovy : Language { override val id = "groovy" - override val version = "4.0.2" + override val version = "4.0.22" override fun initiate(project: Project) { project.rootGradle.plugins.add(id) @@ -23,6 +23,6 @@ class Groovy : Language { val gradleFile = project.getGradleFile(Android.ID) as AndroidGradleFile gradleFile.srcFolders.add("'src/main/groovy'") } - addDependency(project, "org.codehaus.groovy:groovy-all:\$groovyVersion") + addDependency(project, "org.apache.groovy:groovy-all:\$groovyVersion") } } diff --git a/src/main/resources/ui-data/defaults.properties b/src/main/resources/ui-data/defaults.properties index def1c148..8b2e5dbe 100644 --- a/src/main/resources/ui-data/defaults.properties +++ b/src/main/resources/ui-data/defaults.properties @@ -9,7 +9,7 @@ languagesDefaultVersions= extensionsDefaultNames= thirdPartyDefaultNames= templateDefaultName=classic -groovyDefaultVersion=4.0.2 +groovyDefaultVersion=4.0.22 kotlinDefaultVersion=1.9.22 scalaDefaultVersion=2.13.8 libgdxDefaultVersion=1.12.1