GH-7: Add checkstyle and javaformat plugins

Fixes: #7

* Run `./gradlew format`
* Updates from PR review suggestions
This commit is contained in:
Chris Bono
2023-12-29 21:08:58 -06:00
committed by Artem Bilan
parent 84e732da08
commit 836708f0f2
357 changed files with 4344 additions and 4519 deletions

View File

@@ -21,4 +21,5 @@ import java.util.Collection;
import org.springframework.integration.handler.MessageProcessor;
public interface CommandLineArgumentsMessageMapper extends MessageProcessor<Collection<String>> {
}

View File

@@ -23,7 +23,8 @@ import java.util.Map;
import org.springframework.util.StringUtils;
/**
* Parses a comma delimited list of key value pairs in which the values can contain commas as well.
* Parses a comma delimited list of key value pairs in which the values can contain commas
* as well.
*
* @author Chris Schaeffer
* @author David Turanski
@@ -63,4 +64,5 @@ abstract class KeyValueListParser {
properties.put(pair.substring(0, firstEquals).trim(), pair.substring(firstEquals + 1).trim());
}
}
}

View File

@@ -25,6 +25,7 @@ import java.util.Map;
import com.fasterxml.jackson.annotation.JsonProperty;
public class TaskLaunchRequest {
@JsonProperty("args")
private List<String> commandlineArguments = new ArrayList<>();
@@ -62,4 +63,5 @@ public class TaskLaunchRequest {
this.commandlineArguments.addAll(args);
return this;
}
}

View File

@@ -36,13 +36,17 @@ import org.springframework.messaging.Message;
import org.springframework.util.StringUtils;
/**
* Configuration for a {@link TaskLaunchRequestFunction}, provided as a common function that can be composed with other Suppliers or
* Functions to transform any {@link Message} to a {@link TaskLaunchRequest} which may be used as input to the {@code TaskLauncherFunction} to launch a task.
* Configuration for a {@link TaskLaunchRequestFunction}, provided as a common function
* that can be composed with other Suppliers or Functions to transform any {@link Message}
* to a {@link TaskLaunchRequest} which may be used as input to the
* {@code TaskLauncherFunction} to launch a task.
*
* Command line arguments used by the task, as well as the task name itself may be statically configured or extracted from
* the message contents, using SpEL. See {@link TaskLaunchRequestFunctionProperties} for details.
* Command line arguments used by the task, as well as the task name itself may be
* statically configured or extracted from the message contents, using SpEL. See
* {@link TaskLaunchRequestFunctionProperties} for details.
*
* It is also possible to provide your own implementations of {@link CommandLineArgumentsMessageMapper} and {@link TaskNameMessageMapper}.
* It is also possible to provide your own implementations of
* {@link CommandLineArgumentsMessageMapper} and {@link TaskNameMessageMapper}.
*
* @author David Turanski
**/
@@ -58,9 +62,8 @@ public class TaskLaunchRequestFunctionConfiguration {
/**
* A {@link java.util.function.Function} to transform a {@link Message} payload to a
* {@link TaskLaunchRequest}.
*
* @param taskLaunchRequestMessageProcessor a {@link TaskLaunchRequestMessageProcessor}.
*
* @param taskLaunchRequestMessageProcessor a
* {@link TaskLaunchRequestMessageProcessor}.
* @return a {@code TaskLaunchRequest} Message.
*/
@Bean(name = TASK_LAUNCH_REQUEST_FUNCTION_NAME)
@@ -78,10 +81,8 @@ public class TaskLaunchRequestFunctionConfiguration {
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
@Bean
public TaskLaunchRequestMessageProcessor taskLaunchRequestMessageProcessor(
TaskLaunchRequestSupplier taskLaunchRequestInitializer,
TaskLaunchRequestFunctionProperties properties,
EvaluationContext evaluationContext,
@Nullable TaskNameMessageMapper taskNameMessageMapper,
TaskLaunchRequestSupplier taskLaunchRequestInitializer, TaskLaunchRequestFunctionProperties properties,
EvaluationContext evaluationContext, @Nullable TaskNameMessageMapper taskNameMessageMapper,
@Nullable CommandLineArgumentsMessageMapper commandLineArgumentsMessageMapper) {
if (taskNameMessageMapper == null) {
@@ -92,8 +93,7 @@ public class TaskLaunchRequestFunctionConfiguration {
commandLineArgumentsMessageMapper = commandLineArgumentsMessageMapper(properties, evaluationContext);
}
return new TaskLaunchRequestMessageProcessor(taskLaunchRequestInitializer,
taskNameMessageMapper,
return new TaskLaunchRequestMessageProcessor(taskLaunchRequestInitializer, taskNameMessageMapper,
commandLineArgumentsMessageMapper);
}
@@ -103,11 +103,11 @@ public class TaskLaunchRequestFunctionConfiguration {
}
private TaskNameMessageMapper taskNameMessageMapper(TaskLaunchRequestFunctionProperties taskLaunchRequestProperties,
EvaluationContext evaluationContext) {
EvaluationContext evaluationContext) {
if (StringUtils.hasText(taskLaunchRequestProperties.getTaskNameExpression())) {
SpelExpressionParser expressionParser = new SpelExpressionParser();
Expression taskNameExpression = expressionParser
.parseExpression(taskLaunchRequestProperties.getTaskNameExpression());
.parseExpression(taskLaunchRequestProperties.getTaskNameExpression());
return new ExpressionEvaluatingTaskNameMessageMapper(taskNameExpression, evaluationContext);
}
@@ -122,23 +122,23 @@ public class TaskLaunchRequestFunctionConfiguration {
}
private static class TaskLaunchRequestPropertiesInitializer extends TaskLaunchRequestSupplier {
TaskLaunchRequestPropertiesInitializer(
TaskLaunchRequestFunctionProperties taskLaunchRequestProperties) {
this.commandLineArgumentSupplier(
() -> new ArrayList<>(taskLaunchRequestProperties.getArgs()));
TaskLaunchRequestPropertiesInitializer(TaskLaunchRequestFunctionProperties taskLaunchRequestProperties) {
this.deploymentPropertiesSupplier(
() -> KeyValueListParser.parseCommaDelimitedKeyValuePairs(
taskLaunchRequestProperties.getDeploymentProperties()));
this.commandLineArgumentSupplier(() -> new ArrayList<>(taskLaunchRequestProperties.getArgs()));
this.deploymentPropertiesSupplier(() -> KeyValueListParser
.parseCommaDelimitedKeyValuePairs(taskLaunchRequestProperties.getDeploymentProperties()));
this.taskNameSupplier(() -> taskLaunchRequestProperties.getTaskName());
}
}
private static class ExpressionEvaluatingTaskNameMessageMapper implements TaskNameMessageMapper {
private final Expression expression;
private final EvaluationContext evaluationContext;
ExpressionEvaluatingTaskNameMessageMapper(Expression expression, EvaluationContext evaluationContext) {
@@ -150,9 +150,11 @@ public class TaskLaunchRequestFunctionConfiguration {
public String processMessage(Message<?> message) {
return expression.getValue(evaluationContext, message).toString();
}
}
private static class ExpressionEvaluatingCommandLineArgsMapper implements CommandLineArgumentsMessageMapper {
private final Map<String, Expression> argExpressionsMap;
private final EvaluationContext evaluationContext;
@@ -163,8 +165,8 @@ public class TaskLaunchRequestFunctionConfiguration {
if (StringUtils.hasText(argExpressions)) {
SpelExpressionParser expressionParser = new SpelExpressionParser();
KeyValueListParser.parseCommaDelimitedKeyValuePairs(argExpressions).forEach(
(k, v) -> argExpressionsMap.put(k, expressionParser.parseExpression(v)));
KeyValueListParser.parseCommaDelimitedKeyValuePairs(argExpressions)
.forEach((k, v) -> argExpressionsMap.put(k, expressionParser.parseExpression(v)));
}
}
@@ -176,9 +178,10 @@ public class TaskLaunchRequestFunctionConfiguration {
private Collection<String> evaluateArgExpressions(Message<?> message) {
List<String> results = new LinkedList<>();
this.argExpressionsMap.forEach((k, expression) -> results
.add(String.format("%s=%s", k, expression.getValue(this.evaluationContext, message))));
.add(String.format("%s=%s", k, expression.getValue(this.evaluationContext, message))));
return results;
}
}
}

View File

@@ -57,9 +57,9 @@ public class TaskLaunchRequestFunctionProperties {
*/
private String taskName;
/**
* A SpEL expression to extract the task name from each Message, using the Message as the evaluation context.
* A SpEL expression to extract the task name from each Message, using the Message as
* the evaluation context.
*/
private String taskNameExpression;

View File

@@ -57,7 +57,7 @@ class TaskLaunchRequestMessageProcessor implements MessagePostProcessor {
taskLaunchRequest.addCommmandLineArguments(commandLineArgumentsMessageMapper.processMessage(message));
MessageBuilder<TaskLaunchRequest> builder = MessageBuilder.withPayload(taskLaunchRequest)
.copyHeaders(message.getHeaders());
.copyHeaders(message.getHeaders());
return adjustHeaders(builder).build();
}
@@ -65,4 +65,5 @@ class TaskLaunchRequestMessageProcessor implements MessagePostProcessor {
builder.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON);
return builder;
}
}

View File

@@ -64,4 +64,5 @@ class TaskLaunchRequestSupplier implements Supplier<TaskLaunchRequest> {
return taskLaunchRequest;
}
}

View File

@@ -20,4 +20,5 @@ import org.springframework.integration.handler.MessageProcessor;
@FunctionalInterface
public interface TaskNameMessageMapper extends MessageProcessor<String> {
}

View File

@@ -31,8 +31,8 @@ public class KeyValueListParserTests {
@Test
public void testParseSimpleDeploymentProperty() {
Map<String, String> deploymentProperties = KeyValueListParser.parseCommaDelimitedKeyValuePairs(
"app.sftp.param=value");
Map<String, String> deploymentProperties = KeyValueListParser
.parseCommaDelimitedKeyValuePairs("app.sftp.param=value");
assertTrue("Invalid number of deployment properties: " + deploymentProperties.size(),
deploymentProperties.size() == 1);
assertTrue("Expected deployment key not found", deploymentProperties.containsKey("app.sftp.param"));
@@ -41,8 +41,8 @@ public class KeyValueListParserTests {
@Test
public void testParseSimpleDeploymentPropertyMultipleValues() {
Map<String, String> deploymentProperties = KeyValueListParser.parseCommaDelimitedKeyValuePairs(
"app.sftp.param=value1,value2,value3");
Map<String, String> deploymentProperties = KeyValueListParser
.parseCommaDelimitedKeyValuePairs("app.sftp.param=value1,value2,value3");
assertTrue("Invalid number of deployment properties: " + deploymentProperties.size(),
deploymentProperties.size() == 1);
@@ -55,8 +55,7 @@ public class KeyValueListParserTests {
Map<String, String> argExpressions = KeyValueListParser.parseCommaDelimitedKeyValuePairs(
"arg1=payload.substr(0,2),arg2=headers['foo'],arg3=headers['bar']==false");
assertTrue("Invalid number of deployment properties: " + argExpressions.size(),
argExpressions.size() == 3);
assertTrue("Invalid number of deployment properties: " + argExpressions.size(), argExpressions.size() == 3);
assertTrue("Expected deployment key not found", argExpressions.containsKey("arg1"));
assertEquals("Invalid deployment value", "payload.substr(0,2)", argExpressions.get("arg1"));
@@ -69,8 +68,8 @@ public class KeyValueListParserTests {
@Test
public void testParseMultipleDeploymentPropertiesSingleValue() {
Map<String, String> deploymentProperties = KeyValueListParser.parseCommaDelimitedKeyValuePairs(
"app.sftp.param=value1,app.sftp.other.param=value2");
Map<String, String> deploymentProperties = KeyValueListParser
.parseCommaDelimitedKeyValuePairs("app.sftp.param=value1,app.sftp.other.param=value2");
assertTrue("Invalid number of deployment properties: " + deploymentProperties.size(),
deploymentProperties.size() == 2);
@@ -84,8 +83,8 @@ public class KeyValueListParserTests {
public void testParseMultipleDeploymentPropertiesMultipleValues() {
TaskLaunchRequestFunctionProperties taskLaunchRequestProperties = new TaskLaunchRequestFunctionProperties();
Map<String, String> deploymentProperties = KeyValueListParser.parseCommaDelimitedKeyValuePairs(
"app.sftp.param=value1,value2,app.sftp.other.param=other1,other2");
Map<String, String> deploymentProperties = KeyValueListParser
.parseCommaDelimitedKeyValuePairs("app.sftp.param=value1,value2,app.sftp.other.param=other1,other2");
assertTrue("Invalid number of deployment properties: " + deploymentProperties.size(),
deploymentProperties.size() == 2);
@@ -94,4 +93,5 @@ public class KeyValueListParserTests {
assertTrue("Expected deployment key not found", deploymentProperties.containsKey("app.sftp.other.param"));
assertEquals("Invalid deployment value", "other1,other2", deploymentProperties.get("app.sftp.other.param"));
}
}

View File

@@ -45,18 +45,17 @@ public class TaskLaunchRequestFunctionApplicationTests {
@BeforeEach
public void setUp() {
springApplicationBuilder = new SpringApplicationBuilder(TaskLaunchRequestFunctionTestApplication.class)
.web(WebApplicationType.NONE);
.web(WebApplicationType.NONE);
}
@Test
@DirtiesContext
public void simpleDataflowTaskLaunchRequest() throws IOException {
ApplicationContext context = springApplicationBuilder.properties(
"spring.jmx.enabled=false",
"spring.cloud.function.definition=taskLaunchRequestFunction",
"task.launch.request.task-name=foo")
.run();
ApplicationContext context = springApplicationBuilder
.properties("spring.jmx.enabled=false", "spring.cloud.function.definition=taskLaunchRequestFunction",
"task.launch.request.task-name=foo")
.run();
TaskLaunchRequest taskLaunchRequest = verifyAndreceiveTaskLaunchRequest(context);
@@ -69,16 +68,15 @@ public class TaskLaunchRequestFunctionApplicationTests {
@DirtiesContext
public void dataflowTaskLaunchRequestWithArgsAndDeploymentProperties() throws IOException {
ApplicationContext context = springApplicationBuilder.properties(
"spring.jmx.enabled=false", "spring.cloud.function.definition=taskLaunchRequestFunction",
"task.launch.request.task-name=foo", "task.launch.request.args=foo=bar,baz=boo",
"task.launch.request.deploymentProperties=count=3")
.run();
ApplicationContext context = springApplicationBuilder
.properties("spring.jmx.enabled=false", "spring.cloud.function.definition=taskLaunchRequestFunction",
"task.launch.request.task-name=foo", "task.launch.request.args=foo=bar,baz=boo",
"task.launch.request.deploymentProperties=count=3")
.run();
TaskLaunchRequest taskLaunchRequest = verifyAndreceiveTaskLaunchRequest(context);
assertThat(taskLaunchRequest.getTaskName()).isEqualTo("foo");
assertThat(taskLaunchRequest.getCommandlineArguments()).containsExactlyInAnyOrder("foo=bar",
"baz=boo");
assertThat(taskLaunchRequest.getCommandlineArguments()).containsExactlyInAnyOrder("foo=bar", "baz=boo");
assertThat(taskLaunchRequest.getDeploymentProperties()).containsOnly(entry("count", "3"));
}
@@ -86,10 +84,10 @@ public class TaskLaunchRequestFunctionApplicationTests {
@DirtiesContext
public void taskLaunchRequestWithCommandLineArgsMessageMapper() throws IOException {
ApplicationContext context = springApplicationBuilder.properties(
"spring.jmx.enabled=false", "spring.cloud.function.definition=taskLaunchRequestFunction",
"task.launch.request.task-name=foo", "enhanceTLRArgs=true")
.run();
ApplicationContext context = springApplicationBuilder
.properties("spring.jmx.enabled=false", "spring.cloud.function.definition=taskLaunchRequestFunction",
"task.launch.request.task-name=foo", "enhanceTLRArgs=true")
.run();
TaskLaunchRequest taskLaunchRequest = verifyAndreceiveTaskLaunchRequest(context);
@@ -102,12 +100,11 @@ public class TaskLaunchRequestFunctionApplicationTests {
@Test
@DirtiesContext
public void taskLaunchRequestWithArgExpressions() throws IOException {
ApplicationContext context = springApplicationBuilder.properties(
"spring.jmx.enabled=false",
"spring.cloud.function.definition=taskLaunchRequestFunction",
"task.launch.request.task-name=foo",
"task.launch.request.arg-expressions=foo=payload.toUpperCase(),bar=payload.substring(0,2)")
.run();
ApplicationContext context = springApplicationBuilder
.properties("spring.jmx.enabled=false", "spring.cloud.function.definition=taskLaunchRequestFunction",
"task.launch.request.task-name=foo",
"task.launch.request.arg-expressions=foo=payload.toUpperCase(),bar=payload.substring(0,2)")
.run();
Message<String> message = MessageBuilder.withPayload("hello").build();
@@ -123,11 +120,10 @@ public class TaskLaunchRequestFunctionApplicationTests {
@Test
@DirtiesContext
public void taskLaunchRequestWithIntPayload() throws IOException {
ApplicationContext context = springApplicationBuilder.properties(
"spring.jmx.enabled=false", "spring.cloud.function.definition=taskLaunchRequestFunction",
"task.launch.request.task-name=foo",
"task.launch.request.arg-expressions=i=payload")
.run();
ApplicationContext context = springApplicationBuilder
.properties("spring.jmx.enabled=false", "spring.cloud.function.definition=taskLaunchRequestFunction",
"task.launch.request.task-name=foo", "task.launch.request.arg-expressions=i=payload")
.run();
TaskLaunchRequestFunction taskLaunchRequestFunction = context.getBean(TaskLaunchRequestFunction.class);
@@ -144,10 +140,10 @@ public class TaskLaunchRequestFunctionApplicationTests {
@Test
@DirtiesContext
public void taskNameExpression() throws IOException {
ApplicationContext context = springApplicationBuilder.properties(
"spring.jmx.enabled=false", "spring.cloud.function.definition=taskLaunchRequestFunction",
"task.launch.request.task-name-expression=payload+'_task'")
.run();
ApplicationContext context = springApplicationBuilder
.properties("spring.jmx.enabled=false", "spring.cloud.function.definition=taskLaunchRequestFunction",
"task.launch.request.task-name-expression=payload+'_task'")
.run();
TaskLaunchRequestFunction taskLaunchRequestFunction = context.getBean(TaskLaunchRequestFunction.class);
@@ -163,10 +159,10 @@ public class TaskLaunchRequestFunctionApplicationTests {
@Test
@DirtiesContext
public void customTaskNameExtractor() throws IOException {
ApplicationContext context = springApplicationBuilder.properties(
"spring.jmx.enabled=false", "spring.cloud.function.definition=taskLaunchRequestFunction",
"customTaskNameExtractor=true")
.run();
ApplicationContext context = springApplicationBuilder
.properties("spring.jmx.enabled=false", "spring.cloud.function.definition=taskLaunchRequestFunction",
"customTaskNameExtractor=true")
.run();
TaskLaunchRequestFunction taskLaunchRequestFunction = context.getBean(TaskLaunchRequestFunction.class);
Message<String> message = MessageBuilder.withPayload("foo").build();
@@ -184,11 +180,10 @@ public class TaskLaunchRequestFunctionApplicationTests {
assertThat(request.getTaskName()).isEqualTo("defaultTask");
}
private TaskLaunchRequest verifyAndreceiveTaskLaunchRequest(ApplicationContext context)
throws IOException {
private TaskLaunchRequest verifyAndreceiveTaskLaunchRequest(ApplicationContext context) throws IOException {
TaskLaunchRequestFunction taskLaunchRequestFunction = context.getBean(TaskLaunchRequestFunction.class);
Message<TaskLaunchRequest> message = taskLaunchRequestFunction
.apply(MessageBuilder.withPayload(new byte[] {}).build());
.apply(MessageBuilder.withPayload(new byte[] {}).build());
assertThat(message).isNotNull();
return message.getPayload();
}
@@ -207,5 +202,7 @@ public class TaskLaunchRequestFunctionApplicationTests {
CommandLineArgumentsMessageMapper commandLineArgumentsProvider() {
return message -> Collections.singletonList("runtimeArg");
}
}
}

View File

@@ -73,4 +73,5 @@ public class TaskLaunchRequestFunctionPropertiesTests {
static class Conf {
}
}