Commit 03cea378 authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

Ajout d'une commande pour exécuter toute la chaîne de traitement.

No related merge requests found
Showing with 167 additions and 2 deletions
+167 -2
<?php
/*
* Copyright (C) 2015 IRSTEA
* All rights reserved.
*/
namespace Irstea\PlantUmlBundle\Command;
use Irstea\PlantUmlBundle\Model\Graph;
use Irstea\PlantUmlBundle\Writer\OutputWriter;
use Irstea\PlantUmlBundle\Writer\StreamWriter;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\ProcessBuilder;
use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
/**
* Description of ImportAffiliationCommand
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
class RenderCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('irstea:plantuml:render')
->setDescription("Créer la page d'un graphe ou plusieurs graphes.")
->addOption('output', 'o', InputOption::VALUE_REQUIRED, "Répertoire de destination.")
->addOption('format', 'f', InputOption::VALUE_REQUIRED, "Format du fichier à générer")
->addArgument('graph', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'Graphe à générer');
}
/**
*
* @param InputInterface $input
* @param OutputInterface $output
*
* @SuppressWarnings(UnusedFormalParameter)
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$graphs = $input->getArgument('graph') ?: $this->getContainer()->getParameter('irstea_plant_uml.graph_keys');
$format = $input->getOption('format') ?: $this->getContainer()->getParameter('irstea_plant_uml.output.format');
$outputDir = $input->getOption('output') ?: $this->getContainer()->getParameter('irstea_plant_uml.output.directory');
foreach($graphs as $name) {
$target = $outputDir . DIRECTORY_SEPARATOR . $name . "." . $format;
$output->writeln("Graphe: $name => $target.");
$graph = $this->getContainer()->get("irstea_plant_uml.graph.$name");
$this->renderGraph($graph, $target, $format, $output);
}
}
protected function renderGraph(Graph $graph, $target, $format, OutputInterface $output)
{
$output->write("Exploration des classes: ");
$graph->visitAll();
$output->writeln("Ok.");
$output->write("Démarrage de PlantUML: ");
list($proc, $pipes) = $this->startProcess($target, $format);
$output->writeln("Ok.");
$output->write("Génération du graphe: ");
$writer = new StreamWriter($pipes[0]);
$graph->writeTo($writer);
fclose($pipes[0]);
$output->writeln("Ok.");
$output->write("Attente de PlantUML: ");
$res = proc_close($proc);
$output->writeln("Ok.");
dump($res);
}
protected function startProcess($target, $format)
{
$fs = new Filesystem();
$fs->mkdir(dirname($target));
$ctn = $this->getContainer();
$cmd = implode(' ', [
$ctn->getParameter('irstea_plant_uml.binaries.java'),
'-jar', $ctn->getParameter('irstea_plant_uml.binaries.plamtuml_jar'),
'-graphvizdot', $ctn->getParameter('irstea_plant_uml.binaries.dot'),
'-pipe',
'-t' . $format
]);
$desc = [
// stdin
['pipe', 'r'],
// stdout
['file', $target, 'wt'],
// stderr
STDERR
];
$pipes = [];
$proc = proc_open($cmd, $desc, $pipes);
return [$proc, $pipes];
}
}
......@@ -24,8 +24,22 @@ class Configuration implements ConfigurationInterface
$treeBuilder->root('irstea_plant_uml')
->children()
->arrayNode('output')
->addDefaultsIfNotSet()
->children()
->scalarNode('directory')
->info("Répertoire dans lequel écrire les fichiers.")
->defaultValue("%kernel.root_dir%/Resources/doc")
->end()
->enumNode('format')
->info("Format de sortie (cf. PlantUML).")
->defaultValue("svg")
->values(['png', 'svg', 'eps', 'pdf', 'vdx', 'html', 'xmi', 'txt', 'utxt'])
->end()
->end()
->end()
->arrayNode('binaries')
->info("Chemins vers les fichiers binaires (INUTILISE POUR L'INSTANT).")
->info("Chemins vers les fichiers binaires, s'ils en sont pas dans PATH.")
->addDefaultsIfNotSet()
->children()
->scalarNode('java')
......
......@@ -36,11 +36,16 @@ class IrsteaPlantUmlExtension extends Extension
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$container->setParameter('irstea_plant_uml.binaries', $config['binaries']);
$container->setParameter('irstea_plant_uml.binaries.java', $config['binaries']['java']);
$container->setParameter('irstea_plant_uml.binaries.plamtuml_jar', $config['binaries']['plamtuml_jar']);
$container->setParameter('irstea_plant_uml.binaries.dot', $config['binaries']['dot']);
$container->setParameter('irstea_plant_uml.output.directory', $config['output']['directory']);
$container->setParameter('irstea_plant_uml.output.format', $config['output']['format']);
foreach($config['graphs'] as $key => $graph) {
$this->loadGraph($key, $graph, $container);
}
$container->setParameter('irstea_plant_uml.graph_keys', array_keys($config['graphs']));
}
public function loadGraph($key, array $config, ContainerBuilder $container)
......
<?php
/*
* © 2016 IRSTEA
* Guillaume Perréal <guillaume.perreal@irstea.fr>
* Tous droits réservés.
*/
namespace Irstea\PlantUmlBundle\Writer;
/**
* Description of OutputWriter
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
class StreamWriter extends AbstractWriter
{
/**
* @var resource
*/
private $stream;
public function __construct($stream)
{
if (!is_resource($stream)) {
throw new \InvalidArgumentException("Expecting a stream, not a ". gettype($stream));
}
$this->stream = $stream;
}
protected function doWrite($data)
{
fwrite($this->stream, $data);
}
}
Supports Markdown
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