2013-07-13 00:19:43 +02:00
< ? php
2016-07-19 20:28:11 +02:00
namespace PHPCensor\Plugin ;
2013-07-13 00:19:43 +02:00
2018-03-07 18:47:09 +01:00
use b8\Config ;
2016-07-19 20:28:11 +02:00
use PHPCensor\Builder ;
use PHPCensor\Model\Build ;
use PHPCensor\Plugin ;
2018-02-25 12:14:54 +01:00
use Symfony\Component\Filesystem\Filesystem ;
2013-10-10 02:01:06 +02:00
2013-07-13 00:19:43 +02:00
/**
* Pdepend Plugin - Allows Pdepend report
2018-01-20 07:09:30 +01:00
*
2017-03-04 16:39:56 +01:00
* @ author Johan van der Heide < info @ japaveh . nl >
2013-07-13 00:19:43 +02:00
*/
2016-07-11 18:00:04 +02:00
class Pdepend extends Plugin
2013-07-13 00:19:43 +02:00
{
protected $args ;
2016-07-11 18:00:04 +02:00
2018-01-20 07:09:30 +01:00
/**
* @ var string
*/
protected $buildDirectory ;
2018-02-25 12:14:54 +01:00
/**
* @ var string
*/
protected $buildBranchDirectory ;
2013-07-13 00:19:43 +02:00
/**
* @ var string Directory which needs to be scanned
*/
protected $directory ;
2016-07-11 18:00:04 +02:00
2013-07-13 00:19:43 +02:00
/**
* @ var string File where the summary . xml is stored
*/
protected $summary ;
2016-07-11 18:00:04 +02:00
2013-07-13 00:19:43 +02:00
/**
* @ var string File where the chart . svg is stored
*/
protected $chart ;
2016-07-11 18:00:04 +02:00
2013-07-13 00:19:43 +02:00
/**
* @ var string File where the pyramid . svg is stored
*/
protected $pyramid ;
2016-07-11 18:00:04 +02:00
2013-07-13 00:19:43 +02:00
/**
2018-02-25 12:14:54 +01:00
* @ var string
2013-07-13 00:19:43 +02:00
*/
2018-02-25 12:14:54 +01:00
protected $buildLocation ;
/**
* @ var string
*/
protected $buildBranchLocation ;
2013-07-13 00:19:43 +02:00
2017-01-11 16:15:54 +01:00
/**
* @ return string
*/
public static function pluginName ()
{
return 'pdepend' ;
}
2014-12-08 12:25:33 +01:00
/**
2016-07-11 18:00:04 +02:00
* { @ inheritdoc }
2014-12-08 12:25:33 +01:00
*/
2016-07-22 09:05:34 +02:00
public function __construct ( Builder $builder , Build $build , array $options = [])
2013-07-13 00:19:43 +02:00
{
2016-07-22 09:05:34 +02:00
parent :: __construct ( $builder , $build , $options );
2013-07-13 00:19:43 +02:00
2018-01-20 07:09:30 +01:00
$this -> directory = isset ( $options [ 'directory' ])
? $options [ 'directory' ]
: $this -> builder -> buildPath ;
$this -> summary = 'summary.xml' ;
$this -> pyramid = 'pyramid.svg' ;
$this -> chart = 'chart.svg' ;
2013-07-13 00:19:43 +02:00
2018-02-25 12:14:54 +01:00
$this -> buildDirectory = $build -> getBuildDirectory ();
$this -> buildBranchDirectory = $build -> getBuildBranchDirectory ();
$this -> buildLocation = PUBLIC_DIR . 'artifacts/pdepend/' . $this -> buildDirectory ;
$this -> buildBranchLocation = PUBLIC_DIR . 'artifacts/pdepend/' . $this -> buildBranchDirectory ;
2013-07-13 00:19:43 +02:00
}
/**
* Runs Pdepend with the given criteria as arguments
*/
public function execute ()
{
2018-03-07 18:47:09 +01:00
$allowPublicArtifacts = ( bool ) Config :: getInstance () -> get (
'php-censor.build.allow_public_artifacts' ,
true
);
$fileSystem = new Filesystem ();
if ( ! $fileSystem -> exists ( $this -> buildLocation )) {
$fileSystem -> mkdir ( $this -> buildLocation , ( 0777 & ~ umask ()));
2015-05-29 08:26:47 +02:00
}
2018-03-07 18:47:09 +01:00
2018-02-25 12:14:54 +01:00
if ( ! is_writable ( $this -> buildLocation )) {
2018-03-07 18:47:09 +01:00
throw new \Exception ( sprintf (
'The location %s is not writable or does not exist.' ,
$this -> buildLocation
));
2013-07-13 00:19:43 +02:00
}
2017-07-19 05:26:51 +02:00
$pdepend = $this -> findBinary ( 'pdepend' );
2018-03-07 18:47:09 +01:00
$cmd = $pdepend . ' --summary-xml="%s" --jdepend-chart="%s" --overview-pyramid="%s" %s "%s"' ;
2015-04-14 12:17:52 +02:00
2013-08-10 03:28:51 +02:00
// If we need to ignore directories
2016-07-22 09:05:34 +02:00
if ( count ( $this -> builder -> ignore )) {
$ignore = ' --ignore=' . implode ( ',' , $this -> builder -> ignore );
2013-08-10 03:28:51 +02:00
} else {
$ignore = '' ;
}
2016-07-22 09:05:34 +02:00
$success = $this -> builder -> executeCommand (
2013-07-13 00:19:43 +02:00
$cmd ,
2018-02-25 12:14:54 +01:00
$this -> buildLocation . DIRECTORY_SEPARATOR . $this -> summary ,
$this -> buildLocation . DIRECTORY_SEPARATOR . $this -> chart ,
$this -> buildLocation . DIRECTORY_SEPARATOR . $this -> pyramid ,
2013-08-10 03:28:51 +02:00
$ignore ,
2013-07-13 00:19:43 +02:00
$this -> directory
);
2018-03-07 18:47:09 +01:00
if ( ! $allowPublicArtifacts ) {
$fileSystem -> remove ( $this -> buildLocation );
}
if ( $allowPublicArtifacts && file_exists ( $this -> buildLocation )) {
2018-02-25 12:14:54 +01:00
$fileSystem -> remove ( $this -> buildBranchLocation );
$fileSystem -> mirror ( $this -> buildLocation , $this -> buildBranchLocation );
}
2016-07-22 09:05:34 +02:00
$config = $this -> builder -> getSystemConfig ( 'php-censor' );
2013-07-13 00:19:43 +02:00
2018-03-07 18:47:09 +01:00
if ( $allowPublicArtifacts && $success ) {
2016-07-22 09:05:34 +02:00
$this -> builder -> logSuccess (
2013-07-13 00:19:43 +02:00
sprintf (
2018-02-25 12:14:54 +01:00
" \n Pdepend successful build report. \n You can use report for this build for inclusion in the readme.md file: \n %s, \n ![Chart](%s \" Pdepend Chart \" ) and \n ![Pyramid](%s \" Pdepend Pyramid \" ) \n \n Or report for last build in the branch: \n %s, \n ![Chart](%s \" Pdepend Chart \" ) and \n ![Pyramid](%s \" Pdepend Pyramid \" ) \n " ,
2018-01-20 07:09:30 +01:00
$config [ 'url' ] . '/artifacts/pdepend/' . $this -> buildDirectory . '/' . $this -> summary ,
$config [ 'url' ] . '/artifacts/pdepend/' . $this -> buildDirectory . '/' . $this -> chart ,
2018-02-25 12:14:54 +01:00
$config [ 'url' ] . '/artifacts/pdepend/' . $this -> buildDirectory . '/' . $this -> pyramid ,
$config [ 'url' ] . '/artifacts/pdepend/' . $this -> buildBranchDirectory . '/' . $this -> summary ,
$config [ 'url' ] . '/artifacts/pdepend/' . $this -> buildBranchDirectory . '/' . $this -> chart ,
$config [ 'url' ] . '/artifacts/pdepend/' . $this -> buildBranchDirectory . '/' . $this -> pyramid
2013-07-13 00:19:43 +02:00
)
);
}
return $success ;
}
2013-08-10 03:34:19 +02:00
}