From 612da3bda111ba933ba8b891c5dba5eb32700af9 Mon Sep 17 00:00:00 2001 From: mpollack Date: Thu, 25 Jul 2013 18:24:47 -0400 Subject: [PATCH] SHL-82 Improve detection of apple terminal Remove AbstractShellTest as it didn't test anything other than calling for system properties Fix failing tests --- .../shell/core/AbstractShell.java | 9 ---- .../shell/core/JLineShell.java | 11 +++-- .../springframework/shell/BootstrapTest.java | 2 +- .../shell/core/AbstractShellTest.java | 47 ------------------- 4 files changed, 9 insertions(+), 60 deletions(-) delete mode 100644 src/test/java/org/springframework/shell/core/AbstractShellTest.java diff --git a/src/main/java/org/springframework/shell/core/AbstractShell.java b/src/main/java/org/springframework/shell/core/AbstractShell.java index e1eb7005..12463c8f 100644 --- a/src/main/java/org/springframework/shell/core/AbstractShell.java +++ b/src/main/java/org/springframework/shell/core/AbstractShell.java @@ -15,8 +15,6 @@ */ package org.springframework.shell.core; -import static org.springframework.shell.support.util.OsUtils.LINE_SEPARATOR; - import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.File; @@ -26,13 +24,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; -import java.text.DateFormat; import java.util.Collection; -import java.util.Date; -import java.util.Locale; -import java.util.Map.Entry; -import java.util.Set; -import java.util.TreeSet; import java.util.logging.Level; import java.util.logging.Logger; @@ -47,7 +39,6 @@ import org.springframework.shell.support.util.IOUtils; import org.springframework.shell.support.util.MathUtils; import org.springframework.shell.support.util.VersionUtils; import org.springframework.util.Assert; -import org.springframework.util.StringUtils; /** * Provides a base {@link Shell} implementation. diff --git a/src/main/java/org/springframework/shell/core/JLineShell.java b/src/main/java/org/springframework/shell/core/JLineShell.java index e0842c5d..e0ac9974 100644 --- a/src/main/java/org/springframework/shell/core/JLineShell.java +++ b/src/main/java/org/springframework/shell/core/JLineShell.java @@ -74,7 +74,6 @@ public abstract class JLineShell extends AbstractShell implements CommandMarker, private static final String ANSI_CONSOLE_CLASSNAME = "org.fusesource.jansi.AnsiConsole"; private static final boolean JANSI_AVAILABLE = ClassUtils.isPresent(ANSI_CONSOLE_CLASSNAME, JLineShell.class.getClassLoader()); - private static final boolean APPLE_TERMINAL = Boolean.getBoolean("is.apple.terminal"); private static final char ESCAPE = 27; private static final String BEL = "\007"; // Fields @@ -410,7 +409,7 @@ public abstract class JLineShell extends AbstractShell implements CommandMarker, // Externally synchronized via the two calling methods having a mutex on flashInfoMap private void doAnsiFlash(final int row, final Level level, final String message) { ANSIBuffer buff = JLineLogHandler.getANSIBuffer(); - if (APPLE_TERMINAL) { + if (isAppleTerminal()) { buff.append(ESCAPE + "7"); } else { @@ -452,7 +451,7 @@ public abstract class JLineShell extends AbstractShell implements CommandMarker, // Record we want to erase from this positioning next time (so we clean up after ourselves) rowErasureMap.put(row, startFrom); } - if (APPLE_TERMINAL) { + if (isAppleTerminal()) { buff.append(ESCAPE + "8"); } else { @@ -621,5 +620,11 @@ public abstract class JLineShell extends AbstractShell implements CommandMarker, public void setHistorySize(int historySize) { this.historySize = historySize; } + + private static boolean isAppleTerminal() + { + final String terminalName = System.getenv( "TERM_PROGRAM" ); + return ("Apple_Terminal".equalsIgnoreCase( terminalName ) || Boolean.getBoolean("is.apple.terminal")); + } } diff --git a/src/test/java/org/springframework/shell/BootstrapTest.java b/src/test/java/org/springframework/shell/BootstrapTest.java index 33154b68..fcae4605 100644 --- a/src/test/java/org/springframework/shell/BootstrapTest.java +++ b/src/test/java/org/springframework/shell/BootstrapTest.java @@ -18,7 +18,7 @@ public class BootstrapTest { JLineShellComponent shell = bootstrap.getJLineShellComponent(); //This is a brittle assertion - as additiona 'test' commands are added to the suite, this number will increase. - Assert.assertEquals("Number of CommandMarkers is incorrect", 5, shell.getSimpleParser().getCommandMarkers().size()); + Assert.assertEquals("Number of CommandMarkers is incorrect", 9, shell.getSimpleParser().getCommandMarkers().size()); Assert.assertEquals("Number of Converters is incorrect", 16, shell.getSimpleParser().getConverters().size()); } catch (RuntimeException t) { throw t; diff --git a/src/test/java/org/springframework/shell/core/AbstractShellTest.java b/src/test/java/org/springframework/shell/core/AbstractShellTest.java deleted file mode 100644 index a4d1595e..00000000 --- a/src/test/java/org/springframework/shell/core/AbstractShellTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2011-2012 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.shell.core; - -import static org.junit.Assert.assertNotNull; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import org.junit.Test; -import org.springframework.shell.core.AbstractShell; - - -/** - * Unit test of {@link AbstractShell} (not a superclass for writing tests for - * {@link AbstractShell} subclasses) - * - * @author Andrew Swan - * @since 1.2.0 - */ -public class AbstractShellTest { - - @Test - public void testProps() { - // Set up - final AbstractShell shell = mock(AbstractShell.class); - when(shell.props()).thenCallRealMethod(); - - // Invoke - final String props = shell.props(); - - // Check - assertNotNull(props); - } -}