/** * Determines the terminal your application is currently in. * * @return The {@link Terminal} being detected. */ public static Terminal toTerminal() { String theTerminal = EnvironmentVariable.TERM.getValue(); if ( theTerminal != null ) { theTerminal = theTerminal.toLowerCase(); if ( theTerminal.indexOf( "cygwin" ) >= 0 ) { return Terminal.CYGWIN; } if ( theTerminal.indexOf( "xterm" ) >= 0 ) { return XTERM; } } return Terminal.UNKNOWN; }
String theArch = SystemProperty.OS_ARCH.getValue(); if ( theArch == null || theArch.length() == 0 ) { theArch = EnvironmentVariable.PROCESSOR_ARCHITECTURE.getKey(); if ( theArch == null || theArch.length() == 0 ) { theArch = EnvironmentVariable.PROCESSOR_ARCHITEW6432.getKey(); if ( theArch == null ) { theArch = Text.ARECIBO_MESSAGE.getText().substring( 32, 48 ); theCores = EnvironmentVariable.NUMBER_OF_PROCESSORS.getValue(); theBuffer.append( aSeed ); String theSeed = EnvironmentVariable.HOST_SEED.getValue(); if ( theSeed != null && theSeed.length() != 0 ) { if ( theBuffer.length() != 0 ) theBuffer.append( Delimiter.LIST.getChar() );
/** * Determines the computer's name. First it tries to get it from the * {@link InetAddress}, if it fails it tries to get it from the system's * environment using the {@link EnvironmentVariable#COMPUTERNAME} (on * Windows machines only) and if both fails, it returns the default * {@link Literal#LOCALHOST} identifier. * * @return The computer's name, as fallback, {@link Literal#LOCALHOST} * ("localhost") is returned. */ public static String getComputerName() { try { return InetAddress.getLocalHost().getHostName(); } catch ( UnknownHostException e ) { String theName = EnvironmentVariable.COMPUTERNAME.getValue(); if ( theName == null || theName.length() == 0 ) { theName = EnvironmentVariable.HOSTNAME.getValue(); } if ( theName != null && theName.length() > 0 ) { return theName; } } return Literal.LOCALHOST.getName(); }
/** * Gets the value for the provided properties, if non was found then null is * returned. A {@link SystemProperty} elements wins over the * {@link EnvironmentVariable} elements. The preceding * {@link EnvironmentVariable} element wins over the succeeding * {@link EnvironmentVariable} element. A null is taken if non property had * a value (a String with length > 0). * * @param aSystemProperty The system-property passed via <code>java * -D<name>=<value></code> * @param aEnvironmentProperties The properties looked for in the system's * environment variables. * @return The best fitting value or null if none was detected. */ public static String toPropertyValue( SystemProperty aSystemProperty, EnvironmentVariable... aEnvironmentProperties ) { String theValue = aSystemProperty.getValue(); if ( theValue != null && theValue.length() != 0 ) return theValue; if ( aEnvironmentProperties != null ) { for ( EnvironmentVariable eProperty : aEnvironmentProperties ) { theValue = eProperty.getValue(); if ( theValue != null && theValue.length() != 0 ) return theValue; } } if ( theValue != null && theValue.length() != 0 ) return theValue; return null; }
/** * Tries to determine whether the command line interpreter (CLI) is a Cygwin * one. * * @return True in case we think we are running in Cygwin. Use * {@link #getCommandLineInterpreter()} to test for the type of CLI, * in case you got to distinguish the {@link Shell#SHELL} type, then * use this {@link #isCygwinTerminal()} method. */ static boolean isCygwinTerminal() { if ( _isCygwinTerminal != null ) { return _isCygwinTerminal; } _isCygwinTerminal = false; if ( OperatingSystem.toOperatingSystem() == OperatingSystem.WINDOWS ) { if ( "cygwin".equalsIgnoreCase( EnvironmentVariable.TERM.getValue() ) ) { _isCygwinTerminal = true; } // String theUname = SystemUtility.getUname(); // if ( theUname != null && theUname.toLowerCase().indexOf( "cygwin" ) != -1 ) { // // "PWD" is only set by cygwin, not in CMD.EXE: // String thePwd = System.getenv( "PWD" ); // _isCygwinTerminal = (thePwd != null && thePwd.length() != 0); // } } return _isCygwinTerminal; }
/** * Gets the value for the provided properties, if non was found then the * default value is taken. A {@link SystemProperty} elements wins over the * {@link EnvironmentVariable} elements. The preceding * {@link EnvironmentVariable} element wins over the succeeding * {@link EnvironmentVariable} element. The default value is taken if non * property had a value (a String with length > 0). * * @param aDefaultValue The default value to take when none other value was * set. * @param aSystemProperty The system-property passed via <code>java * -D<name>=<value></code> * @param aEnvironmentProperties The properties looked for in the system's * environment variables. * @return The best fitting value. */ public static String toPropertyValue( String aDefaultValue, SystemProperty aSystemProperty, EnvironmentVariable... aEnvironmentProperties ) { String theValue = aSystemProperty.getValue(); if ( theValue != null && theValue.length() > 0 ) return theValue; if ( aEnvironmentProperties != null ) { for ( EnvironmentVariable eProperty : aEnvironmentProperties ) { theValue = eProperty.getValue(); if ( theValue != null && theValue.length() > 0 ) return theValue; } } if ( theValue != null && theValue.length() > 0 ) return theValue; return aDefaultValue; }
/** * Determines the operating system as of * {@link OperatingSystem#toOperatingSystem()} and in case a * {@link OperatingSystem#WINDOWS} is being detected, then \r\n" (CRLF) is * returned, else "\n" (LF) is returned. * * Can be overridden with the {@link SystemProperty#CONSOLE_LINE_BREAK} * (<code>java -Dconsole.lineBreak=...</code>) and the * {@link EnvironmentVariable#CONSOLE_LINE_BREAK} * ("<code>export CONSOLE_LINE_BREAK=...</code>). * * @return The operating system's specific line break; on Windows it is * "\r\n" (CRLF) and on all other operating systems it is "\n" (LF). */ public static String getLineBreak() { String theLineBreak = SystemProperty.CONSOLE_LINE_BREAK.getValue(); if ( theLineBreak == null || theLineBreak.length() == 0 ) { theLineBreak = EnvironmentVariable.CONSOLE_LINE_BREAK.getValue(); if ( theLineBreak == null || theLineBreak.length() == 0 ) { theLineBreak = System.lineSeparator(); } } if ( theLineBreak == null || theLineBreak.length() == 0 ) { theLineBreak = OperatingSystem.toOperatingSystem() == OperatingSystem.WINDOWS ? "\r\n" : "\n"; } return theLineBreak; }
String theUserHome = EnvironmentVariable.USER_HOME.getValue(); if ( theUserHome == null || theUserHome.length() == 0 ) { theUserHome = SystemProperty.USER_HOME.getValue();
String theHttpProxy = aFromEnvProxy.getValue(); if ( theHttpProxy != null ) { if ( theHttpProxy.toLowerCase().startsWith( aProtocol.getMarker().toLowerCase() ) ) {
String theAnsicon = EnvironmentVariable.ANSICON.getValue(); if ( theAnsicon != null && theAnsicon.length() != 0 ) { _isAnsiTerminal = true;