aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2006-11-30 15:01:23 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2006-11-30 15:01:23 +0000
commit94fb8864b45d266e4e0a30bc0d130144c3da9c24 (patch)
tree3d426578b0c92e6dea8c995ccd94652d6fd36fdb
parent59cb5858fd3a1b93559c6631ea8dc02e749d5a32 (diff)
downloadpaludis-94fb8864b45d266e4e0a30bc0d130144c3da9c24.tar.gz
paludis-94fb8864b45d266e4e0a30bc0d130144c3da9c24.tar.xz
Add ruby interface to libpaludisqa.
-rw-r--r--configure.ac1
-rw-r--r--ruby/Makefile.am96
-rw-r--r--ruby/check.cc331
-rw-r--r--ruby/check_TEST.rb233
-rwxr-xr-xruby/check_TEST_cleanup.sh11
-rwxr-xr-xruby/check_TEST_setup.sh28
-rw-r--r--ruby/check_result.cc145
-rw-r--r--ruby/check_result_TEST.rb108
-rw-r--r--ruby/environment.cc3
-rw-r--r--ruby/message.cc125
-rw-r--r--ruby/message_TEST.rb74
-rw-r--r--ruby/metadata_file.cc124
-rw-r--r--ruby/metadata_file_TEST.rb90
-rw-r--r--ruby/paludis_ruby.cc55
-rw-r--r--ruby/paludis_ruby.hh23
-rw-r--r--ruby/qa_environment.cc79
-rw-r--r--ruby/qa_environment_TEST.rb52
-rwxr-xr-xruby/qa_environment_TEST_cleanup.sh11
-rwxr-xr-xruby/qa_environment_TEST_setup.sh36
19 files changed, 1619 insertions, 6 deletions
diff --git a/configure.ac b/configure.ac
index ad0cfc1..93e8ef9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -427,6 +427,7 @@ if test x"$ENABLE_QA" = "xyes" ; then
AC_MSG_ERROR([pcre++ (http://www.daemon.de/PCRE) is required if --enable-qa is used])
fi
need_xml_check=yes
+ AC_DEFINE([ENABLE_RUBY_QA], [1], [Enable QA support in ruby])
fi
AC_SUBST([ENABLE_QA])
AM_CONDITIONAL([ENABLE_QA], test "x$ENABLE_QA" = "xyes")
diff --git a/ruby/Makefile.am b/ruby/Makefile.am
index 9326a8e..4fd52cd 100644
--- a/ruby/Makefile.am
+++ b/ruby/Makefile.am
@@ -28,6 +28,13 @@ IF_RUBY_TESTS = \
portage_dep_parser_TEST.rb \
qualified_package_name_TEST.rb
+IF_RUBY_QA_TESTS = \
+ message_TEST.rb \
+ check_result_TEST.rb \
+ metadata_file_TEST.rb \
+ qa_environment_TEST.rb \
+ check_TEST.rb
+
IF_RUBY_SOURCES = \
paludis_ruby.cc paludis_ruby.hh \
environment.cc \
@@ -42,12 +49,22 @@ IF_RUBY_SOURCES = \
portage_dep_parser.cc \
qualified_package_name.cc
+IF_RUBY_QA_SOURCES = \
+ message.cc \
+ check.cc \
+ check_result.cc \
+ qa_environment.cc \
+ metadata_file.cc
+
EXTRA_DIST = $(IF_RUBY_TESTS) $(IF_RUBY_SOURCES) \
+ $(IF_RUBY_QA_TESTS) $(IF_RUBY_QA_SOURCES) \
environment_TEST_setup.sh environment_TEST_cleanup.sh \
package_database_TEST_setup.sh package_database_TEST_cleanup.sh \
repository_TEST_setup.sh repository_TEST_cleanup.sh \
version_metadata_TEST_setup.sh version_metadata_TEST_cleanup.sh \
- paludis_ruby_TEST_setup.sh paludis_ruby_TEST_cleanup.sh
+ paludis_ruby_TEST_setup.sh paludis_ruby_TEST_cleanup.sh \
+ qa_environment_TEST_setup.sh qa_environment_TEST_cleanup.sh \
+ check_TEST_setup.sh check_TEST_cleanup.sh
TESTS_ENVIRONMENT = env \
PALUDIS_NO_GLOBAL_HOOKS="yes" \
@@ -59,13 +76,15 @@ TESTS_ENVIRONMENT = env \
LD_LIBRARY_PATH=`echo "\`$(top_srcdir)/ebuild/utils/canonicalise $(top_builddir)/paludis/.libs\`: \
\`$(top_srcdir)/ebuild/utils/canonicalise $(top_builddir)/paludis/util/.libs\`: \
\`$(top_srcdir)/ebuild/utils/canonicalise $(top_builddir)/paludis/environment/default/.libs\`: \
- \`$(top_srcdir)/ebuild/utils/canonicalise $(top_builddir)/paludis/environment/no_config/.libs\`" \
+ \`$(top_srcdir)/ebuild/utils/canonicalise $(top_builddir)/paludis/environment/no_config/.libs\`: \
+ \`$(top_srcdir)/ebuild/utils/canonicalise $(top_builddir)/paludis/qa/.libs\`: \
+ \`$(top_srcdir)/ebuild/utils/canonicalise $(top_builddir)/paludis/libxml/.libs\`" \
| tr -d ' '` \
bash $(top_srcdir)/test/run_test.sh "$(RUBY) -I ./.libs/"
if ENABLE_RUBY
-OUR_OBJECTS = \
+BASE_OBJECTS = \
environment.o \
dep_atom.o \
log.o \
@@ -79,7 +98,25 @@ OUR_OBJECTS = \
qualified_package_name.o \
paludis_ruby.o
+if ENABLE_QA
+
+OUR_OBJECTS = $(BASE_OBJECTS)\
+ paludis_ruby.o \
+ message.o \
+ check.o \
+ check_result.o \
+ qa_environment.o \
+ metadata_file.o
+
+TESTS = $(IF_RUBY_TESTS) $(IF_RUBY_QA_TESTS)
+
+else
+
+OUR_OBJECTS = $(BASE_OBJECTS)
TESTS = $(IF_RUBY_TESTS)
+
+endif
+
noinst_DATA = $(OUR_OBJECTS)
check_DATA = .libs/Paludis.so
rubylibdir = @RUBY_INSTALL_DIR@
@@ -125,6 +162,23 @@ portage_dep_parser.o : portage_dep_parser.cc paludis_ruby.hh
qualified_package_name.o : qualified_package_name.cc paludis_ruby.hh
$(OUR_CXXCOMPILE) -o $@ $(srcdir)/qualified_package_name.cc
+message.o : message.cc paludis_ruby.hh
+ $(OUR_CXXCOMPILE) -o $@ $(srcdir)/message.cc
+
+check.o : check.cc paludis_ruby.hh
+ $(OUR_CXXCOMPILE) -o $@ $(srcdir)/check.cc
+
+check_result.o : check_result.cc paludis_ruby.hh
+ $(OUR_CXXCOMPILE) -o $@ $(srcdir)/check_result.cc
+
+qa_environment.o : qa_environment.cc paludis_ruby.hh
+ $(OUR_CXXCOMPILE) -o $@ $(srcdir)/qa_environment.cc
+
+metadata_file.o : metadata_file.cc paludis_ruby.hh
+ $(OUR_CXXCOMPILE) -o $@ $(srcdir)/metadata_file.cc
+
+if ENABLE_QA
+
.libs/Paludis.so : $(OUR_OBJECTS)
mkdir -p .libs
$(CXX) -fPIC -shared $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
@@ -136,9 +190,29 @@ qualified_package_name.o : qualified_package_name.cc paludis_ruby.hh
$(top_builddir)/paludis/util/.libs/libpaludisutil.so \
$(top_builddir)/paludis/.libs/libpaludis.so \
$(top_builddir)/paludis/environment/default/.libs/libpaludisdefaultenvironment.so \
- $(top_builddir)/paludis/environment/no_config/.libs/libpaludisnoconfigenvironment.so
+ $(top_builddir)/paludis/environment/no_config/.libs/libpaludisnoconfigenvironment.so \
+ $(top_builddir)/paludis/qa/.libs/libpaludisqa.so \
+ $(top_builddir)/paludis/libxml/.libs/libpaludislibxml.so \
+ $(PCREPLUSPLUS_LIBS)
Paludis.so : $(OUR_OBJECTS)
+ $(CXX) -fPIC -shared $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) \
+ $(AM_LDFLAGS) $(LDFLAGS) \
+ -I@RUBY_SITEARCHDIR@ -l@RUBY_SONAME@ \
+ -o $@ \
+ $^ \
+ -L$(top_builddir)/paludis/util/.libs/ -lpaludisutil \
+ -L$(top_builddir)/paludis/.libs/ -lpaludis \
+ -L$(top_builddir)/paludis/environment/default/.libs/ -lpaludisdefaultenvironment \
+ -L$(top_builddir)/paludis/environment/no_config/.libs/ -lpaludisnoconfigenvironment \
+ -L$(top_builddir)/paludis/qa/.libs/ -lpaludisqa \
+ -L$(top_builddir)/paludis/libxml/.libs/ -lpaludislibxml \
+ $(PCREPLUSPLUS_LIBS)
+
+else
+
+.libs/Paludis.so : $(OUR_OBJECTS)
mkdir -p .libs
$(CXX) -fPIC -shared $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) \
@@ -146,6 +220,18 @@ Paludis.so : $(OUR_OBJECTS)
-I@RUBY_SITEARCHDIR@ -l@RUBY_SONAME@ \
-o $@ \
$^ \
+ $(top_builddir)/paludis/util/.libs/libpaludisutil.so \
+ $(top_builddir)/paludis/.libs/libpaludis.so \
+ $(top_builddir)/paludis/environment/default/.libs/libpaludisdefaultenvironment.so \
+ $(top_builddir)/paludis/environment/no_config/.libs/libpaludisnoconfigenvironment.so
+
+Paludis.so : $(OUR_OBJECTS)
+ $(CXX) -fPIC -shared $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) \
+ $(AM_LDFLAGS) $(LDFLAGS) \
+ -I@RUBY_SITEARCHDIR@ -l@RUBY_SONAME@ \
+ -o $@ \
+ $^ \
-L$(top_builddir)/paludis/util/.libs/ -lpaludisutil \
-L$(top_builddir)/paludis/.libs/ -lpaludis \
-L$(top_builddir)/paludis/environment/default/.libs/ -lpaludisdefaultenvironment \
@@ -153,6 +239,8 @@ Paludis.so : $(OUR_OBJECTS)
endif
+endif
+
built-sources : $(BUILT_SOURCES)
for s in `echo $(SUBDIRS) | tr -d .` ; do $(MAKE) -C $$s built-sources || exit 1 ; done
diff --git a/ruby/check.cc b/ruby/check.cc
new file mode 100644
index 0000000..5ae236d
--- /dev/null
+++ b/ruby/check.cc
@@ -0,0 +1,331 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Richard Brown <mynamewasgone@gmail.com>
+ *
+ * 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_ruby.hh>
+#include <paludis/qa/check.hh>
+#include <paludis/qa/package_dir_check.hh>
+#include <paludis/util/stringify.hh>
+#include <paludis/qa/qa.hh>
+#include <ruby.h>
+#include <cstdlib>
+#include <iostream>
+
+using namespace paludis;
+using namespace paludis::qa;
+using namespace paludis::ruby;
+using std::cerr;
+
+#define RUBY_FUNC_CAST(x) reinterpret_cast<VALUE (*)(...)>(x)
+
+namespace
+{
+ static VALUE c_ebuild_check_data;
+ static VALUE c_package_dir_check;
+ static VALUE c_package_dir_check_maker;
+ static VALUE c_file_check;
+ static VALUE c_file_check_maker;
+ static VALUE c_ebuild_check;
+ static VALUE c_ebuild_check_maker;
+
+ VALUE
+ ebuild_check_data_init(int, VALUE *, VALUE self)
+ {
+ return self;
+ }
+
+ VALUE
+ ebuild_check_data_new(int argc, VALUE *argv, VALUE self)
+ {
+ EbuildCheckData * ptr(0);
+ try
+ {
+ if (3 == argc)
+ {
+ ptr = new EbuildCheckData(
+ value_to_qualified_package_name(argv[0]),
+ value_to_version_spec(argv[1]),
+ value_to_environment(argv[2])
+ );
+ }
+ else
+ {
+ rb_raise(rb_eArgError, "EbuildCheckData expects three arguments, but got %d",argc);
+ }
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<EbuildCheckData>::free, ptr));
+ rb_obj_call_init(tdata, argc, argv);
+ return tdata;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ template <typename T_>
+ struct CheckStruct
+ {
+ static
+ VALUE describe(VALUE self)
+ {
+ T_ * ptr;
+ Data_Get_Struct(self, T_, ptr);
+ return rb_str_new2((*ptr)->describe().c_str());
+ }
+ static
+ VALUE
+ is_important(VALUE self)
+ {
+ T_ * ptr;
+ Data_Get_Struct(self, T_, ptr);
+ return (*ptr)->is_important() ? Qtrue : Qfalse;
+ }
+ };
+
+ template <typename T_, typename S_>
+ VALUE
+ check_check(VALUE check, S_ arg)
+ {
+ try
+ {
+ T_ * ptr;
+ Data_Get_Struct(check, T_, ptr);
+ return check_result_to_value((**ptr)(arg));
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ package_dir_check_check(VALUE self, VALUE f)
+ {
+ try
+ {
+ return (check_check <PackageDirCheck::Pointer, FSEntry> (self, FSEntry(StringValuePtr(f))));
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ file_check_check(VALUE self, VALUE f)
+ {
+ try
+ {
+ return (check_check <FileCheck::Pointer, FSEntry> (self, FSEntry(StringValuePtr(f))));
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ ebuild_check_check(VALUE self, VALUE f)
+ {
+ try
+ {
+ return (check_check <EbuildCheck::Pointer, EbuildCheckData> (self, value_to_ebuild_check_data(f)));
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ template <typename T_>
+ struct CheckMakerStruct
+ {
+ static
+ VALUE keys(VALUE)
+ {
+ std::list<std::string> checks;
+ T_::get_instance()->copy_keys(std::back_inserter(checks));
+ VALUE result(rb_ary_new());
+ for (std::list<std::string>::const_iterator i(checks.begin()),
+ i_end(checks.end()) ; i != i_end ; ++i)
+ {
+ rb_ary_push(result, rb_str_new2((*i).c_str()));
+ }
+ return result;
+ }
+ };
+
+ VALUE package_dir_check_maker_find_maker(VALUE, VALUE maker)
+ {
+ try
+ {
+ PackageDirCheck::Pointer p = (PackageDirCheckMaker::get_instance()->find_maker(StringValuePtr(maker)))();
+ return package_dir_check_to_value(p);
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE file_check_maker_find_maker(VALUE, VALUE maker)
+ {
+ try
+ {
+ FileCheck::Pointer p = (FileCheckMaker::get_instance()->find_maker(StringValuePtr(maker)))();
+ return file_check_to_value(p);
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE ebuild_check_maker_find_maker(VALUE, VALUE maker)
+ {
+ try
+ {
+ EbuildCheck::Pointer p = (EbuildCheckMaker::get_instance()->find_maker(StringValuePtr(maker)))();
+ return ebuild_check_to_value(p);
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ void do_register_check()
+ {
+ rb_require("singleton");
+
+ c_ebuild_check_data = rb_define_class_under(paludis_qa_module(), "EbuildCheckData", rb_cObject);
+ rb_define_singleton_method(c_ebuild_check_data, "new", RUBY_FUNC_CAST(&ebuild_check_data_new),-1);
+ rb_define_method(c_ebuild_check_data, "initialize", RUBY_FUNC_CAST(&ebuild_check_data_init),-1);
+
+ c_package_dir_check = rb_define_class_under(paludis_qa_module(), "PackageDirCheck", rb_cObject);
+ rb_funcall(c_package_dir_check, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_define_method(c_package_dir_check, "check", RUBY_FUNC_CAST(&package_dir_check_check),1);
+ rb_define_method(c_package_dir_check, "describe", RUBY_FUNC_CAST(&CheckStruct<PackageDirCheck::Pointer>::describe),0);
+ rb_define_method(c_package_dir_check, "is_important?", RUBY_FUNC_CAST(&CheckStruct<PackageDirCheck::Pointer>::is_important),0);
+
+ c_file_check = rb_define_class_under(paludis_qa_module(), "FileCheck", rb_cObject);
+ rb_funcall(c_file_check, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_define_method(c_file_check, "check", RUBY_FUNC_CAST(&file_check_check),1);
+ rb_define_method(c_file_check, "describe", RUBY_FUNC_CAST(&CheckStruct<FileCheck::Pointer>::describe),0);
+ rb_define_method(c_file_check, "is_important?", RUBY_FUNC_CAST(&CheckStruct<FileCheck::Pointer>::is_important),0);
+
+ c_ebuild_check = rb_define_class_under(paludis_qa_module(), "EbuildCheck", rb_cObject);
+ rb_funcall(c_ebuild_check, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_define_method(c_ebuild_check, "check", RUBY_FUNC_CAST(&ebuild_check_check),1);
+ rb_define_method(c_ebuild_check, "describe", RUBY_FUNC_CAST(&CheckStruct<EbuildCheck::Pointer>::describe),0);
+ rb_define_method(c_ebuild_check, "is_important?", RUBY_FUNC_CAST(&CheckStruct<EbuildCheck::Pointer>::is_important),0);
+
+ c_package_dir_check_maker = rb_define_class_under(paludis_qa_module(), "PackageDirCheckMaker", rb_cObject);
+ rb_funcall(c_package_dir_check_maker, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_funcall(rb_const_get(rb_cObject, rb_intern("Singleton")), rb_intern("included"), 1, c_package_dir_check_maker);
+ rb_define_method(c_package_dir_check_maker, "keys", RUBY_FUNC_CAST(CheckMakerStruct<PackageDirCheckMaker>::keys),0);
+ rb_define_method(c_package_dir_check_maker, "find_maker", RUBY_FUNC_CAST(&package_dir_check_maker_find_maker),1);
+
+ c_file_check_maker = rb_define_class_under(paludis_qa_module(), "FileCheckMaker", rb_cObject);
+ rb_funcall(c_file_check_maker, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_funcall(rb_const_get(rb_cObject, rb_intern("Singleton")), rb_intern("included"), 1, c_file_check_maker);
+ rb_define_method(c_file_check_maker, "keys", RUBY_FUNC_CAST(CheckMakerStruct<FileCheckMaker>::keys),0);
+ rb_define_method(c_file_check_maker, "find_maker", RUBY_FUNC_CAST(&file_check_maker_find_maker),1);
+
+ c_ebuild_check_maker = rb_define_class_under(paludis_qa_module(), "EbuildCheckMaker", rb_cObject);
+ rb_funcall(c_ebuild_check_maker, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_funcall(rb_const_get(rb_cObject, rb_intern("Singleton")), rb_intern("included"), 1, c_ebuild_check_maker);
+ rb_define_method(c_ebuild_check_maker, "keys", RUBY_FUNC_CAST(&CheckMakerStruct<EbuildCheckMaker>::keys),0);
+ rb_define_method(c_ebuild_check_maker, "find_maker", RUBY_FUNC_CAST(&ebuild_check_maker_find_maker),1);
+ }
+}
+
+VALUE
+paludis::ruby::file_check_to_value(FileCheck::Pointer m)
+{
+ FileCheck::Pointer * m_ptr(0);
+ try
+ {
+ m_ptr = new FileCheck::Pointer(m);
+ return Data_Wrap_Struct(c_file_check, 0, &Common<FileCheck::Pointer>::free, m_ptr);
+ }
+ catch (const std::exception & e)
+ {
+ delete m_ptr;
+ exception_to_ruby_exception(e);
+ }
+}
+
+VALUE
+paludis::ruby::package_dir_check_to_value(PackageDirCheck::Pointer m)
+{
+ PackageDirCheck::Pointer * m_ptr(0);
+ try
+ {
+ m_ptr = new PackageDirCheck::Pointer(m);
+ return Data_Wrap_Struct(c_package_dir_check, 0, &Common<PackageDirCheck::Pointer>::free, m_ptr);
+ }
+ catch (const std::exception & e)
+ {
+ delete m_ptr;
+ exception_to_ruby_exception(e);
+ }
+}
+
+VALUE
+paludis::ruby::ebuild_check_to_value(EbuildCheck::Pointer m)
+{
+ EbuildCheck::Pointer * m_ptr(0);
+ try
+ {
+ m_ptr = new EbuildCheck::Pointer(m);
+ return Data_Wrap_Struct(c_ebuild_check, 0, &Common<EbuildCheck::Pointer>::free, m_ptr);
+ }
+ catch (const std::exception & e)
+ {
+ delete m_ptr;
+ exception_to_ruby_exception(e);
+ }
+}
+
+VALUE
+paludis::ruby::ebuild_check_data_to_value(const EbuildCheckData & v)
+{
+ EbuildCheckData * vv(new EbuildCheckData(v));
+ return Data_Wrap_Struct(c_ebuild_check_data, 0, &Common<EbuildCheckData>::free, vv);
+}
+
+
+EbuildCheckData
+paludis::ruby::value_to_ebuild_check_data(VALUE v)
+{
+ if (rb_obj_is_kind_of(v, c_ebuild_check_data))
+ {
+ EbuildCheckData * v_ptr;
+ Data_Get_Struct(v, EbuildCheckData, v_ptr);
+ return *v_ptr;
+ }
+ else
+ {
+ std::string message = "can't convert " + std::string(rb_obj_classname(v)) + " into EbuildCheckData";
+ rb_raise(rb_eTypeError, message.c_str());
+ }
+}
+RegisterRubyClass::Register paludis_ruby_register_check PALUDIS_ATTRIBUTE((used))
+ (&do_register_check);
diff --git a/ruby/check_TEST.rb b/ruby/check_TEST.rb
new file mode 100644
index 0000000..90246a5
--- /dev/null
+++ b/ruby/check_TEST.rb
@@ -0,0 +1,233 @@
+#!/usr/bin/env ruby
+# vim: set sw=4 sts=4 et tw=80 :
+
+#
+# Copyright (c) 2006 Richard Brown <mynamewasgone@gmail.com>
+#
+# 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
+#
+
+require 'test/unit'
+require 'Paludis'
+
+Paludis::Log.instance.log_level = Paludis::LogLevel::Warning
+
+module Paludis
+ module QA
+ class TestCase_FileCheckMaker < Test::Unit::TestCase
+ def test_instance
+ assert_equal FileCheckMaker.instance.__id__, FileCheckMaker.instance.__id__
+ assert_kind_of FileCheckMaker, FileCheckMaker.instance
+ end
+
+ def test_no_create
+ assert_raise NoMethodError do
+ x = FileCheckMaker.new()
+ end
+ end
+
+ def test_respond_to
+ assert_respond_to FileCheckMaker.instance, :keys
+ assert_respond_to FileCheckMaker.instance, :find_maker
+ end
+
+ def test_keys
+ assert_kind_of Array, FileCheckMaker.instance.keys
+ assert_not_equal 0, FileCheckMaker.instance.keys
+ end
+
+ def test_find_maker
+ name = FileCheckMaker.instance.keys.first
+ assert_kind_of FileCheck, FileCheckMaker.instance.find_maker(name)
+ end
+ end
+
+ class TestCase_PackageDirCheckMaker < Test::Unit::TestCase
+ def test_instance
+ assert_equal PackageDirCheckMaker.instance.__id__, PackageDirCheckMaker.instance.__id__
+ assert_kind_of PackageDirCheckMaker, PackageDirCheckMaker.instance
+ end
+
+ def test_no_create
+ assert_raise NoMethodError do
+ x = PackageDirCheckMaker.new()
+ end
+ end
+
+ def test_respond_to
+ assert_respond_to FileCheckMaker.instance, :keys
+ assert_respond_to FileCheckMaker.instance, :find_maker
+ end
+
+ def test_keys
+ assert_kind_of Array, PackageDirCheckMaker.instance.keys
+ assert_not_equal 0, PackageDirCheckMaker.instance.keys
+ end
+
+ def test_find_maker
+ name = PackageDirCheckMaker.instance.keys.first
+ assert_kind_of PackageDirCheck, PackageDirCheckMaker.instance.find_maker(name)
+ end
+ end
+
+ class TestCase_EbuildCheckMaker < Test::Unit::TestCase
+ def test_instance
+ assert_equal EbuildCheckMaker.instance.__id__, EbuildCheckMaker.instance.__id__
+ assert_kind_of EbuildCheckMaker, EbuildCheckMaker.instance
+ end
+
+ def test_no_create
+ assert_raise NoMethodError do
+ x = EbuildCheckMaker.new()
+ end
+ end
+
+ def test_respond_to
+ assert_respond_to FileCheckMaker.instance, :keys
+ assert_respond_to FileCheckMaker.instance, :find_maker
+ end
+
+ def test_keys
+ assert_kind_of Array, EbuildCheckMaker.instance.keys
+ assert_not_equal 0, EbuildCheckMaker.instance.keys
+ end
+
+ def test_find_maker
+ name = EbuildCheckMaker.instance.keys.first
+ assert_kind_of EbuildCheck, EbuildCheckMaker.instance.find_maker(name)
+ end
+ end
+
+ class TestCase_EbuildCheckData < Test::Unit::TestCase
+ def test_create
+ env = QAEnvironment.new('check_TEST_dir/repo1')
+ ecd = EbuildCheckData.new('cat-one/pkg-one', "1", env)
+ end
+ end
+
+ class TestCase_PackageDirCheck < Test::Unit::TestCase
+ def get_check
+ PackageDirCheckMaker.instance.find_maker('package_name')
+ end
+
+ def test_no_create
+ assert_raise NoMethodError do
+ x = PackageDirCheck.new()
+ end
+ end
+
+ def test_respond_to
+ check = get_check
+ assert_respond_to check, :describe
+ assert_respond_to check, :is_important?
+ assert_respond_to check, :check
+ end
+
+ def test_describe
+ check = get_check
+ assert_equal "Checks that the category/package name is valid", check.describe
+ end
+
+ def test_is_important
+ check = get_check
+ assert_equal true, check.is_important?
+ end
+
+ def test_check
+ check = get_check
+ assert_nothing_raised do
+ cr = check.check('cat-one/pkg-one')
+ end
+ end
+ end
+
+ class TestCase_FileCheck < Test::Unit::TestCase
+ def get_check
+ FileCheckMaker.instance.find_maker('whitespace')
+ end
+
+ def test_no_create
+ assert_raise NoMethodError do
+ x = FileCheck.new()
+ end
+ end
+
+ def test_respond_to
+ check = get_check
+ assert_respond_to check, :describe
+ assert_respond_to check, :is_important?
+ assert_respond_to check, :check
+ end
+
+ def test_describe
+ check = get_check
+ assert_equal "Checks whitespace", check.describe
+ end
+
+ def test_is_important
+ check = get_check
+ assert_equal false, check.is_important?
+ end
+
+ def test_check
+ check = get_check
+ assert_nothing_raised do
+ cr = check.check('cat-one/pkg-one/pkg-one-1.ebuild')
+ end
+ end
+ end
+
+ class TestCase_EbuildCheck < Test::Unit::TestCase
+ def get_ecd
+ env = QAEnvironment.new('check_TEST_dir/repo1')
+ ecd = EbuildCheckData.new('cat-one/pkg-one', "1", env)
+ end
+
+ def get_check
+ EbuildCheckMaker.instance.find_maker('create_metadata')
+ end
+
+ def test_no_create
+ assert_raise NoMethodError do
+ x = EbuildCheck.new()
+ end
+ end
+
+ def test_respond_to
+ check = get_check
+ assert_respond_to check, :describe
+ assert_respond_to check, :is_important?
+ assert_respond_to check, :check
+ end
+
+ def test_describe
+ check = get_check
+ assert_equal "Checks that the metadata can be generated", check.describe
+ end
+
+ def test_is_important
+ check = get_check
+ assert_equal true, check.is_important?
+ end
+
+ def test_check
+ check = get_check
+ assert_nothing_raised do
+ cr = check.check(get_ecd)
+ end
+ end
+ end
+ end
+end
+
diff --git a/ruby/check_TEST_cleanup.sh b/ruby/check_TEST_cleanup.sh
new file mode 100755
index 0000000..f083e42
--- /dev/null
+++ b/ruby/check_TEST_cleanup.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+if [ -d check_TEST_dir ] ; then
+ rm -fr check_TEST_dir
+else
+ true
+fi
+
+
+
diff --git a/ruby/check_TEST_setup.sh b/ruby/check_TEST_setup.sh
new file mode 100755
index 0000000..66ce831
--- /dev/null
+++ b/ruby/check_TEST_setup.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+mkdir check_TEST_dir || exit 1
+cd check_TEST_dir || exit 1
+
+mkdir -p repo1/{eclass,distfiles,profiles/profile} || exit 1
+cd repo1 || exit 1
+echo "test-repo-1" > profiles/repo_name || exit 1
+cat <<END > profiles/categories || exit 1
+cat-one
+cat-two
+cat-three
+END
+cat <<END > profiles/profile/make.defaults
+ARCH=test
+END
+cat <<END > profiles/profiles.desc
+test profile/ stable
+END
+mkdir -p cat-one/pkg-one
+cat <<END > cat-one/pkg-one/pkg-one-1.ebuild
+DESCRIPTION="foo"
+SLOT="foo"
+END
+
+cd ..
+
diff --git a/ruby/check_result.cc b/ruby/check_result.cc
new file mode 100644
index 0000000..34b4873
--- /dev/null
+++ b/ruby/check_result.cc
@@ -0,0 +1,145 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Richard Brown <mynamewasgone@gmail.com>
+ *
+ * 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_ruby.hh>
+#include <paludis/qa/check_result.hh>
+#include <paludis/util/stringify.hh>
+#include <ruby.h>
+
+using namespace paludis;
+using namespace paludis::qa;
+using namespace paludis::ruby;
+
+#define RUBY_FUNC_CAST(x) reinterpret_cast<VALUE (*)(...)>(x)
+
+namespace
+{
+ static VALUE c_check_result;
+
+ VALUE
+ check_result_init(int, VALUE *, VALUE self)
+ {
+ return self;
+ }
+
+ VALUE
+ check_result_new(int argc, VALUE *argv, VALUE self)
+ {
+ CheckResult * ptr(0);
+ try
+ {
+ if (2 == argc)
+ {
+ ptr = new CheckResult(StringValuePtr(argv[0]), StringValuePtr(argv[1]));
+ }
+ else
+ {
+ rb_raise(rb_eArgError, "CheckResult expects two arguments, but got %d",argc);
+ }
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<CheckResult>::free, ptr));
+ rb_obj_call_init(tdata, argc, argv);
+ return tdata;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ check_result_empty(VALUE self)
+ {
+ CheckResult * ptr;
+ Data_Get_Struct(self, CheckResult, ptr);
+ return (ptr)->empty() ? Qtrue : Qfalse;
+ }
+
+ VALUE
+ check_result_most_severe_level(VALUE self)
+ {
+ CheckResult * ptr;
+ Data_Get_Struct(self, CheckResult, ptr);
+ return INT2NUM((ptr)->most_severe_level());
+ }
+
+ VALUE
+ check_result_cat_message(VALUE self, VALUE message)
+ {
+ try
+ {
+ CheckResult * ptr;
+ Data_Get_Struct(self, CheckResult, ptr);
+ *ptr << value_to_message(message);
+ return self;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+
+ }
+
+ VALUE
+ check_result_messages(VALUE self)
+ {
+ CheckResult * ptr;
+ Data_Get_Struct(self, CheckResult, ptr);
+
+ VALUE result(rb_ary_new());
+ for (CheckResult::Iterator i (ptr->begin()), i_end(ptr->end()) ; i != i_end; ++i)
+ rb_ary_push(result, message_to_value(*i));
+ return result;
+ }
+
+ template <const std::string & (CheckResult::* m_) () const>
+ struct CheckResultValue
+ {
+ static VALUE
+ fetch(VALUE self)
+ {
+ CheckResult * ptr;
+ Data_Get_Struct(self, CheckResult, ptr);
+ return rb_str_new2((((*ptr).*m_)()).c_str());
+ }
+ };
+
+ void do_register_check_result()
+ {
+ c_check_result = rb_define_class_under(paludis_qa_module(), "CheckResult", rb_cObject);
+ rb_define_singleton_method(c_check_result, "new", RUBY_FUNC_CAST(&check_result_new),-1);
+ rb_define_method(c_check_result, "initialize", RUBY_FUNC_CAST(&check_result_init),-1);
+ rb_define_method(c_check_result, "empty?", RUBY_FUNC_CAST(&check_result_empty),0);
+ rb_define_method(c_check_result, "most_severe_level", RUBY_FUNC_CAST(&check_result_most_severe_level),0);
+ rb_define_method(c_check_result, "messages", RUBY_FUNC_CAST(&check_result_messages),0);
+ rb_define_method(c_check_result, "<<", RUBY_FUNC_CAST(&check_result_cat_message),1);
+ rb_define_method(c_check_result, "item", RUBY_FUNC_CAST((&CheckResultValue<&CheckResult::item>::fetch)),0);
+ rb_define_method(c_check_result, "rule", RUBY_FUNC_CAST((&CheckResultValue<&CheckResult::rule>::fetch)),0);
+ }
+}
+
+VALUE
+paludis::ruby::check_result_to_value(const CheckResult & v)
+{
+ CheckResult * vv(new CheckResult(v));
+ return Data_Wrap_Struct(c_check_result, 0, &Common<CheckResult>::free, vv);
+}
+
+RegisterRubyClass::Register paludis_ruby_register_check_result PALUDIS_ATTRIBUTE((used))
+ (&do_register_check_result);
diff --git a/ruby/check_result_TEST.rb b/ruby/check_result_TEST.rb
new file mode 100644
index 0000000..4db80da
--- /dev/null
+++ b/ruby/check_result_TEST.rb
@@ -0,0 +1,108 @@
+#!/usr/bin/env ruby
+# vim: set sw=4 sts=4 et tw=80 :
+
+#
+# Copyright (c) 2006 Richard Brown <mynamewasgone@gmail.com>
+#
+# 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
+#
+
+require 'test/unit'
+require 'Paludis'
+
+module Paludis
+ module QA
+ class TestCase_CheckResult < Test::Unit::TestCase
+ def test_create
+ cr = CheckResult.new('a','b')
+ end
+
+ def test_create_error
+ assert_raise TypeError do
+ cr = CheckResult.new(0, 'test')
+ end
+
+ assert_raise TypeError do
+ cr = CheckResult.new('test', 0)
+ end
+
+ assert_raise ArgumentError do
+ cr = CheckResult.new('test')
+ end
+
+ assert_raise ArgumentError do
+ cr = CheckResult.new('a','b','too_many')
+ end
+ end
+
+ def test_respond_to
+ cr = CheckResult.new('a','b')
+ assert_respond_to cr, :empty?
+ assert_respond_to cr, :most_severe_level
+ assert_respond_to cr, :messages
+ assert_respond_to cr, :<<
+ assert_respond_to cr, :item
+ assert_respond_to cr, :rule
+ end
+
+ def test_item
+ cr = CheckResult.new('a','b')
+ assert_equal 'a', cr.item
+ end
+
+ def test_rule
+ cr = CheckResult.new('a','b')
+ assert_equal 'b', cr.rule
+ end
+
+ def test_cat
+ cr = CheckResult.new('a','b')
+ assert_nothing_raised do
+ cr << Message.new(QALevel::Info, 'test')
+ end
+ end
+
+ def test_empty
+ cr = CheckResult.new('a','b')
+ assert_equal true, cr.empty?
+ cr << Message.new(QALevel::Info, 'test')
+ assert_equal false, cr.empty?
+ end
+
+ def test_most_severe_level
+ cr = CheckResult.new('a','b')
+ assert_equal 0, cr.most_severe_level
+ cr << Message.new(QALevel::Info, 'test')
+ assert_equal QALevel::Info, cr.most_severe_level
+ cr << Message.new(QALevel::Major, 'test2')
+ assert_equal QALevel::Major, cr.most_severe_level
+ cr << Message.new(QALevel::Maybe, 'test3')
+ assert_equal QALevel::Major, cr.most_severe_level
+ end
+
+ def test_messages
+ cr = CheckResult.new('a','b')
+ assert_equal Array.new, cr.messages
+ msgs = [
+ Message.new(QALevel::Info, 'test'),
+ Message.new(QALevel::Fatal, 'test2')
+ ]
+ cr << msgs[0]
+ cr << msgs[1]
+ assert_equal msgs.to_s, cr.messages.to_s
+ end
+ end
+ end
+end
+
diff --git a/ruby/environment.cc b/ruby/environment.cc
index b6445e9..4978ed1 100644
--- a/ruby/environment.cc
+++ b/ruby/environment.cc
@@ -259,8 +259,7 @@ namespace
void do_register_environment()
{
rb_require("singleton");
-
- c_environment = rb_define_class_under(paludis_module(), "Environment", rb_cObject);
+ c_environment = environment_class();
rb_funcall(c_environment, rb_intern("private_class_method"), 1, rb_str_new2("new"));
rb_define_method(c_environment, "query_use", RUBY_FUNC_CAST(&environment_query_use), -1);
rb_define_method(c_environment, "accept_keyword", RUBY_FUNC_CAST(&environment_accept_keyword), -1);
diff --git a/ruby/message.cc b/ruby/message.cc
new file mode 100644
index 0000000..ed0bc68
--- /dev/null
+++ b/ruby/message.cc
@@ -0,0 +1,125 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Richard Brown <mynamewasgone@gmail.com>
+ *
+ * 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_ruby.hh>
+#include <paludis/qa/message.hh>
+#include <paludis/util/stringify.hh>
+#include <ruby.h>
+
+using namespace paludis;
+using namespace paludis::qa;
+using namespace paludis::ruby;
+
+#define RUBY_FUNC_CAST(x) reinterpret_cast<VALUE (*)(...)>(x)
+
+namespace
+{
+ static VALUE c_message;
+ static VALUE c_qa_level;
+
+ VALUE
+ message_init(int, VALUE *, VALUE self)
+ {
+ return self;
+ }
+
+ VALUE
+ message_new(int argc, VALUE *argv, VALUE self)
+ {
+ Message * ptr(0);
+ try
+ {
+ if (2 == argc)
+ {
+ int i = NUM2INT(argv[0]);
+ if (i < 0|| i >= last_qal)
+ rb_raise(rb_eArgError, "QALevel out of range");
+ ptr = new Message(static_cast<QALevel>(i), StringValuePtr(argv[1]));
+ }
+ else
+ {
+ rb_raise(rb_eArgError, "Message expects two arguments, but got %d",argc);
+ }
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<Message>::free, ptr));
+ rb_obj_call_init(tdata, argc, argv);
+ return tdata;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ message_msg(VALUE self)
+ {
+ Message * ptr;
+ Data_Get_Struct(self, Message, ptr);
+ return rb_str_new2((ptr)->msg.c_str());
+ }
+
+ VALUE
+ message_level(VALUE self)
+ {
+ Message * ptr;
+ Data_Get_Struct(self, Message, ptr);
+ return INT2NUM((ptr)->level);
+ }
+ void do_register_message()
+ {
+ c_qa_level = rb_define_module_under(paludis_qa_module(), "QALevel");
+ for (QALevel l(static_cast<QALevel>(0)), l_end(last_qal) ; l != l_end ;
+ l = static_cast<QALevel>(static_cast<int>(l) + 1))
+ rb_define_const(c_qa_level, value_case_to_RubyCase(stringify(l)).c_str(), INT2FIX(l));
+
+ c_message = rb_define_class_under(paludis_qa_module(), "Message", rb_cObject);
+ rb_define_singleton_method(c_message, "new", RUBY_FUNC_CAST(&message_new),-1);
+ rb_define_method(c_message, "initialize", RUBY_FUNC_CAST(&message_init),-1);
+ rb_define_method(c_message, "to_s", RUBY_FUNC_CAST(&Common<Message>::to_s),0);
+ rb_define_method(c_message, "msg", RUBY_FUNC_CAST(&message_msg),0);
+ rb_define_method(c_message, "level", RUBY_FUNC_CAST(&message_level),0);
+ }
+}
+
+Message
+paludis::ruby::value_to_message(VALUE v)
+{
+ if (rb_obj_is_kind_of(v, c_message))
+ {
+ Message * v_ptr;
+ Data_Get_Struct(v, Message, v_ptr);
+ return *v_ptr;
+ }
+ else
+ {
+ std::string message = "TypeError: can't convert " + std::string(rb_obj_classname(v)) + " into Message";
+ rb_raise(rb_eTypeError, message.c_str());
+ }
+}
+
+VALUE
+paludis::ruby::message_to_value(const Message & v)
+{
+ Message * vv(new Message(v));
+ return Data_Wrap_Struct(c_message, 0, &Common<Message>::free, vv);
+}
+
+RegisterRubyClass::Register paludis_ruby_register_message PALUDIS_ATTRIBUTE((used))
+ (&do_register_message);
diff --git a/ruby/message_TEST.rb b/ruby/message_TEST.rb
new file mode 100644
index 0000000..c6973fb
--- /dev/null
+++ b/ruby/message_TEST.rb
@@ -0,0 +1,74 @@
+#!/usr/bin/env ruby
+# vim: set sw=4 sts=4 et tw=80 :
+
+#
+# Copyright (c) 2006 Richard Brown <mynamewasgone@gmail.com>
+#
+# 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
+#
+
+require 'test/unit'
+require 'Paludis'
+
+module Paludis
+ module QA
+ class TestCase_Message < Test::Unit::TestCase
+ def test_create
+ msg = Message.new(QALevel::Info,'test')
+ end
+
+ def test_create_error
+ assert_raise TypeError do
+ msg = Message.new('wrong', 'test')
+ end
+
+ assert_raise TypeError do
+ msg = Message.new(QALevel::Info, 0)
+ end
+
+ assert_raise ArgumentError do
+ msg = Message.new(QALevel::Info)
+ end
+
+ assert_raise ArgumentError do
+ msg = Message.new(QALevel::Info,'test','too_many')
+ end
+
+ end
+
+ def test_respond_to
+ msg = Message.new(QALevel::Info,'test')
+ assert_respond_to msg, :to_s
+ assert_respond_to msg, :msg
+ assert_respond_to msg, :level
+ end
+
+ def test_to_s
+ msg = Message.new(QALevel::Info,'test')
+ assert_equal '(info) test', msg.to_s
+ end
+
+ def test_msg
+ msg = Message.new(QALevel::Info,'test')
+ assert_equal 'test', msg.msg
+ end
+
+ def test_level
+ msg = Message.new(QALevel::Info, 'test')
+ assert_equal QALevel::Info, msg.level
+ end
+ end
+ end
+end
+
diff --git a/ruby/metadata_file.cc b/ruby/metadata_file.cc
new file mode 100644
index 0000000..ffd648b
--- /dev/null
+++ b/ruby/metadata_file.cc
@@ -0,0 +1,124 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Richard Brown <mynamewasgone@gmail.com>
+ *
+ * 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_ruby.hh>
+#include <paludis/qa/metadata_file.hh>
+#include <paludis/util/stringify.hh>
+#include <ruby.h>
+
+using namespace paludis;
+using namespace paludis::qa;
+using namespace paludis::ruby;
+
+#define RUBY_FUNC_CAST(x) reinterpret_cast<VALUE (*)(...)>(x)
+
+namespace
+{
+ static VALUE c_metadata_file;
+
+ VALUE
+ metadata_file_init(int, VALUE *, VALUE self)
+ {
+ return self;
+ }
+
+ VALUE
+ metadata_file_new(int argc, VALUE *argv, VALUE self)
+ {
+ MetadataFile * ptr(0);
+ try
+ {
+ if (1 == argc)
+ {
+ std::string s = StringValuePtr(argv[0]);
+ FSEntry fse = FSEntry(s);
+ if (fse.is_regular_file())
+ ptr = new MetadataFile(fse);
+ else
+ ptr = new MetadataFile(s);
+ }
+ else
+ {
+ rb_raise(rb_eArgError, "MetadataFile expects one argument, but got %d",argc);
+ }
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<MetadataFile>::free, ptr));
+ rb_obj_call_init(tdata, argc, argv);
+ return tdata;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ metadata_file_herds(VALUE self)
+ {
+ MetadataFile * ptr;
+ Data_Get_Struct(self, MetadataFile, ptr);
+
+ VALUE result(rb_ary_new());
+ for (MetadataFile::HerdsIterator i (ptr->begin_herds()),
+ i_end(ptr->end_herds()) ; i != i_end ; ++i)
+ rb_ary_push(result, rb_str_new2(i->c_str()));
+ return result;
+ }
+
+ VALUE
+ metadata_file_maintainers(VALUE self)
+ {
+ MetadataFile * ptr;
+ Data_Get_Struct(self, MetadataFile, ptr);
+ VALUE result(rb_ary_new());
+ VALUE result_hash;
+ for (MetadataFile::MaintainersIterator i(ptr->begin_maintainers()),
+ i_end(ptr->end_maintainers()) ; i != i_end ; ++i)
+ {
+ if (i->first.empty() && i->second.empty())
+ continue;
+
+ result_hash = rb_hash_new();
+ if (!i->first.empty())
+ rb_hash_aset(result_hash, ID2SYM(rb_intern("email")), rb_str_new2(i->first.c_str()));
+ if (!i->second.empty())
+ rb_hash_aset(result_hash, ID2SYM(rb_intern("name")), rb_str_new2(i->second.c_str()));
+ rb_ary_push(result, result_hash);
+ }
+ return result;
+ }
+ void do_register_metadata_file()
+ {
+ c_metadata_file = rb_define_class_under(paludis_qa_module(), "MetadataFile", rb_cObject);
+ rb_define_singleton_method(c_metadata_file, "new", RUBY_FUNC_CAST(&metadata_file_new),-1);
+ rb_define_method(c_metadata_file, "initialize", RUBY_FUNC_CAST(&metadata_file_init),-1);
+ rb_define_method(c_metadata_file, "herds", RUBY_FUNC_CAST(&metadata_file_herds),0);
+ rb_define_method(c_metadata_file, "maintainers", RUBY_FUNC_CAST(&metadata_file_maintainers),0);
+ }
+}
+
+VALUE
+paludis::ruby::metadata_file_to_value(const MetadataFile & v)
+{
+ MetadataFile * vv(new MetadataFile(v));
+ return Data_Wrap_Struct(c_metadata_file, 0, &Common<MetadataFile>::free, vv);
+}
+
+RegisterRubyClass::Register paludis_ruby_register_metadata_file PALUDIS_ATTRIBUTE((used))
+ (&do_register_metadata_file);
diff --git a/ruby/metadata_file_TEST.rb b/ruby/metadata_file_TEST.rb
new file mode 100644
index 0000000..7f33a14
--- /dev/null
+++ b/ruby/metadata_file_TEST.rb
@@ -0,0 +1,90 @@
+#!/usr/bin/env ruby
+# vim: set sw=4 sts=4 et tw=80 :
+
+#
+# Copyright (c) 2006 Richard Brown <mynamewasgone@gmail.com>
+#
+# 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
+#
+
+require 'test/unit'
+require 'Paludis'
+
+module Paludis
+ module QA
+ class TestCase_MetadataFile < Test::Unit::TestCase
+ def metadata
+
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
+<!DOCTYPE pkgmetadata SYSTEM \"http://www.gentoo.org/dtd/metadata.dtd\">
+<pkgmetadata>
+ <herd>vim</herd>
+ <herd> cookie </herd>
+ <maintainer>
+ <email> foo@bar.baz </email>
+ <name> Foo Bar </name>
+ </maintainer>
+ <maintainer>
+ <email>oink@oink</email>
+ </maintainer>
+ <maintainer>
+ <name> Fred the Fish </name>
+ </maintainer>
+ <longdescription lang=\"en\">
+ Some text
+ </longdescription>
+</pkgmetadata>"
+
+ end
+
+ def test_create
+ #check that we can open from file as well
+
+ file = MetadataFile.new(metadata)
+ end
+
+ def test_respond_to
+ file = MetadataFile.new(metadata)
+ assert_respond_to file, :herds
+ assert_respond_to file, :maintainers
+ end
+
+ def test_herds
+ file = MetadataFile.new(metadata)
+ herds = file.herds
+ assert_equal 2, herds.length
+ assert_equal true, herds.include?('vim')
+ assert_equal true, herds.include?('cookie')
+ assert_equal false, herds.include?('monster')
+ end
+
+ def test_maintainers
+ file = MetadataFile.new(metadata)
+ assert_equal 3, file.maintainers.length
+ file.maintainers.each do |m|
+ if m.has_key? :email
+ if m[:email] == 'foo@bar.baz'
+ assert_equal({:email => 'foo@bar.baz', :name => 'Foo Bar'}, m)
+ else
+ assert_equal({:email => 'oink@oink'}, m)
+ end
+ else
+ assert_equal({:name => 'Fred the Fish'}, m)
+ end
+ end
+ end
+ end
+ end
+end
+
diff --git a/ruby/paludis_ruby.cc b/ruby/paludis_ruby.cc
index 941d6da..b561756 100644
--- a/ruby/paludis_ruby.cc
+++ b/ruby/paludis_ruby.cc
@@ -19,10 +19,15 @@
#include <paludis/paludis.hh>
#include <paludis_ruby.hh>
+#include <paludis/config_file.hh>
#include <ruby.h>
#include <list>
#include <ctype.h>
+#ifdef ENABLE_RUBY_QA
+#include <paludis/qa/qa_environment.hh>
+#endif
+
using namespace paludis;
using namespace paludis::ruby;
@@ -55,6 +60,18 @@ namespace
static VALUE c_dep_string_error;
static VALUE c_dep_string_parse_error;
static VALUE c_dep_string_nesting_error;
+ static VALUE c_configuration_error;
+ static VALUE c_config_file_error;
+
+ static VALUE c_environment;
+
+#ifdef ENABLE_RUBY_QA
+ static VALUE c_paludis_qa_module;
+ static VALUE c_profiles_desc_error;
+ static VALUE c_no_such_file_check_type_error;
+ static VALUE c_no_such_package_dir_check_type_error;
+ static VALUE c_no_such_ebuild_check_type_error;
+#endif
VALUE paludis_match_package(VALUE, VALUE en, VALUE a, VALUE t)
{
@@ -128,6 +145,20 @@ void paludis::ruby::exception_to_ruby_exception(const std::exception & ee)
rb_raise(c_dep_string_parse_error, dynamic_cast<const paludis::DepStringParseError *>(&ee)->message().c_str());
else if (0 != dynamic_cast<const paludis::DepStringError *>(&ee))
rb_raise(c_dep_string_error, dynamic_cast<const paludis::DepStringError *>(&ee)->message().c_str());
+#ifdef ENABLE_RUBY_QA
+ else if (0 != dynamic_cast<const paludis::qa::ProfilesDescError *>(&ee))
+ rb_raise(c_profiles_desc_error, dynamic_cast<const paludis::qa::ProfilesDescError *>(&ee)->message().c_str());
+ else if (0 != dynamic_cast<const paludis::qa::NoSuchFileCheckTypeError *>(&ee))
+ rb_raise(c_no_such_file_check_type_error, dynamic_cast<const paludis::qa::NoSuchFileCheckTypeError *>(&ee)->message().c_str());
+ else if (0 != dynamic_cast<const paludis::qa::NoSuchPackageDirCheckTypeError *>(&ee))
+ rb_raise(c_no_such_package_dir_check_type_error, dynamic_cast<const paludis::qa::NoSuchPackageDirCheckTypeError *>(&ee)->message().c_str());
+ else if (0 != dynamic_cast<const paludis::qa::NoSuchEbuildCheckTypeError *>(&ee))
+ rb_raise(c_no_such_ebuild_check_type_error, dynamic_cast<const paludis::qa::NoSuchEbuildCheckTypeError *>(&ee)->message().c_str());
+#endif
+ else if (0 != dynamic_cast<const paludis::ConfigFileError *>(&ee))
+ rb_raise(c_config_file_error, dynamic_cast<const paludis::ConfigFileError *>(&ee)->message().c_str());
+ else if (0 != dynamic_cast<const paludis::ConfigurationError *>(&ee))
+ rb_raise(c_configuration_error, dynamic_cast<const paludis::ConfigurationError *>(&ee)->message().c_str());
else if (0 != dynamic_cast<const paludis::Exception *>(&ee))
rb_raise(rb_eRuntimeError, "Caught paludis::Exception: %s (%s)",
@@ -166,11 +197,26 @@ paludis::ruby::paludis_module()
return c_paludis_module;
}
+VALUE
+paludis::ruby::environment_class()
+{
+ return c_environment;
+}
+
+#ifdef ENABLE_RUBY_QA
+VALUE
+paludis::ruby::paludis_qa_module()
+{
+ return c_paludis_qa_module;
+}
+#endif
+
extern "C"
{
void Init_Paludis()
{
c_paludis_module = rb_define_module("Paludis");
+ c_environment = rb_define_class_under(paludis_module(), "Environment", rb_cObject);
c_name_error = rb_define_class_under(c_paludis_module, "NameError", rb_eRuntimeError);
c_set_name_error = rb_define_class_under(c_paludis_module, "SetNameError", c_name_error);
c_category_name_part_error = rb_define_class_under(c_paludis_module, "CategoryNamePartError", c_name_error);
@@ -185,11 +231,20 @@ extern "C"
c_dep_string_error = rb_define_class_under(c_paludis_module, "DepStringError", rb_eRuntimeError);
c_dep_string_parse_error = rb_define_class_under(c_paludis_module, "DepStringParseError", c_dep_string_error);
c_dep_string_nesting_error = rb_define_class_under(c_paludis_module, "DepStringNestingError", c_dep_string_parse_error);
+ c_configuration_error = rb_define_class_under(c_paludis_module, "ConfigurationError", rb_eRuntimeError);
+ c_config_file_error = rb_define_class_under(c_paludis_module, "ConfigFileError", c_configuration_error);
rb_define_module_function(c_paludis_module, "match_package", RUBY_FUNC_CAST(&paludis_match_package), 3);
rb_define_const(c_paludis_module, "Version", rb_str_new2((stringify(PALUDIS_VERSION_MAJOR) + "."
+ stringify(PALUDIS_VERSION_MINOR) + "." + stringify(PALUDIS_VERSION_MICRO)).c_str()));
+#ifdef ENABLE_RUBY_QA
+ c_paludis_qa_module = rb_define_module_under(c_paludis_module,"QA");
+ c_profiles_desc_error = rb_define_class_under(c_paludis_qa_module, "ProfilesDescError", c_configuration_error);
+ c_no_such_file_check_type_error = rb_define_class_under(c_paludis_qa_module, "NoSuchFileCheckTypeError", rb_eTypeError);
+ c_no_such_package_dir_check_type_error = rb_define_class_under(c_paludis_qa_module, "NoSuchPackageDirCheckTypeError", rb_eTypeError);
+ c_no_such_ebuild_check_type_error = rb_define_class_under(c_paludis_qa_module, "NoSuchEbuildCheckTypeError", rb_eTypeError);
+#endif
RegisterRubyClass::get_instance()->execute();
}
}
diff --git a/ruby/paludis_ruby.hh b/ruby/paludis_ruby.hh
index e64beb3..3d14f7d 100644
--- a/ruby/paludis_ruby.hh
+++ b/ruby/paludis_ruby.hh
@@ -20,6 +20,8 @@
#ifndef PALUDIS_GUARD_RUBY_RUBY_PALUDIS_RUBY_HH
#define PALUDIS_GUARD_RUBY_RUBY_PALUDIS_RUBY_HH 1
+#include "config.h"
+
#include <paludis/util/instantiation_policy.hh>
#include <paludis/util/private_implementation_pattern.hh>
#include <paludis/util/attributes.hh>
@@ -27,10 +29,17 @@
#include <paludis/util/compare.hh>
#include <paludis/package_database.hh>
#include <paludis/mask_reasons.hh>
+#include <paludis/util/fs_entry.hh>
+
+#ifdef ENABLE_RUBY_QA
+#include <paludis/qa/qa.hh>
+#endif
+
#include <ruby.h>
namespace paludis
{
+
namespace ruby
{
/* general utilities */
@@ -40,6 +49,7 @@ namespace paludis
std::string value_case_to_RubyCase(const std::string & s);
VALUE paludis_module();
+ VALUE environment_class();
/* constructors */
@@ -59,6 +69,19 @@ namespace paludis
PackageDatabaseEntry value_to_package_database_entry(VALUE v);
Environment* value_to_environment(VALUE v);
+#ifdef ENABLE_RUBY_QA
+ VALUE paludis_qa_module();
+ qa::Message value_to_message(VALUE v);
+ qa::EbuildCheckData value_to_ebuild_check_data(VALUE v);
+ VALUE ebuild_check_data_to_value(const qa::EbuildCheckData &);
+ VALUE check_result_to_value(const qa::CheckResult &);
+ VALUE package_dir_check_to_value(qa::PackageDirCheck::Pointer);
+ VALUE file_check_to_value(qa::FileCheck::Pointer);
+ VALUE ebuild_check_to_value(qa::EbuildCheck::Pointer);
+ VALUE message_to_value(const qa::Message &);
+ VALUE metadata_file_to_value(const qa::MetadataFile &);
+#endif
+
/* registration */
class RegisterRubyClass :
diff --git a/ruby/qa_environment.cc b/ruby/qa_environment.cc
new file mode 100644
index 0000000..566f5a2
--- /dev/null
+++ b/ruby/qa_environment.cc
@@ -0,0 +1,79 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Richard Brown <mynamewasgone@gmail.com>
+ *
+ * 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_ruby.hh>
+#include <paludis/qa/qa_environment.hh>
+#include <paludis/util/fs_entry.hh>
+#include <ruby.h>
+
+using namespace paludis;
+using namespace paludis::qa;
+using namespace paludis::ruby;
+
+#define RUBY_FUNC_CAST(x) reinterpret_cast<VALUE (*)(...)>(x)
+
+namespace
+{
+ static VALUE c_qa_environment;
+
+ VALUE
+ qa_environment_init(int, VALUE*, VALUE self)
+ {
+ return self;
+ }
+
+ VALUE
+ qa_environment_new(int argc, VALUE* argv, VALUE self)
+ {
+ QAEnvironment * ptr(0);
+ try
+ {
+ if (1 == argc)
+ {
+ ptr = new QAEnvironment(FSEntry(StringValuePtr(argv[0])));
+ }
+ else if (2 == argc)
+ {
+ ptr = new QAEnvironment(FSEntry(StringValuePtr(argv[0])), FSEntry(StringValuePtr(argv[1])));
+ }
+ else
+ {
+ rb_raise(rb_eArgError, "QAEnvironment expects one or two arguments, but got %d",argc);
+ }
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<QAEnvironment>::free, ptr));
+ rb_obj_call_init(tdata, argc, argv);
+ return tdata;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ void do_register_qa_environment()
+ {
+ c_qa_environment = rb_define_class_under(paludis_qa_module(), "QAEnvironment", environment_class());
+ rb_define_singleton_method(c_qa_environment, "new", RUBY_FUNC_CAST(&qa_environment_new),-1);
+ rb_define_method(c_qa_environment, "initialize", RUBY_FUNC_CAST(&qa_environment_init),-1);
+ }
+}
+
+RegisterRubyClass::Register paludis_ruby_register_qa_environment PALUDIS_ATTRIBUTE((used))
+ (&do_register_qa_environment);
diff --git a/ruby/qa_environment_TEST.rb b/ruby/qa_environment_TEST.rb
new file mode 100644
index 0000000..fd3f595
--- /dev/null
+++ b/ruby/qa_environment_TEST.rb
@@ -0,0 +1,52 @@
+#!/usr/bin/env ruby
+# vim: set sw=4 sts=4 et tw=80 :
+
+#
+# Copyright (c) 2006 Richard Brown <mynamewasgone@gmail.com>
+#
+# 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
+#
+
+require 'test/unit'
+require 'Paludis'
+
+Paludis::Log.instance.log_level = Paludis::LogLevel::Silent
+
+module Paludis
+ module QA
+ class TestCase_QAEnvironment < Test::Unit::TestCase
+ def test_create
+ env = QAEnvironment.new('qa_environment_TEST_dir/repo1')
+ end
+
+ def test_pass
+ env = QAEnvironment.new('qa_environment_TEST_dir/repo1')
+ check = EbuildCheckMaker.instance.find_maker('create_metadata')
+ ecd = EbuildCheckData.new('cat-one/pkg-one', "1", env)
+ cr = check.check(ecd)
+ assert_equal true, cr.empty?
+ end
+
+ def test_fail
+ env = QAEnvironment.new('qa_environment_TEST_dir/repo1')
+ check = EbuildCheckMaker.instance.find_maker('create_metadata')
+ ecd = EbuildCheckData.new('cat-one/pkg-one', "2", env)
+ # This outputs stuff to stderr. Don't Panic.
+ cr = check.check(ecd)
+ assert_equal false, cr.empty?
+ end
+ end
+ end
+end
+
diff --git a/ruby/qa_environment_TEST_cleanup.sh b/ruby/qa_environment_TEST_cleanup.sh
new file mode 100755
index 0000000..02ed13f
--- /dev/null
+++ b/ruby/qa_environment_TEST_cleanup.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+if [ -d qa_environment_TEST_dir ] ; then
+ rm -fr qa_environment_TEST_dir
+else
+ true
+fi
+
+
+
diff --git a/ruby/qa_environment_TEST_setup.sh b/ruby/qa_environment_TEST_setup.sh
new file mode 100755
index 0000000..6764e76
--- /dev/null
+++ b/ruby/qa_environment_TEST_setup.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+mkdir qa_environment_TEST_dir || exit 1
+cd qa_environment_TEST_dir || exit 1
+
+mkdir -p repo1/{eclass,distfiles,profiles/profile} || exit 1
+cd repo1 || exit 1
+echo "test-repo-1" > profiles/repo_name || exit 1
+cat <<END > profiles/categories || exit 1
+cat-one
+cat-two
+cat-three
+END
+cat <<END > profiles/profile/make.defaults
+ARCH=test
+END
+cat <<END > profiles/profiles.desc
+test profile/ stable
+END
+mkdir -p cat-one/pkg-one
+cat <<END > cat-one/pkg-one/pkg-one-1.ebuild
+DESCRIPTION="foo"
+SLOT="foo"
+END
+cat <<END > cat-one/pkg-one/pkg-one-2.ebuild
+DESCRIPTION="foo"
+if has_version foo ; then
+ SLOT="foo"
+else
+ SLOT="bar"
+fi
+END
+
+cd ..
+