[Cs-versionparse-commits] SF.net SVN: cs-versionparse:[9] trunk/0.1/cs_version.abstract.class.php
Status: Inactive
Brought to you by:
crazedsanity
|
From: <cra...@us...> - 2009-01-26 05:37:16
|
Revision: 9
http://cs-versionparse.svn.sourceforge.net/cs-versionparse/?rev=9&view=rev
Author: crazedsanity
Date: 2009-01-26 05:37:12 +0000 (Mon, 26 Jan 2009)
Log Message:
-----------
Better finding of VERSION and PROJECT, and tries to auto-set location of VERSION.
/cs_version.abstract.class.php:
* get_version():
-- calls new method, auto_set_version_file() to try to automatically
set the version file location.
-- use preg_match() to find the line with "VERSION: "
-- better exception thrown if version couldn't be found.
* get_project():
-- call auto_set_version_file() to find VERSION file location.
-- use preg_match() to find project name, instead of arbitrary lines.
* auto_set_version_file() [NEW]:
-- using debug_backtrace, it finds the first class that is NOT itself,
and uses that to set as the folder to look for "VERSION" in; if the
folder ends with "test" or "tests", that folder is removed.
Modified Paths:
--------------
trunk/0.1/cs_version.abstract.class.php
Modified: trunk/0.1/cs_version.abstract.class.php
===================================================================
--- trunk/0.1/cs_version.abstract.class.php 2009-01-25 23:19:53 UTC (rev 8)
+++ trunk/0.1/cs_version.abstract.class.php 2009-01-26 05:37:12 UTC (rev 9)
@@ -25,18 +25,15 @@
*/
final public function get_version($asArray=false) {
$retval = NULL;
+
+ $this->auto_set_version_file();
+
if(file_exists($this->versionFileLocation)) {
- $myData = file($this->versionFileLocation);
+ $myMatches = array();
+ $findIt = preg_match('/VERSION: (.+)/', file_get_contents($this->versionFileLocation), $matches);
- //set the logical line number that the version string is on, and
- // drop by one to get the corresponding array index.
- $lineOfVersion = 3;
- $arrayIndex = $lineOfVersion -1;
-
- $myVersionString = trim($myData[$arrayIndex]);
-
- if(preg_match('/^VERSION: /', $myVersionString)) {
- $fullVersionString = preg_replace('/^VERSION: /', '', $myVersionString);
+ if($findIt == 1 && count($matches) == 2) {
+ $fullVersionString = $matches[1];
$pieces = explode('.', $fullVersionString);
$retval = array(
'version_major' => $pieces[0],
@@ -77,7 +74,8 @@
}
}
else {
- throw new exception(__METHOD__ .": failed to retrieve version string");
+ throw new exception(__METHOD__ .": failed to retrieve version string in file " .
+ "(". $this->versionFileLocation .")");
}
}
else {
@@ -94,18 +92,13 @@
//=========================================================================
final public function get_project() {
$retval = NULL;
+ $this->auto_set_version_file();
if(file_exists($this->versionFileLocation)) {
- $myData = file($this->versionFileLocation);
+ $myMatches = array();
+ $findIt = preg_match('/PROJECT: (.+)/', file_get_contents($this->versionFileLocation), $matches);
- //set the logical line number that the version string is on, and
- // drop by one to get the corresponding array index.
- $lineOfProject = 4;
- $arrayIndex = $lineOfProject -1;
-
- $myProject = trim($myData[$arrayIndex]);
-
- if(preg_match('/^PROJECT: /', $myProject)) {
- $retval = preg_replace('/^PROJECT: /', '', $myProject);
+ if($findIt == 1 && count($matches) == 2 && strlen($matches[1])) {
+ $retval = $matches[1];
}
else {
throw new exception(__METHOD__ .": failed to retrieve project string");
@@ -133,5 +126,43 @@
//=========================================================================
+
+ //=========================================================================
+ protected function auto_set_version_file() {
+ if(!strlen($this->versionFileLocation)) {
+ $bt = debug_backtrace();
+ $gf = new cs_globalFunctions;
+ foreach($bt as $callNum=>$data) {
+ if(strlen($data['class'])) {
+ if($data['class'] != __CLASS__) {
+ $dir = dirname($data['file']);
+ if(preg_match('/tests$/', $dir)) {
+ $dir = preg_replace('/\/tests$/', '', $dir);
+ }
+ elseif(preg_match('/test$/', $dir)) {
+ $dir = preg_replace('/\/test$/', '', $dir);
+ }
+ $gf->debug_print(__METHOD__ .": going to use (". $dir .")");
+ cs_debug_backtrace(1);
+ break;
+ }
+ }
+ else {
+ throw new exception(__METHOD__ .": failed to locate the calling class in backtrace");
+ }
+ }
+
+ $gf = new cs_globalFunctions;
+ if(file_exists($dir .'/VERSION')) {
+ $this->set_version_file_location($dir .'/VERSION');
+ }
+ else {
+ throw new exception(__METHOD__ .": failed to automatically set version file");
+ }
+ }
+ }//end auto_set_version_file()
+ //=========================================================================
+
+
}
?>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|