blob: 46b87edf48ae7fb4ff5856d15a2780c765bbdddd [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);
atoulmedfab0852009-02-16 11:47:31 +000068 $file_contents = ereg_replace("\r\n?", "\n", $file_contents);
droy3bb0c962008-01-17 20:45:01 +000069 $aLines = split("\n", $file_contents);
70
71
72 foreach ($aLines as $line) {
73 $line = trim($line);
74
droy87d1b182008-03-04 21:55:24 +000075 # 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 +000076 if(preg_match("/^(plugin|fragment)/", $line)) {
droyb9c2cb12008-10-08 13:58:14 +000077 echo $html_spacer . "Processing line: " . $line . "\n";
droy3bb0c962008-01-17 20:45:01 +000078 $aParts = split("=", $line);
droy87d1b182008-03-04 21:55:24 +000079 $aElements = split("@", $aParts[0]);
droyb9c2cb12008-10-08 13:58:14 +000080 $plugin_id = $aElements[1];
droy3bb0c962008-01-17 20:45:01 +000081 if($aElements[0] == "plugin") {
droyb9c2cb12008-10-08 13:58:14 +000082 echo $html_spacer . $html_spacer . "Processing plugin: " . $aParts[1] . "\n";
droy3bb0c962008-01-17 20:45:01 +000083 $aStuff = parseLocation($aParts[1]);
84
85 $tagstring = "";
86 if(isset($aStuff['tag'])) {
87 $tagstring = "-r " . $aStuff['tag'] . " ";
88 }
droy87d1b182008-03-04 21:55:24 +000089 if(isset($aStuff['plugin'])) {
90 if($aStuff['plugin'] != "") {
91 $aElements[1] = $aStuff['plugin'];
92 }
93 }
droyd9a61af2008-02-26 16:20:29 +000094
droyf3b43282008-05-09 18:45:12 +000095 $command = "";
96 # determine CVS or SVN
97 if(isset($aStuff['cvsroot'])) {
98 $command = "cvs -d " . $aStuff['cvsroot'] . " co " . $tagstring . $aElements[1];
99 }
100 elseif( isset($aStuff['svnroot'])) {
101 $command = "/usr/local/bin/svn co " . $aStuff['svnroot'] . " --config-dir /tmp";
102 }
droy87d1b182008-03-04 21:55:24 +0000103 echo $html_spacer . $html_spacer ."--> " . $command . "\n";
droyf3b43282008-05-09 18:45:12 +0000104
105 $out = "";
106 if($command != "") {
107 $out = shell_exec($command);
108 }
droy3bb0c962008-01-17 20:45:01 +0000109
110 # process the output lines for .properties
111 $aOutLines = split("\n", $out);
112 foreach ($aOutLines as $out_line) {
113 $out_line = trim($out_line);
droyf3b43282008-05-09 18:45:12 +0000114 # remove SVN's multiple spaces
115 $out_line = preg_replace("/\s+/", " ", $out_line);
116
droy87d1b182008-03-04 21:55:24 +0000117 echo $html_spacer . $html_spacer . "CVS out line: " . $out_line . "\n";
droyf3b43282008-05-09 18:45:12 +0000118 # CVS:
droyec50f102008-02-01 19:33:10 +0000119 # U org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/dtd/util/AntDTDUtilMessages.properties
droyf3b43282008-05-09 18:45:12 +0000120 # SVN:
121 # 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 +0000122 if(preg_match("/\.properties$/", $out_line) && !preg_match("/build\.properties$/", $out_line)) {
droy3bb0c962008-01-17 20:45:01 +0000123 # this is a .properties file!
droyec50f102008-02-01 19:33:10 +0000124 $file_name = trim(substr($out_line, 2));
droy87d1b182008-03-04 21:55:24 +0000125 echo $html_spacer . $html_spacer . $html_spacer . "Processing .properties file: " . $file_name . "\n";
droy3bb0c962008-01-17 20:45:01 +0000126
atoulmebe3eae82008-12-05 16:38:20 +0000127 $file_id = File::getFileID($file_name, $myrow_maps['project_id'], $myrow_maps['version']);
atoulmee9ec6d82008-11-19 14:41:30 +0000128
129 if ($files[$file_id] != null) {
130 $File = $files[$file_id];
131 $File->isActive = 1;
132 unset($files[$file_id]);
133 } else {
134 $File = new File();
135 $File->project_id = $myrow_maps['project_id'];
136 $File->version = $myrow_maps['version'];
137 $File->name = $file_name;
138 $File->plugin_id = $plugin_id;
139 $File->isActive = 1;
140 }
droy3bb0c962008-01-17 20:45:01 +0000141 if(!$File->save()) {
droy87d1b182008-03-04 21:55:24 +0000142 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "***ERROR saving file: " . $file_name . "\n";
droy3bb0c962008-01-17 20:45:01 +0000143 }
144 else {
145 # Start importing the strings!
146 $fh = fopen($file_name, 'r');
147 $size = filesize($file_name);
148
149 $content = fread($fh, $size);
150 fclose($fh);
151
152 $strings = $File->parseProperties($content);
droy87d1b182008-03-04 21:55:24 +0000153 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "Strings processed: $strings\n\n";
droy3bb0c962008-01-17 20:45:01 +0000154 }
155
156 }
157 }
158 }
159 }
160 }
161}
atoulmee9ec6d82008-11-19 14:41:30 +0000162echo "Marking the remaining files as inactive\n";
163
164foreach ($files as $file) {
165 $file->isActive = 0;
166 if(!$file->save()) {
167 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "***ERROR saving file: " . $file->name . "\n";
168 }
169}
170
droy1df37fc2008-02-28 21:29:46 +0000171echo "Done.";
droy3bb0c962008-01-17 20:45:01 +0000172
droy58210512008-02-05 16:05:48 +0000173if($headless) {
174 $User = null;
175}
176
droy3bb0c962008-01-17 20:45:01 +0000177function parseLocation($in_string) {
178 # in_string looks something like this:
179 # v_832,:pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse,
droyd9a61af2008-02-26 16:20:29 +0000180 # v20080204,:pserver:anonymous@dev.eclipse.org:/cvsroot/birt,,source/org.eclipse.birt.report.designer.core
droy87d1b182008-03-04 21:55:24 +0000181 # 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 +0000182 # SVN,tags/1.0M5,http://dev.eclipse.org/svnroot/dsdp/org.eclipse.mtj,,features/org.eclipse.mtj
droyf3b43282008-05-09 18:45:12 +0000183 # svn://dev.eclipse.org/svnroot/stp/org.eclipse.stp.bpmn/trunk/
droy87d1b182008-03-04 21:55:24 +0000184
droyd9a61af2008-02-26 16:20:29 +0000185 $aTheseElements = array();
droy3bb0c962008-01-17 20:45:01 +0000186
187 $aLocation = split(",", $in_string);
188 foreach($aLocation as $location_part) {
189 # TAG
droyd9a61af2008-02-26 16:20:29 +0000190 if(preg_match("/^[0-9a-zA-Z_]+$/", $location_part) && !isset($aTheseElements['cvsroot'])) {
191 $aTheseElements['tag'] = $location_part;
droy3bb0c962008-01-17 20:45:01 +0000192 }
193 # CVSROOT
194 if(preg_match("/^:.*:.*@.*:\//", $location_part)) {
droyd9a61af2008-02-26 16:20:29 +0000195 $aTheseElements['cvsroot'] = $location_part;
droy3bb0c962008-01-17 20:45:01 +0000196 }
droyf3b43282008-05-09 18:45:12 +0000197 # SVNROOT
atoulmea8c21012009-01-27 14:06:40 +0000198 # SVN,<tagPath>[:revision],<svnRepositoryURL>,<preTagPath>,<postTagPath>
199 # maps to: svn://<svnRepositoryURL>/<preTagPath>/<tagPath>/<postTagPath>
droyf3b43282008-05-09 18:45:12 +0000200 if(preg_match("/^(http|svn):\/\//", $location_part)) {
201 $location_part = str_replace("http", "svn", $location_part);
atoulmea8c21012009-01-27 14:06:40 +0000202 if ($aLocation[3] == ' ' || $aLocation[3] == '') {
203 $aTheseElements['svnroot'] = $location_part . "/" . $aLocation[1] . "/" . $aLocation[4];
204 } else {
205 $aTheseElements['svnroot'] = $location_part . "/" . $aLocation[3] . "/" . $aLocation[1] . "/" . $aLocation[4];
206 }
droyf3b43282008-05-09 18:45:12 +0000207 }
droy3bb0c962008-01-17 20:45:01 +0000208 }
209
droy87d1b182008-03-04 21:55:24 +0000210 $aTheseElements['plugin'] = substr($in_string, strrpos($in_string, ",") + 1);
211
droyd9a61af2008-02-26 16:20:29 +0000212 return $aTheseElements;
droy3bb0c962008-01-17 20:45:01 +0000213}
214
droyb9c2cb12008-10-08 13:58:14 +0000215?>