Skip to content

Commit

Permalink
Rearranged src. Added PPW build scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
bd808 committed Oct 12, 2011
1 parent 951c7fc commit e15aca1
Show file tree
Hide file tree
Showing 9 changed files with 230 additions and 18 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
build/api
build/code-browser
build/coverage
build/logs
build/pdepend
phpunit.xml
92 changes: 92 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by PHP Project Wizard (PPW) 1.0.4 on Tue Oct 11 23:20:43 MDT 2011 -->

<project name="graphite-graph" default="build" basedir=".">
<property name="source" value="src"/>

<target name="clean" description="Clean up and create artifact directories">
<delete dir="${basedir}/build/api"/>
<delete dir="${basedir}/build/code-browser"/>
<delete dir="${basedir}/build/coverage"/>
<delete dir="${basedir}/build/logs"/>
<delete dir="${basedir}/build/pdepend"/>

<mkdir dir="${basedir}/build/api"/>
<mkdir dir="${basedir}/build/code-browser"/>
<mkdir dir="${basedir}/build/coverage"/>
<mkdir dir="${basedir}/build/logs"/>
<mkdir dir="${basedir}/build/pdepend"/>
</target>

<target name="phpunit" description="Run unit tests using PHPUnit and generates junit.xml and clover.xml">
<exec executable="phpunit" failonerror="true"/>
</target>

<target name="parallelTasks" description="Run the pdepend, phpmd, phpcpd, phpcs, phpdoc and phploc tasks in parallel using a maximum of 2 threads.">
<parallel threadCount="2">
<sequential>
<antcall target="pdepend"/>
<antcall target="phpmd"/>
</sequential>
<antcall target="phpcpd"/>
<antcall target="phpcs"/>
<antcall target="phpdoc"/>
<antcall target="phploc"/>
</parallel>
</target>

<target name="pdepend" description="Generate jdepend.xml and software metrics charts using PHP_Depend">
<exec executable="pdepend">
<arg line="--jdepend-xml=${basedir}/build/logs/jdepend.xml
--jdepend-chart=${basedir}/build/pdepend/dependencies.svg
--overview-pyramid=${basedir}/build/pdepend/overview-pyramid.svg
${source}" />
</exec>
</target>

<target name="phpmd" description="Generate pmd.xml using PHPMD">
<exec executable="phpmd">
<arg line="${source}
xml
codesize,design,naming,unusedcode
--reportfile ${basedir}/build/logs/pmd.xml" />
</exec>
</target>

<target name="phpcpd" description="Generate pmd-cpd.xml using PHPCPD">
<exec executable="phpcpd">
<arg line="--log-pmd ${basedir}/build/logs/pmd-cpd.xml ${source}" />
</exec>
</target>

<target name="phploc" description="Generate phploc.csv">
<exec executable="phploc">
<arg line="--log-csv ${basedir}/build/logs/phploc.csv ${source}" />
</exec>
</target>

<target name="phpcs" description="Generate checkstyle.xml using PHP_CodeSniffer">
<exec executable="phpcs" output="/dev/null">
<arg line="--report=checkstyle
--report-file=${basedir}/build/logs/checkstyle.xml
--standard=PEAR
${source}" />
</exec>
</target>

<target name="phpdoc" description="Generate API documentation using PHPDocumentor">
<exec executable="phpdoc">
<arg line="-d ${source} -t ${basedir}/build/api" />
</exec>
</target>

<target name="phpcb" description="Aggregate tool output with PHP_CodeBrowser">
<exec executable="phpcb">
<arg line="--log ${basedir}/build/logs
--source ${source}
--output ${basedir}/build/code-browser" />
</exec>
</target>

<target name="build" depends="clean,parallelTasks,phpunit,phpcb"/>
</project>
10 changes: 5 additions & 5 deletions cpu_irq.ini → examples/cpu_irq.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,35 @@ description = A really cool graph
; define a service named munin
; fields referencing this service will look for their data in
; <hostname>.munin.cpu.<field>
is_service = 1
:is_service = 1
data = cpu

[irq]
; define a field named irq that uses the munin service
use_service = munin
:use_service = munin
derivative = true
scale = 0.001
color = red
alias = IRQ

[softirq]
; define a field named softirq that uses the munin service
use_service = munin
:use_service = munin
derivative = true
scale = 0.001
color = yellow
alias = Batched IRQ

[puppet_time]
is_service = 1
:is_service = 1
; service sections can specify an explicit name for the service
; fields referencing this service will look for their data in
; <hostname>.puppet.time.<field>
service = puppet
data = time

[puppet_ran]
use_service = puppet_time
:use_service = puppet_time
; field sections can specify an explicit name for the field
field = total
color = blue
Expand Down
4 changes: 2 additions & 2 deletions dsl_example.php → examples/dsl_example.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
require_once 'GraphiteGraph.php';
require_once dirname(__FILE__) . '/../src/autoload.php';

