mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-02 03:25:56 +01:00
use AbstractSimpleRepositoryHandler for scm-svn-plugin
This commit is contained in:
@@ -16,20 +16,9 @@ import javax.xml.bind.annotation.XmlRootElement;
|
|||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
@XmlRootElement(name = "config")
|
@XmlRootElement(name = "config")
|
||||||
public class SvnConfig extends BasicRepositoryConfig
|
public class SvnConfig extends SimpleRepositoryConfig
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getRepositoryDirectory()
|
|
||||||
{
|
|
||||||
return repositoryDirectory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -54,17 +43,6 @@ public class SvnConfig extends BasicRepositoryConfig
|
|||||||
|
|
||||||
//~--- set methods ----------------------------------------------------------
|
//~--- set methods ----------------------------------------------------------
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param repositoryDirectory
|
|
||||||
*/
|
|
||||||
public void setRepositoryDirectory(String repositoryDirectory)
|
|
||||||
{
|
|
||||||
this.repositoryDirectory = repositoryDirectory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -89,9 +67,6 @@ public class SvnConfig extends BasicRepositoryConfig
|
|||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private String repositoryDirectory;
|
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private String svnAccessFile;
|
private String svnAccessFile;
|
||||||
|
|
||||||
|
|||||||
@@ -9,31 +9,18 @@ package sonia.scm.repository;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import sonia.scm.ConfigurationException;
|
|
||||||
import sonia.scm.SCMContextProvider;
|
|
||||||
import sonia.scm.io.CommandResult;
|
|
||||||
import sonia.scm.io.ExtendedCommand;
|
import sonia.scm.io.ExtendedCommand;
|
||||||
import sonia.scm.util.IOUtil;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FilenameFilter;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.xml.bind.JAXB;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
public class SvnRepositoryHandler extends AbstractRepositoryHandler<SvnConfig>
|
public class SvnRepositoryHandler
|
||||||
|
extends AbstractSimpleRepositoryHandler<SvnConfig>
|
||||||
{
|
{
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
@@ -46,209 +33,8 @@ public class SvnRepositoryHandler extends AbstractRepositoryHandler<SvnConfig>
|
|||||||
public static final RepositoryType TYPE = new RepositoryType(TYPE_NAME,
|
public static final RepositoryType TYPE = new RepositoryType(TYPE_NAME,
|
||||||
TYPE_DISPLAYNAME);
|
TYPE_DISPLAYNAME);
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private static final Logger logger =
|
|
||||||
Logger.getLogger(SvnRepositoryHandler.class.getName());
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String CONFIG_DIRECTORY =
|
|
||||||
"config".concat(File.separator).concat("svn");
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param repository
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
* @throws RepositoryException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void create(Repository repository)
|
|
||||||
throws RepositoryException, IOException
|
|
||||||
{
|
|
||||||
initNewRepository(repository);
|
|
||||||
|
|
||||||
File directory = getDirectory(repository);
|
|
||||||
|
|
||||||
if (directory.exists())
|
|
||||||
{
|
|
||||||
throw new RepositoryAllreadyExistExeption();
|
|
||||||
}
|
|
||||||
|
|
||||||
ExtendedCommand cmd = new ExtendedCommand(config.getSvnAdminBinary(),
|
|
||||||
"create", directory.getPath());
|
|
||||||
CommandResult result = cmd.execute();
|
|
||||||
|
|
||||||
if (!result.isSuccessfull())
|
|
||||||
{
|
|
||||||
StringBuilder msg = new StringBuilder("svnadmin exit with error ");
|
|
||||||
|
|
||||||
msg.append(result.getReturnCode()).append(" and message: '");
|
|
||||||
msg.append(result.getOutput()).append("'");
|
|
||||||
|
|
||||||
throw new RepositoryException(msg.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
repository.setType(TYPE_NAME);
|
|
||||||
JAXB.marshal(repository, getRepositoryFile(repository));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param repository
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
* @throws RepositoryException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void delete(Repository repository)
|
|
||||||
throws RepositoryException, IOException
|
|
||||||
{
|
|
||||||
File directory = getDirectory(repository);
|
|
||||||
File repositoryFile = getRepositoryFile(repository);
|
|
||||||
|
|
||||||
if (directory.exists() && repositoryFile.exists())
|
|
||||||
{
|
|
||||||
IOUtil.delete(directory);
|
|
||||||
IOUtil.delete(repositoryFile);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new RepositoryException("repository does not exists");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param context
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void init(SCMContextProvider context)
|
|
||||||
{
|
|
||||||
super.init(context);
|
|
||||||
|
|
||||||
File baseDirectory = context.getBaseDirectory();
|
|
||||||
|
|
||||||
configDirectory = new File(baseDirectory, CONFIG_DIRECTORY);
|
|
||||||
|
|
||||||
if (!configDirectory.exists() &&!configDirectory.mkdirs())
|
|
||||||
{
|
|
||||||
throw new ConfigurationException("could not create config directory");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param repository
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
* @throws RepositoryException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void modify(Repository repository)
|
|
||||||
throws RepositoryException, IOException
|
|
||||||
{
|
|
||||||
Repository old = get(repository.getId());
|
|
||||||
|
|
||||||
if (old.getName().equals(repository.getName()))
|
|
||||||
{
|
|
||||||
JAXB.marshal(repository, getRepositoryFile(repository));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new RepositoryException(
|
|
||||||
"the name of a repository could not changed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param repository
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
* @throws RepositoryException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void refresh(Repository repository)
|
|
||||||
throws RepositoryException, IOException
|
|
||||||
{
|
|
||||||
Repository fresh = get(repository.getId());
|
|
||||||
|
|
||||||
fresh.copyProperties(repository);
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Repository get(String id)
|
|
||||||
{
|
|
||||||
Repository repository = null;
|
|
||||||
File repositoryFile = getRepositoryFile(id);
|
|
||||||
|
|
||||||
if (repositoryFile.exists())
|
|
||||||
{
|
|
||||||
repository = JAXB.unmarshal(repositoryFile, Repository.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
return repository;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Collection<Repository> getAll()
|
|
||||||
{
|
|
||||||
List<Repository> repositories = new ArrayList<Repository>();
|
|
||||||
File[] repositoryFiles = configDirectory.listFiles(new FilenameFilter()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public boolean accept(File dir, String name)
|
|
||||||
{
|
|
||||||
return name.endsWith(".xml");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
for (File repositoryFile : repositoryFiles)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Repository repository = JAXB.unmarshal(repositoryFile,
|
|
||||||
Repository.class);
|
|
||||||
|
|
||||||
repositories.add(repository);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
logger.log(Level.SEVERE, null, ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return repositories;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -261,6 +47,27 @@ public class SvnRepositoryHandler extends AbstractRepositoryHandler<SvnConfig>
|
|||||||
return TYPE;
|
return TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param repository
|
||||||
|
* @param directory
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected ExtendedCommand buildCreateCommand(Repository repository,
|
||||||
|
File directory)
|
||||||
|
{
|
||||||
|
return new ExtendedCommand(config.getSvnAdminBinary(), "create",
|
||||||
|
directory.getPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -272,61 +79,4 @@ public class SvnRepositoryHandler extends AbstractRepositoryHandler<SvnConfig>
|
|||||||
{
|
{
|
||||||
return SvnConfig.class;
|
return SvnConfig.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param repository
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected File getDirectory(Repository repository)
|
|
||||||
{
|
|
||||||
File directory = null;
|
|
||||||
|
|
||||||
if (isConfigured())
|
|
||||||
{
|
|
||||||
directory = new File(config.getRepositoryDirectory(),
|
|
||||||
repository.getName());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new ConfigurationException("RepositoryHandler is not configured");
|
|
||||||
}
|
|
||||||
|
|
||||||
return directory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private File getRepositoryFile(String id)
|
|
||||||
{
|
|
||||||
return new File(configDirectory, id.concat(".xml"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param repository
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private File getRepositoryFile(Repository repository)
|
|
||||||
{
|
|
||||||
return getRepositoryFile(repository.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private File configDirectory;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user