Permalink
Browse files

Initial refactoring of DBAL build.xml into a Build common project

  • Loading branch information...
0 parents commit df376cca0fe14b2374626610a69526bd251a067d @beberlei beberlei committed Dec 19, 2011
Showing with 234 additions and 0 deletions.
  1. +32 −0 README.md
  2. +38 −0 ReplaceTask.php
  3. +43 −0 VersionIncrementTask.php
  4. +121 −0 packaging.xml
@@ -0,0 +1,32 @@
+# Doctrine Build Commons
+
+This project is a base submodule for all Doctrine projects that are using
+a build process yet. It handles versioning, making releases and distributing them.
+
+By the nature of phings limit capabilities we ship a bunch of additional tasks, that mimic Ants API as much as possible to allow future migration to Ant and possibly Manuel Piechlers [build-commons library](http://github.com/manuelpiechler/build-commons).
+
+## New tasks
+
+* ReplaceTask with options file, token, value
+* VersionIncrementTask with options property and version
+
+## Targets
+
+* Build - Depends on clean, prepare, generate-package
+* Clean - Clearn the directory for the next build
+* Prepare - Retrieve version from Version Class constant, also calculate PEAR version and stability automatically.
+* generate-package - Generates the PEAR package, depends on define-pear-package as "abstract task".
+* pirum-release - Use '-Dproject.pirum_dir=path' during build to push to pirum.
+* distribute-download - Use '-Dproject.download_dir=path' during build to move download file.
+* make-release-commit - This task makes a release commit by asking for the release version, sets composer.json version, the Version constant and then increments the version in the mini level and makes another commit for the next "dev".
+
+## Properties
+
+Your build file for a build-common supported project has to look at least:
+
+ # Project Name
+ project.name=DoctrineDBAL
+
+ # Version class and file
+ project.version_class = Doctrine\DBAL\Version
+ project.version_file = lib/Doctrine/DBAL/Version.php
@@ -0,0 +1,38 @@
+<?php
+require_once "phing/Task.php";
+
+class ReplaceTask extends Task
+{
+ protected $file;
+ protected $token;
+ protected $value;
+
+ public function setFile($file)
+ {
+ $this->file = $file;
+ }
+
+ public function setToken($token)
+ {
+ $this->token = $token;
+ }
+
+ public function setValue($value)
+ {
+ $this->value = $value;
+ }
+
+ public function init()
+ {
+ }
+
+ public function main()
+ {
+ if (!file_exists($this->file)) {
+ throw new \InvalidArgumentException("not a valid file: " . $this->file);
+ }
+ $data = file_get_contents($this->file);
+ $data = str_replace($this->token, $this->value, $data);
+ file_put_contents($this->file, $data);
+ }
+}
@@ -0,0 +1,43 @@
+<?php
+
+require_once 'phing/Task.php';
+
+/**
+ * Increments a version number on the mini level.
+ *
+ * Alpha, Beta, Dev Versions are stripped from the version, assumption is
+ * that the next release will be stable.
+ *
+ * @author Benjamin Eberlei <kontakt@beberlei.de>
+ */
+class VersionIncrementTask extends Task
+{
+ protected $version;
+
+ protected $property;
+
+ public function setVersion($version)
+ {
+ $this->version = $version;
+ }
+
+ public function setProperty($property)
+ {
+ $this->property = $property;
+ }
+
+ public function init()
+ {
+
+ }
+
+ public function main()
+ {
+ $parts = explode(".", str_ireplace(array('-DEV', '-ALPHA', '-BETA'), '', $this->version));
+ if (count($parts) != 3) {
+ throw new \InvalidArgumentException("Version is assumed in format x.y.z, $this->version given");
+ }
+ $parts[2]++;
+ $this->project->setProperty($this->property, implode(".", $parts));
+ }
+}
@@ -0,0 +1,121 @@
+<?xml version="1.0"?>
+<!-- Currently a Phing Project, may move to Ant shortly -->
+<project name="DoctrineBuildCommon" default="prepare">
+ <!-- Phing is really annoying in this regard -->
+ <taskdef name="replace" classname="ReplaceTask" classpath="lib/vendor/doctrine-build-common/"/>
+ <taskdef name="versionincrement" classname="VersionIncrementTask" classpath="lib/vendor/doctrine-build-common/"/>
+
+ <property name="build.dir" value="${project.basedir}/build" />
+ <property name="dist.dir" value="${project.basedir}/dist" />
+
+ <!--
+ Clean the directory for the next build.
+ -->
+ <target name="clean">
+ <available file="${project.basedir}/build.properties" property="build_properties_exist" value="true"/>
+ <fail unless="build_properties_exist" message="The build.properties file is missing."/>
+
+ <delete dir="${build.dir}" includeemptydirs="true"/>
+ <delete dir="${dist.dir}" includeemptydirs="true"/>
+ </target>
+
+ <!--
+ Prepare the new build directories after cleaning
+ -->
+ <target name="prepare" depends="clean">
+ <echo msg="Creating build directory: ${build.dir}"/>
+ <mkdir dir="${build.dir}"/>
+ <mkdir dir="${build.dir}/logs"/>
+ <echo msg="Creating distribution directory: ${dist.dir}"/>
+ <mkdir dir="${dist.dir}"/>
+
+ <!-- Including version file and getting the current version from it into a variable -->
+ <exec executable="php" outputProperty="version">
+ <arg value="-r"/>
+ <arg value="include '${project.basedir}/${project.version_file}';echo ${project.version_class}::VERSION;"/>
+ </exec>
+
+ <!-- Guessing the Stability for PEAR from the version -->
+ <condition property="pear.stability" value="beta">
+ <contains string="${version}" substring="beta" casesensitive="false"/>
+ </condition>
+ <condition property="pear.stability" value="alpha">
+ <contains string="${version}" substring="alpha" casesensitive="false"/>
+ </condition>
+ <condition property="pear.stability" value="dev">
+ <contains string="${version}" substring="devel" casesensitive="false"/>
+ </condition>
+ <condition property="pear.stability" value="stable">
+ <not><isset property="pear.stability"/></not>
+ </condition>
+
+ <exec command="php -r &quot;\$data = json_decode(file_get_contents('composer.json'), true); \$ret = (isset(\$data['version']) &amp;&amp; \$data['version'] != '${version}') ? 1 : 0;exit(\$ret);&quot;" checkreturn="true" passthru="true"/>
+ <!-- We need an extra PEAR version, as pear versions dont allow dashes and need to be DEVEL not DEV" -->
+ <exec command="php -r &quot;echo strtolower(str_replace(array('-DEV', '-'), array('DEVEL', ''), '${version}'));&quot;" outputProperty="pear.version"/>
+ <echo msg="Preparing release of version ${version} (${pear.version}+${pear.stability})"/>
+ </target>
+
+ <!-- Generate the PEAR package from a directory and move the files to the dist folder -->
+ <target name="generate-package" depends="define-pear-package">
+ <exec command="pear package" dir="${build.dir}/${project.name}-${version}" passthru="true"/>
+ <echo msg="Moving ${project.name}-${pear.version}.tgz"/>
+ <exec command="mv ${project.name}-${pear.version}.tgz ${dist.dir}/" dir="${build.dir}/${project.name}-${version}" passthru="true" checkreturn="true"/>
+ <tar destfile="dist/${project.name}-${version}-full.tar.gz" compression="gzip" basedir="${build.dir}">
+ <fileset dir="${build.dir}">
+ <include name="**/**"/>
+ <exclude name="logs/"/>
+ </fileset>
+ </tar>
+ </target>
+
+ <!-- Release files to Pirum directory if configured -->
+ <target name="pirum-release" if="project.pirum_dir">
+ <exec command="sudo pirum add ${project.pirum_dir} ${dist.dir}/${project.name}-${version}.tgz" dir="." passthru="true"/>
+ </target>
+
+ <!-- Release files to a download directory if configured -->
+ <target name="distribute-download" if="project.download_dir">
+ <copy file="dist/${project.name}-${version}-full.tar.gz" todir="${project.download_dir}"/>
+ </target>
+
+ <target name="build" depends="define-pear-package,generate-package,distribute-download,pirum-release"/>
+
+ <!--
+ Use this task to create a new release commit.
+ -->
+ <target name="make-release-commit" depends="prepare">
+ <echo msg="Making a release commit of ${version}"/>
+
+ <condition property="isNotDevRelease" value="1">
+ <contains string="${version}" substring="-DEV" casesensitive="false"/>
+ </condition>
+ <fail unless="isNotDevRelease" message="Cannot make a release commit of a non-DEV release (again!)"/>
+
+ <!-- get default version just without -dev -->
+ <exec command="php -r &quot;echo str_replace('-DEV', '', '${version}');&quot;" outputProperty="release_version"/>
+ <!-- prompt release master for new version number anyways -->
+ <propertyprompt propertyName="release_version" defaultValue="${release_version}" promptText="Enter version to be released (without -DEV)"/>
+
+ <!-- start replacing versions in the code -->
+ <replace file="${project.basedir}/${project.version_file}" token="${version}" value="${release_version}"/>
+ <replace file="${project.basedir}/composer.json" token="&quot;library&quot;," value="&quot;library&quot;,&quot;version&quot;:&quot;${release_version}&quot;,"/>
+
+ <!-- Git commit this release commit -->
+ <exec command="git add ${project.basedir}/${project.version_file} ${project.basedir}/composer.json" passthru="true"/>
+ <exec command="git commit -m 'Release ${release_version}'" passthru="true"/>
+ <exec command="git tag -m 'Tag ${release_version}' ${release_version}" passthru="true"/>
+
+ <!-- calculate next version, assume that this is a mini version. -->
+ <exec command="git revert -n HEAD~1" />
+ <versionincrement property="next_version" version="${version}" />
+ <replace file="${project.basedir}/${project.version_file}" token="${version}" value="${next_version}"/>
+
+ <echo msg="Made a git commit for version ${release_version} and tagged it." />
+ <echo msg="IMPORTANT: You need to push the current branch and the tag to origin now!" />
+ </target>
+
+ <target name="next-version" depends="prepare">
+ <versionincrement property="next_version" version="${version}" />
+ <echo msg="Next version is supposedly ${next_version}" />
+ </target>
+</project>

0 comments on commit df376cc

Please sign in to comment.