Skip to content

Commit b7cea22

Browse files
committed
Prepped for next update :>
1 parent 341c047 commit b7cea22

File tree

3 files changed

+35
-19
lines changed

3 files changed

+35
-19
lines changed

src/main/java/org/mangorage/installer/Installer.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.mangorage.installer;
22

33
import com.google.gson.Gson;
4-
import com.google.gson.stream.JsonReader;
4+
import com.google.gson.GsonBuilder;
55
import joptsimple.OptionParser;
66
import joptsimple.OptionSpec;
77
import joptsimple.util.PathConverter;
@@ -68,7 +68,7 @@
6868
*
6969
*/
7070
public class Installer {
71-
private static final Gson GSON = new Gson();
71+
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
7272
private static final ExecutorService TASKS = Executors.newSingleThreadExecutor();
7373
private static final String DEPS_PATH = "installer-data/dependencies.json";
7474
public static final String SERVICE_PATH = "installer-data/services.launch";
@@ -101,7 +101,7 @@ public static void main(String[] args) {
101101
}
102102

103103
if (jars.isEmpty()) {
104-
throw new IllegalStateException("packages.txt was blank!");
104+
throw new IllegalStateException("packages.json was blank!");
105105
}
106106

107107
var dependencies = processJars(jars);
@@ -123,12 +123,12 @@ public static List<File> processPackages() {
123123
File installed = new File("installer/installed.json");
124124
if (installed.exists()) {
125125
// Handle
126-
try (var is = new FileReader(file)) {
127-
var list = GSON.fromJson(is, Installed.class).installed();
128-
list.forEach(installedPackage -> {
126+
System.out.println(installed.toPath().toAbsolutePath());
127+
try (var is = new FileReader(installed)) {
128+
var list = GSON.fromJson(is, Installed.class);
129+
list.installed().forEach(installedPackage -> {
129130
versions.put(installedPackage.id(), installedPackage.version());
130131
});
131-
installed.delete();
132132
} catch (IOException e) {
133133
throw new RuntimeException(e);
134134
}
@@ -180,14 +180,19 @@ public static List<File> processPackages() {
180180
}
181181
});
182182

183+
ArrayList<InstalledPackage> installedList = new ArrayList<>(
184+
newVersions
185+
.entrySet()
186+
.stream()
187+
.map(entry -> new InstalledPackage(entry.getKey(), entry.getValue()))
188+
.toList()
189+
);
190+
191+
183192
try (var fileIS = new FileWriter(installed)) {
184-
newVersions.forEach((name, version) -> {
185-
try {
186-
fileIS.append("%s=%s".formatted(name, version)).append("\n");
187-
} catch (IOException e) {
188-
throw new RuntimeException(e);
189-
}
190-
});
193+
fileIS.write(
194+
GSON.toJson(new Installed(installedList))
195+
);
191196
} catch (IOException e) {
192197
throw new IllegalStateException(e);
193198
}
@@ -226,7 +231,7 @@ public static void processDependencies(List<Dependency> dependencies) {
226231
// TODO: Remove Unused Jars
227232

228233
System.out.println("Processing dependencies for jars");
229-
var libs = Path.of("libs/").toAbsolutePath();
234+
var libs = Path.of("libraries/").toAbsolutePath();
230235

231236
ArrayList<File> currentJarsFiles = new ArrayList<>();
232237
ArrayList<String> currentJars = new ArrayList<>();
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
package org.mangorage.installer;
22

3+
import com.google.gson.Gson;
4+
import com.google.gson.GsonBuilder;
5+
import org.mangorage.installer.core.types.Installed;
6+
7+
import java.io.File;
8+
import java.io.FileNotFoundException;
9+
import java.io.FileReader;
10+
311
public class Test {
4-
public static void main(String[] args) {
5-
Installer.main(new String[]{
6-
"-launch"
7-
});
12+
public static void main(String[] args) throws FileNotFoundException {
13+
File file = new File("new/installed.json");
14+
Gson gson = new GsonBuilder().setPrettyPrinting().create();
15+
16+
var a = gson.fromJson(new FileReader(file), Installed.class);
17+
System.out.println(a);
818
}
919
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.mangorage.installer.core.types;
22

3+
import java.util.ArrayList;
34
import java.util.List;
45

56
public record Installed(List<InstalledPackage> installed) { }

0 commit comments

Comments
 (0)