blob: 060dcb1514ed09d57d8088bd8ad5987dc00ad11a [file] [log] [blame]
kitlo2e780dc2010-01-12 17:58:32 +00001<?php
2/*******************************************************************************
3 * Copyright (c) 2010 Eclipse Foundation 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) - Initial API and implementation
11 * Kit Lo (IBM) - Bug 299402, Extract properties files from Eclipse project update sites for translation
12*******************************************************************************/
13/*
14 * Extract properties files from update sites
15 */
16# To-do: hard-coding the Eclipse, BIRT, & Webtools update sites for now; need to create an UI for project committers to enter their update sites
kitlo0da4aca2010-01-13 05:08:26 +000017$eclipse = array("http://download.eclipse.org/eclipse/updates/3.6milestones/S-3.6M4-200912101301", "eclipse", "3.6");
18$birt = array("http://download.eclipse.org/birt/update-site/2.6-interim", "birt", "2.6.0");
19$webtools = array("http://download.eclipse.org/webtools/updates", "webtools", "3.2");
20$update_sites = array($eclipse, $birt, $webtools);
kitlo2e780dc2010-01-12 17:58:32 +000021
22$temp_dir = "/tmp/tmp-babel/";
23$debug = TRUE;
24
25header("Content-type: text/plain");
26include("global.php");
27InitPage("");
28
29$headless = 0;
30if (!isset($User)) {
31 echo "User not defined - running headless\n";
32 $User = getGenieUser();
33 $headless = 1;
34}
35
36require(dirname(__FILE__) . "/../classes/file/file.class.php");
37global $dbh;
38
kitlo0da4aca2010-01-13 05:08:26 +000039$temp_unzips_dir = $temp_dir . "unzips/";
40if (is_dir($temp_unzips_dir)) {
41 exec("rm -rf $temp_unzips_dir");
kitlo2e780dc2010-01-12 17:58:32 +000042}
kitlo0da4aca2010-01-13 05:08:26 +000043mkdir($temp_unzips_dir, 0777, TRUE) || die("***ERROR: Cannot create working directory: $temp_unzips_dir\n");
44
45global $addon;
46$context = $addon->callHook('context');
47if ($context == "live") {
48 $rsync_host = "download.eclipse.org::eclipseMirror/";
49} else {
50 $rsync_host = "rsync.osuosl.org::eclipse/";
51}
kitlo2e780dc2010-01-12 17:58:32 +000052
53$files = array();
54$sql = "SELECT * FROM files WHERE is_active = 1";
55$rs_files = mysql_query($sql, $dbh);
56while ($myrow_files = mysql_fetch_assoc($rs_files)) {
57 $file = new File();
58 $file->project_id = $myrow_files['project_id'];
59 $file->version = $myrow_files['version'];
60 $file->name = $myrow_files['name'];
61 $file->plugin_id = $myrow_files['plugin_id'];
62 $file->file_id = $myrow_files['file_id'];
63 $files[$file->file_id] = $file;
64}
65
66foreach ($update_sites as $update_site) {
kitlo0da4aca2010-01-13 05:08:26 +000067 $site_url = $update_site[0];
kitlo2e780dc2010-01-12 17:58:32 +000068 $project_id = $update_site[1];
69 $version = $update_site[2];
kitlo0da4aca2010-01-13 05:08:26 +000070 # Sample dirs:
71 # $site_url http://download.eclipse.org/eclipse/updates/3.6milestones/S-3.6M4-200912101301
72 # $site_dir eclipse/updates/3.6milestones/S-3.6M4-200912101301/
73 # $site_plugins_dir eclipse/updates/3.6milestones/S-3.6M4-200912101301/plugins/
74 # $temp_site_dir /tmp/tmp-babel/update_sites/eclipse/3.6/
75 # $temp_unzip_dir /tmp/tmp-babel/unzips/eclipse/3.6/
76 $site_dir = substr($site_url, strpos($site_url, "/", 7) + 1) . "/";
77 $site_plugins_dir = $site_dir . "/plugins/";
78 $temp_site_dir = $temp_dir . "update_sites/" . $project_id . "/" . $version . "/";
79 $temp_unzip_dir = $temp_dir . "unzips/" . $project_id . "/" . $version . "/";
kitlo2e780dc2010-01-12 17:58:32 +000080
kitlo0da4aca2010-01-13 05:08:26 +000081 # Rsync update site
82 exec("mkdir -p $temp_site_dir; rsync -av --delete $rsync_host$site_plugins_dir $temp_site_dir");
83
84 # Make unzip dir
85 mkdir($temp_unzip_dir, 0777, TRUE);
86
87 # Unzip properties files in each jar
88 chdir($temp_site_dir);
kitlo2e780dc2010-01-12 17:58:32 +000089 foreach (glob("*.jar") as $jar_name) {
90 # Sample jar name: org.eclipse.ui.workbench_3.6.0.I20100105-1530.jar
91 #
92 # Remove plugin version from jar name:
93 # org.eclipse.ui.workbench_3.6.0.I20100105-1530.jar => org.eclipse.ui.workbench
94 $temp_str = $jar_name;
95 $temp_str = substr($temp_str, 0, strrpos($temp_str, "."));
96 $temp_str = substr($temp_str, 0, strrpos($temp_str, "."));
97 $temp_str = substr($temp_str, 0, strrpos($temp_str, "_"));
98 $plugin_id = $temp_str;
99
kitlo0da4aca2010-01-13 05:08:26 +0000100 mkdir($temp_unzip_dir . $plugin_id, 0777, TRUE);
101 chdir($temp_unzip_dir . $plugin_id);
102 exec("unzip -o -q $temp_site_dir$jar_name *.properties");
kitlo2e780dc2010-01-12 17:58:32 +0000103 }
104
kitlo0da4aca2010-01-13 05:08:26 +0000105 # Collect properties file names
kitlo2e780dc2010-01-12 17:58:32 +0000106 $properties_file_names = array();
kitlo0da4aca2010-01-13 05:08:26 +0000107 chdir($temp_unzip_dir);
kitlo2e780dc2010-01-12 17:58:32 +0000108 exec("find . -name *.properties", $properties_file_names);
109 sort($properties_file_names);
110
kitlo0da4aca2010-01-13 05:08:26 +0000111 # Parse each properties file
kitlo2e780dc2010-01-12 17:58:32 +0000112 echo "Start processing properties files in project $project_id version $version...\n";
113 foreach ($properties_file_names as $properties_file_name) {
114 $properties_file_name = substr($properties_file_name, 2);
115 $plugin_id = substr($properties_file_name, 0, strpos($properties_file_name, "/"));
116 $file_id = File::getFileID($properties_file_name, $project_id, $version);
117
118 if ($files[$file_id] != null) {
119 $file = $files[$file_id];
120 $file->is_active = 1;
121 unset($files[$file_id]);
122 } else {
123 $file = new File();
124 $file->project_id = $project_id;
125 $file->version = $version;
126 $file->name = $properties_file_name;
127 $file->plugin_id = $plugin_id;
128 $file->is_active = 1;
129 }
130 if (!$file->save()) {
131 echo "***ERROR: Cannot save file $file->name\n";
132 } else {
kitlo0da4aca2010-01-13 05:08:26 +0000133 $file_name = $temp_unzip_dir . $properties_file_name;
kitlo2e780dc2010-01-12 17:58:32 +0000134 $file->parseProperties(file_get_contents($file_name));
135 if ($debug) {
136 echo " " . $file->name . "\n";
137 }
138 }
139 }
140 echo "Done processing " . sizeof($properties_file_names) . " properties files in project $project_id version $version\n\n";
141}
142
143# Deactivate the rest of the files
144foreach ($files as $file) {
145 $file->is_active = 0;
146 if (!$file->save()) {
147 echo "***ERROR: Cannot deactivate file $file->name\n";
148 }
149 if ($debug) {
150 echo " " . $file->name . "\n";
151 }
152}
153
154if ($headless) {
155 $User = null;
156}
157
158echo "Done\n";
159?>