productize

This commit is contained in:
tmont 2009-06-14 00:18:46 +00:00
parent 98b11c6870
commit 258ae5874c
6 changed files with 149 additions and 6 deletions

View File

@ -6,6 +6,7 @@
<target name="clean" depends="init" description="Cleans up artifacts created by the build">
<delete dir="${build.base}"/>
<delete file="${dir.src}/${ant.project.name}/util/Product.php"/>
</target>
<target name="help" depends="set-exe-suffix" description="Displays information about available targets">
@ -23,7 +24,7 @@
</apply>
</target>
<target name="manifest" depends="init" description="Builds the manifest file for the autoload mechanism (to ./inc/manifest.php)">
<target name="manifest" depends="init, product" description="Builds the manifest file for the autoload mechanism (to ./inc/manifest.php)">
<exec executable="php">
<arg line="${dir.tools}/manifester.php"/>
<arg line="-d ${dir.src}/${ant.project.name}"/>
@ -35,6 +36,19 @@
</exec>
</target>
<target name="product" depends="init" description="Generates Product.php (product meta information)">
<exec executable="php">
<arg line="${dir.tools}/productize.php"/>
<arg line="-n ${product.name}"/>
<arg line="-v ${product.version}"/>
<arg line="-a"/>
<arg line="${product.author}"/>
<arg line="-w ${product.website}"/>
<arg line="-p ${ant.project.name}"/>
<arg line="-o ${dir.src}/${ant.project.name}/util/Product.php"/>
</exec>
</target>
<!--
INTERNAL TARGETS
-->

View File

@ -1,4 +1,4 @@
name=TUnit
version=0.1.0
author=Tommy Montgomery
author="Tommy Montgomery"
website=http://tommymontgomery.com/

View File

@ -13,8 +13,6 @@
break;
}
$line .= $frame['file'] . ' (' . $frame['line'] . ') ';
} else {
$line .= '<internal function> ';
}
if (isset($frame['class']) || isset($frame['function'])) {

View File

@ -3,7 +3,7 @@
/**
* Autoload manifest
*
* Autogenerated by manifester.php on 2009-06-13 15:51:52
* Autogenerated by manifester.php on 2009-06-13 17:17:25
*
* @package TUnit
* @version 0.1.0
@ -27,6 +27,7 @@
'IgnoredTest' => 'TUnit/framework/result/FailedTest.php',
'IgnoredTestResult' => 'TUnit/framework/result/IgnoredTestResult.php',
'PassedTestResult' => 'TUnit/framework/result/PassedTestResult.php',
'Product' => 'TUnit/util/Product.php',
'RecursiveTestIterator' => 'TUnit/util/RecursiveTestIterator.php',
'SingleTestResult' => 'TUnit/framework/result/SingleTestResult.php',
'TestCase' => 'TUnit/framework/test/TestCase.php',

View File

@ -40,7 +40,7 @@
$switches->addSwitch(new CliSwitch('directory', 'd', true, 'dir1,dir2,...', 'Comma-delimited list of directories'))
->addSwitch(new CliSwitch('version', 'v', true, 'version_number', 'Version number for use in @version tag'))
->addSwitch(new CliSwitch('package', 'p', true, 'package_name ', 'Name of the package for use in @package tag'))
->addSwitch(new CliSwitch('output', 'o', false, 'file', 'Name of the output file, defaults to stdout if empty and this is really really really really long'))
->addSwitch(new CliSwitch('output', 'o', false, 'file', 'Name of the output file, defaults to stdout if empty'))
->addSwitch(new CliSwitch('quiet', 'q', false, null, 'Do not print progress messages'))
->addSwitch(new CliSwitch('recursive', 'r', false, null, 'Recursively walk the directories'))
->addSwitch(new CliSwitch('base-dir', 'b', true, 'dir', 'Base directory'));

130
tools/productize.php Normal file
View File

@ -0,0 +1,130 @@
<?php
require_once 'cli.php';
/**
* Prints usage
*/
function usage() {
$usage = new Usage(
'Productizer 1.0',
basename(__FIlE__),
'Creates the equivalent of C#.NET\'s "AssemblyInfo.cs"',
'Tommy Montgomery',
'2009'
);
global $switches;
$usage->setSwitches($switches);
echo $usage;
}
global $switches;
$switches = new CliSwitchCollection();
$switches->addSwitch(new CliSwitch('name', 'n', true, 'name', 'Product name'))
->addSwitch(new CliSwitch('version', 'v', true, 'version_number', 'Product version'))
->addSwitch(new CliSwitch('author', 'a', true, 'author_name', 'Product author'))
->addSwitch(new CliSwitch('website', 'w', true, 'url', 'Product website'))
->addSwitch(new CliSwitch('package', 'p', true, 'package_name ', 'Name of the package for use in @package tag'))
->addSwitch(new CliSwitch('doc-version', 'd', false, 'version_number', 'Version number for use in @version tag'))
->addSwitch(new CliSwitch('output', 'o', false, 'file|dir', 'The file/directory to write the generated class to; default is stdout'));
array_shift($argv);
$args = Cli::parseArgs($argv, $switches);
$args = $args['switches'];
if (!isset($args['name'], $args['version'], $args['author'], $args['website'])) {
usage();
fwrite(STDERR, 'name, version, author, website and package are required');
exit(1);
}
$self = basename(__FILE__);
$datetime = date('Y-m-d H:i:s');
$args['name'] = addslashes($args['name']);
$args['version'] = addslashes($args['version']);
$args['author'] = addslashes($args['author']);
$args['website'] = addslashes($args['website']);
$code = <<<ENDCODE
<?php
/**
* Product
*
* @package $args[package]
*/
/**
* Product meta information
*
* This class was auto-generated by $self on $datetime.
*
* @package $args[package]
*/
final class Product {
/**#@+
* @var string
*/
/**
* Product name
*/
const NAME = '$args[name]';
/**
* Product version
*/
const VERSION = '$args[version]';
/**
* Product author
*/
const AUTHOR = '$args[author]';
/**
* Product website
*/
const WEBSITE = '$args[website]';
/**
* Product build date
*/
const DATE = '$datetime';
/**#@-*/
private function __construct() {}
}
?>
ENDCODE;
if (isset($args['output']) && !is_dir(dirname($args['output'])) && !mkdir(dirname($args['output']), 0777, true)) {
fwrite(STDERR, 'Unable to mkdir(): ' . dirname($args['output']));
exit(1);
} else if (!isset($args['output'])) {
$args['output'] = 'php://stdout';
}
if (is_dir($args['output'])) {
$args['output'] .= DIRECTORY_SEPARATOR . 'Product.php';
}
$fp = fopen($args['output'], 'w');
if (!$fp) {
fwrite(STDERR, 'Unable to open ' . $args['output'] . ' for writing');
exit(1);
}
fwrite($fp, $code);
fclose($fp);
echo 'Wrote data to ' . $args['output'] . ' (' . strlen($code) . ' bytes)' . "\n";
exit(0);
?>