diff options
author | kh1 <karsten.heimrich@nokia.com> | 2012-03-13 17:53:03 +0100 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@nokia.com> | 2012-03-13 19:49:38 +0100 |
commit | aea0e0669ac2778680c0966651bdc8d010d40067 (patch) | |
tree | cf1340f80cf84d828447656bd061dad9218f6c99 | |
parent | 06100e103459d0149c8c3c37e524715e7e7fbdd5 (diff) |
Move the common stuff into a different namespace.
Since the tools share repositorygen, use a namespace for tools.
Change-Id: If4ce5baa1fbfdf00a16f257812386229bccbf2ee
Reviewed-by: Tim Jenssen <tim.jenssen@nokia.com>
-rw-r--r-- | installerbuilder/archivegen/archive.cpp | 2 | ||||
-rw-r--r-- | installerbuilder/binarycreator/binarycreator.cpp | 24 | ||||
-rw-r--r-- | installerbuilder/common/repositorygen.cpp | 87 | ||||
-rw-r--r-- | installerbuilder/common/repositorygen.h | 4 | ||||
-rw-r--r-- | installerbuilder/repogen/repogen.cpp | 25 |
5 files changed, 74 insertions, 68 deletions
diff --git a/installerbuilder/archivegen/archive.cpp b/installerbuilder/archivegen/archive.cpp index 9355646a0..2d1257ae7 100644 --- a/installerbuilder/archivegen/archive.cpp +++ b/installerbuilder/archivegen/archive.cpp @@ -64,7 +64,7 @@ int main(int argc, char *argv[]) QInstaller::init(); QInstaller::setVerbose(true); const QStringList sourceDirectories = app.arguments().mid(2); - QInstaller::compressDirectory(sourceDirectories, app.arguments().at(1)); + QInstallerTools::compressDirectory(sourceDirectories, app.arguments().at(1)); return EXIT_SUCCESS; } catch (const Lib7z::SevenZipException &e) { std::cerr << e.message() << std::endl; diff --git a/installerbuilder/binarycreator/binarycreator.cpp b/installerbuilder/binarycreator/binarycreator.cpp index 322e372be..0a469b5cf 100644 --- a/installerbuilder/binarycreator/binarycreator.cpp +++ b/installerbuilder/binarycreator/binarycreator.cpp @@ -395,7 +395,7 @@ static void printUsage() std::cout << " If this parameter is not given, the template used" << std::endl; std::cout << " defaults to installerbase." << std::endl; - printRepositoryGenOptions(); + QInstallerTools::printRepositoryGenOptions(); std::cout << " -n|--nodeps Don't add dependencies of package1...n into the " << std::endl; std::cout << " installer (for online installers)" << std::endl; @@ -421,8 +421,8 @@ static void printUsage() std::cout << std::endl; } -static QString createMetaDataDirectory(const PackageInfoVector &packages, const QString &packagesDir, - const QString &configdir) +static QString createMetaDataDirectory(const QInstallerTools::PackageInfoVector &packages, + const QString &packagesDir, const QString &configdir) { const QString configfile = QFileInfo(configdir, "config.xml").absoluteFilePath(); const QInstaller::Settings &settings = QInstaller::Settings::fromFileAndPrefix(configfile, QString()); @@ -539,7 +539,7 @@ int main(int argc, char **argv) QStringList resources; QStringList components; QStringList filteredPackages; - FilterType ftype = Exclude; + QInstallerTools::FilterType ftype = QInstallerTools::Exclude; const QStringList args = app.arguments().mid(1); for (QStringList::const_iterator it = args.begin(); it != args.end(); ++it) { @@ -572,7 +572,7 @@ int main(int argc, char **argv) if (it == args.end() || it->startsWith(QLatin1String("-"))) return printErrorAndUsageAndExit(QObject::tr("Error: Package to include missing.")); filteredPackages = it->split(QLatin1Char(',')); - ftype = Include; + ftype = QInstallerTools::Include; } else if (*it == QLatin1String("-v") || *it == QLatin1String("--verbose")) { QInstaller::setVerbose(true); @@ -616,8 +616,9 @@ int main(int argc, char **argv) if (it == args.end() || it->startsWith(QLatin1String("-"))) return printErrorAndUsageAndExit(QObject::tr("Error: Resource files to include missing.")); resources = it->split(QLatin1Char(',')); - } else if (*it == QLatin1String("--ignore-translations") || *it == QLatin1String("--ignore-invalid-packages")) { - continue; + } else if (*it == QLatin1String("--ignore-translations") + || *it == QLatin1String("--ignore-invalid-packages")) { + continue; } else { if (target.isEmpty()) target = *it; @@ -631,7 +632,7 @@ int main(int argc, char **argv) " - please use --include or --exclude" << std::endl; if (nodeps) { filteredPackages.append(components); - ftype = Include; + ftype = QInstallerTools::Include; } } @@ -644,7 +645,8 @@ int main(int argc, char **argv) qDebug() << "Parsed arguments, ok."; try { - PackageInfoVector packages = createListOfPackages(packagesDirectory, filteredPackages, ftype); + QInstallerTools::PackageInfoVector packages = createListOfPackages(packagesDirectory, + filteredPackages, ftype); const QString metaDir = createMetaDataDirectory(packages, packagesDirectory, configDir); { QSettings confInternal(metaDir + "/config/config-internal.ini", QSettings::IniFormat); @@ -669,10 +671,10 @@ int main(int argc, char **argv) input.binaryResourcePath = createBinaryResourceFile(metaDir); input.binaryResources = createBinaryResourceFiles(resources); - QInstaller::copyComponentData(packagesDirectory, metaDir, packages); + QInstallerTools::copyComponentData(packagesDirectory, metaDir, packages); // now put the packages into the components section of the binary - foreach (const PackageInfo &info, packages) { + foreach (const QInstallerTools::PackageInfo &info, packages) { Component comp; comp.setName(info.name.toUtf8()); diff --git a/installerbuilder/common/repositorygen.cpp b/installerbuilder/common/repositorygen.cpp index f5465cc47..e3ee55169 100644 --- a/installerbuilder/common/repositorygen.cpp +++ b/installerbuilder/common/repositorygen.cpp @@ -45,9 +45,14 @@ #include <iostream> -using namespace QInstaller; +namespace QInstallerTools { -void QInstaller::printRepositoryGenOptions() +static bool operator==(const PackageInfo &lhs, const PackageInfo &rhs) +{ + return lhs.name == rhs.name && lhs.version == rhs.version; +} + +void QInstallerTools::printRepositoryGenOptions() { std::cout << " -c|--config dir The directory containing the installer configuration" << std::endl; @@ -61,13 +66,6 @@ void QInstaller::printRepositoryGenOptions() std::cout << " --ignore-invalid-packages Ignore all invalid packages instead of aborting." << std::endl; } -QT_BEGIN_NAMESPACE -static bool operator==(const PackageInfo &lhs, const PackageInfo &rhs) -{ - return lhs.name == rhs.name && lhs.version == rhs.version; -} -QT_END_NAMESPACE - /*! Returns PackageInfo of package with right name and version */ @@ -100,7 +98,7 @@ static PackageInfo findMatchingPackage(const QString &name, const PackageInfoVec return PackageInfo(); } -void QInstaller::compressDirectory(const QStringList &paths, const QString &archivePath) +void QInstallerTools::compressDirectory(const QStringList &paths, const QString &archivePath) { foreach (const QString &path, paths) { if (!QFileInfo(path).exists()) @@ -108,11 +106,11 @@ void QInstaller::compressDirectory(const QStringList &paths, const QString &arch } QFile archive(archivePath); - openForWrite(&archive, archivePath); + QInstaller::openForWrite(&archive, archivePath); Lib7z::createArchive(&archive, paths); } -void QInstaller::compressMetaDirectories(const QString &repoDir) +void QInstallerTools::compressMetaDirectories(const QString &repoDir) { QDir dir(repoDir); const QStringList sub = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot); @@ -132,7 +130,7 @@ void QInstaller::compressMetaDirectories(const QString &repoDir) } } -void QInstaller::generateMetaDataDirectory(const QString &outDir, const QString &dataDir, +void QInstallerTools::generateMetaDataDirectory(const QString &outDir, const QString &dataDir, const PackageInfoVector &packages, const QString &appName, const QString &appVersion, const QString &redirectUpdateUrl) { @@ -183,13 +181,13 @@ void QInstaller::generateMetaDataDirectory(const QString &outDir, const QString QDomDocument packageXml; QFile file(packageXmlPath); - openForRead(&file, packageXmlPath); + QInstaller::openForRead(&file, packageXmlPath); QString errMsg; int col = 0; int line = 0; if (!packageXml.setContent(&file, &errMsg, &line, &col)) { - throw Error(QObject::tr("Could not parse %1: line: %2, column: %3: %4 (%5)").arg(packageXmlPath, - QString::number(line), QString::number(col), errMsg, it->name)); + throw QInstaller::Error(QObject::tr("Could not parse %1: line: %2, column: %3: %4 (%5)") + .arg(packageXmlPath, QString::number(line), QString::number(col), errMsg, it->name)); } const QDomNode package = packageXml.firstChildElement("Package"); @@ -272,7 +270,7 @@ void QInstaller::generateMetaDataDirectory(const QString &outDir, const QString root.appendChild(update); if (!QDir(metapath).mkpath(it->name)) - throw Error(QObject::tr("Could not create directory %1.").arg(it->name)); + throw QInstaller::Error(QObject::tr("Could not create directory %1.").arg(it->name)); // copy scripts const QString script = package.firstChildElement("Script").text(); @@ -296,7 +294,7 @@ void QInstaller::generateMetaDataDirectory(const QString &outDir, const QString QString toLocation(QString::fromLatin1("%1/%2/%3").arg(metapath, it->name, script)); if (!QFile::copy(fromLocation, toLocation)) { qDebug() << "failed!"; - throw Error(QObject::tr("Could not copy the script %1 to its target location %2.") + throw QInstaller::Error(QObject::tr("Could not copy the script %1 to its target location %2.") .arg(fromLocation, toLocation)); } else { qDebug() << "\tdone."; @@ -314,8 +312,8 @@ void QInstaller::generateMetaDataDirectory(const QString &outDir, const QString const QDir dir(QString::fromLatin1("%1/meta").arg(it->directory)); const QStringList uis = dir.entryList(QStringList(node.toElement().text()), QDir::Files); if (uis.isEmpty()) { - throw Error(QObject::tr("Couldn't find any user interface matching %1 while copying " - "user interfaces of %2.").arg(node.toElement().text(), it->name)); + throw QInstaller::Error(QObject::tr("Couldn't find any user interface matching %1 while " + "copying user interfaces of %2.").arg(node.toElement().text(), it->name)); } for (QStringList::const_iterator ui = uis.begin(); ui != uis.end(); ++ui) { @@ -325,8 +323,8 @@ void QInstaller::generateMetaDataDirectory(const QString &outDir, const QString if (!QFile::copy(QString::fromLatin1("%1/meta/%2").arg(it->directory, *ui), QString::fromLatin1("%1/%2/%3").arg(metapath, it->name, *ui))) { qDebug() << "failed!"; - throw Error(QObject::tr("Could not copy the UI file %1 to its target location " - "%2.").arg(*ui, it->name)); + throw QInstaller::Error(QObject::tr("Could not copy the UI file %1 to its target " + "location %2.").arg(*ui, it->name)); } else { qDebug() << "done"; } @@ -350,8 +348,8 @@ void QInstaller::generateMetaDataDirectory(const QString &outDir, const QString const QDir dir(QString::fromLatin1("%1/meta").arg(it->directory)); const QStringList qms = dir.entryList(QStringList(node.toElement().text()), QDir::Files); if (qms.isEmpty()) { - throw Error(QObject::tr("Could not find any translation file matching %1 while " - "copying translations of %2.").arg(node.toElement().text(), it->name)); + throw QInstaller::Error(QObject::tr("Could not find any translation file matching %1 " + "while copying translations of %2.").arg(node.toElement().text(), it->name)); } for (QStringList::const_iterator qm = qms.begin(); qm != qms.end(); ++qm) { @@ -361,8 +359,8 @@ void QInstaller::generateMetaDataDirectory(const QString &outDir, const QString if (!QFile::copy(QString::fromLatin1("%1/meta/%2").arg(it->directory, *qm), QString::fromLatin1("%1/%2/%3").arg(metapath, it->name, *qm))) { qDebug() << "failed!"; - throw Error(QObject::tr("Could not copy the translation %1 to its target " - "location %2.").arg(*qm, it->name)); + throw QInstaller::Error(QObject::tr("Could not copy the translation %1 to its " + "target location %2.").arg(*qm, it->name)); } else { qDebug() << "done"; } @@ -386,7 +384,7 @@ void QInstaller::generateMetaDataDirectory(const QString &outDir, const QString const QString &sourceFile = QString::fromLatin1("%1/meta/%2").arg(it->directory).arg(licenseFile); if (!QFile::exists(sourceFile)) { - throw Error(QObject::tr("Could not find any license matching %1 while " + throw QInstaller::Error(QObject::tr("Could not find any license matching %1 while " "copying license files of %2.").arg(licenseFile, it->name)); } @@ -395,7 +393,7 @@ void QInstaller::generateMetaDataDirectory(const QString &outDir, const QString if (!QFile::copy(sourceFile, QString::fromLatin1("%1/%2/%3") .arg(metapath, it->name, licenseFile))) { qDebug() << "failed!"; - throw Error(QObject::tr("Could not copy the license file %1 to its " + throw QInstaller::Error(QObject::tr("Could not copy the license file %1 to its " "target location %2.").arg(licenseFile, it->name)); } else { qDebug() << "done."; @@ -437,11 +435,11 @@ void QInstaller::generateMetaDataDirectory(const QString &outDir, const QString const QString updatesXmlFile = QFileInfo(metapath, "Updates.xml").absoluteFilePath(); QFile updatesXml(updatesXmlFile); - openForWrite(&updatesXml, updatesXmlFile); - blockingWrite(&updatesXml, doc.toByteArray()); + QInstaller::openForWrite(&updatesXml, updatesXmlFile); + QInstaller::blockingWrite(&updatesXml, doc.toByteArray()); } -PackageInfoVector QInstaller::createListOfPackages(const QString &packagesDirectory, +PackageInfoVector QInstallerTools::createListOfPackages(const QString &packagesDirectory, const QStringList &filteredPackages, FilterType filterType) { qDebug() << "Collecting information about available packages..."; @@ -465,8 +463,8 @@ PackageInfoVector QInstaller::createListOfPackages(const QString &packagesDirect if (ignoreInvalidPackages) continue; throw QInstaller::Error(QObject::tr("Component %1 can't contain '-'. This is not allowed, because " - "it is used as the separator between the component name and the version number internally.").arg( - it->fileName())); + "it is used as the separator between the component name and the version number internally.") + .arg(it->fileName())); } QFile file(QString::fromLatin1("%1/meta/package.xml").arg(it->filePath())); @@ -525,7 +523,7 @@ PackageInfoVector QInstaller::createListOfPackages(const QString &packagesDirect return dict; } -QMap<QString, QString> QInstaller::buildPathToVersionMap(const PackageInfoVector &info) +QMap<QString, QString> QInstallerTools::buildPathToVersionMap(const PackageInfoVector &info) { QMap<QString, QString> map; foreach (const PackageInfo &inf, info) @@ -548,7 +546,7 @@ static void writeSHA1ToNodeWithName(QDomDocument &doc, QDomNodeList &list, const } } -void QInstaller::compressMetaDirectories(const QString &repoDir, const QString &baseDir, +void QInstallerTools::compressMetaDirectories(const QString &repoDir, const QString &baseDir, const QMap<QString, QString> &versionMapping) { QDomDocument doc; @@ -590,12 +588,13 @@ void QInstaller::compressMetaDirectories(const QString &repoDir, const QString & throw QInstaller::Error(QObject::tr("Could not move %1 to %2").arg(tmpTarget, finalTarget)); } - openForWrite(&existingUpdatesXml, existingUpdatesXml.fileName()); - blockingWrite(&existingUpdatesXml, doc.toByteArray()); + QInstaller::openForWrite(&existingUpdatesXml, existingUpdatesXml.fileName()); + QInstaller::blockingWrite(&existingUpdatesXml, doc.toByteArray()); existingUpdatesXml.close(); } -void QInstaller::copyComponentData(const QString &packageDir, const QString &repoDir, PackageInfoVector &infos) +void QInstallerTools::copyComponentData(const QString &packageDir, const QString &repoDir, + PackageInfoVector &infos) { for (int i = 0; i < infos.count(); ++i) { const PackageInfo info = infos.at(i); @@ -616,7 +615,7 @@ void QInstaller::copyComponentData(const QString &packageDir, const QString &rep target = QString::fromLatin1("%1/%2/%4%3").arg(repoDir, name, entry, info.version); QFile tmp(dataDir.absoluteFilePath(entry)); qDebug() << QString::fromLatin1("Copying archive from %1 to %2").arg(tmp.fileName(), target); - openForRead(&tmp, tmp.fileName()); + QInstaller::openForRead(&tmp, tmp.fileName()); if (!tmp.copy(target)) { throw QInstaller::Error(QObject::tr("Could not copy %1 to %2: %3").arg(tmp.fileName(), target, tmp.errorString())); @@ -624,7 +623,7 @@ void QInstaller::copyComponentData(const QString &packageDir, const QString &rep } else if (fileInfo.isDir()) { qDebug() << "Compressing data directory" << entry; target = QString::fromLatin1("%1/%2/%4%3.7z").arg(repoDir, name, entry, info.version); - QInstaller::compressDirectory(QStringList() << dataDir.absoluteFilePath(entry), target); + QInstallerTools::compressDirectory(QStringList() << dataDir.absoluteFilePath(entry), target); } else { continue; } @@ -637,18 +636,18 @@ void QInstaller::copyComponentData(const QString &packageDir, const QString &rep qDebug() << "Creating hash of archive" << archiveFile.fileName(); try { - openForRead(&archiveFile, archiveFile.fileName()); + QInstaller::openForRead(&archiveFile, archiveFile.fileName()); const QByteArray archiveData = archiveFile.readAll(); archiveFile.close(); - openForWrite(&archiveHashFile, archiveHashFile.fileName()); + QInstaller::openForWrite(&archiveHashFile, archiveHashFile.fileName()); const QByteArray hashOfArchiveData = QCryptographicHash::hash(archiveData, QCryptographicHash::Sha1).toHex(); archiveHashFile.write(hashOfArchiveData); qDebug() << "Generated sha1 hash:" << hashOfArchiveData; infos[i].copiedArchives.append(archiveHashFile.fileName()); archiveHashFile.close(); - } catch (const Error &/*e*/) { + } catch (const QInstaller::Error &/*e*/) { archiveFile.close(); archiveHashFile.close(); throw; @@ -656,3 +655,5 @@ void QInstaller::copyComponentData(const QString &packageDir, const QString &rep } } } + +} // namespace QInstallerTools diff --git a/installerbuilder/common/repositorygen.h b/installerbuilder/common/repositorygen.h index 1fa28df95..faa7a8083 100644 --- a/installerbuilder/common/repositorygen.h +++ b/installerbuilder/common/repositorygen.h @@ -37,7 +37,7 @@ #include <QtCore/QStringList> #include <QtCore/QVector> -namespace QInstaller { +namespace QInstallerTools { void printRepositoryGenOptions(); @@ -72,6 +72,6 @@ void generateMetaDataDirectory(const QString &outDir, const QString &dataDir, PackageInfoVector createListOfPackages(const QString &packagesDirectory, const QStringList &filteredPackages, FilterType ftype); -} // namespace QInstaller +} // namespace QInstallerTools #endif // QINSTALLER_REPOSITORYGEN_H diff --git a/installerbuilder/repogen/repogen.cpp b/installerbuilder/repogen/repogen.cpp index 3101c658e..48609f9da 100644 --- a/installerbuilder/repogen/repogen.cpp +++ b/installerbuilder/repogen/repogen.cpp @@ -53,12 +53,13 @@ static void printUsage() std::cout << std::endl; std::cout << "Options:" << std::endl; - printRepositoryGenOptions(); + QInstallerTools::printRepositoryGenOptions(); std::cout << " -u|--updateurl url instructs clients to receive updates from a " << std::endl; std::cout << " different location" << std::endl; - std::cout << " --update Update a set of existing components (defined by --include " << std::endl; + std::cout << " --update Update a set of existing components (defined by --include " + << std::endl; std::cout << " or --exclude) in the repository" << std::endl; std::cout << " -v|--verbose Verbose output" << std::endl; @@ -98,7 +99,7 @@ int main(int argc, char** argv) QString packagesDir; QString configDir; QString redirectUpdateUrl; - FilterType filterType = Exclude; + QInstallerTools::FilterType filterType = QInstallerTools::Exclude; //TODO: use a for loop without removing values from args like it is in binarycreator.cpp //for (QStringList::const_iterator it = args.begin(); it != args.end(); ++it) { @@ -124,7 +125,7 @@ int main(int argc, char** argv) return printErrorAndUsageAndExit(QObject::tr("Error: Package to include missing")); filteredPackages = args.first().split(QLatin1Char(',')); args.removeFirst(); - filterType = Include; + filterType = QInstallerTools::Include; } else if (args.first() == QLatin1String("--single") || args.first() == QLatin1String("--update")) { args.removeFirst(); updateExistingRepository = true; @@ -165,8 +166,9 @@ int main(int argc, char** argv) return printErrorAndUsageAndExit(QObject::tr("Error: Config parameter missing argument")); redirectUpdateUrl = args.first(); args.removeFirst(); - } else if (args.first() == QLatin1String("--ignore-translations") || args.first() == QLatin1String("--ignore-invalid-packages")) { - args.removeFirst(); + } else if (args.first() == QLatin1String("--ignore-translations") + || args.first() == QLatin1String("--ignore-invalid-packages")) { + args.removeFirst(); } else { printUsage(); return 1; @@ -210,7 +212,7 @@ int main(int argc, char** argv) " - please use --include or --exclude" << std::endl; if (updateExistingRepository) { filteredPackages.append(components); - filterType = Include; + filterType = QInstallerTools::Include; } } @@ -219,11 +221,12 @@ int main(int argc, char** argv) .arg(repositoryDir)); } - PackageInfoVector packages = createListOfPackages(packagesDir, filteredPackages, filterType); + QInstallerTools::PackageInfoVector packages = QInstallerTools::createListOfPackages(packagesDir, + filteredPackages, filterType); QMap<QString, QString> pathToVersionMapping = buildPathToVersionMap(packages); - for (PackageInfoVector::const_iterator it = packages.begin(); it != packages.end(); ++it) { - const QFileInfo fi(repositoryDir, it->name); + foreach (const QInstallerTools::PackageInfo &package, packages) { + const QFileInfo fi(repositoryDir, package.name); if (fi.exists()) removeDirectory(fi.absoluteFilePath()); } @@ -238,7 +241,7 @@ int main(int argc, char** argv) configDir); generateMetaDataDirectory(metaTmp, repositoryDir, packages, settings.applicationName(), settings.applicationVersion(), redirectUpdateUrl); - compressMetaDirectories(metaTmp, metaTmp, pathToVersionMapping); + QInstallerTools::compressMetaDirectories(metaTmp, metaTmp, pathToVersionMapping); QFile::remove(QFileInfo(repositoryDir, QLatin1String("Updates.xml")).absoluteFilePath()); moveDirectoryContents(metaTmp, repositoryDir); |