INT-1591 FileListFilter is now parameterized. Existing implementations required refactoring to specify <File> for <F>.

This commit is contained in:
Mark Fisher
2010-11-08 17:31:32 -05:00
parent 59a15d6177
commit e4f6b33b7b
37 changed files with 603 additions and 442 deletions

View File

@@ -16,16 +16,18 @@
package org.springframework.integration.sftp.config;
import com.jcraft.jsch.ChannelSftp;
import java.io.File;
import org.apache.commons.lang.SystemUtils;
import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceEditor;
import org.springframework.core.io.ResourceLoader;
import org.springframework.integration.file.entries.CompositeEntryListFilter;
import org.springframework.integration.file.entries.EntryListFilter;
import org.springframework.integration.file.entries.PatternMatchingEntryListFilter;
import org.springframework.integration.file.filters.CompositeFileListFilter;
import org.springframework.integration.file.filters.FileListFilter;
import org.springframework.integration.file.filters.PatternMatchingFileListFilter;
import org.springframework.integration.sftp.QueuedSftpSessionPool;
import org.springframework.integration.sftp.SftpEntryNameExtractor;
import org.springframework.integration.sftp.SftpSessionFactory;
@@ -33,7 +35,7 @@ import org.springframework.integration.sftp.impl.SftpInboundRemoteFileSystemSync
import org.springframework.integration.sftp.impl.SftpInboundRemoteFileSystemSynchronizingMessageSource;
import org.springframework.util.StringUtils;
import java.io.File;
import com.jcraft.jsch.ChannelSftp;
/**
* Factory bean to hide the fairly complex configuration possibilities for an SFTP endpoint
@@ -55,7 +57,7 @@ public class SftpRemoteFileSystemSynchronizingMessageSourceFactoryBean
private volatile String filenamePattern;
private volatile EntryListFilter<ChannelSftp.LsEntry> filter;
private volatile FileListFilter<ChannelSftp.LsEntry> filter;
private int port = 22;
@@ -92,7 +94,7 @@ public class SftpRemoteFileSystemSynchronizingMessageSourceFactoryBean
this.filenamePattern = filenamePattern;
}
public void setFilter(EntryListFilter<ChannelSftp.LsEntry> filter) {
public void setFilter(FileListFilter<ChannelSftp.LsEntry> filter) {
this.filter = filter;
}
@@ -170,10 +172,10 @@ public class SftpRemoteFileSystemSynchronizingMessageSourceFactoryBean
// remote predicates
SftpEntryNameExtractor sftpEntryNameExtractor = new SftpEntryNameExtractor();
CompositeEntryListFilter<ChannelSftp.LsEntry> compositeFtpFileListFilter = new CompositeEntryListFilter<ChannelSftp.LsEntry>();
CompositeFileListFilter<ChannelSftp.LsEntry> compositeFtpFileListFilter = new CompositeFileListFilter<ChannelSftp.LsEntry>();
if (StringUtils.hasText(this.filenamePattern)) {
PatternMatchingEntryListFilter<ChannelSftp.LsEntry> ftpFilePatternMatchingEntryListFilter =
new PatternMatchingEntryListFilter<ChannelSftp.LsEntry>(sftpEntryNameExtractor, filenamePattern);
PatternMatchingFileListFilter<ChannelSftp.LsEntry> ftpFilePatternMatchingEntryListFilter =
new PatternMatchingFileListFilter<ChannelSftp.LsEntry>(sftpEntryNameExtractor, filenamePattern);
compositeFtpFileListFilter.addFilter(ftpFilePatternMatchingEntryListFilter);
}
if (this.filter != null) {

View File

@@ -120,7 +120,7 @@ public class SftpInboundRemoteFileSystemSynchronizer extends AbstractInboundRemo
ChannelSftp channelSftp = session.getChannel();
Collection<ChannelSftp.LsEntry> beforeFilter = channelSftp.ls(remotePath);
ChannelSftp.LsEntry[] entries = (beforeFilter == null) ? new ChannelSftp.LsEntry[0] : beforeFilter.toArray(new ChannelSftp.LsEntry[beforeFilter.size()]);
Collection<ChannelSftp.LsEntry> files = this.filter.filterEntries(entries);
Collection<ChannelSftp.LsEntry> files = this.filter.filterFiles(entries);
for (ChannelSftp.LsEntry lsEntry : files) {
if ((lsEntry != null) && !lsEntry.getAttrs().isDir() && !lsEntry.getAttrs().isLink()) {
copyFromRemoteToLocalDirectory(session, lsEntry, this.localDirectory);

View File

@@ -56,7 +56,7 @@
<beans:bean id="filter" class="org.mockito.Mockito" factory-method="mock">
<beans:constructor-arg value="org.springframework.integration.file.entries.EntryListFilter"/>
<beans:constructor-arg value="org.springframework.integration.file.filters.FileListFilter"/>
</beans:bean>
</beans:beans>

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.sftp;
import static junit.framework.Assert.assertTrue;
@@ -22,13 +23,12 @@ import java.io.File;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author Oleg Zhurakousky
*
*/
public class SftpParserTests {
@@ -44,11 +44,13 @@ public class SftpParserTests {
assertTrue(new File("target/foo").exists());
assertTrue(!new File("target/bar").exists());
}
@Test(expected=BeanCreationException.class)
public void testLocalFilesAutoCreationFalse() throws Exception{
assertTrue(!new File("target/bar").exists());
new ClassPathXmlApplicationContext("SftpParserTests-inbound-all-fail.xml", this.getClass());
}
@Test
public void testLocalFilesAreFound() throws Exception{
assertTrue(new File("target").exists());
@@ -60,4 +62,5 @@ public class SftpParserTests {
public void cleanUp() throws Exception{
new File("target/foo").delete();
}
}