1 package org.gffs.application;
4 import java.io.IOException;
5 import java.net.URISyntaxException;
8 import org.apache.commons.logging.Log;
9 import org.apache.commons.logging.LogFactory;
10 import org.gffs.filesystem.FileSystemHelper;
27 StackTraceElement[] elements = Thread.currentThread().getStackTrace();
28 StringBuilder toReturn =
new StringBuilder();
33 int endFrame = Math.min(howManyFrames + 3, elements.length - 1);
34 for (
int i = startFrame; i < endFrame; i++) {
35 if (toReturn.length() != 0) {
36 toReturn.append(
"\n<= ");
40 return toReturn.toString();
48 StackTraceElement[] elements = Thread.currentThread().getStackTrace();
50 if (which >= elements.length)
51 which = elements.length - 1;
52 return elements[which].toString();
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.");
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.");
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);
142 }
catch (IOException e) {
143 _logger.error(
"could not open osgi directory: " + appPath);
146 _logger.debug(
"startup path after resolution with File: " + appPath);
static String sanitizeFilename(String toClean)