INT-3665: Remove Deprecations and Resolve Issues

https://jira.spring.io/browse/INT-3665

Fixes according Travis report

Introduce `...ExpressionString(String)` setter

Some further fixes and polishing

Address PR comments
This commit is contained in:
Artem Bilan
2015-08-13 16:10:36 -04:00
committed by Gary Russell
parent 84fdd98428
commit cf528c0b5d
81 changed files with 529 additions and 1168 deletions

View File

@@ -21,7 +21,6 @@ import org.w3c.dom.Element;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.ExpressionFactoryBean;
import org.springframework.integration.config.xml.AbstractConsumerEndpointParser;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.springframework.integration.file.filters.RegexPatternFileListFilter;
@@ -74,15 +73,11 @@ public abstract class AbstractRemoteFileOutboundGatewayParser extends AbstractCo
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "auto-create-local-directory");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "order");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "rename-expression");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "rename-expression",
"renameExpressionString");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "requires-reply");
String localFileGeneratorExpression = element.getAttribute("local-filename-generator-expression");
if (StringUtils.hasText(localFileGeneratorExpression)) {
BeanDefinitionBuilder localFileGeneratorExpressionBuilder =
BeanDefinitionBuilder.genericBeanDefinition(ExpressionFactoryBean.class);
localFileGeneratorExpressionBuilder.addConstructorArgValue(localFileGeneratorExpression);
builder.addPropertyValue("localFilenameGeneratorExpression", localFileGeneratorExpressionBuilder.getBeanDefinition());
}
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "local-filename-generator-expression",
"localFilenameGeneratorExpressionString");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "mode", "fileExistsMode");
return builder;
}

View File

