You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by sp...@apache.org on 2009/12/23 04:39:20 UTC

svn commit: r893392 - in /mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd: SshServer.java agent/AprLibrary.java client/channel/ChannelShell.java common/util/OsUtils.java

Author: spearce
Date: Wed Dec 23 03:39:19 2009
New Revision: 893392

URL: http://svn.apache.org/viewvc?rev=893392&view=rev
Log:
Abstract windows OS platform tests into a common location

This is hairy stuff, testing the os.name to verify its some flavor
of Windows vs. a POSIX environment.  Abstract it all into one place
so we don't keep repeating ourselves thoughout the code.

Added:
    mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/util/OsUtils.java
Modified:
    mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/SshServer.java
    mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/agent/AprLibrary.java
    mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelShell.java

Modified: mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/SshServer.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/SshServer.java?rev=893392&r1=893391&r2=893392&view=diff
==============================================================================
--- mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/SshServer.java (original)
+++ mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/SshServer.java Wed Dec 23 03:39:19 2009
@@ -66,6 +66,7 @@
 import org.apache.sshd.common.session.AbstractSession;
 import org.apache.sshd.common.signature.SignatureDSA;
 import org.apache.sshd.common.signature.SignatureRSA;
+import org.apache.sshd.common.util.OsUtils;
 import org.apache.sshd.common.util.SecurityUtils;
 import org.apache.sshd.server.Command;
 import org.apache.sshd.server.CommandFactory;
@@ -463,7 +464,7 @@
         } else {
             sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("key.ser"));
         }
-        if (System.getProperty("os.name").toLowerCase().indexOf("windows") < 0) {
+        if (OsUtils.isUNIX()) {
             sshd.setShellFactory(new ProcessShellFactory(new String[] { "/bin/sh", "-i", "-l" },
                                  EnumSet.of(ProcessShellFactory.TtyOptions.ONlCr)));
         } else {

Modified: mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/agent/AprLibrary.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/agent/AprLibrary.java?rev=893392&r1=893391&r2=893392&view=diff
==============================================================================
--- mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/agent/AprLibrary.java (original)
+++ mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/agent/AprLibrary.java Wed Dec 23 03:39:19 2009
@@ -19,6 +19,7 @@
  */
 package org.apache.sshd.agent;
 
+import org.apache.sshd.common.util.OsUtils;
 import org.apache.tomcat.jni.Library;
 import org.apache.tomcat.jni.Pool;
 
@@ -106,8 +107,7 @@
 
     static String createLocalSocketAddress() throws IOException {
         String name;
-        String os = System.getProperty("os.name").toLowerCase();
-        if (os.indexOf("windows") < 0) {
+        if (OsUtils.isUNIX()) {
             File socket = File.createTempFile("mina", "apr");
             socket.delete();
             name = socket.getAbsolutePath();
@@ -120,8 +120,7 @@
     }
 
     static void secureLocalSocket(String authSocket, long handle) throws IOException {
-        String os = System.getProperty("os.name").toLowerCase();
-        if (os.indexOf("windows") < 0) {
+        if (OsUtils.isUNIX()) {
             File file = new File(authSocket);
             if (!file.setReadable(false, false) || !file.setReadable(true, true)
                     || !file.setExecutable(false, false) || !file.setExecutable(true, true)) {

Modified: mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelShell.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelShell.java?rev=893392&r1=893391&r2=893392&view=diff
==============================================================================
--- mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelShell.java (original)
+++ mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelShell.java Wed Dec 23 03:39:19 2009
@@ -24,6 +24,7 @@
 import org.apache.sshd.common.PtyMode;
 import org.apache.sshd.common.SshConstants;
 import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.OsUtils;
 import org.apache.sshd.common.util.SttySupport;
 
 /**
@@ -63,8 +64,7 @@
 
     public void setupSensibleDefaultPty() {
         try {
-            String os = System.getProperty("os.name").toLowerCase();
-            if (os.indexOf("windows") < 0) {
+            if (OsUtils.isUNIX()) {
                 ptyModes = SttySupport.getUnixPtyModes();
                 ptyColumns = SttySupport.getTerminalWidth();
                 ptyLines = SttySupport.getTerminalHeight();

Added: mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/util/OsUtils.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/util/OsUtils.java?rev=893392&view=auto
==============================================================================
--- mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/util/OsUtils.java (added)
+++ mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/util/OsUtils.java Wed Dec 23 03:39:19 2009
@@ -0,0 +1,46 @@
+/*
+ * 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.util;
+
+/**
+ * Operating system dependent utility methods.
+ *
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ */
+public class OsUtils {
+    private static final boolean win32;
+
+    static {
+        String os = System.getProperty("os.name").toLowerCase();
+        win32 = 0 <= os.indexOf("windows");
+    }
+
+    /** @return true if the host is a UNIX system (and not Windows). */
+    public static boolean isUNIX() {
+        return !win32;
+    }
+
+    /** @return true if the host is Windows (and not UNIX). */
+    public static boolean isWin32() {
+        return win32;
+    }
+
+    private OsUtils () {
+    }
+}