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 java.util.List;
|
||||||
|
|
||||||
import org.springframework.integration.MessagingException;
|
import org.springframework.integration.MessagingException;
|
||||||
import org.springframework.integration.file.entries.AcceptOnceEntryFileListFilter;
|
import org.springframework.integration.file.filters.AcceptOnceFileListFilter;
|
||||||
import org.springframework.integration.file.entries.EntryListFilter;
|
import org.springframework.integration.file.filters.FileListFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default directory scanner and base class for other directory scanners.
|
* 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 {
|
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;
|
private volatile FileLocker locker;
|
||||||
|
|
||||||
|
|
||||||
public void setFilter(EntryListFilter<File> filter) {
|
public void setFilter(FileListFilter<File> filter) {
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ public class DefaultDirectoryScanner implements DirectoryScanner {
|
|||||||
throw new MessagingException("The path [" + directory
|
throw new MessagingException("The path [" + directory
|
||||||
+ "] does not denote a properly accessible 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;
|
package org.springframework.integration.file;
|
||||||
|
|
||||||
import org.springframework.integration.file.entries.EntryListFilter;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.integration.file.filters.FileListFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Strategy for scanning directories. Implementations may select all children
|
* Strategy for scanning directories. Implementations may select all children
|
||||||
* and grandchildren of the scanned directory in any order. This interface is
|
* and grandchildren of the scanned directory in any order. This interface is
|
||||||
@@ -52,7 +52,7 @@ public interface DirectoryScanner {
|
|||||||
* @param filter
|
* @param filter
|
||||||
* the custom filter to be used
|
* 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
|
* 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.aggregator.ResequencingMessageGroupProcessor;
|
||||||
import org.springframework.integration.context.IntegrationObjectSupport;
|
import org.springframework.integration.context.IntegrationObjectSupport;
|
||||||
import org.springframework.integration.core.MessageSource;
|
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.integration.support.MessageBuilder;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link MessageSource} that creates messages from a file system directory. To
|
* {@link MessageSource} that creates messages from a file system directory. To
|
||||||
* prevent messages for certain files, you may supply a
|
* 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
|
* default, an
|
||||||
* {@link org.springframework.integration.file.entries.AcceptOnceEntryFileListFilter}
|
* {@link org.springframework.integration.file.entries.AcceptOnceEntryFileListFilter}
|
||||||
* is used. It ensures files are picked up only once from the directory.
|
* 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
|
* Sets a {@link FileListFilter}. By default a
|
||||||
* {@link org.springframework.integration.file.entries.EntryListFilter}. By
|
* {@link org.springframework.integration.file.filters.AbstractFileListFilter}
|
||||||
* default a
|
* with no bounds is used. In most cases a customized {@link FileListFilter} will
|
||||||
* {@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
|
|
||||||
* be needed to deal with modification and duplication concerns. If multiple
|
* be needed to deal with modification and duplication concerns. If multiple
|
||||||
* filters are required a
|
* 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.
|
* can be used to group them together.
|
||||||
* <p/>
|
* <p/>
|
||||||
* <b>The supplied filter must be thread safe.</b>.
|
* <b>The supplied filter must be thread safe.</b>.
|
||||||
*
|
*
|
||||||
* @param filter a filter
|
* @param filter a filter
|
||||||
*/
|
*/
|
||||||
public void setFilter(EntryListFilter<File> filter) {
|
public void setFilter(FileListFilter<File> filter) {
|
||||||
Assert.notNull(filter, "'filter' must not be null");
|
Assert.notNull(filter, "'filter' must not be null");
|
||||||
this.scanner.setFilter(filter);
|
this.scanner.setFilter(filter);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,13 +16,12 @@
|
|||||||
|
|
||||||
package org.springframework.integration.file;
|
package org.springframework.integration.file;
|
||||||
|
|
||||||
import org.springframework.integration.file.entries.EntryListFilter;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.integration.file.filters.FileListFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A custom scanner that only returns the first <code>maxNumberOfFiles</code>
|
* 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
|
* 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;
|
private final int maxNumberOfFiles;
|
||||||
|
|
||||||
@@ -46,7 +45,7 @@ public class HeadDirectoryScanner extends DefaultDirectoryScanner {
|
|||||||
this.maxNumberOfFiles = maxNumberOfFiles;
|
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));
|
return Arrays.asList(files).subList(0, Math.min(files.length, maxNumberOfFiles));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,22 +16,25 @@
|
|||||||
|
|
||||||
package org.springframework.integration.file.config;
|
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.io.File;
|
||||||
import java.util.Collection;
|
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
|
* @author Mark Fisher
|
||||||
* @since 1.0.3
|
* @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;
|
private volatile String filenamePattern;
|
||||||
|
|
||||||
@@ -39,14 +42,14 @@ public class FileListFilterFactoryBean implements FactoryBean<EntryListFilter<Fi
|
|||||||
|
|
||||||
private final Object monitor = new Object();
|
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;
|
this.filterReferences = filterReferences;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFilterReference(EntryListFilter<File> filterReference) {
|
public void setFilterReference(FileListFilter<File> filterReference) {
|
||||||
this.filterReference = filterReference;
|
this.filterReference = filterReference;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +61,7 @@ public class FileListFilterFactoryBean implements FactoryBean<EntryListFilter<Fi
|
|||||||
this.preventDuplicates = preventDuplicates;
|
this.preventDuplicates = preventDuplicates;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntryListFilter<File> getObject() throws Exception {
|
public FileListFilter<File> getObject() throws Exception {
|
||||||
if (this.fileListFilter == null) {
|
if (this.fileListFilter == null) {
|
||||||
synchronized (this.monitor) {
|
synchronized (this.monitor) {
|
||||||
this.intializeFileListFilter();
|
this.intializeFileListFilter();
|
||||||
@@ -68,7 +71,7 @@ public class FileListFilterFactoryBean implements FactoryBean<EntryListFilter<Fi
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Class<?> getObjectType() {
|
public Class<?> getObjectType() {
|
||||||
return (this.fileListFilter != null) ? this.fileListFilter.getClass() : EntryListFilter.class;
|
return (this.fileListFilter != null) ? this.fileListFilter.getClass() : FileListFilter.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSingleton() {
|
public boolean isSingleton() {
|
||||||
@@ -79,7 +82,7 @@ public class FileListFilterFactoryBean implements FactoryBean<EntryListFilter<Fi
|
|||||||
if (this.fileListFilter != null) {
|
if (this.fileListFilter != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EntryListFilter<File> filter;
|
FileListFilter<File> filter;
|
||||||
if ((this.filterReference != null) && (this.filenamePattern != null)) {
|
if ((this.filterReference != null) && (this.filenamePattern != null)) {
|
||||||
throw new IllegalArgumentException("The 'filter' reference and "
|
throw new IllegalArgumentException("The 'filter' reference and "
|
||||||
+ "'filename-pattern' attributes are mutually exclusive.");
|
+ "'filename-pattern' attributes are mutually exclusive.");
|
||||||
@@ -103,29 +106,29 @@ public class FileListFilterFactoryBean implements FactoryBean<EntryListFilter<Fi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (Boolean.FALSE.equals(this.preventDuplicates)) {
|
else if (Boolean.FALSE.equals(this.preventDuplicates)) {
|
||||||
filter = new AcceptAllEntryListFilter<File>();
|
filter = new AcceptAllFileListFilter<File>();
|
||||||
}
|
}
|
||||||
else { // preventDuplicates is either TRUE or NULL
|
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)) {
|
if ((this.filterReferences != null) && (this.filterReferences.size() > 0)) {
|
||||||
CompositeEntryListFilter<File> compositeFilter = new CompositeEntryListFilter<File>();
|
CompositeFileListFilter<File> compositeFilter = new CompositeFileListFilter<File>();
|
||||||
for (EntryListFilter<File> ff : filterReferences) {
|
for (FileListFilter<File> ff : filterReferences) {
|
||||||
compositeFilter.addFilter(ff);
|
compositeFilter.addFilter(ff);
|
||||||
}
|
}
|
||||||
filter = compositeFilter;
|
filter = compositeFilter;
|
||||||
}
|
}
|
||||||
if (filter == null) {
|
if (filter == null) {
|
||||||
filter = new CompositeEntryListFilter<File>();
|
filter = new CompositeFileListFilter<File>();
|
||||||
}
|
}
|
||||||
this.fileListFilter = filter;
|
this.fileListFilter = filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CompositeEntryListFilter<File> createCompositeWithAcceptOnceFilter(EntryListFilter<File> otherFilter) {
|
private CompositeFileListFilter<File> createCompositeWithAcceptOnceFilter(FileListFilter<File> otherFilter) {
|
||||||
CompositeEntryListFilter<File> compositeFilter = new CompositeEntryListFilter<File>();
|
CompositeFileListFilter<File> compositeFilter = new CompositeFileListFilter<File>();
|
||||||
compositeFilter.addFilter(new AcceptOnceEntryFileListFilter<File>());
|
compositeFilter.addFilter(new AcceptOnceFileListFilter<File>());
|
||||||
compositeFilter.addFilter(otherFilter);
|
compositeFilter.addFilter(otherFilter);
|
||||||
return compositeFilter;
|
return compositeFilter;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,19 +16,19 @@
|
|||||||
|
|
||||||
package org.springframework.integration.file.config;
|
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.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import org.springframework.beans.factory.FactoryBean;
|
import org.springframework.beans.factory.FactoryBean;
|
||||||
import org.springframework.integration.file.DirectoryScanner;
|
import org.springframework.integration.file.DirectoryScanner;
|
||||||
import org.springframework.integration.file.FileReadingMessageSource;
|
import org.springframework.integration.file.FileReadingMessageSource;
|
||||||
import org.springframework.integration.file.entries.CompositeEntryListFilter;
|
import org.springframework.integration.file.filters.CompositeFileListFilter;
|
||||||
import org.springframework.integration.file.entries.EntryListFilter;
|
import org.springframework.integration.file.filters.FileListFilter;
|
||||||
import org.springframework.integration.file.locking.AbstractFileLockerFilter;
|
import org.springframework.integration.file.locking.AbstractFileLockerFilter;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Comparator;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
* @author Iwein Fuld
|
* @author Iwein Fuld
|
||||||
@@ -42,7 +42,7 @@ public class FileReadingMessageSourceFactoryBean implements FactoryBean<FileRead
|
|||||||
|
|
||||||
private volatile File directory;
|
private volatile File directory;
|
||||||
|
|
||||||
private volatile EntryListFilter<File> filter;
|
private volatile FileListFilter<File> filter;
|
||||||
|
|
||||||
private volatile AbstractFileLockerFilter locker;
|
private volatile AbstractFileLockerFilter locker;
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ public class FileReadingMessageSourceFactoryBean implements FactoryBean<FileRead
|
|||||||
this.scanner = scanner;
|
this.scanner = scanner;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFilter(EntryListFilter<File> filter) {
|
public void setFilter(FileListFilter<File> filter) {
|
||||||
if (filter instanceof AbstractFileLockerFilter && (this.locker == null)) {
|
if (filter instanceof AbstractFileLockerFilter && (this.locker == null)) {
|
||||||
this.setLocker((AbstractFileLockerFilter) filter);
|
this.setLocker((AbstractFileLockerFilter) filter);
|
||||||
}
|
}
|
||||||
@@ -137,10 +137,10 @@ public class FileReadingMessageSourceFactoryBean implements FactoryBean<FileRead
|
|||||||
this.source.setFilter(this.filter);
|
this.source.setFilter(this.filter);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
CompositeEntryListFilter<File> fileCompositeEntryListFilter = new CompositeEntryListFilter<File>();
|
CompositeFileListFilter<File> compositeFileListFilter = new CompositeFileListFilter<File>();
|
||||||
fileCompositeEntryListFilter.addFilter(this.filter);
|
compositeFileListFilter.addFilter(this.filter);
|
||||||
fileCompositeEntryListFilter.addFilter(this.locker);
|
compositeFileListFilter.addFilter(this.locker);
|
||||||
this.source.setFilter(fileCompositeEntryListFilter);
|
this.source.setFilter(compositeFileListFilter);
|
||||||
this.source.setLocker(locker);
|
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.springframework.integration.file.filters;
|
package org.springframework.integration.file.filters;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -27,19 +26,16 @@ import java.util.List;
|
|||||||
*
|
*
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
* @author Iwein Fuld
|
* @author Iwein Fuld
|
||||||
*
|
|
||||||
* @deprecated Replaced by AbstractEntryListFilter in 2.0.0
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
public abstract class AbstractFileListFilter<F> implements FileListFilter<F> {
|
||||||
public abstract class AbstractFileListFilter implements FileListFilter {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public final List<File> filterFiles(File[] files) {
|
public final List<F> filterFiles(F[] files) {
|
||||||
List<File> accepted = new ArrayList<File>();
|
List<F> accepted = new ArrayList<F>();
|
||||||
if (files != null) {
|
if (files != null) {
|
||||||
for (File file : files) {
|
for (F file : files) {
|
||||||
if (this.accept(file)) {
|
if (this.accept(file)) {
|
||||||
accepted.add(file);
|
accepted.add(file);
|
||||||
}
|
}
|
||||||
@@ -51,6 +47,6 @@ public abstract class AbstractFileListFilter implements FileListFilter {
|
|||||||
/**
|
/**
|
||||||
* Subclasses must implement this method.
|
* 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
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.integration.file.filters;
|
package org.springframework.integration.file.filters;
|
||||||
|
|
||||||
import org.springframework.integration.file.entries.AcceptOnceEntryFileListFilter;
|
import java.util.Queue;
|
||||||
import org.springframework.util.Assert;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link FileListFilter} that passes files only one time. This can
|
* {@link FileListFilter} that passes files only one time. This can
|
||||||
@@ -30,34 +27,46 @@ import java.util.List;
|
|||||||
* This implementation is thread safe.
|
* This implementation is thread safe.
|
||||||
*
|
*
|
||||||
* @author Iwein Fuld
|
* @author Iwein Fuld
|
||||||
|
* @author Josh Long
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public class AcceptOnceFileListFilter extends AcceptOnceEntryFileListFilter<File> implements FileListFilter{
|
public class AcceptOnceFileListFilter<F> extends AbstractFileListFilter<F> {
|
||||||
|
|
||||||
/**
|
private final Queue<F> seen;
|
||||||
* Creates an AcceptOnceFileFilter that is based on a bounded queue. If the
|
|
||||||
* queue overflows, files that fall out will be passed through this filter
|
private final Object monitor = new Object();
|
||||||
* 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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) {
|
public AcceptOnceFileListFilter(int maxCapacity) {
|
||||||
Assert.notNull(files, "'files' must not be null.");
|
this.seen = new LinkedBlockingQueue<F>(maxCapacity);
|
||||||
return this.filterEntries(files);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.integration.file.filters;
|
package org.springframework.integration.file.filters;
|
||||||
|
|
||||||
import org.springframework.integration.file.entries.CompositeEntryListFilter;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.integration.file.entries.EntryListFilter;
|
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileFilter;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Composition that delegates to multiple {@link FileFilter}s. The composition is AND based, meaning that a file must
|
* Simple {@link FileListFilter} that predicates its matches against any of many
|
||||||
* pass through each filter's {@link #filterFiles(java.io.File[])} method in order to be accepted by the composite.
|
* configured {@link FileListFilter}.
|
||||||
*
|
*
|
||||||
* @author Iwein Fuld
|
* @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) {
|
private final Set<FileListFilter<F>> fileFilters;
|
||||||
this(Arrays.asList(fileFilters));
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompositeFileListFilter(Collection<? extends EntryListFilter<File>> fileFilters) {
|
|
||||||
super(fileFilters);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public CompositeFileListFilter() {
|
||||||
* {@inheritDoc}
|
this.fileFilters = new LinkedHashSet<FileListFilter<F>>();
|
||||||
* <p/>
|
}
|
||||||
* This implementation delegates to a collection of filters and returns only files that pass all the filters.
|
|
||||||
*/
|
public CompositeFileListFilter(Collection<? extends FileListFilter<F>> fileFilters) {
|
||||||
public List<File> filterFiles(File[] files) {
|
this.fileFilters = new LinkedHashSet<FileListFilter<F>>(fileFilters);
|
||||||
Assert.notNull(files, "'files' should not be null.");
|
}
|
||||||
return this.filterEntries(files);
|
|
||||||
}
|
|
||||||
|
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -16,25 +16,23 @@
|
|||||||
|
|
||||||
package org.springframework.integration.file.filters;
|
package org.springframework.integration.file.filters;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.List;
|
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 Iwein Fuld
|
||||||
|
* @author Josh Long
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @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
|
* Filters out files and returns the files that are left in a list, or an
|
||||||
* empty list when a null is passed in.
|
* 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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -16,40 +16,65 @@
|
|||||||
|
|
||||||
package org.springframework.integration.file.filters;
|
package org.springframework.integration.file.filters;
|
||||||
|
|
||||||
import org.springframework.integration.file.entries.FileEntryNameExtractor;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.integration.file.entries.PatternMatchingEntryListFilter;
|
import org.springframework.integration.file.entries.EntryNameExtractor;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.regex.Pattern;
|
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 Iwein Fuld
|
||||||
* @author Mark Fisher
|
* @author Josh Long
|
||||||
*
|
* @param <F> the type of file entry
|
||||||
* @since 1.0.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
public class PatternMatchingFileListFilter extends PatternMatchingEntryListFilter<File> implements FileListFilter{
|
public class PatternMatchingFileListFilter<F> extends AbstractFileListFilter<F> implements InitializingBean {
|
||||||
|
|
||||||
/**
|
private volatile EntryNameExtractor<F> entryNameExtractor;
|
||||||
* Create a file filter for the given pattern.
|
|
||||||
*/
|
private volatile Pattern pattern;
|
||||||
public PatternMatchingFileListFilter(Pattern pattern) {
|
|
||||||
super(new FileEntryNameExtractor(), pattern);
|
private volatile String patternExpression;
|
||||||
|
|
||||||
|
|
||||||
|
public PatternMatchingFileListFilter(EntryNameExtractor<F> entryNameExtractor, String pattern) {
|
||||||
|
this.entryNameExtractor = entryNameExtractor;
|
||||||
|
this.patternExpression = pattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PatternMatchingFileListFilter(String pattern) {
|
public PatternMatchingFileListFilter(EntryNameExtractor<F> entryNameExtractor, Pattern pattern) {
|
||||||
super(new FileEntryNameExtractor(), pattern);
|
this.entryNameExtractor = entryNameExtractor;
|
||||||
|
this.pattern = pattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Filter out the files of which the name doesn't match the pattern of this filter
|
public void setEntryNameExtractor(EntryNameExtractor<F> entryNameExtractor) {
|
||||||
*/
|
this.entryNameExtractor = entryNameExtractor;
|
||||||
public List<File> filterFiles(File[] files) {
|
|
||||||
Assert.notNull(files, "'files' must not be null.");
|
|
||||||
return this.filterEntries(files);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
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.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.
|
* 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
|
* @see org.springframework.integration.file.filters.PatternMatchingFileListFilter
|
||||||
* @since 2.0.0
|
* @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 AntPathMatcher matcher = new AntPathMatcher();
|
||||||
|
|
||||||
private final String path;
|
private final String path;
|
||||||
|
|
||||||
|
|
||||||
public SimplePatternFileListFilter(String path) {
|
public SimplePatternFileListFilter(String path) {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Accept the given file its name matches the pattern,
|
* 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());
|
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -16,11 +16,11 @@
|
|||||||
|
|
||||||
package org.springframework.integration.file.locking;
|
package org.springframework.integration.file.locking;
|
||||||
|
|
||||||
import org.springframework.integration.file.FileLocker;
|
|
||||||
import org.springframework.integration.file.entries.AbstractEntryListFilter;
|
|
||||||
|
|
||||||
import java.io.File;
|
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
|
* 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.
|
* when used in combination with a FileReadingMessageSource through a DirectoryScanner.
|
||||||
@@ -29,10 +29,11 @@ import java.io.File;
|
|||||||
* @since 2.0
|
* @since 2.0
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractFileLockerFilter extends AbstractEntryListFilter<File> implements FileLocker {
|
public abstract class AbstractFileLockerFilter extends AbstractFileListFilter<File> implements FileLocker {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(File file) {
|
public boolean accept(File file) {
|
||||||
return this.isLockable(file);
|
return this.isLockable(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,27 +16,27 @@
|
|||||||
|
|
||||||
package org.springframework.integration.file.synchronization;
|
package org.springframework.integration.file.synchronization;
|
||||||
|
|
||||||
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.integration.MessagingException;
|
import org.springframework.integration.MessagingException;
|
||||||
import org.springframework.integration.endpoint.AbstractEndpoint;
|
import org.springframework.integration.endpoint.AbstractEndpoint;
|
||||||
import org.springframework.integration.file.entries.AcceptAllEntryListFilter;
|
import org.springframework.integration.file.filters.AcceptAllFileListFilter;
|
||||||
import org.springframework.integration.file.entries.EntryListFilter;
|
import org.springframework.integration.file.filters.FileListFilter;
|
||||||
import org.springframework.scheduling.Trigger;
|
import org.springframework.scheduling.Trigger;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import java.util.concurrent.ScheduledFuture;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class charged with knowing how to connect to a remote file system,
|
* Base class charged with knowing how to connect to a remote file system,
|
||||||
* scan it for new files and then download the files.
|
* scan it for new files and then download the files.
|
||||||
* <p/>
|
* <p/>
|
||||||
* The implementation should run through any configured
|
* The implementation should run through any configured
|
||||||
* {@link org.springframework.integration.file.entries.EntryListFilter}s to
|
* {@link org.springframework.integration.file.filters.FileListFilter}s to
|
||||||
* ensure the entry is acceptable.
|
* ensure the file entry is acceptable.
|
||||||
*
|
*
|
||||||
* @author Josh Long
|
* @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
|
* 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;
|
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
|
* The {@link ScheduledFuture} instance we get when we
|
||||||
@@ -63,10 +63,10 @@ public abstract class AbstractInboundRemoteFileSystemSychronizer<T> extends Abst
|
|||||||
/**
|
/**
|
||||||
* The {@link EntryAcknowledgmentStrategy} implementation.
|
* 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;
|
this.entryAcknowledgmentStrategy = entryAcknowledgmentStrategy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ public abstract class AbstractInboundRemoteFileSystemSychronizer<T> extends Abst
|
|||||||
this.localDirectory = localDirectory;
|
this.localDirectory = localDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFilter(EntryListFilter<T> filter) {
|
public void setFilter(FileListFilter<F> filter) {
|
||||||
this.filter = 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.
|
* be a 'live' stateful client (a connection?) that is inappropriate to cache as it has per-request state.
|
||||||
* @param t
|
* @param t
|
||||||
* leverages strategy implementations to enable different
|
* 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
|
* successfully downloaded. Conceptually, you might delete the
|
||||||
* remote one or rename it, etc.
|
* remote one or rename it, etc.
|
||||||
* @throws Throwable
|
* @throws Throwable
|
||||||
* escape hatch exception, let the adapter deal with it.
|
* 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,
|
Assert.notNull(this.entryAcknowledgmentStrategy != null,
|
||||||
"entryAcknowledgmentStrategy can't be 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() {
|
protected void doStart() {
|
||||||
if (this.entryAcknowledgmentStrategy == null) {
|
if (this.entryAcknowledgmentStrategy == null) {
|
||||||
this.entryAcknowledgmentStrategy = new EntryAcknowledgmentStrategy<T>() {
|
this.entryAcknowledgmentStrategy = new EntryAcknowledgmentStrategy<F>() {
|
||||||
public void acknowledge(Object o, T msg) {
|
public void acknowledge(Object o, F msg) {
|
||||||
// no-op
|
// 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
|
* into the pipeline and also some more advanced scenarios (i.e., 'move file
|
||||||
* to another folder on delete ', or 'rename on delete')
|
* 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
|
* 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
|
* the data / file / entry you want to process -- specific to subclasses
|
||||||
* @throws Exception in case of an error while acknowledging
|
* @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.core.MessageSource;
|
||||||
import org.springframework.integration.endpoint.MessageProducerSupport;
|
import org.springframework.integration.endpoint.MessageProducerSupport;
|
||||||
import org.springframework.integration.file.FileReadingMessageSource;
|
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.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
|
* 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/>
|
* <p/>
|
||||||
* The base class supports configuration of whether the remote file system and
|
* 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
|
* 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).
|
* specific).
|
||||||
* <p/>
|
* <p/>
|
||||||
* This class is to be used as a pair with an implementation of
|
* 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
|
* @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> {
|
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
|
* 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.
|
* 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.
|
* 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.
|
* 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) {
|
public void setAutoCreateDirectories(boolean autoCreateDirectories) {
|
||||||
this.autoCreateDirectories = autoCreateDirectories;
|
this.autoCreateDirectories = autoCreateDirectories;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSynchronizer(T synchronizer) {
|
public void setSynchronizer(S synchronizer) {
|
||||||
this.synchronizer = synchronizer;
|
this.synchronizer = synchronizer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@ public abstract class AbstractInboundRemoteFileSystemSynchronizingMessageSource<
|
|||||||
this.localDirectory = localDirectory;
|
this.localDirectory = localDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRemotePredicate(EntryListFilter<Y> remotePredicate) {
|
public void setRemotePredicate(FileListFilter<F> remotePredicate) {
|
||||||
this.remotePredicate = remotePredicate;
|
this.remotePredicate = remotePredicate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,12 +154,12 @@ public abstract class AbstractInboundRemoteFileSystemSynchronizingMessageSource<
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private EntryListFilter<File> buildFilter() {
|
private FileListFilter<File> buildFilter() {
|
||||||
FileEntryNameExtractor fileEntryNameExtractor = new FileEntryNameExtractor();
|
FileEntryNameExtractor fileEntryNameExtractor = new FileEntryNameExtractor();
|
||||||
Pattern completePattern = Pattern.compile("^.*(?<!" + INCOMPLETE_EXTENSION + ")$");
|
Pattern completePattern = Pattern.compile("^.*(?<!" + INCOMPLETE_EXTENSION + ")$");
|
||||||
return new CompositeEntryListFilter<File>(Arrays.asList(
|
return new CompositeFileListFilter<File>(Arrays.asList(
|
||||||
new AcceptOnceEntryFileListFilter<File>(),
|
new AcceptOnceFileListFilter<File>(),
|
||||||
new PatternMatchingEntryListFilter<File>(fileEntryNameExtractor, completePattern)));
|
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -16,18 +16,22 @@
|
|||||||
|
|
||||||
package org.springframework.integration.file;
|
package org.springframework.integration.file;
|
||||||
|
|
||||||
import org.junit.Test;
|
import static org.junit.Assert.assertEquals;
|
||||||
import org.springframework.integration.file.entries.CompositeEntryListFilter;
|
import static org.junit.Assert.assertTrue;
|
||||||
import org.springframework.integration.file.entries.EntryListFilter;
|
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.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.mockito.Mockito.*;
|
import org.springframework.integration.file.filters.CompositeFileListFilter;
|
||||||
|
import org.springframework.integration.file.filters.FileListFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Iwein Fuld
|
* @author Iwein Fuld
|
||||||
@@ -35,46 +39,46 @@ import static org.mockito.Mockito.*;
|
|||||||
public class CompositeFileListFilterTests {
|
public class CompositeFileListFilterTests {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private EntryListFilter<File> fileFilterMock1 = mock(EntryListFilter.class);
|
private FileListFilter<File> fileFilterMock1 = mock(FileListFilter.class);
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private EntryListFilter<File> fileFilterMock2 = mock(EntryListFilter.class);
|
private FileListFilter<File> fileFilterMock2 = mock(FileListFilter.class);
|
||||||
|
|
||||||
private File fileMock = mock(File.class);
|
private File fileMock = mock(File.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void forwardedToFilters() throws Exception {
|
public void forwardedToFilters() throws Exception {
|
||||||
CompositeEntryListFilter<File> compositeFileFilter = new CompositeEntryListFilter<File>();
|
CompositeFileListFilter<File> compositeFileFilter = new CompositeFileListFilter<File>();
|
||||||
compositeFileFilter .addFilter(fileFilterMock1);compositeFileFilter.addFilter( fileFilterMock2);
|
compositeFileFilter .addFilter(fileFilterMock1);compositeFileFilter.addFilter(fileFilterMock2);
|
||||||
List<File> returnedFiles = Arrays.asList( fileMock);
|
List<File> returnedFiles = Arrays.asList( fileMock);
|
||||||
when(fileFilterMock1.filterEntries(isA(File[].class))).thenReturn(returnedFiles);
|
when(fileFilterMock1.filterFiles(isA(File[].class))).thenReturn(returnedFiles);
|
||||||
when(fileFilterMock2.filterEntries(isA(File[].class))).thenReturn(returnedFiles);
|
when(fileFilterMock2.filterFiles(isA(File[].class))).thenReturn(returnedFiles);
|
||||||
assertEquals(returnedFiles, compositeFileFilter.filterEntries(new File[]{fileMock}));
|
assertEquals(returnedFiles, compositeFileFilter.filterFiles(new File[]{fileMock}));
|
||||||
verify(fileFilterMock1).filterEntries(isA(File[].class));
|
verify(fileFilterMock1).filterFiles(isA(File[].class));
|
||||||
verify(fileFilterMock2).filterEntries(isA(File[].class));
|
verify(fileFilterMock2).filterFiles(isA(File[].class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void forwardedToAddedFilters() throws Exception {
|
public void forwardedToAddedFilters() throws Exception {
|
||||||
CompositeEntryListFilter<File> compositeFileFilter = new CompositeEntryListFilter<File>();
|
CompositeFileListFilter<File> compositeFileFilter = new CompositeFileListFilter<File>();
|
||||||
compositeFileFilter.addFilter(fileFilterMock1);
|
compositeFileFilter.addFilter(fileFilterMock1);
|
||||||
compositeFileFilter.addFilter( fileFilterMock2);
|
compositeFileFilter.addFilter( fileFilterMock2);
|
||||||
List<File> returnedFiles = Arrays.asList(fileMock);
|
List<File> returnedFiles = Arrays.asList(fileMock);
|
||||||
when(fileFilterMock1.filterEntries(isA(File[].class))).thenReturn(returnedFiles);
|
when(fileFilterMock1.filterFiles(isA(File[].class))).thenReturn(returnedFiles);
|
||||||
when(fileFilterMock2.filterEntries(isA(File[].class))).thenReturn(returnedFiles);
|
when(fileFilterMock2.filterFiles(isA(File[].class))).thenReturn(returnedFiles);
|
||||||
assertEquals(returnedFiles, compositeFileFilter.filterEntries(new File[]{fileMock}));
|
assertEquals(returnedFiles, compositeFileFilter.filterFiles(new File[]{fileMock}));
|
||||||
verify(fileFilterMock1).filterEntries(isA(File[].class));
|
verify(fileFilterMock1).filterFiles(isA(File[].class));
|
||||||
verify(fileFilterMock2).filterEntries(isA(File[].class));
|
verify(fileFilterMock2).filterFiles(isA(File[].class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void negative() throws Exception {
|
public void negative() throws Exception {
|
||||||
CompositeEntryListFilter<File> compositeFileFilter = new CompositeEntryListFilter<File>();
|
CompositeFileListFilter<File> compositeFileFilter = new CompositeFileListFilter<File>();
|
||||||
compositeFileFilter.addFilter(fileFilterMock1);
|
compositeFileFilter.addFilter(fileFilterMock1);
|
||||||
compositeFileFilter.addFilter(fileFilterMock2);
|
compositeFileFilter.addFilter(fileFilterMock2);
|
||||||
|
|
||||||
when(fileFilterMock2.filterEntries(isA(File[].class))).thenReturn(new ArrayList<File>());
|
when(fileFilterMock2.filterFiles(isA(File[].class))).thenReturn(new ArrayList<File>());
|
||||||
when(fileFilterMock1.filterEntries(isA(File[].class))).thenReturn(new ArrayList<File>());
|
when(fileFilterMock1.filterFiles(isA(File[].class))).thenReturn(new ArrayList<File>());
|
||||||
assertTrue(compositeFileFilter.filterEntries(new File[]{fileMock}).isEmpty());
|
assertTrue(compositeFileFilter.filterFiles(new File[]{fileMock}).isEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,12 +13,12 @@
|
|||||||
<bean id="entryNameExtractor" class="org.springframework.integration.file.entries.FileEntryNameExtractor"/>
|
<bean id="entryNameExtractor" class="org.springframework.integration.file.entries.FileEntryNameExtractor"/>
|
||||||
|
|
||||||
<!-- customized filter -->
|
<!-- customized filter -->
|
||||||
<bean id="legacyCompositeFilter" class="org.springframework.integration.file.entries.CompositeEntryListFilter">
|
<bean id="legacyCompositeFilter" class="org.springframework.integration.file.filters.CompositeFileListFilter">
|
||||||
<constructor-arg>
|
<constructor-arg>
|
||||||
<list>
|
<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.TestFileListFilter"/>
|
||||||
<bean class="org.springframework.integration.file.entries.PatternMatchingEntryListFilter">
|
<bean class="org.springframework.integration.file.filters.PatternMatchingFileListFilter">
|
||||||
<constructor-arg ref="entryNameExtractor"/>
|
<constructor-arg ref="entryNameExtractor"/>
|
||||||
<constructor-arg value="test*"/>
|
<constructor-arg value="test*"/>
|
||||||
</bean>
|
</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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -16,8 +16,21 @@
|
|||||||
|
|
||||||
package org.springframework.integration.file;
|
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.junit.runner.RunWith;
|
||||||
|
|
||||||
import org.springframework.beans.DirectFieldAccessor;
|
import org.springframework.beans.DirectFieldAccessor;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.integration.Message;
|
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.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Iwein Fuld
|
* @author Iwein Fuld
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -16,19 +16,21 @@
|
|||||||
|
|
||||||
package org.springframework.integration.file;
|
package org.springframework.integration.file;
|
||||||
|
|
||||||
import org.junit.Test;
|
import static org.junit.Assert.assertEquals;
|
||||||
import org.springframework.beans.factory.BeanCreationException;
|
import static org.junit.Assert.assertTrue;
|
||||||
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 java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
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
|
* @author Mark Fisher
|
||||||
@@ -41,8 +43,8 @@ public class PatternMatchingFileListFilterTests {
|
|||||||
public void matchSingleFile() {
|
public void matchSingleFile() {
|
||||||
File[] files = new File[]{new File("/some/path/test.txt")};
|
File[] files = new File[]{new File("/some/path/test.txt")};
|
||||||
Pattern pattern = Pattern.compile("[a-z]+\\.txt");
|
Pattern pattern = Pattern.compile("[a-z]+\\.txt");
|
||||||
PatternMatchingEntryListFilter<File> filter = new PatternMatchingEntryListFilter<File>(fileEntryNameExtractor, pattern);
|
PatternMatchingFileListFilter<File> filter = new PatternMatchingFileListFilter<File>(fileEntryNameExtractor, pattern);
|
||||||
List<File> accepted = filter.filterEntries(files);
|
List<File> accepted = filter.filterFiles(files);
|
||||||
assertEquals(1, accepted.size());
|
assertEquals(1, accepted.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,8 +52,8 @@ public class PatternMatchingFileListFilterTests {
|
|||||||
public void noMatchWithSingleFile() {
|
public void noMatchWithSingleFile() {
|
||||||
File[] files = new File[]{new File("/some/path/Test.txt")};
|
File[] files = new File[]{new File("/some/path/Test.txt")};
|
||||||
Pattern pattern = Pattern.compile("[a-z]+\\.txt");
|
Pattern pattern = Pattern.compile("[a-z]+\\.txt");
|
||||||
PatternMatchingEntryListFilter<File> filter = new PatternMatchingEntryListFilter<File>(fileEntryNameExtractor, pattern);
|
PatternMatchingFileListFilter<File> filter = new PatternMatchingFileListFilter<File>(fileEntryNameExtractor, pattern);
|
||||||
List<File> accepted = filter.filterEntries(files);
|
List<File> accepted = filter.filterFiles(files);
|
||||||
assertEquals(0, accepted.size());
|
assertEquals(0, accepted.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,9 +79,9 @@ public class PatternMatchingFileListFilterTests {
|
|||||||
public void patternEditorInContext() {
|
public void patternEditorInContext() {
|
||||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||||
"patternMatchingFileListFilterTests.xml", this.getClass());
|
"patternMatchingFileListFilterTests.xml", this.getClass());
|
||||||
EntryListFilter<File> filter = (EntryListFilter<File>) context.getBean("filter");
|
FileListFilter<File> filter = (FileListFilter<File>) context.getBean("filter");
|
||||||
File[] files = new File[]{new File("/some/path/foo.txt")};
|
File[] files = new File[] { new File("/some/path/foo.txt") };
|
||||||
List<File> accepted = filter.filterEntries(files);
|
List<File> accepted = filter.filterFiles(files);
|
||||||
assertEquals(1, accepted.size());
|
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -16,17 +16,19 @@
|
|||||||
|
|
||||||
package org.springframework.integration.file;
|
package org.springframework.integration.file;
|
||||||
|
|
||||||
import org.springframework.integration.file.entries.EntryListFilter;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.integration.file.filters.FileListFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Iwein Fuld
|
* @author Iwein Fuld
|
||||||
*/
|
*/
|
||||||
public class TestFileListFilter implements EntryListFilter<File> {
|
public class TestFileListFilter implements FileListFilter<File> {
|
||||||
public List<File> filterEntries(File[] entries) {
|
|
||||||
|
public List<File> filterFiles(File[] entries) {
|
||||||
return Arrays.asList(entries);
|
return Arrays.asList(entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,25 +16,28 @@
|
|||||||
|
|
||||||
package org.springframework.integration.file.config;
|
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.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import org.springframework.beans.DirectFieldAccessor;
|
import org.springframework.beans.DirectFieldAccessor;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.integration.channel.AbstractMessageChannel;
|
import org.springframework.integration.channel.AbstractMessageChannel;
|
||||||
import org.springframework.integration.file.DefaultDirectoryScanner;
|
import org.springframework.integration.file.DefaultDirectoryScanner;
|
||||||
import org.springframework.integration.file.FileReadingMessageSource;
|
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.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
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 Iwein Fuld
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
@@ -76,7 +79,7 @@ public class FileInboundChannelAdapterParserTests {
|
|||||||
DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(scanner);
|
DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(scanner);
|
||||||
Object filter = scannerAccessor.getPropertyValue("filter");
|
Object filter = scannerAccessor.getPropertyValue("filter");
|
||||||
assertTrue("'filter' should be set",
|
assertTrue("'filter' should be set",
|
||||||
filter instanceof AcceptOnceEntryFileListFilter);
|
filter instanceof AcceptOnceFileListFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -16,8 +16,17 @@
|
|||||||
|
|
||||||
package org.springframework.integration.file.config;
|
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.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import org.springframework.beans.DirectFieldAccessor;
|
import org.springframework.beans.DirectFieldAccessor;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
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.channel.AbstractMessageChannel;
|
||||||
import org.springframework.integration.endpoint.AbstractEndpoint;
|
import org.springframework.integration.endpoint.AbstractEndpoint;
|
||||||
import org.springframework.integration.file.FileReadingMessageSource;
|
import org.springframework.integration.file.FileReadingMessageSource;
|
||||||
import org.springframework.integration.file.entries.AcceptOnceEntryFileListFilter;
|
import org.springframework.integration.file.filters.AcceptOnceFileListFilter;
|
||||||
import org.springframework.integration.file.entries.CompositeEntryListFilter;
|
import org.springframework.integration.file.filters.CompositeFileListFilter;
|
||||||
import org.springframework.integration.file.entries.EntryListFilter;
|
import org.springframework.integration.file.filters.FileListFilter;
|
||||||
import org.springframework.integration.file.filters.SimplePatternFileListFilter;
|
import org.springframework.integration.file.filters.SimplePatternFileListFilter;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
* @author Iwein Fuld
|
* @author Iwein Fuld
|
||||||
@@ -83,15 +87,14 @@ public class FileInboundChannelAdapterWithPatternParserTests {
|
|||||||
@Test
|
@Test
|
||||||
public void compositeFilterType() {
|
public void compositeFilterType() {
|
||||||
DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(accessor.getPropertyValue("scanner"));
|
DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(accessor.getPropertyValue("scanner"));
|
||||||
assertTrue(scannerAccessor.getPropertyValue("filter") instanceof CompositeEntryListFilter);
|
assertTrue(scannerAccessor.getPropertyValue("filter") instanceof CompositeFileListFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void compositeFilterSetSize() {
|
public void compositeFilterSetSize() {
|
||||||
DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(accessor.getPropertyValue("scanner"));
|
DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(accessor.getPropertyValue("scanner"));
|
||||||
|
Set<FileListFilter<File>> filters = (Set<FileListFilter<File>>) new DirectFieldAccessor(
|
||||||
Set<EntryListFilter<File>> filters = (Set<EntryListFilter<File>>) new DirectFieldAccessor(
|
|
||||||
scannerAccessor.getPropertyValue("filter")).getPropertyValue("fileFilters");
|
scannerAccessor.getPropertyValue("filter")).getPropertyValue("fileFilters");
|
||||||
assertEquals(2, filters.size());
|
assertEquals(2, filters.size());
|
||||||
}
|
}
|
||||||
@@ -100,12 +103,11 @@ public class FileInboundChannelAdapterWithPatternParserTests {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void acceptOnceFilter() {
|
public void acceptOnceFilter() {
|
||||||
DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(accessor.getPropertyValue("scanner"));
|
DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(accessor.getPropertyValue("scanner"));
|
||||||
|
Set<FileListFilter<File>> filters = (Set<FileListFilter<File>>) new DirectFieldAccessor(
|
||||||
Set<EntryListFilter<File>> filters = (Set<EntryListFilter<File>>) new DirectFieldAccessor(
|
|
||||||
scannerAccessor.getPropertyValue("filter")).getPropertyValue("fileFilters");
|
scannerAccessor.getPropertyValue("filter")).getPropertyValue("fileFilters");
|
||||||
boolean hasAcceptOnceFilter = false;
|
boolean hasAcceptOnceFilter = false;
|
||||||
for (EntryListFilter<File> filter : filters) {
|
for (FileListFilter<File> filter : filters) {
|
||||||
if (filter instanceof AcceptOnceEntryFileListFilter) {
|
if (filter instanceof AcceptOnceFileListFilter) {
|
||||||
hasAcceptOnceFilter = true;
|
hasAcceptOnceFilter = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -116,10 +118,10 @@ public class FileInboundChannelAdapterWithPatternParserTests {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void patternFilter() {
|
public void patternFilter() {
|
||||||
DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(accessor.getPropertyValue("scanner"));
|
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");
|
scannerAccessor.getPropertyValue("filter")).getPropertyValue("fileFilters");
|
||||||
String pattern = null;
|
String pattern = null;
|
||||||
for (EntryListFilter<?> filter : filters) {
|
for (FileListFilter<?> filter : filters) {
|
||||||
if (filter instanceof SimplePatternFileListFilter) {
|
if (filter instanceof SimplePatternFileListFilter) {
|
||||||
pattern = (String) new DirectFieldAccessor(filter).getPropertyValue("path");
|
pattern = (String) new DirectFieldAccessor(filter).getPropertyValue("path");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,27 +16,33 @@
|
|||||||
|
|
||||||
package org.springframework.integration.file.config;
|
package org.springframework.integration.file.config;
|
||||||
|
|
||||||
import org.junit.Test;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import org.junit.runner.RunWith;
|
import static org.junit.Assert.assertEquals;
|
||||||
import org.springframework.beans.DirectFieldAccessor;
|
import static org.junit.Assert.assertFalse;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import static org.junit.Assert.assertSame;
|
||||||
import org.springframework.context.ApplicationContext;
|
import static org.junit.Assert.assertThat;
|
||||||
import org.springframework.integration.file.TestFileListFilter;
|
import static org.junit.Assert.assertTrue;
|
||||||
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 java.io.File;
|
import java.io.File;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.*;
|
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
|
* @author Mark Fisher
|
||||||
@@ -55,98 +61,98 @@ public class FileInboundChannelAdapterWithPreventDuplicatesFlagTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void filterAndNull() {
|
public void filterAndNull() {
|
||||||
EntryListFilter<?> filter = this.extractFilter("filterAndNull");
|
FileListFilter<?> filter = this.extractFilter("filterAndNull");
|
||||||
assertFalse(filter instanceof CompositeEntryListFilter);
|
assertFalse(filter instanceof CompositeFileListFilter);
|
||||||
assertSame(testFilter, filter);
|
assertSame(testFilter, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void filterAndTrue() {
|
public void filterAndTrue() {
|
||||||
EntryListFilter<?> filter = this.extractFilter("filterAndTrue");
|
FileListFilter<?> filter = this.extractFilter("filterAndTrue");
|
||||||
assertTrue(filter instanceof CompositeEntryListFilter);
|
assertTrue(filter instanceof CompositeFileListFilter);
|
||||||
Collection<?> filters = (Collection<?>) new DirectFieldAccessor(filter).getPropertyValue("fileFilters");
|
Collection<?> filters = (Collection<?>) new DirectFieldAccessor(filter).getPropertyValue("fileFilters");
|
||||||
assertTrue(filters.iterator().next() instanceof AcceptOnceEntryFileListFilter);
|
assertTrue(filters.iterator().next() instanceof AcceptOnceFileListFilter);
|
||||||
assertTrue(filters.contains(testFilter));
|
assertTrue(filters.contains(testFilter));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void filterAndFalse() throws Exception {
|
public void filterAndFalse() throws Exception {
|
||||||
EntryListFilter<?> filter = this.extractFilter("filterAndFalse");
|
FileListFilter<?> filter = this.extractFilter("filterAndFalse");
|
||||||
assertFalse(filter instanceof CompositeEntryListFilter);
|
assertFalse(filter instanceof CompositeFileListFilter);
|
||||||
assertSame(testFilter, filter);
|
assertSame(testFilter, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void patternAndNull() throws Exception {
|
public void patternAndNull() throws Exception {
|
||||||
EntryListFilter<?> filter = this.extractFilter("patternAndNull");
|
FileListFilter<?> filter = this.extractFilter("patternAndNull");
|
||||||
assertTrue(filter instanceof CompositeEntryListFilter);
|
assertTrue(filter instanceof CompositeFileListFilter);
|
||||||
Collection<EntryListFilter<File>> filters = (Collection<EntryListFilter<File>>)
|
Collection<FileListFilter<File>> filters = (Collection<FileListFilter<File>>)
|
||||||
new DirectFieldAccessor(filter).getPropertyValue("fileFilters");
|
new DirectFieldAccessor(filter).getPropertyValue("fileFilters");
|
||||||
Iterator<EntryListFilter<File>> iterator = filters.iterator();
|
Iterator<FileListFilter<File>> iterator = filters.iterator();
|
||||||
assertTrue(iterator.next() instanceof AcceptOnceEntryFileListFilter);
|
assertTrue(iterator.next() instanceof AcceptOnceFileListFilter);
|
||||||
assertThat(iterator.next(), is(SimplePatternFileListFilter.class));
|
assertThat(iterator.next(), is(SimplePatternFileListFilter.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void patternAndTrue() throws Exception {
|
public void patternAndTrue() throws Exception {
|
||||||
EntryListFilter<?> filter = this.extractFilter("patternAndTrue");
|
FileListFilter<?> filter = this.extractFilter("patternAndTrue");
|
||||||
assertTrue(filter instanceof CompositeEntryListFilter);
|
assertTrue(filter instanceof CompositeFileListFilter);
|
||||||
Collection<EntryListFilter<File>> filters = (Collection<EntryListFilter<File>>)
|
Collection<FileListFilter<File>> filters = (Collection<FileListFilter<File>>)
|
||||||
new DirectFieldAccessor(filter).getPropertyValue("fileFilters");
|
new DirectFieldAccessor(filter).getPropertyValue("fileFilters");
|
||||||
Iterator<EntryListFilter<File>> iterator = filters.iterator();
|
Iterator<FileListFilter<File>> iterator = filters.iterator();
|
||||||
assertTrue(iterator.next() instanceof AcceptOnceEntryFileListFilter);
|
assertTrue(iterator.next() instanceof AcceptOnceFileListFilter);
|
||||||
assertThat(iterator.next(), is(SimplePatternFileListFilter.class));
|
assertThat(iterator.next(), is(SimplePatternFileListFilter.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void patternAndFalse() throws Exception {
|
public void patternAndFalse() throws Exception {
|
||||||
EntryListFilter<File> filter = this.extractFilter("patternAndFalse");
|
FileListFilter<File> filter = this.extractFilter("patternAndFalse");
|
||||||
assertFalse(filter instanceof CompositeEntryListFilter);
|
assertFalse(filter instanceof CompositeFileListFilter);
|
||||||
assertThat(filter, is(SimplePatternFileListFilter.class));
|
assertThat(filter, is(SimplePatternFileListFilter.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultAndNull() throws Exception {
|
public void defaultAndNull() throws Exception {
|
||||||
EntryListFilter<File> filter = this.extractFilter("defaultAndNull");
|
FileListFilter<File> filter = this.extractFilter("defaultAndNull");
|
||||||
assertNotNull(filter);
|
assertNotNull(filter);
|
||||||
assertFalse(filter instanceof CompositeEntryListFilter);
|
assertFalse(filter instanceof CompositeFileListFilter);
|
||||||
assertTrue(filter instanceof AcceptOnceEntryFileListFilter);
|
assertTrue(filter instanceof AcceptOnceFileListFilter);
|
||||||
|
|
||||||
File testFile = new File("test");
|
File testFile = new File("test");
|
||||||
File[] files = new File[] { testFile, testFile, testFile };
|
File[] files = new File[] { testFile, testFile, testFile };
|
||||||
List<File> result = filter.filterEntries(files);
|
List<File> result = filter.filterFiles(files);
|
||||||
assertEquals(1, result.size());
|
assertEquals(1, result.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultAndTrue() throws Exception {
|
public void defaultAndTrue() throws Exception {
|
||||||
EntryListFilter<File> filter = this.extractFilter("defaultAndTrue");
|
FileListFilter<File> filter = this.extractFilter("defaultAndTrue");
|
||||||
assertFalse(filter instanceof CompositeEntryListFilter);
|
assertFalse(filter instanceof CompositeFileListFilter);
|
||||||
assertTrue(filter instanceof AcceptOnceEntryFileListFilter);
|
assertTrue(filter instanceof AcceptOnceFileListFilter);
|
||||||
File testFile = new File("test");
|
File testFile = new File("test");
|
||||||
File[] files = new File[] { testFile, testFile, testFile };
|
File[] files = new File[] { testFile, testFile, testFile };
|
||||||
List<File> result = filter.filterEntries(files);
|
List<File> result = filter.filterFiles(files);
|
||||||
assertEquals(1, result.size());
|
assertEquals(1, result.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultAndFalse() throws Exception {
|
public void defaultAndFalse() throws Exception {
|
||||||
EntryListFilter<File> filter = this.extractFilter("defaultAndFalse");
|
FileListFilter<File> filter = this.extractFilter("defaultAndFalse");
|
||||||
assertNotNull(filter);
|
assertNotNull(filter);
|
||||||
assertFalse(filter instanceof CompositeEntryListFilter);
|
assertFalse(filter instanceof CompositeFileListFilter);
|
||||||
assertFalse(filter instanceof AcceptOnceEntryFileListFilter);
|
assertFalse(filter instanceof AcceptOnceFileListFilter);
|
||||||
File testFile = new File("test");
|
File testFile = new File("test");
|
||||||
File[] files = new File[] { testFile, testFile, testFile };
|
File[] files = new File[] { testFile, testFile, testFile };
|
||||||
List<File> result = filter.filterEntries(files);
|
List<File> result = filter.filterFiles(files);
|
||||||
assertEquals(3, result.size());
|
assertEquals(3, result.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private EntryListFilter<File> extractFilter(String beanName) {
|
private FileListFilter<File> extractFilter(String beanName) {
|
||||||
return (EntryListFilter<File>)
|
return (FileListFilter<File>)
|
||||||
new DirectFieldAccessor(
|
new DirectFieldAccessor(
|
||||||
new DirectFieldAccessor(
|
new DirectFieldAccessor(
|
||||||
new DirectFieldAccessor(context.getBean(beanName))
|
new DirectFieldAccessor(context.getBean(beanName))
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
</inbound-channel-adapter>
|
</inbound-channel-adapter>
|
||||||
<beans:bean class="org.springframework.integration.file.config.FileListFilterFactoryBean" />
|
<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:constructor-arg>
|
||||||
<beans:list></beans:list>
|
<beans:list></beans:list>
|
||||||
</beans:constructor-arg>
|
</beans:constructor-arg>
|
||||||
|
|||||||
@@ -16,17 +16,24 @@
|
|||||||
|
|
||||||
package org.springframework.integration.file.config;
|
package org.springframework.integration.file.config;
|
||||||
|
|
||||||
import org.junit.Test;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import org.springframework.beans.DirectFieldAccessor;
|
import static org.junit.Assert.assertFalse;
|
||||||
import org.springframework.integration.file.entries.*;
|
import static org.junit.Assert.assertSame;
|
||||||
import org.springframework.integration.file.filters.SimplePatternFileListFilter;
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
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
|
* @author Mark Fisher
|
||||||
@@ -47,8 +54,8 @@ public class FileListFilterFactoryBeanTests {
|
|||||||
FileListFilterFactoryBean factory = new FileListFilterFactoryBean();
|
FileListFilterFactoryBean factory = new FileListFilterFactoryBean();
|
||||||
TestFilter testFilter = new TestFilter();
|
TestFilter testFilter = new TestFilter();
|
||||||
factory.setFilterReference(testFilter);
|
factory.setFilterReference(testFilter);
|
||||||
EntryListFilter<File> result = factory.getObject();
|
FileListFilter<File> result = factory.getObject();
|
||||||
assertFalse(result instanceof CompositeEntryListFilter);
|
assertFalse(result instanceof CompositeFileListFilter);
|
||||||
assertSame(testFilter, result);
|
assertSame(testFilter, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,10 +65,10 @@ public class FileListFilterFactoryBeanTests {
|
|||||||
TestFilter testFilter = new TestFilter();
|
TestFilter testFilter = new TestFilter();
|
||||||
factory.setFilterReference(testFilter);
|
factory.setFilterReference(testFilter);
|
||||||
factory.setPreventDuplicates(Boolean.TRUE);
|
factory.setPreventDuplicates(Boolean.TRUE);
|
||||||
EntryListFilter<File> result = factory.getObject();
|
FileListFilter<File> result = factory.getObject();
|
||||||
assertTrue(result instanceof CompositeEntryListFilter);
|
assertTrue(result instanceof CompositeFileListFilter);
|
||||||
Collection<?> filters = (Collection<?>) new DirectFieldAccessor(result).getPropertyValue("fileFilters");
|
Collection<?> filters = (Collection<?>) new DirectFieldAccessor(result).getPropertyValue("fileFilters");
|
||||||
assertTrue(filters.iterator().next() instanceof AcceptOnceEntryFileListFilter);
|
assertTrue(filters.iterator().next() instanceof AcceptOnceFileListFilter);
|
||||||
assertTrue(filters.contains(testFilter));
|
assertTrue(filters.contains(testFilter));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,8 +78,8 @@ public class FileListFilterFactoryBeanTests {
|
|||||||
TestFilter testFilter = new TestFilter();
|
TestFilter testFilter = new TestFilter();
|
||||||
factory.setFilterReference(testFilter);
|
factory.setFilterReference(testFilter);
|
||||||
factory.setPreventDuplicates(Boolean.FALSE);
|
factory.setPreventDuplicates(Boolean.FALSE);
|
||||||
EntryListFilter<File> result = factory.getObject();
|
FileListFilter<File> result = factory.getObject();
|
||||||
assertFalse(result instanceof CompositeEntryListFilter);
|
assertFalse(result instanceof CompositeFileListFilter);
|
||||||
assertSame(testFilter, result);
|
assertSame(testFilter, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,12 +88,12 @@ public class FileListFilterFactoryBeanTests {
|
|||||||
public void filenamePatternAndPreventDuplicatesNull() throws Exception {
|
public void filenamePatternAndPreventDuplicatesNull() throws Exception {
|
||||||
FileListFilterFactoryBean factory = new FileListFilterFactoryBean();
|
FileListFilterFactoryBean factory = new FileListFilterFactoryBean();
|
||||||
factory.setFilenamePattern("foo");
|
factory.setFilenamePattern("foo");
|
||||||
EntryListFilter<File> result = factory.getObject();
|
FileListFilter<File> result = factory.getObject();
|
||||||
assertTrue(result instanceof CompositeEntryListFilter);
|
assertTrue(result instanceof CompositeFileListFilter);
|
||||||
Collection<EntryListFilter<?>> filters = (Collection<EntryListFilter<?>>)
|
Collection<FileListFilter<?>> filters = (Collection<FileListFilter<?>>)
|
||||||
new DirectFieldAccessor(result).getPropertyValue("fileFilters");
|
new DirectFieldAccessor(result).getPropertyValue("fileFilters");
|
||||||
Iterator<EntryListFilter<?>> iterator = filters.iterator();
|
Iterator<FileListFilter<?>> iterator = filters.iterator();
|
||||||
assertTrue(iterator.next() instanceof AcceptOnceEntryFileListFilter);
|
assertTrue(iterator.next() instanceof AcceptOnceFileListFilter);
|
||||||
assertThat(iterator.next(), is(SimplePatternFileListFilter.class));
|
assertThat(iterator.next(), is(SimplePatternFileListFilter.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,12 +103,12 @@ public class FileListFilterFactoryBeanTests {
|
|||||||
FileListFilterFactoryBean factory = new FileListFilterFactoryBean();
|
FileListFilterFactoryBean factory = new FileListFilterFactoryBean();
|
||||||
factory.setFilenamePattern(("foo"));
|
factory.setFilenamePattern(("foo"));
|
||||||
factory.setPreventDuplicates(Boolean.TRUE);
|
factory.setPreventDuplicates(Boolean.TRUE);
|
||||||
EntryListFilter<File> result = factory.getObject();
|
FileListFilter<File> result = factory.getObject();
|
||||||
assertTrue(result instanceof CompositeEntryListFilter);
|
assertTrue(result instanceof CompositeFileListFilter);
|
||||||
Collection<EntryListFilter<?>> filters = (Collection<EntryListFilter<?>>)
|
Collection<FileListFilter<?>> filters = (Collection<FileListFilter<?>>)
|
||||||
new DirectFieldAccessor(result).getPropertyValue("fileFilters");
|
new DirectFieldAccessor(result).getPropertyValue("fileFilters");
|
||||||
Iterator<EntryListFilter<?>> iterator = filters.iterator();
|
Iterator<FileListFilter<?>> iterator = filters.iterator();
|
||||||
assertTrue(iterator.next() instanceof AcceptOnceEntryFileListFilter);
|
assertTrue(iterator.next() instanceof AcceptOnceFileListFilter);
|
||||||
assertThat(iterator.next(), is(SimplePatternFileListFilter.class));
|
assertThat(iterator.next(), is(SimplePatternFileListFilter.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,13 +117,13 @@ public class FileListFilterFactoryBeanTests {
|
|||||||
FileListFilterFactoryBean factory = new FileListFilterFactoryBean();
|
FileListFilterFactoryBean factory = new FileListFilterFactoryBean();
|
||||||
factory.setFilenamePattern(("foo"));
|
factory.setFilenamePattern(("foo"));
|
||||||
factory.setPreventDuplicates(Boolean.FALSE);
|
factory.setPreventDuplicates(Boolean.FALSE);
|
||||||
EntryListFilter<File> result = factory.getObject();
|
FileListFilter<File> result = factory.getObject();
|
||||||
assertFalse(result instanceof CompositeEntryListFilter);
|
assertFalse(result instanceof CompositeFileListFilter);
|
||||||
assertThat(result, is(SimplePatternFileListFilter.class));
|
assertThat(result, is(SimplePatternFileListFilter.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class TestFilter extends AbstractEntryListFilter<File> {
|
private static class TestFilter extends AbstractFileListFilter<File> {
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(File file) {
|
public boolean accept(File file) {
|
||||||
return true;
|
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.integration.file.locking;
|
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.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import org.springframework.beans.DirectFieldAccessor;
|
import org.springframework.beans.DirectFieldAccessor;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
|
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
|
||||||
import org.springframework.integration.file.FileReadingMessageSource;
|
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.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
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
|
* @author Iwein Fuld
|
||||||
*/
|
*/
|
||||||
@@ -65,7 +67,7 @@ public class FileLockingNamespaceTests {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldSetCustomLockerProperly() {
|
public void shouldSetCustomLockerProperly() {
|
||||||
assertThat(extractFromScanner("locker", customLockingSource), is(StubLocker.class));
|
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) {
|
private Object extractFromScanner(String propertyName, FileReadingMessageSource source) {
|
||||||
@@ -75,7 +77,7 @@ public class FileLockingNamespaceTests {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldSetNioLockerProperly() {
|
public void shouldSetNioLockerProperly() {
|
||||||
assertThat(extractFromScanner("locker", nioLockingSource), is(NioFileLocker.class));
|
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 {
|
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.integration.file.locking;
|
package org.springframework.integration.file.locking;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.nullValue;
|
import static org.hamcrest.CoreMatchers.nullValue;
|
||||||
@@ -26,6 +27,7 @@ import org.junit.Before;
|
|||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.integration.file.FileReadingMessageSource;
|
import org.springframework.integration.file.FileReadingMessageSource;
|
||||||
@@ -37,51 +39,51 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
@RunWith(org.springframework.test.context.junit4.SpringJUnit4ClassRunner.class)
|
@RunWith(org.springframework.test.context.junit4.SpringJUnit4ClassRunner.class)
|
||||||
public class FileLockingWithMultipleSourcesIntegrationTests {
|
public class FileLockingWithMultipleSourcesIntegrationTests {
|
||||||
private static File workdir;
|
|
||||||
|
|
||||||
@BeforeClass
|
private static File workdir;
|
||||||
public static void setupWorkDirectory() throws Exception {
|
|
||||||
workdir = new File(
|
|
||||||
new File(System.getProperty("java.io.tmpdir")),
|
|
||||||
FileLockingWithMultipleSourcesIntegrationTests.class.getSimpleName()
|
|
||||||
);
|
|
||||||
workdir.mkdir();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Autowired
|
@BeforeClass
|
||||||
@Qualifier("fileSource1")
|
public static void setupWorkDirectory() throws Exception {
|
||||||
private FileReadingMessageSource fileSource1;
|
workdir = new File(new File(System.getProperty("java.io.tmpdir")),
|
||||||
|
FileLockingWithMultipleSourcesIntegrationTests.class.getSimpleName());
|
||||||
|
workdir.mkdir();
|
||||||
|
}
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("fileSource2")
|
@Qualifier("fileSource1")
|
||||||
private FileReadingMessageSource fileSource2;
|
private FileReadingMessageSource fileSource1;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("fileSource2")
|
@Qualifier("fileSource2")
|
||||||
private FileReadingMessageSource fileSource3;
|
private FileReadingMessageSource fileSource2;
|
||||||
|
|
||||||
@Before
|
@Autowired
|
||||||
public void cleanoutWorkDir() {
|
@Qualifier("fileSource2")
|
||||||
for (File file : workdir.listFiles()) {
|
private FileReadingMessageSource fileSource3;
|
||||||
file.delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Before
|
||||||
public void filePickedUpOnceWithDistinctFilters() throws IOException {
|
public void cleanoutWorkDir() {
|
||||||
File testFile = new File(workdir, "test");
|
for (File file : workdir.listFiles()) {
|
||||||
testFile.createNewFile();
|
file.delete();
|
||||||
assertThat(fileSource1.receive(), hasPayload(testFile));
|
}
|
||||||
assertThat(fileSource2.receive(), nullValue());
|
}
|
||||||
FileChannelCache.closeChannelFor(testFile);
|
|
||||||
}
|
@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
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.integration.file.locking;
|
package org.springframework.integration.file.locking;
|
||||||
|
|
||||||
import org.junit.Rule;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import org.junit.Test;
|
import static org.junit.Assert.assertThat;
|
||||||
import org.junit.rules.TemporaryFolder;
|
|
||||||
import org.springframework.integration.file.entries.EntryListFilter;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import org.junit.Rule;
|
||||||
import static org.junit.Assert.assertThat;
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.TemporaryFolder;
|
||||||
|
|
||||||
|
import org.springframework.integration.file.filters.FileListFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Iwein Fuld
|
* @author Iwein Fuld
|
||||||
@@ -49,20 +51,20 @@ public class NioFileLockerTests {
|
|||||||
NioFileLocker filter = new NioFileLocker();
|
NioFileLocker filter = new NioFileLocker();
|
||||||
File testFile = new File(workdir, "test0");
|
File testFile = new File(workdir, "test0");
|
||||||
testFile.createNewFile();
|
testFile.createNewFile();
|
||||||
assertThat(filter.filterEntries(workdir.listFiles()).get(0), is(testFile));
|
assertThat(filter.filterFiles(workdir.listFiles()).get(0), is(testFile));
|
||||||
filter.lock(testFile);
|
filter.lock(testFile);
|
||||||
assertThat(filter.filterEntries(workdir.listFiles()).get(0), is(testFile));
|
assertThat(filter.filterFiles(workdir.listFiles()).get(0), is(testFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void fileNotListedWhenLockedByOtherFilter() throws IOException {
|
public void fileNotListedWhenLockedByOtherFilter() throws IOException {
|
||||||
NioFileLocker filter1 = new NioFileLocker();
|
NioFileLocker filter1 = new NioFileLocker();
|
||||||
EntryListFilter<File> filter2 = new NioFileLocker();
|
FileListFilter<File> filter2 = new NioFileLocker();
|
||||||
File testFile = new File(workdir, "test1");
|
File testFile = new File(workdir, "test1");
|
||||||
testFile.createNewFile();
|
testFile.createNewFile();
|
||||||
assertThat(filter1.filterEntries(workdir.listFiles()).get(0), is(testFile));
|
assertThat(filter1.filterFiles(workdir.listFiles()).get(0), is(testFile));
|
||||||
filter1.lock(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}"/>
|
<constructor-arg value="fo+\.[tx]{3}"/>
|
||||||
</bean>
|
</bean>
|
||||||
-->
|
-->
|
||||||
<bean id="filter" class="org.springframework.integration.file.entries.PatternMatchingEntryListFilter">
|
<bean id="filter" class="org.springframework.integration.file.filters.PatternMatchingFileListFilter">
|
||||||
<constructor-arg>
|
<constructor-arg>
|
||||||
<bean class="org.springframework.integration.file.entries.FileEntryNameExtractor"/>
|
<bean class="org.springframework.integration.file.entries.FileEntryNameExtractor"/>
|
||||||
</constructor-arg>
|
</constructor-arg>
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ public class FtpInboundRemoteFileSystemSynchronizer extends AbstractInboundRemot
|
|||||||
FtpClientPool.class.getSimpleName() +
|
FtpClientPool.class.getSimpleName() +
|
||||||
" returned a 'null' client. " +
|
" returned a 'null' client. " +
|
||||||
"This is most likely a bug in the pool implementation.");
|
"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 {
|
try {
|
||||||
for (FTPFile ftpFile : fileList) {
|
for (FTPFile ftpFile : fileList) {
|
||||||
if ((ftpFile != null) && ftpFile.isFile()) {
|
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.Resource;
|
||||||
import org.springframework.core.io.ResourceEditor;
|
import org.springframework.core.io.ResourceEditor;
|
||||||
import org.springframework.core.io.ResourceLoader;
|
import org.springframework.core.io.ResourceLoader;
|
||||||
import org.springframework.integration.file.entries.CompositeEntryListFilter;
|
import org.springframework.integration.file.filters.CompositeFileListFilter;
|
||||||
import org.springframework.integration.file.entries.EntryListFilter;
|
import org.springframework.integration.file.filters.FileListFilter;
|
||||||
import org.springframework.integration.file.entries.PatternMatchingEntryListFilter;
|
import org.springframework.integration.file.filters.PatternMatchingFileListFilter;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,7 +62,7 @@ public class FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean
|
|||||||
|
|
||||||
protected volatile Resource localDirectoryResource;
|
protected volatile Resource localDirectoryResource;
|
||||||
|
|
||||||
protected volatile EntryListFilter<FTPFile> filter;
|
protected volatile FileListFilter<FTPFile> filter;
|
||||||
|
|
||||||
protected volatile int clientMode = FTPClient.ACTIVE_LOCAL_DATA_CONNECTION_MODE;
|
protected volatile int clientMode = FTPClient.ACTIVE_LOCAL_DATA_CONNECTION_MODE;
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ public class FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean
|
|||||||
this.localWorkingDirectory = localWorkingDirectory;
|
this.localWorkingDirectory = localWorkingDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFilter(EntryListFilter<FTPFile> filter) {
|
public void setFilter(FileListFilter<FTPFile> filter) {
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,11 +155,11 @@ public class FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean
|
|||||||
}
|
}
|
||||||
this.localDirectoryResource = this.fromText(this.localWorkingDirectory);
|
this.localDirectoryResource = this.fromText(this.localWorkingDirectory);
|
||||||
FtpFileEntryNameExtractor fileEntryNameExtractor = new FtpFileEntryNameExtractor();
|
FtpFileEntryNameExtractor fileEntryNameExtractor = new FtpFileEntryNameExtractor();
|
||||||
CompositeEntryListFilter<FTPFile> compositeFtpFileListFilter = new CompositeEntryListFilter<FTPFile>();
|
CompositeFileListFilter<FTPFile> compositeFtpFileListFilter = new CompositeFileListFilter<FTPFile>();
|
||||||
if (StringUtils.hasText(this.filenamePattern)) {
|
if (StringUtils.hasText(this.filenamePattern)) {
|
||||||
PatternMatchingEntryListFilter<FTPFile> ftpFilePatternMatchingEntryListFilter =
|
PatternMatchingFileListFilter<FTPFile> ftpFilePatternMatchingFileListFilter =
|
||||||
new PatternMatchingEntryListFilter<FTPFile>(fileEntryNameExtractor, filenamePattern);
|
new PatternMatchingFileListFilter<FTPFile>(fileEntryNameExtractor, filenamePattern);
|
||||||
compositeFtpFileListFilter.addFilter(ftpFilePatternMatchingEntryListFilter);
|
compositeFtpFileListFilter.addFilter(ftpFilePatternMatchingFileListFilter);
|
||||||
}
|
}
|
||||||
if (this.filter != null) {
|
if (this.filter != null) {
|
||||||
compositeFtpFileListFilter.addFilter(this.filter);
|
compositeFtpFileListFilter.addFilter(this.filter);
|
||||||
|
|||||||
@@ -62,7 +62,7 @@
|
|||||||
<!-- </ftps:inbound-channel-adapter>-->
|
<!-- </ftps:inbound-channel-adapter>-->
|
||||||
|
|
||||||
<bean id="filter" class="org.mockito.Mockito" factory-method="mock">
|
<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>
|
</bean>
|
||||||
|
|
||||||
<int:channel id="ftpIn">
|
<int:channel id="ftpIn">
|
||||||
|
|||||||
@@ -16,16 +16,18 @@
|
|||||||
|
|
||||||
package org.springframework.integration.sftp.config;
|
package org.springframework.integration.sftp.config;
|
||||||
|
|
||||||
import com.jcraft.jsch.ChannelSftp;
|
import java.io.File;
|
||||||
|
|
||||||
import org.apache.commons.lang.SystemUtils;
|
import org.apache.commons.lang.SystemUtils;
|
||||||
|
|
||||||
import org.springframework.beans.factory.config.AbstractFactoryBean;
|
import org.springframework.beans.factory.config.AbstractFactoryBean;
|
||||||
import org.springframework.context.ResourceLoaderAware;
|
import org.springframework.context.ResourceLoaderAware;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.core.io.ResourceEditor;
|
import org.springframework.core.io.ResourceEditor;
|
||||||
import org.springframework.core.io.ResourceLoader;
|
import org.springframework.core.io.ResourceLoader;
|
||||||
import org.springframework.integration.file.entries.CompositeEntryListFilter;
|
import org.springframework.integration.file.filters.CompositeFileListFilter;
|
||||||
import org.springframework.integration.file.entries.EntryListFilter;
|
import org.springframework.integration.file.filters.FileListFilter;
|
||||||
import org.springframework.integration.file.entries.PatternMatchingEntryListFilter;
|
import org.springframework.integration.file.filters.PatternMatchingFileListFilter;
|
||||||
import org.springframework.integration.sftp.QueuedSftpSessionPool;
|
import org.springframework.integration.sftp.QueuedSftpSessionPool;
|
||||||
import org.springframework.integration.sftp.SftpEntryNameExtractor;
|
import org.springframework.integration.sftp.SftpEntryNameExtractor;
|
||||||
import org.springframework.integration.sftp.SftpSessionFactory;
|
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.integration.sftp.impl.SftpInboundRemoteFileSystemSynchronizingMessageSource;
|
||||||
import org.springframework.util.StringUtils;
|
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
|
* 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 String filenamePattern;
|
||||||
|
|
||||||
private volatile EntryListFilter<ChannelSftp.LsEntry> filter;
|
private volatile FileListFilter<ChannelSftp.LsEntry> filter;
|
||||||
|
|
||||||
private int port = 22;
|
private int port = 22;
|
||||||
|
|
||||||
@@ -92,7 +94,7 @@ public class SftpRemoteFileSystemSynchronizingMessageSourceFactoryBean
|
|||||||
this.filenamePattern = filenamePattern;
|
this.filenamePattern = filenamePattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFilter(EntryListFilter<ChannelSftp.LsEntry> filter) {
|
public void setFilter(FileListFilter<ChannelSftp.LsEntry> filter) {
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,10 +172,10 @@ public class SftpRemoteFileSystemSynchronizingMessageSourceFactoryBean
|
|||||||
|
|
||||||
// remote predicates
|
// remote predicates
|
||||||
SftpEntryNameExtractor sftpEntryNameExtractor = new SftpEntryNameExtractor();
|
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)) {
|
if (StringUtils.hasText(this.filenamePattern)) {
|
||||||
PatternMatchingEntryListFilter<ChannelSftp.LsEntry> ftpFilePatternMatchingEntryListFilter =
|
PatternMatchingFileListFilter<ChannelSftp.LsEntry> ftpFilePatternMatchingEntryListFilter =
|
||||||
new PatternMatchingEntryListFilter<ChannelSftp.LsEntry>(sftpEntryNameExtractor, filenamePattern);
|
new PatternMatchingFileListFilter<ChannelSftp.LsEntry>(sftpEntryNameExtractor, filenamePattern);
|
||||||
compositeFtpFileListFilter.addFilter(ftpFilePatternMatchingEntryListFilter);
|
compositeFtpFileListFilter.addFilter(ftpFilePatternMatchingEntryListFilter);
|
||||||
}
|
}
|
||||||
if (this.filter != null) {
|
if (this.filter != null) {
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ public class SftpInboundRemoteFileSystemSynchronizer extends AbstractInboundRemo
|
|||||||
ChannelSftp channelSftp = session.getChannel();
|
ChannelSftp channelSftp = session.getChannel();
|
||||||
Collection<ChannelSftp.LsEntry> beforeFilter = channelSftp.ls(remotePath);
|
Collection<ChannelSftp.LsEntry> beforeFilter = channelSftp.ls(remotePath);
|
||||||
ChannelSftp.LsEntry[] entries = (beforeFilter == null) ? new ChannelSftp.LsEntry[0] : beforeFilter.toArray(new ChannelSftp.LsEntry[beforeFilter.size()]);
|
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) {
|
for (ChannelSftp.LsEntry lsEntry : files) {
|
||||||
if ((lsEntry != null) && !lsEntry.getAttrs().isDir() && !lsEntry.getAttrs().isLink()) {
|
if ((lsEntry != null) && !lsEntry.getAttrs().isDir() && !lsEntry.getAttrs().isLink()) {
|
||||||
copyFromRemoteToLocalDirectory(session, lsEntry, this.localDirectory);
|
copyFromRemoteToLocalDirectory(session, lsEntry, this.localDirectory);
|
||||||
|
|||||||
@@ -56,7 +56,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<beans:bean id="filter" class="org.mockito.Mockito" factory-method="mock">
|
<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:bean>
|
||||||
|
|
||||||
</beans:beans>
|
</beans:beans>
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.integration.sftp;
|
package org.springframework.integration.sftp;
|
||||||
|
|
||||||
import static junit.framework.Assert.assertTrue;
|
import static junit.framework.Assert.assertTrue;
|
||||||
@@ -22,13 +23,12 @@ import java.io.File;
|
|||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanCreationException;
|
import org.springframework.beans.factory.BeanCreationException;
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Oleg Zhurakousky
|
* @author Oleg Zhurakousky
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class SftpParserTests {
|
public class SftpParserTests {
|
||||||
|
|
||||||
@@ -44,11 +44,13 @@ public class SftpParserTests {
|
|||||||
assertTrue(new File("target/foo").exists());
|
assertTrue(new File("target/foo").exists());
|
||||||
assertTrue(!new File("target/bar").exists());
|
assertTrue(!new File("target/bar").exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=BeanCreationException.class)
|
@Test(expected=BeanCreationException.class)
|
||||||
public void testLocalFilesAutoCreationFalse() throws Exception{
|
public void testLocalFilesAutoCreationFalse() throws Exception{
|
||||||
assertTrue(!new File("target/bar").exists());
|
assertTrue(!new File("target/bar").exists());
|
||||||
new ClassPathXmlApplicationContext("SftpParserTests-inbound-all-fail.xml", this.getClass());
|
new ClassPathXmlApplicationContext("SftpParserTests-inbound-all-fail.xml", this.getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLocalFilesAreFound() throws Exception{
|
public void testLocalFilesAreFound() throws Exception{
|
||||||
assertTrue(new File("target").exists());
|
assertTrue(new File("target").exists());
|
||||||
@@ -60,4 +62,5 @@ public class SftpParserTests {
|
|||||||
public void cleanUp() throws Exception{
|
public void cleanUp() throws Exception{
|
||||||
new File("target/foo").delete();
|
new File("target/foo").delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user