blob: 5931680b016859b7b08594c29eea83709bab0b51 [file] [log] [blame]
droy3bb0c962008-01-17 20:45:01 +00001<?php
2/*******************************************************************************
3 * Copyright (c) 2008 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 * Eclipse Foundation - Initial API and implementation
droyb9c2cb12008-10-08 13:58:14 +000011 * Antoine Toulmé - Bug 248917
atoulmea8c21012009-01-27 14:06:40 +000012 * Motorola - Change SVN map file format to follow SVN PDE
13 * Gustavo de Paula - Bug 261252
droy3bb0c962008-01-17 20:45:01 +000014*******************************************************************************/
droy87d1b182008-03-04 21:55:24 +000015header("Content-type: text/plain");
droy3bb0c962008-01-17 20:45:01 +000016include("global.php");
17InitPage("");
18
droy58210512008-02-05 16:05:48 +000019$headless = 0;
20if(!isset($User)) {
21 echo "User not defined -- running headless.";
atoulme9118d612008-11-12 18:21:38 +000022 $User = getGenieUser();
droy58210512008-02-05 16:05:48 +000023 $headless = 1;
24}
25
droy3bb0c962008-01-17 20:45:01 +000026
atoulme12882d52009-01-26 18:39:17 +000027require(dirname(__FILE__) . "/../classes/file/file.class.php");
droy87d1b182008-03-04 21:55:24 +000028$html_spacer = " ";
droy3bb0c962008-01-17 20:45:01 +000029
atoulme3e5e9342009-01-23 17:34:30 +000030global $dbh;
droy3bb0c962008-01-17 20:45:01 +000031
32if(!is_dir("/tmp/tmp-babel")) {
33 mkdir("/tmp/tmp-babel") || die("Cannot create a working directory");
34}
35chdir("/tmp/tmp-babel") || die("Cannot use working directory");
36
37
atoulmee9ec6d82008-11-19 14:41:30 +000038$files = array();
39$sql = "SELECT * from files";
40$rs_files = mysql_query($sql, $dbh);
41while($myrow_file = mysql_fetch_assoc($rs_files)) {
42 $File = new File();
43 $File->project_id = $myrow_file['project_id'];
44 $File->version = $myrow_file['version'];
45 $File->name = $myrow_file['name'];
46 $File->plugin_id = $myrow_file['plugin_id'];
47 $File->file_id = $myrow_file['file_id'];
48 $files[$File->file_id] = $File;
49}
droy3bb0c962008-01-17 20:45:01 +000050
51
droyabf32a12008-05-09 18:46:20 +000052$sql = "SELECT * FROM map_files WHERE is_active = 1 ORDER BY RAND()";
droy3bb0c962008-01-17 20:45:01 +000053$rs_maps = mysql_query($sql, $dbh);
droyd9a61af2008-02-26 16:20:29 +000054while($myrow_maps = mysql_fetch_assoc($rs_maps)) {
droy87d1b182008-03-04 21:55:24 +000055 echo "Processing map file: " . $myrow_maps['filename'] . " in location: " . $myrow_maps['location'] . "\n";
droy3bb0c962008-01-17 20:45:01 +000056
atoulme84cb3742008-12-05 11:01:39 +000057 $tmpdir = "/tmp/tmp-babel/" . str_replace(" ", "_", $myrow_maps['project_id']);
droyd9a61af2008-02-26 16:20:29 +000058 if(is_dir($tmpdir)) {
59 # zap the directory to make sure CVS versions don't overlap
60 exec("rm -rf " . $tmpdir);
droy3bb0c962008-01-17 20:45:01 +000061 }
droyd9a61af2008-02-26 16:20:29 +000062 mkdir($tmpdir) || die("Cannot create working directory $tmpdir !");
droy3bb0c962008-01-17 20:45:01 +000063 chdir($tmpdir) || die("Cannot write to $tmpdir !");
64
droyd9a61af2008-02-26 16:20:29 +000065 $h = fopen($myrow_maps['location'], "rb");
droy3bb0c962008-01-17 20:45:01 +000066 $file_contents = stream_get_contents($h);
67 fclose($h);
68 $aLines = split("\n", $file_contents);
69
70
71 foreach ($aLines as $line) {
72 $line = trim($line);
73
droy87d1b182008-03-04 21:55:24 +000074 # plugin@org.eclipse.emf.query=v200802262150,:pserver:anonymous@dev.eclipse.org:/cvsroot/modeling,,org.eclipse.emf/org.eclipse.emf.query/plugins/org.eclipse.emf.query
droy3bb0c962008-01-17 20:45:01 +000075 if(preg_match("/^(plugin|fragment)/", $line)) {
droyb9c2cb12008-10-08 13:58:14 +000076 echo $html_spacer . "Processing line: " . $line . "\n";
droy3bb0c962008-01-17 20:45:01 +000077 $aParts = split("=", $line);
droy87d1b182008-03-04 21:55:24 +000078 $aElements = split("@", $aParts[0]);
droyb9c2cb12008-10-08 13:58:14 +000079 $plugin_id = $aElements[1];
droy3bb0c962008-01-17 20:45:01 +000080 if($aElements[0] == "plugin") {
droyb9c2cb12008-10-08 13:58:14 +000081 echo $html_spacer . $html_spacer . "Processing plugin: " . $aParts[1] . "\n";
droy3bb0c962008-01-17 20:45:01 +000082 $aStuff = parseLocation($aParts[1]);
83
84 $tagstring = "";
85 if(isset($aStuff['tag'])) {
86 $tagstring = "-r " . $aStuff['tag'] . " ";
87 }
droy87d1b182008-03-04 21:55:24 +000088 if(isset($aStuff['plugin'])) {
89 if($aStuff['plugin'] != "") {
90 $aElements[1] = $aStuff['plugin'];
91 }
92 }
droyd9a61af2008-02-26 16:20:29 +000093
droyf3b43282008-05-09 18:45:12 +000094 $command = "";
95 # determine CVS or SVN
96 if(isset($aStuff['cvsroot'])) {
97 $command = "cvs -d " . $aStuff['cvsroot'] . " co " . $tagstring . $aElements[1];
98 }
99 elseif( isset($aStuff['svnroot'])) {
100 $command = "/usr/local/bin/svn co " . $aStuff['svnroot'] . " --config-dir /tmp";
101 }
droy87d1b182008-03-04 21:55:24 +0000102 echo $html_spacer . $html_spacer ."--> " . $command . "\n";
droyf3b43282008-05-09 18:45:12 +0000103
104 $out = "";
105 if($command != "") {
106 $out = shell_exec($command);
107 }
droy3bb0c962008-01-17 20:45:01 +0000108
109 # process the output lines for .properties
110 $aOutLines = split("\n", $out);
111 foreach ($aOutLines as $out_line) {
112 $out_line = trim($out_line);
droyf3b43282008-05-09 18:45:12 +0000113 # remove SVN's multiple spaces
114 $out_line = preg_replace("/\s+/", " ", $out_line);
115
droy87d1b182008-03-04 21:55:24 +0000116 echo $html_spacer . $html_spacer . "CVS out line: " . $out_line . "\n";
droyf3b43282008-05-09 18:45:12 +0000117 # CVS:
droyec50f102008-02-01 19:33:10 +0000118 # U org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/dtd/util/AntDTDUtilMessages.properties
droyf3b43282008-05-09 18:45:12 +0000119 # SVN:
120 # A org.eclipse.stp.bpmn/trunk/org.eclipse.stp.bpmn/org.eclipse.stp.eid/trunk/org.eclipse.stp.eid.generator.test/build.properties
droye19e49b2008-01-31 14:05:50 +0000121 if(preg_match("/\.properties$/", $out_line) && !preg_match("/build\.properties$/", $out_line)) {
droy3bb0c962008-01-17 20:45:01 +0000122 # this is a .properties file!
droyec50f102008-02-01 19:33:10 +0000123 $file_name = trim(substr($out_line, 2));
droy87d1b182008-03-04 21:55:24 +0000124 echo $html_spacer . $html_spacer . $html_spacer . "Processing .properties file: " . $file_name . "\n";
droy3bb0c962008-01-17 20:45:01 +0000125
atoulmebe3eae82008-12-05 16:38:20 +0000126 $file_id = File::getFileID($file_name, $myrow_maps['project_id'], $myrow_maps['version']);
atoulmee9ec6d82008-11-19 14:41:30 +0000127
128 if ($files[$file_id] != null) {
129 $File = $files[$file_id];
130 $File->isActive = 1;
131 unset($files[$file_id]);
132 } else {
133 $File = new File();
134 $File->project_id = $myrow_maps['project_id'];
135 $File->version = $myrow_maps['version'];
136 $File->name = $file_name;
137 $File->plugin_id = $plugin_id;
138 $File->isActive = 1;
139 }
droy3bb0c962008-01-17 20:45:01 +0000140 if(!$File->save()) {
droy87d1b182008-03-04 21:55:24 +0000141 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "***ERROR saving file: " . $file_name . "\n";
droy3bb0c962008-01-17 20:45:01 +0000142 }
143 else {
144 # Start importing the strings!
145 $fh = fopen($file_name, 'r');
146 $size = filesize($file_name);
147
148 $content = fread($fh, $size);
149 fclose($fh);
150
151 $strings = $File->parseProperties($content);
droy87d1b182008-03-04 21:55:24 +0000152 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "Strings processed: $strings\n\n";
droy3bb0c962008-01-17 20:45:01 +0000153 }
154
155 }
156 }
157 }
158 }
159 }
160}
atoulmee9ec6d82008-11-19 14:41:30 +0000161echo "Marking the remaining files as inactive\n";
162
163foreach ($files as $file) {
164 $file->isActive = 0;
165 if(!$file->save()) {
166 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "***ERROR saving file: " . $file->name . "\n";
167 }
168}
169
droy1df37fc2008-02-28 21:29:46 +0000170echo "Done.";
droy3bb0c962008-01-17 20:45:01 +0000171
droy58210512008-02-05 16:05:48 +0000172if($headless) {
173 $User = null;
174}
175
droy3bb0c962008-01-17 20:45:01 +0000176function parseLocation($in_string) {
177 # in_string looks something like this:
178 # v_832,:pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse,
droyd9a61af2008-02-26 16:20:29 +0000179 # v20080204,:pserver:anonymous@dev.eclipse.org:/cvsroot/birt,,source/org.eclipse.birt.report.designer.core
droy87d1b182008-03-04 21:55:24 +0000180 # v200802262150,:pserver:anonymous@dev.eclipse.org:/cvsroot/modeling,,org.eclipse.emf/org.eclipse.emf.query/plugins/org.eclipse.emf.query
atoulmea8c21012009-01-27 14:06:40 +0000181 # SVN,tags/1.0M5,http://dev.eclipse.org/svnroot/dsdp/org.eclipse.mtj,,features/org.eclipse.mtj
droyf3b43282008-05-09 18:45:12 +0000182 # svn://dev.eclipse.org/svnroot/stp/org.eclipse.stp.bpmn/trunk/
droy87d1b182008-03-04 21:55:24 +0000183
droyd9a61af2008-02-26 16:20:29 +0000184 $aTheseElements = array();
droy3bb0c962008-01-17 20:45:01 +0000185
186 $aLocation = split(",", $in_string);
187 foreach($aLocation as $location_part) {
188 # TAG
droyd9a61af2008-02-26 16:20:29 +0000189 if(preg_match("/^[0-9a-zA-Z_]+$/", $location_part) && !isset($aTheseElements['cvsroot'])) {
190 $aTheseElements['tag'] = $location_part;
droy3bb0c962008-01-17 20:45:01 +0000191 }
192 # CVSROOT
193 if(preg_match("/^:.*:.*@.*:\//", $location_part)) {
droyd9a61af2008-02-26 16:20:29 +0000194 $aTheseElements['cvsroot'] = $location_part;
droy3bb0c962008-01-17 20:45:01 +0000195 }
droyf3b43282008-05-09 18:45:12 +0000196 # SVNROOT
atoulmea8c21012009-01-27 14:06:40 +0000197 # SVN,<tagPath>[:revision],<svnRepositoryURL>,<preTagPath>,<postTagPath>
198 # maps to: svn://<svnRepositoryURL>/<preTagPath>/<tagPath>/<postTagPath>
droyf3b43282008-05-09 18:45:12 +0000199 if(preg_match("/^(http|svn):\/\//", $location_part)) {
200 $location_part = str_replace("http", "svn", $location_part);
atoulmea8c21012009-01-27 14:06:40 +0000201 if ($aLocation[3] == ' ' || $aLocation[3] == '') {
202 $aTheseElements['svnroot'] = $location_part . "/" . $aLocation[1] . "/" . $aLocation[4];
203 } else {
204 $aTheseElements['svnroot'] = $location_part . "/" . $aLocation[3] . "/" . $aLocation[1] . "/" . $aLocation[4];
205 }
droyf3b43282008-05-09 18:45:12 +0000206 }
droy3bb0c962008-01-17 20:45:01 +0000207 }
208
droy87d1b182008-03-04 21:55:24 +0000209 $aTheseElements['plugin'] = substr($in_string, strrpos($in_string, ",") + 1);
210
droyd9a61af2008-02-26 16:20:29 +0000211 return $aTheseElements;
droy3bb0c962008-01-17 20:45:01 +0000212}
213
droyb9c2cb12008-10-08 13:58:14 +0000214?>