aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-02-14 11:34:31 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-02-14 11:34:31 +0000
commit44a93ae99625de2d05067b590e1a06cc527106d6 (patch)
tree798aefd4d16a7a3c9dc8d4704d375ba980e91724
parent1051ef659e7a52501103e31fef7e9f4dd7df69de (diff)
downloadpaludis-44a93ae99625de2d05067b590e1a06cc527106d6.tar.gz
paludis-44a93ae99625de2d05067b590e1a06cc527106d6.tar.xz
More file checks. Start using them.
-rw-r--r--paludis/qa/files.m41
-rw-r--r--paludis/qa/message.hh1
-rw-r--r--paludis/qa/metadata_check.cc55
-rw-r--r--paludis/qa/metadata_check.hh46
-rw-r--r--src/qualudis/qualudis.cc273
5 files changed, 298 insertions, 78 deletions
diff --git a/paludis/qa/files.m4 b/paludis/qa/files.m4
index b4b1ad9..061cef5 100644
--- a/paludis/qa/files.m4
+++ b/paludis/qa/files.m4
@@ -16,6 +16,7 @@ add(`file_permissions_check', `hh', `cc', `test', `testscript')
add(`has_ebuilds_check', `hh', `cc', `test', `testscript')
add(`has_misc_files_check', `hh', `cc', `test', `testscript')
add(`message', `hh', `cc', `test')
+add(`metadata_check', `hh', `cc')
add(`package_dir_check', `hh', `cc')
add(`package_name_check', `hh', `cc', `test', `testscript')
add(`qa', `hh', `cc')
diff --git a/paludis/qa/message.hh b/paludis/qa/message.hh
index e5490d6..8047c96 100644
--- a/paludis/qa/message.hh
+++ b/paludis/qa/message.hh
@@ -36,6 +36,7 @@ namespace paludis
enum QALevel
{
qal_info,
+ qal_skip,
qal_maybe,
qal_minor,
qal_major,
diff --git a/paludis/qa/metadata_check.cc b/paludis/qa/metadata_check.cc
new file mode 100644
index 0000000..fdfe515
--- /dev/null
+++ b/paludis/qa/metadata_check.cc
@@ -0,0 +1,55 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "metadata_check.hh"
+#include <paludis/pstream.hh>
+
+using namespace paludis;
+using namespace paludis::qa;
+
+MetadataCheck::MetadataCheck()
+{
+}
+
+CheckResult
+MetadataCheck::operator() (const FSEntry & f) const
+{
+ CheckResult result(f, identifier());
+
+ if (f.basename() != "metadata.xml")
+ result << Message(qal_skip, "Not a metadata.xml file");
+ else if (! f.is_regular_file())
+ result << Message(qal_major, "Not a regular file");
+ else
+ {
+ PStream xmllint("xmllint --noout --valid '" + stringify(f) + "'");
+ if (0 != xmllint.exit_status())
+ result << Message(qal_major, "XML validation failed");
+ }
+
+ return result;
+}
+
+const std::string &
+MetadataCheck::identifier()
+{
+ static const std::string id("metadata");
+ return id;
+}
+
diff --git a/paludis/qa/metadata_check.hh b/paludis/qa/metadata_check.hh
new file mode 100644
index 0000000..b1dd447
--- /dev/null
+++ b/paludis/qa/metadata_check.hh
@@ -0,0 +1,46 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_QA_METADATA_CHECK_HH
+#define PALUDIS_GUARD_PALUDIS_QA_METADATA_CHECK_HH 1
+
+#include <paludis/qa/file_check.hh>
+#include <string>
+
+namespace paludis
+{
+ namespace qa
+ {
+ class MetadataCheck :
+ public FileCheck
+ {
+ public:
+ MetadataCheck();
+
+ CheckResult operator() (const FSEntry &) const;
+
+ static const std::string & identifier();
+ };
+
+ static const FileCheckMaker::RegisterMaker register_metadata_check(
+ MetadataCheck::identifier(), &make_file_check<MetadataCheck>);
+ }
+}
+
+#endif
diff --git a/src/qualudis/qualudis.cc b/src/qualudis/qualudis.cc
index 9018321..2c2e6a0 100644
--- a/src/qualudis/qualudis.cc
+++ b/src/qualudis/qualudis.cc
@@ -33,112 +33,229 @@ using std::cout;
using std::cerr;
using std::endl;
-struct DoHelp
+namespace
{
- const std::string message;
-
- DoHelp(const std::string & m = "") :
- message(m)
+ struct DoHelp
{
- }
-};
+ const std::string message;
-struct DoVersion
-{
-};
+ DoHelp(const std::string & m = "") :
+ message(m)
+ {
+ }
+ };
-void
-display_no_errors(const qa::CheckResult & r)
-{
- if (QualudisCommandLine::get_instance()->a_verbose.specified())
- cout << r.item() << ": " << r.rule() << ":" << endl;
-}
+ struct DoVersion
+ {
+ };
-void
-display_errors(const qa::CheckResult & r)
-{
- cout << r.item() << ": " << r.rule() << ":" << endl;
+ void
+ display_header(const qa::CheckResult & r)
+ {
+ cout << r.item() << ": " << r.rule() << ":" << endl;
+ }
- for (qa::CheckResult::Iterator i(r.begin()), i_end(r.end()) ; i != i_end ; ++i)
+ void
+ display_header_once(bool * const once, const qa::CheckResult & r)
{
- do
+ if (! *once)
{
- switch (i->get<qa::mk_level>())
- {
- case qa::qal_info:
- cout << " info: ";
- continue;
-
- case qa::qal_minor:
- cout << " minor: ";
- continue;
+ display_header(r);
+ *once = true;
+ }
+ }
- case qa::qal_major:
- cout << " major: ";
- continue;
+ void
+ display_no_errors(const qa::CheckResult & r)
+ {
+ if (QualudisCommandLine::get_instance()->a_verbose.specified())
+ display_header(r);
+ }
- case qa::qal_fatal:
- cout << " fatal: ";
- continue;
+ void
+ display_errors(const qa::CheckResult & r)
+ {
+ bool done_out(false);
- case qa::qal_maybe:
- cout << " maybe: ";
- continue;
+ for (qa::CheckResult::Iterator i(r.begin()), i_end(r.end()) ; i != i_end ; ++i)
+ {
+ bool show(true);
+ do
+ {
+ switch (i->get<qa::mk_level>())
+ {
+ case qa::qal_info:
+ display_header_once(&done_out, r);
+ cout << " info: ";
+ continue;
+
+ case qa::qal_skip:
+ if (QualudisCommandLine::get_instance()->a_verbose.specified())
+ {
+ display_header_once(&done_out, r);
+ cout << " skip: ";
+ }
+ else
+ show = false;
+ continue;
+
+ case qa::qal_minor:
+ display_header_once(&done_out, r);
+ cout << " minor: ";
+ continue;
+
+ case qa::qal_major:
+ display_header_once(&done_out, r);
+ cout << " major: ";
+ continue;
+
+ case qa::qal_fatal:
+ display_header_once(&done_out, r);
+ cout << " fatal: ";
+ continue;
+
+ case qa::qal_maybe:
+ display_header_once(&done_out, r);
+ cout << " maybe: ";
+ continue;
+ }
+
+ throw InternalError(PALUDIS_HERE, "Bad mk_level");
}
+ while (false);
- throw InternalError(PALUDIS_HERE, "Bad mk_level");
+ if (show)
+ cout << i->get<qa::mk_msg>() << endl;
}
- while (false);
-
- cout << i->get<qa::mk_msg>() << endl;
}
-}
-
-bool
-do_check()
-{
- bool ok(true);
- FSEntry cwd(FSEntry::cwd());
- std::list<std::string> package_dir_checks;
- qa::PackageDirCheckMaker::get_instance()->copy_keys(std::back_inserter(package_dir_checks));
- for (std::list<std::string>::const_iterator i(package_dir_checks.begin()),
- i_end(package_dir_checks.end()) ; i != i_end ; ++i)
+ bool
+ do_check()
{
- qa::CheckResult r((*qa::PackageDirCheckMaker::get_instance()->find_maker(*i)())(cwd));
+ bool ok(true);
+ FSEntry cwd(FSEntry::cwd());
- if (r.empty())
+ std::list<std::string> package_dir_checks;
+ qa::PackageDirCheckMaker::get_instance()->copy_keys(std::back_inserter(package_dir_checks));
+ for (std::list<std::string>::const_iterator i(package_dir_checks.begin()),
+ i_end(package_dir_checks.end()) ; i != i_end ; ++i)
{
- display_no_errors(r);
- continue;
- }
+ try
+ {
+ qa::CheckResult r((*qa::PackageDirCheckMaker::get_instance()->find_maker(*i)())(cwd));
- display_errors(r);
+ if (r.empty())
+ {
+ display_no_errors(r);
+ continue;
+ }
+
+ display_errors(r);
+
+ do
+ {
+ switch (r.most_severe_level())
+ {
+ case qa::qal_info:
+ case qa::qal_skip:
+ case qa::qal_maybe:
+ continue;
+
+ case qa::qal_minor:
+ case qa::qal_major:
+ ok = false;
+ continue;
+
+ case qa::qal_fatal:
+ ok = false;
+ return ok;
+ }
+ throw InternalError(PALUDIS_HERE, "Bad most_severe_level");
+ } while (0);
+ }
+ catch (const InternalError &)
+ {
+ throw;
+ }
+ catch (const Exception & e)
+ {
+ std::cout << "Eek! Caught Exception '" << e.message() << "' (" << e.what()
+ << ") when doing check '" << *i << "'" << endl;
+ ok = false;
+ }
+ catch (const std::exception & e)
+ {
+ std::cout << "Eek! Caught std::exception '" << e.what()
+ << "' when doing check '" << *i << "'" << endl;
+ ok = false;
+ }
+ }
- do
+ std::list<std::string> file_checks;
+ qa::FileCheckMaker::get_instance()->copy_keys(std::back_inserter(file_checks));
+ std::list<FSEntry> files((DirIterator(cwd)), DirIterator());
+ for (std::list<FSEntry>::iterator f(files.begin()) ; f != files.end() ; ++f)
{
- switch (r.most_severe_level())
+ for (std::list<std::string>::const_iterator i(file_checks.begin()),
+ i_end(file_checks.end()) ; i != i_end ; ++i)
{
- case qa::qal_info:
- case qa::qal_maybe:
- continue;
-
- case qa::qal_minor:
- case qa::qal_major:
+ try
+ {
+ qa::CheckResult r((*qa::FileCheckMaker::get_instance()->find_maker(*i)())(*f));
+
+ if (r.empty())
+ {
+ display_no_errors(r);
+ continue;
+ }
+
+ display_errors(r);
+
+ do
+ {
+ switch (r.most_severe_level())
+ {
+ case qa::qal_info:
+ case qa::qal_skip:
+ case qa::qal_maybe:
+ continue;
+
+ case qa::qal_minor:
+ case qa::qal_major:
+ ok = false;
+ continue;
+
+ case qa::qal_fatal:
+ ok = false;
+ return ok;
+ }
+ throw InternalError(PALUDIS_HERE, "Bad most_severe_level");
+ } while (0);
+ }
+ catch (const InternalError &)
+ {
+ throw;
+ }
+ catch (const Exception & e)
+ {
+ std::cout << "Eek! Caught Exception '" << e.message() << "' (" << e.what()
+ << ") when doing check '" << *i << "'" << endl;
ok = false;
- continue;
-
- case qa::qal_fatal:
+ }
+ catch (const std::exception & e)
+ {
+ std::cout << "Eek! Caught std::exception '" << e.what()
+ << "' when doing check '" << *i << "'" << endl;
ok = false;
- return ok;
+ }
+
+ if (f->is_directory())
+ files.insert(files.end(), DirIterator(*f), DirIterator());
}
- throw InternalError(PALUDIS_HERE, "Bad most_severe_level");
- } while (0);
+ }
- ok = false;
+ return ok;
}
-
- return ok;
}
int main(int argc, char *argv[])