mrclay/minify — Issue #17: YUICompressor should alert when java executable is not found or went wrong
Author: meven
Created: 2012-01-18 09:26:22+00:00
State: open

Right now when java cannot be executed correctly no exception is raised.

In Minify/YUICompressor.php

I think the code :

private static function _prepare()
{
if (! is_file(self::$jarFile)
|| ! is_dir(self::$tempDir)
|| ! is_writable(self::$tempDir)
) {
throw new Exception('Minify_YUICompressor : $jarFile and $tempDir must be set.');
}
}

Should be replaced by something like :

private static function _prepare()
{
if (! is_file(self::$jarFile)
|| ! is_dir(self::$tempDir)
|| ! is_writable(self::$tempDir)
|| !is_exectuable(self::$jarFile)
) {
throw new Exception('Minify_YUICompressor : $jarFile and $tempDir must be set.');
}
}

And

private static function _minify($type, $content, $options)
{
self::_prepare();
if (! ($tmpFile = tempnam(self::$tempDir, 'yuic_'))) {
throw new Exception('Minify_YUICompressor : could not create temp file.');
}
file_put_contents($tmpFile, $content);
//echo self::_getCmd($options, $type, $tmpFile);
exec(self::_getCmd($options, $type, $tmpFile), $output);
unlink($tmpFile);
return implode("\n", $output);
}

By :

private static function _minify($type, $content, $options)
{
self::_prepare();
if (! ($tmpFile = tempnam(self::$tempDir, 'yuic_'))) {
throw new Exception('Minify_YUICompressor : could not create temp file.');
}
file_put_contents($tmpFile, $content);
//echo self::_getCmd($options, $type, $tmpFile);
exec(self::_getCmd($options, $type, $tmpFile), $output, $return_var);
unlink($tmpFile);
if($return_var != 0){
throw new Exception('Minify_YUICompressor : yuicompressor execution failed.');
}
return implode("\n", $output);
}