use of com.webobjects.foundation.NSBundle in project wonder-slim by undur.
the class ERXComponentUtilities method pathUrlForResourceNamed.
private static URL pathUrlForResourceNamed(WOResourceManager resourceManager, String resourceName, NSArray languages) {
URL templateUrl = resourceManager.pathURLForResourceNamed(resourceName, null, languages);
if (templateUrl == null) {
NSArray frameworkBundles = NSBundle.frameworkBundles();
if (frameworkBundles != null) {
Enumeration frameworksEnum = frameworkBundles.objectEnumerator();
while (templateUrl == null && frameworksEnum.hasMoreElements()) {
NSBundle frameworkBundle = (NSBundle) frameworksEnum.nextElement();
templateUrl = resourceManager.pathURLForResourceNamed(resourceName, frameworkBundle.name(), languages);
}
}
}
return templateUrl;
}
use of com.webobjects.foundation.NSBundle in project wonder-slim by undur.
the class WOExceptionParser method _ignoredPackages.
private NSArray _ignoredPackages() {
NSBundle bundle;
String path, content;
NSDictionary dic = null;
NSMutableArray<NSBundle> allBundles = new NSMutableArray<>(NSBundle.frameworkBundles());
NSMutableArray<String> ignored = new NSMutableArray<>();
for (Enumeration enumerator = allBundles.objectEnumerator(); enumerator.hasMoreElements(); ) {
bundle = (NSBundle) enumerator.nextElement();
path = WOApplication.application().resourceManager().pathForResourceNamed("WOIgnoredPackage.plist", bundle.name(), null);
if (path != null) {
content = _stringFromFileSafely(path);
if (content != null) {
dic = (NSDictionary) NSPropertyListSerialization.propertyListFromString(content);
if (dic != null && dic.containsKey("ignoredPackages")) {
@SuppressWarnings("unchecked") NSArray<String> tmpArray = (NSArray<String>) dic.objectForKey("ignoredPackages");
if (tmpArray != null && tmpArray.count() > 0) {
ignored.addObjectsFromArray(tmpArray);
}
}
}
}
}
return ignored;
}
use of com.webobjects.foundation.NSBundle in project wonder-slim by undur.
the class ERXApplication method didFinishLaunching.
/**
* Notification method called when the application posts the notification {@link WOApplication#ApplicationDidFinishLaunchingNotification}.
* This method calls subclasse's {@link #didFinishLaunching} method.
*
* @param n notification posted after WOApplication has finished launching and is ready for accepting requests.
*/
public final void didFinishLaunching(NSNotification n) {
didFinishLaunching();
ERXStats.logStatisticsForOperation(statsLog, "sum");
// FIXME: Is this being handled by ERXStats? Check out.
_startupTimeInMilliseconds = System.currentTimeMillis() - _startupTimeInMilliseconds;
log.info(String.format("Startup time %s ms: ", _startupTimeInMilliseconds));
System.out.println("============= LOADED BUNDLES START =============");
for (NSBundle nsBundle : NSBundle._allBundlesReally()) {
System.out.println(String.format("%-22s : %-65s : %s", nsBundle.name(), nsBundle.getClass(), nsBundle.isJar()));
}
System.out.println("============= LOADED BUNDLES END ===============");
}
use of com.webobjects.foundation.NSBundle in project wonder-slim by undur.
the class ERXLoader method bundleDidLoad.
/**
* Will be called after each bundle load. We use it to know when the last
* bundle loaded so we can post a notification for it. Note that the bundles
* will get loaded in the order of the classpath but the main bundle will
* get loaded last. So in order to set the properties correctly, we first
* add all the props that are not already set, then we add the main bundle
* and the WebObjects.properties and finally the command line props.
*/
public void bundleDidLoad(NSNotification n) {
NSBundle bundle = (NSBundle) n.object();
if (allFrameworks.contains(bundle.name())) {
allFrameworks.remove(bundle.name());
debugMsg("Loaded " + bundle.name() + ". Remaining: " + allFrameworks);
} else if (bundle.isFramework()) {
debugMsg("Loaded unexpected framework bundle '" + bundle.name() + "'. Ensure your build.properties settings like project.name match the bundle name (including case).");
}
if (allBundleProps == null) {
allBundleProps = new Properties();
}
String userName = propertyFromCommandLineFirst("user.name");
applyIfUnset(readProperties(bundle, "Properties." + userName));
applyIfUnset(readProperties(bundle, null));
if (allFrameworks.size() == 0) {
mainProps = null;
mainUserProps = null;
collectMainProps(userName);
allBundleProps.putAll(mainProps);
if (mainUserProps != null) {
allBundleProps.putAll(mainUserProps);
}
String userHome = propertyFromCommandLineFirst("user.home");
Properties userHomeProps = null;
if (userHome != null && userHome.length() > 0) {
userHomeProps = readProperties(new File(userHome, "WebObjects.properties"));
}
if (userHomeProps != null) {
allBundleProps.putAll(userHomeProps);
}
Properties props = NSProperties._getProperties();
props.putAll(allBundleProps);
NSProperties._setProperties(props);
insertCommandLineArguments();
if (userHomeProps != null) {
urls.add(0, urls.remove(urls.size() - 1));
}
if (mainUserProps != null) {
urls.add(0, urls.remove(urls.size() - 1));
}
urls.add(0, urls.remove(urls.size() - 1));
// System.out.print(urls);
NSNotificationCenter.defaultCenter().postNotification(new NSNotification(ERXApplication.AllBundlesLoadedNotification, NSKeyValueCoding.NullValue));
}
}
use of com.webobjects.foundation.NSBundle in project wonder-slim by undur.
the class ERXLoader method mainBundle.
private NSBundle mainBundle() {
NSBundle mainBundle = null;
String mainBundleName = NSProperties._mainBundleName();
if (mainBundleName != null) {
mainBundle = NSBundle.bundleForName(mainBundleName);
}
if (mainBundle == null) {
mainBundle = NSBundle.mainBundle();
}
if (mainBundle == null) {
try {
Field ClassPath = NSBundle.class.getDeclaredField("ClassPath");
ClassPath.setAccessible(true);
if (ClassPath.get(NSBundle.class) != null) {
Method init = NSBundle.class.getDeclaredMethod("InitMainBundle");
init.setAccessible(true);
init.invoke(NSBundle.class);
}
} catch (Exception e) {
System.err.println(e);
e.printStackTrace();
System.exit(1);
}
mainBundle = NSBundle.mainBundle();
}
return mainBundle;
}
Aggregations