SHL-82 Improve detection of apple terminal
Remove AbstractShellTest as it didn't test anything other than calling for system properties Fix failing tests
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user