Permalink
Browse files

Add build process for jenkins integration

  • Loading branch information...
1 parent 827ffac commit 8d81b3e1d142ad1eff9c1e7ea8cc210232a35a8a Olivier Paradis committed Apr 30, 2012
Showing with 277 additions and 52 deletions.
  1. +9 −0 .gitignore
  2. +5 −1 .travis.yml
  3. +13 −19 Tests/tests/autoload.php.dist
  4. +0 −31 Tests/tests/vendors.php
  5. +232 −0 build.xml
  6. +5 −1 composer.json
  7. +13 −0 phpunit.xml.dist
View
@@ -0,0 +1,9 @@
+.idea
+.DS_Store
+build
+phpunit.xml
+Resources/doc/_build/*
+nbproject
+coverage
+composer.lock
+vendor
View
@@ -1,4 +1,5 @@
language: php
+
php:
- 5.3
@@ -7,7 +8,10 @@ env:
- SYMFONY_VERSION=origin/2.0
- SYMFONY_VERSION=origin/master
-before_script: php Tests/tests/vendors.php
+before_script:
+ - wget -nc http://getcomposer.org/composer.phar
+ - php composer.phar install
+
script: phpunit
notifications:
@@ -1,28 +1,22 @@
<?php
-// try to reuse lib defined in a current symfony2 project
+// if the bundle is within a symfony project, try to reuse the project's autoload
$autoload = __DIR__.'/../../../../../../app/autoload.php';
+
+// if the bundle is the project, try to use the composer's autoload for the tests
+$composerAutoload = __DIR__.'/../../vendor/autoload.php';
+
if (is_file($autoload)) {
include $autoload;
+} elseif (is_file($composerAutoload)) {
+ include $composerAutoload;
} else {
- $vendorDir = __DIR__.'/../../vendor';
- require_once $vendorDir.'/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
+ die('Unable to find autoload.php file, please use composer to load dependencies:
- $loader = new Symfony\Component\ClassLoader\UniversalClassLoader();
- $loader->registerNamespaces(array(
- 'Symfony' => array($vendorDir.'/symfony/src'),
- ));
- $loader->register();
+wget http://getcomposer.org/composer.phar
+php composer.phar install
- spl_autoload_register(function($class) {
- if (0 === strpos($class, 'Sonata\\IntlBundle\\')) {
- $path = __DIR__.'/../../'.implode('/', array_slice(explode('\\', $class), 2)).'.php';
+Visit http://getcomposer.org/ for more information.
- if (!stream_resolve_include_path($path)) {
- return false;
- }
- require_once $path;
- return true;
- }
- });
-}
+');
+}
@@ -1,31 +0,0 @@
-#!/usr/bin/env php
-<?php
-
-set_time_limit(0);
-
-$vendorDir = __DIR__.'/../../vendor';
-if (!is_dir($vendorDir)) {
- mkdir($vendorDir);
-}
-
-if (isset($argv[1])) {
- $_SERVER['SYMFONY_VERSION'] = $argv[1];
-}
-
-$deps = array(
- array('symfony', 'git://github.com/symfony/symfony.git', isset($_SERVER['SYMFONY_VERSION']) ? $_SERVER['SYMFONY_VERSION'] : 'origin/master'),
-
-);
-
-foreach ($deps as $dep) {
- list($name, $url, $rev) = $dep;
-
- echo "> Installing/Updating $name\n";
-
- $installDir = $vendorDir.'/'.$name;
- if (!is_dir($installDir)) {
- system(sprintf('git clone %s %s', escapeshellarg($url), escapeshellarg($installDir)));
- }
-
- system(sprintf('cd %s && git fetch origin && git reset --hard %s', escapeshellarg($installDir), escapeshellarg($rev)));
-}
View
@@ -0,0 +1,232 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="SonataIntlBundle" basedir="." default="build:main">
+
+ <!-- Config files -->
+ <property name="dir.config" value="${project.basedir}" />
+ <property name="config.phpunit" value="${dir.config}/phpunit.xml.dist" />
+ <property name="config.pmd" value="${dir.config}/pmd.xml.dist" />
+
+ <!-- Build paths -->
+ <property name="dir.build" value="${project.basedir}/build" />
+ <property name="dir.reports" value="${dir.build}/reports" />
+ <property name="dir.reports.check" value="${dir.reports}/check" />
+ <property name="dir.reports.test" value="${dir.reports}/test" />
+ <property name="dir.reports.test.unit" value="${dir.reports.test}/unit" />
+ <property name="dir.reports.test.coverage" value="${dir.reports.test}/coverage" />
+ <property name="dir.docs" value="${dir.build}/docs" />
+ <property name="dir.docs.api" value="${dir.docs}/api" />
+ <property name="dir.docs.rst" value="${dir.docs}/rst" />
+ <property name="dir.docs.php" value="${dir.docs}/php" />
+
+ <!-- Source paths -->
+ <property name="dir.src" value="${project.basedir}" />
+ <property name="dir.src.rst" value="${dir.src}/Resources/doc" />
+
+ <!-- Source fileset (used by check tasks) -->
+ <fileset id="sourcecode" dir="${dir.src}">
+ <include name="**/*.php" />
+ <exclude name="**/*Test.php" />
+ <exclude name="vendor/**/*.php" />
+ </fileset>
+
+
+ <!-- BUILD TASKS -->
+
+ <!-- Main (default) task -->
+ <target name="build:main"
+ depends="build:clean, build:prepare, build:check, build:test, build:doc"
+ description="Run all test and build everything"/>
+
+ <!-- Clean previous build files -->
+ <target name="build:clean"
+ description="Clean previous build files">
+
+ <delete dir="${dir.build}" verbose="true" />
+
+ </target>
+
+ <!-- Prepare build (performed by each build:* task when called as standalone) -->
+ <target name="build:prepare"
+ description="Prepare build">
+
+ <mkdir dir="${dir.build}" />
+
+ </target>
+
+ <!-- Check Project -->
+ <target name="build:check"
+ description="Check source code"
+ depends="build:prepare, check:prepare, check:cs, check:md, check:cpd"/>
+
+ <!-- Test Project -->
+ <target name="build:test"
+ description="Perform all tests"
+ depends="build:prepare, test:prepare, test:unit"/>
+
+ <!-- Generate documentation -->
+ <target name="build:doc"
+ depends="build:prepare, doc:prepare, doc:api"
+ description="Generate API documentation"/>
+
+ <!-- CHECK SECTION -->
+
+ <!-- Prepare check (performed by each check:* task when called as standalone) -->
+ <target name="check:prepare"
+ description="Create check directories">
+
+ <mkdir dir="${dir.reports.check}" />
+
+ </target>
+
+ <!-- CodeSniffer with Symfony2 convention -->
+ <target name="check:cs"
+ depends="check:prepare"
+ description="Generate PHP_CodeSniffer report">
+
+ <phpcodesniffer standard="Symfony2" showSniffs="true" showWarnings="true">
+ <fileset refid="sourcecode" />
+ <config name="error_severity" value="1"/>
+ <config name="warning_severity" value="5"/>
+ <formatter type="checkstyle" outfile="${dir.reports.check}/checkstyle.xml" />
+ </phpcodesniffer>
+
+ </target>
+
+ <!-- PHP Copy and Paste Detector -->
+ <target name="check:cpd"
+ description="Generate phpcpd report"
+ depends="check:prepare">
+
+ <phpcpd>
+ <fileset refid="sourcecode" />
+ <formatter type="pmd" outfile="${dir.reports.check}/cpd.xml" />
+ </phpcpd>
+
+ </target>
+
+ <!-- PHP Mess detector -->
+ <target name="check:md"
+ description="Generate phpmd report"
+ depends="check:prepare" >
+
+ <!-- if config.pmd file not found, use default pmd config -->
+ <if>
+ <not><available file="${config.pmd}"/></not>
+ <then>
+ <echo msg="phpmd config file not found: ${config.pmd}" />
+ <property name="config.pmd" value="codesize,unusedcode,naming,design" override="yes"/>
+ </then>
+ </if>
+
+ <phpmd rulesets="${config.pmd}">
+ <fileset refid="sourcecode" />
+ <formatter type="xml" outfile="${dir.reports.check}/pmd.xml" />
+ </phpmd>
+
+ </target>
+
+ <!-- TEST SECTION -->
+
+ <!-- Prepare test environment (performed by each test:* task when called as standalone) -->
+ <target name="test:prepare"
+ description="Prepare the test environment">
+
+ <echo msg="Prepare test report directory" />
+ <mkdir dir="${dir.reports.test}" />
+
+ <echo msg="Installing/Updating vendors..." />
+ <exec command="composer update --dev" passthru="true"/>
+
+ </target>
+
+ <!-- Prepare unit test environment -->
+ <target name="test:unit:prepare"
+ description="Prepare the unit test environment"
+ depends="test:prepare">
+
+ <mkdir dir="${dir.reports.test.unit}" />
+
+ </target>
+
+ <!-- Execute unit tests and code coverage -->
+ <target name="test:unit"
+ description="Perform unit tests and code coverage"
+ depends="test:prepare, test:unit:prepare">
+
+ <exec executable="phpunit" logoutput="true">
+ <arg line="--log-junit ${dir.reports.test.unit}/phpunit.xml" />
+ <arg line="--coverage-clover ${dir.reports.test.coverage}/clover.xml" />
+ <arg line="--coverage-html ${dir.reports.test.coverage}/html" />
+ <arg line="-c ${config.phpunit}" />
+ </exec>
+
+ </target>
+
+ <!-- DOCUMENTATION SECTION -->
+
+ <!-- Prepare the documentation environment -->
+ <target name="doc:prepare"
+ description="Prepare the documentation">
+
+ <mkdir dir="${dir.docs}" />
+
+ </target>
+
+ <!-- Prepare the Api documentation -->
+ <target name="doc:api:prepare"
+ description="Prepare the API documentation">
+
+ <mkdir dir="${dir.docs.api}" />
+
+ </target>
+
+ <!-- Generate the Api documentation -->
+ <target name="doc:api"
+ description="Generate API documentation"
+ depends="doc:prepare, doc:api:prepare">
+
+ <exec executable="apigen" logoutput="true" passthru="true">
+ <arg line="--source ${dir.src}" />
+ <arg line="--exclude */vendor/*" />
+ <arg line="--exclude */Tests/*" />
+ <arg line="--destination ${dir.docs.api}" />
+ </exec>
+
+ </target>
+
+ <!-- Prepare the phpDoc documentation -->
+ <target name="doc:php:prepare"
+ description="Prepare the Php documentation">
+
+ <mkdir dir="${dir.docs.php}" />
+
+ </target>
+
+ <!-- Build the phpDoc documentation -->
+ <target name="doc:php"
+ description="Generate Php documentation"
+ depends="doc:prepare, doc:php:prepare">
+
+ <exec executable="phpdoc" logoutput="true" passthru="true">
+ <arg line="--directory ${dir.src}" />
+ <arg line="--ignore '*/vendor/*,*/Tests/*'" />
+ <arg line="--target ${dir.docs.php}" />
+ <arg line="--sourcecode" />
+
+ </exec>
+
+ </target>
+
+ <!-- Generate the RST documentation -->
+ <target name="doc:rst"
+ description="Generate RST documentation"
+ depends="doc:prepare">
+
+ <!-- delete previous directory (sphinx refuses to work on an existing directory) -->
+ <delete dir="${dir.docs.rst}"/>
+
+ <exec command="sphinx-build -C -a -b html ${dir.src.rst} ${dir.docs.rst}" passthru="true" />
+
+ </target>
+
+</project>
View
@@ -17,7 +17,11 @@
],
"require": {
"php": ">=5.3.2",
- "symfony/framework-bundle": "2.*"
+ "symfony/http-kernel": "2.*",
+ "symfony/dependency-injection": "2.*",
+ "symfony/templating": "2.*",
+ "symfony/locale": "2.*",
+ "twig/twig": "*"
},
"autoload": {
"psr-0": { "Sonata\\IntlBundle": "" }
View
@@ -17,4 +17,17 @@
</testsuite>
</testsuites>
+ <filter>
+ <whitelist>
+ <directory>./</directory>
+ <exclude>
+ <directory>./Tests/</directory>
+ <directory>./DataFixtures/</directory>
+ <directory>./Resources/</directory>
+ <directory>./DependencyInjection/</directory>
+ <directory>./vendor/</directory>
+ </exclude>
+ </whitelist>
+ </filter>
+
</phpunit>

0 comments on commit 8d81b3e

Please sign in to comment.