Repository: mina-sshd Updated Branches: refs/heads/master b1464ecc1 -> 539893ca6
[SSHD-787] Move all SCP stream resolution code into the ScpFileOpener instead of separate interfaces Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/539893ca Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/539893ca Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/539893ca Branch: refs/heads/master Commit: 539893ca6bbcd2864f5c5f795ad10d7f0fbadc15 Parents: b1464ec Author: Goldstein Lyor <[email protected]> Authored: Thu Dec 21 07:23:36 2017 +0200 Committer: Goldstein Lyor <[email protected]> Committed: Thu Dec 21 09:34:06 2017 +0200 ---------------------------------------------------------------------- .../sshd/client/ClientFactoryManager.java | 2 - .../java/org/apache/sshd/client/SshClient.java | 12 ----- .../sshd/client/scp/DefaultScpClient.java | 15 ++---- .../sshd/client/scp/ScpClientCreator.java | 43 ++++++----------- .../client/session/AbstractClientSession.java | 16 +------ .../apache/sshd/common/scp/ScpFileOpener.java | 4 ++ .../org/apache/sshd/common/scp/ScpHelper.java | 10 ++-- .../common/scp/ScpStreamResolverFactory.java | 32 ------------- .../scp/ScpStreamResolverFactoryHolder.java | 29 ------------ .../scp/helpers/DefaultScpFileOpener.java | 12 +++++ .../DefaultScpStreamResolverFactory.java | 50 -------------------- .../org/apache/sshd/server/scp/ScpCommand.java | 9 +--- .../sshd/server/scp/ScpCommandFactory.java | 35 ++++---------- .../org/apache/sshd/client/scp/ScpTest.java | 8 +--- .../apache/sshd/spring/SpringConfigTest.java | 2 +- 15 files changed, 53 insertions(+), 226 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/539893ca/sshd-core/src/main/java/org/apache/sshd/client/ClientFactoryManager.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/ClientFactoryManager.java b/sshd-core/src/main/java/org/apache/sshd/client/ClientFactoryManager.java index e116651..31b2a22 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/ClientFactoryManager.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/ClientFactoryManager.java @@ -24,7 +24,6 @@ import org.apache.sshd.client.session.ClientProxyConnectorHolder; import org.apache.sshd.common.FactoryManager; import org.apache.sshd.common.config.keys.FilePasswordProvider; import org.apache.sshd.common.scp.ScpFileOpenerHolder; -import org.apache.sshd.common.scp.ScpStreamResolverFactoryHolder; /** * The <code>ClientFactoryManager</code> enable the retrieval of additional @@ -35,7 +34,6 @@ import org.apache.sshd.common.scp.ScpStreamResolverFactoryHolder; public interface ClientFactoryManager extends FactoryManager, ScpFileOpenerHolder, - ScpStreamResolverFactoryHolder, ClientProxyConnectorHolder, ClientAuthenticationManager { http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/539893ca/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java b/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java index a23d098..0e8979e 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java @@ -115,7 +115,6 @@ import org.apache.sshd.common.keyprovider.KeyPairProvider; import org.apache.sshd.common.mac.BuiltinMacs; import org.apache.sshd.common.mac.Mac; import org.apache.sshd.common.scp.ScpFileOpener; -import org.apache.sshd.common.scp.ScpStreamResolverFactory; import org.apache.sshd.common.session.helpers.AbstractSession; import org.apache.sshd.common.util.GenericUtils; import org.apache.sshd.common.util.OsUtils; @@ -212,7 +211,6 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa private FilePasswordProvider filePasswordProvider; private PasswordIdentityProvider passwordIdentityProvider; private ScpFileOpener scpOpener; - private ScpStreamResolverFactory scpStreamFactory; private final List<Object> identities = new CopyOnWriteArrayList<>(); private final AuthenticationIdentitiesProvider identitiesProvider; @@ -250,16 +248,6 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa } @Override - public ScpStreamResolverFactory getScpStreamResolverFactory() { - return scpStreamFactory; - } - - @Override - public void setScpStreamResolverFactory(ScpStreamResolverFactory factory) { - scpStreamFactory = factory; - } - - @Override public ServerKeyVerifier getServerKeyVerifier() { return serverKeyVerifier; } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/539893ca/sshd-core/src/main/java/org/apache/sshd/client/scp/DefaultScpClient.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/scp/DefaultScpClient.java b/sshd-core/src/main/java/org/apache/sshd/client/scp/DefaultScpClient.java index ead4c52..dfc7f7d 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/scp/DefaultScpClient.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/scp/DefaultScpClient.java @@ -47,11 +47,9 @@ import org.apache.sshd.common.file.util.MockPath; import org.apache.sshd.common.scp.ScpFileOpener; import org.apache.sshd.common.scp.ScpHelper; import org.apache.sshd.common.scp.ScpLocation; -import org.apache.sshd.common.scp.ScpStreamResolverFactory; import org.apache.sshd.common.scp.ScpTimestamp; import org.apache.sshd.common.scp.ScpTransferEventListener; import org.apache.sshd.common.scp.helpers.DefaultScpFileOpener; -import org.apache.sshd.common.scp.helpers.DefaultScpStreamResolverFactory; import org.apache.sshd.common.util.GenericUtils; import org.apache.sshd.common.util.ValidateUtils; import org.apache.sshd.common.util.io.NoCloseInputStream; @@ -66,16 +64,13 @@ public class DefaultScpClient extends AbstractScpClient { public static final String SCP_PORT_OPTION = "-P"; protected final ScpFileOpener opener; - protected final ScpStreamResolverFactory streamFactory; protected final ScpTransferEventListener listener; private final ClientSession clientSession; public DefaultScpClient( - ClientSession clientSession, ScpFileOpener fileOpener, - ScpStreamResolverFactory streamFactory, ScpTransferEventListener eventListener) { + ClientSession clientSession, ScpFileOpener fileOpener, ScpTransferEventListener eventListener) { this.clientSession = Objects.requireNonNull(clientSession, "No client session"); this.opener = (fileOpener == null) ? DefaultScpFileOpener.INSTANCE : fileOpener; - this.streamFactory = (streamFactory == null) ? DefaultScpStreamResolverFactory.INSTANCE : streamFactory; this.listener = (eventListener == null) ? ScpTransferEventListener.EMPTY : eventListener; } @@ -92,7 +87,7 @@ public class DefaultScpClient extends AbstractScpClient { try (InputStream invOut = channel.getInvertedOut(); OutputStream invIn = channel.getInvertedIn()) { // NOTE: we use a mock file system since we expect no invocations for it - ScpHelper helper = new ScpHelper(session, invOut, invIn, new MockFileSystem(remote), opener, streamFactory, listener); + ScpHelper helper = new ScpHelper(session, invOut, invIn, new MockFileSystem(remote), opener, listener); helper.receiveFileStream(local, ScpHelper.DEFAULT_RECEIVE_BUFFER_SIZE); handleCommandExitStatus(cmd, channel); } finally { @@ -107,7 +102,7 @@ public class DefaultScpClient extends AbstractScpClient { ChannelExec channel = openCommandChannel(session, cmd); try (InputStream invOut = channel.getInvertedOut(); OutputStream invIn = channel.getInvertedIn()) { - ScpHelper helper = new ScpHelper(session, invOut, invIn, fs, opener, streamFactory, listener); + ScpHelper helper = new ScpHelper(session, invOut, invIn, fs, opener, listener); helper.receive(local, options.contains(Option.Recursive), options.contains(Option.TargetIsDirectory), @@ -132,7 +127,7 @@ public class DefaultScpClient extends AbstractScpClient { try (InputStream invOut = channel.getInvertedOut(); OutputStream invIn = channel.getInvertedIn()) { // NOTE: we use a mock file system since we expect no invocations for it - ScpHelper helper = new ScpHelper(session, invOut, invIn, new MockFileSystem(remote), opener, streamFactory, listener); + ScpHelper helper = new ScpHelper(session, invOut, invIn, new MockFileSystem(remote), opener, listener); Path mockPath = new MockPath(remote); helper.sendStream(new DefaultScpStreamResolver(name, mockPath, perms, time, size, local, cmd), options.contains(Option.PreserveAttributes), ScpHelper.DEFAULT_SEND_BUFFER_SIZE); @@ -160,7 +155,7 @@ public class DefaultScpClient extends AbstractScpClient { try (InputStream invOut = channel.getInvertedOut(); OutputStream invIn = channel.getInvertedIn()) { - ScpHelper helper = new ScpHelper(session, invOut, invIn, fs, opener, streamFactory, listener); + ScpHelper helper = new ScpHelper(session, invOut, invIn, fs, opener, listener); executor.execute(helper, local, options); } finally { try { http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/539893ca/sshd-core/src/main/java/org/apache/sshd/client/scp/ScpClientCreator.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/scp/ScpClientCreator.java b/sshd-core/src/main/java/org/apache/sshd/client/scp/ScpClientCreator.java index 502e5aa..8f8ab63 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/scp/ScpClientCreator.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/scp/ScpClientCreator.java @@ -21,63 +21,49 @@ package org.apache.sshd.client.scp; import org.apache.sshd.common.scp.ScpFileOpener; import org.apache.sshd.common.scp.ScpFileOpenerHolder; -import org.apache.sshd.common.scp.ScpStreamResolverFactory; -import org.apache.sshd.common.scp.ScpStreamResolverFactoryHolder; import org.apache.sshd.common.scp.ScpTransferEventListener; /** * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> */ -public interface ScpClientCreator extends ScpFileOpenerHolder, ScpStreamResolverFactoryHolder { +public interface ScpClientCreator extends ScpFileOpenerHolder { /** * Create an SCP client from this session. * * @return An {@link ScpClient} instance. <B>Note:</B> uses the currently * registered {@link ScpTransferEventListener}, {@link ScpStreamResolverFactoryHolder} - * and {@link ScpFileOpener} if any + * and {@link ScpFileOpener} if any * @see #setScpFileOpener(ScpFileOpener) - * @see #setScpStreamResolverFactory(ScpStreamResolverFactory) * @see #setScpTransferEventListener(ScpTransferEventListener) */ default ScpClient createScpClient() { - return createScpClient(getScpFileOpener(), getScpStreamResolverFactory(), getScpTransferEventListener()); + return createScpClient(getScpFileOpener(), getScpTransferEventListener()); } /** * Create an SCP client from this session. * * @param listener A {@link ScpTransferEventListener} that can be used - * to receive information about the SCP operations - may be {@code null} - * to indicate no more events are required. <B>Note:</B> this listener - * is used <U>instead</U> of any listener set via {@link #setScpTransferEventListener(ScpTransferEventListener)} + * to receive information about the SCP operations - may be {@code null} + * to indicate no more events are required. <B>Note:</B> this listener + * is used <U>instead</U> of any listener set via {@link #setScpTransferEventListener(ScpTransferEventListener)} * @return An {@link ScpClient} instance */ default ScpClient createScpClient(ScpTransferEventListener listener) { - return createScpClient(getScpFileOpener(), getScpStreamResolverFactory(), listener); + return createScpClient(getScpFileOpener(), listener); } /** * Create an SCP client from this session. * * @param opener The {@link ScpFileOpener} to use to control how local files - * are read/written. If {@code null} then a default opener is used. - * <B>Note:</B> this opener is used <U>instead</U> of any instance - * set via {@link #setScpFileOpener(ScpFileOpener)} + * are read/written. If {@code null} then a default opener is used. + * <B>Note:</B> this opener is used <U>instead</U> of any instance + * set via {@link #setScpFileOpener(ScpFileOpener)} * @return An {@link ScpClient} instance */ default ScpClient createScpClient(ScpFileOpener opener) { - return createScpClient(opener, getScpStreamResolverFactory(), getScpTransferEventListener()); - } - - /** - * Create an SCP client from this session. - * - * @param factory The {@link ScpStreamResolverFactory} used to create input/output stream - * for incoming/outgoing files - * @return An {@link ScpClient} instance - */ - default ScpClient createScpClient(ScpStreamResolverFactory factory) { - return createScpClient(getScpFileOpener(), factory, getScpTransferEventListener()); + return createScpClient(opener, getScpTransferEventListener()); } /** @@ -87,15 +73,14 @@ public interface ScpClientCreator extends ScpFileOpenerHolder, ScpStreamResolver * are read/written. If {@code null} then a default opener is used. * <B>Note:</B> this opener is used <U>instead</U> of any instance * set via {@link #setScpFileOpener(ScpFileOpener)} - * @param factory The {@link ScpStreamResolverFactory} to use in order to create - * incoming/outgoing streams for received/sent files * @param listener A {@link ScpTransferEventListener} that can be used * to receive information about the SCP operations - may be {@code null} * to indicate no more events are required. <B>Note:</B> this listener - * is used <U>instead</U> of any listener set via {@link #setScpTransferEventListener(ScpTransferEventListener)} + * is used <U>instead</U> of any listener set via + * {@link #setScpTransferEventListener(ScpTransferEventListener)} * @return An {@link ScpClient} instance */ - ScpClient createScpClient(ScpFileOpener opener, ScpStreamResolverFactory factory, ScpTransferEventListener listener); + ScpClient createScpClient(ScpFileOpener opener, ScpTransferEventListener listener); /** * @return The last {@link ScpTransferEventListener} set via http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/539893ca/sshd-core/src/main/java/org/apache/sshd/client/session/AbstractClientSession.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/session/AbstractClientSession.java b/sshd-core/src/main/java/org/apache/sshd/client/session/AbstractClientSession.java index ee8c550..b67310d 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/session/AbstractClientSession.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/session/AbstractClientSession.java @@ -66,7 +66,6 @@ import org.apache.sshd.common.io.IoWriteFuture; import org.apache.sshd.common.kex.KexProposalOption; import org.apache.sshd.common.kex.KexState; import org.apache.sshd.common.scp.ScpFileOpener; -import org.apache.sshd.common.scp.ScpStreamResolverFactory; import org.apache.sshd.common.scp.ScpTransferEventListener; import org.apache.sshd.common.session.ConnectionService; import org.apache.sshd.common.session.Session; @@ -91,7 +90,6 @@ public abstract class AbstractClientSession extends AbstractSession implements C private List<NamedFactory<UserAuth>> userAuthFactories; private ScpTransferEventListener scpListener; private ScpFileOpener scpOpener; - private ScpStreamResolverFactory scpStreamFactory; private SocketAddress connectAddress; private ClientProxyConnector proxyConnector; @@ -319,16 +317,6 @@ public abstract class AbstractClientSession extends AbstractSession implements C } @Override - public ScpStreamResolverFactory getScpStreamResolverFactory() { - return resolveEffectiveProvider(ScpStreamResolverFactory.class, scpStreamFactory, getFactoryManager().getScpStreamResolverFactory()); - } - - @Override - public void setScpStreamResolverFactory(ScpStreamResolverFactory factory) { - scpStreamFactory = factory; - } - - @Override public ScpTransferEventListener getScpTransferEventListener() { return scpListener; } @@ -339,8 +327,8 @@ public abstract class AbstractClientSession extends AbstractSession implements C } @Override - public ScpClient createScpClient(ScpFileOpener opener, ScpStreamResolverFactory factory, ScpTransferEventListener listener) { - return new DefaultScpClient(this, opener, factory, listener); + public ScpClient createScpClient(ScpFileOpener opener, ScpTransferEventListener listener) { + return new DefaultScpClient(this, opener, listener); } @Override http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/539893ca/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpFileOpener.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpFileOpener.java b/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpFileOpener.java index 3ef8c28..5b78fda 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpFileOpener.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpFileOpener.java @@ -166,6 +166,8 @@ public interface ScpFileOpener { */ InputStream openRead(Session session, Path file, OpenOption... options) throws IOException; + ScpSourceStreamResolver createScpSourceStreamResolver(Path path) throws IOException; + /** * Create an output stream to write to a file * @@ -177,6 +179,8 @@ public interface ScpFileOpener { */ OutputStream openWrite(Session session, Path file, OpenOption... options) throws IOException; + ScpTargetStreamResolver createScpTargetStreamResolver(Path path) throws IOException; + static void updateFileProperties(Path file, Set<PosixFilePermission> perms, ScpTimestamp time) throws IOException { IoUtils.setPermissions(file, perms); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/539893ca/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpHelper.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpHelper.java b/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpHelper.java index 6075234..e8183c8 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpHelper.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpHelper.java @@ -46,7 +46,6 @@ import java.util.concurrent.TimeUnit; import org.apache.sshd.common.file.util.MockPath; import org.apache.sshd.common.scp.ScpTransferEventListener.FileOperation; import org.apache.sshd.common.scp.helpers.DefaultScpFileOpener; -import org.apache.sshd.common.scp.helpers.DefaultScpStreamResolverFactory; import org.apache.sshd.common.session.Session; import org.apache.sshd.common.session.SessionHolder; import org.apache.sshd.common.util.GenericUtils; @@ -101,20 +100,17 @@ public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Sess protected final OutputStream out; protected final FileSystem fileSystem; protected final ScpFileOpener opener; - protected final ScpStreamResolverFactory streamFactory; protected final ScpTransferEventListener listener; private final Session sessionInstance; public ScpHelper(Session session, InputStream in, OutputStream out, - FileSystem fileSystem, ScpFileOpener opener, - ScpStreamResolverFactory streamFactory, ScpTransferEventListener eventListener) { + FileSystem fileSystem, ScpFileOpener opener, ScpTransferEventListener eventListener) { this.sessionInstance = Objects.requireNonNull(session, "No session"); this.in = Objects.requireNonNull(in, "No input stream"); this.out = Objects.requireNonNull(out, "No output stream"); this.fileSystem = fileSystem; this.opener = (opener == null) ? DefaultScpFileOpener.INSTANCE : opener; - this.streamFactory = (streamFactory == null) ? DefaultScpStreamResolverFactory.INSTANCE : streamFactory; this.listener = (eventListener == null) ? ScpTransferEventListener.EMPTY : eventListener; } @@ -286,7 +282,7 @@ public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Sess this, header, path, preserve, time, bufferSize); } - receiveStream(header, streamFactory.createScpTargetStreamResolver(path, opener), time, preserve, bufferSize); + receiveStream(header, opener.createScpTargetStreamResolver(path), time, preserve, bufferSize); } public void receiveStream(String header, ScpTargetStreamResolver resolver, ScpTimestamp time, boolean preserve, int bufferSize) throws IOException { @@ -482,7 +478,7 @@ public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Sess log.debug("sendFile({})[preserve={},buffer-size={}] Sending file {}", this, preserve, bufferSize, path); } - sendStream(streamFactory.createScpSourceStreamResolver(path, opener), preserve, bufferSize); + sendStream(opener.createScpSourceStreamResolver(path), preserve, bufferSize); } public void sendStream(ScpSourceStreamResolver resolver, boolean preserve, int bufferSize) throws IOException { http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/539893ca/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpStreamResolverFactory.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpStreamResolverFactory.java b/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpStreamResolverFactory.java deleted file mode 100644 index 0dce708..0000000 --- a/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpStreamResolverFactory.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.sshd.common.scp; - -import java.io.IOException; -import java.nio.file.Path; - -/** - * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> - */ -public interface ScpStreamResolverFactory { - ScpSourceStreamResolver createScpSourceStreamResolver(Path path, ScpFileOpener opener) throws IOException; - - ScpTargetStreamResolver createScpTargetStreamResolver(Path path, ScpFileOpener opener) throws IOException; -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/539893ca/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpStreamResolverFactoryHolder.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpStreamResolverFactoryHolder.java b/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpStreamResolverFactoryHolder.java deleted file mode 100644 index 3483629..0000000 --- a/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpStreamResolverFactoryHolder.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.sshd.common.scp; - -/** - * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> - */ -public interface ScpStreamResolverFactoryHolder { - ScpStreamResolverFactory getScpStreamResolverFactory(); - - void setScpStreamResolverFactory(ScpStreamResolverFactory factory); -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/539893ca/sshd-core/src/main/java/org/apache/sshd/common/scp/helpers/DefaultScpFileOpener.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/scp/helpers/DefaultScpFileOpener.java b/sshd-core/src/main/java/org/apache/sshd/common/scp/helpers/DefaultScpFileOpener.java index cdf39d4..bb6ae3b 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/scp/helpers/DefaultScpFileOpener.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/scp/helpers/DefaultScpFileOpener.java @@ -28,6 +28,8 @@ import java.nio.file.Path; import java.util.Arrays; import org.apache.sshd.common.scp.ScpFileOpener; +import org.apache.sshd.common.scp.ScpSourceStreamResolver; +import org.apache.sshd.common.scp.ScpTargetStreamResolver; import org.apache.sshd.common.session.Session; import org.apache.sshd.common.util.logging.AbstractLoggingBean; @@ -60,4 +62,14 @@ public class DefaultScpFileOpener extends AbstractLoggingBean implements ScpFile return Files.newOutputStream(file, options); } + + @Override + public ScpSourceStreamResolver createScpSourceStreamResolver(Path path) throws IOException { + return new LocalFileScpSourceStreamResolver(path, this); + } + + @Override + public ScpTargetStreamResolver createScpTargetStreamResolver(Path path) throws IOException { + return new LocalFileScpTargetStreamResolver(path, this); + } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/539893ca/sshd-core/src/main/java/org/apache/sshd/common/scp/helpers/DefaultScpStreamResolverFactory.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/scp/helpers/DefaultScpStreamResolverFactory.java b/sshd-core/src/main/java/org/apache/sshd/common/scp/helpers/DefaultScpStreamResolverFactory.java deleted file mode 100644 index 60933e0..0000000 --- a/sshd-core/src/main/java/org/apache/sshd/common/scp/helpers/DefaultScpStreamResolverFactory.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.sshd.common.scp.helpers; - -import java.io.IOException; -import java.nio.file.Path; - -import org.apache.sshd.common.scp.ScpFileOpener; -import org.apache.sshd.common.scp.ScpSourceStreamResolver; -import org.apache.sshd.common.scp.ScpStreamResolverFactory; -import org.apache.sshd.common.scp.ScpTargetStreamResolver; -import org.apache.sshd.common.util.logging.AbstractLoggingBean; - -/** - * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> - */ -public class DefaultScpStreamResolverFactory extends AbstractLoggingBean implements ScpStreamResolverFactory { - public static final DefaultScpStreamResolverFactory INSTANCE = new DefaultScpStreamResolverFactory(); - - public DefaultScpStreamResolverFactory() { - super(); - } - - @Override - public ScpSourceStreamResolver createScpSourceStreamResolver(Path path, ScpFileOpener opener) throws IOException { - return new LocalFileScpSourceStreamResolver(path, opener); - } - - @Override - public ScpTargetStreamResolver createScpTargetStreamResolver(Path path, ScpFileOpener opener) throws IOException { - return new LocalFileScpTargetStreamResolver(path, opener); - } -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/539893ca/sshd-core/src/main/java/org/apache/sshd/server/scp/ScpCommand.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/scp/ScpCommand.java b/sshd-core/src/main/java/org/apache/sshd/server/scp/ScpCommand.java index 3667aa1..8ff52c1 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/scp/ScpCommand.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/scp/ScpCommand.java @@ -31,10 +31,8 @@ import org.apache.sshd.common.file.FileSystemAware; import org.apache.sshd.common.scp.ScpException; import org.apache.sshd.common.scp.ScpFileOpener; import org.apache.sshd.common.scp.ScpHelper; -import org.apache.sshd.common.scp.ScpStreamResolverFactory; import org.apache.sshd.common.scp.ScpTransferEventListener; import org.apache.sshd.common.scp.helpers.DefaultScpFileOpener; -import org.apache.sshd.common.scp.helpers.DefaultScpStreamResolverFactory; import org.apache.sshd.common.session.Session; import org.apache.sshd.common.session.SessionHolder; import org.apache.sshd.common.util.GenericUtils; @@ -63,7 +61,6 @@ public class ScpCommand protected final int sendBufferSize; protected final int receiveBufferSize; protected final ScpFileOpener opener; - protected final ScpStreamResolverFactory streamFactory; protected boolean optR; protected boolean optT; protected boolean optF; @@ -93,7 +90,6 @@ public class ScpCommand * @param sendSize Size (in bytes) of buffer to use when sending files * @param receiveSize Size (in bytes) of buffer to use when receiving files * @param fileOpener The {@link ScpFileOpener} - if {@code null} then {@link DefaultScpFileOpener} is used - * @param factory The {@link ScpStreamResolverFactory} - if {@code null} then {@link DefaultScpStreamResolverFactory} is used * @param eventListener An {@link ScpTransferEventListener} - may be {@code null} * @see ThreadUtils#newSingleThreadExecutor(String) * @see ScpHelper#MIN_SEND_BUFFER_SIZE @@ -102,7 +98,7 @@ public class ScpCommand public ScpCommand(String command, ExecutorService executorService, boolean shutdownOnExit, int sendSize, int receiveSize, - ScpFileOpener fileOpener, ScpStreamResolverFactory factory, ScpTransferEventListener eventListener) { + ScpFileOpener fileOpener, ScpTransferEventListener eventListener) { name = command; if (executorService == null) { @@ -129,7 +125,6 @@ public class ScpCommand receiveBufferSize = receiveSize; opener = (fileOpener == null) ? DefaultScpFileOpener.INSTANCE : fileOpener; - streamFactory = (factory == null) ? DefaultScpStreamResolverFactory.INSTANCE : factory; listener = (eventListener == null) ? ScpTransferEventListener.EMPTY : eventListener; if (log.isDebugEnabled()) { @@ -273,7 +268,7 @@ public class ScpCommand public void run() { int exitValue = ScpHelper.OK; String exitMessage = null; - ScpHelper helper = new ScpHelper(getServerSession(), in, out, fileSystem, opener, streamFactory, listener); + ScpHelper helper = new ScpHelper(getServerSession(), in, out, fileSystem, opener, listener); try { if (optT) { helper.receive(helper.resolveLocalPath(path), optR, optD, optP, receiveBufferSize); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/539893ca/sshd-core/src/main/java/org/apache/sshd/server/scp/ScpCommandFactory.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/scp/ScpCommandFactory.java b/sshd-core/src/main/java/org/apache/sshd/server/scp/ScpCommandFactory.java index b3b2d89..99e3e34 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/scp/ScpCommandFactory.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/scp/ScpCommandFactory.java @@ -25,8 +25,6 @@ import java.util.concurrent.ExecutorService; import org.apache.sshd.common.scp.ScpFileOpener; import org.apache.sshd.common.scp.ScpFileOpenerHolder; import org.apache.sshd.common.scp.ScpHelper; -import org.apache.sshd.common.scp.ScpStreamResolverFactory; -import org.apache.sshd.common.scp.ScpStreamResolverFactoryHolder; import org.apache.sshd.common.scp.ScpTransferEventListener; import org.apache.sshd.common.util.EventListenerUtils; import org.apache.sshd.common.util.ObjectBuilder; @@ -44,7 +42,6 @@ import org.apache.sshd.server.CommandFactory; */ public class ScpCommandFactory implements ScpFileOpenerHolder, - ScpStreamResolverFactoryHolder, CommandFactory, Cloneable, ExecutorServiceConfigurer { @@ -63,11 +60,6 @@ public class ScpCommandFactory return this; } - public Builder withScpStreamResolverFactory(ScpStreamResolverFactory streamFactory) { - factory.setScpStreamResolverFactory(streamFactory); - return this; - } - public Builder withDelegate(CommandFactory delegate) { factory.setDelegateCommandFactory(delegate); return this; @@ -117,7 +109,6 @@ public class ScpCommandFactory private ExecutorService executors; private boolean shutdownExecutor; private ScpFileOpener fileOpener; - private ScpStreamResolverFactory streamFactory; private int sendBufferSize = ScpHelper.MIN_SEND_BUFFER_SIZE; private int receiveBufferSize = ScpHelper.MIN_RECEIVE_BUFFER_SIZE; private Collection<ScpTransferEventListener> listeners = new CopyOnWriteArraySet<>(); @@ -137,25 +128,15 @@ public class ScpCommandFactory this.fileOpener = fileOpener; } - @Override - public ScpStreamResolverFactory getScpStreamResolverFactory() { - return streamFactory; - } - - @Override - public void setScpStreamResolverFactory(ScpStreamResolverFactory streamFactory) { - this.streamFactory = streamFactory; - } - public CommandFactory getDelegateCommandFactory() { return delegate; } /** * @param factory A {@link CommandFactory} to be used if the - * command is not an SCP one. If {@code null} then an {@link IllegalArgumentException} - * will be thrown when attempting to invoke {@link #createCommand(String)} - * with a non-SCP command + * command is not an SCP one. If {@code null} then an {@link IllegalArgumentException} + * will be thrown when attempting to invoke {@link #createCommand(String)} + * with a non-SCP command */ public void setDelegateCommandFactory(CommandFactory factory) { delegate = factory; @@ -168,10 +149,10 @@ public class ScpCommandFactory /** * @param service An {@link ExecutorService} to be used when - * starting {@link ScpCommand} execution. If {@code null} then a single-threaded - * ad-hoc service is used. <B>Note:</B> the service will <U>not</U> be shutdown - * when the command is terminated - unless it is the ad-hoc service, which will be - * shutdown regardless + * starting {@link ScpCommand} execution. If {@code null} then a single-threaded + * ad-hoc service is used. <B>Note:</B> the service will <U>not</U> be shutdown + * when the command is terminated - unless it is the ad-hoc service, which will be + * shutdown regardless */ @Override public void setExecutorService(ExecutorService service) { @@ -265,7 +246,7 @@ public class ScpCommandFactory return new ScpCommand(command, getExecutorService(), isShutdownOnExit(), getSendBufferSize(), getReceiveBufferSize(), - getScpFileOpener(), getScpStreamResolverFactory(), listenerProxy); + getScpFileOpener(), listenerProxy); } CommandFactory factory = getDelegateCommandFactory(); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/539893ca/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java b/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java index 56ee962..643e238 100644 --- a/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java @@ -53,10 +53,8 @@ import org.apache.sshd.common.random.Random; import org.apache.sshd.common.scp.ScpException; import org.apache.sshd.common.scp.ScpFileOpener; import org.apache.sshd.common.scp.ScpHelper; -import org.apache.sshd.common.scp.ScpStreamResolverFactory; import org.apache.sshd.common.scp.ScpTransferEventListener; import org.apache.sshd.common.scp.helpers.DefaultScpFileOpener; -import org.apache.sshd.common.scp.helpers.DefaultScpStreamResolverFactory; import org.apache.sshd.common.session.Session; import org.apache.sshd.common.util.GenericUtils; import org.apache.sshd.common.util.OsUtils; @@ -770,9 +768,8 @@ public class ScpTest extends BaseTestSupport { private ExitCallback delegate; InternalScpCommand(String command, ExecutorService executorService, boolean shutdownOnExit, - int sendSize, int receiveSize, ScpFileOpener opener, - ScpStreamResolverFactory factory, ScpTransferEventListener eventListener) { - super(command, executorService, shutdownOnExit, sendSize, receiveSize, opener, factory, eventListener); + int sendSize, int receiveSize, ScpFileOpener opener, ScpTransferEventListener eventListener) { + super(command, executorService, shutdownOnExit, sendSize, receiveSize, opener, eventListener); } @Override @@ -812,7 +809,6 @@ public class ScpTest extends BaseTestSupport { getExecutorService(), isShutdownOnExit(), getSendBufferSize(), getReceiveBufferSize(), DefaultScpFileOpener.INSTANCE, - DefaultScpStreamResolverFactory.INSTANCE, ScpTransferEventListener.EMPTY); } }); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/539893ca/sshd-core/src/test/java/org/apache/sshd/spring/SpringConfigTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/spring/SpringConfigTest.java b/sshd-core/src/test/java/org/apache/sshd/spring/SpringConfigTest.java index 3501208..162552a 100644 --- a/sshd-core/src/test/java/org/apache/sshd/spring/SpringConfigTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/spring/SpringConfigTest.java @@ -67,7 +67,7 @@ public class SpringConfigTest extends BaseTestSupport { @After public void tearDown() throws Exception { if (context != null) { - context.destroy(); + context.close(); } }
