aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStevan Radakovic <stevan.radakovic@linaro.org>2012-05-08 13:27:26 +0200
committerStevan Radakovic <stevan.radakovic@linaro.org>2012-05-08 13:27:26 +0200
commitbe2faa9d82964cdeefe70921d09fb5d9edc65ba3 (patch)
tree2995a196f3dbfe04a8932eb22df3f00fbad37507
parentfdec798f6fdbe15dac14d10fd118f4d8ff76d30a (diff)
parentb9189031ed4bf4255c70ab3e71afee12a471253c (diff)
cosmetic changes and some README tweaks
-rw-r--r--README42
-rw-r--r--licenses/LicenseHelper.php170
-rwxr-xr-xscripts/jenkins-post-www.sh2
-rwxr-xr-xscripts/publish_to_snapshots.py4
-rw-r--r--testing/LicenseHelperTest.php204
5 files changed, 207 insertions, 215 deletions
diff --git a/README b/README
index d865626..079e26c 100644
--- a/README
+++ b/README
@@ -42,7 +42,7 @@ www area directly, we set-up two different users on the system with SSH keys:
* android-build-linaro:
- chrooted to /srv3/snapshots.linaro.org/www/android/ and allows sftp
+ chrooted to /srv/snapshots.linaro.org/www/android/ and allows sftp
access to push files over; home directory
* android-build-linaro-trigger:
@@ -74,29 +74,6 @@ To ensure serialization of steps, and allow LAVA submission, these happen as
build steps, and not as publishing steps.
-Unit tests
-----------
-
-There's currently only one unit test file, LicenseHelperTest.php under testing directory. You first need to install the phpunit package from ubuntu repos:
-$ sudo apt-get install php-pear
-$ sudo pear config-set auto_discover 1
-$ sudo pear install pear.phpunit.de/PHPUnit
-
-Then to run the test from the 'testing' directory:
-$ cd testing/
-$ phpunit LicenseHelperTest
-
-In case the tests fail with PHP_CodeCoverage error, do the following to install the phpunit properly:
-
-$ sudo apt-get remove phpunit
-$ sudo apt-get upgrade pear
-$ sudo pear channel-discover pear.phpunit.de
-$ sudo pear channel-discover pear.symfony-project.com
-$ sudo pear channel-discover components.ez.no
-$ sudo pear update-channels
-$ sudo pear upgrade-all
-$ sudo pear install --alldeps phpunit/PHPUnit
-$ sudo apt-get install phpunit
Tests
@@ -107,3 +84,20 @@ Python and Apache2:
$ testr init
$ testr run
+
+
+Tests for PHP license-matching logic
+....................................
+
+There's currently only one unit test file, LicenseHelperTest.php under testing directory. You first need to install the phpunit package from ubuntu repos:
+ $ sudo apt-get install php-unit
+
+
+Recent (as of 2012-05-08) Ubuntu/Debian releases have a broken phpunit package and thus require installation in a different manner:
+ $ sudo apt-get install php-pear
+ $ sudo pear config-set auto_discover 1
+ $ sudo pear install pear.phpunit.de/PHPUnit
+
+Then to run the test from the 'testing' directory:
+$ cd testing/
+$ phpunit LicenseHelperTest
diff --git a/licenses/LicenseHelper.php b/licenses/LicenseHelper.php
index 1329ff9..b55ac49 100644
--- a/licenses/LicenseHelper.php
+++ b/licenses/LicenseHelper.php
@@ -1,104 +1,102 @@
<?php
-class LicenseHelper
+class LicenseHelper
{
- // Get list of files into array to process them later.
- // Used to find special licenses and dirs with only subdirs.
- public static function checkFile($fn)
- {
- if (is_file($fn) or is_link($fn)) {
- return true;
+ /**
+ * Get list of files into array to process them later.
+ * Used to find special licenses and dirs with only subdirs.
+ */
+ public static function checkFile($fn)
+ {
+ if (is_file($fn) or is_link($fn)) {
+ return true;
+ }
+ return false;
}
- return false;
- }
- public static function getFilesList($dirname)
- {
- if (!is_dir($dirname)) {
- throw new InvalidArgumentException('Method argument should be a directory path');
- }
+ /**
+ * Get list of filenames from a directory
+ */
+ public static function getFilesList($dirname)
+ {
+ if (!is_dir($dirname)) {
+ throw new InvalidArgumentException('Method argument '.
+ 'should be a directory path');
+ }
- $files = array();
- if ($handle = opendir($dirname)) {
- while ($handle && false !== ($entry = readdir($handle))) {
- if ($entry != "." && $entry != ".." && !is_dir($dirname."/".$entry) && $entry != "HEADER.html") {
- $files[] = $entry;
- }
- }
+ $files = array();
+ if ($handle = opendir($dirname)) {
+ while ($handle && false !== ($entry = readdir($handle))) {
+ if ($entry != "." && $entry != ".." &&
+ !is_dir($dirname."/".$entry) && $entry != "HEADER.html") {
+ $files[] = $entry;
+ }
+ }
+ }
+ closedir($handle);
+ return $files;
}
- closedir($handle);
- return $files;
- }
- // Get array of file name and extension from full filename.
- public static function splitFilename($filename)
- {
- $pos = strpos($filename, '.');
- if ($pos === false) { // dot is not found in the filename
- return array($filename, ''); // no extension
- } else {
- $basename = substr($filename, 0, $pos);
- $extension = substr($filename, $pos+1);
- return array($basename, $extension);
+ /**
+ * Find a matching filename in an array from given filename template.
+ */
+ public static function findFileByPattern($fl, $pattern)
+ {
+ if (!empty($fl)) {
+ foreach ($fl as $f) {
+ if (preg_match($pattern, $f, $matches)) {
+ return $f;
+ }
+ }
+ }
+ return false;
}
- }
- // Find special EULA based on filename template.
- public static function findFileByPattern($fl, $pattern)
- {
- if (!empty($fl)) {
- foreach ($fl as $f) {
- if (preg_match($pattern, $f, $matches)) {
- return $f;
- }
- }
+ /**
+ * Get license theme name from EULA filename.
+ */
+ public static function getTheme($eula, $down)
+ {
+ if ($eula != 'EULA.txt') { // Special EULA file was found
+ $theme = array_pop(explode(".", $eula));
+ } else { // No special EULA file was found
+ $eula = "EULA.txt";
+ if (preg_match("/.*snowball.*/", $down)) {
+ $theme = "ste";
+ } elseif (preg_match("/.*origen.*/", $down)) {
+ $theme = "samsung";
+ } else {
+ $theme = "linaro";
+ }
+ }
+ return $theme;
}
- return false;
- }
- // Get license theme name from EULA filename.
- public static function getTheme($eula, $down)
- {
- if ($eula != 'EULA.txt') { // Special EULA file was found
- $theme = array_pop(explode(".", $eula));
- } else { // No special EULA file was found
- $eula = "EULA.txt";
- if (preg_match("/.*snowball.*/", $down)) {
- $theme = "ste";
- } elseif (preg_match("/.*origen.*/", $down)) {
- $theme = "samsung";
- } else {
- $theme = "linaro";
- }
+ public static function status_forbidden($dir)
+ {
+ header("Status: 403");
+ header("HTTP/1.1 403 Forbidden");
+ echo "<h1>Forbidden</h1>";
+ echo "You don't have permission to access ".$dir." on this server.";
+ exit;
}
- return $theme;
- }
-
- public static function status_forbidden($dir)
- {
- header("Status: 403");
- header("HTTP/1.1 403 Forbidden");
- echo "<h1>Forbidden</h1>";
- echo "You don't have permission to access ".$dir." on this server.";
- exit;
- }
- public static function status_ok($dir, $domain)
- {
- header("Status: 200");
- header("Location: ".$dir);
- setcookie("redirectlicensephp", "yes", 0, "/", ".".$domain);
- exit;
- }
+ public static function status_ok($dir, $domain)
+ {
+ header("Status: 200");
+ header("Location: ".$dir);
+ setcookie("redirectlicensephp", "yes", 0, "/", ".".$domain);
+ exit;
+ }
- public static function status_not_found()
- {
- header("Status: 404");
- header("HTTP/1.0 404 Not Found");
- echo "<h1>404 Not Found</h1>";
- echo "The requested URL was not found on this server.";
- exit;
- }
+ public static function status_not_found()
+ {
+ header("Status: 404");
+ header("HTTP/1.0 404 Not Found");
+ echo "<h1>404 Not Found</h1>";
+ echo "The requested URL was not found on this server.";
+ exit;
+ }
} \ No newline at end of file
diff --git a/scripts/jenkins-post-www.sh b/scripts/jenkins-post-www.sh
index c6c47cc..6a4705a 100755
--- a/scripts/jenkins-post-www.sh
+++ b/scripts/jenkins-post-www.sh
@@ -1,6 +1,6 @@
#!/bin/bash
BASE_PATH=/home/android-build-linaro/android/.tmp
-TARGET_PATH=/srv3/snapshots.linaro.org/www/android/
+TARGET_PATH=/srv/snapshots.linaro.org/www/android/
# Expected argument: username_jobname/buildno
build_path="$1"
diff --git a/scripts/publish_to_snapshots.py b/scripts/publish_to_snapshots.py
index cf9c1c7..8522988 100755
--- a/scripts/publish_to_snapshots.py
+++ b/scripts/publish_to_snapshots.py
@@ -20,8 +20,8 @@ parser.add_argument("-n", "--build-num", dest="build_num", type=int,
parser.add_argument("-m", "--manifest", dest="manifest", action='store_true',
help="Optional parameter to generate MANIFEST file")
-uploads_path = '/srv3/snapshots.linaro.org/uploads/'
-target_path = '/srv3/snapshots.linaro.org/www/'
+uploads_path = '/srv/snapshots.linaro.org/uploads/'
+target_path = '/srv/snapshots.linaro.org/www/'
PASS = 0
FAIL = 1
acceptable_job_types = [
diff --git a/testing/LicenseHelperTest.php b/testing/LicenseHelperTest.php
index 650cdb0..5d9a515 100644
--- a/testing/LicenseHelperTest.php
+++ b/testing/LicenseHelperTest.php
@@ -3,119 +3,119 @@
class LicenseHelperTest extends PHPUnit_Framework_TestCase
{
- /**
- * Includes test class, creates some help files for testing
- */
- protected function setUp()
- {
- require_once("../licenses/LicenseHelper.php");
- symlink(__FILE__, "test_link");
- }
+ /**
+ * Includes test class, creates some help files for testing
+ */
+ protected function setUp()
+ {
+ require_once("../licenses/LicenseHelper.php");
+ symlink(__FILE__, "test_link");
+ }
- /**
- * Removes help files
- */
- protected function tearDown()
- {
- unlink("test_link");
- }
+ /**
+ * Removes help files
+ */
+ protected function tearDown()
+ {
+ unlink("test_link");
+ }
- /**
- * Test with directory
- */
- public function testCheckFile_nonFile()
- {
- $this->assertFalse(LicenseHelper::checkFile(dirname(__FILE__)));
- }
+ /**
+ * Test with directory
+ */
+ public function testCheckFile_nonFile()
+ {
+ $this->assertFalse(LicenseHelper::checkFile(dirname(__FILE__)));
+ }
- /**
- * Test with link
- */
- public function testCheckFile_link()
- {
- $this->assertTrue(LicenseHelper::checkFile("test_link"));
- }
+ /**
+ * Test with link
+ */
+ public function testCheckFile_link()
+ {
+ $this->assertTrue(LicenseHelper::checkFile("test_link"));
+ }
- /**
- * Test with file
- */
- public function testCheckFile_file()
- {
- $this->assertTrue(LicenseHelper::checkFile(__FILE__));
- }
+ /**
+ * Test with file
+ */
+ public function testCheckFile_file()
+ {
+ $this->assertTrue(LicenseHelper::checkFile(__FILE__));
+ }
- /**
- * Get file list from a file
- */
- public function testGetFilesList_file()
- {
- try {
- $file_list = LicenseHelper::getFilesList(__FILE__);
- $this->assertTrue(FALSE);
- } catch (InvalidArgumentException $e) {
- $this->assertTrue(TRUE);
- } catch (Exception $e) {
- $this->assertTrue(FALSE);
+ /**
+ * Get file list from a file
+ */
+ public function testGetFilesList_file()
+ {
+ try {
+ $file_list = LicenseHelper::getFilesList(__FILE__);
+ $this->assertTrue(FALSE);
+ } catch (InvalidArgumentException $e) {
+ $this->assertTrue(TRUE);
+ } catch (Exception $e) {
+ $this->assertTrue(FALSE);
+ }
}
- }
- /**
- * Get file list from a directory
- */
- public function testGetFilesList_dir()
- {
- $file_list = LicenseHelper::getFilesList(dirname(__FILE__));
- $this->assertNotEmpty($file_list);
- $this->assertContains(basename(__FILE__), $file_list);
-
- // Remove '.' and '..'.
- $expected_count = count(scandir(dirname(__FILE__))) - 2;
- $this->assertCount($expected_count, $file_list);
- }
+ /**
+ * Get file list from a directory
+ */
+ public function testGetFilesList_dir()
+ {
+ $file_list = LicenseHelper::getFilesList(dirname(__FILE__));
+ $this->assertNotEmpty($file_list);
+ $this->assertContains(basename(__FILE__), $file_list);
- /**
- * Test with pattern which will not match any filename.
- */
- public function testFindFileByPattern_noMatch()
- {
- $file_list = array("test.txt", "new_file.pdf");
- $pattern = "/^abc/";
- $this->assertFalse(LicenseHelper::findFileByPattern($file_list, $pattern));
- }
+ // Remove '.' and '..'.
+ $expected_count = count(scandir(dirname(__FILE__))) - 2;
+ $this->assertCount($expected_count, $file_list);
+ }
- /**
- * Test with pattern which will match a filename.
- */
- public function testFindFileByPattern_match()
- {
- $file_list = array("test.txt", "new_file.pdf");
- $pattern = "/test/";
- $this->assertEquals("test.txt",
- LicenseHelper::findFileByPattern($file_list, $pattern));
- }
+ /**
+ * Test with pattern which will not match any filename.
+ */
+ public function testFindFileByPattern_noMatch()
+ {
+ $file_list = array("test.txt", "new_file.pdf");
+ $pattern = "/^abc/";
+ $this->assertFalse(LicenseHelper::findFileByPattern($file_list, $pattern));
+ }
- /**
- * Test with no eula present.
- */
- public function testGetTheme_noEula()
- {
- $eula = "EULA.txt";
- $filename = "snowball.build.tar.bz2";
- $this->assertEquals("ste", LicenseHelper::getTheme($eula, $filename));
- $filename = "origen.build.tar.bz2";
- $this->assertEquals("samsung", LicenseHelper::getTheme($eula, $filename));
- $filename = "build.tar.bz2";
- $this->assertEquals("linaro", LicenseHelper::getTheme($eula, $filename));
- }
+ /**
+ * Test with pattern which will match a filename.
+ */
+ public function testFindFileByPattern_match()
+ {
+ $file_list = array("test.txt", "new_file.pdf");
+ $pattern = "/test/";
+ $this->assertEquals("test.txt",
+ LicenseHelper::findFileByPattern($file_list, $pattern));
+ }
- /**
- * Test with eula present.
- */
- public function testGetTheme_eula()
- {
- $eula = "EULA.txt.test";
- $this->assertEquals("test", LicenseHelper::getTheme($eula, ""));
- }
+ /**
+ * Test with no eula present.
+ */
+ public function testGetTheme_noEula()
+ {
+ $eula = "EULA.txt";
+ $filename = "snowball.build.tar.bz2";
+ $this->assertEquals("ste", LicenseHelper::getTheme($eula, $filename));
+ $filename = "origen.build.tar.bz2";
+ $this->assertEquals("samsung", LicenseHelper::getTheme($eula, $filename));
+ $filename = "build.tar.bz2";
+ $this->assertEquals("linaro", LicenseHelper::getTheme($eula, $filename));
+ }
+
+ /**
+ * Test with eula present.
+ */
+ public function testGetTheme_eula()
+ {
+ $eula = "EULA.txt.test";
+ $this->assertEquals("test", LicenseHelper::getTheme($eula, ""));
+ }
}