11package org .mangorage .installer ;
22
33import com .google .gson .Gson ;
4- import com .google .gson .stream . JsonReader ;
4+ import com .google .gson .GsonBuilder ;
55import joptsimple .OptionParser ;
66import joptsimple .OptionSpec ;
77import joptsimple .util .PathConverter ;
6868 *
6969 */
7070public 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 <>();
0 commit comments