blob: 0af32c8e9267f8b865bf70ba567e2715cdd113b7 [file] [log] [blame]
Kit Lo3c7ce142013-03-02 18:22:40 -05001<?php
2/*******************************************************************************
3 * Copyright (c) 2013 IBM Corporation and others.
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Kit Lo (IBM) - [402192] Extract project source files from Git repositories for translation
11 *******************************************************************************/
12
13/*
14 * Extract properties or js files from update sites
15 */
16$temp_dir = "/tmp/tmp-babel/";
17$files = array();
18$files_collected = array(array());
19
20header("Content-type: text/plain");
21include("global.php");
22InitPage("");
23
24$headless = 0;
25if (!isset($User)) {
26 echo "User not defined - running headless\n";
27 $User = getGenieUser();
28 $headless = 1;
29}
30
31require(dirname(__FILE__) . "/../classes/file/file.class.php");
32global $dbh;
33
34$temp_unzips_dir = $temp_dir . "unzips/";
35if (is_dir($temp_unzips_dir)) {
36 exec("rm -rf $temp_unzips_dir");
37}
38mkdir($temp_unzips_dir, 0777, TRUE) || die("***ERROR: Cannot create working directory: $temp_unzips_dir\n");
39
40global $addon;
41$context = $addon->callHook('context');
42if ($context == "live") {
43 $rsync_host = "download.eclipse.org::eclipseFullMirror/";
44} else {
45 $rsync_host = "rsync.osuosl.org::eclipse/";
46}
47
48# Get all active update sites
49$sql = "SELECT * FROM project_source_locations AS m
50INNER JOIN release_train_projects AS r ON r.project_id = m.project_id AND r.version = m.version
51INNER JOIN release_trains AS t on t.train_id = r.train_id
52WHERE t.is_active = 1";
53$rs_maps = mysql_query($sql, $dbh);
54while($update_site = mysql_fetch_assoc($rs_maps)) {
55 $site_url = $update_site['location'];
56 $project_id = $update_site['project_id'];
57 $version = $update_site['version'];
58
59 # Sample dirs:
60 # $site_url http://git.eclipse.org/c/platform/eclipse.platform.git/snapshot/I20130101-0800.zip
61 # $temp_snapshots_dir /tmp/tmp-babel/snapshots/eclipse/4.3/
62 # $temp_unzips_dir /tmp/tmp-babel/unzips/eclipse/4.3/
63 $temp_snapshots_dir = $temp_dir . "snapshots/" . $project_id . "/" . $version . "/";
64 $temp_unzips_dir = $temp_dir . "unzips/" . $project_id . "/" . $version . "/";
65
66 # Collect all files for this project version
67 if (!(isset($files_collected[$project_id]) && isset($files_collected[$project_id][$version]))) {
68 $files_collected[$project_id][$version] = 1;
69 $sql = "SELECT * FROM files WHERE project_id = \"$project_id\" AND version = \"$version\"";
70 $rs_files = mysql_query($sql, $dbh);
71 while ($myrow_files = mysql_fetch_assoc($rs_files)) {
72 $file = new File();
73 $file->project_id = $myrow_files['project_id'];
74 $file->version = $myrow_files['version'];
75 $file->name = $myrow_files['name'];
76 $file->plugin_id = $myrow_files['plugin_id'];
77 $file->file_id = $myrow_files['file_id'];
78 $file->is_active = $myrow_files['is_active'];
79 $files[$file->file_id] = $file;
80 }
81 }
82
83 # Collect all plugin exclude patterns for this project version
84 $sql = "SELECT pattern FROM plugin_exclude_patterns WHERE project_id = \"$project_id\" AND version = \"$version\"";
85 $rs_patterns = mysql_query($sql, $dbh);
86 $patterns = Array();
87 # Add default exclude patterns
88 $patterns[] = "/^.*\/feature.properties$/";
89 $patterns[] = "/^.*\/build.properties$/";
90 $patterns[] = "/^.*\/pom.properties$/";
91 $patterns[] = "/^.*\.source\/.*$/";
92 $patterns[] = "/^.*\.test\/.*$/";
93 $patterns[] = "/^.*\.tests\/.*$/";
94 $patterns[] = "/^.*\.testing\/.*$/";
95 while ($myrow_patterns = mysql_fetch_assoc($rs_patterns)) {
96 $patterns[] = $myrow_patterns['pattern'];
97 }
98
99 exec("mkdir -p $temp_snapshots_dir");
100 exec("wget $site_url -O ${temp_snapshots_dir}snapshot.zip");
101
102 # Make unzip dir
103 mkdir($temp_unzips_dir, 0777, TRUE);
104 chdir($temp_unzips_dir);
105 exec("unzip -o -q ${temp_snapshots_dir}snapshot.zip");
106
107 # Collect properties file names
108 $properties_file_names = array();
109 chdir($temp_unzips_dir);
110 exec("find . -name *.properties", $properties_file_names);
111 sort($properties_file_names);
112
113 # Parse each properties file
114 echo "Start processing properties files in project $project_id version $version...\n";
115 echo " Update site location: $site_url\n";
116 foreach ($properties_file_names as $properties_file_name) {
117 # extract plugin name
118 $file_name = $temp_unzips_dir . $properties_file_name;
119 $properties_file_name = substr($properties_file_name, strrpos($properties_file_name, "org."));
120 $plugin_id = substr($properties_file_name, 0, strpos($properties_file_name, "/"));
121 $pos = strpos($properties_file_name, '/');
122 if ($pos !== false) {
123 $properties_file_name = substr($properties_file_name, $pos);
124 }
125
126 # remove optional source dir, e.g. 'src' or 'src_ant'
127 $pos = stripos($properties_file_name, '/org/');
128 if ($pos !== false) {
129 $properties_file_name = substr($properties_file_name, $pos);
130 }
131 $pos = strripos($properties_file_name, '/com/');
132 if ($pos !== false) {
133 $properties_file_name = substr($properties_file_name, $pos);
134 }
135
136 # get file ID
137 $properties_file_name = $plugin_id . $properties_file_name;
138 $file_id = File::getFileID($properties_file_name, $project_id, $version);
139
140 # Match plugin exclude list
141 $match = false;
142 foreach ($patterns as $pattern) {
143 if (preg_match($pattern, $properties_file_name)) {
144 $match = true;
145 break;
146 }
147 }
148
149 if (!$match) {
150 if ($file_id > 0 && $files[$file_id] != null) {
151 # Existing file
152 $file = $files[$file_id];
153 $file->is_active = 1;
154 unset($files[$file_id]);
155 } else {
156 # New file
157 $file = new File();
158 $file->project_id = $project_id;
159 $file->version = $version;
160 $file->name = $properties_file_name;
161 $file->plugin_id = $plugin_id;
162 $file->is_active = 1;
163 }
164 if (!$file->save()) {
165 echo "***ERROR: Cannot save file $file->name\n";
166 } else {
167 $file_contents = ereg_replace("\r\n?", "\n", file_get_contents($file_name));
168 $file->parseProperties($file_contents);
169 echo " $properties_file_name\n";
170 }
171 } else {
172 echo " !!! Excluding $properties_file_name\n";
173 }
174 }
175 echo "Done processing " . sizeof($properties_file_names) . " properties files in project $project_id version $version\n\n";
176
177 # Collect js file names
178 $js_file_names = array();
179 chdir($temp_unzips_dir);
180 exec("find . -name *.js | grep nls/root", $js_file_names);
181 sort($js_file_names);
182
183 # Parse each js file
184 echo "Start processing js files in project $project_id version $version...\n";
185 echo " Update site location: $site_url\n";
186 foreach ($js_file_names as $js_file_name) {
187 $file_name = $temp_unzips_dir . $js_file_name;
188 $js_file_name = substr($js_file_name, strrpos($js_file_name, "org.eclipse."));
189 $plugin_id = substr($js_file_name, 0, strpos($js_file_name, "/"));
190 $file_id = File::getFileID($js_file_name, $project_id, $version);
191
192 # Match plugin exclude list
193 $match = false;
194 foreach ($patterns as $pattern) {
195 if (preg_match($pattern, $js_file_name)) {
196 $match = true;
197 break;
198 }
199 }
200
201 if (!$match) {
202 if ($file_id > 0 && $files[$file_id] != null) {
203 # Existing file
204 $file = $files[$file_id];
205 $file->is_active = 1;
206 unset($files[$file_id]);
207 } else {
208 # New file
209 $file = new File();
210 $file->project_id = $project_id;
211 $file->version = $version;
212 $file->name = $js_file_name;
213 $file->plugin_id = $plugin_id;
214 $file->is_active = 1;
215 }
216 if (!$file->save()) {
217 echo "***ERROR: Cannot save file $file->name\n";
218 } else {
219 $file_contents = ereg_replace("\r\n?", "\n", file_get_contents($file_name));
220 $file->parseJs($file_contents);
221 echo " $js_file_name\n";
222 }
223 } else {
224 echo " !!! Excluding $js_file_name\n";
225 }
226 }
227 echo "Done processing " . sizeof($js_file_names) . " js files in project $project_id version $version\n\n";
228
229 chdir($temp_dir);
230 exec("rm -rf $temp_snapshots_dir");
231 exec("rm -rf $temp_unzips_dir");
232}
233
234# Deactivate the rest of the files
235echo "Start deactivating inactive properties or js files in all projects above...\n";
236foreach ($files as $file) {
237 if ($file->is_active == 1) {
238 $file->is_active = 0;
239 if (!$file->save()) {
240 echo "***ERROR: Cannot deactivate file $file->name\n";
241 }
242 echo " " . $file->name . "\n";
243 } else {
244 unset($files[$file->file_id]);
245 }
246}
247echo "Done deactivating " . sizeof($files) . " inactive properties or js files in all projects above\n\n";
248
249chdir($temp_dir);
250exec("rm -rf snapshots");
251exec("rm -rf unzips");
252
253if ($headless) {
254 $User = null;
255}
256
257echo "Done\n";
258?>