added overflow scroll an fixed height to the related objects table
[ajatus.git] / build / releaseAjatus.php
blob66c76998771b8ca15aac6613f0cfd6f6b68e62a1
1 <?php
3 /**
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
7 * http://ajatus.info
9 */
10 require_once "phing/Task.php";
11 require_once "File/Archive.php";
13 File_Archive::setOption("zipCompressionLevel", 0);
15 /**
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
26 /**
27 * The target directory where the packed release file should be saved.
29 protected $target_dir = null;
31 /**
32 * The target directory where the files to be packed should be saved temporarily.
34 protected $temp_dir = null;
36 /**
37 * Version number for the release
39 private $version = null;
41 /**
42 * List of files to include in release
44 private $app_files = null;
46 private $packjs_skip_files = array();
48 /**
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)
63 $this->action = $str;
66 public function setVersion($str)
68 $this->version = $str;
71 /**
72 * Sets property name to set with return value of function or expression.
74 public function setReturnProperty($r)
76 $this->returnProperty = $r;
79 /**
80 * The init method: Do init steps.
82 public function init()
84 $this->packjs_skip_files = array(
88 /**
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);
106 // List contents
107 while (false !== ($entry = $directory->read()))
109 if (substr($entry, 0, 1) == '.') {
110 // Ignore dotfiles
111 continue;
113 if ($entry == '.git') {
114 // Ignore GIT directories
115 continue;
117 if ( $entry == 'build.properties'
118 || $entry == 'build.xml'
119 || $entry == 'test.html')
121 // Ignore GIT directories
122 continue;
125 $include = true;
127 $path_parts = pathinfo($entry);
128 switch ($path_parts['extension'])
130 case 'tmproj':
131 $include = false;
132 break;
133 case 'svg':
134 $include = false;
135 break;
136 case 'js':
137 // if (strpos($path_parts['filename'], '.src') !== false) {
138 // $include = false;
139 // }
140 break;
141 default:
142 break;
145 if (is_dir("{$path}/{$entry}"))
147 if ( $entry != 'build'
148 && $entry != 'testsuite'
149 && $entry != 'temp'
150 && $entry != 'target'
151 && $entry != 'openpsa')
153 // List the subdirectory
154 $subpath = "{$path}/{$entry}";
155 $this->app_files[] = $subpath;
157 $this->_collect_files($subpath);
160 else
162 if ($include) {
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";
183 mkdir($tmp_dir);
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(
198 $path,
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);
219 fclose($handle);
221 $handle = fopen($core_file, "w+");
222 fwrite($handle, $contents);
223 fclose($handle);
225 return true;
228 private function _dcopy($files, $to)
230 if (is_array($files))
232 foreach ($files as $file)
234 if (is_dir($file))
236 $to_f = "{$to}/{$file}";
237 mkdir("{$to_f}");
239 else
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)
254 if ( is_dir($f) )
256 foreach( scandir($f) as $item ) {
257 if ( !strcmp( $item, '.' ) || !strcmp( $item, '..' ) ) {
258 continue;
260 $this->_deltree("{$f}/{$item}");
262 rmdir($f);
263 } else {
264 unlink($f);