mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 00:15:44 +01:00
implement cgi api improvements
This commit is contained in:
@@ -199,13 +199,13 @@ public abstract class AbstractCGIExecutor implements CGIExecutor
|
|||||||
protected EnvList environment;
|
protected EnvList environment;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
protected boolean ignoreExitCode;
|
protected boolean ignoreExitCode = false;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
protected String interpreter;
|
protected String interpreter;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
protected boolean passShellEnvironment;
|
protected boolean passShellEnvironment = false;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
protected File workDirectory;
|
protected File workDirectory;
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ import sonia.scm.SCMContext;
|
|||||||
import sonia.scm.config.ScmConfiguration;
|
import sonia.scm.config.ScmConfiguration;
|
||||||
import sonia.scm.util.HttpUtil;
|
import sonia.scm.util.HttpUtil;
|
||||||
import sonia.scm.util.IOUtil;
|
import sonia.scm.util.IOUtil;
|
||||||
|
import sonia.scm.util.SystemUtil;
|
||||||
import sonia.scm.util.Util;
|
import sonia.scm.util.Util;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
@@ -54,6 +55,7 @@ import java.io.InputStreamReader;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.ServletInputStream;
|
import javax.servlet.ServletInputStream;
|
||||||
@@ -74,6 +76,9 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
|
|||||||
/** Field description */
|
/** Field description */
|
||||||
public static final int DEFAULT_BUFFER_SIZE = 16264;
|
public static final int DEFAULT_BUFFER_SIZE = 16264;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
public static final String SYSTEM_ROOT_WINDOWS = "C:\\WINDOWS";
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private static final String SERVER_SOFTWARE_PREFIX = "scm-manager/";
|
private static final String SERVER_SOFTWARE_PREFIX = "scm-manager/";
|
||||||
|
|
||||||
@@ -166,8 +171,7 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
p = Runtime.getRuntime().exec(execCmd, environment.getEnvArray(),
|
p = Runtime.getRuntime().exec(execCmd, environment.getEnvArray(),
|
||||||
workDirectory);
|
workDirectory);
|
||||||
|
|
||||||
execute(p);
|
execute(p);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
@@ -179,6 +183,25 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param env
|
||||||
|
*/
|
||||||
|
private void apendOsEnvironment(EnvList env)
|
||||||
|
{
|
||||||
|
Map<String, String> osEnv = System.getenv();
|
||||||
|
|
||||||
|
if (Util.isNotEmpty(osEnv))
|
||||||
|
{
|
||||||
|
for (Map.Entry<String, String> e : osEnv.entrySet())
|
||||||
|
{
|
||||||
|
env.set(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -194,8 +217,13 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
|
|||||||
String scriptPath = context.getRealPath(scriptName);
|
String scriptPath = context.getRealPath(scriptName);
|
||||||
String pathTranslated = request.getPathTranslated();
|
String pathTranslated = request.getPathTranslated();
|
||||||
int len = request.getContentLength();
|
int len = request.getContentLength();
|
||||||
|
|
||||||
EnvList env = new EnvList();
|
EnvList env = new EnvList();
|
||||||
|
|
||||||
|
if (passShellEnvironment)
|
||||||
|
{
|
||||||
|
apendOsEnvironment(env);
|
||||||
|
}
|
||||||
|
|
||||||
env.set(ENV_AUTH_TYPE, request.getAuthType());
|
env.set(ENV_AUTH_TYPE, request.getAuthType());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -204,9 +232,8 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
|
|||||||
* Servlet API spec.
|
* Servlet API spec.
|
||||||
*
|
*
|
||||||
* see org.apache.catalina.servlets.CGIServlet
|
* see org.apache.catalina.servlets.CGIServlet
|
||||||
**/
|
*/
|
||||||
|
if (len <= 0)
|
||||||
if ( len <= 0 )
|
|
||||||
{
|
{
|
||||||
env.set(ENV_CONTENT_LENGTH, "");
|
env.set(ENV_CONTENT_LENGTH, "");
|
||||||
}
|
}
|
||||||
@@ -255,6 +282,11 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
|
|||||||
? ENV_HTTPS_VALUE_ON
|
? ENV_HTTPS_VALUE_ON
|
||||||
: ENV_HTTPS_VALUE_OFF));
|
: ENV_HTTPS_VALUE_OFF));
|
||||||
|
|
||||||
|
if (SystemUtil.isWindows())
|
||||||
|
{
|
||||||
|
env.set(ENV_SYSTEM_ROOT, SYSTEM_ROOT_WINDOWS);
|
||||||
|
}
|
||||||
|
|
||||||
return env;
|
return env;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,20 +319,6 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processErrorStreamAsync( final InputStream errorStream )
|
|
||||||
{
|
|
||||||
new Thread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
processErrorStream(errorStream);
|
|
||||||
} catch (IOException ex) {
|
|
||||||
logger.error( "could not read errorstream", ex );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -413,6 +431,31 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param errorStream
|
||||||
|
*/
|
||||||
|
private void processErrorStreamAsync(final InputStream errorStream)
|
||||||
|
{
|
||||||
|
new Thread(new Runnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
processErrorStream(errorStream);
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
logger.error("could not read errorstream", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -481,7 +524,7 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
|
|||||||
{
|
{
|
||||||
int exitCode = process.waitFor();
|
int exitCode = process.waitFor();
|
||||||
|
|
||||||
if (exitCode != 0)
|
if ((exitCode != 0) &&!ignoreExitCode)
|
||||||
{
|
{
|
||||||
logger.warn("process ends with exit code {}", exitCode);
|
logger.warn("process ends with exit code {}", exitCode);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user