forked from doctrine/doctrine-build-common
/
VersionIncrementTask.php
49 lines (40 loc) · 1.17 KB
/
VersionIncrementTask.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?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
{
/** Pattern to match unstable versions */
const UNSTABLE_PATTERN = '((-RC[0-9]+|-DEV|-ALPHA[0-9]+|-BETA[0-9]+))i';
protected $version;
protected $property;
public function setVersion($version)
{
$this->version = $version;
}
public function setProperty($property)
{
$this->property = $property;
}
public function init()
{
}
public function main()
{
$version = preg_replace(self::UNSTABLE_PATTERN, '', $this->version);
$parts = explode(".", $version);
if (count($parts) != 3) {
throw new \InvalidArgumentException("Version is assumed in format x.y.z, $this->version given");
}
if (!preg_match(self::UNSTABLE_PATTERN, $this->version)) {
$parts[2]++;
}
$this->project->setProperty($this->property, implode(".", $parts));
}
}