blob: 68bc56e5ed1e323a6189cbca25cc63384b33ef84 [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
11*******************************************************************************/
12include("global.php");
13InitPage("");
14
droy58210512008-02-05 16:05:48 +000015$headless = 0;
16if(!isset($User)) {
17 echo "User not defined -- running headless.";
18 $User = new User();
19 $User->loadFromID(40623); // genie
20 $headless = 1;
21}
22
droy3bb0c962008-01-17 20:45:01 +000023
24require(BABEL_BASE_DIR . "classes/file/file.class.php");
25$html_spacer = "&#160;&#160;&#160;&#160;";
26
27global $App, $dbh;
28
29if(!is_dir("/tmp/tmp-babel")) {
30 mkdir("/tmp/tmp-babel") || die("Cannot create a working directory");
31}
32chdir("/tmp/tmp-babel") || die("Cannot use working directory");
33
34
35
36
droyd9a61af2008-02-26 16:20:29 +000037$sql = "SELECT * FROM map_files WHERE is_active = 1 ORDER BY version";
droy3bb0c962008-01-17 20:45:01 +000038$rs_maps = mysql_query($sql, $dbh);
droyd9a61af2008-02-26 16:20:29 +000039while($myrow_maps = mysql_fetch_assoc($rs_maps)) {
40 echo "Processing map file: " . $myrow_maps['filename'] . " in location: " . $myrow_maps['location'] . "<br />";
droy3bb0c962008-01-17 20:45:01 +000041
droyd9a61af2008-02-26 16:20:29 +000042 $tmpdir = "/tmp/tmp-babel/" . $myrow_maps['project_id'];
43 if(is_dir($tmpdir)) {
44 # zap the directory to make sure CVS versions don't overlap
45 exec("rm -rf " . $tmpdir);
droy3bb0c962008-01-17 20:45:01 +000046 }
droyd9a61af2008-02-26 16:20:29 +000047 mkdir($tmpdir) || die("Cannot create working directory $tmpdir !");
droy3bb0c962008-01-17 20:45:01 +000048 chdir($tmpdir) || die("Cannot write to $tmpdir !");
49
droyd9a61af2008-02-26 16:20:29 +000050 $h = fopen($myrow_maps['location'], "rb");
droy3bb0c962008-01-17 20:45:01 +000051 $file_contents = stream_get_contents($h);
52 fclose($h);
53 $aLines = split("\n", $file_contents);
54
55
56 foreach ($aLines as $line) {
57 $line = trim($line);
58
59 if(preg_match("/^(plugin|fragment)/", $line)) {
60 echo $html_spacer . "Processling line: " . $line . "<br />";
61 $aParts = split("=", $line);
62 $aElements = split("@", $aParts[0]);
63 if($aElements[0] == "plugin") {
64 echo $html_spacer . $html_spacer . "Processling plugin: " . $aParts[1] . "<br />";
65 $aStuff = parseLocation($aParts[1]);
66
67 $tagstring = "";
68 if(isset($aStuff['tag'])) {
69 $tagstring = "-r " . $aStuff['tag'] . " ";
70 }
71
droyd9a61af2008-02-26 16:20:29 +000072 echo "Elements 1: " . $aElements[1] . "<br />";
73
droy3bb0c962008-01-17 20:45:01 +000074 $command = "cvs -d " . $aStuff['cvsroot'] . " co " . $tagstring . $aElements[1];
75 echo $html_spacer . $html_spacer ."<font color=blue>" . $command . "</font><br />";
76 $out = shell_exec($command);
77
78 # process the output lines for .properties
79 $aOutLines = split("\n", $out);
80 foreach ($aOutLines as $out_line) {
81 $out_line = trim($out_line);
droyec50f102008-02-01 19:33:10 +000082 echo $html_spacer . $html_spacer . "CVS out line: " . $out_line . "<br />";
83 # U org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/dtd/util/AntDTDUtilMessages.properties
droye19e49b2008-01-31 14:05:50 +000084 if(preg_match("/\.properties$/", $out_line) && !preg_match("/build\.properties$/", $out_line)) {
droy3bb0c962008-01-17 20:45:01 +000085 # this is a .properties file!
droyec50f102008-02-01 19:33:10 +000086 $file_name = trim(substr($out_line, 2));
droy3bb0c962008-01-17 20:45:01 +000087 echo $html_spacer . $html_spacer . $html_spacer . "<font color=green>Processing .properties file: " . $file_name . "</font><br />";
88
89 $File = new File();
droyd9a61af2008-02-26 16:20:29 +000090 $File->project_id = $myrow_maps['project_id'];
91 $File->version = $myrow_maps['version'];
droy3bb0c962008-01-17 20:45:01 +000092 $File->name = $file_name;
93 if(!$File->save()) {
94 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "<font color=red>Error saving file: " . $file_name . "</font><br />";
95 }
96 else {
97 # Start importing the strings!
98 $fh = fopen($file_name, 'r');
99 $size = filesize($file_name);
100
101 $content = fread($fh, $size);
102 fclose($fh);
103
104 $strings = $File->parseProperties($content);
droyec50f102008-02-01 19:33:10 +0000105 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "Strings processed: $strings<br /><br />";
droy3bb0c962008-01-17 20:45:01 +0000106 }
107
108 }
109 }
110 }
111 }
112 }
113}
114
droy58210512008-02-05 16:05:48 +0000115if($headless) {
116 $User = null;
117}
118
droy3bb0c962008-01-17 20:45:01 +0000119function parseLocation($in_string) {
120 # in_string looks something like this:
121 # v_832,:pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse,
droyd9a61af2008-02-26 16:20:29 +0000122 # v20080204,:pserver:anonymous@dev.eclipse.org:/cvsroot/birt,,source/org.eclipse.birt.report.designer.core
123 $aTheseElements = array();
droy3bb0c962008-01-17 20:45:01 +0000124
125 $aLocation = split(",", $in_string);
126 foreach($aLocation as $location_part) {
127 # TAG
droyd9a61af2008-02-26 16:20:29 +0000128 if(preg_match("/^[0-9a-zA-Z_]+$/", $location_part) && !isset($aTheseElements['cvsroot'])) {
129 $aTheseElements['tag'] = $location_part;
droy3bb0c962008-01-17 20:45:01 +0000130 }
131 # CVSROOT
132 if(preg_match("/^:.*:.*@.*:\//", $location_part)) {
droyd9a61af2008-02-26 16:20:29 +0000133 $aTheseElements['cvsroot'] = $location_part;
droy3bb0c962008-01-17 20:45:01 +0000134 }
135 }
136
droyd9a61af2008-02-26 16:20:29 +0000137 return $aTheseElements;
droy3bb0c962008-01-17 20:45:01 +0000138}
139
140?>