Sonar issues - complexity
* Fix checkstyle issue.
This commit is contained in:
committed by
Artem Bilan
parent
90d2b30066
commit
86c7e36667
@@ -117,14 +117,8 @@ public class FileListFilterFactoryBean implements FactoryBean<FileListFilter<Fil
|
||||
return;
|
||||
}
|
||||
FileListFilter<File> createdFilter = null;
|
||||
if ((this.filter != null) && (this.filenamePattern != null || this.filenameRegex != null)) {
|
||||
throw new IllegalArgumentException("The 'filter' reference is mutually exclusive with "
|
||||
+ "either the 'filename-pattern' or 'filename-regex' attribute.");
|
||||
}
|
||||
|
||||
if (this.filenamePattern != null && this.filenameRegex != null) {
|
||||
throw new IllegalArgumentException("The 'filename-pattern' and 'filename-regex' attributes are mutually exclusive.");
|
||||
}
|
||||
validate();
|
||||
|
||||
final List<FileListFilter<File>> filtersNeeded = new ArrayList<FileListFilter<File>>();
|
||||
|
||||
@@ -134,36 +128,12 @@ public class FileListFilterFactoryBean implements FactoryBean<FileListFilter<Fil
|
||||
|
||||
//'filter' is set
|
||||
if (this.filter != null) {
|
||||
if (Boolean.TRUE.equals(this.preventDuplicates)) {
|
||||
filtersNeeded.add(new AcceptOnceFileListFilter<File>());
|
||||
filtersNeeded.add(this.filter);
|
||||
}
|
||||
else { // preventDuplicates is either FALSE or NULL
|
||||
filtersNeeded.add(this.filter);
|
||||
}
|
||||
filter(filtersNeeded);
|
||||
}
|
||||
|
||||
// 'file-pattern' or 'file-regex' is set
|
||||
else if (this.filenamePattern != null || this.filenameRegex != null) {
|
||||
|
||||
if (!Boolean.FALSE.equals(this.preventDuplicates)) {
|
||||
//preventDuplicates is either null or true
|
||||
filtersNeeded.add(new AcceptOnceFileListFilter<File>());
|
||||
}
|
||||
if (this.filenamePattern != null) {
|
||||
SimplePatternFileListFilter patternFilter = new SimplePatternFileListFilter(this.filenamePattern);
|
||||
if (this.alwaysAcceptDirectories != null) {
|
||||
patternFilter.setAlwaysAcceptDirectories(this.alwaysAcceptDirectories);
|
||||
}
|
||||
filtersNeeded.add(patternFilter);
|
||||
}
|
||||
if (this.filenameRegex != null) {
|
||||
RegexPatternFileListFilter regexFilter = new RegexPatternFileListFilter(this.filenameRegex);
|
||||
if (this.alwaysAcceptDirectories != null) {
|
||||
regexFilter.setAlwaysAcceptDirectories(this.alwaysAcceptDirectories);
|
||||
}
|
||||
filtersNeeded.add(regexFilter);
|
||||
}
|
||||
pattern(filtersNeeded);
|
||||
}
|
||||
|
||||
// no filters are provided
|
||||
@@ -184,4 +154,47 @@ public class FileListFilterFactoryBean implements FactoryBean<FileListFilter<Fil
|
||||
this.result = createdFilter;
|
||||
}
|
||||
|
||||
private void validate() {
|
||||
if ((this.filter != null) && (this.filenamePattern != null || this.filenameRegex != null)) {
|
||||
throw new IllegalArgumentException("The 'filter' reference is mutually exclusive with "
|
||||
+ "either the 'filename-pattern' or 'filename-regex' attribute.");
|
||||
}
|
||||
|
||||
if (this.filenamePattern != null && this.filenameRegex != null) {
|
||||
throw new IllegalArgumentException("The 'filename-pattern' and 'filename-regex' attributes are "
|
||||
+ "mutually exclusive.");
|
||||
}
|
||||
}
|
||||
|
||||
private void filter(final List<FileListFilter<File>> filtersNeeded) {
|
||||
if (Boolean.TRUE.equals(this.preventDuplicates)) {
|
||||
filtersNeeded.add(new AcceptOnceFileListFilter<File>());
|
||||
filtersNeeded.add(this.filter);
|
||||
}
|
||||
else { // preventDuplicates is either FALSE or NULL
|
||||
filtersNeeded.add(this.filter);
|
||||
}
|
||||
}
|
||||
|
||||
private void pattern(final List<FileListFilter<File>> filtersNeeded) {
|
||||
if (!Boolean.FALSE.equals(this.preventDuplicates)) {
|
||||
//preventDuplicates is either null or true
|
||||
filtersNeeded.add(new AcceptOnceFileListFilter<File>());
|
||||
}
|
||||
if (this.filenamePattern != null) {
|
||||
SimplePatternFileListFilter patternFilter = new SimplePatternFileListFilter(this.filenamePattern);
|
||||
if (this.alwaysAcceptDirectories != null) {
|
||||
patternFilter.setAlwaysAcceptDirectories(this.alwaysAcceptDirectories);
|
||||
}
|
||||
filtersNeeded.add(patternFilter);
|
||||
}
|
||||
if (this.filenameRegex != null) {
|
||||
RegexPatternFileListFilter regexFilter = new RegexPatternFileListFilter(this.filenameRegex);
|
||||
if (this.alwaysAcceptDirectories != null) {
|
||||
regexFilter.setAlwaysAcceptDirectories(this.alwaysAcceptDirectories);
|
||||
}
|
||||
filtersNeeded.add(regexFilter);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.integration.file.config;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.beans.factory.config.AbstractFactoryBean;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
@@ -27,6 +28,7 @@ import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.integration.file.tail.ApacheCommonsFileTailingMessageProducer;
|
||||
import org.springframework.integration.file.tail.FileTailingMessageProducerSupport;
|
||||
import org.springframework.integration.file.tail.OSDelegatingFileTailingMessageProducer;
|
||||
import org.springframework.integration.util.JavaUtils;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -216,45 +218,27 @@ public class FileTailInboundChannelAdapterFactoryBean extends AbstractFactoryBea
|
||||
else {
|
||||
Assert.isTrue(this.nativeOptions == null,
|
||||
"'native-options' is not allowed with 'delay', 'end', or 'reopen'");
|
||||
adapter = new ApacheCommonsFileTailingMessageProducer();
|
||||
if (this.delay != null) {
|
||||
((ApacheCommonsFileTailingMessageProducer) adapter).setPollingDelay(this.delay);
|
||||
}
|
||||
if (this.end != null) {
|
||||
((ApacheCommonsFileTailingMessageProducer) adapter).setEnd(this.end);
|
||||
}
|
||||
if (this.reopen != null) {
|
||||
((ApacheCommonsFileTailingMessageProducer) adapter).setReopen(this.reopen);
|
||||
}
|
||||
ApacheCommonsFileTailingMessageProducer apache = new ApacheCommonsFileTailingMessageProducer();
|
||||
JavaUtils.INSTANCE
|
||||
.acceptIfNotNull(this.delay, apache::setPollingDelay)
|
||||
.acceptIfNotNull(this.end, apache::setEnd)
|
||||
.acceptIfNotNull(this.reopen, apache::setReopen);
|
||||
adapter = apache;
|
||||
}
|
||||
adapter.setFile(this.file);
|
||||
if (this.taskExecutor != null) {
|
||||
adapter.setTaskExecutor(this.taskExecutor);
|
||||
}
|
||||
if (this.taskScheduler != null) {
|
||||
adapter.setTaskScheduler(this.taskScheduler);
|
||||
}
|
||||
if (this.fileDelay != null) {
|
||||
adapter.setTailAttemptsDelay(this.fileDelay);
|
||||
}
|
||||
if (this.idleEventInterval != null) {
|
||||
adapter.setIdleEventInterval(this.idleEventInterval);
|
||||
}
|
||||
adapter.setOutputChannel(this.outputChannel);
|
||||
adapter.setErrorChannel(this.errorChannel);
|
||||
adapter.setBeanName(this.beanName);
|
||||
if (this.autoStartup != null) {
|
||||
adapter.setAutoStartup(this.autoStartup);
|
||||
}
|
||||
if (this.phase != null) {
|
||||
adapter.setPhase(this.phase);
|
||||
}
|
||||
if (this.applicationEventPublisher != null) {
|
||||
adapter.setApplicationEventPublisher(this.applicationEventPublisher);
|
||||
}
|
||||
if (getBeanFactory() != null) {
|
||||
adapter.setBeanFactory(getBeanFactory()); // NOSONAR never null
|
||||
}
|
||||
BeanFactory beanFactory = getBeanFactory();
|
||||
JavaUtils.INSTANCE
|
||||
.acceptIfNotNull(this.taskExecutor, adapter::setTaskExecutor)
|
||||
.acceptIfNotNull(this.taskScheduler, adapter::setTaskScheduler)
|
||||
.acceptIfNotNull(this.fileDelay, adapter::setTailAttemptsDelay)
|
||||
.acceptIfNotNull(this.idleEventInterval, adapter::setIdleEventInterval)
|
||||
.acceptIfNotNull(this.autoStartup, adapter::setAutoStartup)
|
||||
.acceptIfNotNull(this.phase, adapter::setPhase)
|
||||
.acceptIfNotNull(this.applicationEventPublisher, adapter::setApplicationEventPublisher)
|
||||
.acceptIfNotNull(beanFactory, adapter::setBeanFactory);
|
||||
adapter.afterPropertiesSet();
|
||||
this.tailAdapter = adapter;
|
||||
return adapter;
|
||||
|
||||
@@ -77,6 +77,13 @@ abstract class FileWritingMessageHandlerBeanDefinitionBuilder {
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "flush-predicate");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "chmod");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "preserve-timestamp");
|
||||
filenameGenerators(element, parserContext, builder);
|
||||
return builder;
|
||||
}
|
||||
|
||||
private static void filenameGenerators(Element element, ParserContext parserContext,
|
||||
BeanDefinitionBuilder builder) {
|
||||
|
||||
String remoteFileNameGenerator = element.getAttribute("filename-generator");
|
||||
String remoteFileNameGeneratorExpression = element.getAttribute("filename-generator-expression");
|
||||
boolean hasRemoteFileNameGenerator = StringUtils.hasText(remoteFileNameGenerator);
|
||||
@@ -97,7 +104,6 @@ abstract class FileWritingMessageHandlerBeanDefinitionBuilder {
|
||||
builder.addPropertyValue("fileNameGenerator", fileNameGeneratorBuilder.getBeanDefinition());
|
||||
}
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.integration.file.FileNameGenerator;
|
||||
import org.springframework.integration.file.FileWritingMessageHandler;
|
||||
import org.springframework.integration.file.FileWritingMessageHandler.MessageFlushPredicate;
|
||||
import org.springframework.integration.file.support.FileExistsMode;
|
||||
import org.springframework.integration.util.JavaUtils;
|
||||
|
||||
/**
|
||||
* Factory bean used to create {@link FileWritingMessageHandler}s.
|
||||
@@ -167,52 +168,23 @@ public class FileWritingMessageHandlerFactoryBean
|
||||
throw new IllegalStateException("Either directory or directoryExpression must not be null");
|
||||
}
|
||||
|
||||
if (this.charset != null) {
|
||||
handler.setCharset(this.charset);
|
||||
}
|
||||
if (this.fileNameGenerator != null) {
|
||||
handler.setFileNameGenerator(this.fileNameGenerator);
|
||||
}
|
||||
if (this.deleteSourceFiles != null) {
|
||||
handler.setDeleteSourceFiles(this.deleteSourceFiles);
|
||||
}
|
||||
if (this.autoCreateDirectory != null) {
|
||||
handler.setAutoCreateDirectory(this.autoCreateDirectory);
|
||||
}
|
||||
if (this.requiresReply != null) {
|
||||
handler.setRequiresReply(this.requiresReply);
|
||||
}
|
||||
if (this.sendTimeout != null) {
|
||||
handler.setSendTimeout(this.sendTimeout);
|
||||
}
|
||||
if (this.temporaryFileSuffix != null) {
|
||||
handler.setTemporaryFileSuffix(this.temporaryFileSuffix);
|
||||
}
|
||||
handler.setExpectReply(this.expectReply);
|
||||
if (this.appendNewLine != null) {
|
||||
handler.setAppendNewLine(this.appendNewLine);
|
||||
}
|
||||
if (this.fileExistsMode != null) {
|
||||
handler.setFileExistsMode(this.fileExistsMode);
|
||||
}
|
||||
if (this.bufferSize != null) {
|
||||
handler.setBufferSize(this.bufferSize);
|
||||
}
|
||||
if (this.flushInterval != null) {
|
||||
handler.setFlushInterval(this.flushInterval);
|
||||
}
|
||||
if (this.flushWhenIdle != null) {
|
||||
handler.setFlushWhenIdle(this.flushWhenIdle);
|
||||
}
|
||||
if (this.flushPredicate != null) {
|
||||
handler.setFlushPredicate(this.flushPredicate);
|
||||
}
|
||||
if (this.chmod != null) {
|
||||
handler.setChmodOctal(this.chmod);
|
||||
}
|
||||
if (this.preserveTimestamp != null) {
|
||||
handler.setPreserveTimestamp(this.preserveTimestamp);
|
||||
}
|
||||
JavaUtils.INSTANCE
|
||||
.acceptIfNotNull(this.charset, handler::setCharset)
|
||||
.acceptIfNotNull(this.fileNameGenerator, handler::setFileNameGenerator)
|
||||
.acceptIfNotNull(this.deleteSourceFiles, handler::setDeleteSourceFiles)
|
||||
.acceptIfNotNull(this.autoCreateDirectory, handler::setAutoCreateDirectory)
|
||||
.acceptIfNotNull(this.requiresReply, handler::setRequiresReply)
|
||||
.acceptIfNotNull(this.sendTimeout, handler::setSendTimeout)
|
||||
.acceptIfNotNull(this.temporaryFileSuffix, handler::setTemporaryFileSuffix)
|
||||
.acceptIfNotNull(this.appendNewLine, handler::setAppendNewLine)
|
||||
.acceptIfNotNull(this.fileExistsMode, handler::setFileExistsMode)
|
||||
.acceptIfNotNull(this.bufferSize, handler::setBufferSize)
|
||||
.acceptIfNotNull(this.flushInterval, handler::setFlushInterval)
|
||||
.acceptIfNotNull(this.flushWhenIdle, handler::setFlushWhenIdle)
|
||||
.acceptIfNotNull(this.flushPredicate, handler::setFlushPredicate)
|
||||
.acceptIfNotNull(this.chmod, handler::setChmodOctal)
|
||||
.acceptIfNotNull(this.preserveTimestamp, handler::setPreserveTimestamp);
|
||||
|
||||
return handler;
|
||||
}
|
||||
|
||||
@@ -301,7 +301,7 @@ public class RemoteFileTemplate<F> implements RemoteFileOperations<F>, Initializ
|
||||
try {
|
||||
inputStreamHolder.stream.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
catch (@SuppressWarnings("unused") IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -544,47 +544,52 @@ public class RemoteFileTemplate<F> implements RemoteFileOperations<F>, Initializ
|
||||
try {
|
||||
RemoteFileUtils.makeDirectories(remoteDirectory, session, this.remoteFileSeparator, this.logger);
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
catch (@SuppressWarnings("unused") IllegalStateException e) {
|
||||
// Revert to old FTP behavior if recursive mkdir fails, for backwards compatibility
|
||||
session.mkdir(remoteDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
try (InputStream stream = inputStream) {
|
||||
boolean rename = this.useTemporaryFileName;
|
||||
if (FileExistsMode.REPLACE.equals(mode)) {
|
||||
session.write(stream, tempFilePath);
|
||||
}
|
||||
else if (FileExistsMode.APPEND.equals(mode)) {
|
||||
session.append(stream, tempFilePath);
|
||||
}
|
||||
else {
|
||||
if (exists(remoteFilePath)) {
|
||||
if (FileExistsMode.FAIL.equals(mode)) {
|
||||
throw new MessagingException(
|
||||
"The destination file already exists at '" + remoteFilePath + "'.");
|
||||
}
|
||||
else {
|
||||
if (this.logger.isDebugEnabled()) {
|
||||
this.logger.debug("File not transferred to '" + remoteFilePath + "'; already exists.");
|
||||
}
|
||||
}
|
||||
rename = false;
|
||||
}
|
||||
else {
|
||||
session.write(stream, tempFilePath);
|
||||
}
|
||||
}
|
||||
// then rename it to its final name if necessary
|
||||
if (rename) {
|
||||
session.rename(tempFilePath, remoteFilePath);
|
||||
}
|
||||
doSend(session, mode, remoteFilePath, tempFilePath, stream);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new MessagingException("Failed to write to '" + tempFilePath + "' while uploading the file", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void doSend(Session<F> session, FileExistsMode mode, String remoteFilePath, String tempFilePath,
|
||||
InputStream stream) throws IOException {
|
||||
boolean rename = this.useTemporaryFileName;
|
||||
if (FileExistsMode.REPLACE.equals(mode)) {
|
||||
session.write(stream, tempFilePath);
|
||||
}
|
||||
else if (FileExistsMode.APPEND.equals(mode)) {
|
||||
session.append(stream, tempFilePath);
|
||||
}
|
||||
else {
|
||||
if (exists(remoteFilePath)) {
|
||||
if (FileExistsMode.FAIL.equals(mode)) {
|
||||
throw new MessagingException(
|
||||
"The destination file already exists at '" + remoteFilePath + "'.");
|
||||
}
|
||||
else {
|
||||
if (this.logger.isDebugEnabled()) {
|
||||
this.logger.debug("File not transferred to '" + remoteFilePath + "'; already exists.");
|
||||
}
|
||||
}
|
||||
rename = false;
|
||||
}
|
||||
else {
|
||||
session.write(stream, tempFilePath);
|
||||
}
|
||||
}
|
||||
// then rename it to its final name if necessary
|
||||
if (rename) {
|
||||
session.rename(tempFilePath, remoteFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
private String normalizeDirectoryPath(String directoryPath) {
|
||||
if (!StringUtils.hasText(directoryPath)) {
|
||||
return "";
|
||||
|
||||
@@ -758,19 +758,25 @@ public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReply
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (replies.size() > 0 || ex instanceof PartialSuccessException) { // NOSONAR
|
||||
throw new PartialSuccessException(requestMessage,
|
||||
"Partially successful 'mput' operation" +
|
||||
(subDirectory == null ? "" : (" on " + subDirectory)), ex, replies, filteredFiles);
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
catch (RuntimeException ex) {
|
||||
throw handlePutException(requestMessage, subDirectory, filteredFiles, replies, ex);
|
||||
}
|
||||
return replies;
|
||||
}
|
||||
|
||||
private RuntimeException handlePutException(Message<?> requestMessage, String subDirectory,
|
||||
List<File> filteredFiles, List<String> replies, RuntimeException ex) {
|
||||
|
||||
if (replies.size() > 0 || ex instanceof PartialSuccessException) {
|
||||
return new PartialSuccessException(requestMessage,
|
||||
"Partially successful 'mput' operation" +
|
||||
(subDirectory == null ? "" : (" on " + subDirectory)), ex, replies, filteredFiles);
|
||||
}
|
||||
else {
|
||||
return ex;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List remote files to local representation.
|
||||
* The message can be consulted for some context for the current request;
|
||||
@@ -889,8 +895,9 @@ public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReply
|
||||
* @return The file.
|
||||
* @throws IOException Any IOException.
|
||||
*/
|
||||
protected File get(Message<?> message, Session<F> session, String remoteDir, String remoteFilePath,
|
||||
String remoteFilename, F fileInfoParam) throws IOException {
|
||||
protected File get(Message<?> message, Session<F> session, String remoteDir, // NOSONAR complexity
|
||||
String remoteFilePath, String remoteFilename, F fileInfoParam) throws IOException {
|
||||
|
||||
F fileInfo = fileInfoParam;
|
||||
if (fileInfo == null) {
|
||||
F[] files = session.list(remoteFilePath);
|
||||
|
||||
@@ -166,7 +166,7 @@ public class FileSplitter extends AbstractMessageSplitter {
|
||||
this.firstLineHeaderName = firstLineHeaderName;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override// NOSONAR complexity
|
||||
protected Object splitMessage(final Message<?> message) {
|
||||
Object payload = message.getPayload();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user