blob: 8f921945c1370ab3ff2eb17b263ecdde23edf4a1 [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
droy3bb0c962008-01-17 20:45:01 +000012*******************************************************************************/
droy87d1b182008-03-04 21:55:24 +000013header("Content-type: text/plain");
droy3bb0c962008-01-17 20:45:01 +000014include("global.php");
15InitPage("");
16
droy58210512008-02-05 16:05:48 +000017$headless = 0;
18if(!isset($User)) {
19 echo "User not defined -- running headless.";
atoulme9118d612008-11-12 18:21:38 +000020 $User = getGenieUser();
droy58210512008-02-05 16:05:48 +000021 $headless = 1;
22}
23
droy3bb0c962008-01-17 20:45:01 +000024
25require(BABEL_BASE_DIR . "classes/file/file.class.php");
droy87d1b182008-03-04 21:55:24 +000026$html_spacer = " ";
droy3bb0c962008-01-17 20:45:01 +000027
28global $App, $dbh;
29
30if(!is_dir("/tmp/tmp-babel")) {
31 mkdir("/tmp/tmp-babel") || die("Cannot create a working directory");
32}
33chdir("/tmp/tmp-babel") || die("Cannot use working directory");
34
35
36
37
droyabf32a12008-05-09 18:46:20 +000038$sql = "SELECT * FROM map_files WHERE is_active = 1 ORDER BY RAND()";
droy3bb0c962008-01-17 20:45:01 +000039$rs_maps = mysql_query($sql, $dbh);
droyd9a61af2008-02-26 16:20:29 +000040while($myrow_maps = mysql_fetch_assoc($rs_maps)) {
droy87d1b182008-03-04 21:55:24 +000041 echo "Processing map file: " . $myrow_maps['filename'] . " in location: " . $myrow_maps['location'] . "\n";
droy3bb0c962008-01-17 20:45:01 +000042
droyd9a61af2008-02-26 16:20:29 +000043 $tmpdir = "/tmp/tmp-babel/" . $myrow_maps['project_id'];
44 if(is_dir($tmpdir)) {
45 # zap the directory to make sure CVS versions don't overlap
46 exec("rm -rf " . $tmpdir);
droy3bb0c962008-01-17 20:45:01 +000047 }
droyd9a61af2008-02-26 16:20:29 +000048 mkdir($tmpdir) || die("Cannot create working directory $tmpdir !");
droy3bb0c962008-01-17 20:45:01 +000049 chdir($tmpdir) || die("Cannot write to $tmpdir !");
50
droyd9a61af2008-02-26 16:20:29 +000051 $h = fopen($myrow_maps['location'], "rb");
droy3bb0c962008-01-17 20:45:01 +000052 $file_contents = stream_get_contents($h);
53 fclose($h);
54 $aLines = split("\n", $file_contents);
55
56
57 foreach ($aLines as $line) {
58 $line = trim($line);
59
droy87d1b182008-03-04 21:55:24 +000060 # 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 +000061 if(preg_match("/^(plugin|fragment)/", $line)) {
droyb9c2cb12008-10-08 13:58:14 +000062 echo $html_spacer . "Processing line: " . $line . "\n";
droy3bb0c962008-01-17 20:45:01 +000063 $aParts = split("=", $line);
droy87d1b182008-03-04 21:55:24 +000064 $aElements = split("@", $aParts[0]);
droyb9c2cb12008-10-08 13:58:14 +000065 $plugin_id = $aElements[1];
droy3bb0c962008-01-17 20:45:01 +000066 if($aElements[0] == "plugin") {
droyb9c2cb12008-10-08 13:58:14 +000067 echo $html_spacer . $html_spacer . "Processing plugin: " . $aParts[1] . "\n";
droy3bb0c962008-01-17 20:45:01 +000068 $aStuff = parseLocation($aParts[1]);
69
70 $tagstring = "";
71 if(isset($aStuff['tag'])) {
72 $tagstring = "-r " . $aStuff['tag'] . " ";
73 }
droy87d1b182008-03-04 21:55:24 +000074 if(isset($aStuff['plugin'])) {
75 if($aStuff['plugin'] != "") {
76 $aElements[1] = $aStuff['plugin'];
77 }
78 }
droyd9a61af2008-02-26 16:20:29 +000079
droyf3b43282008-05-09 18:45:12 +000080 $command = "";
81 # determine CVS or SVN
82 if(isset($aStuff['cvsroot'])) {
83 $command = "cvs -d " . $aStuff['cvsroot'] . " co " . $tagstring . $aElements[1];
84 }
85 elseif( isset($aStuff['svnroot'])) {
86 $command = "/usr/local/bin/svn co " . $aStuff['svnroot'] . " --config-dir /tmp";
87 }
droy87d1b182008-03-04 21:55:24 +000088 echo $html_spacer . $html_spacer ."--> " . $command . "\n";
droyf3b43282008-05-09 18:45:12 +000089
90 $out = "";
91 if($command != "") {
92 $out = shell_exec($command);
93 }
droy3bb0c962008-01-17 20:45:01 +000094
95 # process the output lines for .properties
96 $aOutLines = split("\n", $out);
97 foreach ($aOutLines as $out_line) {
98 $out_line = trim($out_line);
droyf3b43282008-05-09 18:45:12 +000099 # remove SVN's multiple spaces
100 $out_line = preg_replace("/\s+/", " ", $out_line);
101
droy87d1b182008-03-04 21:55:24 +0000102 echo $html_spacer . $html_spacer . "CVS out line: " . $out_line . "\n";
droyf3b43282008-05-09 18:45:12 +0000103 # CVS:
droyec50f102008-02-01 19:33:10 +0000104 # U org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/dtd/util/AntDTDUtilMessages.properties
droyf3b43282008-05-09 18:45:12 +0000105 # SVN:
106 # 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 +0000107 if(preg_match("/\.properties$/", $out_line) && !preg_match("/build\.properties$/", $out_line)) {
droy3bb0c962008-01-17 20:45:01 +0000108 # this is a .properties file!
droyec50f102008-02-01 19:33:10 +0000109 $file_name = trim(substr($out_line, 2));
droy87d1b182008-03-04 21:55:24 +0000110 echo $html_spacer . $html_spacer . $html_spacer . "Processing .properties file: " . $file_name . "\n";
droy3bb0c962008-01-17 20:45:01 +0000111
112 $File = new File();
droyd9a61af2008-02-26 16:20:29 +0000113 $File->project_id = $myrow_maps['project_id'];
114 $File->version = $myrow_maps['version'];
droy3bb0c962008-01-17 20:45:01 +0000115 $File->name = $file_name;
droyb9c2cb12008-10-08 13:58:14 +0000116 $File->plugin_id = $plugin_id;
droy3bb0c962008-01-17 20:45:01 +0000117 if(!$File->save()) {
droy87d1b182008-03-04 21:55:24 +0000118 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "***ERROR saving file: " . $file_name . "\n";
droy3bb0c962008-01-17 20:45:01 +0000119 }
120 else {
121 # Start importing the strings!
122 $fh = fopen($file_name, 'r');
123 $size = filesize($file_name);
124
125 $content = fread($fh, $size);
126 fclose($fh);
127
128 $strings = $File->parseProperties($content);
droy87d1b182008-03-04 21:55:24 +0000129 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "Strings processed: $strings\n\n";
droy3bb0c962008-01-17 20:45:01 +0000130 }
131
132 }
133 }
134 }
135 }
136 }
137}
droy1df37fc2008-02-28 21:29:46 +0000138echo "Done.";
droy3bb0c962008-01-17 20:45:01 +0000139
droy58210512008-02-05 16:05:48 +0000140if($headless) {
141 $User = null;
142}
143
droy3bb0c962008-01-17 20:45:01 +0000144function parseLocation($in_string) {
145 # in_string looks something like this:
146 # v_832,:pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse,
droyd9a61af2008-02-26 16:20:29 +0000147 # v20080204,:pserver:anonymous@dev.eclipse.org:/cvsroot/birt,,source/org.eclipse.birt.report.designer.core
droy87d1b182008-03-04 21:55:24 +0000148 # v200802262150,:pserver:anonymous@dev.eclipse.org:/cvsroot/modeling,,org.eclipse.emf/org.eclipse.emf.query/plugins/org.eclipse.emf.query
droyf3b43282008-05-09 18:45:12 +0000149 # SVN,trunk,http://dev.eclipse.org/svnroot/stp,,org.eclipse.stp.bpmn/trunk/org.eclipse.stp.bpmn
150 # svn://dev.eclipse.org/svnroot/stp/org.eclipse.stp.bpmn/trunk/
droy87d1b182008-03-04 21:55:24 +0000151
droyd9a61af2008-02-26 16:20:29 +0000152 $aTheseElements = array();
droy3bb0c962008-01-17 20:45:01 +0000153
154 $aLocation = split(",", $in_string);
155 foreach($aLocation as $location_part) {
156 # TAG
droyd9a61af2008-02-26 16:20:29 +0000157 if(preg_match("/^[0-9a-zA-Z_]+$/", $location_part) && !isset($aTheseElements['cvsroot'])) {
158 $aTheseElements['tag'] = $location_part;
droy3bb0c962008-01-17 20:45:01 +0000159 }
160 # CVSROOT
161 if(preg_match("/^:.*:.*@.*:\//", $location_part)) {
droyd9a61af2008-02-26 16:20:29 +0000162 $aTheseElements['cvsroot'] = $location_part;
droy3bb0c962008-01-17 20:45:01 +0000163 }
droyf3b43282008-05-09 18:45:12 +0000164 # SVNROOT
165 # SVN,trunk,http://dev.eclipse.org/svnroot/stp,,org.eclipse.stp.bpmn/trunk/org.eclipse.stp.bpmn
166 # maps to: svn://dev.eclipse.org/svnroot/stp/org.eclipse.stp.bpmn/trunk/
167 if(preg_match("/^(http|svn):\/\//", $location_part)) {
168 $location_part = str_replace("http", "svn", $location_part);
169 $aTheseElements['svnroot'] = $location_part . "/" . $aLocation[4];
170 }
droy3bb0c962008-01-17 20:45:01 +0000171 }
172
droy87d1b182008-03-04 21:55:24 +0000173 $aTheseElements['plugin'] = substr($in_string, strrpos($in_string, ",") + 1);
174
droyd9a61af2008-02-26 16:20:29 +0000175 return $aTheseElements;
droy3bb0c962008-01-17 20:45:01 +0000176}
177
droyb9c2cb12008-10-08 13:58:14 +0000178?>