@@ -374,30 +374,49 @@ public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReply
}
/**
* @deprecated in favor of {@link #setExpressionRename}. Will be changed in a future release
* to use an {@link Expression} parameter.
* @param expression the expression to set.
* @param renameExpression the expression to use.
* @since 4.3
*/
@Deprecated
public void setRenameExpression(String expression) {
Assert.notNull(expression, "'expression' cannot be null");
setExpressionRename(new SpelExpressionParser().parseExpression(expression));
public void setRenameExpression(Expression renameExpression) {
this.renameProcessor = new ExpressionEvaluatingMessageProcessor<String>(renameExpression);
}
/**
* Temporary, will be changed to {@link #setRenameExpression} in a future release.
* @param expression the expression to set.
* @param renameExpression the String in SpEL syntax.
* @since 4.3
*/
public void setExpressionRename(Expression expression) {
Assert.notNull(expression, "'expression' cannot be null");
this.renameProcessor = new ExpressionEvaluatingMessageProcessor<String>(expression);
public void setRenameExpressionString(String renameExpression) {
Assert.hasText(renameExpression, "'renameExpression' cannot be empty");
setRenameExpression(EXPRESSION_PARSER.parseExpression(renameExpression));
}
/**
* @param expression the expression to set.
* @deprecated in favor of {@link #setRenameExpression}.
*/
@Deprecated
public void setExpressionRename(Expression expression) {
setRenameExpression(expression);
}
/**
* @param localFilenameGeneratorExpression the expression to use.
* @since 3.0
*/
public void setLocalFilenameGeneratorExpression(Expression localFilenameGeneratorExpression) {
Assert.notNull(localFilenameGeneratorExpression, "'localFilenameGeneratorExpression' must not be null");
this.localFilenameGeneratorExpression = localFilenameGeneratorExpression;
}
/**
* @param localFilenameGeneratorExpression the String in SpEL syntax.
* @since 4.3
*/
public void setLocalFilenameGeneratorExpressionString(String localFilenameGeneratorExpression) {
Assert.hasText(localFilenameGeneratorExpression, "'localFilenameGeneratorExpression' must not be empty");
this.localFilenameGeneratorExpression = EXPRESSION_PARSER.parseExpression(localFilenameGeneratorExpression);
}
/**
* Determine the action to take when using GET and MGET operations when the file
* already exists locally, or PUT and MPUT when the file exists on the remote

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.file.remote.gateway;
import static org.hamcrest.Matchers.anyOf;
@@ -57,6 +58,7 @@ import org.mockito.stubbing.Answer;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.expression.common.LiteralExpression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.integration.file.FileHeaders;
import org.springframework.integration.file.filters.AbstractSimplePatternFileListFilter;
import org.springframework.integration.file.remote.AbstractFileInfo;
@@ -74,12 +76,15 @@ import org.springframework.messaging.support.GenericMessage;
/**
* @author Gary Russell
* @author liujiong
* @author Liu Jiong
* @author Artem Bilan
* @since 2.1
*/
@SuppressWarnings("rawtypes")
public class RemoteFileOutboundGatewayTests {
private static final SpelExpressionParser PARSER = new SpelExpressionParser();
private final String tmpDir = System.getProperty("java.io.tmpdir");
@Rule
@@ -278,12 +283,11 @@ public class RemoteFileOutboundGatewayTests {
}
@Test
@SuppressWarnings("deprecation")
public void testMoveWithExpression() throws Exception {
SessionFactory sessionFactory = mock(SessionFactory.class);
TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway
(sessionFactory, "mv", "payload");
gw.setRenameExpression("payload.substring(1)");
gw.setRenameExpression(PARSER.parseExpression("payload.substring(1)"));
gw.afterPropertiesSet();
Session<?> session = mock(Session.class);
final AtomicReference<String> args = new AtomicReference<String>();
@@ -304,12 +308,11 @@ public class RemoteFileOutboundGatewayTests {
}
@Test
@SuppressWarnings("deprecation")
public void testMoveWithMkDirs() throws Exception {
SessionFactory sessionFactory = mock(SessionFactory.class);
TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway
(sessionFactory, "mv", "payload");
gw.setRenameExpression("'foo/bar/baz'");
gw.setRenameExpression(PARSER.parseExpression("'foo/bar/baz'"));
gw.afterPropertiesSet();
Session<?> session = mock(Session.class);
final AtomicReference<String> args = new AtomicReference<String>();
@@ -1009,214 +1012,216 @@ public class RemoteFileOutboundGatewayTests {
equalTo("foo/baz.txt"), equalTo("foo/qux.txt"), equalTo("foo/" + dir1.getName() + "/" + file3.getName())));
}
}
abstract static class TestSession implements Session<TestLsEntry> {
abstract class TestSession implements org.springframework.integration.file.remote.session.Session<TestLsEntry> {
private boolean open;
private boolean open;
@Override
public boolean remove(String path) throws IOException {
return false;
@Override
public boolean remove(String path) throws IOException {
return false;
}
@Override
public TestLsEntry[] list(String path) throws IOException {
return null;
}
@Override
public void read(String source, OutputStream outputStream)
throws IOException {
}
@Override
public void write(InputStream inputStream, String destination)
throws IOException {
}
@Override
public void append(InputStream inputStream, String destination)
throws IOException {
}
@Override
public boolean mkdir(String directory) throws IOException {
return true;
}
@Override
public boolean rmdir(String directory) throws IOException {
return true;
}
@Override
public void rename(String pathFrom, String pathTo)
throws IOException {
}
@Override
public void close() {
open = false;
}
@Override
public boolean isOpen() {
return open;
}
@Override
public boolean exists(String path) throws IOException {
return true;
}
@Override
public String[] listNames(String path) throws IOException {
return null;
}
@Override
public InputStream readRaw(String source) throws IOException {
return null;
}
@Override
public boolean finalizeRaw() throws IOException {
return false;
}
@Override
public Object getClientInstance() {
return null;
}
}
@Override
public TestLsEntry[] list(String path) throws IOException {
return null;
static class TestRemoteFileOutboundGateway extends AbstractRemoteFileOutboundGateway<TestLsEntry> {
@SuppressWarnings({"rawtypes", "unchecked"})
public TestRemoteFileOutboundGateway(SessionFactory sessionFactory,
String command, String expression) {
super(sessionFactory, Command.toCommand(command), expression);
this.setBeanFactory(mock(BeanFactory.class));
}
public TestRemoteFileOutboundGateway(RemoteFileTemplate<TestLsEntry> remoteFileTemplate, String command,
String expression) {
super(remoteFileTemplate, command, expression);
this.setBeanFactory(mock(BeanFactory.class));
}
@Override
protected boolean isDirectory(TestLsEntry file) {
return file.isDirectory();
}
@Override
protected boolean isLink(TestLsEntry file) {
return file.isLink();
}
@Override
protected String getFilename(TestLsEntry file) {
return file.getFilename();
}
@Override
protected String getFilename(AbstractFileInfo<TestLsEntry> file) {
return file.getFilename();
}
@Override
protected long getModified(TestLsEntry file) {
return file.getModified();
}
@Override
protected List<AbstractFileInfo<TestLsEntry>> asFileInfoList(
Collection<TestLsEntry> files) {
return new ArrayList<AbstractFileInfo<TestLsEntry>>(files);
}
@Override
protected TestLsEntry enhanceNameWithSubDirectory(TestLsEntry file, String directory) {
file.setFilename(directory + file.getFilename());
return file;
}
}
@Override
public void read(String source, OutputStream outputStream)
throws IOException {
static class TestLsEntry extends AbstractFileInfo<TestLsEntry> {
private volatile String filename;
private final long size;
private final boolean dir;
private final boolean link;
private final long modified;
private final String permissions;
public TestLsEntry(String filename, long size, boolean dir, boolean link,
long modified, String permissions) {
this.filename = filename;
this.size = size;
this.dir = dir;
this.link = link;
this.modified = modified;
this.permissions = permissions;
}
@Override
public boolean isDirectory() {
return this.dir;
}
@Override
public long getModified() {
return this.modified;
}
@Override
public String getFilename() {
return this.filename;
}
@Override
public boolean isLink() {
return this.link;
}
@Override
public long getSize() {
return this.size;
}
@Override
public String getPermissions() {
return this.permissions;
}
@Override
public TestLsEntry getFileInfo() {
return this;
}
public void setFilename(String filename) {
this.filename = filename;
}
}
@Override
public void write(InputStream inputStream, String destination)
throws IOException {
}
static class TestPatternFilter extends AbstractSimplePatternFileListFilter<TestLsEntry> {
@Override
public void append(InputStream inputStream, String destination)
throws IOException {
}
public TestPatternFilter(String path) {
super(path);
}
@Override
public boolean mkdir(String directory) throws IOException {
return true;
}
@Override
protected String getFilename(TestLsEntry file) {
return file.getFilename();
}
@Override
public boolean rmdir(String directory) throws IOException {
return true;
}
@Override
public void rename(String pathFrom, String pathTo)
throws IOException {
}
@Override
public void close() {
open = false;
}
@Override
public boolean isOpen() {
return open;
}
@Override
public boolean exists(String path) throws IOException {
return true;
}
@Override
public String[] listNames(String path) throws IOException {
return null;
}
@Override
public InputStream readRaw(String source) throws IOException {
return null;
}
@Override
public boolean finalizeRaw() throws IOException {
return false;
}
@Override
public Object getClientInstance() {
return null;
}
}
class TestRemoteFileOutboundGateway extends AbstractRemoteFileOutboundGateway<TestLsEntry> {
@SuppressWarnings({"rawtypes", "unchecked"})
public TestRemoteFileOutboundGateway(SessionFactory sessionFactory,
String command, String expression) {
super(sessionFactory, Command.toCommand(command), expression);
this.setBeanFactory(mock(BeanFactory.class));
}
public TestRemoteFileOutboundGateway(RemoteFileTemplate<TestLsEntry> remoteFileTemplate, String command,
String expression) {
super(remoteFileTemplate, command, expression);
this.setBeanFactory(mock(BeanFactory.class));
}
@Override
protected boolean isDirectory(TestLsEntry file) {
return file.isDirectory();
}
@Override
protected boolean isLink(TestLsEntry file) {
return file.isLink();
}
@Override
protected String getFilename(TestLsEntry file) {
return file.getFilename();
}
@Override
protected String getFilename(AbstractFileInfo<TestLsEntry> file) {
return file.getFilename();
}
@Override
protected long getModified(TestLsEntry file) {
return file.getModified();
}
@Override
protected List<AbstractFileInfo<TestLsEntry>> asFileInfoList(
Collection<TestLsEntry> files) {
return new ArrayList<AbstractFileInfo<TestLsEntry>>(files);
}
@Override
protected TestLsEntry enhanceNameWithSubDirectory(TestLsEntry file, String directory) {
file.setFilename(directory + file.getFilename());
return file;
}
}
class TestLsEntry extends AbstractFileInfo<TestLsEntry> {
private volatile String filename;
private final long size;
private final boolean dir;
private final boolean link;
private final long modified;
private final String permissions;
public TestLsEntry(String filename, long size, boolean dir, boolean link,
long modified, String permissions) {
this.filename = filename;
this.size = size;
this.dir = dir;
this.link = link;
this.modified = modified;
this.permissions = permissions;
}
@Override
public boolean isDirectory() {
return this.dir;
}
@Override
public long getModified() {
return this.modified;
}
@Override
public String getFilename() {
return this.filename;
}
@Override
public boolean isLink() {
return this.link;
}
@Override
public long getSize() {
return this.size;
}
@Override
public String getPermissions() {
return this.permissions;
}
@Override
public TestLsEntry getFileInfo() {
return this;
}
public void setFilename(String filename) {
this.filename = filename;
}
}
class TestPatternFilter extends AbstractSimplePatternFileListFilter<TestLsEntry> {
public TestPatternFilter(String path) {
super(path);
}
@Override
protected String getFilename(TestLsEntry file) {
return file.getFilename();
}
}