4 * @copyright Copyright (c) 2007 Jerry Jalava <jerry.jalava@gmail.com>
5 * @copyright Copyright (c) 2007 Nemein Oy <http://nemein.com>
6 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
10 require_once "phing/Task.php";
11 require_once "File/Archive.php";
13 File_Archive
::setOption("zipCompressionLevel", 0);
16 * Phing release script for Ajatus
18 class releaseAjatus
extends Task
20 function __construct()
24 protected $returnProperty; // name of property to set to return value
27 * The target directory where the packed release file should be saved.
29 protected $target_dir = null;
32 * The target directory where the files to be packed should be saved temporarily.
34 protected $temp_dir = null;
37 * Version number for the release
39 private $version = null;
42 * List of files to include in release
44 private $app_files = null;
46 private $packjs_skip_files = array();
49 * The setter for the attribute "target_dir"
51 public function setTarget_dir($str)
53 $this->target_dir
= $str;
56 public function setTemp_dir($str)
58 $this->temp_dir
= $str;
61 public function setAction($str)
66 public function setVersion($str)
68 $this->version
= $str;
72 * Sets property name to set with return value of function or expression.
74 public function setReturnProperty($r)
76 $this->returnProperty
= $r;
80 * The init method: Do init steps.
82 public function init()
84 $this->packjs_skip_files
= array(
89 * The main entry point method.
91 public function main()
93 $this->_collect_files('.');
95 $temp_folder = $this->_copy_to_temp();
96 $this->_packjs_files($temp_folder);
97 $this->_pack_files($temp_folder);
99 $this->project
->setProperty($this->returnProperty
, "Ajatus-{$this->version}.zip");
102 private function _collect_files($path)
104 $directory = dir($path);
107 while (false !== ($entry = $directory->read()))
109 if (substr($entry, 0, 1) == '.') {
113 if ($entry == '.git') {
114 // Ignore GIT directories
117 if ( $entry == 'build.properties'
118 ||
$entry == 'build.xml'
119 ||
$entry == 'test.html')
121 // Ignore GIT directories
127 $path_parts = pathinfo($entry);
128 switch ($path_parts['extension'])
137 // if (strpos($path_parts['filename'], '.src') !== false) {
145 if (is_dir("{$path}/{$entry}"))
147 if ( $entry != 'build'
148 && $entry != 'testsuite'
150 && $entry != 'target'
151 && $entry != 'openpsa')
153 // List the subdirectory
154 $subpath = "{$path}/{$entry}";
155 $this->app_files
[] = $subpath;
157 $this->_collect_files($subpath);
163 $this->app_files
[] = "{$path}/{$entry}";
169 private function _copy_to_temp()
171 if (! is_dir($this->temp_dir
)) {
172 mkdir($this->temp_dir
);
175 $tmp_dir_root = "{$this->temp_dir}/{$this->version}";
177 if (is_dir($tmp_dir_root)) {
178 $this->_deltree($tmp_dir_root);
180 mkdir($tmp_dir_root);
182 $tmp_dir = "{$tmp_dir_root}/ajatus";
185 $this->_dcopy($this->app_files
, $tmp_dir);
187 return $tmp_dir_root;
190 private function _packjs_files($path)
195 private function _pack_files($path)
197 File_Archive
::extract(
199 File_Archive
::toArchive("{$this->target_dir}/Ajatus-{$this->version}.zip", File_Archive
::toFiles())
202 $this->_deltree($path);
205 private function _prepare_ajatus_core($core_file)
207 $handle = fopen($core_file, "r");
208 $contents = fread($handle, filesize($core_file));
210 $version_str = str_replace(".", ", ", $this->version
);
212 $pattern = '/(\$\.ajatus\.version) = \[(\d+), (\d+), (\d+)\]/i';
213 $replacement = '${1} = ['.$version_str.']';
214 $contents = preg_replace($pattern, $replacement, $contents);
216 $contents = str_replace("application_url: '/_utils/ajatus_dev/',", "application_url: '/_utils/ajatus/',", $contents);
217 $contents = str_replace("application_database_identifier: 'dev'", "application_database_identifier: ''", $contents);
221 $handle = fopen($core_file, "w+");
222 fwrite($handle, $contents);
228 private function _dcopy($files, $to)
230 if (is_array($files))
232 foreach ($files as $file)
236 $to_f = "{$to}/{$file}";
241 $to_f = "{$to}/{$file}";
242 copy("{$file}", "{$to_f}");
244 if (strpos($file, 'ajatus.core') !== false) {
245 $this->_prepare_ajatus_core($to_f);
252 private function _deltree($f)
256 foreach( scandir($f) as $item ) {
257 if ( !strcmp( $item, '.' ) ||
!strcmp( $item, '..' ) ) {
260 $this->_deltree("{$f}/{$item}");