diff --git a/.gitignore b/.gitignore
index ceff68ef3..4b456e243 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,9 @@
.metadata
.recommenders
+# IntelliJ IDEA
+/.idea
+
# Eclipse output folders for all projects under source/
bin
diff --git a/build/modules/clc/build.xml b/build/modules/clc/build.xml
index dc5e54cac..f39aae47c 100644
--- a/build/modules/clc/build.xml
+++ b/build/modules/clc/build.xml
@@ -127,6 +127,7 @@
+
diff --git a/build/modules/sdk/build.xml b/build/modules/sdk/build.xml
index 273ac23b9..8e50d705e 100644
--- a/build/modules/sdk/build.xml
+++ b/build/modules/sdk/build.xml
@@ -20,6 +20,7 @@
+
diff --git a/source/com.microsoft.tfs.core/.classpath b/source/com.microsoft.tfs.core/.classpath
index 5d89c2a3c..cc5e60e95 100644
--- a/source/com.microsoft.tfs.core/.classpath
+++ b/source/com.microsoft.tfs.core/.classpath
@@ -41,8 +41,6 @@
-
-
diff --git a/source/com.microsoft.tfs.core/META-INF/MANIFEST.MF b/source/com.microsoft.tfs.core/META-INF/MANIFEST.MF
index 759a01949..96ac15611 100644
--- a/source/com.microsoft.tfs.core/META-INF/MANIFEST.MF
+++ b/source/com.microsoft.tfs.core/META-INF/MANIFEST.MF
@@ -26,8 +26,6 @@ Bundle-ClassPath: com.microsoft.tfs.core.jar,
libs/jackson-core-2.4.1/jackson-core-2.4.1.jar,
libs/jackson-core-2.4.1/jackson-databind-2.4.1.jar,
libs/annotation-detector-3.0.4/annotation-detector-3.0.4.jar,
- libs/jna/jna-4.2.1.jar,
- libs/jna/jna-platform-4.2.1.jar,
libs/slf4j/slf4j-api-1.7.19.jar,
libs/slf4j/slf4j-log4j12-1.7.19.jar,
libs/oauth2-useragent/oauth2-useragent-0.11.2.jar,
diff --git a/source/com.microsoft.tfs.core/build.properties b/source/com.microsoft.tfs.core/build.properties
index 7a40dd1b5..9bd58e13d 100644
--- a/source/com.microsoft.tfs.core/build.properties
+++ b/source/com.microsoft.tfs.core/build.properties
@@ -18,8 +18,6 @@ bin.includes = META-INF/,\
libs/jackson-core-2.4.1/jackson-databind-2.4.1.jar,\
libs/applicationinsights-core/applicationinsights-core-1.0.4.jar,\
libs/annotation-detector-3.0.4/annotation-detector-3.0.4.jar,\
- libs/jna/jna-4.2.1.jar,\
- libs/jna/jna-platform-4.2.1.jar,\
libs/slf4j/slf4j-api-1.7.19.jar,\
libs/slf4j/slf4j-log4j12-1.7.19.jar,\
libs/oauth2-useragent/oauth2-useragent-0.11.2.jar,\
diff --git a/source/com.microsoft.tfs.jni/.classpath b/source/com.microsoft.tfs.jni/.classpath
index 50e024a7b..7af277077 100644
--- a/source/com.microsoft.tfs.jni/.classpath
+++ b/source/com.microsoft.tfs.jni/.classpath
@@ -6,5 +6,7 @@
+
+
diff --git a/source/com.microsoft.tfs.jni/META-INF/MANIFEST.MF b/source/com.microsoft.tfs.jni/META-INF/MANIFEST.MF
index de62f64ec..44c90bbfc 100644
--- a/source/com.microsoft.tfs.jni/META-INF/MANIFEST.MF
+++ b/source/com.microsoft.tfs.jni/META-INF/MANIFEST.MF
@@ -29,4 +29,6 @@ Export-Package: com.microsoft.tfs.jni,
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: com.microsoft.tfs.logging,
com.microsoft.tfs.util
-Bundle-ClassPath: com.microsoft.tfs.jni.jar
+Bundle-ClassPath: com.microsoft.tfs.jni.jar,
+ libs/jna/jna-4.2.1.jar,
+ libs/jna/jna-platform-4.2.1.jar
diff --git a/source/com.microsoft.tfs.jni/build.properties b/source/com.microsoft.tfs.jni/build.properties
index 80b45312c..aad90eb7a 100644
--- a/source/com.microsoft.tfs.jni/build.properties
+++ b/source/com.microsoft.tfs.jni/build.properties
@@ -1,5 +1,7 @@
bin.includes = META-INF/,\
os/,\
com.microsoft.tfs.jni.jar,\
+ libs/jna/jna-4.2.1.jar,\
+ libs/jna/jna-platform-4.2.1.jar,\
plugin.properties
source.com.microsoft.tfs.jni.jar = src/
diff --git a/source/com.microsoft.tfs.core/libs/jna/jna-4.2.1.jar b/source/com.microsoft.tfs.jni/libs/jna/jna-4.2.1.jar
similarity index 100%
rename from source/com.microsoft.tfs.core/libs/jna/jna-4.2.1.jar
rename to source/com.microsoft.tfs.jni/libs/jna/jna-4.2.1.jar
diff --git a/source/com.microsoft.tfs.core/libs/jna/jna-platform-4.2.1.jar b/source/com.microsoft.tfs.jni/libs/jna/jna-platform-4.2.1.jar
similarity index 100%
rename from source/com.microsoft.tfs.core/libs/jna/jna-platform-4.2.1.jar
rename to source/com.microsoft.tfs.jni/libs/jna/jna-platform-4.2.1.jar
diff --git a/source/com.microsoft.tfs.jni/native-src/build-inner.cmd b/source/com.microsoft.tfs.jni/native-src/build-inner.cmd
index 194d05055..ef6428bb6 100644
--- a/source/com.microsoft.tfs.jni/native-src/build-inner.cmd
+++ b/source/com.microsoft.tfs.jni/native-src/build-inner.cmd
@@ -253,7 +253,6 @@ rem ###########################################################
if not defined NOJAVAH (
echo Generating C headers...
"%JAVA_HOME%\bin\javah" -classpath "%BUILD_TMP%" -o "%BUILD_TMP%\native_auth.h" com.microsoft.tfs.jni.internal.auth.NativeAuth
- "%JAVA_HOME%\bin\javah" -classpath "%BUILD_TMP%" -o "%BUILD_TMP%\native_console.h" com.microsoft.tfs.jni.internal.console.NativeConsole
"%JAVA_HOME%\bin\javah" -classpath "%BUILD_TMP%" -o "%BUILD_TMP%\native_filesystem.h" com.microsoft.tfs.jni.internal.filesystem.NativeFileSystem
"%JAVA_HOME%\bin\javah" -classpath "%BUILD_TMP%" -o "%BUILD_TMP%\native_misc.h" com.microsoft.tfs.jni.internal.platformmisc.NativePlatformMisc
"%JAVA_HOME%\bin\javah" -classpath "%BUILD_TMP%" -o "%BUILD_TMP%\native_synchronization.h" com.microsoft.tfs.jni.internal.synchronization.NativeSynchronization
@@ -262,7 +261,6 @@ if not defined NOJAVAH (
)
if not exist "%BUILD_TMP%\native_auth.h" goto javaherror
-if not exist "%BUILD_TMP%\native_console.h" goto javaherror
if not exist "%BUILD_TMP%\native_filesystem.h" goto javaherror
if not exist "%BUILD_TMP%\native_misc.h" goto javaherror
if not exist "%BUILD_TMP%\native_synchronization.h" goto javaherror
@@ -289,7 +287,6 @@ echo Compiling native C code...
rem Compile everything to objects
@echo on
cl -c win32\auth_sspi.c -Fo"%BUILD_TMP%\auth_sspi.obj" %CFLAGS%
-cl -c win32\console_jni.c -Fo"%BUILD_TMP%\console_jni.obj" %CFLAGS%
cl -c win32\filesystem_jni.c -Fo"%BUILD_TMP%\filesystem_jni.obj" %CFLAGS%
cl -c win32\misc_jni.c -Fo"%BUILD_TMP%\misc_jni.obj" %CFLAGS%
cl -c win32\synchronization_jni.c -Fo"%BUILD_TMP%\synchronization_jni.obj" %CFLAGS%
@@ -303,7 +300,6 @@ cl -c common\util.c -Fo"%BUILD_TMP%\util.obj" %CFLAGS%
@echo off
if not exist "%BUILD_TMP%\auth_sspi.obj" goto compileerror
-if not exist "%BUILD_TMP%\console_jni.obj" goto compileerror
if not exist "%BUILD_TMP%\filesystem_jni.obj" goto compileerror
if not exist "%BUILD_TMP%\misc_jni.obj" goto compileerror
if not exist "%BUILD_TMP%\synchronization_jni.obj" goto compileerror
@@ -318,7 +314,6 @@ rem Link individual libraries.
@echo on
link -dll "%BUILD_TMP%\auth.obj" "%BUILD_TMP%\auth_sspi.obj" "%BUILD_TMP%\util.obj" "%BUILD_TMP%\logger_log4j.obj" -out:"%BUILD_TMP%\native_auth.dll" %LFLAGS%
-link -dll "%BUILD_TMP%\console_jni.obj" "%BUILD_TMP%\util.obj" -out:"%BUILD_TMP%\native_console.dll" %LFLAGS%
link -dll "%BUILD_TMP%\filesystem_jni.obj" "%BUILD_TMP%\util.obj" "%BUILD_TMP%\objects.obj" advapi32.lib -out:"%BUILD_TMP%\native_filesystem.dll" %LFLAGS%
link -dll "%BUILD_TMP%\misc_jni.obj" "%BUILD_TMP%\util.obj" advapi32.lib -out:"%BUILD_TMP%\native_misc.dll" %LFLAGS%
link -dll "%BUILD_TMP%\synchronization_jni.obj" "%BUILD_TMP%\util.obj" -out:"%BUILD_TMP%\native_synchronization.dll" %LFLAGS%
@@ -328,7 +323,6 @@ link -dll "%BUILD_TMP%\messagewindow_jni.obj" "%BUILD_TMP%\util.obj" user32.lib
@echo off
if not exist "%BUILD_TMP%\native_auth.dll" goto compileerror
-if not exist "%BUILD_TMP%\native_console.dll" goto compileerror
if not exist "%BUILD_TMP%\native_filesystem.dll" goto compileerror
if not exist "%BUILD_TMP%\native_misc.dll" goto compileerror
if not exist "%BUILD_TMP%\native_synchronization.dll" goto compileerror
@@ -358,11 +352,6 @@ if exist %DESTDIR%\native_auth.dll goto delerror
if exist %SYMBOLDIR%\native_auth.pdb del %SYMBOLDIR%\native_auth.pdb
if exist %SYMBOLDIR%\native_auth.pdb goto delerror
-if exist %DESTDIR%\native_console.dll del %DESTDIR%\native_console.dll
-if exist %DESTDIR%\native_console.dll goto delerror
-if exist %SYMBOLDIR%\native_console.pdb del %SYMBOLDIR%\native_console.pdb
-if exist %SYMBOLDIR%\native_console.pdb goto delerror
-
if exist %DESTDIR%\native_filesystem.dll del %DESTDIR%\native_filesystem.dll
if exist %DESTDIR%\native_filesystem.dll goto delerror
if exist %SYMBOLDIR%\native_filesystem.pdb del %SYMBOLDIR%\native_filesystem.pdb
@@ -402,11 +391,6 @@ if not exist %DESTDIR%\native_auth.dll goto copyerror
copy "%BUILD_TMP%\native_auth.pdb" %SYMBOLDIR%\native_auth.pdb
if not exist %SYMBOLDIR%\native_auth.pdb goto copyerror
-copy "%BUILD_TMP%\native_console.dll" %DESTDIR%\native_console.dll
-if not exist %DESTDIR%\native_console.dll goto copyerror
-copy "%BUILD_TMP%\native_console.pdb" %SYMBOLDIR%\native_console.pdb
-if not exist %SYMBOLDIR%\native_console.pdb goto copyerror
-
copy "%BUILD_TMP%\native_filesystem.dll" %DESTDIR%\native_filesystem.dll
if not exist %DESTDIR%\native_filesystem.dll goto copyerror
copy "%BUILD_TMP%\native_filesystem.pdb" %SYMBOLDIR%\native_filesystem.pdb
diff --git a/source/com.microsoft.tfs.jni/native-src/build.sh b/source/com.microsoft.tfs.jni/native-src/build.sh
index 2295ea375..37f0f1901 100755
--- a/source/com.microsoft.tfs.jni/native-src/build.sh
+++ b/source/com.microsoft.tfs.jni/native-src/build.sh
@@ -254,7 +254,6 @@ esac
# The simple names of the libraries we generate. A "lib" prefix
# and/or file extension is added per-platform.
LIBRARY_AUTH="native_auth"
-LIBRARY_CONSOLE="native_console"
LIBRARY_FILESYSTEM="native_filesystem"
LIBRARY_MISC="native_misc"
LIBRARY_SYNCHRONIZATION="native_synchronization"
@@ -262,7 +261,6 @@ LIBRARY_KEYCHAIN="native_keychain"
# The sources required by each library we compile and link.
SOURCES_AUTH="common/util.c common/objects.c common/logger_log4j.c common/auth.c unix/auth_gss.c"
-SOURCES_CONSOLE="common/util.c common/objects.c unix/console_jni.c"
SOURCES_FILESYSTEM="common/util.c common/objects.c unix/filesystem_jni.c"
SOURCES_MISC="common/util.c common/objects.c unix/misc_jni.c"
SOURCES_SYNCHRONIZATION="common/util.c common/objects.c unix/synchronization_jni.c"
@@ -396,7 +394,6 @@ if [ "$PREVIEW" = 0 ] ; then
$E -n "- Generating C headers... "
javah -jni -o "$TMP/native_auth.h" com.microsoft.tfs.jni.internal.auth.NativeAuth
- javah -jni -o "$TMP/native_console.h" com.microsoft.tfs.jni.internal.console.NativeConsole
javah -jni -o "$TMP/native_filesystem.h" com.microsoft.tfs.jni.internal.filesystem.NativeFileSystem
javah -jni -o "$TMP/native_keychain.h" com.microsoft.tfs.jni.internal.keychain.NativeKeychain
javah -jni -o "$TMP/native_misc.h" com.microsoft.tfs.jni.internal.platformmisc.NativePlatformMisc
@@ -435,7 +432,6 @@ case $PLATFORM in
CFLAGS="$CFLAGS -fstack-protector -Wstack-protector -D_FORTIFY_SOURCE=2 -I${JAVA_FRAMEWORK}/Headers $arch_support -DMACOS_X -DHAS_STAT_MTIMESPEC"
LDFLAGS="$LDFLAGS -bundle -framework JavaVM -framework SystemConfiguration -framework CoreServices -mmacosx-version-min=10.5"
- build_library_gcc "$TMP/lib$LIBRARY_CONSOLE.jnilib" "$SOURCES_CONSOLE"
build_library_gcc "$TMP/lib$LIBRARY_FILESYSTEM.jnilib" "$SOURCES_FILESYSTEM"
build_library_gcc "$TMP/lib$LIBRARY_MISC.jnilib" "$SOURCES_MISC"
build_library_gcc "$TMP/lib$LIBRARY_SYNCHRONIZATION.jnilib" "$SOURCES_SYNCHRONIZATION"
@@ -471,7 +467,6 @@ case $PLATFORM in
CFLAGS="$CFLAGS -m32 -Di386 -Di586 -DcpuIntel -D_LITTLE_ENDIAN"
fi
- build_library_gcc "$TMP/lib$LIBRARY_CONSOLE.so" "$SOURCES_CONSOLE"
build_library_gcc "$TMP/lib$LIBRARY_FILESYSTEM.so" "$SOURCES_FILESYSTEM"
build_library_gcc "$TMP/lib$LIBRARY_MISC.so" "$SOURCES_MISC"
build_library_gcc "$TMP/lib$LIBRARY_SYNCHRONIZATION.so" "$SOURCES_SYNCHRONIZATION"
@@ -506,7 +501,6 @@ case $PLATFORM in
CFLAGS="$CFLAGS -milp32"
fi
- build_library_gcc "$TMP/lib$LIBRARY_CONSOLE.$EXTENSION" "$SOURCES_CONSOLE"
build_library_gcc "$TMP/lib$LIBRARY_FILESYSTEM.$EXTENSION" "$SOURCES_FILESYSTEM"
build_library_gcc "$TMP/lib$LIBRARY_MISC.$EXTENSION" "$SOURCES_MISC"
build_library_gcc "$TMP/lib$LIBRARY_SYNCHRONIZATION.$EXTENSION" "$SOURCES_SYNCHRONIZATION"
@@ -535,7 +529,6 @@ case $PLATFORM in
LDFLAGS="$LDFLAGS -z defs"
fi
- build_library_gcc "$TMP/lib$LIBRARY_CONSOLE.so" "$SOURCES_CONSOLE"
build_library_gcc "$TMP/lib$LIBRARY_FILESYSTEM.so" "$SOURCES_FILESYSTEM"
build_library_gcc "$TMP/lib$LIBRARY_MISC.so" "$SOURCES_MISC"
build_library_gcc "$TMP/lib$LIBRARY_SYNCHRONIZATION.so" "$SOURCES_SYNCHRONIZATION"
@@ -572,7 +565,6 @@ case $PLATFORM in
CFLAGS="$CFLAGS -DPOWERPC -D_BIG_ENDIAN"
fi
- build_library_gcc "$TMP/lib$LIBRARY_CONSOLE.a" "$SOURCES_CONSOLE"
build_library_gcc "$TMP/lib$LIBRARY_FILESYSTEM.a" "$SOURCES_FILESYSTEM"
build_library_gcc "$TMP/lib$LIBRARY_MISC.a" "$SOURCES_MISC"
build_library_gcc "$TMP/lib$LIBRARY_SYNCHRONIZATION.a" "$SOURCES_SYNCHRONIZATION"
@@ -599,7 +591,6 @@ case $PLATFORM in
LDFLAGS="$LDFLAGS -z defs"
fi
- build_library_gcc "$TMP/lib$LIBRARY_CONSOLE.so" "$SOURCES_CONSOLE"
build_library_gcc "$TMP/lib$LIBRARY_FILESYSTEM.so" "$SOURCES_FILESYSTEM"
build_library_gcc "$TMP/lib$LIBRARY_MISC.so" "$SOURCES_MISC"
build_library_gcc "$TMP/lib$LIBRARY_SYNCHRONIZATION.so" "$SOURCES_SYNCHRONIZATION"
@@ -627,7 +618,6 @@ case $PLATFORM in
CFLAGS="$CFLAGS -D_POSIX_SOURCE -D_XOPEN_SOURCE=500 -I$JAVA_HOME/include -W \"c,langlvl(extended),float(ieee),dll,exportall\""
LDFLAGS="$LDFLAGS -W l,dll"
- build_library_zos "$TMP/lib$LIBRARY_CONSOLE.so" "$EBCDIC_DIR" "$SOURCES_CONSOLE"
build_library_zos "$TMP/lib$LIBRARY_FILESYSTEM.so" "$EBCDIC_DIR" "$SOURCES_FILESYSTEM"
build_library_zos "$TMP/lib$LIBRARY_MISC.so" "$EBCDIC_DIR" "$SOURCES_MISC"
build_library_zos "$TMP/lib$LIBRARY_SYNCHRONIZATION.so" "$EBCDIC_DIR" "$SOURCES_SYNCHRONIZATION"
diff --git a/source/com.microsoft.tfs.jni/native-src/unix/console_jni.c b/source/com.microsoft.tfs.jni/native-src/unix/console_jni.c
deleted file mode 100644
index 31093d89f..000000000
--- a/source/com.microsoft.tfs.jni/native-src/unix/console_jni.c
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright (c) Microsoft. All rights reserved.
- * Licensed under the MIT license. See License.txt in the repository root.
- */
-
-/*
- * JNI functions that do console work.
- */
-
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "native_console.h"
-#include "util.h"
-
-/*
- * Does the real console/terminal size work. Not exported via JNI.
- */
-void _getConsoleSize(int * rows, int * columns)
-{
- int ttyfd;
- struct winsize ws;
- static const char * tty = "/dev/tty";
-
- if ((ttyfd = open(tty, O_RDONLY)) >= 0)
- {
- if (ioctl(ttyfd, TIOCGWINSZ, &ws) >= 0)
- {
- *rows = ws.ws_row;
- *columns = ws.ws_col;
- }
- close(ttyfd);
- }
-}
-
-/*
- * Gets the height of the console this process is attached to in rows.
- *
- * If an error occured, 0 is returned.
- */
-JNIEXPORT jint JNICALL Java_com_microsoft_tfs_jni_internal_console_NativeConsole_nativeGetRows(JNIEnv *env, jclass cls)
-{
- int rows = 0, columns = 0;
- _getConsoleSize(&rows, &columns);
- return rows;
-}
-
-/*
- * Gets the width of the terminal this process is attached to in columns.
- *
- * If an error occured, 0 is returned.
- */
-JNIEXPORT jint JNICALL Java_com_microsoft_tfs_jni_internal_console_NativeConsole_nativeGetColumns(JNIEnv *env,
- jclass cls)
-{
- int rows = 0, columns = 0;
- _getConsoleSize(&rows, &columns);
- return columns;
-}
-
-/*
- * Disables character echo on the console.
- *
- * Returns true if the operation succeeded, false if it failed.
- */
-JNIEXPORT jboolean JNICALL Java_com_microsoft_tfs_jni_internal_console_NativeConsole_nativeDisableEcho(JNIEnv *env,
- jclass cls)
-{
- struct termios settings;
-
- /* Get settings. */
- if (tcgetattr(STDIN_FILENO, &settings) != 0)
- {
- return JNI_FALSE;
- }
-
- settings.c_lflag &= (~ECHO);
-
- /* Set them back. */
- if (tcsetattr(STDIN_FILENO, TCSANOW, &settings) != 0)
- {
- return JNI_FALSE;
- }
-
- return JNI_TRUE;
-}
-
-/*
- * Enables character echo on the console.
- *
- * Returns true if the operation succeeded, false if it failed.
- */
-JNIEXPORT jboolean JNICALL Java_com_microsoft_tfs_jni_internal_console_NativeConsole_nativeEnableEcho(JNIEnv *env,
- jclass cls)
-{
- struct termios settings;
-
- /* Get settings. */
- if (tcgetattr(STDIN_FILENO, &settings) != 0)
- {
- return JNI_FALSE;
- }
-
- settings.c_lflag |= (ECHO);
-
- /* Set them back. */
- if (tcsetattr(STDIN_FILENO, TCSANOW, &settings) != 0)
- {
- return JNI_FALSE;
- }
-
- return JNI_TRUE;
-}
diff --git a/source/com.microsoft.tfs.jni/native-src/win32/console_jni.c b/source/com.microsoft.tfs.jni/native-src/win32/console_jni.c
deleted file mode 100644
index 6c0828a88..000000000
--- a/source/com.microsoft.tfs.jni/native-src/win32/console_jni.c
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Copyright (c) Microsoft. All rights reserved.
- * Licensed under the MIT license. See License.txt in the repository root.
- */
-
-#include
-#include
-#include
-#include
-
-#include "tee_sal.h"
-#include "native_console.h"
-
-/*
- * Does the real console size work. Pass NULL for any argument you do not wish to have a value written to.
- * On error no arguments are updated.
- */
-void _getScreenBufferAndWindowSize(_Inout_opt_ int * screenBufferRows, _Inout_opt_ int * screenBufferColumns,
- _Inout_opt_ int * windowRows, _Inout_opt_ int * windowColumns)
-{
- CONSOLE_SCREEN_BUFFER_INFO info;
-
- if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info) != TRUE)
- {
- return;
- }
-
- if (screenBufferRows != NULL)
- {
- *screenBufferRows = info.dwSize.Y;
- }
-
- if (screenBufferColumns != NULL)
- {
- *screenBufferColumns = info.dwSize.X;
- }
-
- if (windowRows != NULL)
- {
- // Add 1 because rows at both bounds are visible
- *windowRows = info.srWindow.Bottom - info.srWindow.Top + 1;
- }
-
- if (windowColumns != NULL)
- {
- // Add 1 because columns at both bounds are visible
- *windowColumns = info.srWindow.Right - info.srWindow.Left + 1;
- }
-}
-
-/*
- * Gets the height of the console WINDOW (not screen buffer) this process is attached to in rows.
- *
- * If an error occured, 0 is returned.
- */
-JNIEXPORT jint JNICALL Java_com_microsoft_tfs_jni_internal_console_NativeConsole_nativeGetRows(JNIEnv *env, jclass cls)
-{
- int rows = 0;
- _getScreenBufferAndWindowSize(NULL, NULL, &rows, NULL);
- return rows;
-}
-
-/*
- * Gets the width of the console SCREEN BUFFER (not window) this process is attached to in columns.
- *
- * If an error occured, 0 is returned.
- */
-JNIEXPORT jint JNICALL Java_com_microsoft_tfs_jni_internal_console_NativeConsole_nativeGetColumns(JNIEnv *env,
- jclass cls)
-{
- int columns = 0;
- _getScreenBufferAndWindowSize(NULL, &columns, NULL, NULL);
- return columns;
-}
-
-/*
- * Disables character echo on the console.
- *
- * Returns true if the operation succeeded, false if it failed.
- */
-JNIEXPORT jboolean JNICALL Java_com_microsoft_tfs_jni_internal_console_NativeConsole_nativeDisableEcho(JNIEnv *env,
- jclass cls)
-{
- HANDLE inputHandle = GetStdHandle(STD_INPUT_HANDLE);
- DWORD consoleFlags;
-
- if (inputHandle != INVALID_HANDLE_VALUE)
- {
- /* Get the current mode. */
- if (GetConsoleMode(inputHandle, &consoleFlags))
- {
- /* Turn off echo. */
- consoleFlags &= ~(ENABLE_ECHO_INPUT);
-
- if (SetConsoleMode(inputHandle, consoleFlags))
- {
- return JNI_TRUE;
- }
- }
- }
-
- return JNI_FALSE;
-}
-
-/*
- * Enables character echo on the console.
- *
- * Returns true if the operation succeeded, false if it failed.
- */
-JNIEXPORT jboolean JNICALL Java_com_microsoft_tfs_jni_internal_console_NativeConsole_nativeEnableEcho(JNIEnv *env,
- jclass cls)
-{
- HANDLE inputHandle = GetStdHandle(STD_INPUT_HANDLE);
- DWORD consoleFlags;
-
- if (inputHandle != INVALID_HANDLE_VALUE)
- {
- /* Get the current mode. */
- if (GetConsoleMode(inputHandle, &consoleFlags))
- {
- /* Turn on echo. */
- consoleFlags |= (ENABLE_ECHO_INPUT);
-
- if (SetConsoleMode(inputHandle, consoleFlags))
- {
- return JNI_TRUE;
- }
- }
- }
-
- return JNI_FALSE;
-}
diff --git a/source/com.microsoft.tfs.jni/os/aix/ppc/libnative_console.a b/source/com.microsoft.tfs.jni/os/aix/ppc/libnative_console.a
deleted file mode 100644
index b05963c20..000000000
Binary files a/source/com.microsoft.tfs.jni/os/aix/ppc/libnative_console.a and /dev/null differ
diff --git a/source/com.microsoft.tfs.jni/os/freebsd/x86/libnative_console.so b/source/com.microsoft.tfs.jni/os/freebsd/x86/libnative_console.so
deleted file mode 100644
index d2b6054ab..000000000
Binary files a/source/com.microsoft.tfs.jni/os/freebsd/x86/libnative_console.so and /dev/null differ
diff --git a/source/com.microsoft.tfs.jni/os/freebsd/x86_64/libnative_console.so b/source/com.microsoft.tfs.jni/os/freebsd/x86_64/libnative_console.so
deleted file mode 100644
index 8a789acc4..000000000
Binary files a/source/com.microsoft.tfs.jni/os/freebsd/x86_64/libnative_console.so and /dev/null differ
diff --git a/source/com.microsoft.tfs.jni/os/hpux/PA_RISC/libnative_console.sl b/source/com.microsoft.tfs.jni/os/hpux/PA_RISC/libnative_console.sl
deleted file mode 100644
index 9a622a221..000000000
Binary files a/source/com.microsoft.tfs.jni/os/hpux/PA_RISC/libnative_console.sl and /dev/null differ
diff --git a/source/com.microsoft.tfs.jni/os/hpux/ia64_32/libnative_console.so b/source/com.microsoft.tfs.jni/os/hpux/ia64_32/libnative_console.so
deleted file mode 100644
index ef7857d1d..000000000
Binary files a/source/com.microsoft.tfs.jni/os/hpux/ia64_32/libnative_console.so and /dev/null differ
diff --git a/source/com.microsoft.tfs.jni/os/linux/arm/libnative_console.so b/source/com.microsoft.tfs.jni/os/linux/arm/libnative_console.so
deleted file mode 100644
index ed6feb197..000000000
Binary files a/source/com.microsoft.tfs.jni/os/linux/arm/libnative_console.so and /dev/null differ
diff --git a/source/com.microsoft.tfs.jni/os/linux/ppc/libnative_console.so b/source/com.microsoft.tfs.jni/os/linux/ppc/libnative_console.so
deleted file mode 100644
index 6cdc6eec1..000000000
Binary files a/source/com.microsoft.tfs.jni/os/linux/ppc/libnative_console.so and /dev/null differ
diff --git a/source/com.microsoft.tfs.jni/os/linux/x86/libnative_console.so b/source/com.microsoft.tfs.jni/os/linux/x86/libnative_console.so
deleted file mode 100644
index b844195ec..000000000
Binary files a/source/com.microsoft.tfs.jni/os/linux/x86/libnative_console.so and /dev/null differ
diff --git a/source/com.microsoft.tfs.jni/os/linux/x86_64/libnative_console.so b/source/com.microsoft.tfs.jni/os/linux/x86_64/libnative_console.so
deleted file mode 100644
index 755db7192..000000000
Binary files a/source/com.microsoft.tfs.jni/os/linux/x86_64/libnative_console.so and /dev/null differ
diff --git a/source/com.microsoft.tfs.jni/os/macosx/libnative_console.jnilib b/source/com.microsoft.tfs.jni/os/macosx/libnative_console.jnilib
deleted file mode 100644
index d4249d7d7..000000000
Binary files a/source/com.microsoft.tfs.jni/os/macosx/libnative_console.jnilib and /dev/null differ
diff --git a/source/com.microsoft.tfs.jni/os/solaris/sparc/libnative_console.so b/source/com.microsoft.tfs.jni/os/solaris/sparc/libnative_console.so
deleted file mode 100644
index 408831d57..000000000
Binary files a/source/com.microsoft.tfs.jni/os/solaris/sparc/libnative_console.so and /dev/null differ
diff --git a/source/com.microsoft.tfs.jni/os/solaris/x86/libnative_console.so b/source/com.microsoft.tfs.jni/os/solaris/x86/libnative_console.so
deleted file mode 100644
index 00e56a908..000000000
Binary files a/source/com.microsoft.tfs.jni/os/solaris/x86/libnative_console.so and /dev/null differ
diff --git a/source/com.microsoft.tfs.jni/os/solaris/x86_64/libnative_console.so b/source/com.microsoft.tfs.jni/os/solaris/x86_64/libnative_console.so
deleted file mode 100644
index de804899d..000000000
Binary files a/source/com.microsoft.tfs.jni/os/solaris/x86_64/libnative_console.so and /dev/null differ
diff --git a/source/com.microsoft.tfs.jni/os/win32/x86/native_console.dll b/source/com.microsoft.tfs.jni/os/win32/x86/native_console.dll
deleted file mode 100644
index cdc14e605..000000000
Binary files a/source/com.microsoft.tfs.jni/os/win32/x86/native_console.dll and /dev/null differ
diff --git a/source/com.microsoft.tfs.jni/os/win32/x86_64/native_console.dll b/source/com.microsoft.tfs.jni/os/win32/x86_64/native_console.dll
deleted file mode 100644
index fc3e8589f..000000000
Binary files a/source/com.microsoft.tfs.jni/os/win32/x86_64/native_console.dll and /dev/null differ
diff --git a/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/LibraryNames.java b/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/LibraryNames.java
index e7b1359eb..d3cb615e3 100644
--- a/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/LibraryNames.java
+++ b/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/LibraryNames.java
@@ -17,11 +17,6 @@ public abstract class LibraryNames {
*/
public static final String MISC_LIBRARY_NAME = "native_misc"; //$NON-NLS-1$
- /**
- * The short name of the native console library.
- */
- public static final String CONSOLE_LIBRARY_NAME = "native_console"; //$NON-NLS-1$
-
/**
* The short name of the authentication library.
*/
diff --git a/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/NativeConsole.java b/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/NativeConsole.java
index 730519e26..fbddd2f7a 100644
--- a/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/NativeConsole.java
+++ b/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/NativeConsole.java
@@ -4,8 +4,7 @@
package com.microsoft.tfs.jni.internal.console;
import com.microsoft.tfs.jni.Console;
-import com.microsoft.tfs.jni.internal.LibraryNames;
-import com.microsoft.tfs.jni.loader.NativeLoader;
+import com.microsoft.tfs.util.Platform;
/**
* An implementation of the {@link Console} interface that uses native methods.
@@ -13,48 +12,30 @@
* @threadsafety thread-safe
*/
public class NativeConsole implements Console {
- /**
- * This static initializer is a "best-effort" native code loader (no
- * exceptions thrown for normal load failures).
- *
- * Apps with multiple classloaders (like Eclipse) can run this initializer
- * more than once in a single JVM OS process, and on some platforms
- * (Windows) the native libraries will fail to load the second time, because
- * they're already loaded. This failure can be ignored because the native
- * code will execute fine.
- */
- static {
- NativeLoader.loadLibraryAndLogError(LibraryNames.CONSOLE_LIBRARY_NAME);
- }
+
+ private static final Console backend =
+ Platform.isCurrentPlatform(Platform.WINDOWS) ? new WindowsNativeConsole() : new UnixNativeConsole();
public NativeConsole() {
}
@Override
public int getConsoleColumns() {
- return nativeGetColumns();
+ return backend.getConsoleColumns();
}
@Override
public int getConsoleRows() {
- return nativeGetRows();
+ return backend.getConsoleRows();
}
@Override
public boolean disableEcho() {
- return nativeDisableEcho();
+ return backend.disableEcho();
}
@Override
public boolean enableEcho() {
- return nativeEnableEcho();
+ return backend.enableEcho();
}
-
- private static native int nativeGetRows();
-
- private static native int nativeGetColumns();
-
- private static native boolean nativeDisableEcho();
-
- private static native boolean nativeEnableEcho();
}
diff --git a/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/UnixNativeConsole.java b/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/UnixNativeConsole.java
new file mode 100644
index 000000000..8f19c5c4b
--- /dev/null
+++ b/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/UnixNativeConsole.java
@@ -0,0 +1,60 @@
+package com.microsoft.tfs.jni.internal.console;
+
+import com.microsoft.tfs.jni.Console;
+import com.microsoft.tfs.jni.internal.console.unix.LibC;
+import com.microsoft.tfs.jni.internal.console.unix.termios;
+import com.microsoft.tfs.jni.internal.console.unix.winsize;
+
+class UnixNativeConsole implements Console {
+
+ private winsize getTtySize() {
+ LibC libC = LibC.INSTANCE;
+ int tty = libC.open("/dev/tty", LibC.O_RDONLY);
+ if (tty >= 0) {
+ try {
+ winsize size = new winsize();
+ if (libC.ioctl(tty, LibC.TIOCGWINSZ, size) >= 0) {
+ return size;
+ }
+ } finally {
+ libC.close(tty);
+ }
+ }
+
+ return null;
+ }
+
+ @Override public int getConsoleColumns() {
+ winsize size = getTtySize();
+ return size == null ? 0 : size.ws_col;
+ }
+
+ @Override public int getConsoleRows() {
+ winsize size = getTtySize();
+ return size == null ? 0 : size.ws_row;
+ }
+
+ @Override public boolean disableEcho() {
+ LibC libC = LibC.INSTANCE;
+
+ termios settings = new termios();
+ if (libC.tcgetattr(LibC.STDIN_FILENO, settings) != 0)
+ return false;
+
+ settings.c_lflag &= ~LibC.ECHO;
+
+ return libC.tcsetattr(LibC.STDIN_FILENO, LibC.TCSANOW, settings) == 0;
+ }
+
+ @Override public boolean enableEcho() {
+ LibC libC = LibC.INSTANCE;
+
+ termios settings = new termios();
+ if (libC.tcgetattr(LibC.STDIN_FILENO, settings) != 0)
+ return false;
+
+ settings.c_lflag |= LibC.ECHO;
+
+ return libC.tcsetattr(LibC.STDIN_FILENO, LibC.TCSANOW, settings) == 0;
+ }
+}
diff --git a/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/WindowsNativeConsole.java b/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/WindowsNativeConsole.java
new file mode 100644
index 000000000..6e56e4bee
--- /dev/null
+++ b/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/WindowsNativeConsole.java
@@ -0,0 +1,63 @@
+package com.microsoft.tfs.jni.internal.console;
+
+import com.microsoft.tfs.jni.Console;
+import com.microsoft.tfs.jni.internal.console.winapi.ConsoleScreenBufferInfo;
+import com.microsoft.tfs.jni.internal.console.winapi.Kernel32;
+import com.sun.jna.Pointer;
+import com.sun.jna.platform.win32.WinNT;
+import com.sun.jna.ptr.IntByReference;
+
+import static com.microsoft.tfs.jni.internal.console.winapi.Kernel32.ENABLE_ECHO_INPUT;
+
+class WindowsNativeConsole implements Console {
+ private static ConsoleScreenBufferInfo getConsoleScreenBufferInfo() {
+ Kernel32 kernel32 = Kernel32.INSTANCE;
+ WinNT.HANDLE handle = kernel32.GetStdHandle(Kernel32.STD_OUTPUT_HANDLE);
+ if (handle.getPointer().equals(Pointer.NULL))
+ return null;
+
+ ConsoleScreenBufferInfo info = new ConsoleScreenBufferInfo();
+ if (!kernel32.GetConsoleScreenBufferInfo(handle, info))
+ return null;
+
+ return info;
+ }
+
+ @Override public int getConsoleColumns() {
+ ConsoleScreenBufferInfo info = getConsoleScreenBufferInfo();
+ return info == null ? 0 : info.dwSize.x;
+ }
+
+ @Override public int getConsoleRows() {
+ ConsoleScreenBufferInfo info = getConsoleScreenBufferInfo();
+ return info == null ? 0 : info.dwSize.y;
+ }
+
+ @Override public boolean disableEcho() {
+ Kernel32 kernel32 = Kernel32.INSTANCE;
+ WinNT.HANDLE stdOut = kernel32.GetStdHandle(Kernel32.STD_OUTPUT_HANDLE);
+ if (stdOut.equals(Pointer.NULL))
+ return false;
+
+ IntByReference consoleMode = new IntByReference();
+ if (!kernel32.GetConsoleMode(stdOut, consoleMode))
+ return false;
+
+ int newConsoleMode = consoleMode.getValue() & ~ENABLE_ECHO_INPUT;
+ return kernel32.SetConsoleMode(stdOut, newConsoleMode);
+ }
+
+ @Override public boolean enableEcho() {
+ Kernel32 kernel32 = Kernel32.INSTANCE;
+ WinNT.HANDLE stdOut = kernel32.GetStdHandle(Kernel32.STD_OUTPUT_HANDLE);
+ if (stdOut.equals(Pointer.NULL))
+ return false;
+
+ IntByReference consoleMode = new IntByReference();
+ if (!kernel32.GetConsoleMode(stdOut, consoleMode))
+ return false;
+
+ int newConsoleMode = consoleMode.getValue() | ENABLE_ECHO_INPUT;
+ return kernel32.SetConsoleMode(stdOut, newConsoleMode);
+ }
+}
diff --git a/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/unix/LibC.java b/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/unix/LibC.java
new file mode 100644
index 000000000..e215ad8ba
--- /dev/null
+++ b/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/unix/LibC.java
@@ -0,0 +1,27 @@
+package com.microsoft.tfs.jni.internal.console.unix;
+
+import com.sun.jna.Library;
+import com.sun.jna.Native;
+import com.sun.jna.Platform;
+import com.sun.jna.Pointer;
+
+public interface LibC extends Library {
+
+ LibC INSTANCE = (LibC) Native.loadLibrary("c", LibC.class);
+
+ int O_RDONLY = 0;
+ long TIOCGWINSZ = Platform.isLinux() ? 0x5413L : 0x40087468L;
+ int STDIN_FILENO = 0;
+ int ECHO = 8;
+ int TCSANOW = 0;
+
+ int open(String pathname, int flags);
+
+ int close(int fd);
+
+ int ioctl(int fd, long cmd, winsize p);
+
+ int tcgetattr(int fd, termios termios_p);
+
+ int tcsetattr(int fd, int optional_actions, termios termios_p);
+}
diff --git a/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/unix/termios.java b/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/unix/termios.java
new file mode 100644
index 000000000..8ec37d316
--- /dev/null
+++ b/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/unix/termios.java
@@ -0,0 +1,22 @@
+package com.microsoft.tfs.jni.internal.console.unix;
+
+import com.sun.jna.Structure;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class termios extends Structure {
+
+ @Override protected List getFieldOrder() {
+ return Arrays.asList("c_iflag", "c_oflag", "c_cflag", "c_lflag", "c_line", "c_cc", "c_ispeed", "c_ospeed");
+ }
+
+ public int c_iflag; /* input mode flags */
+ public int c_oflag; /* output mode flags */
+ public int c_cflag; /* control mode flags */
+ public int c_lflag; /* local mode flags */
+ public byte c_line; /* line discipline */
+ public byte[] c_cc = new byte[32]; /* control characters */
+ public int c_ispeed; /* input speed */
+ public int c_ospeed; /* output speed */
+}
diff --git a/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/unix/winsize.java b/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/unix/winsize.java
new file mode 100644
index 000000000..660270b81
--- /dev/null
+++ b/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/unix/winsize.java
@@ -0,0 +1,18 @@
+package com.microsoft.tfs.jni.internal.console.unix;
+
+import com.sun.jna.Structure;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class winsize extends Structure {
+
+ @Override protected List getFieldOrder() {
+ return Arrays.asList("ws_row", "ws_col", "ws_xpixel", "ws_ypixel");
+ }
+
+ public short ws_row;
+ public short ws_col;
+ public short ws_xpixel;
+ public short ws_ypixel;
+}
diff --git a/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/winapi/ConsoleScreenBufferInfo.java b/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/winapi/ConsoleScreenBufferInfo.java
new file mode 100644
index 000000000..fb84f6cda
--- /dev/null
+++ b/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/winapi/ConsoleScreenBufferInfo.java
@@ -0,0 +1,19 @@
+package com.microsoft.tfs.jni.internal.console.winapi;
+
+import com.sun.jna.Structure;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class ConsoleScreenBufferInfo extends Structure {
+
+ @Override protected List getFieldOrder() {
+ return Arrays.asList("dwSize", "dwCursorPosition", "wAttributes", "srWindow", "dwMaximumWindowSize");
+ }
+
+ public Coord dwSize;
+ public Coord dwCursorPosition;
+ public short wAttributes;
+ public SmallRect srWindow;
+ public Coord dwMaximumWindowSize;
+}
\ No newline at end of file
diff --git a/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/winapi/Coord.java b/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/winapi/Coord.java
new file mode 100644
index 000000000..e04ffe26a
--- /dev/null
+++ b/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/winapi/Coord.java
@@ -0,0 +1,19 @@
+package com.microsoft.tfs.jni.internal.console.winapi;
+
+import com.sun.jna.Structure;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class Coord extends Structure {
+
+ public static class ByValue extends Coord implements Structure.ByValue {
+ }
+
+ @Override protected List getFieldOrder() {
+ return Arrays.asList("x", "y");
+ }
+
+ public short x;
+ public short y;
+}
diff --git a/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/winapi/Kernel32.java b/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/winapi/Kernel32.java
new file mode 100644
index 000000000..e3e22208d
--- /dev/null
+++ b/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/winapi/Kernel32.java
@@ -0,0 +1,11 @@
+package com.microsoft.tfs.jni.internal.console.winapi;
+
+import com.sun.jna.Native;
+
+public interface Kernel32 extends com.sun.jna.platform.win32.Kernel32 {
+
+ Kernel32 INSTANCE = (Kernel32) Native.loadLibrary("Kernel32", Kernel32.class);
+ int ENABLE_ECHO_INPUT = 0x0004;
+
+ boolean GetConsoleScreenBufferInfo(HANDLE hConsoleOutput, ConsoleScreenBufferInfo lpConsoleScreenBufferInfo);
+}
diff --git a/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/winapi/SmallRect.java b/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/winapi/SmallRect.java
new file mode 100644
index 000000000..044a2d37e
--- /dev/null
+++ b/source/com.microsoft.tfs.jni/src/com/microsoft/tfs/jni/internal/console/winapi/SmallRect.java
@@ -0,0 +1,18 @@
+package com.microsoft.tfs.jni.internal.console.winapi;
+
+import com.sun.jna.Structure;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class SmallRect extends Structure {
+
+ @Override protected List getFieldOrder() {
+ return Arrays.asList("left", "top", "right", "bottom");
+ }
+
+ public short left;
+ public short top;
+ public short right;
+ public short bottom;
+}