From dd0d442618e51f73647c9514e3f3eb718946426d Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 10 Sep 2018 22:02:58 +0300 Subject: Add build-configs service --- etc/brep-module.conf | 1 + mod/mod-build-configs.cxx | 104 ++++++++++++++++++++++++++++++++++++++++++++ mod/mod-build-configs.hxx | 48 ++++++++++++++++++++ mod/mod-repository-root.cxx | 18 +++++++- mod/mod-repository-root.hxx | 2 + mod/options.cli | 10 +++++ www/build-configs-body.css | 6 +++ www/build-configs.css | 3 ++ www/build-configs.scss | 3 ++ 9 files changed, 194 insertions(+), 1 deletion(-) create mode 100644 mod/mod-build-configs.cxx create mode 100644 mod/mod-build-configs.hxx create mode 100644 www/build-configs-body.css create mode 100644 www/build-configs.css create mode 100644 www/build-configs.scss diff --git a/etc/brep-module.conf b/etc/brep-module.conf index 6608f6b..5602d61 100644 --- a/etc/brep-module.conf +++ b/etc/brep-module.conf @@ -22,6 +22,7 @@ # menu Packages= # menu Builds=?builds +# menu Configs=?build-configs # menu Submit=?submit # menu CI=?ci menu About=?about diff --git a/mod/mod-build-configs.cxx b/mod/mod-build-configs.cxx new file mode 100644 index 0000000..63bbe0b --- /dev/null +++ b/mod/mod-build-configs.cxx @@ -0,0 +1,104 @@ +// file : mod/mod-build-configs.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include + +#include + +#include +#include + +#include +#include +#include + +using namespace std; +using namespace bbot; +using namespace brep::cli; + +// While currently the user-defined copy constructor is not required (we don't +// need to deep copy nullptr's), it is a good idea to keep the placeholder +// ready for less trivial cases. +// +brep::build_configs:: +build_configs (const build_configs& r) + : handler (r), + options_ (r.initialized_ ? r.options_ : nullptr), + build_conf_ (r.initialized_ ? r.build_conf_ : nullptr) +{ +} + +void brep::build_configs:: +init (scanner& s) +{ + HANDLER_DIAG; + + options_ = make_shared ( + s, unknown_mode::fail, unknown_mode::fail); + + if (options_->build_config_specified ()) + try + { + build_conf_ = shared_build_config (options_->build_config ()); + } + catch (const io_error& e) + { + fail << "unable to read build configuration '" + << options_->build_config () << "': " << e; + } +} + +bool brep::build_configs:: +handle (request& rq, response& rs) +{ + using namespace web::xhtml; + + HANDLER_DIAG; + + if (build_conf_ == nullptr) + throw invalid_request (501, "not implemented"); + + const dir_path& root (options_->root ()); + + // Make sure no parameters passed. + // + try + { + name_value_scanner s (rq.parameters (1024)); + params::build_configs (s, unknown_mode::fail, unknown_mode::fail); + } + catch (const cli::exception& e) + { + throw invalid_request (400, e.what ()); + } + + static const string title ("Build Configurations"); + xml::serializer s (rs.content (), title); + + s << HTML + << HEAD + << TITLE << title << ~TITLE + << CSS_LINKS (path ("build-configs.css"), root) + << ~HEAD + << BODY + << DIV_HEADER (options_->logo (), options_->menu (), root, tenant) + << DIV(ID="content") + << TABLE(CLASS="proplist") + << TBODY; + + for (const build_config& c: *build_conf_) + { + s << TR(CLASS="config") + << TD << SPAN(CLASS="value") << c.name << ~SPAN << ~TD + << ~TR; + } + + s << ~TBODY + << ~TABLE + << ~DIV + << ~BODY + << ~HTML; + + return true; +} diff --git a/mod/mod-build-configs.hxx b/mod/mod-build-configs.hxx new file mode 100644 index 0000000..0c57359 --- /dev/null +++ b/mod/mod-build-configs.hxx @@ -0,0 +1,48 @@ +// file : mod/mod-build-configs.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef MOD_MOD_BUILD_CONFIGS_HXX +#define MOD_MOD_BUILD_CONFIGS_HXX + +#include +#include + +#include + +#include +#include + +namespace brep +{ + class build_configs: public handler + { + public: + build_configs () = default; + + // Create a shallow copy (handling instance) if initialized and a deep + // copy (context exemplar) otherwise. + // + explicit + build_configs (const build_configs&); + + virtual bool + handle (request&, response&); + + virtual const cli::options& + cli_options () const + { + return options::build_configs::description (); + } + + private: + virtual void + init (cli::scanner&); + + private: + shared_ptr options_; + shared_ptr build_conf_; + }; +} + +#endif // MOD_MOD_BUILD_CONFIGS_HXX diff --git a/mod/mod-repository-root.cxx b/mod/mod-repository-root.cxx index b825ea1..bdabf9c 100644 --- a/mod/mod-repository-root.cxx +++ b/mod/mod-repository-root.cxx @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -115,6 +116,7 @@ namespace brep build_force_ (make_shared ()), build_log_ (make_shared ()), builds_ (make_shared ()), + build_configs_ (make_shared ()), submit_ (make_shared ()), ci_ (make_shared ()) { @@ -164,6 +166,10 @@ namespace brep r.initialized_ ? r.builds_ : make_shared (*r.builds_)), + build_configs_ ( + r.initialized_ + ? r.build_configs_ + : make_shared (*r.build_configs_)), submit_ ( r.initialized_ ? r.submit_ @@ -195,6 +201,7 @@ namespace brep append (r, build_force_->options ()); append (r, build_log_->options ()); append (r, builds_->options ()); + append (r, build_configs_->options ()); append (r, submit_->options ()); append (r, ci_->options ()); return r; @@ -239,6 +246,7 @@ namespace brep sub_init (*build_force_, "build_force"); sub_init (*build_log_, "build_log"); sub_init (*builds_, "builds"); + sub_init (*build_configs_, "build_configs"); sub_init (*submit_, "submit"); sub_init (*ci_, "ci"); @@ -260,7 +268,8 @@ namespace brep // auto verify = [&fail] (const string& v, const char* what) { - cstrings vs ({"packages", "builds", "about", "submit", "ci"}); + cstrings vs ({ + "packages", "builds", "build-configs", "about", "submit", "ci"}); if (find (vs.begin (), vs.end (), v) == vs.end ()) fail << what << " value '" << v << "' is invalid"; @@ -396,6 +405,13 @@ namespace brep return handle ("builds", param); } + else if (func == "build-configs") + { + if (handler_ == nullptr) + handler_.reset (new build_configs (*build_configs_)); + + return handle ("build_configs", param); + } else if (func == "packages") { if (handler_ == nullptr) diff --git a/mod/mod-repository-root.hxx b/mod/mod-repository-root.hxx index a46f43f..83d9bee 100644 --- a/mod/mod-repository-root.hxx +++ b/mod/mod-repository-root.hxx @@ -22,6 +22,7 @@ namespace brep class build_force; class build_log; class builds; + class build_configs; class submit; class ci; @@ -67,6 +68,7 @@ namespace brep shared_ptr build_force_; shared_ptr build_log_; shared_ptr builds_; + shared_ptr build_configs_; shared_ptr submit_; shared_ptr ci_; diff --git a/mod/options.cli b/mod/options.cli index d5d4e61..5fbd117 100644 --- a/mod/options.cli +++ b/mod/options.cli @@ -391,6 +391,10 @@ namespace brep } }; + class build_configs: build, page, handler + { + }; + class submit: page, handler { dir_path submit-data @@ -714,6 +718,12 @@ namespace brep string result | rs = "*"; }; + class build_configs + { + // No parameters so far. + // + }; + // Parameters, except simulate, must either be all present (actual // submission) or absent (submission form request). // diff --git a/www/build-configs-body.css b/www/build-configs-body.css new file mode 100644 index 0000000..5250573 --- /dev/null +++ b/www/build-configs-body.css @@ -0,0 +1,6 @@ +tr.config td .value +{ + /* style. */ + font-family: monospace; + font-size: 0.94em; +} diff --git a/www/build-configs.css b/www/build-configs.css new file mode 100644 index 0000000..f23b91b --- /dev/null +++ b/www/build-configs.css @@ -0,0 +1,3 @@ +@import url(common.css); +@import url(brep-common.css); +@import url(build-configs-body.css); diff --git a/www/build-configs.scss b/www/build-configs.scss new file mode 100644 index 0000000..c2d97d3 --- /dev/null +++ b/www/build-configs.scss @@ -0,0 +1,3 @@ +@import "common"; +@import "brep-common"; +@import "build-configs-body"; -- cgit v1.1