$g = new GraphiteGraph(null,
$g = new Graphite_GraphBuilder(null,
array('width' => 800, 'height' => 400),
array( 'hostname' => 'com.example.foo'));

Expand Down
4 changes: 2 additions & 2 deletions example.php → examples/ini_example.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
require_once 'GraphiteGraph.php';
require_once dirname(__FILE__) . '/../src/autoload.php';

$g = new GraphiteGraph('cpu_irq.ini',
$g = new Graphite_GraphBuilder('cpu_irq.ini',
array('width' => 800, 'height' => 400),
array( 'hostname' => 'com.example.foo'));
echo $g->url, "\n";
31 changes: 31 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by PHP Project Wizard (PPW) 1.0.4 on Tue Oct 11 23:20:43 MDT 2011 -->

<phpunit bootstrap="src/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
strict="true"
verbose="true">
<testsuites>
<testsuite name="graphite-graph">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>

<logging>
<log type="coverage-html" target="build/coverage" title="graphite-graph"
charset="UTF-8" yui="true" highlight="true"
lowUpperBound="35" highLowerBound="70"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/>
</logging>

<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
<exclude>
<file>src/autoload.php</file>
</exclude>
</whitelist>
</filter>
</phpunit>
21 changes: 12 additions & 9 deletions GraphiteGraph.php → src/Graphite/GraphBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,21 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package Graphite
*/


/**
* DSL for creating graph desciptions for <a
* href="http://graphite.wikidot.com/">Graphite</a>.
*
* @package Graphite
* @author Bryan Davis <[email protected]>
* @version SVN: $Id: skeleton.php 81 2007-07-11 15:04:33Z bpd $
* @copyright 2011 Bryan Davis and contributors. All Rights Reserved.
*/
class GraphiteGraph {
class Graphite_GraphBuilder {

/**
* Properties for graph.
Expand Down Expand Up @@ -88,7 +91,7 @@ public function __construct ($file=null, $overrides=array(), $info=array()) {
* Start a service block.
* @param string $service Name of service
* @param string $data Data collection of interest
* @return GraphiteGraph Self, for message chaining
* @return Graphite_GraphBuilder Self, for message chaining
*/
public function service ($service, $data) {
if (!isset($this->info['hostname'])) {
Expand All @@ -101,7 +104,7 @@ public function service ($service, $data) {

/**
* End service block.
* @return GraphiteGraph Self, for message chaining
* @return Graphite_GraphBuilder Self, for message chaining
*/
public function endService () {
$this->service = null;
Expand All @@ -113,7 +116,7 @@ public function endService () {
* Add a data series to the graph.
* @param string $name Name of data field to graph
* @param array $opts Series options
* @return GraphiteGraph Self, for message chaining
* @return Graphite_GraphBuilder Self, for message chaining
*/
public function field ($name, $opts) {
if (isset($this->series[$name])) {
Expand Down Expand Up @@ -248,16 +251,16 @@ protected function load ($file) {
$services = array();
foreach ($ini as $name => $data) {
// look for services first
if (isset($data['is_service'])) {
if (isset($data[':is_service'])) {
$services[$name] = $data;
continue;
}

// it must be a field
if (isset($data['use_service'])) {
$svcData = $services[$data['use_service']];
if (isset($data[':use_service'])) {
$svcData = $services[$data[':use_service']];
$svcName = (isset($svcData['service']))?
$svcData['service']: $data['use_service'];
$svcData['service']: $data[':use_service'];

$this->service($svcName, $svcData['data']);
}
Expand All @@ -271,4 +274,4 @@ protected function load ($file) {
} //end load


} //end GraphiteGraph
} //end Graphite_GraphBuilder
39 changes: 39 additions & 0 deletions src/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* Copyright (c) 2011, Bryan Davis and contributors
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* a. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* b. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/


/**
* Simple autoloader that converts underscore and backslash to directories.
* @param string $class Class to load
* @return void
*/
function graphite_graph_autoload ($class) {
require dirname(__FILE__) . '/' . strtr($class, '_\\', '//') . '.php';
}

spl_autoload_register('graphite_graph_autoload');
41 changes: 41 additions & 0 deletions tests/Graphite/GraphBuilderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Copyright (c) 2011, Bryan Davis and contributors
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* a. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* b. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/


/**
* @author Bryan Davis <[email protected]>
* @version SVN: $Id: skeleton.php 81 2007-07-11 15:04:33Z bpd $
* @copyright 2011 Bryan Davis and contributors. All Rights Reserved.
*/
class Graphite_GraphBuilderTest extends PHPUnit_Framework_TestCase {

public function testNothing () {
$this->assertTrue(true);
}

} //end Graphite_GraphBuilderTest

0 comments on commit e15aca1

Please sign in to comment.