2727use Phing \Io \FileWriter ;
2828use Phing \Io \File ;
2929use Phing \Project ;
30+ use Phing \Util \StringHelper ;
3031use Psr \Http \Message \ResponseInterface ;
3132use SimpleXMLElement ;
3233use XSLTProcessor ;
@@ -113,9 +114,9 @@ public function init(): void
113114 $ this ->log ($ exceptionMessage , Project::MSG_ERR );
114115 throw new BuildException ($ exceptionMessage );
115116 }
116- $ this ->setFormat (VisualizerTask ::FORMAT_PNG );
117- $ this ->setServer (VisualizerTask ::SERVER );
118- $ this ->setDirection (VisualizerTask ::ARROWS_VERTICAL );
117+ $ this ->setFormat (self ::FORMAT_PNG );
118+ $ this ->setServer (self ::SERVER );
119+ $ this ->setDirection (self ::ARROWS_VERTICAL );
119120 $ this ->setShowTitle (true );
120121 $ this ->setShowDescription (false );
121122 $ this ->setFooter ('' );
@@ -140,6 +141,7 @@ public function main(): void
140141 * Retrieves loaded buildfiles and generates a PlantUML diagram
141142 *
142143 * @return string
144+ * @throws \Phing\Io\IOException
143145 */
144146 protected function generatePumlDiagram (): string
145147 {
@@ -158,6 +160,7 @@ protected function generatePumlDiagram(): string
158160 * @param \Phing\Io\File[] $buildFiles
159161 *
160162 * @return string
163+ * @throws \Phing\Io\IOException
161164 */
162165 protected function generatePuml (array $ buildFiles ): string
163166 {
@@ -167,17 +170,17 @@ protected function generatePuml(array $buildFiles): string
167170 throw new BuildException ($ exceptionMessage );
168171 }
169172
170- $ puml = $ this ->transformToPuml ($ firstBuildFile , VisualizerTask ::XSL_HEADER );
173+ $ puml = $ this ->transformToPuml ($ firstBuildFile , self ::XSL_HEADER );
171174
172175 $ puml = array_reduce ($ buildFiles , function (string $ carry , File $ buildFile ) {
173- return $ carry . $ this ->transformToPuml ($ buildFile , VisualizerTask ::XSL_CALLS );
176+ return $ carry . $ this ->transformToPuml ($ buildFile , self ::XSL_CALLS );
174177 }, $ puml );
175178
176179 $ puml = array_reduce ($ buildFiles , function (string $ carry , File $ buildFile ) {
177- return $ carry . $ this ->transformToPuml ($ buildFile , VisualizerTask ::XSL_TARGETS );
180+ return $ carry . $ this ->transformToPuml ($ buildFile , self ::XSL_TARGETS );
178181 }, $ puml );
179182
180- $ puml .= $ this ->transformToPuml ($ firstBuildFile , VisualizerTask ::XSL_FOOTER );
183+ $ puml .= $ this ->transformToPuml ($ firstBuildFile , self ::XSL_FOOTER );
181184
182185 return $ puml ;
183186 }
@@ -263,10 +266,10 @@ public function getFormat(): string
263266 public function setFormat (string $ format ): VisualizerTask
264267 {
265268 switch ($ format ) {
266- case VisualizerTask ::FORMAT_PUML :
267- case VisualizerTask ::FORMAT_PNG :
268- case VisualizerTask ::FORMAT_EPS :
269- case VisualizerTask ::FORMAT_SVG :
269+ case self ::FORMAT_PUML :
270+ case self ::FORMAT_PNG :
271+ case self ::FORMAT_EPS :
272+ case self ::FORMAT_SVG :
270273 $ this ->format = $ format ;
271274 break ;
272275 default :
@@ -301,9 +304,9 @@ public function setDestination(?string $destination): self
301304 /**
302305 * Figure diagram's file path
303306 *
304- * @param string $buildfilePath Path to main buildfile
305- * @param string $format Extension to use
306- * @param null|string $destination Desired destination provided by user
307+ * @param string $buildfilePath Path to main buildfile, this is used as fallback dir.
308+ * @param string $format Extension to use.
309+ * @param null|string $destination Desired destination provided by user.
307310 *
308311 * @return string
309312 */
@@ -321,7 +324,12 @@ protected function resolveDestination(string $buildfilePath, string $format, ?st
321324 $ destination .= DIRECTORY_SEPARATOR . $ buildfileInfo ['filename ' ] . '. ' . $ format ;
322325 }
323326
324- // Check if path is available
327+ // Adding right extension if necessary
328+ if (!StringHelper::endsWith (". $ format " , $ destination )) {
329+ $ destination .= ". $ format " ;
330+ }
331+
332+ // Parent directory must exist
325333 if (!is_dir (dirname ($ destination ))) {
326334 $ exceptionMessage = "Directory ' $ destination' is invalid " ;
327335 $ this ->log ($ exceptionMessage , Project::MSG_ERR );
@@ -342,7 +350,7 @@ protected function resolveDestination(string $buildfilePath, string $format, ?st
342350 */
343351 protected function generateImage (string $ pumlDiagram , string $ format ): string
344352 {
345- if ($ format === VisualizerTask ::FORMAT_PUML ) {
353+ if ($ format === self ::FORMAT_PUML ) {
346354 $ this ->log ('Bypassing, no need to call server ' , Project::MSG_DEBUG );
347355
348356 return $ pumlDiagram ;
@@ -360,6 +368,7 @@ protected function generateImage(string $pumlDiagram, string $format): string
360368 *
361369 * @param string $pumlDiagram
362370 * @param string $format
371+ * @throws \Jawira\PlantUmlClient\ClientException
363372 */
364373 protected function prepareImageUrl (string $ pumlDiagram , string $ format ): void
365374 {
@@ -466,7 +475,7 @@ protected function processResponse(ResponseInterface $response): void
466475 $ this ->log ("Response status: $ status " , Project::MSG_DEBUG );
467476 $ this ->log ("Response reason: $ reasonPhrase " , Project::MSG_DEBUG );
468477
469- if ($ status !== VisualizerTask ::STATUS_OK ) {
478+ if ($ status !== self ::STATUS_OK ) {
470479 $ exceptionMessage = "Request unsuccessful. Response from server: $ status $ reasonPhrase " ;
471480 $ this ->log ($ exceptionMessage , Project::MSG_ERR );
472481 throw new BuildException ($ exceptionMessage );
@@ -484,7 +493,7 @@ protected function processResponse(ResponseInterface $response): void
484493 protected function saveToFile (string $ content , File $ destination ): void
485494 {
486495 $ path = $ destination ->getPath ();
487- $ this ->log ("Writing: $ path " , Project:: MSG_INFO );
496+ $ this ->log ("Writing: $ path " );
488497
489498 (new FileWriter ($ destination ))->write ($ content );
490499 }
0 commit comments