mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 07:55:47 +01:00
use new python scritps
This commit is contained in:
@@ -38,6 +38,7 @@ package sonia.scm.repository;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import sonia.scm.SCMContext;
|
||||||
import sonia.scm.util.IOUtil;
|
import sonia.scm.util.IOUtil;
|
||||||
import sonia.scm.util.Util;
|
import sonia.scm.util.Util;
|
||||||
import sonia.scm.web.HgUtil;
|
import sonia.scm.web.HgUtil;
|
||||||
@@ -91,7 +92,7 @@ public class AbstractHgHandler
|
|||||||
public static final String ENV_PYTHONIOENCODING = "PYTHONIOENCODING";
|
public static final String ENV_PYTHONIOENCODING = "PYTHONIOENCODING";
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
public static final String ENV_PYTHON_PATH = "SCM_PYTHON_PATH";
|
public static final String ENV_PYTHONPATH = "PYTHONPATH";
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
public static final String ENV_REPOSITORY_PATH = "SCM_REPOSITORY_PATH";
|
public static final String ENV_REPOSITORY_PATH = "SCM_REPOSITORY_PATH";
|
||||||
@@ -232,29 +233,20 @@ public class AbstractHgHandler
|
|||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
* @param script
|
||||||
* @param extraEnv
|
* @param extraEnv
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*
|
*
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
protected Process createPythonProcess(Map<String, String> extraEnv)
|
protected Process createScriptProcess(HgPythonScript script,
|
||||||
|
Map<String, String> extraEnv)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
return createProcess(extraEnv, handler.getConfig().getPythonBinary());
|
return createProcess(
|
||||||
}
|
extraEnv, handler.getConfig().getPythonBinary(),
|
||||||
|
script.getFile(SCMContext.getContext()).getAbsolutePath());
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
protected Process createPythonProcess() throws IOException
|
|
||||||
{
|
|
||||||
return createPythonProcess(new HashMap<String, String>());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -297,7 +289,7 @@ public class AbstractHgHandler
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param resultType
|
* @param resultType
|
||||||
* @param scriptResource
|
* @param script
|
||||||
* @param <T>
|
* @param <T>
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
@@ -306,10 +298,10 @@ public class AbstractHgHandler
|
|||||||
* @throws RepositoryException
|
* @throws RepositoryException
|
||||||
*/
|
*/
|
||||||
protected <T> T getResultFromScript(Class<T> resultType,
|
protected <T> T getResultFromScript(Class<T> resultType,
|
||||||
String scriptResource)
|
HgPythonScript script)
|
||||||
throws IOException, RepositoryException
|
throws IOException, RepositoryException
|
||||||
{
|
{
|
||||||
return getResultFromScript(resultType, scriptResource,
|
return getResultFromScript(resultType, script,
|
||||||
new HashMap<String, String>());
|
new HashMap<String, String>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -318,7 +310,7 @@ public class AbstractHgHandler
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param resultType
|
* @param resultType
|
||||||
* @param scriptResource
|
* @param script
|
||||||
* @param extraEnv
|
* @param extraEnv
|
||||||
* @param <T>
|
* @param <T>
|
||||||
*
|
*
|
||||||
@@ -328,11 +320,10 @@ public class AbstractHgHandler
|
|||||||
* @throws RepositoryException
|
* @throws RepositoryException
|
||||||
*/
|
*/
|
||||||
protected <T> T getResultFromScript(Class<T> resultType,
|
protected <T> T getResultFromScript(Class<T> resultType,
|
||||||
String scriptResource, Map<String, String> extraEnv)
|
HgPythonScript script, Map<String, String> extraEnv)
|
||||||
throws IOException, RepositoryException
|
throws IOException, RepositoryException
|
||||||
{
|
{
|
||||||
return getResultFromScript(resultType, scriptResource, jaxbContext,
|
return getResultFromScript(resultType, script, jaxbContext, extraEnv);
|
||||||
extraEnv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -340,7 +331,7 @@ public class AbstractHgHandler
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param resultType
|
* @param resultType
|
||||||
* @param scriptResource
|
* @param script
|
||||||
* @param jaxbContext
|
* @param jaxbContext
|
||||||
* @param extraEnv
|
* @param extraEnv
|
||||||
* @param <T>
|
* @param <T>
|
||||||
@@ -351,22 +342,17 @@ public class AbstractHgHandler
|
|||||||
* @throws RepositoryException
|
* @throws RepositoryException
|
||||||
*/
|
*/
|
||||||
protected <T> T getResultFromScript(Class<T> resultType,
|
protected <T> T getResultFromScript(Class<T> resultType,
|
||||||
String scriptResource, JAXBContext jaxbContext,
|
HgPythonScript script, JAXBContext jaxbContext,
|
||||||
Map<String, String> extraEnv)
|
Map<String, String> extraEnv)
|
||||||
throws IOException, RepositoryException
|
throws IOException, RepositoryException
|
||||||
{
|
{
|
||||||
Process p = createPythonProcess(extraEnv);
|
Process p = createScriptProcess(script, extraEnv);
|
||||||
T result = null;
|
T result = null;
|
||||||
InputStream resource = null;
|
|
||||||
InputStream input = null;
|
InputStream input = null;
|
||||||
OutputStream output = null;
|
OutputStream output = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
resource = HgUtil.class.getResourceAsStream(scriptResource);
|
|
||||||
output = p.getOutputStream();
|
|
||||||
IOUtil.copy(resource, output);
|
|
||||||
output.close();
|
|
||||||
handleErrorStream(p.getErrorStream());
|
handleErrorStream(p.getErrorStream());
|
||||||
input = p.getInputStream();
|
input = p.getInputStream();
|
||||||
result = (T) jaxbContext.createUnmarshaller().unmarshal(input);
|
result = (T) jaxbContext.createUnmarshaller().unmarshal(input);
|
||||||
@@ -380,7 +366,6 @@ public class AbstractHgHandler
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
IOUtil.close(resource);
|
|
||||||
IOUtil.close(input);
|
IOUtil.close(input);
|
||||||
IOUtil.close(output);
|
IOUtil.close(output);
|
||||||
}
|
}
|
||||||
@@ -465,7 +450,21 @@ public class AbstractHgHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
env.put(ENV_PYTHON_PATH, Util.nonNull(config.getPythonPath()));
|
String pythonPath = Util.nonNull(config.getPythonPath());
|
||||||
|
|
||||||
|
if (Util.isNotEmpty(pythonPath))
|
||||||
|
{
|
||||||
|
pythonPath = pythonPath.concat(":");
|
||||||
|
}
|
||||||
|
|
||||||
|
//J-
|
||||||
|
pythonPath = pythonPath.concat(
|
||||||
|
HgPythonScript.getScriptDirectory(
|
||||||
|
SCMContext.getContext()
|
||||||
|
).getAbsolutePath()
|
||||||
|
);
|
||||||
|
//J+
|
||||||
|
env.put(ENV_PYTHONPATH, pythonPath);
|
||||||
env.put(ENV_REPOSITORY_PATH, directory.getAbsolutePath());
|
env.put(ENV_REPOSITORY_PATH, directory.getAbsolutePath());
|
||||||
env.putAll(extraEnv);
|
env.putAll(extraEnv);
|
||||||
|
|
||||||
|
|||||||
@@ -56,9 +56,6 @@ import javax.xml.bind.JAXBContext;
|
|||||||
public class HgBlameViewer extends AbstractHgHandler implements BlameViewer
|
public class HgBlameViewer extends AbstractHgHandler implements BlameViewer
|
||||||
{
|
{
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String RESOURCE_BLAME = "/sonia/scm/hgblame.py";
|
|
||||||
|
|
||||||
/** the logger for HgBlameViewer */
|
/** the logger for HgBlameViewer */
|
||||||
private static final Logger logger =
|
private static final Logger logger =
|
||||||
LoggerFactory.getLogger(HgBlameViewer.class);
|
LoggerFactory.getLogger(HgBlameViewer.class);
|
||||||
@@ -109,6 +106,6 @@ public class HgBlameViewer extends AbstractHgHandler implements BlameViewer
|
|||||||
|
|
||||||
Map<String, String> env = createEnvironment(revision, path);
|
Map<String, String> env = createEnvironment(revision, path);
|
||||||
|
|
||||||
return getResultFromScript(BlameResult.class, RESOURCE_BLAME, env);
|
return getResultFromScript(BlameResult.class, HgPythonScript.BLAME, env);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,9 +59,6 @@ public class HgChangesetViewer extends AbstractHgHandler
|
|||||||
implements ChangesetViewer
|
implements ChangesetViewer
|
||||||
{
|
{
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String RESOURCE_LOG = "/sonia/scm/hglog.py";
|
|
||||||
|
|
||||||
/** the logger for HgChangesetViewer */
|
/** the logger for HgChangesetViewer */
|
||||||
private static final Logger logger =
|
private static final Logger logger =
|
||||||
LoggerFactory.getLogger(HgChangesetViewer.class);
|
LoggerFactory.getLogger(HgChangesetViewer.class);
|
||||||
@@ -133,8 +130,8 @@ public class HgChangesetViewer extends AbstractHgHandler
|
|||||||
env.put(ENV_REVISION_START, Util.EMPTY_STRING);
|
env.put(ENV_REVISION_START, Util.EMPTY_STRING);
|
||||||
env.put(ENV_REVISION_END, Util.EMPTY_STRING);
|
env.put(ENV_REVISION_END, Util.EMPTY_STRING);
|
||||||
|
|
||||||
return getResultFromScript(Changeset.class, RESOURCE_LOG, changesetContext,
|
return getResultFromScript(Changeset.class, HgPythonScript.CHANGELOG,
|
||||||
env);
|
changesetContext, env);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -225,7 +222,8 @@ public class HgChangesetViewer extends AbstractHgHandler
|
|||||||
env.put(ENV_REVISION_START, Util.nonNull(revisionStart));
|
env.put(ENV_REVISION_START, Util.nonNull(revisionStart));
|
||||||
env.put(ENV_REVISION_END, Util.nonNull(revisionEnd));
|
env.put(ENV_REVISION_END, Util.nonNull(revisionEnd));
|
||||||
|
|
||||||
return getResultFromScript(ChangesetPagingResult.class, RESOURCE_LOG, env);
|
return getResultFromScript(ChangesetPagingResult.class,
|
||||||
|
HgPythonScript.CHANGELOG, env);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -57,11 +57,6 @@ public class HgRepositoryBrowser extends AbstractHgHandler
|
|||||||
implements RepositoryBrowser
|
implements RepositoryBrowser
|
||||||
{
|
{
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String RESOURCE_BROWSE = "/sonia/scm/hgbrowse.py";
|
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs ...
|
* Constructs ...
|
||||||
*
|
*
|
||||||
@@ -131,6 +126,7 @@ public class HgRepositoryBrowser extends AbstractHgHandler
|
|||||||
{
|
{
|
||||||
Map<String, String> env = createEnvironment(revision, path);
|
Map<String, String> env = createEnvironment(revision, path);
|
||||||
|
|
||||||
return getResultFromScript(BrowserResult.class, RESOURCE_BROWSE, env);
|
return getResultFromScript(BrowserResult.class, HgPythonScript.FILELOG,
|
||||||
|
env);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user