aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorgy Redkozubov <georgy.redkozubov@linaro.org>2012-06-11 14:44:16 +0400
committerGeorgy Redkozubov <georgy.redkozubov@linaro.org>2012-06-11 14:44:16 +0400
commit102ae4d0454935e1f87d9fc2e3c7d2ebdbc87aba (patch)
treed427c6af0ee7fefb0c96d94d1fb620015034983d
parent26a1a9e092db5f7638a2d23b0d7173873d8fce58 (diff)
Refactored 'getX' methods into single 'get' method. Updated code to use new approach.
-rw-r--r--android/build-info/BUILD-INFO.txt8
-rw-r--r--licenses/BuildInfo.php91
-rw-r--r--licenses/license.php8
-rw-r--r--tests/BuildInfoTest.php95
4 files changed, 37 insertions, 165 deletions
diff --git a/android/build-info/BUILD-INFO.txt b/android/build-info/BUILD-INFO.txt
index d5c2ad7..b55aa30 100644
--- a/android/build-info/BUILD-INFO.txt
+++ b/android/build-info/BUILD-INFO.txt
@@ -5,7 +5,7 @@ Build-Name: landing-snowball
Theme: ste
License-Type: protected
License-Text: <p>IMPORTANT — PLEASE READ THE FOLLOWING AGREEMENT CAREFULLY.</p>
-<p>
+ <p>
THIS IS A LEGALLY BINDING AGREEMENT BETWEEN YOU, an individual or a
legal entity, (“LICENSEE”) AND SAMSUNG ELECTRONICS CO.,
LTD. (“SAMSUNG”). BY CLICKING THE "ACCEPT" BUTTON, OR BY DOWNLOADING OR
@@ -14,14 +14,14 @@ License-Text: <p>IMPORTANT — PLEASE READ THE FOLLOWING AGREEMENT CAREFULLY.</p
AGREEMENT OR ARE NOT AUTHORISED TO ACCEPT AND AGREE TO THE TERMS OF THE
AGREEMENT ON BEHALF OF YOUR LEGAL ENTITY, DO NOT DOWNLOAD, INSTALL OR
OTHERWISE USE THE SOFTWARE.
-</p>
+ </p>
Files-Pattern: *origen*
Build-Name: landing-origen
Theme: samsung
License-Type: protected
License-Text: <p>IMPORTANT — PLEASE READ THE FOLLOWING AGREEMENT CAREFULLY.</p>
-<p>
+ <p>
THIS IS A LEGALLY BINDING AGREEMENT BETWEEN YOU, an individual or a
legal entity, (“LICENSEE”) AND SAMSUNG ELECTRONICS CO.,
LTD. (“SAMSUNG”). BY CLICKING THE "ACCEPT" BUTTON, OR BY DOWNLOADING OR
@@ -30,7 +30,7 @@ License-Text: <p>IMPORTANT — PLEASE READ THE FOLLOWING AGREEMENT CAREFULLY.</p
AGREEMENT OR ARE NOT AUTHORISED TO ACCEPT AND AGREE TO THE TERMS OF THE
AGREEMENT ON BEHALF OF YOUR LEGAL ENTITY, DO NOT DOWNLOAD, INSTALL OR
OTHERWISE USE THE SOFTWARE.
-</p>
+ </p>
Files-Pattern: *panda*
Build-Name: landing-panda
diff --git a/licenses/BuildInfo.php b/licenses/BuildInfo.php
index 5672ae3..3cf93bb 100644
--- a/licenses/BuildInfo.php
+++ b/licenses/BuildInfo.php
@@ -2,29 +2,36 @@
class BuildInfo
{
- private $text_array = array();
- private $fields_defined = array("Format-Version", "Files-Pattern",
- "Build-Name", "Theme", "License-Type", "OpenID-Launchpad-Teams",
- "Collect-User-Data", "License-Text");
- private $multiline_vars = array("License-Text");
- private $search_path = '';
- private $fname = '';
+ private $build_info_array;
+ private $fields_defined;
+ private $multiline_vars;
+ private $search_path;
+ private $fname;
+ private $file_info_array;
public function __construct($fn)
{
+ $this->build_info_array = array();
+ $this->file_info_array = array();
+ $this->fields_defined = array("Format-Version", "Files-Pattern",
+ "Build-Name", "Theme", "License-Type", "OpenID-Launchpad-Teams",
+ "Collect-User-Data", "License-Text");
+ $this->multiline_vars = array("License-Text");
$this->search_path = dirname($fn);
- $this->fname = $fn;
+ $this->fname = basename($fn);
+ $this->build_info_file = $this->search_path."/BUILD-INFO.txt";
$data = $this->readFile();
if (is_array($data)) {
- $this->text_array = $this->parseData($data);
+ $this->build_info_array = $this->parseData($data);
+ $this->file_info_array = $this->getInfoForFile($this->fname);
}
}
public function readFile()
{
$data = array();
- if (is_dir($this->fname) or !is_file($this->fname) or filesize($this->fname) == 0) return false;
- $file = fopen($this->fname, "r") or exit("Unable to open file $this->fname!");
+ if (is_dir($this->build_info_file) or !is_file($this->build_info_file) or filesize($this->build_info_file) == 0) return false;
+ $file = fopen($this->build_info_file, "r") or exit("Unable to open file $this->build_info_file!");
while(!feof($file)) {
$line = fgets($file);
if (trim($line) == "")
@@ -39,75 +46,29 @@ class BuildInfo
/**
* Get array of fields for corresponding file
*/
- foreach (array_keys($this->text_array) as $key)
+ foreach (array_keys($this->build_info_array) as $key)
if ($key != 'Format-Version') {
$files = glob($this->search_path."/".$key);
foreach ($files as $file)
if ($file == $this->search_path."/".$fname)
- return $this->text_array[$key];
+ return $this->build_info_array[$key];
}
return array();
}
public function getFormatVersion()
{
- if (array_key_exists('Format-Version', $this->text_array))
- return $this->text_array["Format-Version"];
+ if (array_key_exists('Format-Version', $this->build_info_array))
+ return $this->build_info_array["Format-Version"];
else
return false;
}
- // Get value of specified field for correspondong file
- public function getBuildName($fname)
+ // Get value of specified field for corresponding file
+ public function get($field)
{
- $info = $this->getInfoForFile($fname);
- if (array_key_exists('Build-Name', $info))
- return $info["Build-Name"];
- else
- return false;
- }
-
- public function getTheme($fname)
- {
- $info = $this->getInfoForFile($fname);
- if (array_key_exists('Theme', $info))
- return $info["Theme"];
- else
- return false;
- }
-
- public function getLicenseType($fname)
- {
- $info = $this->getInfoForFile($fname);
- if (array_key_exists('License-Type', $info))
- return $info["License-Type"];
- else
- return false;
- }
-
- public function getLaunchpadTeams($fname)
- {
- $info = $this->getInfoForFile($fname);
- if (array_key_exists('OpenID-Launchpad-Teams', $info))
- return $info["OpenID-Launchpad-Teams"];
- else
- return false;
- }
-
- public function getCollectUserData($fname)
- {
- $info = $this->getInfoForFile($fname);
- if (array_key_exists('Collect-User-Data', $info))
- return $info["Collect-User-Data"];
- else
- return false;
- }
-
- public function getLicenseText($fname)
- {
- $info = $this->getInfoForFile($fname);
- if (array_key_exists('License-Text', $info))
- return $info["License-Text"];
+ if (array_key_exists($field, $this->file_info_array))
+ return $this->file_info_array[$field];
else
return false;
}
diff --git a/licenses/license.php b/licenses/license.php
index 8cb5202..6f5cd50 100644
--- a/licenses/license.php
+++ b/licenses/license.php
@@ -30,10 +30,10 @@ if (file_exists($fn) and LicenseHelper::checkFile($fn)) { // Requested download
if (file_exists($search_dir."/BUILD-INFO.txt")) {
$bi_found = 1;
- $bi = new BuildInfo($search_dir."/BUILD-INFO.txt");
- $theme = $bi->getTheme($name_only[0]);
- $lic_type = $bi->getLicenseType($name_only[0]);
- $lic_text = $bi->getLicenseText($name_only[0]);
+ $bi = new BuildInfo($search_dir."/".$name_only[0]);
+ $theme = $bi->get("Theme");
+ $lic_type = $bi->get("License-Type");
+ $lic_text = $bi->get("License-Text");
} else {
$flist = LicenseHelper::getFilesList($search_dir);
if (!empty($name_only)) {
diff --git a/tests/BuildInfoTest.php b/tests/BuildInfoTest.php
index 93cb130..14f9dc8 100644
--- a/tests/BuildInfoTest.php
+++ b/tests/BuildInfoTest.php
@@ -9,8 +9,6 @@ class BuildInfoTest extends PHPUnit_Framework_TestCase
private $good_bi;
private $empty_bi;
private $fname;
- private $lic_text_test =
- '<p>IMPORTANT — PLEASE READ THE FOLLOWING AGREEMENT CAREFULLY.</p>';
public function setUp()
{
@@ -228,106 +226,19 @@ class BuildInfoTest extends PHPUnit_Framework_TestCase
public function test_getBuildName_empty()
{
- $this->assertFalse($this->empty_bi->getBuildName($this->fname));
+ $this->assertFalse($this->empty_bi->get("Build-Name"));
}
public function test_getBuildName_type()
{
$this->assertInternalType(
- 'string', $this->good_bi->getBuildName($this->fname));
+ 'string', $this->good_bi->get("Build-Name"));
}
public function test_getBuildName()
{
$this->assertEquals(
- 'landing-snowball', $this->good_bi->getBuildName($this->fname));
- }
-
- public function test_getTheme_empty()
- {
- $this->assertFalse($this->empty_bi->getTheme($this->fname));
- }
-
- public function test_getTheme_type()
- {
- $this->assertInternalType(
- 'string', $this->good_bi->getTheme($this->fname));
- }
-
- public function test_getTheme()
- {
- $this->assertEquals(
- 'stericsson', $this->good_bi->getTheme($this->fname));
- }
-
- public function test_getLicenseType_empty()
- {
- $this->assertFalse($this->empty_bi->getLicenseType($this->fname));
- }
-
- public function test_getLicenseType_type()
- {
- $this->assertInternalType(
- 'string', $this->good_bi->getLicenseType($this->fname));
- }
-
- public function test_getLicenseType()
- {
- $this->assertEquals(
- 'open', $this->good_bi->getLicenseType($this->fname));
- }
-
- public function test_getCollectUserData_empty()
- {
- $this->assertFalse($this->empty_bi->getCollectUserData($this->fname));
- }
-
- public function test_getCollectUserData_type()
- {
- $this->assertInternalType(
- 'string', $this->good_bi->getCollectUserData($this->fname));
- }
-
- public function test_getCollectUserData()
- {
- $this->assertEquals(
- 'yes', $this->good_bi->getCollectUserData($this->fname));
- }
-
- public function test_getLaunchpadTeams_empty()
- {
- $this->assertFalse($this->empty_bi->getLaunchpadTeams($this->fname));
- }
-
- public function test_getLaunchpadTeams_type()
- {
- $this->assertInternalType(
- 'string', $this->good_bi->getLaunchpadTeams($this->fname));
- }
-
- public function test_getLaunchpadTeams()
- {
- $this->assertEquals(
- 'linaro,non-linaro',
- $this->good_bi->getLaunchpadTeams($this->fname));
- }
-
- public function test_getLicenseText_empty()
- {
- $this->assertFalse($this->empty_bi->getLicenseText($this->fname));
- }
-
- public function test_getLicenseText_type()
- {
- $this->assertInternalType(
- 'string', $this->good_bi->getLicenseText($this->fname));
- }
-
- public function test_getLicenseText()
- {
- $this->assertStringStartsWith(
- $this->lic_text_test,
- $this->good_bi->getLicenseText($this->fname));
+ 'landing-snowball', $this->good_bi->get("Build-Name"));
}
}
?>