Esempio n. 1
0
 protected function getVersionedCachedData($cache_domain_key, XRef_IFileProvider $file_provider, $filename, $callback_get_data, $callback_validate_data)
 {
     // try to load cached data for this file
     // 1. find the id for this file
     if (isset($this->filesMap[$filename])) {
         $file_id = $this->filesMap[$filename];
     } else {
         $file_content = $file_provider->getFileContent($filename);
         if (!$file_content) {
             // file doesn't exist in this revision
             return call_user_func($callback_get_data, null);
         }
         $file_id = sha1($file_content);
         $this->filesMap[$filename] = $file_id;
         // update/create filesMap
     }
     // 2. load the data for this file_id & check version
     $data = null;
     if ($this->storageManager && !$this->rewriteCache) {
         $d = $this->storageManager->restoreData($cache_domain_key, $file_id);
         if (isset($d) && isset($d["xrefVersion"]) && $d["xrefVersion"] == XRef::version()) {
             $data = $d["data"];
         }
     }
     if (call_user_func($callback_validate_data, $data)) {
         $this->stats["cache_hit"]++;
     } else {
         // 3. cached report not found, parse the file and run the lint plugins
         if (!isset($file_content)) {
             $file_content = $file_provider->getFileContent($filename);
         }
         $pf = $this->getParsedFile($file_id, $filename, $file_content);
         $data = call_user_func($callback_get_data, $pf);
         // 4. save the report
         if ($this->storageManager) {
             $d = array("data" => $data, "filename" => $filename, "xrefVersion" => XRef::version(), "uniq" => $file_provider->getPersistentId());
             $this->storageManager->saveData($cache_domain_key, $file_id, $d);
         }
     }
     return $data;
 }
Esempio n. 2
0
<?php

