blob: 0e1e0fec1035d4d50796cb1a32ae9978a714adc5 [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
15
16require(BABEL_BASE_DIR . "classes/file/file.class.php");
17$html_spacer = "&#160;&#160;&#160;&#160;";
18
19global $App, $dbh;
20
21if(!is_dir("/tmp/tmp-babel")) {
22 mkdir("/tmp/tmp-babel") || die("Cannot create a working directory");
23}
24chdir("/tmp/tmp-babel") || die("Cannot use working directory");
25
26
27
28
29$sql = "SELECT * FROM map_files WHERE is_active = 1";
30$rs_maps = mysql_query($sql, $dbh);
31while($myrow = mysql_fetch_assoc($rs_maps)) {
32 echo "Processing map file: " . $myrow['filename'] . " in location: " . $myrow['location'] . "<br />";
33
34 $tmpdir = "/tmp/tmp-babel/" . $myrow['project_id'];
35 if(!is_dir($tmpdir)) {
36 mkdir($tmpdir) || die("Cannot create working directory $tmpdir !");
37 }
38 chdir($tmpdir) || die("Cannot write to $tmpdir !");
39
40 $h = fopen($myrow['location'], "rb");
41 $file_contents = stream_get_contents($h);
42 fclose($h);
43 $aLines = split("\n", $file_contents);
44
45
46 foreach ($aLines as $line) {
47 $line = trim($line);
48
49 if(preg_match("/^(plugin|fragment)/", $line)) {
50 echo $html_spacer . "Processling line: " . $line . "<br />";
51 $aParts = split("=", $line);
52 $aElements = split("@", $aParts[0]);
53 if($aElements[0] == "plugin") {
54 echo $html_spacer . $html_spacer . "Processling plugin: " . $aParts[1] . "<br />";
55 $aStuff = parseLocation($aParts[1]);
56
57 $tagstring = "";
58 if(isset($aStuff['tag'])) {
59 $tagstring = "-r " . $aStuff['tag'] . " ";
60 }
61
62 $command = "cvs -d " . $aStuff['cvsroot'] . " co " . $tagstring . $aElements[1];
63 echo $html_spacer . $html_spacer ."<font color=blue>" . $command . "</font><br />";
64 $out = shell_exec($command);
65
66 # process the output lines for .properties
67 $aOutLines = split("\n", $out);
68 foreach ($aOutLines as $out_line) {
69 $out_line = trim($out_line);
droye19e49b2008-01-31 14:05:50 +000070 if(preg_match("/\.properties$/", $out_line) && !preg_match("/build\.properties$/", $out_line)) {
droy3bb0c962008-01-17 20:45:01 +000071 # this is a .properties file!
72 $parts = split(" ", $out_line);
73 $file_name = $parts[1];
74 echo $html_spacer . $html_spacer . $html_spacer . "<font color=green>Processing .properties file: " . $file_name . "</font><br />";
75
76 $File = new File();
77 $File->project_id = $myrow['project_id'];
78 $File->version = $myrow['version'];
79 $File->name = $file_name;
80 if(!$File->save()) {
81 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "<font color=red>Error saving file: " . $file_name . "</font><br />";
82 }
83 else {
84 # Start importing the strings!
85 $fh = fopen($file_name, 'r');
86 $size = filesize($file_name);
87
88 $content = fread($fh, $size);
89 fclose($fh);
90
91 $strings = $File->parseProperties($content);
92 }
93
94 }
95 }
96 }
97 }
98 }
99}
100
101function parseLocation($in_string) {
102 # in_string looks something like this:
103 # v_832,:pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse,
104 $aElements = array();
105
106 $aLocation = split(",", $in_string);
107 foreach($aLocation as $location_part) {
108 # TAG
109 if(preg_match("/^[0-9a-zA-Z_]+$/", $location_part) && !isset($aElements['cvsroot'])) {
110 $aElements['tag'] = $location_part;
111 }
112 # CVSROOT
113 if(preg_match("/^:.*:.*@.*:\//", $location_part)) {
114 $aElements['cvsroot'] = $location_part;
115 }
116 }
117
118 return $aElements;
119}
120
121?>