mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 16:35:45 +01:00
improve scm-hg-plugin
This commit is contained in:
@@ -29,6 +29,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.api.rest.resources;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
@@ -107,7 +109,6 @@ public class HgConfigResource
|
||||
*
|
||||
*
|
||||
* @param uriInfo
|
||||
* @param servletContext
|
||||
* @param config
|
||||
*
|
||||
* @return
|
||||
@@ -116,14 +117,12 @@ public class HgConfigResource
|
||||
*/
|
||||
@POST
|
||||
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public Response setConfig(@Context UriInfo uriInfo,
|
||||
@Context ServletContext servletContext,
|
||||
HgConfig config)
|
||||
public Response setConfig(@Context UriInfo uriInfo, HgConfig config)
|
||||
throws IOException
|
||||
{
|
||||
handler.setConfig(config);
|
||||
handler.storeConfig();
|
||||
new HgWebConfigWriter(config).write(servletContext);
|
||||
new HgWebConfigWriter(config).write();
|
||||
|
||||
return Response.created(uriInfo.getRequestUri()).build();
|
||||
}
|
||||
|
||||
@@ -29,12 +29,12 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
@@ -42,7 +42,7 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@XmlRootElement(name = "config")
|
||||
public class HgConfig extends BasicRepositoryConfig
|
||||
public class HgConfig extends SimpleRepositoryConfig
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -75,17 +75,6 @@ public class HgConfig extends BasicRepositoryConfig
|
||||
return pythonBinary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public File getRepositoryDirectory()
|
||||
{
|
||||
return repositoryDirectory;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -110,25 +99,11 @@ public class HgConfig extends BasicRepositoryConfig
|
||||
this.pythonBinary = pythonBinary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositoryDirectory
|
||||
*/
|
||||
public void setRepositoryDirectory(File repositoryDirectory)
|
||||
{
|
||||
this.repositoryDirectory = repositoryDirectory;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private String hgBinary = "hg";
|
||||
private String hgBinary;
|
||||
|
||||
/** Field description */
|
||||
private String pythonBinary = "python";
|
||||
|
||||
/** Field description */
|
||||
private File repositoryDirectory;
|
||||
private String pythonBinary;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
/**
|
||||
* 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.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.io.Command;
|
||||
import sonia.scm.io.CommandResult;
|
||||
import sonia.scm.io.SimpleCommand;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class HgInitialConfigBuilder
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String DIRECTORY_REPOSITORY = "repositories";
|
||||
|
||||
/** Field description */
|
||||
private static final String[] PATH = new String[]
|
||||
{
|
||||
|
||||
// default path
|
||||
"/usr/bin",
|
||||
|
||||
// manually installed
|
||||
"/usr/local/bin",
|
||||
|
||||
// mac ports
|
||||
"/opt/local/bin",
|
||||
|
||||
// opencsw
|
||||
"/opt/csw/bin"
|
||||
};
|
||||
|
||||
/** the logger for HgInitialConfigBuilder */
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(HgInitialConfigBuilder.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param baseDirectory
|
||||
*/
|
||||
public HgInitialConfigBuilder(File baseDirectory)
|
||||
{
|
||||
this.baseDirectory = baseDirectory;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public HgConfig createInitialConfig()
|
||||
{
|
||||
File repoDirectory = new File(
|
||||
baseDirectory,
|
||||
DIRECTORY_REPOSITORY.concat(File.separator).concat(
|
||||
HgRepositoryHandler.TYPE_NAME));
|
||||
|
||||
IOUtil.mkdirs(repoDirectory);
|
||||
config.setRepositoryDirectory(repoDirectory);
|
||||
config.setHgBinary(search("hg"));
|
||||
config.setPythonBinary(search("python"));
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO check for windows
|
||||
*
|
||||
*
|
||||
* @param cmd
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String search(String cmd)
|
||||
{
|
||||
String cmdPath = null;
|
||||
|
||||
try
|
||||
{
|
||||
Command command = new SimpleCommand(cmd, "--version");
|
||||
CommandResult result = command.execute();
|
||||
|
||||
if (result.isSuccessfull())
|
||||
{
|
||||
cmdPath = cmd;
|
||||
}
|
||||
}
|
||||
catch (IOException ex) {}
|
||||
|
||||
if (cmdPath == null)
|
||||
{
|
||||
for (String pathPart : PATH)
|
||||
{
|
||||
File file = new File(pathPart, cmd);
|
||||
|
||||
if (file.exists())
|
||||
{
|
||||
cmdPath = file.getAbsolutePath();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cmdPath != null)
|
||||
{
|
||||
if (logger.isInfoEnabled())
|
||||
{
|
||||
logger.info("found {} at {}", cmd, cmdPath);
|
||||
}
|
||||
}
|
||||
else if (logger.isWarnEnabled())
|
||||
{
|
||||
logger.warn("could not find {}", cmd);
|
||||
}
|
||||
|
||||
return cmdPath;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private File baseDirectory;
|
||||
|
||||
/** Field description */
|
||||
private HgConfig config = new HgConfig();
|
||||
}
|
||||
@@ -50,6 +50,7 @@ import sonia.scm.io.INIConfigurationWriter;
|
||||
import sonia.scm.io.INISection;
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.Util;
|
||||
import sonia.scm.web.HgWebConfigWriter;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
@@ -62,6 +63,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -154,6 +156,31 @@ public class HgRepositoryHandler extends AbstractRepositoryHandler<HgConfig>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void loadConfig()
|
||||
{
|
||||
super.loadConfig();
|
||||
|
||||
if (config == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
config =
|
||||
new HgInitialConfigBuilder(baseDirectory).createInitialConfig();
|
||||
storeConfig();
|
||||
new HgWebConfigWriter(config).write();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.error(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.web;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
@@ -49,8 +51,6 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -83,11 +83,10 @@ public class HgWebConfigWriter
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param context
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public void write(ServletContext context) throws IOException
|
||||
public void write() throws IOException
|
||||
{
|
||||
File webConfigFile = new File(config.getRepositoryDirectory(), CONFIG_NAME);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user