require_once 'PEAR/PackageFileManager2.php';
require_once dirname(__FILE__) . '/../XRef.class.php';
$version = XRef::version();
PEAR::setErrorHandling(PEAR_ERROR_DIE);
$pfm = new PEAR_PackageFileManager2();
$pfm->setOptions(array('baseinstalldir' => 'XRef', 'packagedirectory' => '.', 'filelistgenerator' => 'file', 'ignore' => array('Makefile', 'dev/', '.idea', '.xref', 'tmp'), 'dir_roles' => array('bin' => 'script', 'config' => 'data', 'tests' => 'test', 'examples' => 'doc', 'templates' => 'data', 'scripts' => 'php', 'web-scripts' => 'php', 'plugins' => 'php'), 'exceptions' => array('README.md' => 'doc')));
$pfm->setPackage('XRef');
$pfm->setSummary('XRef - php source file toolkit');
$pfm->setDescription('XRef Lint - php lint and crossref doc tool');
$pfm->setChannel('pear.xref-lint.net');
$pfm->setAPIVersion($version);
$pfm->setReleaseVersion($version);
$pfm->setReleaseStability('stable');
$pfm->setAPIStability('stable');
$pfm->setNotes("v1.0.0 release candidate #1");
$pfm->setPackageType('php');
// dependencies
//$pfm->addDependency("Console_Getopt");
// windows-release
$pfm->addRelease();
// set up a release section
$pfm->setOSInstallCondition('windows');
$pfm->addIgnoreToRelease('bin/xref-lint');
$pfm->addIgnoreToRelease('bin/xref-doc');
$pfm->addIgnoreToRelease('bin/xref-ci');
$pfm->addIgnoreToRelease('bin/git-xref-lint');
$pfm->addInstallAs('bin/xref-lint.bat', 'xref-lint.bat');
$pfm->addInstallAs('bin/xref-doc.bat', 'xref-doc.bat');
// other platforms
Esempio n. 3
0
    public function testCI()
    {
        $old_rev = "377d2edc1da549a80b5b44286e7dcaf59cee300a";
        $current_rev = "190fc6a9fddcae0313decbbbce92e4a83bf47ab9";
        XRef::setConfigValue('mail.reply-to', '*****@*****.**');
        XRef::setConfigValue('mail.from', '*****@*****.**');
        XRef::setConfigValue('mail.to', array('*****@*****.**', '{%ae}', '{%an}@xref-lint.net'));
        XRef::setConfigValue('project.name', 'unit-test');
        XRef::setConfigValue('project.source-url', 'https://github.com/gariev/xref/blob/{%revision}/{%fileName}#L{%lineNumber}');
        XRef::setConfigValue('xref.smarty-class', self::SMARTY_CLASS_PATH);
        XRef::setConfigValue('xref.data-dir', 'tmp');
        $scm = $this->xref->getSourceCodeManager();
        $file_provider_old = $scm->getFileProvider($old_rev);
        $file_provider_new = $scm->getFileProvider($current_rev);
        $modified_files = $scm->getListOfModifiedFiles($old_rev, $current_rev);
        $lint_engine = new XRef_LintEngine_ProjectCheck($this->xref, false);
        $errors = $lint_engine->getIncrementalReport($file_provider_old, $file_provider_new, $modified_files);
        list($recipients, $subject, $body, $headers) = $this->xref->getNotificationEmail($errors, 'tests-git', $old_rev, $current_rev);
        //print_r(array($recipients, $subject, $body, $headers));
        // assert that our comparison function works
        $this->assertTrue($this->strSmartSpaces("\t hello,\r \n world  ") == $this->strSmartSpaces("hello, world"));
        $this->assertTrue($this->strSmartSpaces("\t hello,\r \n world  ") != $this->strSmartSpaces("hello , world"));
        $this->assertTrue(count($recipients) == 3);
        $this->assertTrue($recipients[0] == '*****@*****.**');
        $this->assertTrue($recipients[1] == '*****@*****.**');
        $this->assertTrue($recipients[2] == '*****@*****.**');
        $this->assertTrue($this->strSmartSpaces($subject) == "XRef CI unit-test: tests-git/190fc6a");
        $expected_body = <<<END
            <html><body>
            Hi, you've got this e-mail as the author (gariev) of commit 190fc6a to branch tests-git.
            It looks like there are problems in file(s) modified since previous revision 377d2ed:
                <ul>
                    <li>broken.php</li>
                    <ul>
                        <li>
                            <span class='error'>error</span>
                            (<a href="https://github.com/gariev/xref/blob/master/README.md#xr010">xr010</a>): Use of unknown variable (\$error)
                             at <a href="https://github.com/gariev/xref/blob/190fc6a9fddcae0313decbbbce92e4a83bf47ab9/broken.php#L3">line 3</a>
                        </li>
                    </ul>
                </ul>
            <p>If the problems above are real, you can fix them.
            If these warnings are from code merged from other branch and not result of merge conflict, you can ignore them or find the author of the original commit.
            If the report is wrong, you can help <a href='mailto:gariev@hotmail.com?subject=xref'>improve XRef CI</a> itself and/or ignore this e-mail.
            </p>
            <p><small>
              Generated by XRef CI version <<VERSION>>. About XRef:
                <a href="https://github.com/gariev/xref/blob/master/README.md">documentation</a>,
                <a href="https://github.com/gariev/xref/">source code</a>,
                <a href="http://xref-lint.net/bin/xref-lint.php">online tool</a>.
            </small></p>
            </body></html>
END;
        $expected_body = str_replace('<<VERSION>>', XRef::version(), $expected_body);
        $this->assertTrue($this->strSmartSpaces($body) == $this->strSmartSpaces($expected_body));
        $expected_headers = <<<END
            MIME-Version: 1.0
            Content-type: text/html
            Reply-to: no-reply@xref-lint.net
            From: ci-server@xref-lint.net
END;
        $this->assertTrue($this->strSmartSpaces($headers) == $this->strSmartSpaces($expected_headers));
    }