Example #1
0
 public function run()
 {
     $progress = 0;
     $begin = microtime(true);
     $this->project_dir = $this->config->projects_root . '/projects/onepage/';
     // checking for installation
     if (!file_exists($this->project_dir)) {
         shell_exec($this->config->php . ' ' . $this->config->executable . ' init -p onepage ');
         mkdir($this->project_dir . '/code', 0755);
         shell_exec($this->config->php . ' ' . $this->config->executable . ' phploc -p onepage ');
     }
     $this->updateProgress($progress++);
     // todo : check that there is indeed this project or create it.
     if (!file_exists($this->config->filename)) {
         throw new NoSuchFile($this->config->filename);
     }
     // todo : check that there is indeed this project or create it.
     if (!is_file($this->config->filename) || !is_readable($this->config->filename)) {
         die("'{$this->config->filename}' must be a readable file. Aborting\n");
     }
     $this->cleanLogForProject('onepage');
     copy($this->config->filename, $this->config->projects_root . '/projects/onepage/code/onepage.php');
     $this->updateProgress($progress++);
     $this->logTime('Start');
     $datastorePath = $this->config->projects_root . '/projects/onepage/datastore.sqlite';
     if (file_exists($datastorePath)) {
         unlink($datastorePath);
     }
     unset($this->datastore);
     $this->datastore = new Datastore($this->config, Datastore::CREATE);
     $audit_start = time();
     $this->datastore->addRow('hash', array('audit_start' => $audit_start, 'exakat_version' => Exakat::VERSION, 'exakat_build' => Exakat::BUILD));
     display("Cleaning DB\n");
     $task = new CleanDb($this->gremlin, $this->config);
     $task->run();
     $this->updateProgress($progress++);
     $this->logTime('CleanDb');
     display("Running files\n");
     $task = new Files($this->gremlin, $this->config);
     $task->run();
     $this->updateProgress($progress++);
     $this->logTime('Files');
     display("Running project 'onepage'\n");
     $task = new Load($this->gremlin, $this->config);
     $task->run();
     display("Project loaded\n");
     $this->updateProgress($progress++);
     $this->logTime('Loading');
     $task = new Analyze($this->gremlin, $this->config);
     $task->run();
     rename($this->config->projects_root . '/projects/onepage/log/analyze.log', $this->config->projects_root . '/projects/onepage/log/analyze.onepage.log');
     display("Project analyzed\n");
     $this->updateProgress($progress++);
     $this->logTime('Analyze');
     $b1 = microtime(true);
     $task = new Dump($this->gremlin, $this->config);
     $task->run();
     display("Project dumped\n");
     $e1 = microtime(true);
     $task = new Report2($this->gremlin, $this->config);
     $task->run();
     display("Project reported\n");
     $this->logTime('Report');
     $this->updateProgress($progress++);
     display("Project reported\n");
     $this->updateProgress($progress++);
     // Clean code
     unlink($this->config->projects_root . '/projects/onepage/code/onepage.php');
     $audit_end = time();
     $this->datastore->addRow('hash', array('audit_end' => $audit_end, 'audit_length' => $audit_end - $audit_start));
     $this->logTime('Final');
     display("End 2\n");
     $end = microtime(true);
     $this->updateProgress($progress++);
     $this->logTime('Files');
     // Back to 0
     $this->updateProgress(0);
 }
