blob: 07e6a829b499de385591cde6267e59e9e8470b8a [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.";
20 $User = new User();
21 $User->loadFromID(40623); // genie
22 $headless = 1;
23}
24
droy3bb0c962008-01-17 20:45:01 +000025
26require(BABEL_BASE_DIR . "classes/file/file.class.php");
droy87d1b182008-03-04 21:55:24 +000027$html_spacer = " ";
droy3bb0c962008-01-17 20:45:01 +000028
29global $App, $dbh;
30
31if(!is_dir("/tmp/tmp-babel")) {
32 mkdir("/tmp/tmp-babel") || die("Cannot create a working directory");
33}
34chdir("/tmp/tmp-babel") || die("Cannot use working directory");
35
36
37
38
droyabf32a12008-05-09 18:46:20 +000039$sql = "SELECT * FROM map_files WHERE is_active = 1 ORDER BY RAND()";
droy3bb0c962008-01-17 20:45:01 +000040$rs_maps = mysql_query($sql, $dbh);
droyd9a61af2008-02-26 16:20:29 +000041while($myrow_maps = mysql_fetch_assoc($rs_maps)) {
droy87d1b182008-03-04 21:55:24 +000042 echo "Processing map file: " . $myrow_maps['filename'] . " in location: " . $myrow_maps['location'] . "\n";
droy3bb0c962008-01-17 20:45:01 +000043
droyd9a61af2008-02-26 16:20:29 +000044 $tmpdir = "/tmp/tmp-babel/" . $myrow_maps['project_id'];
45 if(is_dir($tmpdir)) {
46 # zap the directory to make sure CVS versions don't overlap
47 exec("rm -rf " . $tmpdir);
droy3bb0c962008-01-17 20:45:01 +000048 }
droyd9a61af2008-02-26 16:20:29 +000049 mkdir($tmpdir) || die("Cannot create working directory $tmpdir !");
droy3bb0c962008-01-17 20:45:01 +000050 chdir($tmpdir) || die("Cannot write to $tmpdir !");
51
droyd9a61af2008-02-26 16:20:29 +000052 $h = fopen($myrow_maps['location'], "rb");
droy3bb0c962008-01-17 20:45:01 +000053 $file_contents = stream_get_contents($h);
54 fclose($h);
55 $aLines = split("\n", $file_contents);
56
57
58 foreach ($aLines as $line) {
59 $line = trim($line);
60
droy87d1b182008-03-04 21:55:24 +000061 # 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 +000062 if(preg_match("/^(plugin|fragment)/", $line)) {
droyb9c2cb12008-10-08 13:58:14 +000063 echo $html_spacer . "Processing line: " . $line . "\n";
droy3bb0c962008-01-17 20:45:01 +000064 $aParts = split("=", $line);
droy87d1b182008-03-04 21:55:24 +000065 $aElements = split("@", $aParts[0]);
droyb9c2cb12008-10-08 13:58:14 +000066 $plugin_id = $aElements[1];
droy3bb0c962008-01-17 20:45:01 +000067 if($aElements[0] == "plugin") {
droyb9c2cb12008-10-08 13:58:14 +000068 echo $html_spacer . $html_spacer . "Processing plugin: " . $aParts[1] . "\n";
droy3bb0c962008-01-17 20:45:01 +000069 $aStuff = parseLocation($aParts[1]);
70
71 $tagstring = "";
72 if(isset($aStuff['tag'])) {
73 $tagstring = "-r " . $aStuff['tag'] . " ";
74 }
droy87d1b182008-03-04 21:55:24 +000075 if(isset($aStuff['plugin'])) {
76 if($aStuff['plugin'] != "") {
77 $aElements[1] = $aStuff['plugin'];
78 }
79 }
droyd9a61af2008-02-26 16:20:29 +000080
droyf3b43282008-05-09 18:45:12 +000081 $command = "";
82 # determine CVS or SVN
83 if(isset($aStuff['cvsroot'])) {
84 $command = "cvs -d " . $aStuff['cvsroot'] . " co " . $tagstring . $aElements[1];
85 }
86 elseif( isset($aStuff['svnroot'])) {
87 $command = "/usr/local/bin/svn co " . $aStuff['svnroot'] . " --config-dir /tmp";
88 }
droy87d1b182008-03-04 21:55:24 +000089 echo $html_spacer . $html_spacer ."--> " . $command . "\n";
droyf3b43282008-05-09 18:45:12 +000090
91 $out = "";
92 if($command != "") {
93 $out = shell_exec($command);
94 }
droy3bb0c962008-01-17 20:45:01 +000095
96 # process the output lines for .properties
97 $aOutLines = split("\n", $out);
98 foreach ($aOutLines as $out_line) {
99 $out_line = trim($out_line);
droyf3b43282008-05-09 18:45:12 +0000100 # remove SVN's multiple spaces
101 $out_line = preg_replace("/\s+/", " ", $out_line);
102
droy87d1b182008-03-04 21:55:24 +0000103 echo $html_spacer . $html_spacer . "CVS out line: " . $out_line . "\n";
droyf3b43282008-05-09 18:45:12 +0000104 # CVS:
droyec50f102008-02-01 19:33:10 +0000105 # U org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/dtd/util/AntDTDUtilMessages.properties
droyf3b43282008-05-09 18:45:12 +0000106 # SVN:
107 # 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 +0000108 if(preg_match("/\.properties$/", $out_line) && !preg_match("/build\.properties$/", $out_line)) {
droy3bb0c962008-01-17 20:45:01 +0000109 # this is a .properties file!
droyec50f102008-02-01 19:33:10 +0000110 $file_name = trim(substr($out_line, 2));
droy87d1b182008-03-04 21:55:24 +0000111 echo $html_spacer . $html_spacer . $html_spacer . "Processing .properties file: " . $file_name . "\n";
droy3bb0c962008-01-17 20:45:01 +0000112
113 $File = new File();
droyd9a61af2008-02-26 16:20:29 +0000114 $File->project_id = $myrow_maps['project_id'];
115 $File->version = $myrow_maps['version'];
droy3bb0c962008-01-17 20:45:01 +0000116 $File->name = $file_name;
droyb9c2cb12008-10-08 13:58:14 +0000117 $File->plugin_id = $plugin_id;
droy3bb0c962008-01-17 20:45:01 +0000118 if(!$File->save()) {
droy87d1b182008-03-04 21:55:24 +0000119 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "***ERROR saving file: " . $file_name . "\n";
droy3bb0c962008-01-17 20:45:01 +0000120 }
121 else {
122 # Start importing the strings!
123 $fh = fopen($file_name, 'r');
124 $size = filesize($file_name);
125
126 $content = fread($fh, $size);
127 fclose($fh);
128
129 $strings = $File->parseProperties($content);
droy87d1b182008-03-04 21:55:24 +0000130 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "Strings processed: $strings\n\n";
droy3bb0c962008-01-17 20:45:01 +0000131 }
132
133 }
134 }
135 }
136 }
137 }
138}
droy1df37fc2008-02-28 21:29:46 +0000139echo "Done.";
droy3bb0c962008-01-17 20:45:01 +0000140
droy58210512008-02-05 16:05:48 +0000141if($headless) {
142 $User = null;
143}
144
droy3bb0c962008-01-17 20:45:01 +0000145function parseLocation($in_string) {
146 # in_string looks something like this:
147 # v_832,:pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse,
droyd9a61af2008-02-26 16:20:29 +0000148 # v20080204,:pserver:anonymous@dev.eclipse.org:/cvsroot/birt,,source/org.eclipse.birt.report.designer.core
droy87d1b182008-03-04 21:55:24 +0000149 # 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 +0000150 # SVN,trunk,http://dev.eclipse.org/svnroot/stp,,org.eclipse.stp.bpmn/trunk/org.eclipse.stp.bpmn
151 # svn://dev.eclipse.org/svnroot/stp/org.eclipse.stp.bpmn/trunk/
droy87d1b182008-03-04 21:55:24 +0000152
droyd9a61af2008-02-26 16:20:29 +0000153 $aTheseElements = array();
droy3bb0c962008-01-17 20:45:01 +0000154
155 $aLocation = split(",", $in_string);
156 foreach($aLocation as $location_part) {
157 # TAG
droyd9a61af2008-02-26 16:20:29 +0000158 if(preg_match("/^[0-9a-zA-Z_]+$/", $location_part) && !isset($aTheseElements['cvsroot'])) {
159 $aTheseElements['tag'] = $location_part;
droy3bb0c962008-01-17 20:45:01 +0000160 }
161 # CVSROOT
162 if(preg_match("/^:.*:.*@.*:\//", $location_part)) {
droyd9a61af2008-02-26 16:20:29 +0000163 $aTheseElements['cvsroot'] = $location_part;
droy3bb0c962008-01-17 20:45:01 +0000164 }
droyf3b43282008-05-09 18:45:12 +0000165 # SVNROOT
166 # SVN,trunk,http://dev.eclipse.org/svnroot/stp,,org.eclipse.stp.bpmn/trunk/org.eclipse.stp.bpmn
167 # maps to: svn://dev.eclipse.org/svnroot/stp/org.eclipse.stp.bpmn/trunk/
168 if(preg_match("/^(http|svn):\/\//", $location_part)) {
169 $location_part = str_replace("http", "svn", $location_part);
170 $aTheseElements['svnroot'] = $location_part . "/" . $aLocation[4];
171 }
droy3bb0c962008-01-17 20:45:01 +0000172 }
173
droy87d1b182008-03-04 21:55:24 +0000174 $aTheseElements['plugin'] = substr($in_string, strrpos($in_string, ",") + 1);
175
droyd9a61af2008-02-26 16:20:29 +0000176 return $aTheseElements;
droy3bb0c962008-01-17 20:45:01 +0000177}
178
droyb9c2cb12008-10-08 13:58:14 +0000179?>