Skip to content
Snippets Groups Projects
Commit 878cee42 authored by felmer's avatar felmer
Browse files

SSDM-3745: Disable not-used jython lib. MasterDataRegistrationScriptRunner...

SSDM-3745: Disable not-used jython lib. MasterDataRegistrationScriptRunner uses configured jython version. IJythonInterpreter extended.

SVN: 36747
parent 90f90faf
No related branches found
No related tags found
No related merge requests found
Showing with 92 additions and 6 deletions
......@@ -19,6 +19,10 @@ package ch.systemsx.cisd.common.jython;
public interface IJythonInterpreter
{
void exec(String scriptString, String scriptFile);
void exec(String scriptString);
void addToPath(String... pythonPaths);
void set(String variableName, Object object);
......
......@@ -16,6 +16,8 @@
package ch.systemsx.cisd.common.jython.evaluator;
import ch.systemsx.cisd.common.jython.IJythonInterpreterFactory;
/**
* @author Jakub Straszewski
*/
......@@ -30,6 +32,7 @@ public class Evaluator
}
private static IJythonEvaluatorFactory factory;
private static IJythonInterpreterFactory interpreterFactory;
static void setFactory(IJythonEvaluatorFactory factory)
{
......@@ -40,13 +43,34 @@ public class Evaluator
{
if (factory == null)
{
// we should make sure that the initialization hapens before first call to this method
throw new IllegalStateException(
"Jython evaluator component not initialized. Application context is not initialized properly - JythonEvaluatorSpringComponent must be initialized before jython evaluators are used.");
// we should make sure that the initialization happens before first call to this method
throw createException("evaluators");
}
return factory;
}
static void setInterpreterFactory(IJythonInterpreterFactory interpreterFactory)
{
Evaluator.interpreterFactory = interpreterFactory;
}
public static IJythonInterpreterFactory getInterpreterFactory()
{
if (interpreterFactory == null)
{
// we should make sure that the initialization happens before first call to this method
throw createException("interpreters");
}
return interpreterFactory;
}
private static IllegalStateException createException(String type)
{
return new IllegalStateException(
"Jython evaluator component not initialized. Application context is not initialized properly "
+ "- JythonEvaluatorSpringComponent must be initialized before jython " + type + " are used.");
}
public static boolean isMultiline(String expression)
{
return expression.indexOf('\n') >= 0;
......
......@@ -21,7 +21,9 @@ import org.springframework.beans.factory.BeanInitializationException;
import ch.rinn.restrictions.Private;
import ch.systemsx.cisd.common.jython.v25.Jython25EvaluatorFactory;
import ch.systemsx.cisd.common.jython.v25.Jython25InterpreterFactory;
import ch.systemsx.cisd.common.jython.v27.Jython27EvaluatorFactory;
import ch.systemsx.cisd.common.jython.v27.Jython27InterpreterFactory;
import ch.systemsx.cisd.common.logging.LogCategory;
import ch.systemsx.cisd.common.logging.LogFactory;
import ch.systemsx.cisd.common.spring.ExposablePropertyPlaceholderConfigurer;
......@@ -42,9 +44,11 @@ public class JythonEvaluatorSpringComponent
if ("2.7".equals(jythonVersion))
{
Evaluator.setFactory(new Jython27EvaluatorFactory());
Evaluator.setInterpreterFactory(new Jython27InterpreterFactory());
} else if ("2.5".equals(jythonVersion))
{
Evaluator.setFactory(new Jython25EvaluatorFactory());
Evaluator.setInterpreterFactory(new Jython25InterpreterFactory());
} else
{
String msg =
......
......@@ -115,12 +115,24 @@ public class Jython25InterpreterFactory implements IJythonInterpreterFactory
interpreter.exec(scriptString, scriptFile);
}
@Override
public void exec(String scriptString)
{
interpreter.exec(scriptString);
}
@Override
public void set(String variableName, Object object)
{
interpreter.set(variableName, object);
}
@Override
public void addToPath(String... pythonPaths)
{
interpreter.addToPath(pythonPaths);
}
@Override
public void releaseResources()
{
......
......@@ -116,12 +116,24 @@ public class Jython27InterpreterFactory implements IJythonInterpreterFactory
interpreter.exec(scriptString, scriptFile);
}
@Override
public void exec(String scriptString)
{
interpreter.exec(scriptString);
}
@Override
public void set(String variableName, Object object)
{
interpreter.set(variableName, object);
}
@Override
public void addToPath(String... pythonPaths)
{
interpreter.addToPath(pythonPaths);
}
@Override
public void releaseResources()
{
......
......@@ -18,10 +18,11 @@ if [ ! -x "$JVM" ]; then
exit 1
fi
disableJythonByProperty
LIB=$BASE/../webapps/$APPLICATION_NAME/WEB-INF/lib
$JVM \
-Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StrErrLog \
-cp $LIB/jython-2.5.2.jar:$LIB/\* \
-cp $LIB/\* \
ch.systemsx.cisd.openbis.generic.server.jython.api.v1.impl.MasterDataRegistrationScriptRunnerStandalone "$@"
......@@ -87,3 +87,27 @@ printStatus()
return 2
fi
}
enableJython()
{
version=$1
path=`ls webapps/openbis/WEB-INF/lib/jyth*$version*`
mv $path ${path%_*}
echo ${path%_*}
}
disableJythonByProperty()
{
jython25=`enableJython 2.5`
jython27=`enableJython 2.7`
required_jython_version=`awk -F'=' '/^jython-version/ {gsub(/[ \t]/, "", $2); print $2}' etc/service.properties`
echo "required jython version: $required_jython_version"
if [ "$required_jython_version" == "2.5" ]; then
mv "$jython27" "${jython27}_disabled"
echo jython 2.7 disabled
fi
if [ "$required_jython_version" == "2.7" ]; then
mv "$jython25" "${jython25}_disabled"
echo jython 2.5 disabled
fi
}
\ No newline at end of file
......@@ -5,6 +5,8 @@
source `dirname "$0"`/setup-env
checkNotRoot
bin/status.sh -q
......@@ -13,6 +15,8 @@ if [ $? -eq 0 ]; then
exit 1
fi
disableJythonByProperty
$JVM -DSTOP.PORT=$JETTY_STOP_PORT \
-DSTOP.KEY=$JETTY_STOP_KEY \
$JAVA_OPTS $JAVA_MEM_OPTS \
......
......@@ -21,9 +21,10 @@ import java.util.List;
import ch.systemsx.cisd.base.exceptions.CheckedExceptionTunnel;
import ch.systemsx.cisd.common.filesystem.FileUtilities;
import ch.systemsx.cisd.common.jython.IJythonInterpreter;
import ch.systemsx.cisd.common.jython.JythonScriptSplitter;
import ch.systemsx.cisd.common.jython.JythonUtils;
import ch.systemsx.cisd.common.jython.PythonInterpreter;
import ch.systemsx.cisd.common.jython.evaluator.Evaluator;
/**
* A class for running python scripts that register master data.
......@@ -56,7 +57,7 @@ public class MasterDataRegistrationScriptRunner implements IMasterDataScriptRegi
MasterDataRegistrationService service = new MasterDataRegistrationService(commonServer);
// Configure the evaluator
PythonInterpreter interpreter = PythonInterpreter.createIsolatedPythonInterpreter();
IJythonInterpreter interpreter = Evaluator.getInterpreterFactory().createInterpreter();
interpreter.addToPath(jythonPath);
interpreter.set(SERVICE_VARIABLE_NAME, service);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment