add loaded project to list of projects
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 17 May 2008 17:48:53 +0000 (17:48 +0000)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 17 May 2008 17:48:53 +0000 (17:48 +0000)
fix property names on project save
don't save when creating (properties are null)

git-svn-id: http://trooper/svn/projects/jSite/trunk@907 c3eda9e8-030b-0410-8277-bc7414b0a119

src/net/pterodactylus/jsite/core/ProjectManager.java

index 786098b..5bb4c75 100644 (file)
@@ -29,8 +29,10 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Properties;
+import java.util.logging.Logger;
 
 import net.pterodactylus.util.io.Closer;
+import net.pterodactylus.util.logging.Logging;
 
 /**
  * Manages projects, taking care of persistence, lifetime statistics, and other
@@ -41,6 +43,9 @@ import net.pterodactylus.util.io.Closer;
  */
 public class ProjectManager {
 
+       /** Logger. */
+       private static final Logger logger = Logging.getLogger(ProjectManager.class.getName());
+
        /** The directory the projects are stored in. */
        private final String directory;
 
@@ -129,6 +134,8 @@ public class ProjectManager {
                        project.setDescription(projectDescription);
                        project.setPrivateKey(projectPrivateKey);
                        project.setPublicKey(projectPublicKey);
+                       projects.add(project);
+                       logger.fine("loaded project “" + project.getName() + "”.");
                        projectIndex++;
                }
        }
@@ -150,10 +157,10 @@ public class ProjectManager {
                int projectIndex = 0;
                for (Project project: projects) {
                        String projectPrefix = "projects." + projectIndex;
-                       projectProperties.setProperty("projects." + projectPrefix + ".name", project.getName());
-                       projectProperties.setProperty("projects." + projectPrefix + ".description", project.getDescription());
-                       projectProperties.setProperty("projects." + projectPrefix + ".privateKey", project.getPrivateKey());
-                       projectProperties.setProperty("projects." + projectPrefix + ".publicKey", project.getPublicKey());
+                       projectProperties.setProperty(projectPrefix + ".name", project.getName());
+                       projectProperties.setProperty(projectPrefix + ".description", project.getDescription());
+                       projectProperties.setProperty(projectPrefix + ".privateKey", project.getPrivateKey());
+                       projectProperties.setProperty(projectPrefix + ".publicKey", project.getPublicKey());
                        projectIndex++;
                }
                File projectFile = new File(directoryFile, "projects.properties");
@@ -182,11 +189,6 @@ public class ProjectManager {
                project.setPrivateKey(keyPair[0]);
                project.setPublicKey(keyPair[1]);
                projects.add(project);
-               try {
-                       save();
-               } catch (IOException ioe1) {
-                       /* ignore, save() will be called again on quit. */
-               }
                return project;
        }
 }