blob: a3b7af811fa6c12925db0ab4bd49c28b63090b5d [file] [log] [blame]
Raphael628920b2011-11-22 10:40:13 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifdef _WIN32
18
19#include "find_java.h"
20
21#define _CRT_SECURE_NO_WARNINGS 1
22
23extern bool gDebug;
24
25// Search java.exe in the path
26bool findJavaInEnvPath(CPath *outJavaPath) {
27 SetLastError(0);
28 const char* envPath = getenv("PATH");
29 if (!envPath) return false;
30
31 CArray<CString> *paths = CString(envPath).split(';');
32 for(int i = 0; i < paths->size(); i++) {
33 CPath p((*paths)[i].cstr());
34 p.addPath("java.exe");
35 if (p.fileExists()) {
36 // Make sure we can actually run "java -version".
37 CString cmd;
38 cmd.setf("\"%s\" -version", p.cstr());
39 int code = execWait(cmd.cstr());
40 if (code == 0) {
41 if (gDebug) msgBox("Java found via env path: %s", p.cstr());
42 outJavaPath->set(p.cstr());
43 delete paths;
44 return true;
45 }
46 }
47 }
48
49 delete paths;
50 return false;
51}
52
53bool findJavaInRegistry(CPath *outJavaPath) {
54 // TODO
55 return false;
56}
57
58bool findJavaInProgramFiles(CPath *outJavaPath) {
59 // TODO
60 return false;
61}
62
63#endif /* _WIN32 */