aboutsummaryrefslogtreecommitdiffstats
path: root/find_java
diff options
context:
space:
mode:
authorRaphael <raphael@google.com>2012-01-26 19:15:43 -0800
committerRaphael <raphael@google.com>2012-01-26 20:10:38 -0800
commita418de56908e413187e1144b7d1d430bbfc459d5 (patch)
tree8a59e90188c2b639c5f0a35d46052631732ae1e8 /find_java
parent692d2b58196af2a73343b476af6e33df876c45a5 (diff)
downloadsdk-a418de56908e413187e1144b7d1d430bbfc459d5.zip
sdk-a418de56908e413187e1144b7d1d430bbfc459d5.tar.gz
sdk-a418de56908e413187e1144b7d1d430bbfc459d5.tar.bz2
SDK: use new find_java.exe in SDK bat files
Change-Id: I9f3fc572c3af6d8457a75cebae1aa6a850511afc
Diffstat (limited to 'find_java')
-rwxr-xr-xfind_java/find_java.bat47
-rw-r--r--find_java/find_java_exe.cpp17
2 files changed, 64 insertions, 0 deletions
diff --git a/find_java/find_java.bat b/find_java/find_java.bat
new file mode 100755
index 0000000..0ee00e5
--- /dev/null
+++ b/find_java/find_java.bat
@@ -0,0 +1,47 @@
+@echo off
+rem Copyright (C) 2007 The Android Open Source Project
+rem
+rem Licensed under the Apache License, Version 2.0 (the "License");
+rem you may not use this file except in compliance with the License.
+rem You may obtain a copy of the License at
+rem
+rem http://www.apache.org/licenses/LICENSE-2.0
+rem
+rem Unless required by applicable law or agreed to in writing, software
+rem distributed under the License is distributed on an "AS IS" BASIS,
+rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+rem See the License for the specific language governing permissions and
+rem limitations under the License.
+
+rem This script is called by the other batch files to find a suitable Java.exe
+rem to use. The script changes the "java_exe" env variable. The variable
+rem is left unset if Java.exe was not found.
+
+rem Useful links:
+rem Command-line reference:
+rem http://technet.microsoft.com/en-us/library/bb490890.aspx
+
+rem Check we have a valid Java.exe in the path. The return code will
+rem be 0 if the command worked or 1 if the exec failed (program not found).
+for /f %%a in ('%~dps0\find_java.exe -s') do set java_exe=%%a
+if not defined java_exe goto :CheckFailed
+
+:SearchJavaW
+rem Check if we can find a javaw.exe at the same location than java.exe.
+rem If that doesn't work, just fall back on the java.exe we just found.
+for /f %%a in ('%~dps0\find_java.exe -s -w') do set javaw_exe=%%a
+if not exist %javaw_exe% set javaw_exe=%java_exe%
+goto :EOF
+
+
+:CheckFailed
+echo.
+echo ERROR: No suitable Java found. In order to properly use the Android Developer
+echo Tools, you need a suitable version of Java JDK installed on your system.
+echo We recommend that you install the JDK version of JavaSE, available here:
+echo http://www.oracle.com/technetwork/java/javase/downloads
+echo.
+echo You can find the complete Android SDK requirements here:
+echo http://developer.android.com/sdk/requirements.html
+echo.
+goto :EOF
diff --git a/find_java/find_java_exe.cpp b/find_java/find_java_exe.cpp
index 74f8ac1..c74cfd9 100644
--- a/find_java/find_java_exe.cpp
+++ b/find_java/find_java_exe.cpp
@@ -65,6 +65,7 @@ int main(int argc, char* argv[]) {
gIsDebug = (getenv("ANDROID_SDKMAN_DEBUG") != NULL);
bool doShortPath = false;
bool doVersion = false;
+ bool doJavaW = false;
for (int i = 1; i < argc; i++) {
if (strncmp(argv[i], "-t", 2) == 0) {
@@ -80,6 +81,9 @@ int main(int argc, char* argv[]) {
} else if (strncmp(argv[i], "-v", 2) == 0) {
doVersion = true;
+ } else if (strcmp(argv[i], "-w") == 0 || strcmp(argv[i], "-javaw") == 0) {
+ doJavaW = true;
+
} else {
printf(
"Outputs the path of the first Java.exe found on the local system.\n"
@@ -88,6 +92,7 @@ int main(int argc, char* argv[]) {
"-h / -help : This help.\n"
"-t / -test : Internal test.\n"
"-s / -short : Print path in short DOS form.\n"
+ "-w / -javaw : Search a matching javaw.exe; defaults to java.exe if not found.\n"
"-v / -version: Only prints the Java version found.\n"
);
return 2;
@@ -125,6 +130,18 @@ int main(int argc, char* argv[]) {
}
}
+ if (doJavaW) {
+ // Try to find a javaw.exe instead of java.exe at the same location.
+ CPath javawPath(javaPath);
+ javawPath.replaceName("java.exe", "javaw.exe");
+ // Only accept it if we can actually find the exec
+ PVOID oldWow64Value = disableWow64FsRedirection();
+ if (javawPath.fileExists()) {
+ javaPath.set(javawPath.cstr());
+ }
+ revertWow64FsRedirection(&oldWow64Value);
+ }
+
// Print java.exe path found
printf("%s", javaPath.cstr());
return 0;