diff --git a/BlueBerry/Bundles/org.blueberry.osgi/src/berryBundleLoader.cpp b/BlueBerry/Bundles/org.blueberry.osgi/src/berryBundleLoader.cpp index f705835dcb..c9364ac473 100644 --- a/BlueBerry/Bundles/org.blueberry.osgi/src/berryBundleLoader.cpp +++ b/BlueBerry/Bundles/org.blueberry.osgi/src/berryBundleLoader.cpp @@ -1,492 +1,505 @@ /*========================================================================= 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 "berryBundleLoader.h" #include "internal/berryBundleContext.h" #include "internal/berryBundleDirectory.h" #include "event/berryBundleEvents.h" #include "internal/berryDefaultActivator.h" #include "internal/berrySystemBundleActivator.h" #include "internal/berryCodeCache.h" #include "internal/berryInternalPlatform.h" #include "berryPlugin.h" #include "berryPlatform.h" #include "berryPlatformException.h" #include "service/berryIExtensionPointService.h" #include namespace berry { BundleLoader::BundleLoader(CodeCache* codeCache, Poco::Logger& logger) //, BundleFactory* bundleFactory, BundleContextFactory* bundleContextFactory); : m_CodeCache(codeCache), m_Logger(logger), m_ConsoleLog(false) { m_ConsoleLog = InternalPlatform::GetInstance()->ConsoleLog(); } BundleLoader::~BundleLoader() { } +void BundleLoader::SetCTKPlugins(const QStringList& installedCTKPlugins) +{ + this->installedCTKPlugins = installedCTKPlugins; +} + Poco::Logger& BundleLoader::GetLogger() const { return m_Logger; } IBundleContext::Pointer BundleLoader::GetContextForBundle(IBundle::ConstPointer bundle) { Poco::Mutex::ScopedLock lock(m_Mutex); return m_BundleMap[bundle->GetSymbolicName()].m_Context; } Bundle::Pointer BundleLoader::CreateBundle(const Poco::Path& path) { BundleDirectory::Pointer bundleStorage(new BundleDirectory(path)); Bundle::Pointer bundle(new Bundle(*this, bundleStorage)); + if (bundle->GetState() == IBundle::BUNDLE_INSTALLED && + installedCTKPlugins.contains(QString::fromStdString(bundle->GetSymbolicName()))) + { + BERRY_WARN << "Ignoring legacy BlueBerry bundle " << bundle->GetSymbolicName() + << " because a CTK plug-in with the same name already exists."; + return Bundle::Pointer(0); + } + if (bundle->GetState() == IBundle::BUNDLE_INSTALLED && bundle->IsSystemBundle()) { bundle = new SystemBundle(*this, bundleStorage); m_SystemBundle = bundle; } //BundleEvent event(bundle, BundleEvent::EV_BUNDLE_INSTALLED); //m_BundleEvents.bundleInstalled(this, event); return bundle; } BundleEvents& BundleLoader::GetEvents() { return m_BundleEvents; } IBundle::Pointer BundleLoader::FindBundle(const std::string& symbolicName) { if (symbolicName == "system.bundle") return m_SystemBundle; Poco::Mutex::ScopedLock lock(m_Mutex); BundleMap::const_iterator iter; iter = m_BundleMap.find(symbolicName); if (iter == m_BundleMap.end()) return IBundle::Pointer(); return iter->second.m_Bundle; } std::vector BundleLoader::GetBundles() const { std::vector result; BundleMap::const_iterator end = m_BundleMap.end(); for (BundleMap::const_iterator it = m_BundleMap.begin(); it != end; ++it) { result.push_back(it->second.m_Bundle); } return result; } Bundle::Pointer BundleLoader::LoadBundle(const Poco::Path& path) { Bundle::Pointer bundle = this->CreateBundle(path); - this->LoadBundle(bundle); + if (bundle) this->LoadBundle(bundle); return bundle; } void BundleLoader::LoadBundle(Bundle::Pointer bundle) { if (bundle->GetState() == IBundle::BUNDLE_INSTALLED || bundle->GetState() == IBundle::BUNDLE_RESOLVED) { Poco::Mutex::ScopedLock lock(m_Mutex); if (m_BundleMap[bundle->GetSymbolicName()].m_Bundle.IsNull()) { BundleInfo bundleInfo; bundleInfo.m_Bundle = bundle; bundleInfo.m_ClassLoader = new ActivatorClassLoader(); Poco::Path path; Platform::GetStatePath(path, bundle); bundleInfo.m_Context = new BundleContext(*this, bundle, path); m_BundleMap[bundle->GetSymbolicName()] = bundleInfo; this->InstallLibraries(bundle); //BundleEvent event(bundle, BundleEvent::EV_BUNDLE_LOADED); //m_BundleEvents.bundleLoaded(this, event); } else { //TODO version conflict check } } else { throw BundleStateException("The bundle must be in state INSTALLED in order to be loaded."); } } Poco::Path BundleLoader::GetPathForLibrary(const std::string& libraryName) { return m_CodeCache->GetPathForLibrary(libraryName); } Poco::Path BundleLoader::GetLibraryPathFor(IBundle::Pointer bundle) { std::string libName = bundle->GetActivatorLibrary(); if (libName.empty()) libName = "lib" + bundle->GetSymbolicName(); return this->GetPathForLibrary(libName); } std::string BundleLoader::GetContributionsPathFor(IBundle::Pointer /*bundle*/) { return "plugin.xml"; } void BundleLoader::ResolveBundle(IBundle::Pointer bundle) { try { BERRY_INFO(m_ConsoleLog) << "Trying to resolve bundle " << bundle->GetSymbolicName(); bundle->Resolve(); BERRY_INFO(m_ConsoleLog) << "Bundle " << bundle->GetSymbolicName() << ": " << bundle->GetStateString(); } catch (BundleResolveException exc) { BERRY_ERROR << "Bundle resolve failed: " << exc.displayText(); } // if (bundle->IsResolved()) // { // BundleEvent event(bundle, BundleEvent::EV_BUNDLE_RESOLVED); // m_BundleEvents.bundleResolved(this, event); // } } void BundleLoader::ResolveAllBundles() { Poco::Mutex::ScopedLock lock(m_Mutex); BundleMap::iterator iter; for (iter = m_BundleMap.begin(); iter != m_BundleMap.end(); iter++) { this->ResolveBundle(iter->second.m_Bundle); } } void BundleLoader::ListLibraries(IBundle::Pointer bundle, std::vector& list) { ListLibraries(bundle, list, "bin/"); #ifdef CMAKE_INTDIR ListLibraries(bundle, list, "bin/" CMAKE_INTDIR "/"); #endif } void BundleLoader::ListLibraries(IBundle::Pointer bundle, std::vector& list, const std::string& baseDir) { std::vector tmpList; bundle->GetStorage().List(baseDir, tmpList); std::string::size_type suf = Poco::SharedLibrary::suffix().size(); std::vector::iterator iter; for (iter = tmpList.begin(); iter != tmpList.end(); ) { if (bundle->GetStorage().IsDirectory(baseDir + *iter)) { // uncomment the following line for a recursive lookup //this->ListLibraries(bundle, list, baseDir + *iter + "/"); iter = tmpList.erase(iter); } else { if (iter->substr(iter->size() - suf) == Poco::SharedLibrary::suffix()) { iter->erase(iter->size() - suf); iter->insert(0, baseDir); ++iter; } else { iter = tmpList.erase(iter); } } } list.insert(list.end(), tmpList.begin(), tmpList.end()); } void BundleLoader::InstallLibraries(IBundle::Pointer bundle, bool copy) { std::vector libraries; this->ListLibraries(bundle, libraries); std::vector::iterator iter; for (iter = libraries.begin(); iter != libraries.end(); ++iter) { if (iter->empty()) continue; //BERRY_INFO << "Testing CodeCache for: " << *iter << std::endl; std::size_t separator = iter->find_last_of("/"); std::string libFileName = *iter; if (separator != std::string::npos) libFileName = iter->substr(separator+1); if (!m_CodeCache->HasLibrary(libFileName)) { std::string libDir = ""; if (separator != std::string::npos) libDir += iter->substr(0, separator); // Check if we should copy the dll (from a ZIP file for example) if (copy) { //TODO This copies all files which start with *iter to the // plugin cache. This is necessary for Windows, for example, // where a .dll file is accompanied by a set of other files. // This should be extended to check for the right dll files, since // it would be possible (and a good idea anyway) to put multiple // versions of the same library in the ZIP file, targeting different // compilers for example. std::vector files; bundle->GetStorage().List(libDir, files); for (std::vector::iterator fileName = files.begin(); fileName != files.end(); ++fileName) { std::size_t size = std::min(libFileName.size(), fileName->size()); if (fileName->compare(0, size, libFileName) != 0) continue; std::istream* istr = bundle->GetResource(libDir + *fileName); m_CodeCache->InstallLibrary(*iter, *istr); delete istr; } } else { Poco::Path bundlePath = bundle->GetStorage().GetPath(); bundlePath.append(Poco::Path::forDirectory(libDir)); // On Windows, we set the path environment variable to include // the path to the library, so the loader can find it. We do this // programmatically because otherwise, a user would have to edit // a batch file every time he adds a new plugin from outside the // build system. #ifdef BERRY_OS_FAMILY_WINDOWS std::string pathEnv = Poco::Environment::get("PATH", ""); if (!pathEnv.empty()) pathEnv += ";"; pathEnv += bundlePath.toString(); Poco::Environment::set("PATH", pathEnv); #endif m_CodeCache->InstallLibrary(libFileName, bundlePath); } } } } void BundleLoader::ReadAllContributions() { Poco::Mutex::ScopedLock lock(m_Mutex); BundleMap::iterator iter; for (iter = m_BundleMap.begin(); iter != m_BundleMap.end(); ++iter) { if (iter->second.m_Bundle && iter->second.m_Bundle->IsResolved()) this->ReadContributions(iter->second.m_Bundle); } } void BundleLoader::ReadContributions(IBundle::Pointer bundle) { this->ReadDependentContributions(bundle); IExtensionPointService::Pointer service = Platform::GetExtensionPointService(); if (service->HasContributionFrom(bundle->GetSymbolicName())) return; std::istream* istr = bundle->GetResource(this->GetContributionsPathFor(bundle)); if (istr) { service->AddContribution(*istr, bundle->GetSymbolicName()); delete istr; } } void BundleLoader::ReadDependentContributions(IBundle::Pointer bundle) { Poco::Mutex::ScopedLock lock(m_Mutex); const IBundleManifest::Dependencies& deps = bundle->GetRequiredBundles(); IBundleManifest::Dependencies::const_iterator iter; for (iter = deps.begin(); iter != deps.end(); ++iter) { BundleMap::const_iterator depIter = m_BundleMap.find(iter->symbolicName); if (depIter != m_BundleMap.end()) { // only read contributions from legacy BlueBerry bundles if (IBundle::Pointer depBundle = depIter->second.m_Bundle) { this->ReadContributions(depBundle); } } } } void BundleLoader::StartAllBundles() { Poco::Mutex::ScopedLock lock(m_Mutex); BundleMap::iterator iter; for (iter = m_BundleMap.begin(); iter != m_BundleMap.end(); ++iter) { try { if (iter->second.m_Bundle && iter->second.m_Bundle->GetActivationPolicy() == IBundleManifest::EAGER && !iter->second.m_Bundle->IsSystemBundle()) this->StartBundle(iter->second.m_Bundle); } catch (Poco::Exception exc) { BERRY_ERROR << exc.displayText() << std::endl; } } } void BundleLoader::StartBundle(Bundle::Pointer bundle) { Poco::Mutex::ScopedLock lock(m_Mutex); if (bundle->GetState() != IBundle::BUNDLE_RESOLVED) return; this->StartDependencies(bundle); BundleInfo info = m_BundleMap[bundle->GetSymbolicName()]; IBundleActivator* activator = this->LoadActivator(info); Plugin* plugin = dynamic_cast(activator); if (plugin) plugin->m_Bundle = bundle; bundle->SetActivator(activator); bundle->Start(); } void BundleLoader::StartSystemBundle(SystemBundle::Pointer bundle) { Poco::Mutex::ScopedLock lock(m_Mutex); if (bundle->IsStarted()) return; BundleInfo info = m_BundleMap[bundle->GetSymbolicName()]; //IBundleActivator* activator = this->LoadActivator(info); IBundleActivator* activator = new SystemBundleActivator(); bundle->SetActivator(activator); activator->Start(info.m_Context); } void BundleLoader::StartDependencies(Bundle::Pointer bundle) { Poco::Mutex::ScopedLock lock(m_Mutex); const IBundleManifest::Dependencies& deps = bundle->GetRequiredBundles(); IBundleManifest::Dependencies::const_iterator iter; QList > ctkPlugins = CTKPluginActivator::getPluginContext()->getPlugins(); for (iter = deps.begin(); iter != deps.end(); ++iter) { BundleMap::const_iterator depIter = m_BundleMap.find(iter->symbolicName); if (depIter != m_BundleMap.end()) { if (Bundle::Pointer depBundle = depIter->second.m_Bundle) { this->StartBundle(depBundle); } } else { foreach (QSharedPointer ctkPlugin, ctkPlugins) { if (ctkPlugin->getSymbolicName() == QString::fromStdString(iter->symbolicName)) { ctkPlugin->start(0); break; } } } } } IBundleActivator* BundleLoader::LoadActivator(BundleInfo& bundleInfo) { Poco::Mutex::ScopedLock lock(m_Mutex); std::string activator = bundleInfo.m_Bundle->GetActivatorClass(); if (activator == "") return new DefaultActivator(); Poco::Path libPath = this->GetLibraryPathFor(bundleInfo.m_Bundle); std::string strLibPath(libPath.toString()); BERRY_INFO(m_ConsoleLog) << "Loading activator library: " << strLibPath; try { /* retrieves only an empty string and its not required #ifdef BERRY_OS_FAMILY_WINDOWS char cDllPath[512]; GetDllDirectory(512, cDllPath); BERRY_INFO << "Dll Path: " << cDllPath << std::endl; #endif */ bundleInfo.m_ClassLoader->loadLibrary(strLibPath); return bundleInfo.m_ClassLoader->create(activator); } catch (Poco::LibraryLoadException exc) { BERRY_ERROR << "Could not create Plugin activator. Did you export the class \"" << activator << "\" ?\n" << " Exception displayText(): " << exc.displayText(); exc.rethrow(); } return 0; } } // namespace berry diff --git a/BlueBerry/Bundles/org.blueberry.osgi/src/berryBundleLoader.h b/BlueBerry/Bundles/org.blueberry.osgi/src/berryBundleLoader.h index 30e5728fd5..5960af7996 100644 --- a/BlueBerry/Bundles/org.blueberry.osgi/src/berryBundleLoader.h +++ b/BlueBerry/Bundles/org.blueberry.osgi/src/berryBundleLoader.h @@ -1,132 +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. =========================================================================*/ #ifndef BERRYBUNDLELOADER_H_ #define BERRYBUNDLELOADER_H_ #include "Poco/ClassLoader.h" #include "Poco/Mutex.h" #include "Poco/Path.h" #include "Poco/Any.h" #include "Poco/SharedPtr.h" #include "Poco/Logger.h" #include #include +#include + #include "event/berryBundleEvents.h" #include "berryIBundleActivator.h" #include "internal/berryBundle.h" #include "internal/berrySystemBundle.h" namespace berry { class CodeCache; struct IBundleContext; /** * Intentionally no BERRY_OSGI macro. This class belongs into "internal" but * needs to stay here. */ class BERRY_OSGI BundleLoader { private: typedef Poco::ClassLoader ActivatorClassLoader; typedef Poco::SharedPtr ActivatorClassLoaderPtr; struct BundleInfo { Bundle::Pointer m_Bundle; ActivatorClassLoaderPtr m_ClassLoader; std::map m_ClassLoaderMap; SmartPointer m_Context; }; typedef std::map BundleMap; BundleMap m_BundleMap; BundleEvents m_BundleEvents; CodeCache* m_CodeCache; mutable Poco::Logger& m_Logger; Bundle::Pointer m_SystemBundle; mutable Poco::Mutex m_Mutex; bool m_ConsoleLog; + QStringList installedCTKPlugins; + IBundleActivator* LoadActivator(BundleInfo& bundleInfo); friend class InternalPlatform; friend class BundleContext; void StartSystemBundle(SmartPointer bundle); void ListLibraries(SmartPointer bundle, std::vector& list, const std::string& baseDir); public: BundleLoader(CodeCache* codeCache, Poco::Logger& logger); //, BundleFactory* bundleFactory, BundleContextFactory* bundleContextFactory); virtual ~BundleLoader(); + void SetCTKPlugins(const QStringList& installedCTKPlugins); + SmartPointer GetContextForBundle(IBundle::ConstPointer bundle); Bundle::Pointer CreateBundle(const Poco::Path& path); BundleEvents& GetEvents(); IBundle::Pointer FindBundle(const std::string& symbolicName); std::vector GetBundles() const; Bundle::Pointer LoadBundle(const Poco::Path& path); void LoadBundle(Bundle::Pointer bundle); Poco::Path GetPathForLibrary(const std::string& libraryName); Poco::Path GetLibraryPathFor(SmartPointer bundle); std::string GetContributionsPathFor(SmartPointer bundle); Poco::Logger& GetLogger() const; void ResolveBundle(SmartPointer bundle); void ResolveAllBundles(); void ReadAllContributions(); void ReadContributions(SmartPointer bundle); void ReadDependentContributions(SmartPointer bundle); void ListLibraries(SmartPointer bundle, std::vector& list); void InstallLibraries(SmartPointer bundle, bool copy = false); // start all resolved bundles, except the system bundle // (it is assumed, that the system bundle has already // been started) void StartAllBundles(); void StartBundle(SmartPointer bundle); void StartDependencies(SmartPointer bundle); template C* LoadClass(const std::string& bundleName, const std::string& className); template C* LoadClass(const std::string& bundleName, const std::string& className, const std::string& manifestName); }; } // namespace berry #include "berryBundleLoader.txx" #endif /*BERRYBUNDLELOADER_H_*/ diff --git a/BlueBerry/Bundles/org.blueberry.osgi/src/internal/berryInternalPlatform.cpp b/BlueBerry/Bundles/org.blueberry.osgi/src/internal/berryInternalPlatform.cpp index 83deeedf7a..11b820a051 100644 --- a/BlueBerry/Bundles/org.blueberry.osgi/src/internal/berryInternalPlatform.cpp +++ b/BlueBerry/Bundles/org.blueberry.osgi/src/internal/berryInternalPlatform.cpp @@ -1,471 +1,482 @@ /*========================================================================= 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 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(Poco::Path::home()); m_UserPath.pushDirectory("." + this->commandName()); Poco::File userFile(m_UserPath); try { userFile.createDirectory(); 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())); 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); } QList pluginsToStart = provInfo.getPluginsToStart(); foreach(QUrl pluginUrl, provInfo.getPluginsToInstall()) { QSharedPointer plugin = pfwContext->installPlugin(pluginUrl); if (pluginsToStart.contains(pluginUrl)) { m_CTKPluginsToStart << plugin->getPluginId(); } } } + // 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); - BERRY_INFO(m_ConsoleLog) << "Bundle state (" << pathIter->toString() << "): " << bundle->GetStateString() << std::endl; + 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::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 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) { context->getPlugin(pluginId)->start(); } 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); } }