use of org.springframework.batch.core.annotation.BeforeStep in project jvarkit by lindenb.
the class JdkFilterItemProcessor method beforeStep.
@BeforeStep
public void beforeStep(final StepExecution stepExecution) {
try {
InMemoryCompiler javac = new InMemoryCompiler();
String javaCode = InMemoryCompiler.getTheSourceCode(getExpression(), getScriptFile());
final Class<?> clazz;
if (CODE2CLASS.containsKey(javaCode)) {
if (LOG.isWarnEnabled())
LOG.warn("Code already compiled");
clazz = CODE2CLASS.get(javaCode);
} else {
final String className = "FunctionImpl" + rand.nextInt() + System.currentTimeMillis();
if (LOG.isInfoEnabled())
LOG.info("Compiling\n" + InMemoryCompiler.beautifyCode(javaCode));
clazz = javac.compileClass(className, javaCode.replace("__CLASS__", className));
CODE2CLASS.put(javaCode, clazz);
}
final Constructor<?> ctor = clazz.getConstructor();
final Object instance = ctor.newInstance();
if (!(instance instanceof Function)) {
throw new JvarkitException.ScriptingError("Not an instance of Function");
}
this.transformer = (Function) instance;
} catch (final Exception err) {
throw new RuntimeException(err);
}
}
Aggregations