diff --git a/BlueBerry/Bundles/org.blueberry.core.runtime/src/internal/berryPluginActivator.cpp b/BlueBerry/Bundles/org.blueberry.core.runtime/src/internal/berryPluginActivator.cpp index ffe73f6a83..c13ef008d2 100644 --- a/BlueBerry/Bundles/org.blueberry.core.runtime/src/internal/berryPluginActivator.cpp +++ b/BlueBerry/Bundles/org.blueberry.core.runtime/src/internal/berryPluginActivator.cpp @@ -1,45 +1,45 @@ /*========================================================================= Program: BlueBerry Platform Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "berryPluginActivator.h" #include namespace berry { org_blueberry_core_runtime_Activator::org_blueberry_core_runtime_Activator() { } void org_blueberry_core_runtime_Activator::start(ctkPluginContext* context) { - m_PreferencesService = new PreferencesService(); + m_PreferencesService = new PreferencesService(context->getDataFile("").absolutePath().toStdString()); m_PrefServiceReg = context->registerService(m_PreferencesService.GetPointer()); } void org_blueberry_core_runtime_Activator::stop(ctkPluginContext* context) { m_PrefServiceReg.unregister(); m_PreferencesService->ShutDown(); m_PreferencesService = 0; m_PrefServiceReg = 0; } } Q_EXPORT_PLUGIN2(org_blueberry_core_runtime, berry::org_blueberry_core_runtime_Activator) diff --git a/BlueBerry/Bundles/org.blueberry.osgi/src/internal/berryCodeCache.cpp b/BlueBerry/Bundles/org.blueberry.osgi/src/internal/berryCodeCache.cpp index 7da51acb98..eb69cfc069 100644 --- a/BlueBerry/Bundles/org.blueberry.osgi/src/internal/berryCodeCache.cpp +++ b/BlueBerry/Bundles/org.blueberry.osgi/src/internal/berryCodeCache.cpp @@ -1,135 +1,138 @@ /*========================================================================= Program: BlueBerry Platform Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "berryLog.h" #include "berryCodeCache.h" #include "berryInternalPlatform.h" #include "Poco/Path.h" #include "Poco/SharedLibrary.h" #include #include #include namespace berry { CodeCache::CodeCache(const std::string& path) : m_CachePath(path) { BERRY_INFO(InternalPlatform::GetInstance()->ConsoleLog()) << "Creating CodeCache with path: " << path << std::endl; if (!m_CachePath.exists()) { m_CachePath.createDirectories(); } } CodeCache::~CodeCache() { } void CodeCache::Clear() { - BERRY_INFO(InternalPlatform::GetInstance()->ConsoleLog()) << "Clearing code cache\n"; - std::vector files; - m_CachePath.list(files); - for (std::vector::iterator iter = files.begin(); iter != files.end(); ++iter) + if (m_CachePath.exists()) { - iter->remove(true); + BERRY_INFO(InternalPlatform::GetInstance()->ConsoleLog()) << "Clearing code cache\n"; + std::vector files; + m_CachePath.list(files); + for (std::vector::iterator iter = files.begin(); iter != files.end(); ++iter) + { + iter->remove(true); + } } } bool CodeCache::HasLibrary(const std::string& name) { //BERRY_INFO << "HasLibrary checks for: " << name; std::vector files; m_CachePath.list(files); std::string libName(name); //libName.append(Poco::SharedLibrary::suffix()); std::vector::iterator iter; for (iter = files.begin(); iter != files.end(); iter++) { if ((*iter) == libName) { //BERRY_INFO << " FOUND\n"; return true; } } //BERRY_INFO << " NOT FOUND\n"; return false; } void CodeCache::InstallLibrary(const std::string& name, std::istream& istr) { //BERRY_INFO << "Installing library " << name << " to " << this->GetPathForLibrary(name).toString() << std::endl; std::ofstream ostr(this->GetPathForLibrary(name).toString().c_str(), std::ios::binary | std::ios::trunc); ostr << istr.rdbuf(); } void CodeCache::InstallLibrary(const std::string& name, const Poco::File& path) { //BERRY_INFO << "Registering library " << name << " in " << path.path() << std::endl; m_LibPaths.insert(std::make_pair(name, path)); } void CodeCache::UnInstallLibrary(const std::string& name) { std::map::iterator iter = m_LibPaths.find(name); if (iter == m_LibPaths.end()) { Poco::File(this->GetPathForLibrary(name)).remove(); } else { m_LibPaths.erase(name); } } Poco::Path CodeCache::GetPathForLibrary(const std::string& name) { // We instructed cmake to replace "." with "_" in library names // since they are also used for defines (for Windows dll import/export // stuff) and . is bad in identifiers. // Hence we must replace all "." with "_" here too std::string libName(name); std::replace(libName.begin(), libName.end(), '.', '_'); //BERRY_INFO << "Getting path for library: " << libName << std::endl; if (m_LibPaths.find(libName) != m_LibPaths.end()) { return Poco::Path(m_LibPaths[libName].path(), libName + Poco::SharedLibrary::suffix()); } else { return Poco::Path(m_CachePath.path(), libName + Poco::SharedLibrary::suffix()); } } } diff --git a/BlueBerry/Bundles/org.blueberry.osgi/src/internal/berryInternalPlatform.cpp b/BlueBerry/Bundles/org.blueberry.osgi/src/internal/berryInternalPlatform.cpp index 200c4f3cf4..0ac3b73686 100644 --- a/BlueBerry/Bundles/org.blueberry.osgi/src/internal/berryInternalPlatform.cpp +++ b/BlueBerry/Bundles/org.blueberry.osgi/src/internal/berryInternalPlatform.cpp @@ -1,519 +1,519 @@ /*========================================================================= Program: BlueBerry Platform Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "berryInternalPlatform.h" #include "berryLog.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "../berryPlatform.h" #include "../berryPlatformException.h" #include "../berryDebugUtil.h" #include "../event/berryPlatformEvents.h" #include "berryPlatformLogChannel.h" #include "../berryIBundle.h" #include "berryCodeCache.h" #include "../berryBundleLoader.h" #include "berrySystemBundle.h" #include "berryBundleDirectory.h" #include "berryProvisioningInfo.h" #include #include namespace berry { Poco::Mutex InternalPlatform::m_Mutex; InternalPlatform::InternalPlatform() : m_Initialized(false), m_Running(false), m_ConsoleLog(false), m_ServiceRegistry(0), m_CodeCache(0), m_BundleLoader(0), m_SystemBundle(0), m_PlatformLogger(0), m_ctkPluginFrameworkFactory(0), m_EventStarted(PlatformEvent::EV_PLATFORM_STARTED) { } InternalPlatform::~InternalPlatform() { } InternalPlatform* InternalPlatform::GetInstance() { Poco::Mutex::ScopedLock lock(m_Mutex); static InternalPlatform instance; return &instance; } bool InternalPlatform::ConsoleLog() const { return m_ConsoleLog; } ctkPluginContext* InternalPlatform::GetCTKPluginFrameworkContext() const { if (m_ctkPluginFrameworkFactory) { return m_ctkPluginFrameworkFactory->getFramework()->getPluginContext(); } return 0; } ServiceRegistry& InternalPlatform::GetServiceRegistry() { AssertInitialized(); return *m_ServiceRegistry; } void InternalPlatform::Initialize(int& argc, char** argv, Poco::Util::AbstractConfiguration* config) { // initialization Poco::Mutex::ScopedLock lock(m_Mutex); m_Argc = &argc; m_Argv = argv; try { this->init(argc, argv); } catch (const Poco::Util::UnknownOptionException& e) { BERRY_WARN << e.displayText(); } this->loadConfiguration(); if (config) { this->config().add(config, 50, false); } m_ServiceRegistry = new ServiceRegistry(); m_ConsoleLog = this->GetConfiguration().hasProperty(Platform::ARG_CONSOLELOG); m_ConfigPath.assign(this->GetConfiguration().getString("application.configDir")); m_InstancePath.assign(this->GetConfiguration().getString("application.dir")); try { m_InstallPath.assign(this->GetConfiguration().getString(Platform::ARG_HOME)); } catch (Poco::NotFoundException& ) { m_InstallPath.assign(m_InstancePath); } - m_UserPath.assign(QDesktopServices::storageLocation(QDesktopServices::DataLocation).toStdString()); + m_UserPath.assign(QDesktopServices::storageLocation(QDesktopServices::DataLocation).toStdString() + '/'); Poco::File userFile(m_UserPath); try { userFile.createDirectories(); userFile.canWrite(); } catch(const Poco::IOException& e) { BERRY_WARN << e.displayText(); m_UserPath.assign(Poco::Path::temp()); m_UserPath.pushDirectory("." + this->commandName()); userFile = m_UserPath; } - - m_BaseStatePath = m_UserPath; - m_BaseStatePath.pushDirectory(".metadata"); - m_BaseStatePath.pushDirectory(".plugins"); - - Poco::Path logPath(m_UserPath); - logPath.setFileName(this->commandName() + ".log"); - m_PlatformLogChannel = new PlatformLogChannel(logPath.toString()); - m_PlatformLogger = &Poco::Logger::create("PlatformLogger", m_PlatformLogChannel, Poco::Message::PRIO_TRACE); - - try - { - m_CodeCache = new CodeCache(this->GetConfiguration().getString(Platform::ARG_PLUGIN_CACHE)); - } - catch (Poco::NotFoundException&) - { - Poco::Path cachePath(m_UserPath); - cachePath.pushDirectory("plugin_cache"); - m_CodeCache = new CodeCache(cachePath.toString()); - } - m_BundleLoader = new BundleLoader(m_CodeCache, *m_PlatformLogger); // Initialize the CTK Plugin Framework ctkProperties fwProps; fwProps.insert(ctkPluginConstants::FRAMEWORK_STORAGE, QString::fromStdString(userFile.path())); if (this->GetConfiguration().hasProperty(Platform::ARG_CLEAN)) { fwProps.insert(ctkPluginConstants::FRAMEWORK_STORAGE_CLEAN, ctkPluginConstants::FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT); } m_ctkPluginFrameworkFactory = new ctkPluginFrameworkFactory(fwProps); QSharedPointer pfw = m_ctkPluginFrameworkFactory->getFramework(); pfw->init(); ctkPluginContext* pfwContext = pfw->getPluginContext(); std::string provisioningFile = this->GetConfiguration().getString(Platform::ARG_PROVISIONING); if (!provisioningFile.empty()) { ProvisioningInfo provInfo(QString::fromStdString(provisioningFile)); foreach(QString pluginPath, provInfo.getPluginDirs()) { ctkPluginFrameworkLauncher::addSearchPath(pluginPath); } bool forcePluginOverwrite = this->GetConfiguration().hasOption(Platform::ARG_FORCE_PLUGIN_INSTALL); QList pluginsToStart = provInfo.getPluginsToStart(); foreach(QUrl pluginUrl, provInfo.getPluginsToInstall()) { if (forcePluginOverwrite) { uninstallPugin(pluginUrl, pfwContext); } QSharedPointer plugin = pfwContext->installPlugin(pluginUrl); if (pluginsToStart.contains(pluginUrl)) { m_CTKPluginsToStart << plugin->getPluginId(); } } } + m_BaseStatePath = m_UserPath; + m_BaseStatePath.pushDirectory("bb-metadata"); + m_BaseStatePath.pushDirectory("bb-plugins"); + + Poco::Path logPath(m_UserPath); + logPath.setFileName(this->commandName() + ".log"); + m_PlatformLogChannel = new PlatformLogChannel(logPath.toString()); + m_PlatformLogger = &Poco::Logger::create("PlatformLogger", m_PlatformLogChannel, Poco::Message::PRIO_TRACE); + + try + { + m_CodeCache = new CodeCache(this->GetConfiguration().getString(Platform::ARG_PLUGIN_CACHE)); + } + catch (Poco::NotFoundException&) + { + Poco::Path cachePath(m_UserPath); + cachePath.pushDirectory("bb-plugin_cache"); + m_CodeCache = new CodeCache(cachePath.toString()); + } + m_BundleLoader = new BundleLoader(m_CodeCache, *m_PlatformLogger); + // tell the BundleLoader about the installed CTK plug-ins QStringList installedCTKPlugins; foreach(QSharedPointer plugin, pfwContext->getPlugins()) { installedCTKPlugins << plugin->getSymbolicName(); } m_BundleLoader->SetCTKPlugins(installedCTKPlugins); m_Initialized = true; // Clear the CodeCache if (this->GetConfiguration().hasProperty(Platform::ARG_CLEAN)) m_CodeCache->Clear(); try { // assemble a list of base plugin-directories (which contain // the real plugins as directories) std::vector pluginBaseDirs; Poco::StringTokenizer tokenizer(this->GetConfiguration().getString(Platform::ARG_PLUGIN_DIRS, ""), ";", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM); for (Poco::StringTokenizer::Iterator token = tokenizer.begin(); token != tokenizer.end(); ++token) { pluginBaseDirs.push_back(*token); } std::vector pluginPaths; for (std::vector::iterator pluginBaseDir = pluginBaseDirs.begin(); pluginBaseDir != pluginBaseDirs.end(); ++pluginBaseDir) { BERRY_INFO(m_ConsoleLog) << "Plugin base directory: " << *pluginBaseDir; Poco::File pluginDir(*pluginBaseDir); if (!pluginDir.exists() || !pluginDir.isDirectory()) { BERRY_WARN(m_ConsoleLog) << *pluginBaseDir << " is not a direcotry or does not exist. SKIPPED.\n"; continue; } std::vector pluginList; pluginDir.list(pluginList); std::vector::iterator iter; for (iter = pluginList.begin(); iter != pluginList.end(); iter++) { Poco::Path pluginPath = Poco::Path::forDirectory(*pluginBaseDir); pluginPath.pushDirectory(*iter); Poco::File file(pluginPath); if (file.exists() && file.isDirectory()) { pluginPaths.push_back(pluginPath); } } } std::vector::iterator pathIter; for (pathIter = pluginPaths.begin(); pathIter != pluginPaths.end(); pathIter++) { try { Bundle::Pointer bundle = m_BundleLoader->LoadBundle(*pathIter); if (bundle) { BERRY_INFO(m_ConsoleLog) << "Bundle state (" << pathIter->toString() << "): " << bundle->GetStateString() << std::endl; } } catch (const BundleStateException& exc) { BERRY_WARN << exc.displayText() << std::endl; } } // resolve plugins m_BundleLoader->ResolveAllBundles(); } catch (Poco::Exception& exc) { this->logger().log(exc); } #ifdef BLUEBERRY_DEBUG_SMARTPOINTER DebugUtil::RestoreState(); #endif } void InternalPlatform::uninstallPugin(const QUrl& pluginUrl, ctkPluginContext* pfwContext) { QFileInfo libInfo(pluginUrl.toLocalFile()); QString libName = libInfo.baseName(); if (libName.startsWith("lib")) { libName = libName.mid(3); } QString symbolicName = libName.replace('_', '.'); foreach(QSharedPointer plugin, pfwContext->getPlugins()) { if (plugin->getSymbolicName() == symbolicName && plugin->getLocation() != pluginUrl.toString()) { BERRY_WARN << "A plug-in with the symbolic name " << symbolicName.toStdString() << " but different location is already installed. Trying to uninstall " << plugin->getLocation().toStdString(); plugin->uninstall(); return; } } } void InternalPlatform::Launch() { AssertInitialized(); if (m_Running) return; m_Running = true; this->run(); } void InternalPlatform::Shutdown() { Poco::Mutex::ScopedLock lock(m_Mutex); AssertInitialized(); DebugUtil::SaveState(); m_Initialized = false; this->uninitialize(); delete m_ServiceRegistry; delete m_BundleLoader; delete m_CodeCache; } void InternalPlatform::AssertInitialized() { if (!m_Initialized) throw Poco::SystemException("The Platform has not been initialized yet!"); } IExtensionPointService::Pointer InternalPlatform::GetExtensionPointService() { Poco::Mutex::ScopedLock lock(m_Mutex); this->AssertInitialized(); return m_ServiceRegistry->GetServiceById(IExtensionPointService::SERVICE_ID); } const Poco::Path& InternalPlatform::GetConfigurationPath() { return m_ConfigPath; } const Poco::Path& InternalPlatform::GetInstallPath() { return m_InstallPath; } const Poco::Path& InternalPlatform::GetInstancePath() { return m_InstancePath; } bool InternalPlatform::GetStatePath(Poco::Path& statePath, IBundle::Pointer bundle, bool create) { statePath = m_BaseStatePath; statePath.pushDirectory(bundle->GetSymbolicName()); try { Poco::File stateFile(statePath); if (!stateFile.exists() && create) stateFile.createDirectories(); } catch (Poco::FileException&) { return false; } return true; } PlatformEvents& InternalPlatform::GetEvents() { return m_Events; } const Poco::Path& InternalPlatform::GetUserPath() { return m_UserPath; } bool InternalPlatform::IsRunning() const { Poco::Mutex::ScopedLock lock(m_Mutex); return (m_Initialized && m_Running); } IBundle::Pointer InternalPlatform::GetBundle(const std::string& id) { Poco::Mutex::ScopedLock lock(m_Mutex); AssertInitialized(); return m_BundleLoader->FindBundle(id); } std::vector InternalPlatform::GetBundles() const { return m_BundleLoader->GetBundles(); } Poco::Logger* InternalPlatform::GetLogger() { return m_PlatformLogger; } Poco::Util::LayeredConfiguration& InternalPlatform::GetConfiguration() const { return this->config(); } std::vector InternalPlatform::GetApplicationArgs() const { return m_FilteredArgs; } int& InternalPlatform::GetRawApplicationArgs(char**& argv) { argv = m_Argv; return *m_Argc; } void InternalPlatform::defineOptions(Poco::Util::OptionSet& options) { Poco::Util::Option helpOption("help", "h", "print this help text"); helpOption.callback(Poco::Util::OptionCallback(this, &InternalPlatform::PrintHelp)); options.addOption(helpOption); Poco::Util::Option cleanOption(Platform::ARG_CLEAN, "", "cleans the plugin cache"); cleanOption.binding(Platform::ARG_CLEAN); options.addOption(cleanOption); Poco::Util::Option appOption(Platform::ARG_APPLICATION, "", "the id of the application extension to be executed"); appOption.argument("").binding(Platform::ARG_APPLICATION); options.addOption(appOption); Poco::Util::Option consoleLogOption(Platform::ARG_CONSOLELOG, "", "log messages to the console"); consoleLogOption.binding(Platform::ARG_CONSOLELOG); options.addOption(consoleLogOption); Poco::Util::Option forcePluginOption(Platform::ARG_FORCE_PLUGIN_INSTALL, "", "force installing plug-ins with same symbolic name"); forcePluginOption.binding(Platform::ARG_FORCE_PLUGIN_INSTALL); options.addOption(forcePluginOption); Poco::Util::Option testPluginOption(Platform::ARG_TESTPLUGIN, "", "the plug-in to be tested"); testPluginOption.argument("").binding(Platform::ARG_TESTPLUGIN); options.addOption(testPluginOption); Poco::Util::Option testAppOption(Platform::ARG_TESTAPPLICATION, "", "the application to be tested"); testAppOption.argument("").binding(Platform::ARG_TESTAPPLICATION); options.addOption(testAppOption); Poco::Util::Application::defineOptions(options); } int InternalPlatform::main(const std::vector& args) { m_FilteredArgs = args; m_FilteredArgs.insert(m_FilteredArgs.begin(), this->config().getString("application.argv[0]")); ctkPluginContext* context = GetCTKPluginFrameworkContext(); QFileInfo storageDir = context->getDataFile(""); BundleDirectory::Pointer bundleStorage(new BundleDirectory(Poco::Path(storageDir.absolutePath().toStdString()))); SystemBundle::Pointer systemBundle(new SystemBundle(*m_BundleLoader, bundleStorage)); if (systemBundle == 0) throw PlatformException("Could not find the system bundle"); m_BundleLoader->m_SystemBundle = systemBundle; m_BundleLoader->LoadBundle(systemBundle); m_ctkPluginFrameworkFactory->getFramework()->start(); foreach(long pluginId, m_CTKPluginsToStart) { // do not change the autostart setting of this plugin context->getPlugin(pluginId)->start(ctkPlugin::START_TRANSIENT | ctkPlugin::START_ACTIVATION_POLICY); } m_BundleLoader->StartSystemBundle(systemBundle); systemBundle->Resume(); return EXIT_OK; } void InternalPlatform::PrintHelp(const std::string&, const std::string&) { Poco::Util::HelpFormatter help(this->options()); help.setAutoIndent(); help.setCommand(this->commandName()); help.format(std::cout); exit(EXIT_OK); } } diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryWorkbenchPlugin.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryWorkbenchPlugin.cpp index 6463bc7f33..5152a9ee1e 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryWorkbenchPlugin.cpp +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryWorkbenchPlugin.cpp @@ -1,329 +1,330 @@ /*========================================================================= Program: BlueBerry Platform Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "berryLog.h" #include "berryWorkbenchPlugin.h" #include "berryWorkbenchRegistryConstants.h" #include "berryWorkbench.h" #include "berryPlatform.h" #include "intro/berryEditorIntroAdapterPart.h" #include "../berryImageDescriptor.h" #include +#include namespace berry { bool WorkbenchPlugin::DEBUG = false; char WorkbenchPlugin::PREFERENCE_PAGE_CATEGORY_SEPARATOR = '/'; WorkbenchPlugin* WorkbenchPlugin::inst = 0; WorkbenchPlugin::WorkbenchPlugin() : AbstractUICTKPlugin() { inst = this; presentationFactory = 0; editorRegistry = 0; viewRegistry = 0; perspRegistry = 0; introRegistry = 0; } WorkbenchPlugin::~WorkbenchPlugin() { delete editorRegistry; delete viewRegistry; delete perspRegistry; delete introRegistry; } bool WorkbenchPlugin::HasExecutableExtension( IConfigurationElement::Pointer element, const std::string& extensionName) { std::string attr; if (element->GetAttribute(extensionName, attr)) return true; std::string elementText(element->GetValue()); if (elementText != "") return true; IConfigurationElement::vector children(element->GetChildren(extensionName)); if (children.size() == 1) { if (children[0]->GetAttribute(WorkbenchRegistryConstants::ATT_CLASS, attr)) return true; } return false; } bool WorkbenchPlugin::IsBundleLoadedForExecutableExtension( IConfigurationElement::Pointer element, const std::string& extensionName) { IBundle::Pointer bundle(WorkbenchPlugin::GetBundleForExecutableExtension(element, extensionName)); if (bundle.IsNull()) return true; return bundle->GetState() == IBundle::BUNDLE_ACTIVE; } IBundle::Pointer WorkbenchPlugin::GetBundleForExecutableExtension( IConfigurationElement::Pointer element, const std::string& extensionName) { // this code is derived heavily from // ConfigurationElement.createExecutableExtension. std::string prop; std::string executable; std::string contributorName; std::string::size_type i; if (extensionName != "") element->GetAttribute(extensionName, prop); else { // property not specified, try as element value prop = element->GetValue(); if (prop != "") { Poco::trimInPlace(prop); } } if (prop == "") { // property not defined, try as a child element IConfigurationElement::vector exec(element->GetChildren(extensionName)); if (exec.size() != 0) exec[0]->GetAttribute("plugin", contributorName); //$NON-NLS-1$ } else { // simple property or element value, parse it into its components i = prop.find_first_of(':'); if (i != std::string::npos) executable = Poco::trim(prop.substr(0, i)); else executable = prop; i = executable.find_first_of('/'); if (i != std::string::npos) contributorName = Poco::trim(executable.substr(0, i)); } if (contributorName == "") contributorName = element->GetContributor(); return Platform::GetBundle(contributorName); } WorkbenchPlugin* WorkbenchPlugin::GetDefault() { return inst; } std::size_t WorkbenchPlugin::GetBundleCount() { // TODO BundleContext GetBundles //return bundleContext->GetBundles().size(); return 0; } // ImageRegistry createImageRegistry() { // return WorkbenchImages.getImageRegistry(); // } IPerspectiveRegistry* WorkbenchPlugin::GetPerspectiveRegistry() { if (perspRegistry == 0) { perspRegistry = new PerspectiveRegistry(); // the load methods can touch on WorkbenchImages if an image is // missing so we need to wrap the call in // a startup block for the case where a custom descriptor exists on // startup that does not have an image // associated with it. See bug 196352. //StartupThreading.runWithoutExceptions(new StartupRunnable() { // public void runWithException() throws Throwable { perspRegistry->Load(); // } //}); } return perspRegistry; } // PreferenceManager getPreferenceManager() { // if (preferenceManager == null) { // preferenceManager = new WorkbenchPreferenceManager( // PREFERENCE_PAGE_CATEGORY_SEPARATOR); // // //Get the pages from the registry // PreferencePageRegistryReader registryReader = new PreferencePageRegistryReader( // getWorkbench()); // registryReader // .loadFromRegistry(Platform.getExtensionRegistry()); // preferenceManager.addPages(registryReader.getTopLevelNodes()); // // } // return preferenceManager; // } // ISharedImages getSharedImages() { // if (sharedImages == null) { // sharedImages = new SharedImages(); // } // return sharedImages; // } IIntroRegistry* WorkbenchPlugin::GetIntroRegistry() { if (introRegistry == 0) { introRegistry = new IntroRegistry(); } return introRegistry; } IViewRegistry* WorkbenchPlugin::GetViewRegistry() { if (!viewRegistry) viewRegistry = new ViewRegistry(); return viewRegistry; } IEditorRegistry* WorkbenchPlugin::GetEditorRegistry() { if (!editorRegistry) editorRegistry = new EditorRegistry(); return editorRegistry; } IPresentationFactory* WorkbenchPlugin::GetPresentationFactory() { if (presentationFactory != 0) return presentationFactory; std::string targetID = Workbench::GetInstance()->GetPresentationId(); presentationFactory = this->CreateExtension( WorkbenchRegistryConstants::PL_PRESENTATION_FACTORIES, "factory", targetID); if (presentationFactory == 0) WorkbenchPlugin::Log("Error creating presentation factory: " + targetID + " -- class is not an IPresentationFactory"); return presentationFactory; } void WorkbenchPlugin::Log(const std::string& message) { BERRY_INFO << "LOG: " << message << std::endl; //inst->GetLog().log(message); } void WorkbenchPlugin::Log(const Poco::RuntimeException& exc) { BERRY_INFO << "LOG: " << exc.message() << std::endl; //inst->GetLog().log(exc); } void WorkbenchPlugin::Log(const std::string& message, const Poco::RuntimeException& t) { PlatformException exc(message, t); WorkbenchPlugin::Log(exc); } void WorkbenchPlugin::Log(const std::string& clazz, const std::string& methodName, const Poco::RuntimeException& t) { std::string msg = "Exception in " + clazz + "." + methodName + ": " + t.what(); WorkbenchPlugin::Log(msg, t); } void WorkbenchPlugin::start(ctkPluginContext* context) { //context.addBundleListener(getBundleListener()); AbstractUICTKPlugin::start(context); bundleContext = context; BERRY_REGISTER_EXTENSION_CLASS(EditorIntroAdapterPart, context) // The UI plugin needs to be initialized so that it can install the callback in PrefUtil, // which needs to be done as early as possible, before the workbench // accesses any API preferences. // Bundle uiBundle = Platform.getBundle(PlatformUI.PLUGIN_ID); // try // { // // Attempt to load the activator of the ui bundle. This will force lazy start // // of the ui bundle. Using the bundle activator class here because it is a // // class that needs to be loaded anyway so it should not cause extra classes // // to be loaded. // if(uiBundle != null) // uiBundle.loadClass(UI_BUNDLE_ACTIVATOR); // } // catch (ClassNotFoundException e) // { // WorkbenchPlugin.log("Unable to load UI activator", e); //$NON-NLS-1$ // } /* * DO NOT RUN ANY OTHER CODE AFTER THIS LINE. If you do, then you are * likely to cause a deadlock in class loader code. Please see Bug 86450 * for more information. */ } //const std::vector WorkbenchPlugin::GetBundles() //{ // return bundleContext.IsNull() ? std::vector() : bundleContext->GetBundles(); //} ctkPluginContext* WorkbenchPlugin::GetPluginContext() { return bundleContext; } void WorkbenchPlugin::stop(ctkPluginContext* context) { AbstractUICTKPlugin::stop(context); delete perspRegistry; } bool WorkbenchPlugin::GetDataPath(Poco::Path& path) { QFileInfo fileInfo = bundleContext->getDataFile(""); - path.assign(fileInfo.absolutePath().toStdString()); + path.assign(fileInfo.absolutePath().toStdString() + '/'); return fileInfo.isWritable(); } } Q_EXPORT_PLUGIN2(org_blueberry_ui, berry::WorkbenchPlugin)