diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2018-09-10 22:02:58 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2018-09-10 22:31:44 +0300 |
commit | dd0d442618e51f73647c9514e3f3eb718946426d (patch) | |
tree | 863dbf205aa44a691b0a5ece007d928ac1fdc970 /mod | |
parent | b777cee2a0e5bb2d6c2d552d11c59672b0db8aa7 (diff) |
Add build-configs service
Diffstat (limited to 'mod')
-rw-r--r-- | mod/mod-build-configs.cxx | 104 | ||||
-rw-r--r-- | mod/mod-build-configs.hxx | 48 | ||||
-rw-r--r-- | mod/mod-repository-root.cxx | 18 | ||||
-rw-r--r-- | mod/mod-repository-root.hxx | 2 | ||||
-rw-r--r-- | mod/options.cli | 10 |
5 files changed, 181 insertions, 1 deletions
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 <mod/mod-build-configs.hxx> + +#include <libstudxml/serializer.hxx> + +#include <web/xhtml.hxx> +#include <web/module.hxx> + +#include <mod/page.hxx> +#include <mod/options.hxx> +#include <mod/build-config.hxx> + +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<options::build_configs> ( + 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 <libbrep/types.hxx> +#include <libbrep/utility.hxx> + +#include <libbbot/build-config.hxx> + +#include <mod/module.hxx> +#include <mod/options.hxx> + +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::build_configs> options_; + shared_ptr<const bbot::build_configs> 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 <mod/mod-build-task.hxx> #include <mod/mod-build-force.hxx> #include <mod/mod-build-result.hxx> +#include <mod/mod-build-configs.hxx> #include <mod/mod-package-details.hxx> #include <mod/mod-repository-details.hxx> #include <mod/mod-package-version-details.hxx> @@ -115,6 +116,7 @@ namespace brep build_force_ (make_shared<build_force> ()), build_log_ (make_shared<build_log> ()), builds_ (make_shared<builds> ()), + build_configs_ (make_shared<build_configs> ()), submit_ (make_shared<submit> ()), ci_ (make_shared<ci> ()) { @@ -164,6 +166,10 @@ namespace brep r.initialized_ ? r.builds_ : make_shared<builds> (*r.builds_)), + build_configs_ ( + r.initialized_ + ? r.build_configs_ + : make_shared<build_configs> (*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> build_force_; shared_ptr<build_log> build_log_; shared_ptr<builds> builds_; + shared_ptr<build_configs> build_configs_; shared_ptr<submit> submit_; shared_ptr<ci> 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). // |