1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
require_once 'FakePluginDescriptor.php'; |
4
|
|
|
|
5
|
|
|
class ReleaseVersionComparator { |
6
|
|
|
const COLOR_RED = "\033[31m"; |
7
|
|
|
const COLOR_GREEN = "\033[32m"; |
8
|
|
|
const COLOR_NOCOLOR = "\033[0m"; |
9
|
|
|
|
10
|
|
|
protected $tmpNames = array(); |
11
|
|
|
|
12
|
|
|
public function __construct($prevUri, $curUri) { |
13
|
|
|
$this->prevUri = $prevUri; |
14
|
|
|
$this->curUri = $curUri; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function __destruct() { |
18
|
|
|
foreach ($this->tmpNames as $file) { |
19
|
|
|
@unlink($file); |
|
|
|
|
20
|
|
|
} |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function iterateOverPaths($paths, $rpms, $verbose=false) { |
24
|
|
|
$iRpms = array_flip(array_map('strtolower', $rpms)); |
25
|
|
|
foreach ($paths as $path) { |
26
|
|
|
$versionPath = $path.'/VERSION'; |
27
|
|
|
$curVersion = $this->getCurrentVersion($versionPath); |
28
|
|
|
try { |
29
|
|
|
$prevVersion = $this->getPreviousVersion($versionPath); |
30
|
|
|
$this->displayOneLine($path, $curVersion, $prevVersion, $iRpms, $verbose); |
31
|
|
|
} catch(Exception $e) { |
32
|
|
|
echo "Impossible to get previous $versionPath. It's normal if it's new in this release. Otherwise, please check\n"; |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function displayOneLine($path, $curVersion, $prevVersion, $iRpms, $verbose) { |
38
|
|
|
$versionOk = version_compare($curVersion, $prevVersion, '>'); |
39
|
|
|
if ($verbose || !$versionOk) { |
40
|
|
|
$flag = ''; |
41
|
|
|
$name = basename($path); |
42
|
|
|
if (isset($iRpms[strtolower($name)])) { |
43
|
|
|
if ($versionOk) { |
44
|
|
|
$flag .= self::COLOR_GREEN; |
45
|
|
|
} else { |
46
|
|
|
$flag .= self::COLOR_RED; |
47
|
|
|
} |
48
|
|
|
$flag .= '[RPM] '; |
49
|
|
|
} |
50
|
|
|
echo "\t$flag".$path.": ".$curVersion.' (Previous release was: '.$prevVersion.')'.self::COLOR_NOCOLOR.PHP_EOL; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getCurrentVersion($relPath) { |
55
|
|
|
if (is_dir($this->curUri)) { |
56
|
|
|
return $this->getVersionContent($this->curUri.$relPath); |
57
|
|
|
} else { |
58
|
|
|
return $this->getRemoteVersion($this->curUri.$relPath); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function getPreviousVersion($relPath) { |
63
|
|
|
return $this->getRemoteVersion($this->prevUri.$relPath); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
protected function getRemoteVersion($url) { |
67
|
|
|
$filePath = $this->getRemoteFile($url); |
68
|
|
|
return $this->getVersionContent($filePath); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
protected function getRemoteFile($url) { |
72
|
|
|
$name = tempnam('/tmp', 'codendi_release_'); |
73
|
|
|
$this->tmpNames[] = $name; |
74
|
|
|
$output = array(); |
75
|
|
|
$retVal = false; |
76
|
|
|
exec('svn cat '.$url.' 2>/dev/null > '.$name, $output, $retVal); |
77
|
|
|
if ($retVal === 0) { |
78
|
|
|
return $name; |
79
|
|
|
} |
80
|
|
|
throw new Exception('Impossible to get remote file: '.$url); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
protected function getVersionContent($filePath) { |
84
|
|
|
return trim(file_get_contents($filePath)); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
class PluginReleaseVersionComparator extends ReleaseVersionComparator { |
90
|
|
|
|
91
|
|
|
public function __construct($prevUri, $curUri, $fpd) { |
92
|
|
|
parent::__construct($prevUri, $curUri); |
93
|
|
|
$this->fpd = $fpd; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function getPreviousVersion($relPath) { |
97
|
|
|
try { |
98
|
|
|
return $this->getRemoteVersion($this->prevUri.$relPath); |
99
|
|
|
} catch (Exception $e) { |
100
|
|
|
$pluginRoot = dirname($relPath); |
101
|
|
|
$pluginName = basename($pluginRoot); |
102
|
|
|
$path = $this->fpd->findDescriptor($this->curUri.$pluginRoot); |
103
|
|
|
$relPath = substr($path, -(strlen($path)-strlen($this->curUri))); |
104
|
|
|
|
105
|
|
|
// Get descriptor |
106
|
|
|
$oldDescPath = $this->getRemoteFile($this->prevUri.$relPath); |
107
|
|
|
$oldDesc = $this->fpd->getDescriptorFromFile($pluginName, $oldDescPath); |
108
|
|
|
return $oldDesc->getVersion(); |
109
|
|
|
} |
110
|
|
|
throw new Exception('No way to get the previous version number'); |
|
|
|
|
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
?> |
If you suppress an error, we recommend checking for the error condition explicitly: