diff -r e3d60e01a68d libs.jsch/src/com/jcraft/jsch/HotFixChannelExec.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libs.jsch/src/com/jcraft/jsch/HotFixChannelExec.java Thu Aug 19 14:07:52 2010 +0400 @@ -0,0 +1,105 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2009 Sun Microsystems, Inc. + */ +package com.jcraft.jsch; + +import java.io.IOException; +import java.io.OutputStream; + +public final class HotFixChannelExec extends ChannelExec { + + private volatile boolean isConnected; + + public void connect(int connectTimeout) throws JSchException { + try { + super.connect(connectTimeout); + } finally { + setConnected(); + } + } + + public void disconnect() { + try { + super.disconnect(); + } finally { + setConnected(); + } + } + + private void setConnected() { + isConnected = isConnected(); + } + + public OutputStream getOutputStream() throws IOException { + final OutputStream os = super.getOutputStream(); + + return new OutputStream() { + + public void close() throws IOException { + os.close(); + } + + public void flush() throws IOException { + if (isConnected) { + os.flush(); + } + } + + public void write(byte[] b) throws IOException { + if (isConnected) { + os.write(b); + } + } + + public void write(byte[] b, int off, int len) throws IOException { + if (isConnected) { + os.write(b, off, len); + } + } + + public void write(int b) throws IOException { + if (isConnected) { + os.write(b); + } + } + }; + } +} diff -r e3d60e01a68d libs.jsch/src/com/jcraft/jsch/HotFixJSch.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libs.jsch/src/com/jcraft/jsch/HotFixJSch.java Thu Aug 19 14:07:52 2010 +0400 @@ -0,0 +1,67 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2009 Sun Microsystems, Inc. + */ + +package com.jcraft.jsch; + +/** + * An attempt to overcome 'Received data for nonexistent channel' jsch problem + * @see https://sourceforge.net/tracker/?func=detail&aid=3047673&group_id=64920&atid=509122 + */ +public final class HotFixJSch extends JSch { + + public Session getSession(String username, String host, int port) throws JSchException { + if (username == null) { + throw new JSchException("username must not be null."); // NOI18N + } + + if (host == null) { + throw new JSchException("host must not be null."); // NOI18N + } + + Session s = new HotFixSession(this); + s.setUserName(username); + s.setHost(host); + s.setPort(port); + + return s; + } +} diff -r e3d60e01a68d libs.jsch/src/com/jcraft/jsch/HotFixSession.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libs.jsch/src/com/jcraft/jsch/HotFixSession.java Thu Aug 19 14:07:52 2010 +0400 @@ -0,0 +1,73 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2009 Sun Microsystems, Inc. + */ +package com.jcraft.jsch; + +public final class HotFixSession extends Session { + + HotFixSession(JSch jsch) throws JSchException { + super(jsch); + } + + public Channel openChannel(String type) throws JSchException { + if (!isConnected()) { + throw new JSchException("session is down"); // NOI18N + } + + try { + Channel channel = getChannel(type); + addChannel(channel); + channel.init(); + return channel; + } catch (Exception e) { + //e.printStackTrace(); + } + return null; + } + + private Channel getChannel(String type) { + if (type.equals("exec")) { + return new HotFixChannelExec(); + } + + return Channel.getChannel(type); + } +}