From 8c54519b32b2230293be60c5f9a8f514401171fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Tue, 15 Jan 2013 14:53:45 +0200 Subject: [PATCH] Minify_YUICompressor: add support for increasing stack size --- min/lib/Minify/YUICompressor.php | 14 ++++++-- min_unit_tests/test_Minify_YuiCSS.php | 46 +++++++++++++++++++++++++++ min_unit_tests/test_all.php | 1 + 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 min_unit_tests/test_Minify_YuiCSS.php diff --git a/min/lib/Minify/YUICompressor.php b/min/lib/Minify/YUICompressor.php index ef44629..8e6bfcb 100644 --- a/min/lib/Minify/YUICompressor.php +++ b/min/lib/Minify/YUICompressor.php @@ -13,14 +13,17 @@ * Java environment. * * - * Minify_YUICompressor::$jarFile = '/path/to/yuicompressor-2.3.5.jar'; + * Minify_YUICompressor::$jarFile = '/path/to/yuicompressor-2.4.6.jar'; * Minify_YUICompressor::$tempDir = '/tmp'; * $code = Minify_YUICompressor::minifyJs( * $code * ,array('nomunge' => true, 'line-break' => 1000) * ); * - * + * + * Note: In case you run out stack (default is 512k), you may increase stack size in $options: + * array('stack-size' => '2048k') + * * @todo unit tests, $options docs * * @package Minify @@ -108,10 +111,15 @@ class Minify_YUICompressor { ,'nomunge' => false ,'preserve-semi' => false ,'disable-optimizations' => false + ,'stack-size' => '' ) ,$userOptions ); - $cmd = self::$javaExecutable . ' -jar ' . escapeshellarg(self::$jarFile) + $cmd = self::$javaExecutable + . (!empty($o['stack-size']) + ? ' -Xss' . $o['stack-size'] + : '') + . ' -jar ' . escapeshellarg(self::$jarFile) . " --type {$type}" . (preg_match('/^[\\da-zA-Z0-9\\-]+$/', $o['charset']) ? " --charset {$o['charset']}" diff --git a/min_unit_tests/test_Minify_YuiCSS.php b/min_unit_tests/test_Minify_YuiCSS.php new file mode 100644 index 0000000..b0f33d0 --- /dev/null +++ b/min_unit_tests/test_Minify_YuiCSS.php @@ -0,0 +1,46 @@ +getMessage() == 'Minify_YUICompressor : YUI compressor execution failed.', 'got expected Exception'); + } + + try { + $options = array( + 'stack-size' => '2m', + ); + $minOutput = Minify_YUICompressor::minifyCss($src, $options); + } catch (Exception $e) { + assertTrue(false, $e->getMessage());; + $minOutput = false; + } + + $passed = assertTrue($minExpected == $minOutput, 'Minify_YUICompressor : Overall'); + if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) { + echo "\n---Output: " .countBytes($minOutput). " bytes\n\n{$minOutput}\n\n"; + echo "---Expected: " .countBytes($minExpected). " bytes\n\n{$minExpected}\n\n"; + echo "---Source: " .countBytes($src). " bytes\n\n{$src}\n\n\n"; + } +} + +test_Minify_YuiCSS(); diff --git a/min_unit_tests/test_all.php b/min_unit_tests/test_all.php index ff26b51..caba028 100644 --- a/min_unit_tests/test_all.php +++ b/min_unit_tests/test_all.php @@ -10,6 +10,7 @@ require 'test_Minify_Cache_ZendPlatform.php'; require 'test_Minify_CSS.php'; require 'test_Minify_CSS_UriRewriter.php'; require 'test_Minify_JS_ClosureCompiler.php'; +require 'test_Minify_YuiCSS.php'; require 'test_Minify_CommentPreserver.php'; require 'test_Minify_HTML.php'; require 'test_Minify_ImportProcessor.php';