aboutsummaryrefslogtreecommitdiff
path: root/0.8.0/paludis/repositories/cran
diff options
context:
space:
mode:
Diffstat (limited to '0.8.0/paludis/repositories/cran')
-rw-r--r--0.8.0/paludis/repositories/cran/Makefile.am97
-rw-r--r--0.8.0/paludis/repositories/cran/cran_dep_parser.cc61
-rw-r--r--0.8.0/paludis/repositories/cran/cran_dep_parser.hh21
-rw-r--r--0.8.0/paludis/repositories/cran/cran_dep_parser_TEST.cc149
-rw-r--r--0.8.0/paludis/repositories/cran/cran_description.cc103
-rw-r--r--0.8.0/paludis/repositories/cran/cran_description.hh129
-rw-r--r--0.8.0/paludis/repositories/cran/cran_installed_repository.cc599
-rw-r--r--0.8.0/paludis/repositories/cran/cran_installed_repository.hh137
-rw-r--r--0.8.0/paludis/repositories/cran/cran_installed_repository.sr23
-rw-r--r--0.8.0/paludis/repositories/cran/cran_repository.cc637
-rw-r--r--0.8.0/paludis/repositories/cran/cran_repository.hh137
-rw-r--r--0.8.0/paludis/repositories/cran/cran_repository.sr27
-rw-r--r--0.8.0/paludis/repositories/cran/cran_repository_TEST.cc97
-rwxr-xr-x0.8.0/paludis/repositories/cran/cran_repository_TEST_cleanup.sh8
-rwxr-xr-x0.8.0/paludis/repositories/cran/cran_repository_TEST_setup.sh57
15 files changed, 2282 insertions, 0 deletions
diff --git a/0.8.0/paludis/repositories/cran/Makefile.am b/0.8.0/paludis/repositories/cran/Makefile.am
new file mode 100644
index 0000000..cb681c0
--- /dev/null
+++ b/0.8.0/paludis/repositories/cran/Makefile.am
@@ -0,0 +1,97 @@
+CLEANFILES = *~ gmon.out *.gcov *.gcno *.gcda
+DISTCLEANFILES = cran_repository-sr.hh cran_repository-sr.cc
+MAINTAINERCLEANFILES = Makefile.in
+
+AM_CXXFLAGS = -I$(top_srcdir) @PALUDIS_CXXFLAGS@ @PALUDIS_CXXFLAGS_VISIBILITY@
+DEFS= \
+ -DSYSCONFDIR=\"$(sysconfdir)\" \
+ -DLIBEXECDIR=\"$(libexecdir)\" \
+ -DDATADIR=\"$(datadir)\" \
+ -DLIBDIR=\"$(libdir)\"
+
+paludis_repositories_libdir = $(libdir)/paludis/repositories
+paludis_repositories_lib_LTLIBRARIES = libpaludiscranrepository.la
+paludis_repositories_cran_includedir = $(includedir)/paludis/repositories/cran/
+libpaludiscranrepository_la_LDFLAGS = -version-info @VERSION_LIB_CURRENT@:@VERSION_LIB_REVISION@:0
+
+paludis_repositories_cran_include_HEADERS = \
+ cran_description.hh \
+ cran_dep_parser.hh \
+ cran_repository.hh \
+ cran_repository-sr.hh \
+ cran_installed_repository.hh \
+ cran_installed_repository-sr.hh
+
+libpaludiscranrepository_la_SOURCES = \
+ cran_description.cc \
+ cran_dep_parser.cc \
+ cran_repository.cc \
+ cran_installed_repository.cc \
+ $(paludis_repositories_cran_include_HEADERS)
+
+libpaludiscranrepository_la_LIBADD = \
+ $(top_builddir)/paludis/libpaludis.la \
+ $(top_builddir)/paludis/util/libpaludisutil.la \
+ $(DYNAMIC_LD_LIBS)
+
+TESTS = cran_dep_parser_TEST cran_repository_TEST
+
+cran_dep_parser_TEST_SOURCES = cran_dep_parser_TEST.cc
+
+cran_dep_parser_TEST_LDADD= \
+ $(top_builddir)/paludis/util/test_extras.o \
+ $(top_builddir)/test/libtest.a \
+ libpaludiscranrepository.la
+
+cran_repository_TEST_SOURCES = cran_repository_TEST.cc
+
+cran_repository_TEST_LDADD = \
+ $(top_builddir)/paludis/util/test_extras.o \
+ $(top_builddir)/test/libtest.a \
+ libpaludiscranrepository.la \
+ $(top_builddir)/paludis/libpaludis.la \
+ $(top_builddir)/paludis/util/libpaludisutil.la \
+ $(top_builddir)/paludis/environment/test/libpaludistestenvironment.la \
+ $(DYNAMIC_LD_LIBS)
+
+cran_repository_TEST_CXXFLAGS = -I$(top_srcdir)
+
+EXTRA_DIST = \
+ cran_repository_TEST.cc \
+ cran_repository_TEST_setup.sh \
+ cran_repository_TEST_cleanup.sh \
+ cran_repository.sr \
+ cran_repository-sr.hh \
+ cran_repository-sr.cc \
+ cran_installed_repository.sr \
+ cran_installed_repository-sr.hh \
+ cran_installed_repository-sr.cc
+
+BUILT_SOURCES = \
+ cran_repository-sr.hh \
+ cran_repository-sr.cc \
+ cran_installed_repository-sr.hh \
+ cran_installed_repository-sr.cc
+
+check_PROGRAMS = $(TESTS)
+check_SCRIPTS = cran_repository_TEST_setup.sh cran_repository_TEST_cleanup.sh
+
+TESTS_ENVIRONMENT = env \
+ CRAN_BASH_DIR="$(top_srcdir)/cran/" \
+ PALUDIS_SKIP_CONFIG="yes" \
+ TEST_SCRIPT_DIR="$(srcdir)/" \
+ PALUDIS_REPOSITORY_SO_DIR="$(top_builddir)/paludis/repositories" \
+ bash $(top_srcdir)/test/run_test.sh
+
+cran_repository-sr.hh : cran_repository.sr $(top_srcdir)/misc/make_sr.bash
+ $(top_srcdir)/misc/make_sr.bash --header $(srcdir)/cran_repository.sr > $@
+
+cran_repository-sr.cc : cran_repository.sr $(top_srcdir)/misc/make_sr.bash
+ $(top_srcdir)/misc/make_sr.bash --source $(srcdir)/cran_repository.sr > $@
+
+cran_installed_repository-sr.hh : cran_installed_repository.sr $(top_srcdir)/misc/make_sr.bash
+ $(top_srcdir)/misc/make_sr.bash --header $(srcdir)/cran_installed_repository.sr > $@
+
+cran_installed_repository-sr.cc : cran_installed_repository.sr $(top_srcdir)/misc/make_sr.bash
+ $(top_srcdir)/misc/make_sr.bash --source $(srcdir)/cran_installed_repository.sr > $@
+
diff --git a/0.8.0/paludis/repositories/cran/cran_dep_parser.cc b/0.8.0/paludis/repositories/cran/cran_dep_parser.cc
new file mode 100644
index 0000000..456487e
--- /dev/null
+++ b/0.8.0/paludis/repositories/cran/cran_dep_parser.cc
@@ -0,0 +1,61 @@
+#include <paludis/dep_atom.hh>
+#include <paludis/repositories/cran/cran_dep_parser.hh>
+#include <paludis/repositories/cran/cran_description.hh>
+#include <paludis/util/strip.hh>
+#include <paludis/util/tokeniser.hh>
+
+#include <string>
+#include <list>
+
+using namespace paludis;
+
+DepAtom::ConstPointer
+CRANDepParser::parse(const std::string & s)
+{
+ Context context("When parsing CRAN 'Depends:' string: '" + s + "':");
+
+ CompositeDepAtom::Pointer result(new AllDepAtom);
+ Tokeniser<delim_kind::AnyOfTag, delim_mode::DelimiterTag> atom_tokeniser(",");
+
+ std::list<std::string> atoms;
+ atom_tokeniser.tokenise(s, std::back_inserter(atoms));
+ std::list<std::string>::const_iterator a(atoms.begin()), a_end(atoms.end());
+ for ( ; a != a_end ; ++a)
+ {
+ Context local_context("When processing token '" + *a + "':");
+
+ std::string aa = strip_leading(strip_trailing(*a, ")"), " \t");
+
+ std::string name, tmp, version, range;
+ std::string::size_type p(aa.find('('));
+ if ((std::string::npos != p))
+ {
+ name = strip_leading(strip_trailing(aa.substr(0, p), " \t"), " \t");
+ tmp = aa.substr(p + 1);
+ p = tmp.find(')');
+ aa = tmp.substr(0, p);
+ version = strip_trailing(strip_leading(aa, " \t(<>=~"), " )\t\n");
+ range = strip_trailing(strip_leading(aa.substr(0, aa.find(version)), " \t"), " \t\n");
+ }
+ else
+ name = strip_leading(strip_trailing(aa, " \t"), " \t");
+
+ CRANDescription::normalise_name(name);
+ CRANDescription::normalise_version(version);
+
+ if ("R" == name)
+ name = "dev-lang/R";
+ else
+ name = "cran/" + name;
+
+ std::string atom_string;
+ if (version.empty() || range.empty())
+ atom_string = name;
+ else
+ atom_string = range + name + "-" + version;
+ PackageDepAtom::Pointer atom(new PackageDepAtom(atom_string));
+ result->add_child(atom);
+ }
+
+ return result;
+}
diff --git a/0.8.0/paludis/repositories/cran/cran_dep_parser.hh b/0.8.0/paludis/repositories/cran/cran_dep_parser.hh
new file mode 100644
index 0000000..69bdd80
--- /dev/null
+++ b/0.8.0/paludis/repositories/cran/cran_dep_parser.hh
@@ -0,0 +1,21 @@
+#ifndef PALUDIS_GUARD_PALUDIS_CRAN_DEP_PARSER_HH
+#define PALUDIS_GUARD_PALUDIS_CRAN_DEP_PARSER_HH 1
+
+#include <paludis/dep_atom.hh>
+#include <string>
+
+namespace paludis
+{
+ /**
+ * The CRANDepParser conversts a string representation of a CRAN Depends:
+ * specification into a DepAtom instance.
+ *
+ * \ingroup grpdepparser
+ */
+ struct PALUDIS_VISIBLE CRANDepParser
+ {
+ static DepAtom::ConstPointer parse(const std::string & s);
+ };
+}
+
+#endif
diff --git a/0.8.0/paludis/repositories/cran/cran_dep_parser_TEST.cc b/0.8.0/paludis/repositories/cran/cran_dep_parser_TEST.cc
new file mode 100644
index 0000000..9308c8d
--- /dev/null
+++ b/0.8.0/paludis/repositories/cran/cran_dep_parser_TEST.cc
@@ -0,0 +1,149 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Danny van Dyk <kugelfang@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 <paludis/dep_atom.hh>
+#include <paludis/dep_atom_flattener.hh>
+#include <paludis/repositories/cran/cran_dep_parser.hh>
+#include <paludis/environment/test/test_environment.hh>
+#include <paludis/util/system.hh>
+#include <test/test_framework.hh>
+#include <test/test_runner.hh>
+
+using namespace test;
+using namespace paludis;
+
+#ifndef DOXYGEN
+namespace
+{
+ class DepAtomDumper :
+ public DepAtomVisitorTypes::ConstVisitor,
+ private InstantiationPolicy<DepAtomDumper, instantiation_method::NonCopyableTag>
+ {
+ private:
+ std::ostream * const _o;
+
+ public:
+ DepAtomDumper(std::ostream * const o);
+
+ void visit(const AllDepAtom * const);
+
+ void visit(const AnyDepAtom * const);
+
+ void visit(const UseDepAtom * const);
+
+ void visit(const PackageDepAtom * const);
+
+ void visit(const PlainTextDepAtom * const);
+
+ void visit(const BlockDepAtom * const);
+ };
+
+ DepAtomDumper::DepAtomDumper(std::ostream * const o) :
+ _o(o)
+ {
+ }
+
+ void
+ DepAtomDumper::visit(const AllDepAtom * const a)
+ {
+ *_o << "<all>";
+ std::for_each(a->begin(), a->end(), accept_visitor(this));
+ *_o << "</all>";
+ }
+
+ void
+ DepAtomDumper::visit(const AnyDepAtom * const a)
+ {
+ *_o << "<any>";
+ std::for_each(a->begin(), a->end(), accept_visitor(this));
+ *_o << "</any>";
+ }
+
+ void
+ DepAtomDumper::visit(const UseDepAtom * const a)
+ {
+ *_o << "<use flag=\"" << a->flag() << "\" inverse=\""
+ << (a->inverse() ? "true" : "false") << "\">";
+ std::for_each(a->begin(), a->end(), accept_visitor(this));
+ *_o << "</use>";
+ }
+
+ void
+ DepAtomDumper::visit(const PackageDepAtom * const p)
+ {
+ *_o << "<package";
+ if (p->slot_ptr())
+ *_o << " slot=\"" << *p->slot_ptr() << "\"";
+ if (p->version_spec_ptr())
+ *_o << " version=\"" << p->version_operator() << *p->version_spec_ptr() << "\"";
+ *_o << ">" << p->package() << "</package>";
+ }
+
+ void
+ DepAtomDumper::visit(const PlainTextDepAtom * const t)
+ {
+ *_o << "<text>" << t->text() << "</text>";
+ }
+
+ void
+ DepAtomDumper::visit(const BlockDepAtom * const b)
+ {
+ *_o << "<block>";
+ b->blocked_atom()->accept(this);
+ *_o << "</block>";
+ }
+}
+#endif
+
+/** \file
+ * Test cases for CRANRepository.
+ *
+ * \ingroup grptestcases
+ */
+
+namespace test_cases
+{
+ /**
+ * \test Test CRANDepParser::parse to parse well formed CRAN Depends: strings.
+ *
+ * \ingroup grptestcases
+ */
+ struct CRANDepParserTest : TestCase
+ {
+ CRANDepParserTest() : TestCase("DepParser") { }
+
+ void run()
+ {
+ std::stringstream s1, s2, s3;
+ DepAtomDumper d1(&s1), d2(&s2), d3(&s3);
+ // test R dependency
+ std::string dep1("R (>= 2.0.0)");
+ CRANDepParser::parse(dep1)->accept(&d1);
+ TEST_CHECK_EQUAL(s1.str(), "<all><package version=\">=2.0.0\">dev-lang/R</package></all>");
+ // test varying whitespaces
+ std::string dep2("testpackage1 \t(<1.9)");
+ CRANDepParser::parse(dep2)->accept(&d2);
+ TEST_CHECK_EQUAL(s2.str(), "<all><package version=\"<1.9\">cran/testpackage1</package></all>");
+ // test for package-name and version normalisation
+ std::string dep3("R.matlab (>= 2.3-1)");
+ CRANDepParser::parse(dep3)->accept(&d3);
+ TEST_CHECK_EQUAL(s3.str(), "<all><package version=\">=2.3.1\">cran/R-matlab</package></all>");
+ }
+ } test_cran_dep_parser;
+}
diff --git a/0.8.0/paludis/repositories/cran/cran_description.cc b/0.8.0/paludis/repositories/cran/cran_description.cc
new file mode 100644
index 0000000..b831414
--- /dev/null
+++ b/0.8.0/paludis/repositories/cran/cran_description.cc
@@ -0,0 +1,103 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Danny van Dyk <kugelfang@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 <paludis/repositories/cran/cran_description.hh>
+#include <paludis/repositories/cran/cran_dep_parser.hh>
+#include <paludis/config_file.hh>
+#include <paludis/util/log.hh>
+#include <paludis/util/strip.hh>
+#include <string>
+
+using namespace paludis;
+
+CRANDescription::CRANDescription(const std::string & n, const FSEntry & f) :
+ name("cran/" + n),
+ version("0"),
+ metadata(new VersionMetadata::CRAN(CRANDepParser::parse))
+{
+ Context context("When parsing file '" + stringify(f) + "' for package '" + n + "':");
+
+ if (! f.is_regular_file())
+ {
+ Log::get_instance()->message(ll_warning, lc_context, "Unexpected irregular file: '" + stringify(f) + "'.");
+ metadata->eapi = "INVALID";
+
+ return;
+ }
+
+ LineConfigFile file(f);
+ LineConfigFile::Iterator l(file.begin()), l_end(file.end());
+
+ // Fill in default values
+ metadata->slot = SlotName("0");
+ metadata->eapi = "CRAN-0";
+ metadata->get_cran_interface()->keywords = std::string("*");
+
+ std::string key;
+ for ( ; l != l_end ; ++l)
+ {
+ Context local_context("When parsing line '" + *l + "':");
+
+ std::string line(strip_leading(strip_trailing(*l, " \t\r\n"), " \t\r\n")), value;
+ std::string::size_type pos(line.find(':'));
+ if (std::string::npos == pos)
+ {
+ value = strip_leading(strip_trailing(line, " \t"), " \t");
+ }
+ else
+ {
+ key = strip_leading(strip_trailing(line.substr(0, pos), " \t"), " \t");
+ value = strip_leading(strip_trailing(line.substr(pos + 1), " \t\r\n"), " \t\r\n");
+ }
+
+ if ("Package" == key)
+ {
+ metadata->get_cran_interface()->package = value;
+ metadata->homepage = "http://cran.r-project.org/src/contrib/Descriptions/" + value + ".html";
+ CRANDescription::normalise_name(value);
+ if (n != value)
+ Log::get_instance()->message(ll_warning, lc_context, "Inconsistent package name in file '" +
+ stringify(name) + "': '" + n + "', '" + value + "':");
+ }
+ else if ("Bundle" == key)
+ {
+ metadata->get_cran_interface()->is_bundle = true;
+ }
+ else if ("Version" == key)
+ {
+ metadata->get_cran_interface()->version = value;
+ normalise_version(value);
+ version = VersionSpec(value);
+ }
+ else if ("Title" == key)
+ {
+ metadata->description = value;
+ }
+ else if ("Depends" == key)
+ {
+ if (value.empty())
+ value = "R";
+ else
+ value.append(", R");
+ metadata->deps.build_depend_string = value;
+ metadata->deps.run_depend_string = value;
+ }
+ }
+}
+
diff --git a/0.8.0/paludis/repositories/cran/cran_description.hh b/0.8.0/paludis/repositories/cran/cran_description.hh
new file mode 100644
index 0000000..45f354e
--- /dev/null
+++ b/0.8.0/paludis/repositories/cran/cran_description.hh
@@ -0,0 +1,129 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Danny van Dyk <kugelfang@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_CRAN_DESCRIPTION_HH
+#define PALUDIS_GUARD_PALUDIS_CRAN_DESCRIPTION_HH 1
+
+#include <paludis/version_metadata.hh>
+#include <paludis/util/fs_entry.hh>
+
+namespace paludis
+{
+ /**
+ * CRANDescription as used by CRANRepository and CRANInstalledRepository
+ */
+ struct PALUDIS_VISIBLE CRANDescription
+ {
+ /// Our package name.
+ QualifiedPackageName name;
+
+ /// Our package version.
+ VersionSpec version;
+
+ /// Our metadata, may be zero.
+ VersionMetadata::Pointer metadata;
+
+ /// Turn a CRAN package name into a paludis package name.
+ static void normalise_name(std::string & s)
+ {
+ std::replace_if(s.begin(), s.end(), std::bind2nd(std::equal_to<char>(), '.'), '-');
+ }
+
+ /// Turn a paludis package name into a CRAN package name.
+ static void denormalise_name(std::string & s)
+ {
+ std::replace_if(s.begin(), s.end(), std::bind2nd(std::equal_to<char>(), '-'), '.');
+ }
+
+ /// Turn a CRAN package version into a paludis package version.
+ static void normalise_version(std::string & s)
+ {
+ std::replace_if(s.begin(), s.end(), std::bind2nd(std::equal_to<char>(), '-'), '.');
+ }
+
+ /// Constructor
+ CRANDescription(const std::string & n, const FSEntry & f);
+
+ /// Comparison operator
+ bool operator< (const CRANDescription & other) const
+ {
+ if (name < other.name)
+ return true;
+ if (name > other.name)
+ return false;
+ if (version < other.version)
+ return true;
+ return false;
+ }
+
+ /**
+ * Compare a CRANDescription by name only.
+ *
+ * \ingroup grpcrandesc
+ */
+ struct PALUDIS_VISIBLE ComparePackage
+ {
+ bool operator() (const QualifiedPackageName & c, const CRANDescription & d) const
+ {
+ return c < d.name;
+ }
+
+ bool operator() (const CRANDescription & d, const QualifiedPackageName & c) const
+ {
+ return d.name < c;
+ }
+ };
+
+ /**
+ * Compare a CRANIDescription by name and version.
+ *
+ * \ingroup grpcrandesc
+ */
+ struct PALUDIS_VISIBLE CompareVersion
+ {
+ bool operator() (const std::pair<QualifiedPackageName, VersionSpec> & c,
+ const CRANDescription & d) const
+ {
+ if (c.first < d.name)
+ return true;
+ else if (c.first > d.name)
+ return false;
+ else if (c.second < d.version)
+ return true;
+ else
+ return false;
+ }
+
+ bool operator() (const CRANDescription & d,
+ const std::pair<QualifiedPackageName, VersionSpec> & c) const
+ {
+ if (d.name < c.first)
+ return true;
+ else if (d.name > c.first)
+ return false;
+ else if (d.version < c.second)
+ return true;
+ else
+ return false;
+ }
+ };
+ };
+}
+
+#endif
diff --git a/0.8.0/paludis/repositories/cran/cran_installed_repository.cc b/0.8.0/paludis/repositories/cran/cran_installed_repository.cc
new file mode 100644
index 0000000..a34a1c8
--- /dev/null
+++ b/0.8.0/paludis/repositories/cran/cran_installed_repository.cc
@@ -0,0 +1,599 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Danny van Dyk <kugelfang@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 <paludis/hashed_containers.hh>
+#include <paludis/config_file.hh>
+#include <paludis/match_package.hh>
+#include <paludis/package_database.hh>
+#include <paludis/repositories/cran/cran_description.hh>
+#include <paludis/repositories/cran/cran_dep_parser.hh>
+#include <paludis/repositories/cran/cran_installed_repository.hh>
+#include <paludis/util/collection_concrete.hh>
+#include <paludis/util/iterator.hh>
+#include <paludis/util/dir_iterator.hh>
+#include <paludis/util/fs_entry.hh>
+#include <paludis/util/system.hh>
+#include <paludis/util/log.hh>
+#include <paludis/util/pstream.hh>
+#include <paludis/util/stringify.hh>
+#include <paludis/util/strip.hh>
+#include <paludis/util/tokeniser.hh>
+
+#include <fstream>
+#include <functional>
+#include <algorithm>
+#include <vector>
+
+using namespace paludis;
+
+#include <paludis/repositories/cran/cran_installed_repository-sr.cc>
+
+namespace paludis
+{
+ /// Map for metadata.
+ typedef MakeHashedMap<std::pair<QualifiedPackageName, VersionSpec>, VersionMetadata::Pointer>::Type MetadataMap;
+
+ template <>
+ struct Implementation<CRANInstalledRepository> :
+ InternalCounted<Implementation<CRANInstalledRepository> >
+ {
+ /// Our owning db..
+ const PackageDatabase * const db;
+
+ /// Our owning env.
+ const Environment * const env;
+
+ /// Our base location.
+ FSEntry location;
+
+ /// Root location
+ FSEntry root;
+
+ /// World file.
+ FSEntry world_file;
+
+ // Do we have entries loaded?
+ mutable bool entries_valid;
+
+ mutable std::vector<CRANDescription> entries;
+
+ /// Load entries.
+ void load_entries() const;
+
+ /// Load metadata for one entry.
+ void load_entry(std::vector<CRANDescription>::iterator) const;
+
+ /// Metadata cache
+ mutable MetadataMap metadata;
+
+ /// Provide map.
+ mutable std::map<QualifiedPackageName, QualifiedPackageName> provide_map;
+
+ /// Constructor.
+ Implementation(const CRANInstalledRepositoryParams &);
+
+ /// Destructor.
+ ~Implementation();
+
+ /// Invalidate.
+ void invalidate() const;
+ };
+}
+
+Implementation<CRANInstalledRepository>::Implementation(const CRANInstalledRepositoryParams & p) :
+ db(p.package_database),
+ env(p.environment),
+ location(p.location),
+ root(p.root),
+ world_file(p.world),
+ entries_valid(false)
+{
+}
+
+Implementation<CRANInstalledRepository>::~Implementation()
+{
+}
+
+void
+Implementation<CRANInstalledRepository>::load_entries() const
+{
+ Context context("When loading CRANInstalledRepository entries from '" +
+ stringify(location) + "':");
+
+ entries.clear();
+ entries_valid = true;
+ try
+ {
+ for (DirIterator d(location), d_end ; d != d_end ; ++d)
+ {
+ Context local_context("When parsing directoryy '" + stringify(*d) + "'.");
+ if (! d->is_directory())
+ continue;
+
+ FSEntry f(FSEntry(stringify(*d)) / "DESCRIPTION");
+ if (! f.is_regular_file())
+ continue;
+
+ std::string n(d->basename());
+ CRANDescription::normalise_name(n);
+
+ CRANDescription desc(n, f);
+ entries.push_back(desc);
+
+ QualifiedPackageName q("cran/" + n);
+ metadata.insert(std::make_pair(std::make_pair(q, VersionSpec(desc.version)), desc.metadata));
+ }
+ }
+ catch (...)
+ {
+ entries_valid = false;
+ throw;
+ }
+}
+
+void
+Implementation<CRANInstalledRepository>::invalidate() const
+{
+ entries_valid = false;
+ entries.clear();
+}
+
+CRANInstalledRepository::CRANInstalledRepository(const CRANInstalledRepositoryParams & p) :
+ Repository(RepositoryName("cran_installed"),
+ RepositoryCapabilities::create()
+ .mask_interface(0)
+ .installable_interface(0)
+ .installed_interface(this)
+ .news_interface(0)
+ .sets_interface(this)
+ .syncable_interface(0)
+ .uninstallable_interface(this)
+ .use_interface(0)
+ .world_interface(this)
+ .environment_variable_interface(0)
+ .mirrors_interface(0)
+ .virtuals_interface(0)
+ .provides_interface(0)),
+ PrivateImplementationPattern<CRANInstalledRepository>(new Implementation<CRANInstalledRepository>(p))
+{
+ RepositoryInfoSection::Pointer config_info(new RepositoryInfoSection("Configuration information"));
+
+ config_info->add_kv("location", stringify(_imp->location));
+ config_info->add_kv("root", stringify(_imp->root));
+ config_info->add_kv("format", std::string("cran-installed"));
+
+ _info->add_section(config_info);
+}
+
+CRANInstalledRepository::~CRANInstalledRepository()
+{
+}
+
+bool
+CRANInstalledRepository::do_has_category_named(const CategoryNamePart & c) const
+{
+ return (CategoryNamePart("cran") == c);
+}
+
+bool
+CRANInstalledRepository::do_has_package_named(const QualifiedPackageName & q) const
+{
+ Context context("When checking for package '" + stringify(q) +
+ "' in " + stringify(name()) + ":");
+
+ if (! do_has_category_named(q.category))
+ return false;
+
+ if (! _imp->entries_valid)
+ _imp->load_entries();
+
+ std::pair<std::vector<CRANDescription>::const_iterator, std::vector<CRANDescription>::const_iterator>
+ r(std::equal_range(_imp->entries.begin(), _imp->entries.end(), q,
+ CRANDescription::ComparePackage()));
+
+ return r.first != r.second;
+}
+
+CategoryNamePartCollection::ConstPointer
+CRANInstalledRepository::do_category_names() const
+{
+ if (! _imp->entries_valid)
+ _imp->load_entries();
+
+ CategoryNamePartCollection::Pointer result(new CategoryNamePartCollection::Concrete);
+ result->insert(CategoryNamePart("cran"));
+ return result;
+}
+
+QualifiedPackageNameCollection::ConstPointer
+CRANInstalledRepository::do_package_names(const CategoryNamePart & c) const
+{
+ Context context("When fetching package names in category '" + stringify(c)
+ + "' in " + stringify(name()) + ":");
+
+ QualifiedPackageNameCollection::Pointer result(new QualifiedPackageNameCollection::Concrete);
+ if (! do_has_category_named(c))
+ return result;
+
+ std::vector<CRANDescription>::const_iterator e(_imp->entries.begin()), e_end(_imp->entries.end());
+ for ( ; e != e_end ; ++e)
+ result->insert(e->name);
+
+ return result;
+}
+
+VersionSpecCollection::ConstPointer
+CRANInstalledRepository::do_version_specs(const QualifiedPackageName & n) const
+{
+ Context context("When fetching versions of '" + stringify(n) + "' in "
+ + stringify(name()) + ":");
+
+ VersionSpecCollection::Pointer result(new VersionSpecCollection::Concrete);
+
+ std::pair<std::vector<CRANDescription>::const_iterator, std::vector<CRANDescription>::const_iterator>
+ r(std::equal_range(_imp->entries.begin(), _imp->entries.end(), n,
+ CRANDescription::ComparePackage()));
+
+ for ( ; r.first != r.second ; ++(r.first))
+ result->insert(r.first->version);
+
+ return result;
+}
+
+bool
+CRANInstalledRepository::do_has_version(const QualifiedPackageName & q,
+ const VersionSpec & v) const
+{
+ Context context("When checking for version '" + stringify(v) + "' in '"
+ + stringify(q) + "' in " + stringify(name()) + ":");
+
+ VersionSpecCollection::ConstPointer versions(do_version_specs(q));
+ return versions->end() != versions->find(v);
+}
+
+VersionMetadata::ConstPointer
+CRANInstalledRepository::do_version_metadata(
+ const QualifiedPackageName & q, const VersionSpec & v) const
+{
+ if (_imp->metadata.end() != _imp->metadata.find(
+ std::make_pair(q, v)))
+ return _imp->metadata.find(std::make_pair(q, v))->second;
+
+ Context context("When fetching metadata for " + stringify(q) +
+ "-" + stringify(v));
+
+ if (! has_version(q, v))
+ throw NoSuchPackageError(stringify(PackageDatabaseEntry(q, v, name())));
+
+ VersionMetadata::Pointer result(0);
+
+ FSEntry d(_imp->location);
+ d /= stringify(q.package);
+ d /= "DESCRIPTION";
+
+ if (d.is_regular_file())
+ {
+ CRANDescription description(stringify(q.package), d);
+ result = description.metadata;
+ }
+ else
+ {
+ Log::get_instance()->message(ll_warning, lc_no_context, "has_version failed for request for '" +
+ stringify(q) + "-" + stringify(v) + "' in repository '" +
+ stringify(name()) + "': No DESCRIPTION file present.");
+ result.assign(new VersionMetadata(CRANDepParser::parse));
+ result->eapi = "UNKNOWN";
+ return result;
+ }
+
+ _imp->metadata.insert(std::make_pair(std::make_pair(q, v), result));
+ return result;
+}
+
+Contents::ConstPointer
+CRANInstalledRepository::do_contents(
+ const QualifiedPackageName & q, const VersionSpec & v) const
+{
+ Context context("When fetching contents for " + stringify(q) +
+ "-" + stringify(v));
+
+ Contents::Pointer result(new Contents);
+
+ if (! _imp->entries_valid)
+ _imp->load_entries();
+
+ if (! has_version(q, v))
+ return result;
+
+ std::string pn = stringify(q.package);
+ CRANDescription::normalise_name(pn);
+ FSEntry f(_imp->location / "paludis" / pn / "CONTENTS");
+ if (! f.is_regular_file())
+ {
+ Log::get_instance()->message(ll_warning, lc_no_context, "CONTENTS lookup failed for request for' " +
+ stringify(q) + "-" + stringify(v) + "' in CRANInstalled '" +
+ stringify(_imp->location) + "'");
+ return result;
+ }
+
+ std::ifstream ff(stringify(f).c_str());
+ if (! ff)
+ throw InternalError(PALUDIS_HERE, "TODO reading " + stringify(_imp->location) + " name " +
+ stringify(q) + " version " + stringify(v) + " CONTENTS"); /// \todo
+
+ std::string line;
+ unsigned line_number(0);
+ while (std::getline(ff, line))
+ {
+ ++line_number;
+
+ std::vector<std::string> tokens;
+ WhitespaceTokeniser::get_instance()->tokenise(line, std::back_inserter(tokens));
+ if (tokens.empty())
+ continue;
+
+ if (tokens.size() < 2)
+ {
+ Log::get_instance()->message(ll_warning, lc_no_context, "CONTENTS for '" +
+ stringify(q) + "-" + stringify(v) + "' in vdb '" +
+ stringify(_imp->location) + "' has broken line " +
+ stringify(line_number) + ", skipping");
+ continue;
+ }
+
+ if ("obj" == tokens.at(0))
+ result->add(ContentsEntry::Pointer(new ContentsFileEntry(tokens.at(1))));
+ else if ("dir" == tokens.at(0))
+ result->add(ContentsEntry::Pointer(new ContentsDirEntry(tokens.at(1))));
+ else if ("misc" == tokens.at(0))
+ result->add(ContentsEntry::Pointer(new ContentsMiscEntry(tokens.at(1))));
+ else if ("sym" == tokens.at(0))
+ {
+ if (tokens.size() < 4)
+ {
+ Log::get_instance()->message(ll_warning, lc_no_context, "CONTENTS for '" +
+ stringify(q) + "-" + stringify(v) + "' in vdb '" +
+ stringify(_imp->location) + "' has broken sym line " +
+ stringify(line_number) + ", skipping");
+ continue;
+ }
+
+ result->add(ContentsEntry::Pointer(new ContentsSymEntry(
+ tokens.at(1), tokens.at(3))));
+ }
+ }
+
+ return result;
+}
+
+CountedPtr<Repository>
+CRANInstalledRepository::make_cran_installed_repository(
+ const Environment * const env,
+ const PackageDatabase * const db,
+ AssociativeCollection<std::string, std::string>::ConstPointer m)
+{
+ Context context("When making CRAN installed repository from repo_file '" +
+ (m->end() == m->find("repo_file") ? std::string("?") : m->find("repo_file")->second) + "':");
+
+ std::string location;
+ if (m->end() == m->find("location") || ((location = m->find("location")->second)).empty())
+ throw CRANInstalledRepositoryConfigurationError("Key 'location' not specified or empty");
+
+ std::string root;
+ if (m->end() == m->find("root") || ((root = m->find("root")->second)).empty())
+ root = "/";
+
+ std::string world;
+ if (m->end() == m->find("world") || ((world = m->find("world")->second)).empty())
+ world = location + "/world";
+
+ return CountedPtr<Repository>(new CRANInstalledRepository(CRANInstalledRepositoryParams::create()
+ .environment(env)
+ .package_database(db)
+ .location(location)
+ .root(root)
+ .world(world)));
+}
+
+CRANInstalledRepositoryConfigurationError::CRANInstalledRepositoryConfigurationError(
+ const std::string & msg) throw () :
+ ConfigurationError("CRAN installed repository configuration error: " + msg)
+{
+}
+
+bool
+CRANInstalledRepository::do_is_licence(const std::string &) const
+{
+ return false;
+}
+
+void
+CRANInstalledRepository::do_uninstall(const QualifiedPackageName & q, const VersionSpec & v,
+ const InstallOptions &) const
+{
+ Context context("When uninstalling '" + stringify(q) + "-" + stringify(v) +
+ "' from '" + stringify(name()) + "':");
+
+ if (! _imp->location.is_directory())
+ throw PackageInstallActionError("Couldn't uninstall '" + stringify(q) + "-" +
+ stringify(v) + "' because its location ('" + stringify(_imp->location) + "') is not a directory");
+
+ VersionMetadata::ConstPointer vm(do_version_metadata(q, v));
+
+ MakeEnvCommand cmd(LIBEXECDIR "/paludis/cran.bash unmerge", "");
+ cmd = cmd("PN", vm->get_cran_interface()->package);
+ cmd = cmd("PV", stringify(v));
+ cmd = cmd("PALUDIS_CRAN_LIBRARY", stringify(_imp->location));
+ cmd = cmd("PALUDIS_EBUILD_DIR", std::string(LIBEXECDIR "/paludis/"));
+ cmd = cmd("PALUDIS_BASHRC_FILES", _imp->env->bashrc_files());
+
+ if (0 != run_command(cmd))
+ throw PackageUninstallActionError("Couldn't unmerge '" + stringify(q) + "-" + stringify(v) + "'");
+}
+
+DepAtom::Pointer
+CRANInstalledRepository::do_package_set(const std::string & s) const
+{
+ Context context("When fetching package set '" + s + "' from '" +
+ stringify(name()) + "':");
+
+ if ("everything" == s)
+ {
+ AllDepAtom::Pointer result(new AllDepAtom);
+ if (! _imp->entries_valid)
+ _imp->load_entries();
+
+ for (std::vector<CRANDescription>::const_iterator p(_imp->entries.begin()),
+ p_end(_imp->entries.end()) ; p != p_end ; ++p)
+ {
+ PackageDepAtom::Pointer atom(new PackageDepAtom(p->name));
+ result->add_child(atom);
+ }
+
+ return result;
+ }
+ else if ("world" == s)
+ {
+ AllDepAtom::Pointer result(new AllDepAtom);
+
+ if (_imp->world_file.exists())
+ {
+ LineConfigFile world(_imp->world_file);
+
+ for (LineConfigFile::Iterator line(world.begin()), line_end(world.end()) ;
+ line != line_end ; ++line)
+ {
+ PackageDepAtom::Pointer atom(new PackageDepAtom(QualifiedPackageName(*line)));
+ result->add_child(atom);
+ }
+ }
+ else
+ Log::get_instance()->message(ll_warning, lc_no_context, "World file '" + stringify(_imp->world_file)
+ + "' doesn't exist");
+
+ return result;
+ }
+ else
+ return DepAtom::Pointer(0);
+}
+
+SetsCollection::ConstPointer
+CRANInstalledRepository::sets_list() const
+{
+ Context context("While generating the list of sets:");
+
+ SetsCollection::Pointer result(new SetsCollection::Concrete);
+ result->insert("everything");
+ result->insert("world");
+ return result;
+}
+
+bool
+CRANInstalledRepository::do_sync() const
+{
+ return false;
+}
+
+void
+CRANInstalledRepository::invalidate() const
+{
+ _imp->invalidate();
+}
+
+void
+CRANInstalledRepository::add_to_world(const QualifiedPackageName & n) const
+{
+ bool found(false);
+
+ if (_imp->world_file.exists())
+ {
+ LineConfigFile world(_imp->world_file);
+
+ for (LineConfigFile::Iterator line(world.begin()), line_end(world.end()) ;
+ line != line_end ; ++line)
+ if (QualifiedPackageName(*line) == n)
+ {
+ found = true;
+ break;
+ }
+ }
+
+ if (! found)
+ {
+ std::ofstream world(stringify(_imp->world_file).c_str(), std::ios::out | std::ios::app);
+ if (! world)
+ Log::get_instance()->message(ll_warning, lc_no_context, "Cannot append to world file '"
+ + stringify(_imp->world_file) + "', skipping world update");
+ else
+ world << n << std::endl;
+ }
+}
+
+void
+CRANInstalledRepository::remove_from_world(const QualifiedPackageName & n) const
+{
+ std::list<std::string> world_lines;
+
+ if (_imp->world_file.exists())
+ {
+ std::ifstream world_file(stringify(_imp->world_file).c_str());
+
+ if (! world_file)
+ {
+ Log::get_instance()->message(ll_warning, lc_no_context, "Cannot read world file '"
+ + stringify(_imp->world_file) + "', skipping world update");
+ return;
+ }
+
+ std::string line;
+ while (std::getline(world_file, line))
+ {
+ if (strip_leading(strip_trailing(line, " \t"), "\t") != stringify(n))
+ world_lines.push_back(line);
+ else
+ Log::get_instance()->message(ll_debug, lc_context, "Removing line '"
+ + line + "' from world file '" + stringify(_imp->world_file));
+ }
+ }
+
+ std::ofstream world_file(stringify(_imp->world_file).c_str());
+
+ if (! world_file)
+ {
+ Log::get_instance()->message(ll_warning, lc_no_context, "Cannot write world file '"
+ + stringify(_imp->world_file) + "', skipping world update");
+ return;
+ }
+
+ std::copy(world_lines.begin(), world_lines.end(),
+ std::ostream_iterator<std::string>(world_file, "\n"));
+}
+
+#ifdef PALUDIS_ENABLE_VISIBILITY
+# pragma GCC visibility push(default)
+#endif
+namespace
+{
+ const RepositoryMaker::RegisterMaker register_cran_installed_repository PALUDIS_ATTRIBUTE((used)) (
+ "cran_installed", &CRANInstalledRepository::make_cran_installed_repository);
+}
+#ifdef PALUDIS_ENABLE_VISIBILITY
+# pragma GCC visibility pop
+#endif
+
diff --git a/0.8.0/paludis/repositories/cran/cran_installed_repository.hh b/0.8.0/paludis/repositories/cran/cran_installed_repository.hh
new file mode 100644
index 0000000..6f82e17
--- /dev/null
+++ b/0.8.0/paludis/repositories/cran/cran_installed_repository.hh
@@ -0,0 +1,137 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Danny van Dyk <kugelfang@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_CRAN_INSTALLED_REPOSITORY_HH
+#define PALUDIS_GUARD_PALUDIS_CRAN_INSTALLED_REPOSITORY_HH 1
+
+#include <paludis/repository.hh>
+#include <paludis/util/attributes.hh>
+#include <paludis/util/private_implementation_pattern.hh>
+#include <paludis/util/fs_entry.hh>
+
+/** \file
+ * Declarations for CRANInstalledRepository.
+ *
+ * \ingroup grpcraninstrepository
+ */
+
+
+namespace paludis
+{
+
+#include <paludis/repositories/cran/cran_installed_repository-sr.hh>
+
+ /**
+ * A CRANInstalledRepository represents the database used for
+ * installed CRAN packages.
+ *
+ * \ingroup grpcraninstrepository
+ */
+ class PALUDIS_VISIBLE CRANInstalledRepository :
+ public Repository,
+ public RepositoryInstalledInterface,
+ public RepositoryUninstallableInterface,
+ public RepositorySetsInterface,
+ public RepositoryWorldInterface,
+ public PrivateImplementationPattern<CRANInstalledRepository>
+ {
+ protected:
+ virtual bool do_has_category_named(const CategoryNamePart &) const;
+
+ virtual bool do_has_package_named(const QualifiedPackageName &) const;
+
+ virtual CategoryNamePartCollection::ConstPointer do_category_names() const;
+
+ virtual QualifiedPackageNameCollection::ConstPointer do_package_names(
+ const CategoryNamePart &) const;
+
+ virtual VersionSpecCollection::ConstPointer do_version_specs(
+ const QualifiedPackageName &) const;
+
+ virtual bool do_has_version(const QualifiedPackageName &,
+ const VersionSpec &) const;
+
+ virtual VersionMetadata::ConstPointer do_version_metadata(
+ const QualifiedPackageName &,
+ const VersionSpec &) const;
+
+ virtual Contents::ConstPointer do_contents(
+ const QualifiedPackageName &,
+ const VersionSpec &) const;
+
+ virtual bool do_is_licence(const std::string &) const;
+
+ virtual void do_uninstall(const QualifiedPackageName &, const VersionSpec &,
+ const InstallOptions &) const;
+
+ virtual DepAtom::Pointer do_package_set(const std::string &) const;
+
+ virtual SetsCollection::ConstPointer sets_list() const;
+
+ virtual bool do_sync() const;
+
+ public:
+ /**
+ * Constructor.
+ */
+ CRANInstalledRepository(const CRANInstalledRepositoryParams &);
+
+ /**
+ * Virtual constructor.
+ */
+ static CountedPtr<Repository> make_cran_installed_repository(
+ const Environment * const env,
+ const PackageDatabase * const db,
+ AssociativeCollection<std::string, std::string>::ConstPointer m);
+
+ /**
+ * Destructor.
+ */
+ ~CRANInstalledRepository();
+
+ virtual bool installed() const
+ {
+ return true;
+ }
+
+ virtual void invalidate() const;
+
+ virtual void add_to_world(const QualifiedPackageName &) const;
+
+ virtual void remove_from_world(const QualifiedPackageName &) const;
+ };
+
+ /**
+ * Thrown if invalid parameters are provided for
+ * PortageRepository::make_portage_repository.
+ *
+ * \ingroup grpcraninstrepository
+ * \ingroup grpexceptions
+ */
+ class PALUDIS_VISIBLE CRANInstalledRepositoryConfigurationError : public ConfigurationError
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ CRANInstalledRepositoryConfigurationError(const std::string & msg) throw ();
+ };
+}
+
+#endif
diff --git a/0.8.0/paludis/repositories/cran/cran_installed_repository.sr b/0.8.0/paludis/repositories/cran/cran_installed_repository.sr
new file mode 100644
index 0000000..48791bc
--- /dev/null
+++ b/0.8.0/paludis/repositories/cran/cran_installed_repository.sr
@@ -0,0 +1,23 @@
+#!/bin/bash
+# vim: set sw=4 sts=4 et :
+
+make_class_CRANInstalledRepositoryParams()
+{
+ key environment "const Environment *"
+ key package_database "const PackageDatabase *"
+ key location FSEntry
+ key root FSEntry
+ key world FSEntry
+
+ doxygen_comment << "END"
+ /**
+ * Parameters used to create a CRANInstalledRepository
+ *
+ * \see CRANInstalledRepository
+ * \ingroup grpcraninstrepository
+ */
+END
+
+ allow_named_args
+}
+
diff --git a/0.8.0/paludis/repositories/cran/cran_repository.cc b/0.8.0/paludis/repositories/cran/cran_repository.cc
new file mode 100644
index 0000000..7ab4ac2
--- /dev/null
+++ b/0.8.0/paludis/repositories/cran/cran_repository.cc
@@ -0,0 +1,637 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Danny van Dyk <kugelfang@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 "config.h"
+
+#include <paludis/dep_atom.hh>
+#include <paludis/dep_atom_flattener.hh>
+#include <paludis/hashed_containers.hh>
+#include <paludis/config_file.hh>
+#include <paludis/match_package.hh>
+#include <paludis/package_database_entry.hh>
+#include <paludis/package_database.hh>
+#include <paludis/repositories/cran/cran_dep_parser.hh>
+#include <paludis/repositories/cran/cran_description.hh>
+#include <paludis/repositories/cran/cran_repository.hh>
+#include <paludis/syncer.hh>
+#include <paludis/util/collection_concrete.hh>
+#include <paludis/util/dir_iterator.hh>
+#include <paludis/util/fs_entry.hh>
+#include <paludis/util/iterator.hh>
+#include <paludis/util/log.hh>
+#include <paludis/util/pstream.hh>
+#include <paludis/util/random.hh>
+#include <paludis/util/save.hh>
+#include <paludis/util/stringify.hh>
+#include <paludis/util/strip.hh>
+#include <paludis/util/system.hh>
+#include <paludis/util/tokeniser.hh>
+
+#include <map>
+#include <list>
+#include <fstream>
+#include <functional>
+#include <algorithm>
+#include <vector>
+#include <deque>
+#include <limits>
+
+#include <strings.h>
+#include <ctype.h>
+
+/** \file
+ * Implementation CRANRepository.
+ *
+ * \ingroup grpcranrepository
+ */
+
+using namespace paludis;
+
+#include <paludis/repositories/cran/cran_repository-sr.cc>
+
+namespace paludis
+{
+ /// Map for versions.
+ typedef MakeHashedMap<QualifiedPackageName, VersionSpec>::Type VersionsMap;
+
+ /// Map for packages.
+ typedef MakeHashedMap<QualifiedPackageName, bool>::Type PackagesMap;
+
+ /// Map for mirrors.
+ typedef MakeHashedMap<std::string, std::list<std::string> >::Type MirrorMap;
+
+ /// Map for metadata.
+ typedef MakeHashedMap<std::pair<QualifiedPackageName, VersionSpec>, VersionMetadata::Pointer>::Type MetadataMap;
+
+ /**
+ * Implementation data for a CRANRepository.
+ *
+ * \ingroup grpportagerepository
+ */
+ template <>
+ struct Implementation<CRANRepository> :
+ InternalCounted<Implementation<CRANRepository> >
+ {
+ /// Our owning db.
+ const PackageDatabase * const db;
+
+ /// Our owning env.
+ const Environment * const env;
+
+ /// Our base location.
+ FSEntry location;
+
+ /// Distfiles dir
+ FSEntry distdir;
+
+ /// Mirror URL
+ std::string mirror;
+
+ /// Sync URL
+ std::string sync;
+
+ /// Build root location
+ FSEntry buildroot;
+
+ /// Root location
+ FSEntry root;
+
+ /// Library location
+ FSEntry library;
+
+ /// Have we loaded our category names?
+ mutable bool has_packages;
+
+ /// Our package names, and whether we have a fully loaded list of
+ /// version specs for that category.
+ mutable PackagesMap package_names;
+
+ /// Our version specs for each package.
+ mutable VersionsMap version_specs;
+
+ /// Metadata cache.
+ mutable MetadataMap metadata;
+
+ /// Do we have mirrors?
+ mutable bool has_mirrors;
+
+ /// Mirrors.
+ mutable MirrorMap mirrors;
+
+ /// Constructor.
+ Implementation(const CRANRepositoryParams &);
+
+ /// Destructor.
+ ~Implementation();
+
+ /// Invalidate our cache.
+ void invalidate() const;
+
+ /// (Empty) provides map.
+ const std::map<QualifiedPackageName, QualifiedPackageName> provide_map;
+ };
+}
+
+Implementation<CRANRepository>::Implementation(const CRANRepositoryParams & p) :
+ db(p.package_database),
+ env(p.environment),
+ location(p.location),
+ distdir(p.distdir),
+ mirror(p.mirror),
+ sync(p.sync),
+ buildroot(p.buildroot),
+ root(p.root),
+ library(p.library),
+ has_packages(false),
+ has_mirrors(false)
+{
+}
+
+Implementation<CRANRepository>::~Implementation()
+{
+}
+
+void
+Implementation<CRANRepository>::invalidate() const
+{
+ package_names.clear();
+ has_packages = false;
+ version_specs.clear();
+ metadata.clear();
+ has_mirrors = false;
+ mirrors.clear();
+}
+
+
+CRANRepository::CRANRepository(const CRANRepositoryParams & p) :
+ Repository(CRANRepository::fetch_repo_name(stringify(p.location)),
+ RepositoryCapabilities::create()
+ .mask_interface(0)
+ .installable_interface(this)
+ .installed_interface(0)
+ .news_interface(0)
+ .sets_interface(this)
+ .syncable_interface(this)
+ .uninstallable_interface(0)
+ .use_interface(0)
+ .world_interface(0)
+ .environment_variable_interface(0)
+ .mirrors_interface(0)
+ .provides_interface(0)
+ .virtuals_interface(0)),
+ PrivateImplementationPattern<CRANRepository>(new Implementation<CRANRepository>(p))
+{
+ RepositoryInfoSection::Pointer config_info(new RepositoryInfoSection("Configuration information"));
+
+ config_info->add_kv("location", stringify(_imp->location));
+ config_info->add_kv("distdir", stringify(_imp->distdir));
+ config_info->add_kv("format", "cran");
+ config_info->add_kv("buildroot", stringify(_imp->buildroot));
+ config_info->add_kv("root", stringify(_imp->root));
+ config_info->add_kv("library", stringify(_imp->library));
+ config_info->add_kv("sync", _imp->sync);
+
+ _info->add_section(config_info);
+}
+
+CRANRepository::~CRANRepository()
+{
+}
+
+bool
+CRANRepository::do_has_category_named(const CategoryNamePart & c) const
+{
+ Context context("When checking for category '" + stringify(c) +
+ "' in " + stringify(name()) + ":");
+
+ return "cran" == stringify(c);
+}
+
+bool
+CRANRepository::do_has_package_named(const QualifiedPackageName & q) const
+{
+ Context context("When checking for package '" + stringify(q) + "' in " +
+ stringify(name()) + ":");
+
+ need_packages();
+
+ if (! do_has_category_named(q.category))
+ return false;
+
+ return _imp->package_names.end() != _imp->package_names.find(q);
+}
+
+CategoryNamePartCollection::ConstPointer
+CRANRepository::do_category_names() const
+{
+ Context context("When fetching category names in " + stringify(name()) + ":");
+
+ CategoryNamePartCollection::Pointer result(new CategoryNamePartCollection::Concrete);
+ result->insert(CategoryNamePart("cran"));
+
+ return result;
+}
+
+QualifiedPackageNameCollection::ConstPointer
+CRANRepository::do_package_names(const CategoryNamePart & c) const
+{
+ Context context("When fetching package names in category '" + stringify(c)
+ + "' in " + stringify(name()) + ":");
+
+ need_packages();
+
+ QualifiedPackageNameCollection::Pointer result(new QualifiedPackageNameCollection::Concrete);
+ if (! do_has_category_named(c))
+ return result;
+
+ PackagesMap::const_iterator n(_imp->package_names.begin()), n_end(_imp->package_names.end());
+ for ( ; n != n_end ; ++n)
+ result->insert(n->first);
+
+ return result;
+}
+
+VersionSpecCollection::ConstPointer
+CRANRepository::do_version_specs(const QualifiedPackageName & n) const
+{
+ Context context("When fetching versions of '" + stringify(n) + "' in "
+ + stringify(name()) + ":");
+
+ need_packages();
+
+ VersionSpecCollection::Pointer result(new VersionSpecCollection::Concrete);
+ if (_imp->version_specs.end() != _imp->version_specs.find(n))
+ result->insert(_imp->version_specs.find(n)->second);
+
+ return result;
+}
+
+bool
+CRANRepository::do_has_version(const QualifiedPackageName & q,
+ const VersionSpec & v) const
+{
+ Context context("When checking for version '" + stringify(v) + "' in '"
+ + stringify(q) + "' in " + stringify(name()) + ":");
+
+ need_packages();
+
+ if (has_package_named(q))
+ return v == _imp->version_specs.find(q)->second;
+ else
+ return false;
+}
+
+void
+CRANRepository::need_packages() const
+{
+ if (_imp->has_packages)
+ return;
+
+ Context context("When loading category names for " + stringify(name()) + ":");
+
+ LineConfigFile packages(FSEntry(_imp->location / "PACKAGES"));
+ LineConfigFile::Iterator l(packages.begin()), l_end(packages.end());
+ std::string last_package_name;
+ bool skip_invalid_package = false;
+ for ( ; l != l_end ; ++l)
+ {
+ Context local_context("When parsing line '" + *l + "':");
+
+ std::string line(strip_leading(strip_trailing(*l, " \t"), " \t"));
+ if (line.empty())
+ continue;
+
+ std::string::size_type pos(line.find(':'));
+ if (std::string::npos == pos)
+ {
+ Log::get_instance()->message(ll_warning, lc_context, "Broken line in PACKAGES file: '" + stringify(_imp->location / "PACKAGES") + "'");
+ continue;
+ }
+
+ std::string key(line.substr(0, pos)), value(line.substr(pos + 1));
+ key = strip_leading(strip_trailing(key, " \t"), " \t");
+ value = strip_leading(strip_trailing(value, " \t"), " \t");
+ if (("Package" != key) && (skip_invalid_package))
+ {
+ skip_invalid_package = false;
+ continue;
+ }
+
+ if ("Package" == key)
+ {
+ CRANDescription::normalise_name(value);
+ last_package_name = value;
+ QualifiedPackageName package_name(CategoryNamePart("cran"), PackageNamePart(last_package_name));
+ _imp->package_names[package_name] = true;
+ }
+ else if ("Version" == key)
+ {
+ QualifiedPackageName package_name(CategoryNamePart("cran"), PackageNamePart(last_package_name));
+ CRANDescription::normalise_version(value);
+ VersionSpec version(value);
+ if (false == _imp->version_specs.insert(VersionsMap::value_type(package_name, version)).second)
+ {
+ skip_invalid_package = true;
+ Log::get_instance()->message(ll_warning, lc_context, "Multiple versions for package '"
+ + last_package_name + "'.");
+ continue;
+ }
+ }
+ else if ("Contains" == key)
+ {
+ std::list<std::string> contains;
+ WhitespaceTokeniser::get_instance()->tokenise(value, std::back_inserter(contains));
+ std::list<std::string>::const_iterator i(contains.begin()), i_end(contains.end());
+ // load metadata immediately
+ for ( ; i != i_end ; ++i)
+ {
+ Context c("When processing 'Contains:' line: '" + stringify(*i) + "':");
+
+ if (*i == last_package_name)
+ continue;
+
+ CRANDescription d(*i, FSEntry(_imp->location / std::string(last_package_name + ".DESCRIPTION")));
+
+ std::string dep(d.metadata->deps.build_depend_string);
+ std::string pkg(d.metadata->get_cran_interface()->package);
+ if ("" == dep)
+ dep = pkg;
+ else
+ dep += "," + pkg;
+ d.metadata->deps.build_depend_string = dep;
+
+ _imp->package_names[d.name] = true;
+ _imp->metadata.insert(std::make_pair(std::make_pair(d.name, d.version), d.metadata));
+ _imp->version_specs.insert(VersionsMap::value_type(d.name, d.version));
+ }
+ }
+ }
+
+ _imp->has_packages = true;
+}
+
+RepositoryName
+CRANRepository::fetch_repo_name(const std::string & location)
+{
+ std::string modified_location(FSEntry(location).basename());
+ std::replace(modified_location.begin(), modified_location.end(), '/', '-');
+ return RepositoryName("cran-" + modified_location);
+}
+
+VersionMetadata::ConstPointer
+CRANRepository::do_version_metadata(
+ const QualifiedPackageName & q, const VersionSpec & v) const
+{
+ if (_imp->metadata.end() != _imp->metadata.find(
+ std::make_pair(q, v)))
+ return _imp->metadata.find(std::make_pair(q, v))->second;
+
+ Context context("When fetching metadata for " + stringify(q) +
+ "-" + stringify(v));
+
+ if (! has_version(q, v))
+ throw NoSuchPackageError(stringify(PackageDatabaseEntry(q, v, name())));
+
+ VersionMetadata::Pointer result(new VersionMetadata(CRANDepParser::parse));
+
+ FSEntry d(_imp->location);
+ PackageNamePart p(q.package);
+ std::string n(stringify(p));
+ CRANDescription::denormalise_name(n);
+ d /= n + ".DESCRIPTION";
+
+ if (d.is_regular_file())
+ {
+ CRANDescription desc(stringify(p), d);
+ result = desc.metadata;
+ }
+ else
+ {
+ Log::get_instance()->message(ll_warning, lc_no_context, "has_version failed for request for '" +
+ stringify(q) + "-" + stringify(v) + "' in repository '" +
+ stringify(name()) + "': File '" + n + ".DESCRIPTION' not present.");
+ result.assign(new VersionMetadata(CRANDepParser::parse));
+ result->eapi = "UNKNOWN";
+ }
+
+ _imp->metadata.insert(std::make_pair(std::make_pair(q, v), result));
+ return result;
+}
+
+Contents::ConstPointer
+CRANRepository::do_contents(
+ const CategoryNamePart &, const PackageNamePart &, const VersionSpec &) const
+{
+ return Contents::Pointer(new Contents);
+}
+
+CountedPtr<Repository>
+CRANRepository::make_cran_repository(
+ const Environment * const env,
+ const PackageDatabase * const db,
+ AssociativeCollection<std::string, std::string>::ConstPointer m)
+{
+ Context context("When making CRAN repository from repo_file '" +
+ (m->end() == m->find("repo_file") ? std::string("?") : m->find("repo_file")->second) + "':");
+
+ std::string location;
+ if (m->end() == m->find("location") || ((location = m->find("location")->second)).empty())
+ throw CRANRepositoryConfigurationError("Key 'location' not specified or empty");
+
+ std::string library;
+ if (m->end() == m->find("library") || ((library = m->find("library")->second)).empty())
+ throw CRANRepositoryConfigurationError("Key 'library' not specified or empty");
+
+ std::string distdir;
+ if (m->end() == m->find("distdir") || ((distdir = m->find("distdir")->second)).empty())
+ distdir = location + "/distfiles";
+
+ std::string mirror;
+ if (m->end() == m->find("mirror") || ((mirror = m->find("mirror")->second)).empty())
+ mirror = "http://cran.r-project.org/";
+
+ std::string sync;
+ if (m->end() == m->find("sync") || ((sync = m->find("sync")->second)).empty())
+ sync = "rsync://cran.r-project.org/CRAN";
+
+ std::string buildroot;
+ if (m->end() == m->find("buildroot") || ((buildroot = m->find("buildroot")->second)).empty())
+ buildroot = "/var/tmp/paludis";
+
+ std::string root;
+ if (m->end() == m->find("root") || ((root = m->find("root")->second)).empty())
+ root = "/";
+
+ return CountedPtr<Repository>(new CRANRepository(CRANRepositoryParams::create()
+ .environment(env)
+ .package_database(db)
+ .location(location)
+ .distdir(distdir)
+ .sync(sync)
+ .buildroot(buildroot)
+ .root(root)
+ .library(library)
+ .mirror(mirror)));
+}
+
+CRANRepositoryConfigurationError::CRANRepositoryConfigurationError(
+ const std::string & msg) throw () :
+ ConfigurationError("CRAN repository configuration error: " + msg)
+{
+}
+
+bool
+CRANRepository::do_is_licence(const std::string &) const
+{
+ return false;
+}
+
+void
+CRANRepository::do_install(const QualifiedPackageName &q, const VersionSpec &vn,
+ const InstallOptions &o) const
+{
+ PackageNamePart pn(q.package);
+ CategoryNamePart c("cran");
+ VersionMetadata::ConstPointer vm(do_version_metadata(q, vn));
+ std::string p(vm->get_cran_interface()->package);
+ std::string v(vm->get_cran_interface()->version);
+
+ MakeEnvCommand cmd(LIBEXECDIR "/paludis/cran.bash fetch", "");
+ cmd = cmd("CATEGORY", "cran");
+ cmd = cmd("DISTDIR", stringify(_imp->distdir));
+ cmd = cmd("DISTFILE", std::string(p + "_" + v + ".tar.gz"));
+ cmd = cmd("PN", stringify(pn));
+ cmd = cmd("PV", stringify(vn));
+ cmd = cmd("PALUDIS_CRAN_MIRRORS", _imp->mirror);
+ cmd = cmd("PALUDIS_EBUILD_DIR", std::string(LIBEXECDIR "/paludis/"));
+ cmd = cmd("PALUDIS_EBUILD_LOG_LEVEL", stringify(Log::get_instance()->log_level()));
+ cmd = cmd("PALUDIS_BASHRC_FILES", _imp->env->bashrc_files());
+
+
+ if (0 != run_command(cmd))
+ throw PackageInstallActionError("Couldn't fetch sources for '" + stringify(q) + "-" + stringify(vn) + "'");
+
+ if (o.fetch_only)
+ return;
+
+ std::string image(stringify(_imp->buildroot / stringify(q) / "image"));
+ std::string workdir(stringify(_imp->buildroot / stringify(q) / "work"));
+
+ cmd = MakeEnvCommand(make_sandbox_command(LIBEXECDIR "/paludis/cran.bash clean install"), "");
+ cmd = cmd("CATEGORY", "cran");
+ cmd = cmd("DISTDIR", stringify(_imp->distdir));
+ cmd = cmd("DISTFILE", std::string(p + "_" + v + ".tar.gz"));
+ cmd = cmd("IMAGE", image);
+ cmd = cmd("PN", stringify(pn));
+ cmd = cmd("PV", stringify(vn));
+ cmd = cmd("PALUDIS_CRAN_LIBRARY", stringify(_imp->library));
+ cmd = cmd("PALUDIS_EBUILD_DIR", std::string(LIBEXECDIR "/paludis/"));
+ cmd = cmd("PALUDIS_EBUILD_LOG_LEVEL", stringify(Log::get_instance()->log_level()));
+ cmd = cmd("PALUDIS_BASHRC_FILES", _imp->env->bashrc_files());
+ cmd = cmd("ROOT", stringify(_imp->root));
+ cmd = cmd("WORKDIR", workdir);
+
+
+ if (0 != run_command(cmd))
+ throw PackageInstallActionError("Couldn't install '" + stringify(q) + "-" + stringify(vn) + "' to '" +
+ image + "'");
+
+ cmd = MakeEnvCommand(LIBEXECDIR "/paludis/cran.bash merge clean", "");
+ cmd = cmd("IMAGE", image);
+ cmd = cmd("PN", p);
+ cmd = cmd("PV", stringify(vn));
+ cmd = cmd("PALUDIS_CRAN_LIBRARY", stringify(_imp->library));
+ cmd = cmd("PALUDIS_EBUILD_DIR", std::string(LIBEXECDIR "/paludis/"));
+ cmd = cmd("PALUDIS_EBUILD_LOG_LEVEL", stringify(Log::get_instance()->log_level()));
+ cmd = cmd("PALUDIS_BASHRC_FILES", _imp->env->bashrc_files());
+ cmd = cmd("ROOT", stringify(_imp->root));
+ cmd = cmd("WORKDIR", workdir);
+
+
+ if (0 != run_command(cmd))
+ throw PackageInstallActionError("Couldn't merge '" + stringify(q) + "-" + stringify(vn) + "' to '" +
+ stringify(_imp->root) + "'");
+
+ return;
+}
+
+DepAtom::Pointer
+CRANRepository::do_package_set(const std::string & s) const
+{
+ if ("base" == s)
+ {
+ /**
+ * \todo Implement system as all package which are installed
+ * by dev-lang/R by default.
+ */
+ return AllDepAtom::Pointer(new AllDepAtom);
+ }
+ else
+ return DepAtom::Pointer(0);
+}
+
+SetsCollection::ConstPointer
+CRANRepository::sets_list() const
+{
+ Context context("While generating the list of sets:");
+
+ SetsCollection::Pointer result(new SetsCollection::Concrete);
+ result->insert("base");
+ return result;
+}
+
+bool
+CRANRepository::do_sync() const
+{
+ Context context("When syncing repository '" + stringify(name()) + "':");
+
+ std::string cmd("rsync --delete --recursive --progress --exclude \"*.html\" --exclude \"*.INDEX\" '" +
+ _imp->sync + "/src/contrib/Descriptions/' ./");
+
+ if (0 != run_command_in_directory(cmd, _imp->location))
+ return false;
+
+ cmd = "rsync --progress '" + _imp->sync + "/src/contrib/PACKAGES' ./";
+
+ if (0 != run_command_in_directory(cmd, _imp->location))
+ return false;
+
+ cmd = "rsync --progress '" + _imp->sync + "/CRAN_mirrors.csv' ./";
+
+ return 0 == run_command_in_directory(cmd, _imp->location);
+}
+
+void
+CRANRepository::invalidate() const
+{
+ _imp->invalidate();
+}
+
+#ifdef PALUDIS_ENABLE_VISIBILITY
+# pragma GCC visibility push(default)
+#endif
+namespace
+{
+ const RepositoryMaker::RegisterMaker register_cran_repository PALUDIS_ATTRIBUTE((used)) (
+ "cran", &CRANRepository::make_cran_repository);
+}
+#ifdef PALUDIS_ENABLE_VISIBILITY
+# pragma GCC visibility pop
+#endif
+
diff --git a/0.8.0/paludis/repositories/cran/cran_repository.hh b/0.8.0/paludis/repositories/cran/cran_repository.hh
new file mode 100644
index 0000000..fcaf61b
--- /dev/null
+++ b/0.8.0/paludis/repositories/cran/cran_repository.hh
@@ -0,0 +1,137 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Danny van Dyk <kugelfang@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_CRAN_REPOSITORY_HH
+#define PALUDIS_GUARD_PALUDIS_CRAN_REPOSITORY_HH 1
+
+#include <paludis/repository.hh>
+#include <paludis/util/fs_entry.hh>
+#include <paludis/util/private_implementation_pattern.hh>
+#include <string>
+
+/** \file
+ * Declaration for the CRANRepository class.
+ *
+ * \ingroup grpcranrepository
+ */
+
+namespace paludis
+{
+ class PackageDatabase;
+
+#include <paludis/repositories/cran/cran_repository-sr.hh>
+
+ /**
+ * A CRANRepository is a Repository that handles the layout used by
+ * the GNU R project for the Comprehensive R Archive Network
+ *
+ * \ingroup grpcranrepository
+ */
+ class PALUDIS_VISIBLE CRANRepository :
+ public Repository,
+ public RepositoryInstallableInterface,
+ public RepositorySyncableInterface,
+ public RepositorySetsInterface,
+ private PrivateImplementationPattern<CRANRepository>
+ {
+ private:
+ void need_packages() const;
+ void need_version_names(const QualifiedPackageName &) const;
+ void need_virtual_names() const;
+
+ protected:
+ /**
+ * Try to get the repository name for a particular repository.
+ */
+ static RepositoryName fetch_repo_name(const std::string & location);
+
+ virtual bool do_has_category_named(const CategoryNamePart &) const;
+
+ virtual bool do_has_package_named(const QualifiedPackageName &) const;
+
+ virtual CategoryNamePartCollection::ConstPointer do_category_names() const;
+
+ virtual QualifiedPackageNameCollection::ConstPointer do_package_names(
+ const CategoryNamePart &) const;
+
+ virtual VersionSpecCollection::ConstPointer do_version_specs(
+ const QualifiedPackageName &) const;
+
+ virtual bool do_has_version(const QualifiedPackageName &,
+ const VersionSpec &) const;
+
+ virtual VersionMetadata::ConstPointer do_version_metadata(
+ const QualifiedPackageName &,
+ const VersionSpec &) const;
+
+ virtual Contents::ConstPointer do_contents(
+ const CategoryNamePart &, const PackageNamePart &,
+ const VersionSpec &) const;
+
+ virtual bool do_is_licence(const std::string &) const;
+
+ virtual void do_install(const QualifiedPackageName &, const VersionSpec &,
+ const InstallOptions &) const;
+
+ virtual DepAtom::Pointer do_package_set(const std::string &) const;
+
+ virtual SetsCollection::ConstPointer sets_list() const;
+
+ virtual bool do_sync() const;
+
+ public:
+ /**
+ * Constructor.
+ */
+ CRANRepository(const CRANRepositoryParams &);
+
+ /**
+ * Virtual constructor.
+ */
+ static CountedPtr<Repository> make_cran_repository(
+ const Environment * const env,
+ const PackageDatabase * const db,
+ AssociativeCollection<std::string, std::string>::ConstPointer m);
+
+ /**
+ * Destructor.
+ */
+ virtual ~CRANRepository();
+
+ virtual void invalidate() const;
+ };
+
+ /**
+ * Thrown if invalid parameters are provided for
+ * CRANRepository::make_cran_repository.
+ *
+ * \ingroup grpexceptions
+ * \ingroup grpportagerepository
+ */
+ class PALUDIS_VISIBLE CRANRepositoryConfigurationError : public ConfigurationError
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ CRANRepositoryConfigurationError(const std::string & msg) throw ();
+ };
+}
+
+#endif
diff --git a/0.8.0/paludis/repositories/cran/cran_repository.sr b/0.8.0/paludis/repositories/cran/cran_repository.sr
new file mode 100644
index 0000000..fb4344d
--- /dev/null
+++ b/0.8.0/paludis/repositories/cran/cran_repository.sr
@@ -0,0 +1,27 @@
+#!/bin/bash
+# vim: set sw=4 sts=4 et :
+
+make_class_CRANRepositoryParams()
+{
+ key environment "const Environment *"
+ key package_database "const PackageDatabase *"
+ key location FSEntry
+ key distdir FSEntry
+ key mirror std::string
+ key sync std::string
+ key buildroot FSEntry
+ key root FSEntry
+ key library FSEntry
+
+ doxygen_comment << "END"
+ /**
+ * Parameters used to create a CRANRepository
+ *
+ * \see CRANRepository
+ * \ingroup grpcranrepository
+ */
+END
+
+ allow_named_args
+}
+
diff --git a/0.8.0/paludis/repositories/cran/cran_repository_TEST.cc b/0.8.0/paludis/repositories/cran/cran_repository_TEST.cc
new file mode 100644
index 0000000..850b0c4
--- /dev/null
+++ b/0.8.0/paludis/repositories/cran/cran_repository_TEST.cc
@@ -0,0 +1,97 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Danny van Dyk <kugelfang@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 <paludis/dep_atom.hh>
+#include <paludis/dep_atom_flattener.hh>
+#include <paludis/repositories/cran/cran_dep_parser.hh>
+#include <paludis/repositories/cran/cran_description.hh>
+#include <paludis/repositories/cran/cran_repository.hh>
+#include <paludis/environment/test/test_environment.hh>
+#include <paludis/util/collection_concrete.hh>
+#include <paludis/util/system.hh>
+#include <test/test_framework.hh>
+#include <test/test_runner.hh>
+
+using namespace test;
+using namespace paludis;
+
+/** \file
+ * Test cases for CRANRepository.
+ *
+ * \ingroup grptestcases
+ */
+
+namespace test_cases
+{
+ /**
+ * \test Test CRANRepository to parse a well formed PACKAGES file.
+ *
+ * \ingroup grptestcases
+ */
+ struct CRANRepositoryPackagesTest : TestCase
+ {
+ CRANRepositoryPackagesTest() : TestCase("PACKAGES") { }
+
+ void run()
+ {
+ TestEnvironment env;
+ AssociativeCollection<std::string, std::string>::Pointer keys(
+ new AssociativeCollection<std::string, std::string>::Concrete);
+ keys->insert("format", "cran");
+ keys->insert("library", "cran_repository_TEST_dir/library");
+ keys->insert("location", "cran_repository_TEST_dir/repo1");
+ keys->insert("buildroot", "cran_repository_TEST_dir/tmp");
+ CRANRepository::Pointer repo(CRANRepository::make_cran_repository(
+ &env, env.package_database().raw_pointer(), keys));
+ TEST_CHECK(repo->has_category_named(CategoryNamePart("cran")));
+ TEST_CHECK(repo->has_package_named(QualifiedPackageName("cran/testpackage1")));
+ TEST_CHECK(repo->has_package_named(QualifiedPackageName("cran/testpackage2")));
+ }
+ } test_cran_repository_packages;
+
+ /**
+ * \test Test CRANRepository to handly 'Bundle:'s correctly.
+ *
+ * \ingroup grptestcases
+ */
+ struct CRANRepositoryBundleTest: TestCase
+ {
+ CRANRepositoryBundleTest() : TestCase("Bundle") { }
+
+ void run()
+ {
+ TestEnvironment env;
+ AssociativeCollection<std::string, std::string>::Pointer keys(
+ new AssociativeCollection<std::string, std::string>::Concrete);
+ keys->insert("format", "cran");
+ keys->insert("library", "cran_repository_TEST_dir/library");
+ keys->insert("location", "cran_repository_TEST_dir/repo2");
+ keys->insert("buildroot", "cran_repository_TEST_dir/tmp");
+ CRANRepository::Pointer repo(CRANRepository::make_cran_repository(
+ &env, env.package_database().raw_pointer(), keys));
+ TEST_CHECK(repo->has_package_named(QualifiedPackageName("cran/testbundle")));
+ TEST_CHECK(repo->has_package_named(QualifiedPackageName("cran/bundlepkg1")));
+ TEST_CHECK(repo->has_package_named(QualifiedPackageName("cran/bundlepkg2")));
+ }
+ } test_cran_repository_bundle;
+
+ /** \todo in repo1
+ * \todo test case for DESCRIPTION files
+ */
+}
diff --git a/0.8.0/paludis/repositories/cran/cran_repository_TEST_cleanup.sh b/0.8.0/paludis/repositories/cran/cran_repository_TEST_cleanup.sh
new file mode 100755
index 0000000..d304922
--- /dev/null
+++ b/0.8.0/paludis/repositories/cran/cran_repository_TEST_cleanup.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+# vim: set ft=sh sw=4 sts=4 et :
+
+if [ -d cran_repository_TEST_dir ] ; then
+ rm -fr cran_repository_TEST_dir
+else
+ true
+fi
diff --git a/0.8.0/paludis/repositories/cran/cran_repository_TEST_setup.sh b/0.8.0/paludis/repositories/cran/cran_repository_TEST_setup.sh
new file mode 100755
index 0000000..93fdbee
--- /dev/null
+++ b/0.8.0/paludis/repositories/cran/cran_repository_TEST_setup.sh
@@ -0,0 +1,57 @@
+#!/bin/sh
+# vim: set ft=sh sw=4 sts=4 et :
+
+mkdir cran_repository_TEST_dir || exit 1
+cd cran_repository_TEST_dir || exit 1
+
+# repo1
+mkdir -p repo1
+cat <<EOF >> repo1/PACKAGES
+Package: testpackage1
+Version: 2006.05.08
+Title: Test on a well formed PACKAGES file
+Depends: R (>= 2.0.0)
+
+
+Package: testpackage2
+Version: 2006.05.08
+Title: Test on a well formed PACKAGES file
+EOF
+cat <<EOF >> repo1/testpackage1.DESCRIPTION
+Package: testpackage1
+Version: 2006.05.08
+Title: Test on a well formed PACKAGES file
+Depends: R (>= 2.0.0)
+Description: This description
+ spans
+ multiple lines without
+ trailing backslashes or leading tabs :-/
+License: Some weirdo license string
+Packaged: Mon May 08 12:00:00 2006; kugelfang
+EOF
+cat <<EOF >> repo1/testpackage2.DESCRIPTION
+Package: testpackage2
+Version: 1
+Title: 2nd Test Packages
+Depends: R, testpackage1
+License: Another weirdo license string
+Packaged: Mon May 08 22:00:00 2006; kugelfang
+EOF
+
+mkdir -p repo2
+cat <<EOF >> repo2/PACKAGES
+Package: testbundle
+Version: 1
+Title: Testbundle for bundlepkg1 and bundlepkg2
+Bundle: testbundle
+Contains: bundlepkg1 bundlepkg2
+EOF
+cat <<EOF >> repo2/testbundle.DESCRIPTION
+Bundle: testbundle
+Version: 1
+Date: 21 May 2006
+Title: Testbundle for bundlepkg1 and bundlepkg2
+Contains: bundlepkg1 bundlepkg2
+License: Weird obfuscation of GPL
+Packaged: Sun May 21 12:34:56 2006; kugelfang
+EOF