added getPythonInstallations and getHgInstallations methods to HgConfigResource

This commit is contained in:
Sebastian Sdorra
2011-04-25 13:18:06 +02:00
parent f6c9902691
commit 65ce0d5820
4 changed files with 166 additions and 5 deletions

View File

@@ -38,6 +38,7 @@ package sonia.scm.api.rest.resources;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import sonia.scm.installer.HgInstallerFactory;
import sonia.scm.repository.HgConfig;
import sonia.scm.repository.HgRepositoryHandler;
import sonia.scm.web.HgWebConfigWriter;
@@ -46,12 +47,15 @@ import sonia.scm.web.HgWebConfigWriter;
import java.io.IOException;
import java.util.List;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
@@ -121,6 +125,42 @@ public class HgConfigResource
return config;
}
/**
* Method description
*
*
* @return
*/
@GET
@Path("installations/hg")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public GenericEntity<List<String>> getHgInstallations()
{
List<String> installations =
HgInstallerFactory.createInstaller().getHgInstallations();
return new GenericEntity<List<String>>(installations) {}
;
}
/**
* Method description
*
*
* @return
*/
@GET
@Path("installations/python")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public GenericEntity<List<String>> getPythonInstallations()
{
List<String> installations =
HgInstallerFactory.createInstaller().getPythonInstallations();
return new GenericEntity<List<String>>(installations) {}
;
}
//~--- set methods ----------------------------------------------------------
/**

View File

@@ -42,6 +42,8 @@ import sonia.scm.repository.HgConfig;
import java.io.File;
import java.io.IOException;
import java.util.List;
/**
*
* @author Sebastian Sdorra
@@ -72,4 +74,22 @@ public interface HgInstaller
* @throws IOException
*/
public void update(File baseDirectory, HgConfig config) throws IOException;
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
public List<String> getHgInstallations();
/**
* Method description
*
*
* @return
*/
public List<String> getPythonInstallations();
}

View File

@@ -43,6 +43,8 @@ import sonia.scm.util.IOUtil;
import java.io.File;
import java.io.IOException;
import java.util.List;
/**
*
* @author Sebastian Sdorra
@@ -50,6 +52,14 @@ import java.io.IOException;
public class UnixHgInstaller extends AbstractHgInstaller
{
/** Field description */
public static final String COMMAND_HG = "hg";
/** Field description */
public static final String COMMAND_PYTHON = "python";
//~--- methods --------------------------------------------------------------
/**
* Method description
*
@@ -64,8 +74,8 @@ public class UnixHgInstaller extends AbstractHgInstaller
public void install(File baseDirectory, HgConfig config) throws IOException
{
super.install(baseDirectory, config);
config.setHgBinary(IOUtil.search("hg"));
config.setPythonBinary(IOUtil.search("python"));
config.setHgBinary(IOUtil.search(COMMAND_HG));
config.setPythonBinary(IOUtil.search(COMMAND_PYTHON));
}
/**
@@ -82,4 +92,30 @@ public class UnixHgInstaller extends AbstractHgInstaller
// do nothing
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
public List<String> getHgInstallations()
{
return IOUtil.searchAll(COMMAND_HG);
}
/**
* Method description
*
*
* @return
*/
@Override
public List<String> getPythonInstallations()
{
return IOUtil.searchAll(COMMAND_PYTHON);
}
}

View File

@@ -49,6 +49,9 @@ import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Sebastian Sdorra
@@ -87,8 +90,12 @@ public class WindowsHgInstaller extends AbstractHgInstaller
};
/** Field description */
private static final String REGISTRY_PYTHON =
"HKEY_CLASSES_ROOT\\Python.File\\shell\\open\\command";
private static final String[] REGISTRY_PYTHON = new String[]
{
// .py files
"HKEY_CLASSES_ROOT\\Python.File\\shell\\open\\command"
};
/** the logger for WindowsHgInstaller */
private static final Logger logger =
@@ -141,6 +148,34 @@ public class WindowsHgInstaller extends AbstractHgInstaller
@Override
public void update(File baseDirectory, HgConfig config) {}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
public List<String> getHgInstallations()
{
return getInstallations(REGISTRY_HG);
}
/**
* Method description
*
*
* @return
*/
@Override
public List<String> getPythonInstallations()
{
return getInstallations(REGISTRY_PYTHON);
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
@@ -235,6 +270,36 @@ public class WindowsHgInstaller extends AbstractHgInstaller
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param registryKeys
*
* @return
*/
private List<String> getInstallations(String[] registryKeys)
{
List<String> installations = new ArrayList<String>();
for (String registryKey : registryKeys)
{
String path = RegistryUtil.getRegistryValue(registryKey);
if (path != null)
{
File file = new File(path);
if (!file.exists())
{
installations.add(path);
}
}
}
return installations;
}
/**
* Method description
*
@@ -310,7 +375,7 @@ public class WindowsHgInstaller extends AbstractHgInstaller
*/
private String getPythonBinary()
{
String python = RegistryUtil.getRegistryValue(REGISTRY_PYTHON);
String python = RegistryUtil.getRegistryValue(REGISTRY_PYTHON[0]);
if (python == null)
{