diff options
author | Christian Lippka <christian.lippka@sun.com> | 2010-06-01 14:04:07 +0200 |
---|---|---|
committer | Christian Lippka <christian.lippka@sun.com> | 2010-06-01 14:04:07 +0200 |
commit | bba2a81a5e2215591d8f29e69bd64d0e31fc23b1 (patch) | |
tree | b299bb6409a1700f49d22c603461ba51b44ef7a7 /desktop/source/migration | |
parent | 5c3614277d347e72c403135f5c92c0c13fb55d5f (diff) | |
parent | f8e7afbac976ca862a801b9648fd95b2107757b2 (diff) |
cws renaissance2: rebase m80
Diffstat (limited to 'desktop/source/migration')
-rw-r--r-- | desktop/source/migration/migration.cxx | 230 | ||||
-rw-r--r-- | desktop/source/migration/migration_impl.hxx | 5 |
2 files changed, 103 insertions, 132 deletions
diff --git a/desktop/source/migration/migration.cxx b/desktop/source/migration/migration.cxx index b9be788ebd4b..3789171ce254 100644 --- a/desktop/source/migration/migration.cxx +++ b/desktop/source/migration/migration.cxx @@ -28,6 +28,10 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_desktop.hxx" +#include <map> +#include <new> +#include <set> + #include "migration.hxx" #include "migration_impl.hxx" #include "cfgfilter.hxx" @@ -37,6 +41,7 @@ #include <comphelper/sequence.hxx> #include <unotools/bootstrap.hxx> #include <rtl/bootstrap.hxx> +#include <rtl/uri.hxx> #include <tools/config.hxx> #include <i18npool/lang.h> #include <tools/urlobj.hxx> @@ -46,12 +51,11 @@ #include <osl/security.hxx> #include <unotools/configmgr.hxx> +#include <com/sun/star/configuration/Update.hpp> #include <com/sun/star/lang/XInitialization.hpp> #include <com/sun/star/task/XJob.hpp> #include <com/sun/star/beans/NamedValue.hpp> #include <com/sun/star/beans/XPropertySet.hpp> -#include <com/sun/star/configuration/backend/XLayer.hpp> -#include <com/sun/star/configuration/backend/XSingleLayerStratum.hpp> #include <com/sun/star/util/XRefreshable.hpp> #include <com/sun/star/util/XChangesBatch.hpp> #include <com/sun/star/util/XStringSubstitution.hpp> @@ -64,8 +68,6 @@ using namespace com::sun::star::lang; using namespace com::sun::star::beans; using namespace com::sun::star::util; using namespace com::sun::star::container; -using namespace com::sun::star::configuration; -using namespace com::sun::star::configuration::backend; using com::sun::star::uno::Exception; using namespace com::sun::star; @@ -154,18 +156,15 @@ MigrationImpl::~MigrationImpl() sal_Bool MigrationImpl::doMigration() { - // compile file and service list for migration - m_vrFileList = compileFileList(); - m_vrServiceList = compileServiceList(); + // compile file list for migration + m_vrFileList = compileFileList(); sal_Bool result = sal_False; try{ copyFiles(); // execute the migration items from Setup.xcu - // and refresh the cache copyConfig(); - refresh(); // execute custom migration services from Setup.xcu // and refresh the cache @@ -333,13 +332,6 @@ migrations_vr MigrationImpl::readMigrationSteps(const ::rtl::OUString& rMigratio tmpStep.excludeExtensions.push_back(tmpSeq[j]); } - // config components - if (tmpAccess->getByName(OUString::createFromAscii("ServiceConfigComponents")) >>= tmpSeq) - { - for (sal_Int32 j=0; j<tmpSeq.getLength(); j++) - tmpStep.configComponents.push_back(tmpSeq[j]); - } - // generic service tmpAccess->getByName(OUString::createFromAscii("MigrationService")) >>= tmpStep.service; @@ -526,77 +518,104 @@ strings_vr MigrationImpl::compileFileList() return vrResult; } +namespace { -void MigrationImpl::copyConfig() -{ - try { - // 1. get a list of all components from hierachy browser - uno::Reference< XJob > xBrowser(m_xFactory->createInstance( - OUString::createFromAscii("com.sun.star.configuration.backend.LocalHierarchyBrowser")), uno::UNO_QUERY_THROW); - - uno::Sequence< NamedValue > seqArgs(2); - seqArgs[0] = NamedValue( - OUString::createFromAscii("LayerDataUrl"), - uno::makeAny(m_aInfo.userdata + OUString::createFromAscii("/user/registry"))); - seqArgs[1] = NamedValue( - OUString::createFromAscii("FetchComponentNames"), - uno::makeAny(sal_True)); - - // execute the search - uno::Any aResult = xBrowser->execute(seqArgs); - uno::Sequence< OUString > seqComponents; - aResult >>= seqComponents; - OSL_ENSURE(seqComponents.getLength()>0, "MigrationImpl::copyConfig(): no config components available"); - - // 2. create an importer - uno::Reference< XJob > xImporter(m_xFactory->createInstance( - OUString::createFromAscii("com.sun.star.configuration.backend.LocalDataImporter")), uno::UNO_QUERY_THROW); - - // 3. for each migration step... - uno::Sequence< NamedValue > importerArgs(3); - importerArgs[0] = NamedValue( - OUString::createFromAscii("LayerDataUrl"), - uno::makeAny(m_aInfo.userdata + OUString::createFromAscii("/user/registry"))); - importerArgs[1] = NamedValue( - OUString::createFromAscii("LayerFilter"), - uno::Any()); - importerArgs[2] = NamedValue( - OUString::createFromAscii("Component"), - uno::Any()); - - migrations_v::const_iterator i_mig = m_vrMigrations->begin(); - while (i_mig != m_vrMigrations->end()) - { - // a. create config filter for step - uno::Reference< XInitialization > xFilter( - new CConfigFilter(&(i_mig->includeConfig), &(i_mig->excludeConfig))); - importerArgs[1].Value = uno::makeAny(xFilter); +struct componentParts { + std::set< rtl::OUString > includedPaths; + std::set< rtl::OUString > excludedPaths; +}; - // b. run each importer with config filter - for (sal_Int32 i=0; i<seqComponents.getLength(); i++) - { - OUString component = seqComponents[i]; - importerArgs[2].Value = uno::makeAny(seqComponents[i]); - try { - aResult = xImporter->execute(importerArgs); - Exception myException; - if (aResult >>= myException) throw myException; - } catch(Exception& aException) { - OString aMsg("Exception in config layer import.\ncomponent: "); - aMsg += OUStringToOString(seqComponents[i], RTL_TEXTENCODING_ASCII_US); - aMsg += "\nmessage: "; - aMsg += OUStringToOString(aException.Message, RTL_TEXTENCODING_ASCII_US); - OSL_ENSURE(sal_False, aMsg.getStr()); - } +typedef std::map< rtl::OUString, componentParts > Components; + +bool getComponent(rtl::OUString const & path, rtl::OUString * component) { + OSL_ASSERT(component != 0); + if (path.getLength() == 0 || path[0] != '/') { + OSL_TRACE( + ("configuration migration in/exclude path %s ignored (does not" + " start with slash)"), + rtl::OUStringToOString(path, RTL_TEXTENCODING_UTF8).getStr()); + return false; + } + sal_Int32 i = path.indexOf('/', 1); + *component = i < 0 ? path.copy(1) : path.copy(1, i - 1); + return true; +} + +uno::Sequence< rtl::OUString > setToSeq(std::set< rtl::OUString > const & set) { + std::set< rtl::OUString >::size_type n = set.size(); + if (n > SAL_MAX_INT32) { + throw std::bad_alloc(); + } + uno::Sequence< rtl::OUString > seq(static_cast< sal_Int32 >(n)); + sal_Int32 i = 0; + for (std::set< rtl::OUString >::const_iterator j(set.begin()); + j != set.end(); ++j) + { + seq[i++] = *j; + } + return seq; +} + +} + +void MigrationImpl::copyConfig() { + Components comps; + for (migrations_v::const_iterator i(m_vrMigrations->begin()); + i != m_vrMigrations->end(); ++i) + { + for (strings_v::const_iterator j(i->includeConfig.begin()); + j != i->includeConfig.end(); ++j) + { + rtl::OUString comp; + if (getComponent(*j, &comp)) { + comps[comp].includedPaths.insert(*j); + } + } + for (strings_v::const_iterator j(i->excludeConfig.begin()); + j != i->excludeConfig.end(); ++j) + { + rtl::OUString comp; + if (getComponent(*j, &comp)) { + comps[comp].excludedPaths.insert(*j); } - i_mig++; } } - catch (Exception& e) - { - OString aMsg("Exception in config layer import.\nmessage: "); - aMsg += OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US); - OSL_ENSURE(sal_False, aMsg.getStr()); + for (Components::const_iterator i(comps.begin()); i != comps.end(); ++i) { + if (!i->second.includedPaths.empty()) { + rtl::OUStringBuffer buf(m_aInfo.userdata); + buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("/user/registry/data")); + sal_Int32 n = 0; + do { + rtl::OUString seg(i->first.getToken(0, '.', n)); + rtl::OUString enc( + rtl::Uri::encode( + seg, rtl_UriCharClassPchar, rtl_UriEncodeStrict, + RTL_TEXTENCODING_UTF8)); + if (enc.getLength() == 0 && seg.getLength() != 0) { + OSL_TRACE( + ("configuration migration component %s ignored (cannot" + " be encoded as file path)"), + rtl::OUStringToOString( + i->first, RTL_TEXTENCODING_UTF8).getStr()); + goto next; + } + buf.append(sal_Unicode('/')); + buf.append(enc); + } while (n >= 0); + buf.appendAscii(RTL_CONSTASCII_STRINGPARAM(".xcu")); + configuration::Update::get( + comphelper::getProcessComponentContext())-> + insertModificationXcuFile( + buf.makeStringAndClear(), setToSeq(i->second.includedPaths), + setToSeq(i->second.excludedPaths)); + } else { + OSL_TRACE( + ("configuration migration component %s ignored (only excludes," + " no includes)"), + rtl::OUStringToOString( + i->first, RTL_TEXTENCODING_UTF8).getStr()); + } + next:; } } @@ -705,17 +724,8 @@ void MigrationImpl::copyFiles() void MigrationImpl::runServices() { - //create stratum for old user layer - OUString aOldLayerURL = m_aInfo.userdata; - aOldLayerURL += OUString::createFromAscii("/user/registry"); - OUString aStratumSvc = OUString::createFromAscii("com.sun.star.configuration.backend.LocalSingleStratum"); - uno::Sequence< uno::Any > stratumArgs(1); - stratumArgs[0] = uno::makeAny(aOldLayerURL); - uno::Reference< XSingleLayerStratum> xStartum( m_xFactory->createInstanceWithArguments( - aStratumSvc, stratumArgs), uno::UNO_QUERY); - // Build argument array - uno::Sequence< uno::Any > seqArguments(4); + uno::Sequence< uno::Any > seqArguments(3); seqArguments[0] = uno::makeAny(NamedValue( OUString::createFromAscii("Productname"), uno::makeAny(m_aInfo.productname))); @@ -736,34 +746,13 @@ void MigrationImpl::runServices() try { - // create access to old configuration components in the user layer - // that were requested by the migration service - uno::Sequence< NamedValue > seqComponents(i_mig->configComponents.size()); - strings_v::const_iterator i_comp = i_mig->configComponents.begin(); - sal_Int32 i = 0; - while (i_comp != i_mig->configComponents.end() && xStartum.is()) - { - // create Layer for i_comp - seqComponents[i] = NamedValue( - *i_comp, uno::makeAny(xStartum->getLayer(*i_comp, OUString()))); - - // next component - i_comp++; - i++; - } - - // set old config argument - seqArguments[2] = uno::makeAny(NamedValue( - OUString::createFromAscii("OldConfiguration"), - uno::makeAny(seqComponents))); - // set black list for extension migration uno::Sequence< rtl::OUString > seqExtBlackList; sal_uInt32 nSize = i_mig->excludeExtensions.size(); if ( nSize > 0 ) seqExtBlackList = comphelper::arrayToSequence< ::rtl::OUString >( &i_mig->excludeExtensions[0], nSize ); - seqArguments[3] = uno::makeAny(NamedValue( + seqArguments[2] = uno::makeAny(NamedValue( OUString::createFromAscii("ExtensionBlackList"), uno::makeAny( seqExtBlackList ))); @@ -792,17 +781,4 @@ void MigrationImpl::runServices() } } - -strings_vr MigrationImpl::compileServiceList() -{ - strings_vr vrResult(new strings_v); - migrations_v::const_iterator i_migr = m_vrMigrations->begin(); - while (i_migr != m_vrMigrations->end()) - { - vrResult->push_back(i_migr->service); - i_migr++; - } - return vrResult; -} - } // namespace desktop diff --git a/desktop/source/migration/migration_impl.hxx b/desktop/source/migration/migration_impl.hxx index b40de510261d..8cad1cce4b16 100644 --- a/desktop/source/migration/migration_impl.hxx +++ b/desktop/source/migration/migration_impl.hxx @@ -64,7 +64,6 @@ struct migration_step strings_v excludeFiles; strings_v includeConfig; strings_v excludeConfig; - strings_v configComponents; strings_v includeExtensions; strings_v excludeExtensions; rtl::OUString service; @@ -92,8 +91,6 @@ private: migrations_vr m_vrMigrations; // list of all migration specs from config install_info m_aInfo; // info about the version being migrated strings_vr m_vrFileList; // final list of files to be copied - strings_vr m_vrConfigList; // final list of nodes to be copied - strings_vr m_vrServiceList; // final list of services to be called // functions to control the migration process bool readAvailableMigrations(migrations_available&); @@ -101,8 +98,6 @@ private: sal_Int32 findPreferedMigrationProcess(const migrations_available&); install_info findInstallation(const strings_v& rVersions); strings_vr compileFileList(); - strings_vr compileConfigList(); - strings_vr compileServiceList(); // helpers void substract(strings_v& va, const strings_v& vb_c) const; |