Permalink
Browse files

Initial import of development tools.

This first import contains a functional module package builder.
  • Loading branch information...
mmakaay committed Jul 24, 2011
0 parents commit 4b949784d3a70c78d0db902964ac47cbd10f9856
Showing with 1,166 additions and 0 deletions.
  1. +98 −0 bin/build_phorum_module
  2. +109 −0 lib/Phorum/ModuleBuilder.php
  3. +382 −0 lib/Phorum/ModuleInfo.php
  4. +577 −0 lib/Phorum/PackageBuilder.php
@@ -0,0 +1,98 @@
+#!/usr/bin/env php
+<?php
+
+require_once dirname(__FILE__) . '/../lib/Phorum/ModuleBuilder.php';
+
+// ----------------------------------------------------------------------
+// Parse arguments
+// ----------------------------------------------------------------------
+
+$args = array();
+
+$verbose = FALSE;
+$build_dir = "/tmp";
+
+for ($i = 1; $i < $_SERVER['argc']; $i++)
+{
+ $opt = $_SERVER['argv'][$i];
+
+ // Gather non-options.
+ if ($opt[0] != '-') {
+ $args[] = $opt;
+ continue;
+ }
+
+ // Process options.
+ switch ($opt)
+ {
+ case "-h":
+ usage();
+ exit;
+ break;
+
+ case "-v":
+ $verbose = TRUE;
+ break;
+
+ case "-b":
+ if (!isset($_SERVER['argv'][++$i])) {
+ die("Missing value for option -b!\n");
+ }
+ $build_dir = $_SERVER['argv'][$i];
+ break;
+
+ default:
+ die("Unknown option: $opt\n");
+ }
+}
+
+$count = count($args);
+switch ($count)
+{
+ case 0 : $module_dir = getcwd(); break;
+ case 1 : $module_dir = $args[0]; break;
+ default : die("Only one module dir expected, but got $count!\n");
+}
+
+// ----------------------------------------------------------------------
+// Generate the module package
+// ----------------------------------------------------------------------
+
+try
+{
+ $builder = new Phorum_ModuleBuilder($module_dir, $build_dir);
+ if ($verbose) $builder->enableScreenLogger();
+ $output = $builder->build();
+ if (!$verbose) {
+ print "Package archives created:\n";
+ foreach ($output as $file) {
+ print "> $file\n";
+ }
+ }
+}
+catch (Exception $e)
+{
+ die("Error: " . $e->getMessage() . "\n");
+}
+
+// ----------------------------------------------------------------------
+// Utility functions
+// ----------------------------------------------------------------------
+
+function usage()
+{
+ $program = basename($_SERVER['argv'][0]);
+
+ print "\n";
+ print "Usage: $program [OPTIONS] [MODULE DIR]\n";
+ print "\n";
+ print " -h : Show this help.\n";
+ print " -v : Enable verbose output.\n";
+ print " -b <path> : The working directory for building the module\n";
+ print " package. By default, /tmp is used.\n";
+ print "\n";
+ print " MODULE DIR : The path to the Phorum module for which to\n";
+ print " build a distribution package. By default,\n";
+ print " the active working directory is used.\n";
+ print "\n";
+}
@@ -0,0 +1,109 @@
+<?php
+/**
+ * This script implements the Phorum_ModuleBuilder class.
+ *
+ * @author Maurice Makaay
+ * @copyright Phorum
+ * @package Phorum
+ * @category DevTools
+ */
+
+require_once dirname(__FILE__) . "/ModuleInfo.php";
+require_once dirname(__FILE__) . "/PackageBuilder.php";
+
+/**
+ * The Phorum_ModuleBuilder class.
+ *
+ * This class provides functionality for packaging a Phorum module
+ * into a format that can be used for distribution.
+ *
+ * @package Phorum
+ */
+class Phorum_ModuleBuilder extends Phorum_PackageBuilder
+{
+ /**
+ * An object that contains information about the Phorum module.
+ *
+ * @var Phorum_ModuleInfo
+ */
+ protected $_module_info;
+
+ /**
+ * Create a new Phorum ModuleBuilder object.
+ *
+ * @param string $path
+ * The path for the directory where the module code is stored (this is
+ * the directory with the info.txt in it).
+ *
+ * @param string $build_dir
+ * The working directory for building the package (default is "/tmp").
+ *
+ * @throws Exception
+ * when illegal parameters are used.
+ */
+ public function __construct($path, $build_dir = "/tmp")
+ {
+ if (!is_dir($path)) throw new Exception(
+ "Illegal module source dir '$path' provided: " .
+ "not a directory"
+ );
+
+ $info_file = realpath("$path/info.txt");
+ if (!file_exists($info_file)) throw new Exception(
+ "Illegal module source dir '$path' provided: " .
+ "no info.txt file found"
+ );
+
+ if (!is_dir($build_dir)) throw new Exception(
+ "Illegal build dir '$build_dir' provided: not a directory"
+ );
+
+ // Initialize a module info object, used for gathering information
+ // about the module. We will use this object at various places during
+ // building the package.
+ $this->_module_info = new Phorum_ModuleInfo();
+ $this->_module_info->load($info_file);
+
+ parent::__construct($this->_module_info->getID(), $path, $build_dir);
+ }
+
+ /**
+ * Retrieve the version of the package.
+ * This version is read from the module info.txt file.
+ *
+ * @return string
+ */
+ protected function _getPackageVersion()
+ {
+ return $this->_module_info->getVersion();
+ }
+
+ /**
+ * Retrieve the directory where the package is built.
+ *
+ * Overridden from Phorum_PackageBuilder to keep out the
+ * version number of the directory. For Phorum modules, it's
+ * easiest to not have the version number included in the
+ * packaged directory.
+ *
+ * @return string
+ */
+ protected function _getBuildPackageDir()
+ {
+ return $this->_build_dir . '/' . $this->_package_name;
+ }
+
+ protected function _substituteTags($data)
+ {
+ $data = str_replace('@TITLE@', $this->_module_info->getTitle(), $data);
+ $data = str_replace('@MODULE_ID@', $this->_module_info->getId(), $data);
+
+ $description = wordwrap(
+ strip_tags($this->_module_info->getDescription()), 72
+ );
+ $data = str_replace('@DESCRIPTION@', $description, $data);
+
+ return parent::_substituteTags($data);
+ }
+}
+
Oops, something went wrong.

0 comments on commit 4b94978

Please sign in to comment.