Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switched to Google Closure compiler.
- Loading branch information
Alex Gorbatchev
committed
Jul 2, 2010
1 parent
04fc240
commit 682bf8c
Showing
4 changed files
with
89 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,81 @@ | ||
<?php | ||
require_once("phing/tasks/system/CopyTask.php"); | ||
require_once(dirname(__FILE__)."/packer/class.JavaScriptPacker.php"); | ||
|
||
class PackerTask extends CopyTask | ||
{ | ||
protected $filesets = array(); // all fileset objects assigned to this task | ||
|
||
/** | ||
* Nested creator, creates a FileSet for this task | ||
* | ||
* @access public | ||
* @return object The created fileset object | ||
*/ | ||
function createFileSet() | ||
{ | ||
$num = array_push($this->filesets, new FileSet()); | ||
return $this->filesets[$num-1]; | ||
} | ||
|
||
/** | ||
* Validates attributes coming in from XML | ||
* | ||
* @access private | ||
* @return void | ||
* @throws BuildException | ||
*/ | ||
protected function validateAttributes() | ||
{ | ||
if (count($this->filesets) === 0) | ||
throw new BuildException("PackerTask. Specify a fileset."); | ||
} | ||
|
||
public function init() | ||
{ | ||
} | ||
|
||
public function pack($file) | ||
{ | ||
$file = realpath($file); | ||
$home = dirname(__FILE__); | ||
$jar = realpath("$home/custom_rhino.jar"); | ||
|
||
$java = "java"; | ||
exec("$java -version", &$output, &$result); | ||
if ($result != 0) | ||
throw new BuildException("Java not found."); | ||
|
||
// first we pack the file using DOJO shrinksafe | ||
$cmd = "$java -jar \"$jar\" -c \"$file\" > \"$file.tmp\""; | ||
exec($cmd, &$output, &$result); | ||
|
||
if ($result != 0) | ||
throw new BuildException("Java error."); | ||
|
||
unlink($file); | ||
rename("$file.tmp", $file); | ||
|
||
// after DOJO, we use the Packer to tighten it up. | ||
$script = file_get_contents($file); | ||
$packer = new JavaScriptPacker($script, 62, true, false); | ||
$packed = $packer->pack(); | ||
file_put_contents($file, $packed); | ||
|
||
$this->log("$file packed.", Project::MSG_INFO); | ||
} | ||
|
||
public function main() | ||
{ | ||
foreach($this->filesets as $fs) | ||
{ | ||
$ds = $fs->getDirectoryScanner($this->project); | ||
$files = $ds->getIncludedFiles(); | ||
|
||
$dir = $fs->getDir($this->project); | ||
|
||
foreach($files as $file) | ||
$this->pack("$dir/$file"); | ||
} | ||
} | ||
} | ||
<?php | ||
require_once("phing/tasks/system/CopyTask.php"); | ||
require_once(dirname(__FILE__)."/packer/class.JavaScriptPacker.php"); | ||
|
||
class PackerTask extends CopyTask | ||
{ | ||
protected $filesets = array(); // all fileset objects assigned to this task | ||
|
||
/** | ||
* Nested creator, creates a FileSet for this task | ||
* | ||
* @access public | ||
* @return object The created fileset object | ||
*/ | ||
function createFileSet() | ||
{ | ||
$num = array_push($this->filesets, new FileSet()); | ||
return $this->filesets[$num-1]; | ||
} | ||
|
||
/** | ||
* Validates attributes coming in from XML | ||
* | ||
* @access private | ||
* @return void | ||
* @throws BuildException | ||
*/ | ||
protected function validateAttributes() | ||
{ | ||
if (count($this->filesets) === 0) | ||
throw new BuildException("PackerTask. Specify a fileset."); | ||
} | ||
|
||
public function init() | ||
{ | ||
} | ||
|
||
public function pack($file) | ||
{ | ||
$file = realpath($file); | ||
$home = dirname(__FILE__); | ||
$jar = realpath("$home/compiler.jar"); | ||
|
||
$java = "java"; | ||
exec("$java -version", &$output, &$result); | ||
if ($result != 0) | ||
throw new BuildException("Java not found."); | ||
|
||
// first we pack the file using DOJO shrinksafe | ||
$cmd = "$java -jar \"$jar\" --js=\"$file\" --js_output_file=\"$file.tmp\""; | ||
exec($cmd, &$output, &$result); | ||
|
||
if ($result != 0) | ||
throw new BuildException("Java error."); | ||
|
||
unlink($file); | ||
rename("$file.tmp", $file); | ||
|
||
// after DOJO, we use the Packer to tighten it up. | ||
$script = file_get_contents($file); | ||
$packer = new JavaScriptPacker($script, 62, true, false); | ||
$packed = $packer->pack(); | ||
file_put_contents($file, $packed); | ||
|
||
$this->log("$file packed.", Project::MSG_INFO); | ||
} | ||
|
||
public function main() | ||
{ | ||
foreach($this->filesets as $fs) | ||
{ | ||
$ds = $fs->getDirectoryScanner($this->project); | ||
$files = $ds->getIncludedFiles(); | ||
|
||
$dir = $fs->getDir($this->project); | ||
|
||
foreach($files as $file) | ||
$this->pack("$dir/$file"); | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.