aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-10-05 12:55:28 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-10-05 12:55:28 +0000
commitd8f0a3541b7db652c2ab52ad58175f11898d30c4 (patch)
tree872a05c0ff40293d1a880c6c9164461ddef4e69c
parente356fc524ef45615bd9399b05edb3207f147cbad (diff)
downloadpaludis-d8f0a3541b7db652c2ab52ad58175f11898d30c4.tar.gz
paludis-d8f0a3541b7db652c2ab52ad58175f11898d30c4.tar.xz
Include maintainer information in qualudis output
-rw-r--r--paludis/qa/files.m42
-rw-r--r--paludis/qa/libxml_utils.hh59
-rw-r--r--paludis/qa/metadata_check.cc33
-rw-r--r--paludis/qa/metadata_file.cc143
-rw-r--r--paludis/qa/metadata_file.hh51
-rw-r--r--paludis/qa/metadata_file_TEST.cc72
-rw-r--r--src/qualudis/qualudis.cc41
7 files changed, 362 insertions, 39 deletions
diff --git a/paludis/qa/files.m4 b/paludis/qa/files.m4
index 2af2e7c..0e80675 100644
--- a/paludis/qa/files.m4
+++ b/paludis/qa/files.m4
@@ -36,9 +36,11 @@ add(`homepage_check', `hh', `cc')
add(`inherits_check', `hh', `cc')
add(`iuse_check', `hh', `cc')
add(`keywords_check', `hh', `cc')
+add(`libxml_utils', `hh')
add(`license_check', `hh', `cc')
add(`message', `hh', `cc', `sr', `test')
add(`metadata_check', `hh', `cc')
+add(`metadata_file', `hh', `cc', `test')
add(`package_dir_check', `hh', `cc')
add(`package_name_check', `hh', `cc', `test', `testscript')
add(`parse_deps_check', `hh', `cc')
diff --git a/paludis/qa/libxml_utils.hh b/paludis/qa/libxml_utils.hh
new file mode 100644
index 0000000..dbe2896
--- /dev/null
+++ b/paludis/qa/libxml_utils.hh
@@ -0,0 +1,59 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.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_LIBXML_UTILS_HH
+#define PALUDIS_GUARD_PALUDIS_QA_LIBXML_UTILS_HH 1
+
+namespace paludis
+{
+ namespace qa
+ {
+ template <typename PtrType_>
+ class LibXmlPtrHolder
+ {
+ private:
+ PtrType_ _ptr;
+ void (* _free_func) (PtrType_);
+
+ LibXmlPtrHolder(const LibXmlPtrHolder &);
+ void operator= (const LibXmlPtrHolder &);
+
+ public:
+ LibXmlPtrHolder(PtrType_ ptr, void (* free_func) (PtrType_)) :
+ _ptr(ptr),
+ _free_func(free_func)
+ {
+ }
+
+ ~LibXmlPtrHolder()
+ {
+ if (0 != _ptr)
+ _free_func(_ptr);
+ }
+
+ operator PtrType_ () const
+ {
+ return _ptr;
+ }
+ };
+ }
+}
+
+
+#endif
diff --git a/paludis/qa/metadata_check.cc b/paludis/qa/metadata_check.cc
index e53d00b..edc3613 100644
--- a/paludis/qa/metadata_check.cc
+++ b/paludis/qa/metadata_check.cc
@@ -20,6 +20,7 @@
#include <ctime>
#include <fstream>
#include <paludis/qa/metadata_check.hh>
+#include <paludis/qa/libxml_utils.hh>
#include <paludis/util/pstream.hh>
#include <paludis/util/system.hh>
#include <paludis/util/log.hh>
@@ -34,38 +35,6 @@
using namespace paludis;
using namespace paludis::qa;
-namespace
-{
- template <typename PtrType_>
- class LibXmlPtrHolder
- {
- private:
- PtrType_ _ptr;
- void (* _free_func) (PtrType_);
-
- LibXmlPtrHolder(const LibXmlPtrHolder &);
- void operator= (const LibXmlPtrHolder &);
-
- public:
- LibXmlPtrHolder(PtrType_ ptr, void (* free_func) (PtrType_)) :
- _ptr(ptr),
- _free_func(free_func)
- {
- }
-
- ~LibXmlPtrHolder()
- {
- if (0 != _ptr)
- _free_func(_ptr);
- }
-
- operator PtrType_ () const
- {
- return _ptr;
- }
- };
-}
-
MetadataCheck::MetadataCheck()
{
}
diff --git a/paludis/qa/metadata_file.cc b/paludis/qa/metadata_file.cc
new file mode 100644
index 0000000..ec6737f
--- /dev/null
+++ b/paludis/qa/metadata_file.cc
@@ -0,0 +1,143 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.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_file.hh"
+#include <paludis/qa/libxml_utils.hh>
+#include <paludis/util/fs_entry.hh>
+#include <paludis/util/log.hh>
+#include <paludis/util/save.hh>
+#include <paludis/util/join.hh>
+#include <paludis/util/tokeniser.hh>
+#include <libxml/tree.h>
+#include <libxml/parser.h>
+#include <set>
+#include <list>
+
+using namespace paludis;
+using namespace paludis::qa;
+
+namespace paludis
+{
+ template<>
+ class Implementation<MetadataFile> :
+ public InternalCounted<Implementation<MetadataFile> >
+ {
+ private:
+ std::string _email, _name;
+
+ std::string normalise(const std::string & s)
+ {
+ std::list<std::string> words;
+ WhitespaceTokeniser::get_instance()->tokenise(s, std::back_inserter(words));
+ return join(words.begin(), words.end(), " ");
+ }
+
+ public:
+ std::set<std::string> herds;
+ std::set<std::pair<std::string, std::string> > maintainers;
+
+ void handle_node(xmlDocPtr doc, xmlNode * const node)
+ {
+ for (xmlNode * n(node) ; n ; n = n->next)
+ {
+ if (n->type == XML_ELEMENT_NODE)
+ {
+ std::string name(reinterpret_cast<const char *>(n->name));
+ if (name == "maintainer")
+ {
+ _email.clear();
+ _name.clear();
+ handle_node(doc, n->children);
+ maintainers.insert(std::make_pair(_email, _name));
+ }
+ else if (name == "herd")
+ herds.insert(normalise(reinterpret_cast<const char *>(xmlNodeListGetString(doc,
+ n->xmlChildrenNode, 1))));
+ else if (name == "email")
+ _email = normalise(reinterpret_cast<const char *>(xmlNodeListGetString(
+ doc, n->xmlChildrenNode, 1)));
+ else if (name == "name")
+ _name = normalise(reinterpret_cast<const char *>(xmlNodeListGetString(
+ doc, n->xmlChildrenNode, 1)));
+ else
+ handle_node(doc, n->children);
+ }
+ else
+ handle_node(doc, n->children);
+ }
+ }
+ };
+}
+
+MetadataFile::MetadataFile(const FSEntry & f) :
+ PrivateImplementationPattern<MetadataFile>(new Implementation<MetadataFile>)
+{
+ LibXmlPtrHolder<xmlDocPtr> xml_doc(xmlReadFile(stringify(f).c_str(), 0, 0), &xmlFreeDoc);
+ if (! xml_doc)
+ {
+ Log::get_instance()->message(ll_warning, lc_no_context, "Couldn't parse xml file '" +
+ stringify(f) + "'");
+ return;
+ }
+
+ _imp->handle_node(xml_doc, xmlDocGetRootElement(xml_doc));
+}
+
+MetadataFile::MetadataFile(const std::string & text) :
+ PrivateImplementationPattern<MetadataFile>(new Implementation<MetadataFile>)
+{
+ LibXmlPtrHolder<xmlDocPtr> xml_doc(xmlReadDoc(reinterpret_cast<const xmlChar *>(text.c_str()),
+ "file:///var/empty/", 0, 0), &xmlFreeDoc);
+ if (! xml_doc)
+ {
+ Log::get_instance()->message(ll_warning, lc_no_context, "Couldn't parse xml text");
+ return;
+ }
+
+ _imp->handle_node(xml_doc, xmlDocGetRootElement(xml_doc));
+}
+
+MetadataFile::~MetadataFile()
+{
+}
+
+MetadataFile::HerdsIterator
+MetadataFile::begin_herds() const
+{
+ return HerdsIterator(_imp->herds.begin());
+}
+
+MetadataFile::HerdsIterator
+MetadataFile::end_herds() const
+{
+ return HerdsIterator(_imp->herds.end());
+}
+
+MetadataFile::MaintainersIterator
+MetadataFile::begin_maintainers() const
+{
+ return MaintainersIterator(_imp->maintainers.begin());
+}
+
+MetadataFile::MaintainersIterator
+MetadataFile::end_maintainers() const
+{
+ return MaintainersIterator(_imp->maintainers.end());
+}
+
diff --git a/paludis/qa/metadata_file.hh b/paludis/qa/metadata_file.hh
new file mode 100644
index 0000000..4eed78f
--- /dev/null
+++ b/paludis/qa/metadata_file.hh
@@ -0,0 +1,51 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.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_FILE_HH
+#define PALUDIS_GUARD_PALUDIS_QA_METADATA_FILE_HH 1
+
+#include <paludis/util/private_implementation_pattern.hh>
+#include <libwrapiter/libwrapiter_forward_iterator.hh>
+
+namespace paludis
+{
+ class FSEntry;
+
+ namespace qa
+ {
+ class MetadataFile :
+ public PrivateImplementationPattern<MetadataFile>
+ {
+ public:
+ MetadataFile(const FSEntry & location);
+ MetadataFile(const std::string & text);
+ ~MetadataFile();
+
+ typedef libwrapiter::ForwardIterator<MetadataFile, const std::string> HerdsIterator;
+ HerdsIterator begin_herds() const;
+ HerdsIterator end_herds() const;
+
+ typedef libwrapiter::ForwardIterator<MetadataFile, const std::pair<std::string, std::string> > MaintainersIterator;
+ MaintainersIterator begin_maintainers() const;
+ MaintainersIterator end_maintainers() const;
+ };
+ }
+}
+
+#endif
diff --git a/paludis/qa/metadata_file_TEST.cc b/paludis/qa/metadata_file_TEST.cc
new file mode 100644
index 0000000..11ac1c1
--- /dev/null
+++ b/paludis/qa/metadata_file_TEST.cc
@@ -0,0 +1,72 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.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 <paludis/qa/metadata_file.hh>
+#include <test/test_framework.hh>
+#include <test/test_runner.hh>
+
+using namespace paludis;
+using namespace paludis::qa;
+using namespace test;
+
+namespace test_cases
+{
+ struct MetadataFileTest : TestCase
+ {
+ MetadataFileTest() : TestCase("metadata file") { }
+
+ void run()
+ {
+ MetadataFile f(
+"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+"<!DOCTYPE pkgmetadata SYSTEM \"http://www.gentoo.org/dtd/metadata.dtd\">\n"
+"<pkgmetadata>\n"
+" <herd>vim</herd>\n"
+" <herd> cookie </herd>\n"
+" <maintainer>\n"
+" <email> foo@bar.baz </email>\n"
+" <name> Foo Bar </name>\n"
+" </maintainer>\n"
+" <maintainer>\n"
+" <email>oink@oink</email>\n"
+" </maintainer>\n"
+" <maintainer>\n"
+" <name> Fred the Fish </name>\n"
+" </maintainer>\n"
+" <longdescription lang=\"en\">\n"
+" Some text\n"
+" </longdescription>\n"
+"</pkgmetadata>\n"
+ );
+
+ TEST_CHECK(f.end_herds() != std::find(f.begin_herds(), f.end_herds(), "vim"));
+ TEST_CHECK(f.end_herds() != std::find(f.begin_herds(), f.end_herds(), "cookie"));
+ TEST_CHECK(f.end_herds() == std::find(f.begin_herds(), f.end_herds(), "monster"));
+
+ TEST_CHECK(f.end_maintainers() != std::find(f.begin_maintainers(),
+ f.end_maintainers(), std::make_pair(std::string("foo@bar.baz"), std::string("Foo Bar"))));
+ TEST_CHECK(f.end_maintainers() != std::find(f.begin_maintainers(),
+ f.end_maintainers(), std::make_pair(std::string("oink@oink"), std::string(""))));
+ TEST_CHECK(f.end_maintainers() != std::find(f.begin_maintainers(),
+ f.end_maintainers(), std::make_pair(std::string(""), std::string("Fred the Fish"))));
+ }
+ } test_has_ebuilds_check;
+}
+
+
diff --git a/src/qualudis/qualudis.cc b/src/qualudis/qualudis.cc
index 036c2bc..82f3a2e 100644
--- a/src/qualudis/qualudis.cc
+++ b/src/qualudis/qualudis.cc
@@ -20,7 +20,11 @@
#include <paludis/args/args.hh>
#include <paludis/paludis.hh>
#include <paludis/qa/qa.hh>
-#include <paludis/util/util.hh>
+#include <paludis/util/join.hh>
+#include <paludis/util/dir_iterator.hh>
+#include <paludis/util/log.hh>
+#include <paludis/util/is_file_with_extension.hh>
+#include <paludis/util/strip.hh>
#include <cstdlib>
#include <iostream>
@@ -94,14 +98,14 @@ namespace
{
case qa::qal_info:
display_header_once(&done_out, r);
- cout << " info: ";
+ cout << " info: ";
continue;
case qa::qal_skip:
if (QualudisCommandLine::get_instance()->a_verbose.specified())
{
display_header_once(&done_out, r);
- cout << " skip: ";
+ cout << " skip: ";
}
else
show = false;
@@ -109,22 +113,22 @@ namespace
case qa::qal_minor:
display_header_once(&done_out, r);
- cout << " minor: ";
+ cout << " minor: ";
continue;
case qa::qal_major:
display_header_once(&done_out, r);
- cout << " major: ";
+ cout << " major: ";
continue;
case qa::qal_fatal:
display_header_once(&done_out, r);
- cout << " fatal: ";
+ cout << " fatal: ";
continue;
case qa::qal_maybe:
display_header_once(&done_out, r);
- cout << " maybe: ";
+ cout << " maybe: ";
continue;
}
@@ -270,6 +274,29 @@ namespace
}
}
+ if (! ok && (dir / "metadata.xml").is_regular_file())
+ {
+ cout << "metadata.xml:" << endl;
+ qa::MetadataFile metadata(dir / "metadata.xml");
+ if (metadata.end_herds() != metadata.begin_herds())
+ cout << " herds: " << join(metadata.begin_herds(), metadata.end_herds(), ", ") << endl;
+ if (metadata.end_maintainers() != metadata.begin_maintainers())
+ for (qa::MetadataFile::MaintainersIterator i(metadata.begin_maintainers()),
+ i_end(metadata.end_maintainers()) ; i != i_end ; ++i)
+ {
+ if (i->first.empty() && i->second.empty())
+ continue;
+
+ cout << " maintainer: ";
+ if (i->first.empty())
+ cout << i->second;
+ else if (i->second.empty())
+ cout << "<" << i->first << ">";
+ else
+ cout << i->second << " <" << i->first << ">";
+ cout << endl;
+ }
+ }
cout << endl;
return ok;