mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-15 09:46:16 +01:00
added url and creationdate to repository
This commit is contained in:
@@ -24,8 +24,11 @@ import sonia.scm.util.Util;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@@ -87,6 +90,8 @@ public class HgRepositoryHandler implements RepositoryHandler
|
|||||||
throws RepositoryException, IOException
|
throws RepositoryException, IOException
|
||||||
{
|
{
|
||||||
repository.setId(UUID.randomUUID().toString());
|
repository.setId(UUID.randomUUID().toString());
|
||||||
|
repository.setUrl(buildUrl(repository.getName()));
|
||||||
|
repository.setCreationDate(new Date());
|
||||||
|
|
||||||
File directory = getDirectory(repository);
|
File directory = getDirectory(repository);
|
||||||
|
|
||||||
@@ -113,7 +118,7 @@ public class HgRepositoryHandler implements RepositoryHandler
|
|||||||
|
|
||||||
File hgDirectory = new File(directory, ".hg");
|
File hgDirectory = new File(directory, ".hg");
|
||||||
|
|
||||||
writeHgrc(repository, hgDirectory);
|
storeRepository(repository, hgDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -187,7 +192,7 @@ public class HgRepositoryHandler implements RepositoryHandler
|
|||||||
|
|
||||||
if (hgDirectory.exists())
|
if (hgDirectory.exists())
|
||||||
{
|
{
|
||||||
writeHgrc(repository, hgDirectory);
|
storeRepository(repository, hgDirectory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,7 +214,7 @@ public class HgRepositoryHandler implements RepositoryHandler
|
|||||||
|
|
||||||
if (hgDirectory.exists())
|
if (hgDirectory.exists())
|
||||||
{
|
{
|
||||||
readHgrc(repository, hgDirectory);
|
loadRepository(repository, hgDirectory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,7 +252,7 @@ public class HgRepositoryHandler implements RepositoryHandler
|
|||||||
repository = new Repository();
|
repository = new Repository();
|
||||||
repository.setType(TYPE_NAME);
|
repository.setType(TYPE_NAME);
|
||||||
repository.setName(directory.getName());
|
repository.setName(directory.getName());
|
||||||
readHgrc(repository, hgDirectory);
|
loadRepository(repository, hgDirectory);
|
||||||
|
|
||||||
if (!id.equals(repository.getId()))
|
if (!id.equals(repository.getId()))
|
||||||
{
|
{
|
||||||
@@ -382,13 +387,39 @@ public class HgRepositoryHandler implements RepositoryHandler
|
|||||||
repository = new Repository();
|
repository = new Repository();
|
||||||
repository.setType(TYPE_NAME);
|
repository.setType(TYPE_NAME);
|
||||||
repository.setName(name);
|
repository.setName(name);
|
||||||
readHgrc(repository, hgDirectory);
|
repository.setUrl(buildUrl(name));
|
||||||
|
loadRepository(repository, hgDirectory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return repository;
|
return repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -396,7 +427,7 @@ public class HgRepositoryHandler implements RepositoryHandler
|
|||||||
* @param repository
|
* @param repository
|
||||||
* @param hgDirectory
|
* @param hgDirectory
|
||||||
*/
|
*/
|
||||||
private void readHgrc(Repository repository, File hgDirectory)
|
private void loadRepository(Repository repository, File hgDirectory)
|
||||||
{
|
{
|
||||||
File hgrc = new File(hgDirectory, "hgrc");
|
File hgrc = new File(hgDirectory, "hgrc");
|
||||||
|
|
||||||
@@ -441,6 +472,20 @@ public class HgRepositoryHandler implements RepositoryHandler
|
|||||||
String id = scmSection.getParameter("id");
|
String id = scmSection.getParameter("id");
|
||||||
|
|
||||||
repository.setId(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)
|
catch (IOException ex)
|
||||||
@@ -459,7 +504,7 @@ public class HgRepositoryHandler implements RepositoryHandler
|
|||||||
*
|
*
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private void writeHgrc(Repository repository, File hgDirectory)
|
private void storeRepository(Repository repository, File hgDirectory)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
INISection section = new INISection("web");
|
INISection section = new INISection("web");
|
||||||
@@ -491,6 +536,13 @@ public class HgRepositoryHandler implements RepositoryHandler
|
|||||||
|
|
||||||
scmSection.setParameter("id", repository.getId());
|
scmSection.setParameter("id", repository.getId());
|
||||||
|
|
||||||
|
Date creationDate = repository.getCreationDate();
|
||||||
|
|
||||||
|
if (creationDate != null)
|
||||||
|
{
|
||||||
|
scmSection.setParameter("creationDate", Util.formatDate(creationDate));
|
||||||
|
}
|
||||||
|
|
||||||
INIConfiguration iniConfig = new INIConfiguration();
|
INIConfiguration iniConfig = new INIConfiguration();
|
||||||
|
|
||||||
iniConfig.addSection(section);
|
iniConfig.addSection(section);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import java.io.Serializable;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
@@ -29,7 +30,8 @@ import javax.xml.bind.annotation.XmlType;
|
|||||||
@XmlRootElement(name = "repositories")
|
@XmlRootElement(name = "repositories")
|
||||||
@XmlType(propOrder =
|
@XmlType(propOrder =
|
||||||
{
|
{
|
||||||
"id", "type", "name", "contact", "description", "permissions"
|
"id", "type", "name", "contact", "description", "creationDate", "url",
|
||||||
|
"permissions"
|
||||||
})
|
})
|
||||||
public class Repository implements Serializable
|
public class Repository implements Serializable
|
||||||
{
|
{
|
||||||
@@ -102,6 +104,17 @@ public class Repository implements Serializable
|
|||||||
return contact;
|
return contact;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Date getCreationDate()
|
||||||
|
{
|
||||||
|
return creationDate;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -157,6 +170,17 @@ public class Repository implements Serializable
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getUrl()
|
||||||
|
{
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
//~--- set methods ----------------------------------------------------------
|
//~--- set methods ----------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -170,6 +194,17 @@ public class Repository implements Serializable
|
|||||||
this.contact = contact;
|
this.contact = contact;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param creationDate
|
||||||
|
*/
|
||||||
|
public void setCreationDate(Date creationDate)
|
||||||
|
{
|
||||||
|
this.creationDate = creationDate;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -225,11 +260,25 @@ public class Repository implements Serializable
|
|||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param url
|
||||||
|
*/
|
||||||
|
public void setUrl(String url)
|
||||||
|
{
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private String contact;
|
private String contact;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private Date creationDate;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
@@ -244,4 +293,7 @@ public class Repository implements Serializable
|
|||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private String url;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,12 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.TimeZone;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@@ -26,6 +31,9 @@ import java.util.logging.Logger;
|
|||||||
public class Util
|
public class Util
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
public static final String DATE_PATTERN = "yyyy-MM-dd HH-mm-ss";
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private static final Logger logger = Logger.getLogger(Util.class.getName());
|
private static final Logger logger = Logger.getLogger(Util.class.getName());
|
||||||
|
|
||||||
@@ -100,6 +108,79 @@ public class Util
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user