|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the puli/composer-plugin package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Bernhard Schussek <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Puli\ComposerPlugin; |
|
13
|
|
|
|
|
14
|
|
|
use RuntimeException; |
|
15
|
|
|
use Symfony\Component\Process\Process; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Thrown when an error occurs while running Puli. |
|
19
|
|
|
* |
|
20
|
|
|
* @since 1.0 |
|
21
|
|
|
* |
|
22
|
|
|
* @author Bernhard Schussek <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
class PuliRunnerException extends RuntimeException |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
private $command; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var int |
|
33
|
|
|
*/ |
|
34
|
|
|
private $exitCode; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var string |
|
38
|
|
|
*/ |
|
39
|
|
|
private $shortError; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var string |
|
43
|
|
|
*/ |
|
44
|
|
|
private $fullError; |
|
45
|
|
|
|
|
46
|
3 |
|
public static function forProcess(Process $process) |
|
47
|
|
|
{ |
|
48
|
3 |
|
$shortError = $fullError = $process->getErrorOutput(); |
|
49
|
|
|
|
|
50
|
3 |
|
if (preg_match('~^fatal: (.+)$~', $shortError, $matches)) { |
|
51
|
1 |
|
$shortError = trim($matches[1]); |
|
52
|
2 |
|
} elseif (preg_match('~^\s+\[([\w\\\\]+\\\\)?(\w+)\]\s+(.+)\r?\n\r?\n\S~s', $shortError, $matches)) { |
|
53
|
2 |
|
$shortError = trim($matches[2]).': '.trim($matches[3]); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
3 |
|
return new static($process->getCommandLine(), $process->getExitCode(), $shortError, $fullError); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param string $command |
|
61
|
|
|
* @param int $exitCode |
|
62
|
|
|
* @param string $shortError |
|
63
|
|
|
* @param string $fullError |
|
64
|
|
|
*/ |
|
65
|
11 |
|
public function __construct($command, $exitCode, $shortError, $fullError) |
|
66
|
|
|
{ |
|
67
|
11 |
|
parent::__construct(sprintf( |
|
68
|
11 |
|
'An error occurred while running: %s (status %s): %s', |
|
69
|
|
|
$command, |
|
70
|
|
|
$exitCode, |
|
71
|
|
|
$shortError |
|
72
|
|
|
)); |
|
73
|
|
|
|
|
74
|
11 |
|
$this->command = $command; |
|
75
|
11 |
|
$this->exitCode = $exitCode; |
|
76
|
11 |
|
$this->shortError = $shortError; |
|
77
|
11 |
|
$this->fullError = $fullError; |
|
78
|
11 |
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @return string |
|
82
|
|
|
*/ |
|
83
|
3 |
|
public function getCommand() |
|
84
|
|
|
{ |
|
85
|
3 |
|
return $this->command; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @return int |
|
90
|
|
|
*/ |
|
91
|
3 |
|
public function getExitCode() |
|
92
|
|
|
{ |
|
93
|
3 |
|
return $this->exitCode; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @return string |
|
98
|
|
|
*/ |
|
99
|
11 |
|
public function getShortError() |
|
100
|
|
|
{ |
|
101
|
11 |
|
return $this->shortError; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @return string |
|
106
|
|
|
*/ |
|
107
|
3 |
|
public function getFullError() |
|
108
|
|
|
{ |
|
109
|
3 |
|
return $this->fullError; |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|