63 String appPath =
null;
65 URL url =
ProgramTools.class.getProtectionDomain().getCodeSource().getLocation();
68 appPath =
new File(url.toURI().getSchemeSpecificPart()).toString().replace(
'\\',
'/');
69 }
catch (URISyntaxException e) {
70 String msg =
"failed to convert code source url to app path: " + url;
72 throw new RuntimeException(msg);
75 _logger.trace(
"got source path as: " + appPath);
76 if (appPath.endsWith(
".jar")) {
78 int lastSlash = appPath.lastIndexOf(
"/");
82 String msg =
"could not find a slash character in the path: " + appPath;
84 throw new RuntimeException(msg);
86 appPath = appPath.substring(0, lastSlash);
88 _logger.trace(
"truncated path since inside jar: " + appPath);
90 appPath = appPath.concat(
"/..");
93 _logger.trace(
"jar-intuited startup bundle path: " + appPath);
95 File startupDir =
new File(appPath);
96 if (!startupDir.exists() || !startupDir.isDirectory()) {
97 throw new RuntimeException(
98 "the location where we believe the installation is running from does not actually exist as a directory.");
107 File testingBundlesDir =
new File(startupDir,
"bundles");
108 File testingExtDir =
new File(startupDir,
"ext");
109 String lastStartupDirState =
"not-equal";
111 while (!testingBundlesDir.exists() || !testingExtDir.exists()) {
112 if (
_logger.isDebugEnabled()) {
114 _logger.debug(
"failed to find bundles directory at '" + startupDir.getAbsolutePath() +
"', popping up a level.");
117 if (lastStartupDirState.equals(FileSystemHelper.sanitizeFilename(startupDir.getAbsolutePath()))) {
118 throw new RuntimeException(
119 "caught the startup directory not changing, which means we have hit the root and failed to find our bundles and ext directories.");
122 lastStartupDirState = FileSystemHelper.sanitizeFilename(startupDir.getAbsolutePath());
125 startupDir =
new File(startupDir,
"..");
126 testingBundlesDir =
new File(startupDir,
"bundles");
127 testingExtDir =
new File(startupDir,
"ext");
129 if (startupDir.getParent() ==
null) {
130 throw new RuntimeException(
"failed to find the bundles and ext directories after hitting top of file system paths.");
135 if (
_logger.isTraceEnabled()) {
136 _logger.debug(
"successfully found bundles directory under path: " + appPath);
141 appPath = FileSystemHelper.sanitizeFilename(startupDir.getCanonicalPath());
142 }
catch (IOException e) {
143 _logger.error(
"could not open osgi directory: " + appPath);
146 _logger.debug(
"startup path after resolution with File: " + appPath);