Home | History | Annotate | Download | only in src
      1 /*
      2 * Copyright (C) 2014 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 #pragma once
     18 
     19 
     20 #include <set>                                  // STL std::set
     21 #include "JavaPath.h"
     22 
     23 class CJavaFinder {
     24 public:
     25     // Creates a new JavaFinder.
     26     // minVersion to accept, using JAVA_VERS_TO_INT macro. 0 to accept everything.
     27     CJavaFinder(int minVersion = 0);
     28     ~CJavaFinder();
     29 
     30     int getMinVersion() const { return mMinVersion;  }
     31 
     32     // Returns the path recorded in the registry.
     33     // If there is no path or it is no longer valid, returns an empty string.
     34     CJavaPath getRegistryPath();
     35 
     36     // Sets the given path as the default to use in the registry.
     37     // Returns true on success.
     38     bool setRegistryPath(const CJavaPath &javaPath);
     39 
     40     // Scans the registry, the environment and program files for potential Java.exe locations.
     41     // Fills the given set with the tuples (version, path) found, guaranteed sorted and unique.
     42     void findJavaPaths(std::set<CJavaPath> *paths);
     43 
     44     // Checks the given path for a given java.exe.
     45     // Input path variation tried are: path as-is, path/java.exe or path/bin/java.exe.
     46     // Places the java path and version in outPath;
     47     // Returns true if a java path was found *and* its version is at least mMinVersion.
     48     bool checkJavaPath(const CString &path, CJavaPath *outPath);
     49 
     50 private:
     51     int mMinVersion;
     52 };
     53