/** * Returns the path of the installation of the directory server. Note that this method assumes * that this code is being run locally. * * @param installPath The installation path * @return the path of the installation of the directory server. */ static String getInstancePathFromInstallPath(final String installPath) { String instancePathFileName = Installation.INSTANCE_LOCATION_PATH; final File _svcScriptPath = new File(installPath + File.separator + SVC_SCRIPT_FILE_NAME); // look for /etc/opt/opendj/instance.loc File f = new File(instancePathFileName); if (!_svcScriptPath.exists() || !f.exists()) { // look for <installPath>/instance.loc instancePathFileName = installPath + File.separator + Installation.INSTANCE_LOCATION_PATH_RELATIVE; f = new File(instancePathFileName); if (!f.exists()) { return installPath; } } BufferedReader reader; try { reader = new BufferedReader(new FileReader(instancePathFileName)); } catch (Exception e) { return installPath; } // Read the first line and close the file. String line; try { line = reader.readLine(); File instanceLoc = new File(line.trim()); if (instanceLoc.isAbsolute()) { return instanceLoc.getAbsolutePath(); } else { return new File(installPath + File.separator + instanceLoc.getPath()).getAbsolutePath(); } } catch (Exception e) { return installPath; } finally { StaticUtils.close(reader); } }
static File getFileForPath(String path) { final File f = new File(path); return f.isAbsolute() ? f : new File(getInstancePath() + File.separator + path); }