blob: 3b4287861e876feb642631c57e70f2e4ee1da920 [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");
kitlo27e80be2010-01-13 13:03:55 +000020
21# BIRT 2.6.0 & Webtools 3.2 are not defined yet, cannot test on staging server
22#$update_sites = array($eclipse, $birt, $webtools);
23$update_sites = array($eclipse);
kitlo2e780dc2010-01-12 17:58:32 +000024
25$temp_dir = "/tmp/tmp-babel/";
26$debug = TRUE;
kitlo3efbb262010-01-13 15:18:57 +000027$files = array();
kitlo2e780dc2010-01-12 17:58:32 +000028
29header("Content-type: text/plain");
30include("global.php");
31InitPage("");
32
33$headless = 0;
34if (!isset($User)) {
35 echo "User not defined - running headless\n";
36 $User = getGenieUser();
37 $headless = 1;
38}
39
40require(dirname(__FILE__) . "/../classes/file/file.class.php");
41global $dbh;
42
kitlo0da4aca2010-01-13 05:08:26 +000043$temp_unzips_dir = $temp_dir . "unzips/";
44if (is_dir($temp_unzips_dir)) {
45 exec("rm -rf $temp_unzips_dir");
kitlo2e780dc2010-01-12 17:58:32 +000046}
kitlo0da4aca2010-01-13 05:08:26 +000047mkdir($temp_unzips_dir, 0777, TRUE) || die("***ERROR: Cannot create working directory: $temp_unzips_dir\n");
48
49global $addon;
50$context = $addon->callHook('context');
51if ($context == "live") {
52 $rsync_host = "download.eclipse.org::eclipseMirror/";
53} else {
54 $rsync_host = "rsync.osuosl.org::eclipse/";
55}
kitlo2e780dc2010-01-12 17:58:32 +000056
kitlo2e780dc2010-01-12 17:58:32 +000057foreach ($update_sites as $update_site) {
kitlo0da4aca2010-01-13 05:08:26 +000058 $site_url = $update_site[0];
kitlo2e780dc2010-01-12 17:58:32 +000059 $project_id = $update_site[1];
60 $version = $update_site[2];
kitlo0da4aca2010-01-13 05:08:26 +000061 # Sample dirs:
62 # $site_url http://download.eclipse.org/eclipse/updates/3.6milestones/S-3.6M4-200912101301
63 # $site_dir eclipse/updates/3.6milestones/S-3.6M4-200912101301/
64 # $site_plugins_dir eclipse/updates/3.6milestones/S-3.6M4-200912101301/plugins/
65 # $temp_site_dir /tmp/tmp-babel/update_sites/eclipse/3.6/
66 # $temp_unzip_dir /tmp/tmp-babel/unzips/eclipse/3.6/
67 $site_dir = substr($site_url, strpos($site_url, "/", 7) + 1) . "/";
68 $site_plugins_dir = $site_dir . "/plugins/";
69 $temp_site_dir = $temp_dir . "update_sites/" . $project_id . "/" . $version . "/";
70 $temp_unzip_dir = $temp_dir . "unzips/" . $project_id . "/" . $version . "/";
kitlo2e780dc2010-01-12 17:58:32 +000071
kitlo3efbb262010-01-13 15:18:57 +000072 # Find all current active files for this project version
73 $sql = "SELECT * FROM files WHERE is_active = 1 AND project_id = \"$project_id\" AND version = \"$version\"";
74 $rs_files = mysql_query($sql, $dbh);
75 while ($myrow_files = mysql_fetch_assoc($rs_files)) {
76 $file = new File();
77 $file->project_id = $myrow_files['project_id'];
78 $file->version = $myrow_files['version'];
79 $file->name = $myrow_files['name'];
80 $file->plugin_id = $myrow_files['plugin_id'];
81 $file->file_id = $myrow_files['file_id'];
82 $files[$file->file_id] = $file;
83 }
84
kitlo0da4aca2010-01-13 05:08:26 +000085 # Rsync update site
86 exec("mkdir -p $temp_site_dir; rsync -av --delete $rsync_host$site_plugins_dir $temp_site_dir");
87
88 # Make unzip dir
89 mkdir($temp_unzip_dir, 0777, TRUE);
90
91 # Unzip properties files in each jar
92 chdir($temp_site_dir);
kitlo2e780dc2010-01-12 17:58:32 +000093 foreach (glob("*.jar") as $jar_name) {
94 # Sample jar name: org.eclipse.ui.workbench_3.6.0.I20100105-1530.jar
95 #
96 # Remove plugin version from jar name:
97 # org.eclipse.ui.workbench_3.6.0.I20100105-1530.jar => org.eclipse.ui.workbench
98 $temp_str = $jar_name;
99 $temp_str = substr($temp_str, 0, strrpos($temp_str, "."));
100 $temp_str = substr($temp_str, 0, strrpos($temp_str, "."));
101 $temp_str = substr($temp_str, 0, strrpos($temp_str, "_"));
102 $plugin_id = $temp_str;
103
kitlo20071c52010-01-13 14:10:52 +0000104 if (!is_dir($temp_unzip_dir . $plugin_id)) {
105 mkdir($temp_unzip_dir . $plugin_id, 0777, TRUE);
106 }
kitlo0da4aca2010-01-13 05:08:26 +0000107 chdir($temp_unzip_dir . $plugin_id);
kitlo281a6412010-01-13 13:34:57 +0000108 exec("unzip -o -q $temp_site_dir$jar_name");
kitlo2e780dc2010-01-12 17:58:32 +0000109 }
110
kitlo0da4aca2010-01-13 05:08:26 +0000111 # Collect properties file names
kitlo2e780dc2010-01-12 17:58:32 +0000112 $properties_file_names = array();
kitlo0da4aca2010-01-13 05:08:26 +0000113 chdir($temp_unzip_dir);
kitlo2e780dc2010-01-12 17:58:32 +0000114 exec("find . -name *.properties", $properties_file_names);
115 sort($properties_file_names);
116
kitlo0da4aca2010-01-13 05:08:26 +0000117 # Parse each properties file
kitlo2e780dc2010-01-12 17:58:32 +0000118 echo "Start processing properties files in project $project_id version $version...\n";
119 foreach ($properties_file_names as $properties_file_name) {
120 $properties_file_name = substr($properties_file_name, 2);
121 $plugin_id = substr($properties_file_name, 0, strpos($properties_file_name, "/"));
122 $file_id = File::getFileID($properties_file_name, $project_id, $version);
123
124 if ($files[$file_id] != null) {
125 $file = $files[$file_id];
126 $file->is_active = 1;
127 unset($files[$file_id]);
128 } else {
129 $file = new File();
130 $file->project_id = $project_id;
131 $file->version = $version;
132 $file->name = $properties_file_name;
133 $file->plugin_id = $plugin_id;
134 $file->is_active = 1;
135 }
136 if (!$file->save()) {
137 echo "***ERROR: Cannot save file $file->name\n";
138 } else {
kitlo0da4aca2010-01-13 05:08:26 +0000139 $file_name = $temp_unzip_dir . $properties_file_name;
kitlo2e780dc2010-01-12 17:58:32 +0000140 $file->parseProperties(file_get_contents($file_name));
141 if ($debug) {
142 echo " " . $file->name . "\n";
143 }
144 }
145 }
146 echo "Done processing " . sizeof($properties_file_names) . " properties files in project $project_id version $version\n\n";
147}
148
149# Deactivate the rest of the files
150foreach ($files as $file) {
151 $file->is_active = 0;
152 if (!$file->save()) {
153 echo "***ERROR: Cannot deactivate file $file->name\n";
154 }
155 if ($debug) {
156 echo " " . $file->name . "\n";
157 }
158}
159
160if ($headless) {
161 $User = null;
162}
163
164echo "Done\n";
165?>