Commits

Sebastian Sdorra committed 818fba1

added url and creationdate to repository

  • Participants
  • Parent commits ef98dd9

Comments (0)

Files changed (3)

File plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryHandler.java

 import java.io.File;
 import java.io.IOException;
 
+import java.text.ParseException;
+
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Date;
 import java.util.List;
 import java.util.UUID;
 import java.util.logging.Level;
           throws RepositoryException, IOException
   {
     repository.setId(UUID.randomUUID().toString());
+    repository.setUrl(buildUrl(repository.getName()));
+    repository.setCreationDate(new Date());
 
     File directory = getDirectory(repository);
 
 
     File hgDirectory = new File(directory, ".hg");
 
-    writeHgrc(repository, hgDirectory);
+    storeRepository(repository, hgDirectory);
   }
 
   /**
 
     if (hgDirectory.exists())
     {
-      writeHgrc(repository, hgDirectory);
+      storeRepository(repository, hgDirectory);
     }
   }
 
 
     if (hgDirectory.exists())
     {
-      readHgrc(repository, hgDirectory);
+      loadRepository(repository, hgDirectory);
     }
   }
 
         repository = new Repository();
         repository.setType(TYPE_NAME);
         repository.setName(directory.getName());
-        readHgrc(repository, hgDirectory);
+        loadRepository(repository, hgDirectory);
 
         if (!id.equals(repository.getId()))
         {
         repository = new Repository();
         repository.setType(TYPE_NAME);
         repository.setName(name);
-        readHgrc(repository, hgDirectory);
+        repository.setUrl(buildUrl(name));
+        loadRepository(repository, hgDirectory);
       }
     }
 
    * Method description
    *
    *
+   * @param name
+   *
+   * @return
+   */
+  private String buildUrl(String name)
+  {
+    String url = config.getBaseUrl();
+
+    if (Util.isNotEmpty(url))
+    {
+      if (!url.endsWith("/"))
+      {
+        url = url.concat("/");
+      }
+
+      url = url.concat(name);
+    }
+
+    return url;
+  }
+
+  /**
+   * Method description
+   *
+   *
    * @param repository
    * @param hgDirectory
    */
-  private void readHgrc(Repository repository, File hgDirectory)
+  private void loadRepository(Repository repository, File hgDirectory)
   {
     File hgrc = new File(hgDirectory, "hgrc");
 
           String id = scmSection.getParameter("id");
 
           repository.setId(id);
+
+          String creationDateString = scmSection.getParameter("creationDate");
+
+          if (Util.isNotEmpty(creationDateString))
+          {
+            try
+            {
+              repository.setCreationDate(Util.parseDate(creationDateString));
+            }
+            catch (ParseException ex)
+            {
+              logger.log(Level.SEVERE, null, ex);
+            }
+          }
         }
       }
       catch (IOException ex)
    *
    * @throws IOException
    */
-  private void writeHgrc(Repository repository, File hgDirectory)
+  private void storeRepository(Repository repository, File hgDirectory)
           throws IOException
   {
     INISection section = new INISection("web");
 
     scmSection.setParameter("id", repository.getId());
 
+    Date creationDate = repository.getCreationDate();
+
+    if (creationDate != null)
+    {
+      scmSection.setParameter("creationDate", Util.formatDate(creationDate));
+    }
+
     INIConfiguration iniConfig = new INIConfiguration();
 
     iniConfig.addSection(section);

File scm-core/src/main/java/sonia/scm/repository/Repository.java

 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Date;
 import java.util.List;
 
 import javax.xml.bind.annotation.XmlRootElement;
 @XmlRootElement(name = "repositories")
 @XmlType(propOrder =
 {
-  "id", "type", "name", "contact", "description", "permissions"
+  "id", "type", "name", "contact", "description", "creationDate", "url",
+  "permissions"
 })
 public class Repository implements Serializable
 {
    *
    * @return
    */
+  public Date getCreationDate()
+  {
+    return creationDate;
+  }
+
+  /**
+   * Method description
+   *
+   *
+   * @return
+   */
   public String getDescription()
   {
     return description;
     return type;
   }
 
+  /**
+   * Method description
+   *
+   *
+   * @return
+   */
+  public String getUrl()
+  {
+    return url;
+  }
+
   //~--- set methods ----------------------------------------------------------
 
   /**
    * Method description
    *
    *
+   * @param creationDate
+   */
+  public void setCreationDate(Date creationDate)
+  {
+    this.creationDate = creationDate;
+  }
+
+  /**
+   * Method description
+   *
+   *
    * @param description
    */
   public void setDescription(String description)
     this.type = type;
   }
 
+  /**
+   * Method description
+   *
+   *
+   * @param url
+   */
+  public void setUrl(String url)
+  {
+    this.url = url;
+  }
+
   //~--- fields ---------------------------------------------------------------
 
   /** Field description */
   private String contact;
 
   /** Field description */
+  private Date creationDate;
+
+  /** Field description */
   private String description;
 
   /** Field description */
 
   /** Field description */
   private String type;
+
+  /** Field description */
+  private String url;
 }

File scm-core/src/main/java/sonia/scm/util/Util.java

 import java.io.InputStream;
 import java.io.OutputStream;
 
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+
 import java.util.Collection;
+import java.util.Date;
+import java.util.TimeZone;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
 {
 
   /** Field description */
+  public static final String DATE_PATTERN = "yyyy-MM-dd HH-mm-ss";
+
+  /** Field description */
   private static final Logger logger = Logger.getLogger(Util.class.getName());
 
   //~--- methods --------------------------------------------------------------
     }
   }
 
+  /**
+   * Method description
+   *
+   *
+   * @param date
+   * @param tz
+   *
+   * @return
+   */
+  public static String formatDate(Date date, TimeZone tz)
+  {
+    SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN);
+
+    if (tz != null)
+    {
+      sdf.setTimeZone(tz);
+    }
+
+    return sdf.format(date);
+  }
+
+  /**
+   * Method description
+   *
+   *
+   * @param date
+   *
+   * @return
+   */
+  public static String formatDate(Date date)
+  {
+    return formatDate(date, null);
+  }
+
+  /**
+   * Method description
+   *
+   *
+   * @param dateString
+   * @param tz
+   *
+   * @return
+   *
+   * @throws ParseException
+   */
+  public static Date parseDate(String dateString, TimeZone tz)
+          throws ParseException
+  {
+    SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN);
+
+    if (tz != null)
+    {
+      sdf.setTimeZone(tz);
+    }
+
+    return sdf.parse(dateString);
+  }
+
+  /**
+   * Method description
+   *
+   *
+   * @param dateString
+   *
+   * @return
+   *
+   * @throws ParseException
+   */
+  public static Date parseDate(String dateString) throws ParseException
+  {
+    return parseDate(dateString, null);
+  }
+
   //~--- get methods ----------------------------------------------------------
 
   /**