mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +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.LoggerFactory;
|
||||
|
||||
import sonia.scm.SCMContext;
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.Util;
|
||||
import sonia.scm.web.HgUtil;
|
||||
@@ -91,7 +92,7 @@ public class AbstractHgHandler
|
||||
public static final String ENV_PYTHONIOENCODING = "PYTHONIOENCODING";
|
||||
|
||||
/** Field description */
|
||||
public static final String ENV_PYTHON_PATH = "SCM_PYTHON_PATH";
|
||||
public static final String ENV_PYTHONPATH = "PYTHONPATH";
|
||||
|
||||
/** Field description */
|
||||
public static final String ENV_REPOSITORY_PATH = "SCM_REPOSITORY_PATH";
|
||||
@@ -232,29 +233,20 @@ public class AbstractHgHandler
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param script
|
||||
* @param extraEnv
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
protected Process createPythonProcess(Map<String, String> extraEnv)
|
||||
protected Process createScriptProcess(HgPythonScript script,
|
||||
Map<String, String> extraEnv)
|
||||
throws IOException
|
||||
{
|
||||
return createProcess(extraEnv, handler.getConfig().getPythonBinary());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
protected Process createPythonProcess() throws IOException
|
||||
{
|
||||
return createPythonProcess(new HashMap<String, String>());
|
||||
return createProcess(
|
||||
extraEnv, handler.getConfig().getPythonBinary(),
|
||||
script.getFile(SCMContext.getContext()).getAbsolutePath());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -297,7 +289,7 @@ public class AbstractHgHandler
|
||||
*
|
||||
*
|
||||
* @param resultType
|
||||
* @param scriptResource
|
||||
* @param script
|
||||
* @param <T>
|
||||
*
|
||||
* @return
|
||||
@@ -306,10 +298,10 @@ public class AbstractHgHandler
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
protected <T> T getResultFromScript(Class<T> resultType,
|
||||
String scriptResource)
|
||||
HgPythonScript script)
|
||||
throws IOException, RepositoryException
|
||||
{
|
||||
return getResultFromScript(resultType, scriptResource,
|
||||
return getResultFromScript(resultType, script,
|
||||
new HashMap<String, String>());
|
||||
}
|
||||
|
||||
@@ -318,7 +310,7 @@ public class AbstractHgHandler
|
||||
*
|
||||
*
|
||||
* @param resultType
|
||||
* @param scriptResource
|
||||
* @param script
|
||||
* @param extraEnv
|
||||
* @param <T>
|
||||
*
|
||||
@@ -328,11 +320,10 @@ public class AbstractHgHandler
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
protected <T> T getResultFromScript(Class<T> resultType,
|
||||
String scriptResource, Map<String, String> extraEnv)
|
||||
HgPythonScript script, Map<String, String> extraEnv)
|
||||
throws IOException, RepositoryException
|
||||
{
|
||||
return getResultFromScript(resultType, scriptResource, jaxbContext,
|
||||
extraEnv);
|
||||
return getResultFromScript(resultType, script, jaxbContext, extraEnv);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -340,7 +331,7 @@ public class AbstractHgHandler
|
||||
*
|
||||
*
|
||||
* @param resultType
|
||||
* @param scriptResource
|
||||
* @param script
|
||||
* @param jaxbContext
|
||||
* @param extraEnv
|
||||
* @param <T>
|
||||
@@ -351,22 +342,17 @@ public class AbstractHgHandler
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
protected <T> T getResultFromScript(Class<T> resultType,
|
||||
String scriptResource, JAXBContext jaxbContext,
|
||||
HgPythonScript script, JAXBContext jaxbContext,
|
||||
Map<String, String> extraEnv)
|
||||
throws IOException, RepositoryException
|
||||
{
|
||||
Process p = createPythonProcess(extraEnv);
|
||||
Process p = createScriptProcess(script, extraEnv);
|
||||
T result = null;
|
||||
InputStream resource = null;
|
||||
InputStream input = null;
|
||||
OutputStream output = null;
|
||||
|
||||
try
|
||||
{
|
||||
resource = HgUtil.class.getResourceAsStream(scriptResource);
|
||||
output = p.getOutputStream();
|
||||
IOUtil.copy(resource, output);
|
||||
output.close();
|
||||
handleErrorStream(p.getErrorStream());
|
||||
input = p.getInputStream();
|
||||
result = (T) jaxbContext.createUnmarshaller().unmarshal(input);
|
||||
@@ -380,7 +366,6 @@ public class AbstractHgHandler
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close(resource);
|
||||
IOUtil.close(input);
|
||||
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.putAll(extraEnv);
|
||||
|
||||
|
||||
@@ -56,9 +56,6 @@ import javax.xml.bind.JAXBContext;
|
||||
public class HgBlameViewer extends AbstractHgHandler implements BlameViewer
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String RESOURCE_BLAME = "/sonia/scm/hgblame.py";
|
||||
|
||||
/** the logger for HgBlameViewer */
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(HgBlameViewer.class);
|
||||
@@ -109,6 +106,6 @@ public class HgBlameViewer extends AbstractHgHandler implements BlameViewer
|
||||
|
||||
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
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String RESOURCE_LOG = "/sonia/scm/hglog.py";
|
||||
|
||||
/** the logger for HgChangesetViewer */
|
||||
private static final Logger logger =
|
||||
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_END, Util.EMPTY_STRING);
|
||||
|
||||
return getResultFromScript(Changeset.class, RESOURCE_LOG, changesetContext,
|
||||
env);
|
||||
return getResultFromScript(Changeset.class, HgPythonScript.CHANGELOG,
|
||||
changesetContext, env);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -225,7 +222,8 @@ public class HgChangesetViewer extends AbstractHgHandler
|
||||
env.put(ENV_REVISION_START, Util.nonNull(revisionStart));
|
||||
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
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String RESOURCE_BROWSE = "/sonia/scm/hgbrowse.py";
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
@@ -131,6 +126,7 @@ public class HgRepositoryBrowser extends AbstractHgHandler
|
||||
{
|
||||
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