INT-1591 FileListFilter is now parameterized. Existing implementations required refactoring to specify <File> for <F>.
This commit is contained in:
@@ -21,8 +21,8 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.integration.MessagingException;
|
||||
import org.springframework.integration.file.entries.AcceptOnceEntryFileListFilter;
|
||||
import org.springframework.integration.file.entries.EntryListFilter;
|
||||
import org.springframework.integration.file.filters.AcceptOnceFileListFilter;
|
||||
import org.springframework.integration.file.filters.FileListFilter;
|
||||
|
||||
/**
|
||||
* Default directory scanner and base class for other directory scanners.
|
||||
@@ -33,12 +33,12 @@ import org.springframework.integration.file.entries.EntryListFilter;
|
||||
*/
|
||||
public class DefaultDirectoryScanner implements DirectoryScanner {
|
||||
|
||||
private volatile EntryListFilter<File> filter = new AcceptOnceEntryFileListFilter<File>();
|
||||
private volatile FileListFilter<File> filter = new AcceptOnceFileListFilter<File>();
|
||||
|
||||
private volatile FileLocker locker;
|
||||
|
||||
|
||||
public void setFilter(EntryListFilter<File> filter) {
|
||||
public void setFilter(FileListFilter<File> filter) {
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class DefaultDirectoryScanner implements DirectoryScanner {
|
||||
throw new MessagingException("The path [" + directory
|
||||
+ "] does not denote a properly accessible directory.");
|
||||
}
|
||||
return (this.filter != null) ? this.filter.filterEntries(files) : Arrays.asList(files);
|
||||
return (this.filter != null) ? this.filter.filterFiles(files) : Arrays.asList(files);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
|
||||
package org.springframework.integration.file;
|
||||
|
||||
import org.springframework.integration.file.entries.EntryListFilter;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.integration.file.filters.FileListFilter;
|
||||
|
||||
/**
|
||||
* Strategy for scanning directories. Implementations may select all children
|
||||
* and grandchildren of the scanned directory in any order. This interface is
|
||||
@@ -52,7 +52,7 @@ public interface DirectoryScanner {
|
||||
* @param filter
|
||||
* the custom filter to be used
|
||||
*/
|
||||
void setFilter(EntryListFilter<File> filter);
|
||||
void setFilter(FileListFilter<File> filter);
|
||||
|
||||
/**
|
||||
* Sets a custom locker to be used by this scanner. The locker will get a
|
||||
|
||||
@@ -31,14 +31,14 @@ import org.springframework.integration.MessagingException;
|
||||
import org.springframework.integration.aggregator.ResequencingMessageGroupProcessor;
|
||||
import org.springframework.integration.context.IntegrationObjectSupport;
|
||||
import org.springframework.integration.core.MessageSource;
|
||||
import org.springframework.integration.file.entries.EntryListFilter;
|
||||
import org.springframework.integration.file.filters.FileListFilter;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* {@link MessageSource} that creates messages from a file system directory. To
|
||||
* prevent messages for certain files, you may supply a
|
||||
* {@link org.springframework.integration.file.entries.EntryListFilter}. By
|
||||
* {@link org.springframework.integration.file.filters.FileListFilter}. By
|
||||
* default, an
|
||||
* {@link org.springframework.integration.file.entries.AcceptOnceEntryFileListFilter}
|
||||
* is used. It ensures files are picked up only once from the directory.
|
||||
@@ -174,22 +174,19 @@ public class FileReadingMessageSource extends IntegrationObjectSupport implement
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a
|
||||
* {@link org.springframework.integration.file.entries.EntryListFilter}. By
|
||||
* default a
|
||||
* {@link org.springframework.integration.file.entries.AcceptOnceEntryFileListFilter}
|
||||
* with no bounds is used. In most cases a customized
|
||||
* {@link org.springframework.integration.file.entries.EntryListFilter} will
|
||||
* Sets a {@link FileListFilter}. By default a
|
||||
* {@link org.springframework.integration.file.filters.AbstractFileListFilter}
|
||||
* with no bounds is used. In most cases a customized {@link FileListFilter} will
|
||||
* be needed to deal with modification and duplication concerns. If multiple
|
||||
* filters are required a
|
||||
* {@link org.springframework.integration.file.entries.CompositeEntryListFilter}
|
||||
* {@link org.springframework.integration.file.filters.CompositeFileListFilter}
|
||||
* can be used to group them together.
|
||||
* <p/>
|
||||
* <b>The supplied filter must be thread safe.</b>.
|
||||
*
|
||||
* @param filter a filter
|
||||
*/
|
||||
public void setFilter(EntryListFilter<File> filter) {
|
||||
public void setFilter(FileListFilter<File> filter) {
|
||||
Assert.notNull(filter, "'filter' must not be null");
|
||||
this.scanner.setFilter(filter);
|
||||
}
|
||||
|
||||
@@ -16,13 +16,12 @@
|
||||
|
||||
package org.springframework.integration.file;
|
||||
|
||||
import org.springframework.integration.file.entries.EntryListFilter;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.integration.file.filters.FileListFilter;
|
||||
|
||||
/**
|
||||
* A custom scanner that only returns the first <code>maxNumberOfFiles</code>
|
||||
* elements from a directory listing. This is useful to limit the number of File
|
||||
@@ -38,7 +37,7 @@ public class HeadDirectoryScanner extends DefaultDirectoryScanner {
|
||||
}
|
||||
|
||||
|
||||
private static class HeadFilter implements EntryListFilter<File> {
|
||||
private static class HeadFilter implements FileListFilter<File> {
|
||||
|
||||
private final int maxNumberOfFiles;
|
||||
|
||||
@@ -46,7 +45,7 @@ public class HeadDirectoryScanner extends DefaultDirectoryScanner {
|
||||
this.maxNumberOfFiles = maxNumberOfFiles;
|
||||
}
|
||||
|
||||
public List<File> filterEntries(File[] files) {
|
||||
public List<File> filterFiles(File[] files) {
|
||||
return Arrays.asList(files).subList(0, Math.min(files.length, maxNumberOfFiles));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,22 +16,25 @@
|
||||
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.integration.file.entries.*;
|
||||
import org.springframework.integration.file.filters.SimplePatternFileListFilter;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.integration.file.filters.AcceptAllFileListFilter;
|
||||
import org.springframework.integration.file.filters.AcceptOnceFileListFilter;
|
||||
import org.springframework.integration.file.filters.CompositeFileListFilter;
|
||||
import org.springframework.integration.file.filters.FileListFilter;
|
||||
import org.springframework.integration.file.filters.SimplePatternFileListFilter;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @since 1.0.3
|
||||
*/
|
||||
public class FileListFilterFactoryBean implements FactoryBean<EntryListFilter<File>> {
|
||||
public class FileListFilterFactoryBean implements FactoryBean<FileListFilter<File>> {
|
||||
|
||||
private volatile EntryListFilter<File> fileListFilter;
|
||||
private volatile FileListFilter<File> fileListFilter;
|
||||
|
||||
private volatile EntryListFilter<File> filterReference;
|
||||
private volatile FileListFilter<File> filterReference;
|
||||
|
||||
private volatile String filenamePattern;
|
||||
|
||||
@@ -39,14 +42,14 @@ public class FileListFilterFactoryBean implements FactoryBean<EntryListFilter<Fi
|
||||
|
||||
private final Object monitor = new Object();
|
||||
|
||||
private volatile Collection<EntryListFilter<File>> filterReferences;
|
||||
private volatile Collection<FileListFilter<File>> filterReferences;
|
||||
|
||||
|
||||
public void setFilterReferences(Collection<EntryListFilter<File>> filterReferences) {
|
||||
public void setFilterReferences(Collection<FileListFilter<File>> filterReferences) {
|
||||
this.filterReferences = filterReferences;
|
||||
}
|
||||
|
||||
public void setFilterReference(EntryListFilter<File> filterReference) {
|
||||
public void setFilterReference(FileListFilter<File> filterReference) {
|
||||
this.filterReference = filterReference;
|
||||
}
|
||||
|
||||
@@ -58,7 +61,7 @@ public class FileListFilterFactoryBean implements FactoryBean<EntryListFilter<Fi
|
||||
this.preventDuplicates = preventDuplicates;
|
||||
}
|
||||
|
||||
public EntryListFilter<File> getObject() throws Exception {
|
||||
public FileListFilter<File> getObject() throws Exception {
|
||||
if (this.fileListFilter == null) {
|
||||
synchronized (this.monitor) {
|
||||
this.intializeFileListFilter();
|
||||
@@ -68,7 +71,7 @@ public class FileListFilterFactoryBean implements FactoryBean<EntryListFilter<Fi
|
||||
}
|
||||
|
||||
public Class<?> getObjectType() {
|
||||
return (this.fileListFilter != null) ? this.fileListFilter.getClass() : EntryListFilter.class;
|
||||
return (this.fileListFilter != null) ? this.fileListFilter.getClass() : FileListFilter.class;
|
||||
}
|
||||
|
||||
public boolean isSingleton() {
|
||||
@@ -79,7 +82,7 @@ public class FileListFilterFactoryBean implements FactoryBean<EntryListFilter<Fi
|
||||
if (this.fileListFilter != null) {
|
||||
return;
|
||||
}
|
||||
EntryListFilter<File> filter;
|
||||
FileListFilter<File> filter;
|
||||
if ((this.filterReference != null) && (this.filenamePattern != null)) {
|
||||
throw new IllegalArgumentException("The 'filter' reference and "
|
||||
+ "'filename-pattern' attributes are mutually exclusive.");
|
||||
@@ -103,29 +106,29 @@ public class FileListFilterFactoryBean implements FactoryBean<EntryListFilter<Fi
|
||||
}
|
||||
}
|
||||
else if (Boolean.FALSE.equals(this.preventDuplicates)) {
|
||||
filter = new AcceptAllEntryListFilter<File>();
|
||||
filter = new AcceptAllFileListFilter<File>();
|
||||
}
|
||||
else { // preventDuplicates is either TRUE or NULL
|
||||
filter = new AcceptOnceEntryFileListFilter<File>();
|
||||
filter = new AcceptOnceFileListFilter<File>();
|
||||
}
|
||||
|
||||
// finally, it might be that they simply want a {@link CompositeEntryListFilter}
|
||||
// finally, it might be that they simply want a {@link CompositeFileListFilter}
|
||||
if ((this.filterReferences != null) && (this.filterReferences.size() > 0)) {
|
||||
CompositeEntryListFilter<File> compositeFilter = new CompositeEntryListFilter<File>();
|
||||
for (EntryListFilter<File> ff : filterReferences) {
|
||||
CompositeFileListFilter<File> compositeFilter = new CompositeFileListFilter<File>();
|
||||
for (FileListFilter<File> ff : filterReferences) {
|
||||
compositeFilter.addFilter(ff);
|
||||
}
|
||||
filter = compositeFilter;
|
||||
}
|
||||
if (filter == null) {
|
||||
filter = new CompositeEntryListFilter<File>();
|
||||
filter = new CompositeFileListFilter<File>();
|
||||
}
|
||||
this.fileListFilter = filter;
|
||||
}
|
||||
|
||||
private CompositeEntryListFilter<File> createCompositeWithAcceptOnceFilter(EntryListFilter<File> otherFilter) {
|
||||
CompositeEntryListFilter<File> compositeFilter = new CompositeEntryListFilter<File>();
|
||||
compositeFilter.addFilter(new AcceptOnceEntryFileListFilter<File>());
|
||||
private CompositeFileListFilter<File> createCompositeWithAcceptOnceFilter(FileListFilter<File> otherFilter) {
|
||||
CompositeFileListFilter<File> compositeFilter = new CompositeFileListFilter<File>();
|
||||
compositeFilter.addFilter(new AcceptOnceFileListFilter<File>());
|
||||
compositeFilter.addFilter(otherFilter);
|
||||
return compositeFilter;
|
||||
}
|
||||
|
||||
@@ -16,19 +16,19 @@
|
||||
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.integration.file.DirectoryScanner;
|
||||
import org.springframework.integration.file.FileReadingMessageSource;
|
||||
import org.springframework.integration.file.entries.CompositeEntryListFilter;
|
||||
import org.springframework.integration.file.entries.EntryListFilter;
|
||||
import org.springframework.integration.file.filters.CompositeFileListFilter;
|
||||
import org.springframework.integration.file.filters.FileListFilter;
|
||||
import org.springframework.integration.file.locking.AbstractFileLockerFilter;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Iwein Fuld
|
||||
@@ -42,7 +42,7 @@ public class FileReadingMessageSourceFactoryBean implements FactoryBean<FileRead
|
||||
|
||||
private volatile File directory;
|
||||
|
||||
private volatile EntryListFilter<File> filter;
|
||||
private volatile FileListFilter<File> filter;
|
||||
|
||||
private volatile AbstractFileLockerFilter locker;
|
||||
|
||||
@@ -71,7 +71,7 @@ public class FileReadingMessageSourceFactoryBean implements FactoryBean<FileRead
|
||||
this.scanner = scanner;
|
||||
}
|
||||
|
||||
public void setFilter(EntryListFilter<File> filter) {
|
||||
public void setFilter(FileListFilter<File> filter) {
|
||||
if (filter instanceof AbstractFileLockerFilter && (this.locker == null)) {
|
||||
this.setLocker((AbstractFileLockerFilter) filter);
|
||||
}
|
||||
@@ -137,10 +137,10 @@ public class FileReadingMessageSourceFactoryBean implements FactoryBean<FileRead
|
||||
this.source.setFilter(this.filter);
|
||||
}
|
||||
else {
|
||||
CompositeEntryListFilter<File> fileCompositeEntryListFilter = new CompositeEntryListFilter<File>();
|
||||
fileCompositeEntryListFilter.addFilter(this.filter);
|
||||
fileCompositeEntryListFilter.addFilter(this.locker);
|
||||
this.source.setFilter(fileCompositeEntryListFilter);
|
||||
CompositeFileListFilter<File> compositeFileListFilter = new CompositeFileListFilter<File>();
|
||||
compositeFileListFilter.addFilter(this.filter);
|
||||
compositeFileListFilter.addFilter(this.locker);
|
||||
this.source.setFilter(compositeFileListFilter);
|
||||
this.source.setLocker(locker);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 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,7 +16,6 @@
|
||||
|
||||
package org.springframework.integration.file.filters;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -27,19 +26,16 @@ import java.util.List;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Iwein Fuld
|
||||
*
|
||||
* @deprecated Replaced by AbstractEntryListFilter in 2.0.0
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class AbstractFileListFilter implements FileListFilter {
|
||||
public abstract class AbstractFileListFilter<F> implements FileListFilter<F> {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public final List<File> filterFiles(File[] files) {
|
||||
List<File> accepted = new ArrayList<File>();
|
||||
public final List<F> filterFiles(F[] files) {
|
||||
List<F> accepted = new ArrayList<F>();
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
for (F file : files) {
|
||||
if (this.accept(file)) {
|
||||
accepted.add(file);
|
||||
}
|
||||
@@ -51,6 +47,6 @@ public abstract class AbstractFileListFilter implements FileListFilter {
|
||||
/**
|
||||
* Subclasses must implement this method.
|
||||
*/
|
||||
protected abstract boolean accept(File file);
|
||||
protected abstract boolean accept(F file);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2002-2010 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.file.filters;
|
||||
|
||||
|
||||
/**
|
||||
* Simple implementation of {@link FileListFilter} that always returns true.
|
||||
* Suitable as a default.
|
||||
*
|
||||
* @author Iwein Fuld
|
||||
* @author Josh Long
|
||||
* @param <F>
|
||||
*/
|
||||
public class AcceptAllFileListFilter<F> extends AbstractFileListFilter<F> {
|
||||
|
||||
@Override
|
||||
public boolean accept(F file) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,14 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.file.filters;
|
||||
|
||||
import org.springframework.integration.file.entries.AcceptOnceEntryFileListFilter;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
/**
|
||||
* {@link FileListFilter} that passes files only one time. This can
|
||||
@@ -30,34 +27,46 @@ import java.util.List;
|
||||
* This implementation is thread safe.
|
||||
*
|
||||
* @author Iwein Fuld
|
||||
* @author Josh Long
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class AcceptOnceFileListFilter extends AcceptOnceEntryFileListFilter<File> implements FileListFilter{
|
||||
public class AcceptOnceFileListFilter<F> extends AbstractFileListFilter<F> {
|
||||
|
||||
/**
|
||||
* Creates an AcceptOnceFileFilter that is based on a bounded queue. If the
|
||||
* queue overflows, files that fall out will be passed through this filter
|
||||
* again if passed to the {@link #filterFiles(File[])} method.
|
||||
*
|
||||
* @param maxCapacity the maximum number of Files to maintain in the 'seen'
|
||||
* queue.
|
||||
*/
|
||||
public AcceptOnceFileListFilter(int maxCapacity) {
|
||||
super(maxCapacity);
|
||||
}
|
||||
private final Queue<F> seen;
|
||||
|
||||
private final Object monitor = new Object();
|
||||
|
||||
/**
|
||||
* Creates an AcceptOnceFileFilter based on an unbounded queue.
|
||||
*/
|
||||
public AcceptOnceFileListFilter() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter out all the files that this instance has seen before.
|
||||
* Creates an AcceptOnceFileListFilter that is based on a bounded queue. If the queue overflows,
|
||||
* files that fall out will be passed through this filter again if passed to the
|
||||
* {@link #filterFiles(Object[])}
|
||||
*
|
||||
* @param maxCapacity the maximum number of Files to maintain in the 'seen' queue.
|
||||
*/
|
||||
public List<File> filterFiles(File[] files) {
|
||||
Assert.notNull(files, "'files' must not be null.");
|
||||
return this.filterEntries(files);
|
||||
public AcceptOnceFileListFilter(int maxCapacity) {
|
||||
this.seen = new LinkedBlockingQueue<F>(maxCapacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an AcceptOnceFileListFilter based on an unbounded queue.
|
||||
*/
|
||||
public AcceptOnceFileListFilter() {
|
||||
this.seen = new LinkedBlockingQueue<F>();
|
||||
}
|
||||
|
||||
|
||||
public boolean accept(F file) {
|
||||
synchronized (this.monitor) {
|
||||
if (this.seen.contains(file)) {
|
||||
return false;
|
||||
}
|
||||
if (!this.seen.offer(file)) {
|
||||
this.seen.poll();
|
||||
this.seen.add(file);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -13,41 +13,82 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.file.filters;
|
||||
|
||||
import org.springframework.integration.file.entries.CompositeEntryListFilter;
|
||||
import org.springframework.integration.file.entries.EntryListFilter;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* Composition that delegates to multiple {@link FileFilter}s. The composition is AND based, meaning that a file must
|
||||
* pass through each filter's {@link #filterFiles(java.io.File[])} method in order to be accepted by the composite.
|
||||
* Simple {@link FileListFilter} that predicates its matches against any of many
|
||||
* configured {@link FileListFilter}.
|
||||
*
|
||||
* @author Iwein Fuld
|
||||
* @author Mark Fisher
|
||||
* @author Josh Long
|
||||
* @param <F>
|
||||
*/
|
||||
public class CompositeFileListFilter extends CompositeEntryListFilter<File> implements FileListFilter{
|
||||
public class CompositeFileListFilter<F> implements FileListFilter<F> {
|
||||
|
||||
public CompositeFileListFilter(EntryListFilter<File>... fileFilters) {
|
||||
this(Arrays.asList(fileFilters));
|
||||
}
|
||||
private final Set<FileListFilter<F>> fileFilters;
|
||||
|
||||
public CompositeFileListFilter(Collection<? extends EntryListFilter<File>> fileFilters) {
|
||||
super(fileFilters);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p/>
|
||||
* This implementation delegates to a collection of filters and returns only files that pass all the filters.
|
||||
*/
|
||||
public List<File> filterFiles(File[] files) {
|
||||
Assert.notNull(files, "'files' should not be null.");
|
||||
return this.filterEntries(files);
|
||||
}
|
||||
public CompositeFileListFilter() {
|
||||
this.fileFilters = new LinkedHashSet<FileListFilter<F>>();
|
||||
}
|
||||
|
||||
public CompositeFileListFilter(Collection<? extends FileListFilter<F>> fileFilters) {
|
||||
this.fileFilters = new LinkedHashSet<FileListFilter<F>>(fileFilters);
|
||||
}
|
||||
|
||||
|
||||
public CompositeFileListFilter<F> addFilter(FileListFilter<F> filter) {
|
||||
return this.addFilters(Collections.singletonList(filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param filters one or more new filters to add
|
||||
* @return this CompositeFileFilter instance with the added filters
|
||||
* @see #addFilters(Collection)
|
||||
*/
|
||||
public CompositeFileListFilter<F> addFilters(FileListFilter<F>... filters) {
|
||||
return addFilters(Arrays.asList(filters));
|
||||
}
|
||||
|
||||
/**
|
||||
* Not thread safe. Only a single thread may add filters at a time.
|
||||
* <p/>
|
||||
* Add the new filters to this CompositeFileListFilter while maintaining the existing filters.
|
||||
*
|
||||
* @param filtersToAdd a list of filters to add
|
||||
* @return this CompositeFileListFilter instance with the added filters
|
||||
*/
|
||||
public CompositeFileListFilter<F> addFilters(Collection<? extends FileListFilter<F>> filtersToAdd) {
|
||||
for (FileListFilter<? extends F> elf : filtersToAdd) {
|
||||
if (elf instanceof InitializingBean) {
|
||||
try {
|
||||
((InitializingBean) elf).afterPropertiesSet();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.fileFilters.addAll(filtersToAdd);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<F> filterFiles(F[] files) {
|
||||
Assert.notNull(files, "'files' should not be null");
|
||||
List<F> leftOver = Arrays.asList(files);
|
||||
for (FileListFilter<F> fileFilter : this.fileFilters) {
|
||||
F[] fileArray = (F[]) leftOver.toArray();
|
||||
leftOver = fileFilter.filterFiles(fileArray);
|
||||
}
|
||||
return leftOver;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 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,25 +16,23 @@
|
||||
|
||||
package org.springframework.integration.file.filters;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Strategy interface for filtering a group of files.
|
||||
* Strategy interface for filtering a group of files. This is a generic filter intended
|
||||
* to work with either local files or references to remote files.
|
||||
*
|
||||
* @author Iwein Fuld
|
||||
* @author Josh Long
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @see org.springframework.integration.file.entries.EntryListFilter
|
||||
*
|
||||
*/
|
||||
public interface FileListFilter {
|
||||
public interface FileListFilter<F> {
|
||||
|
||||
/**
|
||||
* Filters out files and returns the files that are left in a list, or an
|
||||
* empty list when a null is passed in.
|
||||
*/
|
||||
List<File> filterFiles(File[] files);
|
||||
List<F> filterFiles(F[] files);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 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,40 +16,65 @@
|
||||
|
||||
package org.springframework.integration.file.filters;
|
||||
|
||||
import org.springframework.integration.file.entries.FileEntryNameExtractor;
|
||||
import org.springframework.integration.file.entries.PatternMatchingEntryListFilter;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.integration.file.entries.EntryNameExtractor;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* An {@link org.springframework.integration.file.entries.EntryListFilter} implementation that matches a File against a {@link Pattern}.
|
||||
* Filters a listing of files by qualifying their 'name' (as determined by {@link org.springframework.integration.file.entries.EntryNameExtractor})
|
||||
* against a regular expression (an instance of {@link java.util.regex.Pattern})
|
||||
*
|
||||
* @author Iwein Fuld
|
||||
* @author Mark Fisher
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Josh Long
|
||||
* @param <F> the type of file entry
|
||||
* @since 2.0
|
||||
*/
|
||||
public class PatternMatchingFileListFilter extends PatternMatchingEntryListFilter<File> implements FileListFilter{
|
||||
public class PatternMatchingFileListFilter<F> extends AbstractFileListFilter<F> implements InitializingBean {
|
||||
|
||||
/**
|
||||
* Create a file filter for the given pattern.
|
||||
*/
|
||||
public PatternMatchingFileListFilter(Pattern pattern) {
|
||||
super(new FileEntryNameExtractor(), pattern);
|
||||
private volatile EntryNameExtractor<F> entryNameExtractor;
|
||||
|
||||
private volatile Pattern pattern;
|
||||
|
||||
private volatile String patternExpression;
|
||||
|
||||
|
||||
public PatternMatchingFileListFilter(EntryNameExtractor<F> entryNameExtractor, String pattern) {
|
||||
this.entryNameExtractor = entryNameExtractor;
|
||||
this.patternExpression = pattern;
|
||||
}
|
||||
|
||||
public PatternMatchingFileListFilter(String pattern) {
|
||||
super(new FileEntryNameExtractor(), pattern);
|
||||
public PatternMatchingFileListFilter(EntryNameExtractor<F> entryNameExtractor, Pattern pattern) {
|
||||
this.entryNameExtractor = entryNameExtractor;
|
||||
this.pattern = pattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter out the files of which the name doesn't match the pattern of this filter
|
||||
*/
|
||||
public List<File> filterFiles(File[] files) {
|
||||
Assert.notNull(files, "'files' must not be null.");
|
||||
return this.filterEntries(files);
|
||||
|
||||
public void setEntryNameExtractor(EntryNameExtractor<F> entryNameExtractor) {
|
||||
this.entryNameExtractor = entryNameExtractor;
|
||||
}
|
||||
|
||||
public void setPattern(Pattern pattern) {
|
||||
this.pattern = pattern;
|
||||
}
|
||||
|
||||
public void setPatternExpression(String patternExpression) {
|
||||
this.patternExpression = patternExpression;
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if (StringUtils.hasText(this.patternExpression) && (pattern == null)) {
|
||||
this.pattern = Pattern.compile(this.patternExpression);
|
||||
}
|
||||
Assert.notNull(this.entryNameExtractor, "'entryNameExtractor' must not be null!");
|
||||
Assert.notNull(this.pattern, "'pattern' must not be null!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(F entry) {
|
||||
return (entry != null) && this.pattern.matcher(this.entryNameExtractor.getName(entry)).matches();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,24 @@
|
||||
/*
|
||||
* Copyright 2002-2010 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.file.filters;
|
||||
|
||||
import org.springframework.integration.file.entries.AbstractEntryListFilter;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
|
||||
/**
|
||||
* Filter that supports ant style path expressions, which are less powerful but more readable than regular expressions.
|
||||
@@ -16,15 +29,18 @@ import java.util.List;
|
||||
* @see org.springframework.integration.file.filters.PatternMatchingFileListFilter
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public class SimplePatternFileListFilter extends AbstractEntryListFilter<File> implements FileListFilter {
|
||||
public class SimplePatternFileListFilter extends AbstractFileListFilter<File> {
|
||||
|
||||
private final AntPathMatcher matcher = new AntPathMatcher();
|
||||
|
||||
private final String path;
|
||||
|
||||
|
||||
public SimplePatternFileListFilter(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Accept the given file its name matches the pattern,
|
||||
*/
|
||||
@@ -33,8 +49,4 @@ public class SimplePatternFileListFilter extends AbstractEntryListFilter<File> i
|
||||
return matcher.match(path, file.getName());
|
||||
}
|
||||
|
||||
public List<File> filterFiles(File[] files) {
|
||||
Assert.notNull("'files' must not be null.");
|
||||
return this.filterEntries(files);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 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,11 +16,11 @@
|
||||
|
||||
package org.springframework.integration.file.locking;
|
||||
|
||||
import org.springframework.integration.file.FileLocker;
|
||||
import org.springframework.integration.file.entries.AbstractEntryListFilter;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.springframework.integration.file.FileLocker;
|
||||
import org.springframework.integration.file.filters.AbstractFileListFilter;
|
||||
|
||||
/**
|
||||
* Convenience base class for implementing FileLockers that check a lock before accepting a file. This is needed
|
||||
* when used in combination with a FileReadingMessageSource through a DirectoryScanner.
|
||||
@@ -29,10 +29,11 @@ import java.io.File;
|
||||
* @since 2.0
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractFileLockerFilter extends AbstractEntryListFilter<File> implements FileLocker {
|
||||
public abstract class AbstractFileLockerFilter extends AbstractFileListFilter<File> implements FileLocker {
|
||||
|
||||
@Override
|
||||
public boolean accept(File file) {
|
||||
return this.isLockable(file);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,27 +16,27 @@
|
||||
|
||||
package org.springframework.integration.file.synchronization;
|
||||
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.integration.MessagingException;
|
||||
import org.springframework.integration.endpoint.AbstractEndpoint;
|
||||
import org.springframework.integration.file.entries.AcceptAllEntryListFilter;
|
||||
import org.springframework.integration.file.entries.EntryListFilter;
|
||||
import org.springframework.integration.file.filters.AcceptAllFileListFilter;
|
||||
import org.springframework.integration.file.filters.FileListFilter;
|
||||
import org.springframework.scheduling.Trigger;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
/**
|
||||
* Base class charged with knowing how to connect to a remote file system,
|
||||
* scan it for new files and then download the files.
|
||||
* <p/>
|
||||
* The implementation should run through any configured
|
||||
* {@link org.springframework.integration.file.entries.EntryListFilter}s to
|
||||
* ensure the entry is acceptable.
|
||||
* {@link org.springframework.integration.file.filters.FileListFilter}s to
|
||||
* ensure the file entry is acceptable.
|
||||
*
|
||||
* @author Josh Long
|
||||
*/
|
||||
public abstract class AbstractInboundRemoteFileSystemSychronizer<T> extends AbstractEndpoint {
|
||||
public abstract class AbstractInboundRemoteFileSystemSychronizer<F> extends AbstractEndpoint {
|
||||
|
||||
/**
|
||||
* Should we <emphasis>delete</emphasis> the <b>source</b> file? For an FTP
|
||||
@@ -50,9 +50,9 @@ public abstract class AbstractInboundRemoteFileSystemSychronizer<T> extends Abst
|
||||
protected volatile Resource localDirectory;
|
||||
|
||||
/**
|
||||
* An {@link EntryListFilter} that runs against the <emphasis>remote</emphasis> file system view.
|
||||
* An {@link FileListFilter} that runs against the <emphasis>remote</emphasis> file system view.
|
||||
*/
|
||||
protected volatile EntryListFilter<T> filter = new AcceptAllEntryListFilter<T>();
|
||||
protected volatile FileListFilter<F> filter = new AcceptAllFileListFilter<F>();
|
||||
|
||||
/**
|
||||
* The {@link ScheduledFuture} instance we get when we
|
||||
@@ -63,10 +63,10 @@ public abstract class AbstractInboundRemoteFileSystemSychronizer<T> extends Abst
|
||||
/**
|
||||
* The {@link EntryAcknowledgmentStrategy} implementation.
|
||||
*/
|
||||
protected EntryAcknowledgmentStrategy<T> entryAcknowledgmentStrategy;
|
||||
protected EntryAcknowledgmentStrategy<F> entryAcknowledgmentStrategy;
|
||||
|
||||
|
||||
public void setEntryAcknowledgmentStrategy(EntryAcknowledgmentStrategy<T> entryAcknowledgmentStrategy) {
|
||||
public void setEntryAcknowledgmentStrategy(EntryAcknowledgmentStrategy<F> entryAcknowledgmentStrategy) {
|
||||
this.entryAcknowledgmentStrategy = entryAcknowledgmentStrategy;
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ public abstract class AbstractInboundRemoteFileSystemSychronizer<T> extends Abst
|
||||
this.localDirectory = localDirectory;
|
||||
}
|
||||
|
||||
public void setFilter(EntryListFilter<T> filter) {
|
||||
public void setFilter(FileListFilter<F> filter) {
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
@@ -90,16 +90,16 @@ public abstract class AbstractInboundRemoteFileSystemSychronizer<T> extends Abst
|
||||
* be a 'live' stateful client (a connection?) that is inappropriate to cache as it has per-request state.
|
||||
* @param t
|
||||
* leverages strategy implementations to enable different
|
||||
* behavior. It's a hook to the entry ({@link T}) after it's been
|
||||
* behavior. It's a hook to the file entry ({@link F}) after it's been
|
||||
* successfully downloaded. Conceptually, you might delete the
|
||||
* remote one or rename it, etc.
|
||||
* @throws Throwable
|
||||
* escape hatch exception, let the adapter deal with it.
|
||||
*/
|
||||
protected void acknowledge(Object usefulContextOrClientData, T t) throws Throwable {
|
||||
protected void acknowledge(Object usefulContextOrClientData, F file) throws Throwable {
|
||||
Assert.notNull(this.entryAcknowledgmentStrategy != null,
|
||||
"entryAcknowledgmentStrategy can't be null!");
|
||||
this.entryAcknowledgmentStrategy.acknowledge(usefulContextOrClientData, t);
|
||||
this.entryAcknowledgmentStrategy.acknowledge(usefulContextOrClientData, file);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,8 +107,8 @@ public abstract class AbstractInboundRemoteFileSystemSychronizer<T> extends Abst
|
||||
*/
|
||||
protected void doStart() {
|
||||
if (this.entryAcknowledgmentStrategy == null) {
|
||||
this.entryAcknowledgmentStrategy = new EntryAcknowledgmentStrategy<T>() {
|
||||
public void acknowledge(Object o, T msg) {
|
||||
this.entryAcknowledgmentStrategy = new EntryAcknowledgmentStrategy<F>() {
|
||||
public void acknowledge(Object o, F msg) {
|
||||
// no-op
|
||||
}
|
||||
};
|
||||
@@ -167,9 +167,9 @@ public abstract class AbstractInboundRemoteFileSystemSychronizer<T> extends Abst
|
||||
* into the pipeline and also some more advanced scenarios (i.e., 'move file
|
||||
* to another folder on delete ', or 'rename on delete')
|
||||
*
|
||||
* @param <T> the entry type (file, sftp, ftp, ...)
|
||||
* @param <F> the file entry type (file, sftp, ftp, ...)
|
||||
*/
|
||||
public static interface EntryAcknowledgmentStrategy<T> {
|
||||
public static interface EntryAcknowledgmentStrategy<F> {
|
||||
|
||||
/**
|
||||
* Semantics are simple. You get a pointer to the entry just processed
|
||||
@@ -183,7 +183,7 @@ public abstract class AbstractInboundRemoteFileSystemSychronizer<T> extends Abst
|
||||
* the data / file / entry you want to process -- specific to subclasses
|
||||
* @throws Exception in case of an error while acknowledging
|
||||
*/
|
||||
void acknowledge(Object useful, T msg) throws Exception;
|
||||
void acknowledge(Object useful, F msg) throws Exception;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -27,11 +27,11 @@ import org.springframework.integration.MessagingException;
|
||||
import org.springframework.integration.core.MessageSource;
|
||||
import org.springframework.integration.endpoint.MessageProducerSupport;
|
||||
import org.springframework.integration.file.FileReadingMessageSource;
|
||||
import org.springframework.integration.file.entries.AcceptOnceEntryFileListFilter;
|
||||
import org.springframework.integration.file.entries.CompositeEntryListFilter;
|
||||
import org.springframework.integration.file.entries.EntryListFilter;
|
||||
import org.springframework.integration.file.entries.FileEntryNameExtractor;
|
||||
import org.springframework.integration.file.entries.PatternMatchingEntryListFilter;
|
||||
import org.springframework.integration.file.filters.AcceptOnceFileListFilter;
|
||||
import org.springframework.integration.file.filters.CompositeFileListFilter;
|
||||
import org.springframework.integration.file.filters.FileListFilter;
|
||||
import org.springframework.integration.file.filters.PatternMatchingFileListFilter;
|
||||
|
||||
/**
|
||||
* Factors out the common logic between the FTP and SFTP adapters. Designed to
|
||||
@@ -43,7 +43,7 @@ import org.springframework.integration.file.entries.PatternMatchingEntryListFilt
|
||||
* <p/>
|
||||
* The base class supports configuration of whether the remote file system and
|
||||
* local file system's directories should be created on start (what 'creating a
|
||||
* directory' means to the specific adapter is of course implementaton
|
||||
* directory' means to the specific adapter is of course implementation
|
||||
* specific).
|
||||
* <p/>
|
||||
* This class is to be used as a pair with an implementation of
|
||||
@@ -53,7 +53,7 @@ import org.springframework.integration.file.entries.PatternMatchingEntryListFilt
|
||||
*
|
||||
* @author Josh Long
|
||||
*/
|
||||
public abstract class AbstractInboundRemoteFileSystemSynchronizingMessageSource<Y, T extends AbstractInboundRemoteFileSystemSychronizer<Y>>
|
||||
public abstract class AbstractInboundRemoteFileSystemSynchronizingMessageSource<F, S extends AbstractInboundRemoteFileSystemSychronizer<F>>
|
||||
extends MessageProducerSupport implements MessageSource<File> {
|
||||
|
||||
/**
|
||||
@@ -70,7 +70,7 @@ public abstract class AbstractInboundRemoteFileSystemSynchronizingMessageSource<
|
||||
* An implementation that will handle the chores of actually connecting to and synching up
|
||||
* the remote file system with the local one, in an inbound direction.
|
||||
*/
|
||||
protected volatile T synchronizer;
|
||||
protected volatile S synchronizer;
|
||||
|
||||
/**
|
||||
* Directory to which things should be synched locally.
|
||||
@@ -85,14 +85,14 @@ public abstract class AbstractInboundRemoteFileSystemSynchronizingMessageSource<
|
||||
/**
|
||||
* The predicate to use in scanning the remote File system for downloads.
|
||||
*/
|
||||
protected EntryListFilter<Y> remotePredicate;
|
||||
protected FileListFilter<F> remotePredicate;
|
||||
|
||||
|
||||
public void setAutoCreateDirectories(boolean autoCreateDirectories) {
|
||||
this.autoCreateDirectories = autoCreateDirectories;
|
||||
}
|
||||
|
||||
public void setSynchronizer(T synchronizer) {
|
||||
public void setSynchronizer(S synchronizer) {
|
||||
this.synchronizer = synchronizer;
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ public abstract class AbstractInboundRemoteFileSystemSynchronizingMessageSource<
|
||||
this.localDirectory = localDirectory;
|
||||
}
|
||||
|
||||
public void setRemotePredicate(EntryListFilter<Y> remotePredicate) {
|
||||
public void setRemotePredicate(FileListFilter<F> remotePredicate) {
|
||||
this.remotePredicate = remotePredicate;
|
||||
}
|
||||
|
||||
@@ -154,12 +154,12 @@ public abstract class AbstractInboundRemoteFileSystemSynchronizingMessageSource<
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private EntryListFilter<File> buildFilter() {
|
||||
private FileListFilter<File> buildFilter() {
|
||||
FileEntryNameExtractor fileEntryNameExtractor = new FileEntryNameExtractor();
|
||||
Pattern completePattern = Pattern.compile("^.*(?<!" + INCOMPLETE_EXTENSION + ")$");
|
||||
return new CompositeEntryListFilter<File>(Arrays.asList(
|
||||
new AcceptOnceEntryFileListFilter<File>(),
|
||||
new PatternMatchingEntryListFilter<File>(fileEntryNameExtractor, completePattern)));
|
||||
return new CompositeFileListFilter<File>(Arrays.asList(
|
||||
new AcceptOnceFileListFilter<File>(),
|
||||
new PatternMatchingFileListFilter<File>(fileEntryNameExtractor, completePattern)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 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,18 +16,22 @@
|
||||
|
||||
package org.springframework.integration.file;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.integration.file.entries.CompositeEntryListFilter;
|
||||
import org.springframework.integration.file.entries.EntryListFilter;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.isA;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.*;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.file.filters.CompositeFileListFilter;
|
||||
import org.springframework.integration.file.filters.FileListFilter;
|
||||
|
||||
/**
|
||||
* @author Iwein Fuld
|
||||
@@ -35,46 +39,46 @@ import static org.mockito.Mockito.*;
|
||||
public class CompositeFileListFilterTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private EntryListFilter<File> fileFilterMock1 = mock(EntryListFilter.class);
|
||||
private FileListFilter<File> fileFilterMock1 = mock(FileListFilter.class);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private EntryListFilter<File> fileFilterMock2 = mock(EntryListFilter.class);
|
||||
private FileListFilter<File> fileFilterMock2 = mock(FileListFilter.class);
|
||||
|
||||
private File fileMock = mock(File.class);
|
||||
|
||||
@Test
|
||||
public void forwardedToFilters() throws Exception {
|
||||
CompositeEntryListFilter<File> compositeFileFilter = new CompositeEntryListFilter<File>();
|
||||
compositeFileFilter .addFilter(fileFilterMock1);compositeFileFilter.addFilter( fileFilterMock2);
|
||||
CompositeFileListFilter<File> compositeFileFilter = new CompositeFileListFilter<File>();
|
||||
compositeFileFilter .addFilter(fileFilterMock1);compositeFileFilter.addFilter(fileFilterMock2);
|
||||
List<File> returnedFiles = Arrays.asList( fileMock);
|
||||
when(fileFilterMock1.filterEntries(isA(File[].class))).thenReturn(returnedFiles);
|
||||
when(fileFilterMock2.filterEntries(isA(File[].class))).thenReturn(returnedFiles);
|
||||
assertEquals(returnedFiles, compositeFileFilter.filterEntries(new File[]{fileMock}));
|
||||
verify(fileFilterMock1).filterEntries(isA(File[].class));
|
||||
verify(fileFilterMock2).filterEntries(isA(File[].class));
|
||||
when(fileFilterMock1.filterFiles(isA(File[].class))).thenReturn(returnedFiles);
|
||||
when(fileFilterMock2.filterFiles(isA(File[].class))).thenReturn(returnedFiles);
|
||||
assertEquals(returnedFiles, compositeFileFilter.filterFiles(new File[]{fileMock}));
|
||||
verify(fileFilterMock1).filterFiles(isA(File[].class));
|
||||
verify(fileFilterMock2).filterFiles(isA(File[].class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forwardedToAddedFilters() throws Exception {
|
||||
CompositeEntryListFilter<File> compositeFileFilter = new CompositeEntryListFilter<File>();
|
||||
CompositeFileListFilter<File> compositeFileFilter = new CompositeFileListFilter<File>();
|
||||
compositeFileFilter.addFilter(fileFilterMock1);
|
||||
compositeFileFilter.addFilter( fileFilterMock2);
|
||||
List<File> returnedFiles = Arrays.asList(fileMock);
|
||||
when(fileFilterMock1.filterEntries(isA(File[].class))).thenReturn(returnedFiles);
|
||||
when(fileFilterMock2.filterEntries(isA(File[].class))).thenReturn(returnedFiles);
|
||||
assertEquals(returnedFiles, compositeFileFilter.filterEntries(new File[]{fileMock}));
|
||||
verify(fileFilterMock1).filterEntries(isA(File[].class));
|
||||
verify(fileFilterMock2).filterEntries(isA(File[].class));
|
||||
when(fileFilterMock1.filterFiles(isA(File[].class))).thenReturn(returnedFiles);
|
||||
when(fileFilterMock2.filterFiles(isA(File[].class))).thenReturn(returnedFiles);
|
||||
assertEquals(returnedFiles, compositeFileFilter.filterFiles(new File[]{fileMock}));
|
||||
verify(fileFilterMock1).filterFiles(isA(File[].class));
|
||||
verify(fileFilterMock2).filterFiles(isA(File[].class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void negative() throws Exception {
|
||||
CompositeEntryListFilter<File> compositeFileFilter = new CompositeEntryListFilter<File>();
|
||||
CompositeFileListFilter<File> compositeFileFilter = new CompositeFileListFilter<File>();
|
||||
compositeFileFilter.addFilter(fileFilterMock1);
|
||||
compositeFileFilter.addFilter(fileFilterMock2);
|
||||
|
||||
when(fileFilterMock2.filterEntries(isA(File[].class))).thenReturn(new ArrayList<File>());
|
||||
when(fileFilterMock1.filterEntries(isA(File[].class))).thenReturn(new ArrayList<File>());
|
||||
assertTrue(compositeFileFilter.filterEntries(new File[]{fileMock}).isEmpty());
|
||||
when(fileFilterMock2.filterFiles(isA(File[].class))).thenReturn(new ArrayList<File>());
|
||||
when(fileFilterMock1.filterFiles(isA(File[].class))).thenReturn(new ArrayList<File>());
|
||||
assertTrue(compositeFileFilter.filterFiles(new File[]{fileMock}).isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,12 @@
|
||||
<bean id="entryNameExtractor" class="org.springframework.integration.file.entries.FileEntryNameExtractor"/>
|
||||
|
||||
<!-- customized filter -->
|
||||
<bean id="legacyCompositeFilter" class="org.springframework.integration.file.entries.CompositeEntryListFilter">
|
||||
<bean id="legacyCompositeFilter" class="org.springframework.integration.file.filters.CompositeFileListFilter">
|
||||
<constructor-arg>
|
||||
<list>
|
||||
<bean class="org.springframework.integration.file.entries.AcceptOnceEntryFileListFilter"/>
|
||||
<bean class="org.springframework.integration.file.filters.AcceptOnceFileListFilter"/>
|
||||
<bean class="org.springframework.integration.file.TestFileListFilter"/>
|
||||
<bean class="org.springframework.integration.file.entries.PatternMatchingEntryListFilter">
|
||||
<bean class="org.springframework.integration.file.filters.PatternMatchingFileListFilter">
|
||||
<constructor-arg ref="entryNameExtractor"/>
|
||||
<constructor-arg value="test*"/>
|
||||
</bean>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 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,21 @@
|
||||
|
||||
package org.springframework.integration.file;
|
||||
|
||||
import org.junit.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.integration.Message;
|
||||
@@ -25,11 +38,6 @@ import org.springframework.test.annotation.Repeat;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Iwein Fuld
|
||||
*/
|
||||
|
||||
@@ -16,19 +16,21 @@
|
||||
|
||||
package org.springframework.integration.file;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.file.entries.EntryListFilter;
|
||||
import org.springframework.integration.file.entries.FileEntryNameExtractor;
|
||||
import org.springframework.integration.file.entries.PatternMatchingEntryListFilter;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.file.entries.FileEntryNameExtractor;
|
||||
import org.springframework.integration.file.entries.PatternMatchingEntryListFilter;
|
||||
import org.springframework.integration.file.filters.FileListFilter;
|
||||
import org.springframework.integration.file.filters.PatternMatchingFileListFilter;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -41,8 +43,8 @@ public class PatternMatchingFileListFilterTests {
|
||||
public void matchSingleFile() {
|
||||
File[] files = new File[]{new File("/some/path/test.txt")};
|
||||
Pattern pattern = Pattern.compile("[a-z]+\\.txt");
|
||||
PatternMatchingEntryListFilter<File> filter = new PatternMatchingEntryListFilter<File>(fileEntryNameExtractor, pattern);
|
||||
List<File> accepted = filter.filterEntries(files);
|
||||
PatternMatchingFileListFilter<File> filter = new PatternMatchingFileListFilter<File>(fileEntryNameExtractor, pattern);
|
||||
List<File> accepted = filter.filterFiles(files);
|
||||
assertEquals(1, accepted.size());
|
||||
}
|
||||
|
||||
@@ -50,8 +52,8 @@ public class PatternMatchingFileListFilterTests {
|
||||
public void noMatchWithSingleFile() {
|
||||
File[] files = new File[]{new File("/some/path/Test.txt")};
|
||||
Pattern pattern = Pattern.compile("[a-z]+\\.txt");
|
||||
PatternMatchingEntryListFilter<File> filter = new PatternMatchingEntryListFilter<File>(fileEntryNameExtractor, pattern);
|
||||
List<File> accepted = filter.filterEntries(files);
|
||||
PatternMatchingFileListFilter<File> filter = new PatternMatchingFileListFilter<File>(fileEntryNameExtractor, pattern);
|
||||
List<File> accepted = filter.filterFiles(files);
|
||||
assertEquals(0, accepted.size());
|
||||
}
|
||||
|
||||
@@ -77,9 +79,9 @@ public class PatternMatchingFileListFilterTests {
|
||||
public void patternEditorInContext() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"patternMatchingFileListFilterTests.xml", this.getClass());
|
||||
EntryListFilter<File> filter = (EntryListFilter<File>) context.getBean("filter");
|
||||
File[] files = new File[]{new File("/some/path/foo.txt")};
|
||||
List<File> accepted = filter.filterEntries(files);
|
||||
FileListFilter<File> filter = (FileListFilter<File>) context.getBean("filter");
|
||||
File[] files = new File[] { new File("/some/path/foo.txt") };
|
||||
List<File> accepted = filter.filterFiles(files);
|
||||
assertEquals(1, accepted.size());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 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,17 +16,19 @@
|
||||
|
||||
package org.springframework.integration.file;
|
||||
|
||||
import org.springframework.integration.file.entries.EntryListFilter;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.integration.file.filters.FileListFilter;
|
||||
|
||||
/**
|
||||
* @author Iwein Fuld
|
||||
*/
|
||||
public class TestFileListFilter implements EntryListFilter<File> {
|
||||
public List<File> filterEntries(File[] entries) {
|
||||
public class TestFileListFilter implements FileListFilter<File> {
|
||||
|
||||
public List<File> filterFiles(File[] entries) {
|
||||
return Arrays.asList(entries);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,25 +16,28 @@
|
||||
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Comparator;
|
||||
import java.util.concurrent.PriorityBlockingQueue;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.integration.channel.AbstractMessageChannel;
|
||||
import org.springframework.integration.file.DefaultDirectoryScanner;
|
||||
import org.springframework.integration.file.FileReadingMessageSource;
|
||||
import org.springframework.integration.file.entries.AcceptOnceEntryFileListFilter;
|
||||
import org.springframework.integration.file.filters.AcceptOnceFileListFilter;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Comparator;
|
||||
import java.util.concurrent.PriorityBlockingQueue;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Iwein Fuld
|
||||
* @author Mark Fisher
|
||||
@@ -76,7 +79,7 @@ public class FileInboundChannelAdapterParserTests {
|
||||
DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(scanner);
|
||||
Object filter = scannerAccessor.getPropertyValue("filter");
|
||||
assertTrue("'filter' should be set",
|
||||
filter instanceof AcceptOnceEntryFileListFilter);
|
||||
filter instanceof AcceptOnceFileListFilter);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,8 +16,17 @@
|
||||
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@@ -25,18 +34,13 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.integration.channel.AbstractMessageChannel;
|
||||
import org.springframework.integration.endpoint.AbstractEndpoint;
|
||||
import org.springframework.integration.file.FileReadingMessageSource;
|
||||
import org.springframework.integration.file.entries.AcceptOnceEntryFileListFilter;
|
||||
import org.springframework.integration.file.entries.CompositeEntryListFilter;
|
||||
import org.springframework.integration.file.entries.EntryListFilter;
|
||||
import org.springframework.integration.file.filters.AcceptOnceFileListFilter;
|
||||
import org.springframework.integration.file.filters.CompositeFileListFilter;
|
||||
import org.springframework.integration.file.filters.FileListFilter;
|
||||
import org.springframework.integration.file.filters.SimplePatternFileListFilter;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Iwein Fuld
|
||||
@@ -83,15 +87,14 @@ public class FileInboundChannelAdapterWithPatternParserTests {
|
||||
@Test
|
||||
public void compositeFilterType() {
|
||||
DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(accessor.getPropertyValue("scanner"));
|
||||
assertTrue(scannerAccessor.getPropertyValue("filter") instanceof CompositeEntryListFilter);
|
||||
assertTrue(scannerAccessor.getPropertyValue("filter") instanceof CompositeFileListFilter);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void compositeFilterSetSize() {
|
||||
DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(accessor.getPropertyValue("scanner"));
|
||||
|
||||
Set<EntryListFilter<File>> filters = (Set<EntryListFilter<File>>) new DirectFieldAccessor(
|
||||
Set<FileListFilter<File>> filters = (Set<FileListFilter<File>>) new DirectFieldAccessor(
|
||||
scannerAccessor.getPropertyValue("filter")).getPropertyValue("fileFilters");
|
||||
assertEquals(2, filters.size());
|
||||
}
|
||||
@@ -100,12 +103,11 @@ public class FileInboundChannelAdapterWithPatternParserTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void acceptOnceFilter() {
|
||||
DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(accessor.getPropertyValue("scanner"));
|
||||
|
||||
Set<EntryListFilter<File>> filters = (Set<EntryListFilter<File>>) new DirectFieldAccessor(
|
||||
Set<FileListFilter<File>> filters = (Set<FileListFilter<File>>) new DirectFieldAccessor(
|
||||
scannerAccessor.getPropertyValue("filter")).getPropertyValue("fileFilters");
|
||||
boolean hasAcceptOnceFilter = false;
|
||||
for (EntryListFilter<File> filter : filters) {
|
||||
if (filter instanceof AcceptOnceEntryFileListFilter) {
|
||||
for (FileListFilter<File> filter : filters) {
|
||||
if (filter instanceof AcceptOnceFileListFilter) {
|
||||
hasAcceptOnceFilter = true;
|
||||
}
|
||||
}
|
||||
@@ -116,10 +118,10 @@ public class FileInboundChannelAdapterWithPatternParserTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void patternFilter() {
|
||||
DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(accessor.getPropertyValue("scanner"));
|
||||
Set<EntryListFilter<?>> filters = (Set<EntryListFilter<?>>) new DirectFieldAccessor(
|
||||
Set<FileListFilter<?>> filters = (Set<FileListFilter<?>>) new DirectFieldAccessor(
|
||||
scannerAccessor.getPropertyValue("filter")).getPropertyValue("fileFilters");
|
||||
String pattern = null;
|
||||
for (EntryListFilter<?> filter : filters) {
|
||||
for (FileListFilter<?> filter : filters) {
|
||||
if (filter instanceof SimplePatternFileListFilter) {
|
||||
pattern = (String) new DirectFieldAccessor(filter).getPropertyValue("path");
|
||||
}
|
||||
|
||||
@@ -16,27 +16,33 @@
|
||||
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.integration.file.TestFileListFilter;
|
||||
import org.springframework.integration.file.entries.AcceptOnceEntryFileListFilter;
|
||||
import org.springframework.integration.file.entries.CompositeEntryListFilter;
|
||||
import org.springframework.integration.file.entries.EntryListFilter;
|
||||
import org.springframework.integration.file.filters.SimplePatternFileListFilter;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.integration.file.TestFileListFilter;
|
||||
import org.springframework.integration.file.filters.AcceptOnceFileListFilter;
|
||||
import org.springframework.integration.file.filters.CompositeFileListFilter;
|
||||
import org.springframework.integration.file.filters.FileListFilter;
|
||||
import org.springframework.integration.file.filters.SimplePatternFileListFilter;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -55,98 +61,98 @@ public class FileInboundChannelAdapterWithPreventDuplicatesFlagTests {
|
||||
|
||||
@Test
|
||||
public void filterAndNull() {
|
||||
EntryListFilter<?> filter = this.extractFilter("filterAndNull");
|
||||
assertFalse(filter instanceof CompositeEntryListFilter);
|
||||
FileListFilter<?> filter = this.extractFilter("filterAndNull");
|
||||
assertFalse(filter instanceof CompositeFileListFilter);
|
||||
assertSame(testFilter, filter);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterAndTrue() {
|
||||
EntryListFilter<?> filter = this.extractFilter("filterAndTrue");
|
||||
assertTrue(filter instanceof CompositeEntryListFilter);
|
||||
FileListFilter<?> filter = this.extractFilter("filterAndTrue");
|
||||
assertTrue(filter instanceof CompositeFileListFilter);
|
||||
Collection<?> filters = (Collection<?>) new DirectFieldAccessor(filter).getPropertyValue("fileFilters");
|
||||
assertTrue(filters.iterator().next() instanceof AcceptOnceEntryFileListFilter);
|
||||
assertTrue(filters.iterator().next() instanceof AcceptOnceFileListFilter);
|
||||
assertTrue(filters.contains(testFilter));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterAndFalse() throws Exception {
|
||||
EntryListFilter<?> filter = this.extractFilter("filterAndFalse");
|
||||
assertFalse(filter instanceof CompositeEntryListFilter);
|
||||
FileListFilter<?> filter = this.extractFilter("filterAndFalse");
|
||||
assertFalse(filter instanceof CompositeFileListFilter);
|
||||
assertSame(testFilter, filter);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void patternAndNull() throws Exception {
|
||||
EntryListFilter<?> filter = this.extractFilter("patternAndNull");
|
||||
assertTrue(filter instanceof CompositeEntryListFilter);
|
||||
Collection<EntryListFilter<File>> filters = (Collection<EntryListFilter<File>>)
|
||||
FileListFilter<?> filter = this.extractFilter("patternAndNull");
|
||||
assertTrue(filter instanceof CompositeFileListFilter);
|
||||
Collection<FileListFilter<File>> filters = (Collection<FileListFilter<File>>)
|
||||
new DirectFieldAccessor(filter).getPropertyValue("fileFilters");
|
||||
Iterator<EntryListFilter<File>> iterator = filters.iterator();
|
||||
assertTrue(iterator.next() instanceof AcceptOnceEntryFileListFilter);
|
||||
Iterator<FileListFilter<File>> iterator = filters.iterator();
|
||||
assertTrue(iterator.next() instanceof AcceptOnceFileListFilter);
|
||||
assertThat(iterator.next(), is(SimplePatternFileListFilter.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void patternAndTrue() throws Exception {
|
||||
EntryListFilter<?> filter = this.extractFilter("patternAndTrue");
|
||||
assertTrue(filter instanceof CompositeEntryListFilter);
|
||||
Collection<EntryListFilter<File>> filters = (Collection<EntryListFilter<File>>)
|
||||
FileListFilter<?> filter = this.extractFilter("patternAndTrue");
|
||||
assertTrue(filter instanceof CompositeFileListFilter);
|
||||
Collection<FileListFilter<File>> filters = (Collection<FileListFilter<File>>)
|
||||
new DirectFieldAccessor(filter).getPropertyValue("fileFilters");
|
||||
Iterator<EntryListFilter<File>> iterator = filters.iterator();
|
||||
assertTrue(iterator.next() instanceof AcceptOnceEntryFileListFilter);
|
||||
Iterator<FileListFilter<File>> iterator = filters.iterator();
|
||||
assertTrue(iterator.next() instanceof AcceptOnceFileListFilter);
|
||||
assertThat(iterator.next(), is(SimplePatternFileListFilter.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void patternAndFalse() throws Exception {
|
||||
EntryListFilter<File> filter = this.extractFilter("patternAndFalse");
|
||||
assertFalse(filter instanceof CompositeEntryListFilter);
|
||||
FileListFilter<File> filter = this.extractFilter("patternAndFalse");
|
||||
assertFalse(filter instanceof CompositeFileListFilter);
|
||||
assertThat(filter, is(SimplePatternFileListFilter.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultAndNull() throws Exception {
|
||||
EntryListFilter<File> filter = this.extractFilter("defaultAndNull");
|
||||
FileListFilter<File> filter = this.extractFilter("defaultAndNull");
|
||||
assertNotNull(filter);
|
||||
assertFalse(filter instanceof CompositeEntryListFilter);
|
||||
assertTrue(filter instanceof AcceptOnceEntryFileListFilter);
|
||||
assertFalse(filter instanceof CompositeFileListFilter);
|
||||
assertTrue(filter instanceof AcceptOnceFileListFilter);
|
||||
|
||||
File testFile = new File("test");
|
||||
File[] files = new File[] { testFile, testFile, testFile };
|
||||
List<File> result = filter.filterEntries(files);
|
||||
List<File> result = filter.filterFiles(files);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultAndTrue() throws Exception {
|
||||
EntryListFilter<File> filter = this.extractFilter("defaultAndTrue");
|
||||
assertFalse(filter instanceof CompositeEntryListFilter);
|
||||
assertTrue(filter instanceof AcceptOnceEntryFileListFilter);
|
||||
FileListFilter<File> filter = this.extractFilter("defaultAndTrue");
|
||||
assertFalse(filter instanceof CompositeFileListFilter);
|
||||
assertTrue(filter instanceof AcceptOnceFileListFilter);
|
||||
File testFile = new File("test");
|
||||
File[] files = new File[] { testFile, testFile, testFile };
|
||||
List<File> result = filter.filterEntries(files);
|
||||
List<File> result = filter.filterFiles(files);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultAndFalse() throws Exception {
|
||||
EntryListFilter<File> filter = this.extractFilter("defaultAndFalse");
|
||||
FileListFilter<File> filter = this.extractFilter("defaultAndFalse");
|
||||
assertNotNull(filter);
|
||||
assertFalse(filter instanceof CompositeEntryListFilter);
|
||||
assertFalse(filter instanceof AcceptOnceEntryFileListFilter);
|
||||
assertFalse(filter instanceof CompositeFileListFilter);
|
||||
assertFalse(filter instanceof AcceptOnceFileListFilter);
|
||||
File testFile = new File("test");
|
||||
File[] files = new File[] { testFile, testFile, testFile };
|
||||
List<File> result = filter.filterEntries(files);
|
||||
List<File> result = filter.filterFiles(files);
|
||||
assertEquals(3, result.size());
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private EntryListFilter<File> extractFilter(String beanName) {
|
||||
return (EntryListFilter<File>)
|
||||
private FileListFilter<File> extractFilter(String beanName) {
|
||||
return (FileListFilter<File>)
|
||||
new DirectFieldAccessor(
|
||||
new DirectFieldAccessor(
|
||||
new DirectFieldAccessor(context.getBean(beanName))
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
</inbound-channel-adapter>
|
||||
<beans:bean class="org.springframework.integration.file.config.FileListFilterFactoryBean" />
|
||||
|
||||
<beans:bean id="filter" class="org.springframework.integration.file.entries.CompositeEntryListFilter">
|
||||
<beans:bean id="filter" class="org.springframework.integration.file.filters.CompositeFileListFilter">
|
||||
<beans:constructor-arg>
|
||||
<beans:list></beans:list>
|
||||
</beans:constructor-arg>
|
||||
|
||||
@@ -16,17 +16,24 @@
|
||||
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.integration.file.entries.*;
|
||||
import org.springframework.integration.file.filters.SimplePatternFileListFilter;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.integration.file.filters.AbstractFileListFilter;
|
||||
import org.springframework.integration.file.filters.AcceptOnceFileListFilter;
|
||||
import org.springframework.integration.file.filters.CompositeFileListFilter;
|
||||
import org.springframework.integration.file.filters.FileListFilter;
|
||||
import org.springframework.integration.file.filters.SimplePatternFileListFilter;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -47,8 +54,8 @@ public class FileListFilterFactoryBeanTests {
|
||||
FileListFilterFactoryBean factory = new FileListFilterFactoryBean();
|
||||
TestFilter testFilter = new TestFilter();
|
||||
factory.setFilterReference(testFilter);
|
||||
EntryListFilter<File> result = factory.getObject();
|
||||
assertFalse(result instanceof CompositeEntryListFilter);
|
||||
FileListFilter<File> result = factory.getObject();
|
||||
assertFalse(result instanceof CompositeFileListFilter);
|
||||
assertSame(testFilter, result);
|
||||
}
|
||||
|
||||
@@ -58,10 +65,10 @@ public class FileListFilterFactoryBeanTests {
|
||||
TestFilter testFilter = new TestFilter();
|
||||
factory.setFilterReference(testFilter);
|
||||
factory.setPreventDuplicates(Boolean.TRUE);
|
||||
EntryListFilter<File> result = factory.getObject();
|
||||
assertTrue(result instanceof CompositeEntryListFilter);
|
||||
FileListFilter<File> result = factory.getObject();
|
||||
assertTrue(result instanceof CompositeFileListFilter);
|
||||
Collection<?> filters = (Collection<?>) new DirectFieldAccessor(result).getPropertyValue("fileFilters");
|
||||
assertTrue(filters.iterator().next() instanceof AcceptOnceEntryFileListFilter);
|
||||
assertTrue(filters.iterator().next() instanceof AcceptOnceFileListFilter);
|
||||
assertTrue(filters.contains(testFilter));
|
||||
}
|
||||
|
||||
@@ -71,8 +78,8 @@ public class FileListFilterFactoryBeanTests {
|
||||
TestFilter testFilter = new TestFilter();
|
||||
factory.setFilterReference(testFilter);
|
||||
factory.setPreventDuplicates(Boolean.FALSE);
|
||||
EntryListFilter<File> result = factory.getObject();
|
||||
assertFalse(result instanceof CompositeEntryListFilter);
|
||||
FileListFilter<File> result = factory.getObject();
|
||||
assertFalse(result instanceof CompositeFileListFilter);
|
||||
assertSame(testFilter, result);
|
||||
}
|
||||
|
||||
@@ -81,12 +88,12 @@ public class FileListFilterFactoryBeanTests {
|
||||
public void filenamePatternAndPreventDuplicatesNull() throws Exception {
|
||||
FileListFilterFactoryBean factory = new FileListFilterFactoryBean();
|
||||
factory.setFilenamePattern("foo");
|
||||
EntryListFilter<File> result = factory.getObject();
|
||||
assertTrue(result instanceof CompositeEntryListFilter);
|
||||
Collection<EntryListFilter<?>> filters = (Collection<EntryListFilter<?>>)
|
||||
FileListFilter<File> result = factory.getObject();
|
||||
assertTrue(result instanceof CompositeFileListFilter);
|
||||
Collection<FileListFilter<?>> filters = (Collection<FileListFilter<?>>)
|
||||
new DirectFieldAccessor(result).getPropertyValue("fileFilters");
|
||||
Iterator<EntryListFilter<?>> iterator = filters.iterator();
|
||||
assertTrue(iterator.next() instanceof AcceptOnceEntryFileListFilter);
|
||||
Iterator<FileListFilter<?>> iterator = filters.iterator();
|
||||
assertTrue(iterator.next() instanceof AcceptOnceFileListFilter);
|
||||
assertThat(iterator.next(), is(SimplePatternFileListFilter.class));
|
||||
}
|
||||
|
||||
@@ -96,12 +103,12 @@ public class FileListFilterFactoryBeanTests {
|
||||
FileListFilterFactoryBean factory = new FileListFilterFactoryBean();
|
||||
factory.setFilenamePattern(("foo"));
|
||||
factory.setPreventDuplicates(Boolean.TRUE);
|
||||
EntryListFilter<File> result = factory.getObject();
|
||||
assertTrue(result instanceof CompositeEntryListFilter);
|
||||
Collection<EntryListFilter<?>> filters = (Collection<EntryListFilter<?>>)
|
||||
FileListFilter<File> result = factory.getObject();
|
||||
assertTrue(result instanceof CompositeFileListFilter);
|
||||
Collection<FileListFilter<?>> filters = (Collection<FileListFilter<?>>)
|
||||
new DirectFieldAccessor(result).getPropertyValue("fileFilters");
|
||||
Iterator<EntryListFilter<?>> iterator = filters.iterator();
|
||||
assertTrue(iterator.next() instanceof AcceptOnceEntryFileListFilter);
|
||||
Iterator<FileListFilter<?>> iterator = filters.iterator();
|
||||
assertTrue(iterator.next() instanceof AcceptOnceFileListFilter);
|
||||
assertThat(iterator.next(), is(SimplePatternFileListFilter.class));
|
||||
}
|
||||
|
||||
@@ -110,13 +117,13 @@ public class FileListFilterFactoryBeanTests {
|
||||
FileListFilterFactoryBean factory = new FileListFilterFactoryBean();
|
||||
factory.setFilenamePattern(("foo"));
|
||||
factory.setPreventDuplicates(Boolean.FALSE);
|
||||
EntryListFilter<File> result = factory.getObject();
|
||||
assertFalse(result instanceof CompositeEntryListFilter);
|
||||
FileListFilter<File> result = factory.getObject();
|
||||
assertFalse(result instanceof CompositeFileListFilter);
|
||||
assertThat(result, is(SimplePatternFileListFilter.class));
|
||||
}
|
||||
|
||||
|
||||
private static class TestFilter extends AbstractEntryListFilter<File> {
|
||||
private static class TestFilter extends AbstractFileListFilter<File> {
|
||||
@Override
|
||||
public boolean accept(File file) {
|
||||
return true;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -13,25 +13,27 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.file.locking;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
|
||||
import org.springframework.integration.file.FileReadingMessageSource;
|
||||
import org.springframework.integration.file.entries.CompositeEntryListFilter;
|
||||
import org.springframework.integration.file.filters.CompositeFileListFilter;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Iwein Fuld
|
||||
*/
|
||||
@@ -65,7 +67,7 @@ public class FileLockingNamespaceTests {
|
||||
@Test
|
||||
public void shouldSetCustomLockerProperly() {
|
||||
assertThat(extractFromScanner("locker", customLockingSource), is(StubLocker.class));
|
||||
assertThat(extractFromScanner("filter", customLockingSource), is(CompositeEntryListFilter.class));
|
||||
assertThat(extractFromScanner("filter", customLockingSource), is(CompositeFileListFilter.class));
|
||||
}
|
||||
|
||||
private Object extractFromScanner(String propertyName, FileReadingMessageSource source) {
|
||||
@@ -75,7 +77,7 @@ public class FileLockingNamespaceTests {
|
||||
@Test
|
||||
public void shouldSetNioLockerProperly() {
|
||||
assertThat(extractFromScanner("locker", nioLockingSource), is(NioFileLocker.class));
|
||||
assertThat(extractFromScanner("filter", nioLockingSource), is(CompositeEntryListFilter.class));
|
||||
assertThat(extractFromScanner("filter", nioLockingSource), is(CompositeFileListFilter.class));
|
||||
}
|
||||
|
||||
public static class StubLocker extends AbstractFileLockerFilter {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.file.locking;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
@@ -26,6 +27,7 @@ import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.integration.file.FileReadingMessageSource;
|
||||
@@ -37,51 +39,51 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
@ContextConfiguration
|
||||
@RunWith(org.springframework.test.context.junit4.SpringJUnit4ClassRunner.class)
|
||||
public class FileLockingWithMultipleSourcesIntegrationTests {
|
||||
private static File workdir;
|
||||
|
||||
@BeforeClass
|
||||
public static void setupWorkDirectory() throws Exception {
|
||||
workdir = new File(
|
||||
new File(System.getProperty("java.io.tmpdir")),
|
||||
FileLockingWithMultipleSourcesIntegrationTests.class.getSimpleName()
|
||||
);
|
||||
workdir.mkdir();
|
||||
}
|
||||
private static File workdir;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("fileSource1")
|
||||
private FileReadingMessageSource fileSource1;
|
||||
@BeforeClass
|
||||
public static void setupWorkDirectory() throws Exception {
|
||||
workdir = new File(new File(System.getProperty("java.io.tmpdir")),
|
||||
FileLockingWithMultipleSourcesIntegrationTests.class.getSimpleName());
|
||||
workdir.mkdir();
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@Qualifier("fileSource2")
|
||||
private FileReadingMessageSource fileSource2;
|
||||
@Autowired
|
||||
@Qualifier("fileSource1")
|
||||
private FileReadingMessageSource fileSource1;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("fileSource2")
|
||||
private FileReadingMessageSource fileSource3;
|
||||
@Autowired
|
||||
@Qualifier("fileSource2")
|
||||
private FileReadingMessageSource fileSource2;
|
||||
|
||||
@Before
|
||||
public void cleanoutWorkDir() {
|
||||
for (File file : workdir.listFiles()) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
@Autowired
|
||||
@Qualifier("fileSource2")
|
||||
private FileReadingMessageSource fileSource3;
|
||||
|
||||
@Test
|
||||
public void filePickedUpOnceWithDistinctFilters() throws IOException {
|
||||
File testFile = new File(workdir, "test");
|
||||
testFile.createNewFile();
|
||||
assertThat(fileSource1.receive(), hasPayload(testFile));
|
||||
assertThat(fileSource2.receive(), nullValue());
|
||||
FileChannelCache.closeChannelFor(testFile);
|
||||
}
|
||||
@Before
|
||||
public void cleanoutWorkDir() {
|
||||
for (File file : workdir.listFiles()) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filePickedUpOnceWithDistinctFilters() throws IOException {
|
||||
File testFile = new File(workdir, "test");
|
||||
testFile.createNewFile();
|
||||
assertThat(fileSource1.receive(), hasPayload(testFile));
|
||||
assertThat(fileSource2.receive(), nullValue());
|
||||
FileChannelCache.closeChannelFor(testFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filePickedUpTwiceWithSharedFilter() throws Exception {
|
||||
File testFile = new File(workdir, "test");
|
||||
testFile.createNewFile();
|
||||
assertThat(fileSource1.receive(), hasPayload(testFile));
|
||||
assertThat(fileSource3.receive(), hasPayload(testFile));
|
||||
FileChannelCache.closeChannelFor(testFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filePickedUpTwiceWithSharedFilter() throws Exception {
|
||||
File testFile = new File(workdir, "test");
|
||||
testFile.createNewFile();
|
||||
assertThat(fileSource1.receive(), hasPayload(testFile));
|
||||
assertThat(fileSource3.receive(), hasPayload(testFile));
|
||||
FileChannelCache.closeChannelFor(testFile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,20 +13,22 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.file.locking;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.springframework.integration.file.entries.EntryListFilter;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import org.springframework.integration.file.filters.FileListFilter;
|
||||
|
||||
/**
|
||||
* @author Iwein Fuld
|
||||
@@ -49,20 +51,20 @@ public class NioFileLockerTests {
|
||||
NioFileLocker filter = new NioFileLocker();
|
||||
File testFile = new File(workdir, "test0");
|
||||
testFile.createNewFile();
|
||||
assertThat(filter.filterEntries(workdir.listFiles()).get(0), is(testFile));
|
||||
assertThat(filter.filterFiles(workdir.listFiles()).get(0), is(testFile));
|
||||
filter.lock(testFile);
|
||||
assertThat(filter.filterEntries(workdir.listFiles()).get(0), is(testFile));
|
||||
assertThat(filter.filterFiles(workdir.listFiles()).get(0), is(testFile));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fileNotListedWhenLockedByOtherFilter() throws IOException {
|
||||
NioFileLocker filter1 = new NioFileLocker();
|
||||
EntryListFilter<File> filter2 = new NioFileLocker();
|
||||
FileListFilter<File> filter2 = new NioFileLocker();
|
||||
File testFile = new File(workdir, "test1");
|
||||
testFile.createNewFile();
|
||||
assertThat(filter1.filterEntries(workdir.listFiles()).get(0), is(testFile));
|
||||
assertThat(filter1.filterFiles(workdir.listFiles()).get(0), is(testFile));
|
||||
filter1.lock(testFile);
|
||||
assertThat(filter2.filterEntries(workdir.listFiles()), is((List<File>)new ArrayList<File>()));
|
||||
assertThat(filter2.filterFiles(workdir.listFiles()), is((List<File>) new ArrayList<File>()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<constructor-arg value="fo+\.[tx]{3}"/>
|
||||
</bean>
|
||||
-->
|
||||
<bean id="filter" class="org.springframework.integration.file.entries.PatternMatchingEntryListFilter">
|
||||
<bean id="filter" class="org.springframework.integration.file.filters.PatternMatchingFileListFilter">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.file.entries.FileEntryNameExtractor"/>
|
||||
</constructor-arg>
|
||||
|
||||
@@ -104,7 +104,7 @@ public class FtpInboundRemoteFileSystemSynchronizer extends AbstractInboundRemot
|
||||
FtpClientPool.class.getSimpleName() +
|
||||
" returned a 'null' client. " +
|
||||
"This is most likely a bug in the pool implementation.");
|
||||
Collection<FTPFile> fileList = this.filter.filterEntries(client.listFiles());
|
||||
Collection<FTPFile> fileList = this.filter.filterFiles(client.listFiles());
|
||||
try {
|
||||
for (FTPFile ftpFile : fileList) {
|
||||
if ((ftpFile != null) && ftpFile.isFile()) {
|
||||
|
||||
@@ -28,9 +28,9 @@ 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.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -62,7 +62,7 @@ public class FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean
|
||||
|
||||
protected volatile Resource localDirectoryResource;
|
||||
|
||||
protected volatile EntryListFilter<FTPFile> filter;
|
||||
protected volatile FileListFilter<FTPFile> filter;
|
||||
|
||||
protected volatile int clientMode = FTPClient.ACTIVE_LOCAL_DATA_CONNECTION_MODE;
|
||||
|
||||
@@ -113,7 +113,7 @@ public class FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean
|
||||
this.localWorkingDirectory = localWorkingDirectory;
|
||||
}
|
||||
|
||||
public void setFilter(EntryListFilter<FTPFile> filter) {
|
||||
public void setFilter(FileListFilter<FTPFile> filter) {
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
@@ -155,11 +155,11 @@ public class FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean
|
||||
}
|
||||
this.localDirectoryResource = this.fromText(this.localWorkingDirectory);
|
||||
FtpFileEntryNameExtractor fileEntryNameExtractor = new FtpFileEntryNameExtractor();
|
||||
CompositeEntryListFilter<FTPFile> compositeFtpFileListFilter = new CompositeEntryListFilter<FTPFile>();
|
||||
CompositeFileListFilter<FTPFile> compositeFtpFileListFilter = new CompositeFileListFilter<FTPFile>();
|
||||
if (StringUtils.hasText(this.filenamePattern)) {
|
||||
PatternMatchingEntryListFilter<FTPFile> ftpFilePatternMatchingEntryListFilter =
|
||||
new PatternMatchingEntryListFilter<FTPFile>(fileEntryNameExtractor, filenamePattern);
|
||||
compositeFtpFileListFilter.addFilter(ftpFilePatternMatchingEntryListFilter);
|
||||
PatternMatchingFileListFilter<FTPFile> ftpFilePatternMatchingFileListFilter =
|
||||
new PatternMatchingFileListFilter<FTPFile>(fileEntryNameExtractor, filenamePattern);
|
||||
compositeFtpFileListFilter.addFilter(ftpFilePatternMatchingFileListFilter);
|
||||
}
|
||||
if (this.filter != null) {
|
||||
compositeFtpFileListFilter.addFilter(this.filter);
|
||||
|
||||
@@ -62,7 +62,7 @@
|
||||
<!-- </ftps:inbound-channel-adapter>-->
|
||||
|
||||
<bean id="filter" class="org.mockito.Mockito" factory-method="mock">
|
||||
<constructor-arg value="org.springframework.integration.file.entries.EntryListFilter"/>
|
||||
<constructor-arg value="org.springframework.integration.file.filters.FileListFilter"/>
|
||||
</bean>
|
||||
|
||||
<int:channel id="ftpIn">
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user