fix potential bugs

This commit is contained in:
Sebastian Sdorra
2010-11-07 15:30:23 +01:00
parent 2c7fee14e8
commit e8a838c063
5 changed files with 20 additions and 95 deletions

View File

@@ -401,7 +401,8 @@ public class HgRepositoryHandler extends AbstractRepositoryHandler<HgConfig>
{
try
{
repository.setCreationDate(Util.parseDate(creationDateString));
repository.setCreationDate(
Util.parseDate(creationDateString).getTime());
}
catch (ParseException ex)
{
@@ -460,11 +461,12 @@ public class HgRepositoryHandler extends AbstractRepositoryHandler<HgConfig>
scmSection.setParameter("id", repository.getId());
Date creationDate = repository.getCreationDate();
long creationDate = repository.getCreationDate();
if (creationDate != null)
if (creationDate >= -1)
{
scmSection.setParameter("creationDate", Util.formatDate(creationDate));
scmSection.setParameter("creationDate",
Util.formatDate(new Date(creationDate)));
}
INIConfiguration iniConfig = new INIConfiguration();

View File

@@ -29,6 +29,8 @@
*
*/
package sonia.scm.io;
//~--- non-JDK imports --------------------------------------------------------
@@ -43,7 +45,6 @@ import sonia.scm.util.IOUtil;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
/**
@@ -139,16 +140,16 @@ public class SimpleCommand implements Command
protected SimpleCommandResult getResult(Process process) throws IOException
{
SimpleCommandResult result = null;
InputStream input = null;
BufferedReader reader = null;
try
{
String s = System.getProperty("line.separator");
StringBuilder content = new StringBuilder();
input = process.getInputStream();
reader =
new BufferedReader(new InputStreamReader(process.getInputStream()));
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
String line = reader.readLine();
while (line != null)
@@ -174,7 +175,7 @@ public class SimpleCommand implements Command
}
finally
{
IOUtil.close(input);
IOUtil.close(reader);
}
return result;

View File

@@ -29,6 +29,8 @@
*
*/
package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
@@ -42,7 +44,6 @@ import sonia.scm.util.Util;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
@@ -223,7 +224,7 @@ public abstract class AbstractRepositoryHandler<C extends BasicRepositoryConfig>
{
repository.setId(UUID.randomUUID().toString());
repository.setUrl(buildUrl(repository));
repository.setCreationDate(new Date());
repository.setCreationDate(System.currentTimeMillis());
}
/**

View File

@@ -36,8 +36,8 @@ package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.TypedObject;
import sonia.scm.util.DateAdapter;
import sonia.scm.util.Util;
import sonia.scm.xml.XmlTimestampDateAdapter;
//~--- JDK imports ------------------------------------------------------------
@@ -45,7 +45,6 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
@@ -160,7 +159,7 @@ public class Repository implements TypedObject, Serializable
*
* @return
*/
public Date getCreationDate()
public long getCreationDate()
{
return creationDate;
}
@@ -251,7 +250,7 @@ public class Repository implements TypedObject, Serializable
*
* @param creationDate
*/
public void setCreationDate(Date creationDate)
public void setCreationDate(long creationDate)
{
this.creationDate = creationDate;
}
@@ -328,8 +327,8 @@ public class Repository implements TypedObject, Serializable
private String contact;
/** Field description */
@XmlJavaTypeAdapter(DateAdapter.class)
private Date creationDate;
@XmlJavaTypeAdapter(XmlTimestampDateAdapter.class)
private Long creationDate;
/** Field description */
private String description;

View File

@@ -1,78 +0,0 @@
/**
* Copyright (c) 2010, Sebastian Sdorra
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of SCM-Manager; nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.util;
//~--- JDK imports ------------------------------------------------------------
import java.util.Date;
import javax.xml.bind.annotation.adapters.XmlAdapter;
/**
*
* @author Sebastian Sdorra
*/
public class DateAdapter extends XmlAdapter<String, Date>
{
/**
* Method description
*
*
* @param data
*
* @return
*
* @throws Exception
*/
@Override
public String marshal(Date data) throws Exception
{
return Util.formatDate(data);
}
/**
* Method description
*
*
* @param string
*
* @return
*
* @throws Exception
*/
@Override
public Date unmarshal(String string) throws Exception
{
return Util.parseDate(string);
}
}