FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
fo_integration.php
1 <?php
2 /*
3  Copyright (C) 2011 Hewlett-Packard Development Company, L.P.
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  version 2 as published by the Free Software Foundation.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
44 {
45  public $srcPath;
46  public $logPath;
47  protected $LOGFD;
48 
49  public function __construct($sourcePath, $logPath=NULL)
50  {
51  if(empty($sourcePath))
52  {
53  $this->srcPath = getcwd();
54  }
55  else
56  {
57  $this->srcPath = $sourcePath;
58  }
59  if(is_NULL($logPath))
60  {
61  $this->logPath = getcwd() . "/fo_integration.log";
62  echo "DB: logpath is:$this->logPath\n";
63  }
64  else
65  {
66  $this->logPath = $logPath;
67  echo "DB: logpath is:$this->logPath\n";
68  }
69 
70  $this->LOGFD = fopen($this->logPath, 'a+');
71  if($this->LOGFD === FALSE)
72  {
73  $error = "Error! cannot open $this->logPath" . " File: " . __FILE__ .
74  " on line: " . __LINE__;
75  throw new exception($error);
76  }
77 
78  } // __construct
79 
90  protected function log($message)
91  {
92  if(fwrite($this->LOGFD, $message) === FALSE)
93  {
94  // remove the warning? and have caller do it?
95  echo "WARNING! cannot write to log file, there may be no log messages\n";
96  return(FALSE);
97  }
98  return(TRUE);
99  } // log
100 
101 } //fo_integration
102 
103 
122 class Build extends FoIntegration
123 {
124 
134  function __construct($srcPath, $logPath=NULL)
135  {
136  parent::__construct($srcPath,$logPath);
137  if (!chdir($this->srcPath))
138  {
139  throw new exception("FATAL! can't cd to $this->srcPath\n");
140  }
141  $this->log("Executing Make Clean\n");
142  $mcLast = exec('make clean > make-clean.out 2>&1', $results, $rtn);
143  //print "results of the make clean are:$rtn, $mcLast\n";
144  $this->log("Executing Make all\n");
145  $makeLast = exec('make > make.out 2>&1', $results, $rtn);
146  //print "results of the make are:$rtn, $makeLast\n"; print_r($results) . "\n";
147  if ($rtn == 0)
148  {
149  //print "results of the make are:\n"; print_r($results) . "\n";
150  if (array_search('Error', $results))
151  {
152  //print "Found Error string in the Make output\n";
153  // TODO: write results out to: make.out ?? what ??
154  throw new exception("Errors in make, inspect make.out for details\n");
155  }
156  }
157  else
158  {
159  throw new exception("Errors in make, inspect make.out for details\n");
160  }
161  } // makeFossology
162 
163 } // build
164 ?>
make fossology, check for warnings and errors
log($message)
log a message in a file
base class for fossology integration.
__construct($srcPath, $logPath=NULL)
make fossology