Add Nullability support into Java DSL

This commit is contained in:
abilan
2023-04-14 14:16:36 -04:00
parent 053cc00484
commit d5181bf0d7
105 changed files with 514 additions and 366 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,6 +29,7 @@ import org.springframework.integration.JavaUtils;
import org.springframework.integration.file.tail.ApacheCommonsFileTailingMessageProducer;
import org.springframework.integration.file.tail.FileTailingMessageProducerSupport;
import org.springframework.integration.file.tail.OSDelegatingFileTailingMessageProducer;
import org.springframework.lang.Nullable;
import org.springframework.messaging.MessageChannel;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.util.Assert;
@@ -137,7 +138,7 @@ public class FileTailInboundChannelAdapterFactoryBean extends AbstractFactoryBea
}
@Override
public void setBeanName(String name) {
public void setBeanName(@Nullable String name) {
this.beanName = name;
}

View File

@@ -36,6 +36,7 @@ import org.springframework.integration.file.config.FileListFilterFactoryBean;
import org.springframework.integration.file.filters.ExpressionFileListFilter;
import org.springframework.integration.file.filters.FileListFilter;
import org.springframework.integration.file.locking.NioFileLocker;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -51,10 +52,13 @@ public class FileInboundChannelAdapterSpec
protected final FileListFilterFactoryBean fileListFilterFactoryBean = new FileListFilterFactoryBean(); // NOSONAR
@Nullable
private FileLocker locker;
@Nullable
private ExpressionFileListFilter<File> expressionFileListFilter;
@Nullable
private DirectoryScanner scanner;
private boolean filtersSet;
@@ -63,7 +67,7 @@ public class FileInboundChannelAdapterSpec
this.target = new FileReadingMessageSource();
}
protected FileInboundChannelAdapterSpec(Comparator<File> receptionOrderComparator) {
protected FileInboundChannelAdapterSpec(@Nullable Comparator<File> receptionOrderComparator) {
this.target = new FileReadingMessageSource(receptionOrderComparator);
}
@@ -314,7 +318,7 @@ public class FileInboundChannelAdapterSpec
return Collections.singletonMap(this.expressionFileListFilter, null);
}
else {
return null;
return Collections.emptyMap();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2020 the original author or authors.
* Copyright 2016-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@ import java.nio.charset.Charset;
import org.springframework.integration.dsl.MessageHandlerSpec;
import org.springframework.integration.file.splitter.FileSplitter;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
/**
@@ -39,10 +40,12 @@ public class FileSplitterSpec extends MessageHandlerSpec<FileSplitterSpec, FileS
private boolean markersJson;
@Nullable
private Charset charset;
private boolean applySequence;
@Nullable
private String firstLineHeaderName;
protected FileSplitterSpec() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2019 the original author or authors.
* Copyright 2016-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@ import org.springframework.integration.file.remote.RemoteFileTemplate;
import org.springframework.integration.file.remote.handler.FileTransferringMessageHandler;
import org.springframework.integration.file.remote.session.SessionFactory;
import org.springframework.integration.file.support.FileExistsMode;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.util.Assert;
@@ -49,8 +50,10 @@ public abstract class FileTransferringMessageHandlerSpec<F, S extends FileTransf
extends MessageHandlerSpec<S, FileTransferringMessageHandler<F>>
implements ComponentsRegistration {
@Nullable
private FileNameGenerator fileNameGenerator;
@Nullable
private DefaultFileNameGenerator defaultFileNameGenerator;
// TODO: should be refactored using generics in next release (breaking change), see PR-3080.
@@ -238,7 +241,7 @@ public abstract class FileTransferringMessageHandlerSpec<F, S extends FileTransf
if (this.defaultFileNameGenerator != null) {
return Collections.singletonMap(this.defaultFileNameGenerator, null);
}
return null;
return Collections.emptyMap();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 the original author or authors.
* Copyright 2016-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,6 +29,7 @@ import org.springframework.integration.file.DefaultFileNameGenerator;
import org.springframework.integration.file.FileNameGenerator;
import org.springframework.integration.file.FileWritingMessageHandler;
import org.springframework.integration.file.support.FileExistsMode;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.util.Assert;
@@ -45,8 +46,10 @@ public class FileWritingMessageHandlerSpec
extends MessageHandlerSpec<FileWritingMessageHandlerSpec, FileWritingMessageHandler>
implements ComponentsRegistration {
@Nullable
private FileNameGenerator fileNameGenerator;
@Nullable
private DefaultFileNameGenerator defaultFileNameGenerator;
protected FileWritingMessageHandlerSpec(File destinationDirectory) {
@@ -264,7 +267,7 @@ public class FileWritingMessageHandlerSpec
if (this.defaultFileNameGenerator != null) {
return Collections.singletonMap(this.defaultFileNameGenerator, null);
}
return null;
return Collections.emptyMap();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2019 the original author or authors.
* Copyright 2016-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@ import java.util.function.Function;
import org.springframework.expression.Expression;
import org.springframework.integration.file.transformer.FileToByteArrayTransformer;
import org.springframework.integration.file.transformer.FileToStringTransformer;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
/**
@@ -50,7 +51,8 @@ public abstract class Files {
* @return the {@link FileInboundChannelAdapterSpec} instance.
*/
public static FileInboundChannelAdapterSpec inboundAdapter(File directory,
Comparator<File> receptionOrderComparator) {
@Nullable Comparator<File> receptionOrderComparator) {
return new FileInboundChannelAdapterSpec(receptionOrderComparator).directory(directory);
}
@@ -197,7 +199,7 @@ public abstract class Files {
* @param deleteFiles true to delete the file.
* @return the {@link FileToStringTransformer}.
*/
public static FileToStringTransformer toStringTransformer(String charset, boolean deleteFiles) {
public static FileToStringTransformer toStringTransformer(@Nullable String charset, boolean deleteFiles) {
FileToStringTransformer transformer = new FileToStringTransformer();
if (charset != null) {
transformer.setCharset(charset);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2022 the original author or authors.
* Copyright 2016-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@ import org.springframework.integration.file.filters.FileListFilter;
import org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer;
import org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizingMessageSource;
import org.springframework.integration.metadata.MetadataStore;
import org.springframework.lang.Nullable;
/**
* A {@link MessageSourceSpec} for an {@link AbstractInboundFileSynchronizingMessageSource}.
@@ -52,6 +53,7 @@ public abstract class RemoteFileInboundChannelAdapterSpec<F, S extends RemoteFil
protected final AbstractInboundFileSynchronizer<F> synchronizer; // NOSONAR final
@Nullable
private ExpressionFileListFilter<F> expressionFileListFilter;
protected RemoteFileInboundChannelAdapterSpec(AbstractInboundFileSynchronizer<F> synchronizer) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2020 the original author or authors.
* Copyright 2016-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,6 +33,7 @@ import org.springframework.integration.file.filters.RegexPatternFileListFilter;
import org.springframework.integration.file.filters.SimplePatternFileListFilter;
import org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway;
import org.springframework.integration.file.support.FileExistsMode;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
/**
@@ -50,12 +51,16 @@ public abstract class RemoteFileOutboundGatewaySpec<F, S extends RemoteFileOutbo
extends MessageHandlerSpec<S, AbstractRemoteFileOutboundGateway<F>>
implements ComponentsRegistration {
@Nullable
private CompositeFileListFilter<F> filter;
@Nullable
private ExpressionFileListFilter<F> expressionFileListFilter;
@Nullable
private ExpressionFileListFilter<File> mputExpressionFileListFilter;
@Nullable
private CompositeFileListFilter<File> mputFilter;
protected RemoteFileOutboundGatewaySpec(AbstractRemoteFileOutboundGateway<F> outboundGateway) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2019 the original author or authors.
* Copyright 2016-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@ import org.springframework.integration.expression.FunctionExpression;
import org.springframework.integration.file.filters.ExpressionFileListFilter;
import org.springframework.integration.file.filters.FileListFilter;
import org.springframework.integration.file.remote.AbstractRemoteFileStreamingMessageSource;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
/**
@@ -46,6 +47,7 @@ public abstract class RemoteFileStreamingInboundChannelAdapterSpec<F,
extends MessageSourceSpec<S, MS>
implements ComponentsRegistration {
@Nullable
private ExpressionFileListFilter<F> expressionFileListFilter;
/**
@@ -143,7 +145,7 @@ public abstract class RemoteFileStreamingInboundChannelAdapterSpec<F,
return Collections.singletonMap(this.expressionFileListFilter, null);
}
else {
return null;
return Collections.emptyMap();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2022 the original author or authors.
* Copyright 2016-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@ import org.springframework.core.task.TaskExecutor;
import org.springframework.integration.dsl.MessageProducerSpec;
import org.springframework.integration.file.config.FileTailInboundChannelAdapterFactoryBean;
import org.springframework.integration.file.tail.FileTailingMessageProducerSupport;
import org.springframework.lang.Nullable;
import org.springframework.messaging.MessageChannel;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.util.Assert;
@@ -39,8 +40,10 @@ public class TailAdapterSpec extends MessageProducerSpec<TailAdapterSpec, FileTa
private final FileTailInboundChannelAdapterFactoryBean factoryBean = new FileTailInboundChannelAdapterFactoryBean();
@Nullable
private MessageChannel outputChannel;
@Nullable
private MessageChannel errorChannel;
protected TailAdapterSpec() {
@@ -155,7 +158,7 @@ public class TailAdapterSpec extends MessageProducerSpec<TailAdapterSpec, FileTa
}
@Override
public TailAdapterSpec id(String id) {
public TailAdapterSpec id(@Nullable String id) {
this.factoryBean.setBeanName(id);
return _this();
}
@@ -186,14 +189,16 @@ public class TailAdapterSpec extends MessageProducerSpec<TailAdapterSpec, FileTa
@Override
protected FileTailingMessageProducerSupport doGet() {
FileTailingMessageProducerSupport tailingMessageProducerSupport = null;
FileTailingMessageProducerSupport tailingMessageProducerSupport;
try {
this.factoryBean.afterPropertiesSet();
tailingMessageProducerSupport = this.factoryBean.getObject();
}
catch (Exception e) {
throw new IllegalStateException(e);
catch (Exception ex) {
throw new IllegalStateException(ex);
}
Assert.notNull(tailingMessageProducerSupport,
"The 'FileTailInboundChannelAdapterFactoryBean' must not produce null");
if (this.errorChannel != null) {
tailingMessageProducerSupport.setErrorChannel(this.errorChannel);
}

View File

@@ -1,4 +1,6 @@
/**
* Provides File Components support for Spring Integration Java DSL.
*/
@org.springframework.lang.NonNullApi
@org.springframework.lang.NonNullFields
package org.springframework.integration.file.dsl;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2021-2022 the original author or authors.
* Copyright 2021-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -102,7 +102,7 @@ class KotlinFileAggregatorTests {
class Config {
@Bean
fun fileSplitterAggregatorFlow(taskExecutor: TaskExecutor?) =
fun fileSplitterAggregatorFlow(taskExecutor: TaskExecutor) =
integrationFlow {
split(Files.splitter().markers().firstLineAsHeader("firstLine"))
channel { executor(taskExecutor) }
@@ -115,4 +115,4 @@ class KotlinFileAggregatorTests {
}
}
}