Example #2
0
    public function run()
    {
        $progress = 0;
        $project = $this->config->project;
        $this->project_dir = $this->config->projects_root . '/projects/' . $project;
        if ($this->config->project == "default") {
            throw new ProjectNeeded();
        }
        if (!file_exists($this->config->projects_root . '/projects/' . $project)) {
            throw new NoSuchProject($this->config->project);
        }
        // cleaning log directory (possibly logs)
        $logs = glob($this->config->projects_root . '/projects/' . $project . '/log/*');
        foreach ($logs as $log) {
            unlink($log);
        }
        $this->logTime('Start');
        $this->addSnitch(array('step' => 'Start', 'project' => $this->config->project));
        // cleaning datastore
        $this->datastore = new Datastore($this->config, Datastore::CREATE);
        $audit_start = time();
        $this->datastore->addRow('hash', array('audit_start' => $audit_start, 'exakat_version' => Exakat::VERSION, 'exakat_build' => Exakat::BUILD));
        display("Running project '{$project}'\n");
        display("Cleaning DB\n");
        $analyze = new CleanDb($this->gremlin, $this->config, Tasks::IS_SUBTASK);
        $analyze->run();
        unset($analyze);
        $this->logTime('CleanDb');
        $this->addSnitch(array('step' => 'Clean DB', 'project' => $this->config->project));
        display("Search for external libraries\n");
        $args = array(1 => 'findextlib', 2 => '-p', 3 => $this->config->project, 4 => '-u');
        $configThema = Config::push($args);
        $analyze = new FindExternalLibraries($this->gremlin, $configThema, Tasks::IS_SUBTASK);
        $analyze->run();
        $this->addSnitch(array('step' => 'External lib', 'project' => $this->config->project));
        Config::pop();
        unset($analyze);
        display("Running files\n");
        $analyze = new Files($this->gremlin, $this->config, Tasks::IS_SUBTASK);
        $analyze->run();
        unset($analyze);
        $this->logTime('Files');
        $this->addSnitch(array('step' => 'Files', 'project' => $this->config->project));
        $this->checkTokenLimit();
        $analyze = new Load($this->gremlin, $this->config, Tasks::IS_SUBTASK);
        $analyze->run();
        unset($analyze);
        display("Project loaded\n");
        $this->logTime('Loading');
        // paralell running
        exec($this->config->php . ' ' . $this->config->executable . ' magicnumber -p ' . $this->config->project . '   > /dev/null &');
        $this->addSnitch(array('step' => 'Magic Numbers', 'project' => $this->config->project));
        // Dump is a child process
        shell_exec($this->config->php . ' ' . $this->config->executable . ' dump -p ' . $this->config->project);
        foreach ($this->themes as $theme) {
            $this->addSnitch(array('step' => 'Analyze : ' . $theme, 'project' => $this->config->project));
            $themeForFile = strtolower(str_replace(' ', '_', trim($theme, '"')));
            $args = array(1 => 'analyze', 2 => '-p', 3 => $this->config->project, 4 => '-T', 5 => trim($theme, '"'), 6 => '-norefresh', 7 => '-u');
            try {
                $configThema = Config::push($args);
                $analyze = new Analyze($this->gremlin, $configThema, Tasks::IS_SUBTASK);
                $analyze->run();
                unset($analyze);
                rename($this->config->projects_root . '/projects/' . $project . '/log/analyze.log', $this->config->projects_root . '/projects/' . $project . '/log/analyze.' . $themeForFile . '.log');
                Config::pop();
                $args = array(1 => 'dump', 2 => '-p', 3 => $this->config->project, 4 => '-T', 5 => trim($theme, '"'), 6 => '-u');
                $configThema = Config::push($args);
                $dump = new Dump($this->gremlin, $configThema, Tasks::IS_SUBTASK);
                $dump->run();
                unset($dump);
                Config::pop();
            } catch (\Exception $e) {
                echo "Error while running the Analyze {$theme} \n", $e->getMessage(), "\nTrying next analysis\n";
                file_put_contents($this->config->projects_root . '/projects/' . $project . '/log/analyze.' . $themeForFile . '.final.log', $e->getMessage());
            }
        }
        display("Analyzed project\n");
        $this->logTime('Analyze');
        $this->addSnitch(array('step' => 'Analyzed', 'project' => $this->config->project));
        $this->logTime('Analyze');
        $oldConfig = Config::factory();
        foreach ($this->reports as $reportName => $formats) {
            foreach ($formats as $format => $fileName) {
                display("Reporting {$reportName} in {$format}\n");
                $this->addSnitch(array('step' => 'Report : ' . $format, 'project' => $this->config->project));
                $args = array(1 => 'report', 2 => '-p', 3 => $this->config->project, 4 => '-file', 5 => $fileName, 6 => '-format', 7 => $format);
                $this->config = Config::factory($args);
                try {
                    $report = new Report2($this->gremlin, $this->config, Tasks::IS_SUBTASK);
                    $report->run();
                    unset($report);
                } catch (\Exception $e) {
                    echo "Error while building {$reportName} in {$format} \n", $e->getMessage(), "\nTrying next report\n";
                }
            }
        }
        Config::factory($oldConfig);
        display("Reported project\n");
        $audit_end = time();
        // measure Neo4j's final size
        $res = shell_exec('du -sh ' . $this->config->neo4j_folder . ' 2>/dev/null');
        $neo4jSize = trim(str_replace(basename($this->config->neo4j_folder), '', $res));
        $this->datastore->addRow('hash', array('audit_end' => $audit_end, 'audit_length' => $audit_end - $audit_start, 'neo4jSize' => $neo4jSize));
        $query = <<<GREMLIN
g.V().where( __.sideEffect{x = []; }.in('ANALYZED').sideEffect{ x.add(it.get().value('analyzer')); }.barrier().sideEffect{ y = x.groupBy().findAll{ i,j -> j.size() > 1;};} )
.filter{ y.size() > 0; }
.map{ y; };
GREMLIN;
        $res = $this->gremlin->query($query);
        if (!empty($res)) {
            file_put_contents($this->config->projects_root . '/projects/' . $project . '/log/doublons.log', var_export($res, true));
        }
        $this->logTime('Final');
        $this->removeSnitch();
        display("End\n");
    }