Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@

import java.util.Map;

import org.jspecify.annotations.Nullable;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.integration.handler.MessageProcessor;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.scripting.ScriptSource;
import org.springframework.util.Assert;

/**
* Base {@link MessageProcessor} for scripting implementations to extend.
*
* @param <T> the paylaod type.
* @param <T> the payload type.
*
* @author Mark Fisher
* @author Stefan Reuter
Expand All @@ -44,8 +45,10 @@ public abstract class AbstractScriptExecutingMessageProcessor<T>

private final ScriptVariableGenerator scriptVariableGenerator;

@SuppressWarnings("NullAway.Init")
private ClassLoader beanClassLoader;

@SuppressWarnings("NullAway.Init")
private BeanFactory beanFactory;

protected AbstractScriptExecutingMessageProcessor() {
Expand Down Expand Up @@ -83,8 +86,7 @@ protected BeanFactory getBeanFactory() {
* Execute the script and return the result.
*/
@Override
@Nullable
public final T processMessage(Message<?> message) {
public final @Nullable T processMessage(Message<?> message) {
ScriptSource source = getScriptSource(message);
Map<String, Object> variables = this.scriptVariableGenerator.generateScriptVariables(message);
return executeScript(source, variables);
Expand All @@ -105,7 +107,6 @@ public final T processMessage(Message<?> message) {
* @param variables The variables.
* @return The result of the execution.
*/
@Nullable
protected abstract T executeScript(ScriptSource scriptSource, Map<String, Object> variables);
protected abstract @Nullable T executeScript(ScriptSource scriptSource, Map<String, Object> variables);

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public DefaultScriptVariableGenerator(Map<String, Object> variableMap) {
}

public Map<String, Object> generateScriptVariables(Message<?> message) {
Map<String, Object> scriptVariables = new HashMap<String, Object>();
Map<String, Object> scriptVariables = new HashMap<>();
// Add Message content
if (message != null) {
scriptVariables.put("payload", message.getPayload());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Value;
import org.jspecify.annotations.Nullable;

import org.springframework.lang.Nullable;
import org.springframework.scripting.ScriptSource;
import org.springframework.util.Assert;

Expand Down Expand Up @@ -63,7 +63,7 @@ public PolyglotScriptExecutor(String language, Context.Builder contextBuilder) {
}

@Override
public Object executeScript(ScriptSource scriptSource, @Nullable Map<String, Object> variables) {
public @Nullable Object executeScript(ScriptSource scriptSource, @Nullable Map<String, Object> variables) {
try (Context context = this.contextBuilder.build()) {
if (variables != null) {
Value bindings = context.getBindings(this.language);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.io.IOException;
import java.util.concurrent.atomic.AtomicLong;

import org.jspecify.annotations.Nullable;

import org.springframework.core.io.Resource;
import org.springframework.scripting.ScriptSource;
import org.springframework.scripting.support.ResourceScriptSource;
Expand All @@ -41,6 +43,7 @@ public class RefreshableResourceScriptSource implements ScriptSource {

private final AtomicLong lastModifiedChecked = new AtomicLong(System.currentTimeMillis());

@SuppressWarnings("NullAway.Init")
private volatile String script;

public RefreshableResourceScriptSource(Resource resource, long refreshDelay) {
Expand All @@ -62,7 +65,7 @@ public String getScriptAsString() throws IOException {
return this.script;
}

public String suggestedClassName() {
public @Nullable String suggestedClassName() {
return this.source.getResource().getFilename();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@

package org.springframework.integration.scripting;

import org.jspecify.annotations.Nullable;

import org.springframework.integration.endpoint.AbstractMessageSource;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;

/**
* The {@link org.springframework.integration.core.MessageSource} strategy implementation
Expand All @@ -29,6 +33,8 @@
*/
public class ScriptExecutingMessageSource extends AbstractMessageSource<Object> {

private static final Message<byte[]> EMPTY_MESSAGE = MessageBuilder.withPayload(new byte[0]).build();

private final AbstractScriptExecutingMessageProcessor<?> scriptMessageProcessor;

public ScriptExecutingMessageSource(AbstractScriptExecutingMessageProcessor<?> scriptMessageProcessor) {
Expand All @@ -41,8 +47,8 @@ public String getComponentType() {
}

@Override
protected Object doReceive() {
return this.scriptMessageProcessor.processMessage(null);
protected @Nullable Object doReceive() {
return this.scriptMessageProcessor.processMessage(EMPTY_MESSAGE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

import java.util.Map;

import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;

import org.springframework.scripting.ScriptSource;

/**
Expand Down Expand Up @@ -46,8 +47,7 @@ public interface ScriptExecutor {
* @param scriptSource The script source.
* @return The result of the execution.
*/
@Nullable
default Object executeScript(ScriptSource scriptSource) {
default @Nullable Object executeScript(ScriptSource scriptSource) {
return executeScript(scriptSource, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.integration.scripting;

import org.jspecify.annotations.Nullable;

import org.springframework.messaging.MessagingException;

/**
Expand All @@ -30,7 +32,7 @@ public ScriptingException(String description) {
super(description);
}

public ScriptingException(String description, Throwable cause) {
public ScriptingException(@Nullable String description, Throwable cause) {
super(description, cause);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private ManagedMap<String, Object> buildVariablesMap(final Element element, fina
List<Element> variableElements) {

@SuppressWarnings("serial")
ManagedMap<String, Object> variableMap = new ManagedMap<String, Object>() {
ManagedMap<String, Object> variableMap = new ManagedMap<>() {

@Override
public Object put(String key, Object value) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* Provides classes for configuration - parsers, namespace handlers.
*/
@org.jspecify.annotations.NullMarked
package org.springframework.integration.scripting.config.jsr223;
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* Base package supporting configuration.
*/
@org.jspecify.annotations.NullMarked
package org.springframework.integration.scripting.config;
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.integration.scripting.dsl;

import org.jspecify.annotations.Nullable;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.InitializingBean;
Expand Down Expand Up @@ -47,20 +49,25 @@
class DslScriptExecutingMessageProcessor
implements MessageProcessor<Object>, InitializingBean, ApplicationContextAware, BeanClassLoaderAware {

@SuppressWarnings("NullAway.Init")
private Resource script;

private String location;
private @Nullable String location;

private String lang;
private @Nullable String lang;

private long refreshCheckDelay = -1;

@SuppressWarnings("NullAway.Init")
private ScriptVariableGenerator variableGenerator;

@SuppressWarnings("NullAway.Init")
private ApplicationContext applicationContext;

@SuppressWarnings("NullAway.Init")
private AbstractScriptExecutingMessageProcessor<?> delegate;

@SuppressWarnings("NullAway.Init")
private ClassLoader classLoader;

DslScriptExecutingMessageProcessor(Resource script) {
Expand Down Expand Up @@ -124,7 +131,7 @@ public void afterPropertiesSet() {
}

@Override
public Object processMessage(Message<?> message) {
public @Nullable Object processMessage(Message<?> message) {
return this.delegate.processMessage(message);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.util.Collections;
import java.util.Map;

import org.jspecify.annotations.Nullable;

import org.springframework.core.io.Resource;
import org.springframework.integration.core.MessageSource;
import org.springframework.integration.dsl.ComponentsRegistration;
Expand Down Expand Up @@ -125,8 +127,8 @@ protected MessageSource<?> doGet() {
}

@Override
public Map<Object, String> getComponentsToRegister() {
return Collections.singletonMap(this.delegate.getObject(), this.delegate.getId());
public Map<Object, @Nullable String> getComponentsToRegister() {
return Collections.<Object, @Nullable String>singletonMap(this.delegate.getObject(), this.delegate.getId());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.util.HashMap;
import java.util.Map;

import org.jspecify.annotations.Nullable;

import org.springframework.core.io.Resource;
import org.springframework.integration.dsl.MessageProcessorSpec;
import org.springframework.integration.handler.MessageProcessor;
Expand All @@ -38,7 +40,7 @@ public class ScriptSpec extends MessageProcessorSpec<ScriptSpec> {

private final DslScriptExecutingMessageProcessor processor;

private ScriptVariableGenerator variableGenerator;
private @Nullable ScriptVariableGenerator variableGenerator;

private final Map<String, Object> variables = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Provides Scripting Components support for Spring Integration Java DSL.
*/
@org.springframework.lang.NonNullApi
@org.jspecify.annotations.NullMarked
package org.springframework.integration.scripting.dsl;
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;

import org.springframework.integration.scripting.ScriptExecutor;
import org.springframework.integration.scripting.ScriptingException;
import org.springframework.lang.Nullable;
import org.springframework.scripting.ScriptSource;
import org.springframework.util.Assert;

Expand Down Expand Up @@ -69,8 +69,7 @@ public ScriptEngine getScriptEngine() {
}

@Override
@Nullable
public Object executeScript(ScriptSource scriptSource, Map<String, Object> variables) {
public @Nullable Object executeScript(ScriptSource scriptSource, @Nullable Map<String, Object> variables) {
try {
Object result;
String script = scriptSource.getScriptAsString();
Expand Down Expand Up @@ -108,7 +107,7 @@ public Object executeScript(ScriptSource scriptSource, Map<String, Object> varia
* @param bindings the bindings.
* @return modified result
*/
protected abstract Object postProcess(Object result, ScriptEngine scriptEngine, String script, Bindings bindings);
protected abstract Object postProcess(Object result, ScriptEngine scriptEngine, String script, @Nullable Bindings bindings);

private static String invalidLanguageMessage(String language) {
return ScriptEngineManager.class.getName() +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import javax.script.Bindings;
import javax.script.ScriptEngine;

import org.jspecify.annotations.Nullable;

/**
* Default implementation of the {@link AbstractScriptExecutor}.
* Accepts a scripting language for resolving a target {@code ScriptEngine} for
Expand All @@ -43,7 +45,7 @@ public DefaultScriptExecutor(String language) {
}

@Override
protected Object postProcess(Object result, ScriptEngine scriptEngine, String script, Bindings bindings) {
protected Object postProcess(Object result, ScriptEngine scriptEngine, String script, @Nullable Bindings bindings) {
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import java.util.Map;

import org.jspecify.annotations.Nullable;

import org.springframework.integration.scripting.AbstractScriptExecutingMessageProcessor;
import org.springframework.integration.scripting.DefaultScriptVariableGenerator;
import org.springframework.integration.scripting.ScriptExecutor;
Expand Down Expand Up @@ -88,7 +90,7 @@ protected ScriptSource getScriptSource(Message<?> message) {
}

@Override
protected Object executeScript(ScriptSource scriptSource, Map<String, Object> variables) {
protected @Nullable Object executeScript(ScriptSource scriptSource, Map<String, Object> variables) {
Assert.notNull(scriptSource, "scriptSource must not be null");
return this.scriptExecutor.executeScript(scriptSource, variables);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* Provides classes supporting JSR223 Scripting.
*/
@org.jspecify.annotations.NullMarked
package org.springframework.integration.scripting.jsr223;
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* Base package for scripting support.
*/
@org.jspecify.annotations.NullMarked
package org.springframework.integration.scripting;