Commit 5ef6f6b1 authored by Guillaume Perréal's avatar Guillaume Perréal

Trouve les exécutables java et dot avant de lancer les commandes.

parent e2e58190
...@@ -29,6 +29,7 @@ use Symfony\Component\Console\Input\InputOption; ...@@ -29,6 +29,7 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\ExecutableFinder;
/** /**
* Description of ImportAffiliationCommand. * Description of ImportAffiliationCommand.
...@@ -69,7 +70,13 @@ class RenderCommand extends ContainerAwareCommand ...@@ -69,7 +70,13 @@ class RenderCommand extends ContainerAwareCommand
} }
} }
protected function renderGraph(Graph $graph, $target, $format, SymfonyStyle $io) /**
* @param Graph $graph
* @param $target
* @param $format
* @param SymfonyStyle $io
*/
private function renderGraph(Graph $graph, $target, $format, SymfonyStyle $io): void
{ {
$io->writeln("Fichier de sortie: <comment>$target</comment>"); $io->writeln("Fichier de sortie: <comment>$target</comment>");
...@@ -103,20 +110,28 @@ class RenderCommand extends ContainerAwareCommand ...@@ -103,20 +110,28 @@ class RenderCommand extends ContainerAwareCommand
} }
} }
protected function startProcess($target, $format) /**
* @param $target
* @param $format
* @return array
*/
private function startProcess($target, $format): array
{ {
$ctn = $this->getContainer();
$javaBin = $this->findExecutable($ctn->getParameter('irstea_plant_uml.binaries.java'));
$dotBin = $this->findExecutable($ctn->getParameter('irstea_plant_uml.binaries.dot'));
$fs = new Filesystem(); $fs = new Filesystem();
$fs->mkdir(dirname($target)); $fs->mkdir(dirname($target));
$ctn = $this->getContainer();
$cmd = implode( $cmd = implode(
' ', ' ',
[ [
$ctn->getParameter('irstea_plant_uml.binaries.java'), $javaBin,
'-jar', '-jar',
$ctn->getParameter('irstea_plant_uml.binaries.plamtuml_jar'), $ctn->getParameter('irstea_plant_uml.binaries.plamtuml_jar'),
'-graphvizdot', '-graphvizdot',
$ctn->getParameter('irstea_plant_uml.binaries.dot'), $dotBin,
'-pipe', '-pipe',
'-t' . $format, '-t' . $format,
] ]
...@@ -136,4 +151,21 @@ class RenderCommand extends ContainerAwareCommand ...@@ -136,4 +151,21 @@ class RenderCommand extends ContainerAwareCommand
return [$proc, $pipes]; return [$proc, $pipes];
} }
/**
* @param string $nameOrPath
* @return string
*/
private function findExecutable(string $nameOrPath): string
{
if (\file_exists($nameOrPath) && \is_executable($nameOrPath)) {
return $nameOrPath;
}
$exec = new ExecutableFinder();
$path = $exec->find($nameOrPath);
if ($path === null) {
throw new \RuntimeException("cannot find executable: $nameOrPath");
}
return $path;
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment