Upgrade SMB to Spring Integration 5.0

code style fixes
This commit is contained in:
Prafull Kumar Sonii
2018-04-24 19:16:29 -05:00
committed by Artem Bilan
parent 11b8990daf
commit fa98e45597
13 changed files with 183 additions and 36 deletions

View File

@@ -3,8 +3,8 @@ buildscript {
maven { url 'https://repo.spring.io/plugins-release' }
}
dependencies {
classpath 'io.spring.gradle:dependency-management-plugin:1.0.0.RC2'
classpath 'io.spring.gradle:spring-io-plugin:0.0.6.RELEASE'
classpath 'io.spring.gradle:dependency-management-plugin:1.0.5.RELEASE'
classpath 'io.spring.gradle:spring-io-plugin:0.0.8.RELEASE'
classpath 'io.spring.gradle:docbook-reference-plugin:0.3.1'
}
}
@@ -44,8 +44,8 @@ if (project.hasProperty('platformVersion')) {
}
compileJava {
sourceCompatibility = 1.7
targetCompatibility = 1.7
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
compileTestJava {
@@ -54,9 +54,9 @@ compileTestJava {
}
ext {
jcifsVersion = '1.3.18.2'
jcifsVersion = '1.3.18.3'
log4jVersion = '1.2.17'
springIntegrationVersion = '4.3.6.RELEASE'
springIntegrationVersion = '5.0.4.RELEASE'
idPrefix = 'smb'
@@ -171,7 +171,7 @@ task schemaZip(type: Zip) {
description = "Builds -${classifier} archive containing all " +
"XSDs for deployment at static.springframework.org/schema."
def Properties schemas = new Properties();
Properties schemas = new Properties()
def shortName = idPrefix.replaceFirst("${idPrefix}-", '')
project.sourceSets.main.resources.find {
@@ -215,7 +215,7 @@ task distZip(type: Zip, dependsOn: [docsZip, schemaZip]) {
description = "Builds -${classifier} archive, containing all jars and docs, " +
"suitable for community download page."
ext.baseDir = "${project.name}-${project.version}";
ext.baseDir = "${project.name}-${project.version}"
from('src/dist') {
include 'readme.txt'

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -17,8 +17,10 @@
package org.springframework.integration.smb.config;
import org.springframework.integration.file.config.AbstractRemoteFileInboundChannelAdapterParser;
import org.springframework.integration.file.filters.AbstractPersistentAcceptOnceFileListFilter;
import org.springframework.integration.file.filters.FileListFilter;
import org.springframework.integration.file.remote.synchronizer.InboundFileSynchronizer;
import org.springframework.integration.smb.filters.SmbPersistentAcceptOnceFileListFilter;
import org.springframework.integration.smb.filters.SmbRegexPatternFileListFilter;
import org.springframework.integration.smb.filters.SmbSimplePatternFileListFilter;
import org.springframework.integration.smb.inbound.SmbInboundFileSynchronizer;
@@ -29,6 +31,7 @@ import org.springframework.integration.smb.inbound.SmbInboundFileSynchronizingMe
*
* @author Markus Spann
* @author Artem Bilan
* @author Prafull Kumar Soni
*/
public class SmbInboundChannelAdapterParser extends AbstractRemoteFileInboundChannelAdapterParser {
@@ -52,4 +55,9 @@ public class SmbInboundChannelAdapterParser extends AbstractRemoteFileInboundCha
return SmbRegexPatternFileListFilter.class;
}
@Override
protected Class<? extends AbstractPersistentAcceptOnceFileListFilter<?>> getPersistentAcceptOnceFileListFilterClass() {
return SmbPersistentAcceptOnceFileListFilter.class;
}
}

View File

@@ -0,0 +1,44 @@
/*
* Copyright 2018 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.smb.filters;
import jcifs.smb.SmbFile;
import org.springframework.integration.file.filters.AbstractPersistentAcceptOnceFileListFilter;
import org.springframework.integration.metadata.ConcurrentMetadataStore;
/**
* Implementation of {@link AbstractPersistentAcceptOnceFileListFilter} for SMB.
*
* @author Prafull Kumar Soni
*/
public class SmbPersistentAcceptOnceFileListFilter extends AbstractPersistentAcceptOnceFileListFilter<SmbFile> {
public SmbPersistentAcceptOnceFileListFilter(ConcurrentMetadataStore store, String prefix) {
super(store, prefix);
}
@Override
protected long modified(SmbFile file) {
return file.getLastModified();
}
@Override
protected String fileName(SmbFile file) {
return file.getName();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -16,8 +16,10 @@
package org.springframework.integration.smb.filters;
import java.io.UncheckedIOException;
import java.util.regex.Pattern;
import jcifs.smb.SmbException;
import org.springframework.integration.file.filters.AbstractRegexPatternFileListFilter;
import jcifs.smb.SmbFile;
@@ -26,6 +28,7 @@ import jcifs.smb.SmbFile;
* Implementation of {@link AbstractRegexPatternFileListFilter} for SMB.
*
* @author Markus Spann
* @author Prafull Kumar Soni
*/
public class SmbRegexPatternFileListFilter extends AbstractRegexPatternFileListFilter<SmbFile> {
@@ -48,4 +51,13 @@ public class SmbRegexPatternFileListFilter extends AbstractRegexPatternFileListF
return (file != null ? file.getName() : null);
}
@Override
protected boolean isDirectory(SmbFile file) {
try {
return file.isDirectory();
}
catch (SmbException e) {
throw new UncheckedIOException(e);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -16,14 +16,18 @@
package org.springframework.integration.smb.filters;
import jcifs.smb.SmbException;
import org.springframework.integration.file.filters.AbstractSimplePatternFileListFilter;
import jcifs.smb.SmbFile;
import java.io.UncheckedIOException;
/**
* Implementation of {@link AbstractSimplePatternFileListFilter} for SMB.
*
* @author Markus Spann
* @author Prafull Kumar Soni
*
*/
public class SmbSimplePatternFileListFilter extends AbstractSimplePatternFileListFilter<SmbFile> {
@@ -43,4 +47,14 @@ public class SmbSimplePatternFileListFilter extends AbstractSimplePatternFileLis
return (file != null) ? file.getName() : null;
}
@Override
protected boolean isDirectory(SmbFile file) {
try {
return file.isDirectory();
}
catch (SmbException e) {
throw new UncheckedIOException(e);
}
}
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright 2018 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.smb.filters;
import jcifs.smb.SmbFile;
import org.springframework.integration.file.filters.AbstractMarkerFilePresentFileListFilter;
import org.springframework.integration.file.filters.FileListFilter;
import java.util.Map;
import java.util.function.Function;
/**
* Implementation of {@link AbstractMarkerFilePresentFileListFilter} for SMB.
*
* @author Prafull Kumar Soni
*/
public class SmbSystemMarkerFilePresentFileListFilter extends AbstractMarkerFilePresentFileListFilter<SmbFile> {
public SmbSystemMarkerFilePresentFileListFilter(FileListFilter<SmbFile> filter) {
super(filter);
}
public SmbSystemMarkerFilePresentFileListFilter(FileListFilter<SmbFile> filter, String suffix) {
super(filter, suffix);
}
public SmbSystemMarkerFilePresentFileListFilter(FileListFilter<SmbFile> filter, Function<String, String> function) {
super(filter, function);
}
public SmbSystemMarkerFilePresentFileListFilter(Map<FileListFilter<SmbFile>, Function<String, String>> filtersAndFunctions) {
super(filtersAndFunctions);
}
@Override
protected String getFilename(SmbFile file) {
return file.getName();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.util.StringUtils;
* smb://[[[domain;]username[:password]@]server[:port]/[[share/[dir/]file]]][?[param=value[param2=value2[...]]]
*
* @author Markus Spann
* @author Prafull Kumar Soni
* @since 1.0
*/
public class SmbConfig {
@@ -52,8 +53,7 @@ public class SmbConfig {
public SmbConfig() {
}
public SmbConfig(String _host, int _port, String _domain, String _username, String _password, String _shareAndDir)
throws UnsupportedEncodingException {
public SmbConfig(String _host, int _port, String _domain, String _username, String _password, String _shareAndDir) {
setHost(_host);
setPort(_port);
setDomain(_domain);
@@ -81,7 +81,7 @@ public class SmbConfig {
}
public void setDomain(String _domain) {
Assert.notNull(_domain);
Assert.notNull(_domain, "_domain can't be null");
this.domain = _domain;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -52,6 +52,7 @@ import jcifs.smb.SmbFileOutputStream;
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Artem Bilan
* @author Prafull Kumar Soni
*
*/
public class SmbSession implements Session<SmbFile> {
@@ -395,7 +396,7 @@ public class SmbSession implements Session<SmbFile> {
}
@Override
public boolean finalizeRaw() throws IOException {
public boolean finalizeRaw() {
return true;
}
@@ -524,7 +525,7 @@ public class SmbSession implements Session<SmbFile> {
}
@Override
public String[] listNames(String path) throws IOException {
public String[] listNames(String path) {
throw new UnsupportedOperationException("Not implemented yet");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -24,12 +24,13 @@ import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
/**
* @author Markus Spann
* @author Prafull Kumar Soni
*
*/
public class SmbMessageHistoryTests extends AbstractBaseTests {
@Test
public void testMessageHistory() throws Exception {
public void testMessageHistory() {
SourcePollingChannelAdapter adapter = getApplicationContext()
.getBean("smbInboundChannelAdapter", SourcePollingChannelAdapter.class);
assertEquals("smbInboundChannelAdapter", adapter.getComponentName());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.context.support.ClassPathXmlApplicationContext;
/**
* @author Markus Spann
* @author Prafull Kumar Soni
*
*/
public class SmbParserInboundTests extends AbstractBaseTests {
@@ -38,7 +39,7 @@ public class SmbParserInboundTests extends AbstractBaseTests {
}
@Test
public void testLocalFilesAutoCreationTrue() throws Exception {
public void testLocalFilesAutoCreationTrue() {
assertFileNotExists(new File("test-temp/local-10"));
new ClassPathXmlApplicationContext(getApplicationContextXmlFile(), this.getClass());
assertFileExists(new File("test-temp/local-10"));
@@ -46,7 +47,7 @@ public class SmbParserInboundTests extends AbstractBaseTests {
}
@Test(expected = BeanCreationException.class)
public void testLocalFilesAutoCreationFalse() throws Exception {
public void testLocalFilesAutoCreationFalse() {
assertFileNotExists(new File("test-temp/local-6"));
new ClassPathXmlApplicationContext(getApplicationContextXmlFile("-fail"), this.getClass())
.close();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -24,7 +24,9 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.PriorityBlockingQueue;
import org.junit.Test;
@@ -34,6 +36,9 @@ import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
import org.springframework.integration.file.filters.CompositeFileListFilter;
import org.springframework.integration.file.filters.FileListFilter;
import org.springframework.integration.smb.filters.SmbPersistentAcceptOnceFileListFilter;
import org.springframework.integration.smb.filters.SmbSimplePatternFileListFilter;
import org.springframework.integration.smb.inbound.SmbInboundFileSynchronizer;
import org.springframework.integration.smb.inbound.SmbInboundFileSynchronizingMessageSource;
@@ -47,6 +52,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Markus Spann
* @author Gunnar Hillert
* @author Artem Bilan
* @author Prafull Kumar Soni
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@@ -56,11 +62,10 @@ public class SmbInboundChannelAdapterParserTests {
ApplicationContext applicationContext;
@Test(timeout = 100000)
public void testSmbInboundChannelAdapterComplete() throws Exception {
public void testSmbInboundChannelAdapterComplete() {
final SourcePollingChannelAdapter adapter = this.applicationContext.getBean("smbInbound", SourcePollingChannelAdapter.class);
final PriorityBlockingQueue<?> queue = TestUtils.getPropertyValue(adapter, "source.fileSource.toBeReceived", PriorityBlockingQueue.class);
assertNotNull(queue.comparator());
assertEquals("smbInbound", adapter.getComponentName());
assertEquals("smb:inbound-channel-adapter", adapter.getComponentType());
@@ -75,14 +80,20 @@ public class SmbInboundChannelAdapterParserTests {
String remoteFileSeparator = (String) TestUtils.getPropertyValue(fisync, "remoteFileSeparator");
assertNotNull(remoteFileSeparator);
assertEquals("", remoteFileSeparator);
SmbSimplePatternFileListFilter filter = (SmbSimplePatternFileListFilter) TestUtils.getPropertyValue(fisync, "filter");
FileListFilter<?> filter = TestUtils.getPropertyValue(fisync, "filter", FileListFilter.class);
assertNotNull(filter);
assertThat(filter, instanceOf(CompositeFileListFilter.class));
Set<?> fileFilters = TestUtils.getPropertyValue(filter, "fileFilters", Set.class);
Iterator<?> filtersIterator = fileFilters.iterator();
assertThat(filtersIterator.next(), instanceOf(SmbSimplePatternFileListFilter.class));
assertThat(filtersIterator.next(), instanceOf(SmbPersistentAcceptOnceFileListFilter.class));
Object sessionFactory = TestUtils.getPropertyValue(fisync, "remoteFileTemplate.sessionFactory");
assertTrue(SmbSessionFactory.class.isAssignableFrom(sessionFactory.getClass()));
}
@Test
public void testNoCachingSessionFactoryByDefault() throws Exception {
public void testNoCachingSessionFactoryByDefault() {
SourcePollingChannelAdapter adapter = applicationContext.getBean("simpleAdapter", SourcePollingChannelAdapter.class);
Object sessionFactory = TestUtils.getPropertyValue(adapter, "source.synchronizer.remoteFileTemplate.sessionFactory");
assertThat(sessionFactory, instanceOf(SmbSessionFactory.class));
@@ -94,7 +105,7 @@ public class SmbInboundChannelAdapterParserTests {
}
@Test(timeout = 10000)
public void testSmbInboundChannelAdapterCompleteNoId() throws Exception {
public void testSmbInboundChannelAdapterCompleteNoId() {
Map<String, SourcePollingChannelAdapter> spcas = applicationContext.getBeansOfType(SourcePollingChannelAdapter.class);
SourcePollingChannelAdapter adapter = null;
@@ -109,7 +120,7 @@ public class SmbInboundChannelAdapterParserTests {
public static class TestSessionFactoryBean implements FactoryBean<SmbSessionFactory> {
public SmbSessionFactory getObject() throws Exception {
public SmbSessionFactory getObject() {
SmbSessionFactory smbFactory = mock(SmbSessionFactory.class);
SmbSession session = mock(SmbSession.class);
when(smbFactory.getSession()).thenReturn(session);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -39,11 +39,12 @@ import org.springframework.messaging.MessageHandler;
* @author Markus Spann
* @author Gunnar Hillert
* @author Artem Bilan
* @author Prafull Kumar Soni
*/
public class SmbOutboundChannelAdapterParserTests extends AbstractBaseTests {
@Test
public void testSmbOutboundChannelAdapterComplete() throws Exception {
public void testSmbOutboundChannelAdapterComplete() {
ApplicationContext ac = getApplicationContext();
Object consumer = ac.getBean("smbOutboundChannelAdapter");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -44,6 +44,7 @@ import jcifs.smb.SmbFile;
/**
* @author Markus Spann
* @author Artem Bilan
* @author Prafull Kumar Soni
*/
public class SmbSendingMessageHandlerTests extends AbstractBaseTests {
@@ -65,7 +66,7 @@ public class SmbSendingMessageHandlerTests extends AbstractBaseTests {
}
@Test
public void testHandleFileContentMessage() throws Exception {
public void testHandleFileContentMessage() {
File file = createNewFile("remote-target-dir/handlerContent.test");
FileTransferringMessageHandler<?> handler = new FileTransferringMessageHandler<SmbFile>(smbSessionFactory);
handler.setRemoteDirectoryExpression(new LiteralExpression("remote-target-dir"));
@@ -78,7 +79,7 @@ public class SmbSendingMessageHandlerTests extends AbstractBaseTests {
}
@Test
public void testHandleFileAsByte() throws Exception {
public void testHandleFileAsByte() {
File file = createNewFile("remote-target-dir/handlerContent.test");
FileTransferringMessageHandler<?> handler = new FileTransferringMessageHandler<SmbFile>(smbSessionFactory);
handler.setRemoteDirectoryExpression(new LiteralExpression("remote-target-dir"));
@@ -135,7 +136,7 @@ public class SmbSendingMessageHandlerTests extends AbstractBaseTests {
doAnswer(new Answer<Object>() {
public Object answer(InvocationOnMock _invocation) throws Throwable {
public Object answer(InvocationOnMock _invocation) {
String path = (String) _invocation.getArguments()[0];
new File(path).mkdirs();
return null;