mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
added getResultFromScript to HgUtil
This commit is contained in:
@@ -101,39 +101,9 @@ public class HgBlameViewer implements BlameViewer
|
|||||||
{
|
{
|
||||||
AssertUtil.assertIsNotEmpty(path);
|
AssertUtil.assertIsNotEmpty(path);
|
||||||
|
|
||||||
Process p = HgUtil.createPythonProcess(handler, repository, revision, path);
|
return HgUtil.getResultFromScript(BlameResult.class, blameResultContext,
|
||||||
BlameResult result = null;
|
RESOURCE_BLAME, handler, repository,
|
||||||
InputStream resource = null;
|
revision, path);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|||||||
@@ -170,40 +170,9 @@ public class HgRepositoryBrowser implements RepositoryBrowser
|
|||||||
public BrowserResult getResult(String revision, String path)
|
public BrowserResult getResult(String revision, String path)
|
||||||
throws IOException, RepositoryException
|
throws IOException, RepositoryException
|
||||||
{
|
{
|
||||||
Process p = HgUtil.createPythonProcess(handler, repository, revision, path);
|
return HgUtil.getResultFromScript(BrowserResult.class,
|
||||||
BrowserResult result = null;
|
browserResultContext, RESOURCE_BROWSE,
|
||||||
InputStream resource = null;
|
handler, repository, revision, path);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|||||||
@@ -35,19 +35,29 @@ package sonia.scm.web;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import sonia.scm.SCMContext;
|
import sonia.scm.SCMContext;
|
||||||
|
import sonia.scm.repository.BrowserResult;
|
||||||
import sonia.scm.repository.HgConfig;
|
import sonia.scm.repository.HgConfig;
|
||||||
import sonia.scm.repository.HgRepositoryHandler;
|
import sonia.scm.repository.HgRepositoryHandler;
|
||||||
import sonia.scm.repository.Repository;
|
import sonia.scm.repository.Repository;
|
||||||
|
import sonia.scm.util.IOUtil;
|
||||||
import sonia.scm.util.Util;
|
import sonia.scm.util.Util;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.xml.bind.JAXBContext;
|
||||||
|
import javax.xml.bind.JAXBException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
@@ -76,6 +86,9 @@ public class HgUtil
|
|||||||
/** Field description */
|
/** Field description */
|
||||||
public static final String REVISION_TIP = "tip";
|
public static final String REVISION_TIP = "tip";
|
||||||
|
|
||||||
|
/** the logger for HgUtil */
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(HgUtil.class);
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -146,4 +159,58 @@ public class HgUtil
|
|||||||
? REVISION_TIP
|
? REVISION_TIP
|
||||||
: revision;
|
: 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