-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathPdepend.php
More file actions
148 lines (123 loc) · 4.5 KB
/
Copy pathPdepend.php
File metadata and controls
148 lines (123 loc) · 4.5 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
namespace PHPCensor\Plugin;
use PHPCensor\Builder;
use PHPCensor\Common\Exception\RuntimeException;
use PHPCensor\Model\Build;
use PHPCensor\Plugin;
use Symfony\Component\Filesystem\Filesystem;
/**
* Pdepend Plugin - Allows Pdepend report
*
* @package PHP Censor
* @subpackage Application
*
* @author Johan van der Heide <info@japaveh.nl>
* @author Dmitry Khomutov <poisoncorpsee@gmail.com>
*/
class Pdepend extends Plugin
{
protected $args;
/**
* @var string
*/
protected $buildDirectory;
/**
* @var string
*/
protected $buildBranchDirectory;
/**
* @var string File where the summary.xml is stored
*/
protected $summary = 'summary.xml';
/**
* @var string File where the chart.svg is stored
*/
protected $chart = 'chart.svg';
/**
* @var string File where the pyramid.svg is stored
*/
protected $pyramid = 'pyramid.svg';
/**
* @var string
*/
protected $buildLocation;
/**
* @var string
*/
protected $buildBranchLocation;
/**
* @return string
*/
public static function pluginName()
{
return 'pdepend';
}
/**
* {@inheritDoc}
*/
public function __construct(Builder $builder, Build $build, array $options = [])
{
parent::__construct($builder, $build, $options);
$this->executable = $this->findBinary(['pdepend', 'pdepend.phar']);
$this->buildDirectory = $build->getBuildDirectory();
$this->buildBranchDirectory = $build->getBuildBranchDirectory();
$this->buildLocation = PUBLIC_DIR . 'artifacts/pdepend/' . $this->buildDirectory;
$this->buildBranchLocation = PUBLIC_DIR . 'artifacts/pdepend/' . $this->buildBranchDirectory;
}
/**
* Runs Pdepend with the given criteria as arguments
*/
public function execute()
{
$allowPublicArtifacts = (bool)$this->builder->getConfiguration()->get(
'php-censor.build.allow_public_artifacts',
false
);
$fileSystem = new Filesystem();
if (!$fileSystem->exists($this->buildLocation)) {
$fileSystem->mkdir($this->buildLocation, (0777 & ~\umask()));
}
if (!\is_writable($this->buildLocation)) {
throw new RuntimeException(\sprintf(
'The location %s is not writable or does not exist.',
$this->buildLocation
));
}
$pdepend = $this->executable;
$cmd = 'cd "%s" && ' . $pdepend . ' --summary-xml="%s" --jdepend-chart="%s" --overview-pyramid="%s" %s "%s"';
$ignore = '';
if (\count($this->ignore)) {
$ignore = \sprintf(' --ignore="%s"', \implode(',', $this->ignore));
}
$success = $this->builder->executeCommand(
$cmd,
$this->builder->buildPath,
$this->buildLocation . '/' . $this->summary,
$this->buildLocation . '/' . $this->chart,
$this->buildLocation . '/' . $this->pyramid,
$ignore,
$this->directory
);
if (!$allowPublicArtifacts) {
$fileSystem->remove($this->buildLocation);
}
if ($allowPublicArtifacts && \file_exists($this->buildLocation)) {
$fileSystem->remove($this->buildBranchLocation);
$fileSystem->mirror($this->buildLocation, $this->buildBranchLocation);
}
if ($allowPublicArtifacts && $success) {
$this->builder->logSuccess(
\sprintf(
"\nPdepend successful build report.\nYou can use report for this build for inclusion in the readme.md file:\n%s,\n and\n\n\nOr report for last build in the branch:\n%s,\n and\n\n",
APP_URL . 'artifacts/pdepend/' . $this->buildDirectory . '/' . $this->summary,
APP_URL . 'artifacts/pdepend/' . $this->buildDirectory . '/' . $this->chart,
APP_URL . 'artifacts/pdepend/' . $this->buildDirectory . '/' . $this->pyramid,
APP_URL . 'artifacts/pdepend/' . $this->buildBranchDirectory . '/' . $this->summary,
APP_URL . 'artifacts/pdepend/' . $this->buildBranchDirectory . '/' . $this->chart,
APP_URL . 'artifacts/pdepend/' . $this->buildBranchDirectory . '/' . $this->pyramid
)
);
}
return $success;
}
}