mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
added getResultFromScript to HgUtil
This commit is contained in:
@@ -101,39 +101,9 @@ public class HgBlameViewer implements BlameViewer
|
||||
{
|
||||
AssertUtil.assertIsNotEmpty(path);
|
||||
|
||||
Process p = HgUtil.createPythonProcess(handler, repository, revision, path);
|
||||
BlameResult result = null;
|
||||
InputStream resource = null;
|
||||
InputStream input = null;
|
||||
OutputStream output = null;
|
||||
|
||||
try
|
||||
{
|
||||
resource = HgBlameViewer.class.getResourceAsStream(RESOURCE_BLAME);
|
||||
output = p.getOutputStream();
|
||||
IOUtil.copy(resource, output);
|
||||
output.close();
|
||||
|
||||
// IOUtil.copy(p.getErrorStream(), System.err);
|
||||
input = p.getInputStream();
|
||||
result =
|
||||
(BlameResult) blameResultContext.createUnmarshaller().unmarshal(input);
|
||||
|
||||
// IOUtil.copy(input, System.out);
|
||||
input.close();
|
||||
}
|
||||
catch (JAXBException ex)
|
||||
{
|
||||
logger.error("could not parse result", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close(resource);
|
||||
IOUtil.close(input);
|
||||
IOUtil.close(output);
|
||||
}
|
||||
|
||||
return result;
|
||||
return HgUtil.getResultFromScript(BlameResult.class, blameResultContext,
|
||||
RESOURCE_BLAME, handler, repository,
|
||||
revision, path);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
@@ -170,40 +170,9 @@ public class HgRepositoryBrowser implements RepositoryBrowser
|
||||
public BrowserResult getResult(String revision, String path)
|
||||
throws IOException, RepositoryException
|
||||
{
|
||||
Process p = HgUtil.createPythonProcess(handler, repository, revision, path);
|
||||
BrowserResult result = null;
|
||||
InputStream resource = null;
|
||||
InputStream input = null;
|
||||
OutputStream output = null;
|
||||
|
||||
try
|
||||
{
|
||||
resource = HgRepositoryBrowser.class.getResourceAsStream(RESOURCE_BROWSE);
|
||||
output = p.getOutputStream();
|
||||
IOUtil.copy(resource, output);
|
||||
output.close();
|
||||
|
||||
// IOUtil.copy(p.getErrorStream(), System.err);
|
||||
input = p.getInputStream();
|
||||
result =
|
||||
(BrowserResult) browserResultContext.createUnmarshaller().unmarshal(
|
||||
input);
|
||||
|
||||
// IOUtil.copy(input, System.out);
|
||||
input.close();
|
||||
}
|
||||
catch (JAXBException ex)
|
||||
{
|
||||
logger.error("could not parse result", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close(resource);
|
||||
IOUtil.close(input);
|
||||
IOUtil.close(output);
|
||||
}
|
||||
|
||||
return result;
|
||||
return HgUtil.getResultFromScript(BrowserResult.class,
|
||||
browserResultContext, RESOURCE_BROWSE,
|
||||
handler, repository, revision, path);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
@@ -35,19 +35,29 @@ package sonia.scm.web;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.SCMContext;
|
||||
import sonia.scm.repository.BrowserResult;
|
||||
import sonia.scm.repository.HgConfig;
|
||||
import sonia.scm.repository.HgRepositoryHandler;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -76,6 +86,9 @@ public class HgUtil
|
||||
/** Field description */
|
||||
public static final String REVISION_TIP = "tip";
|
||||
|
||||
/** the logger for HgUtil */
|
||||
private static final Logger logger = LoggerFactory.getLogger(HgUtil.class);
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -146,4 +159,58 @@ public class HgUtil
|
||||
? REVISION_TIP
|
||||
: revision;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param resultType
|
||||
* @param context
|
||||
* @param scriptResource
|
||||
* @param handler
|
||||
* @param repository
|
||||
* @param revision
|
||||
* @param path
|
||||
* @param <T>
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public static <T> T getResultFromScript(Class<T> resultType, JAXBContext context,
|
||||
String scriptResource,
|
||||
HgRepositoryHandler handler,
|
||||
Repository repository, String revision,
|
||||
String path)
|
||||
throws IOException
|
||||
{
|
||||
Process p = createPythonProcess(handler, repository, revision, path);
|
||||
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();
|
||||
input = p.getInputStream();
|
||||
result = (T) context.createUnmarshaller().unmarshal(input);
|
||||
input.close();
|
||||
}
|
||||
catch (JAXBException ex)
|
||||
{
|
||||
logger.error("could not parse result", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close(resource);
|
||||
IOUtil.close(input);
|
||||
IOUtil.close(output);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user