public function run() { $project = 'test'; // Check for requested file if (!empty($this->config->filename) && !file_exists($this->config->filename)) { throw new NoSuchFile($this->config->filename); } elseif (!empty($this->config->dirname) && !file_exists($this->config->dirname)) { throw new NoSuchDir($this->config->filename); } // Check for requested analyze $analyzer = $this->config->program; if (Analyzer::getClass($analyzer)) { $analyzers_class = array($analyzer); } else { $r = Analyzer::getSuggestionClass($analyzer); if (count($r) > 0) { echo 'did you mean : ', implode(', ', str_replace('_', '/', $r)), "\n"; } throw new NoSuchAnalyzer($analyzer); } display("Cleaning DB\n"); $clean = new CleanDb($this->gremlin, $this->config, Tasks::IS_SUBTASK); $clean->run(); $load = new Load($this->gremlin, $this->config, Tasks::IS_SUBTASK); $load->run(); unset($load); display("Project loaded\n"); $analyze = new Analyze($this->gremlin, $this->config, Tasks::IS_SUBTASK); $analyze->run(); unset($analyze); $results = new Results($this->gremlin, $this->config, Tasks::IS_SUBTASK); $results->run(); unset($results); display("Analyzed project\n"); }
public function execute(Config $config) { switch ($config->command) { case 'doctor': $doctor = new Tasks\Doctor($this->gremlin, $this->config); $doctor->run($config); break; case 'init': $task = new Tasks\Initproject($this->gremlin, $this->config); $task->run($config); break; case 'anonymize': $task = new Tasks\Anonymize($this->gremlin, $this->config); $task->run($config); break; case 'files': $task = new Tasks\Files($this->gremlin, $this->config); $task->run($config); break; case 'load': $task = new Tasks\Load($this->gremlin, $this->config); $task->run($config); break; case 'stat': $task = new Tasks\Stat($this->gremlin, $this->config); $task->run($config); break; case 'analyze': $task = new Tasks\Analyze($this->gremlin, $this->config); $task->run($config); break; case 'results': $task = new Tasks\Results($this->gremlin, $this->config); $task->run($config); break; case 'export': $task = new Tasks\Export($this->gremlin, $this->config); $task->run($config); break; case 'report': $task = new Tasks\Report2($this->gremlin, $this->config); $task->run($config); break; case 'project': $task = new Tasks\Project($this->gremlin, $this->config); $task->run($config); break; case 'magicnumber': $task = new Tasks\Magicnumber($this->gremlin, $this->config); $task->run($config); break; case 'clean': $task = new Tasks\Clean($this->gremlin, $this->config); $task->run($config); break; case 'status': $task = new Tasks\Status($this->gremlin, $this->config); $task->run($config); break; case 'help': $task = new Tasks\Help($this->gremlin, $this->config); $task->run($config); break; case 'cleandb': $task = new Tasks\CleanDb($this->gremlin, $this->config); $task->run($config); break; case 'onepage': $task = new Tasks\OnePage($this->gremlin, $this->config); $task->run($config); break; case 'update': $task = new Tasks\Update($this->gremlin, $this->config); $task->run($config); break; case 'onepagereport': $task = new Tasks\OnepageReport($this->gremlin, $this->config); $task->run($config); break; case 'phploc': $task = new Tasks\Phploc($this->gremlin, $this->config); $task->run($config); break; case 'findextlib': $task = new Tasks\FindExternalLibraries($this->gremlin, $this->config); $task->run($config); break; case 'dump': $task = new Tasks\Dump($this->gremlin, $this->config); $task->run($config); break; case 'jobqueue': $task = new Tasks\Jobqueue($this->gremlin, $this->config); $task->run($config); break; case 'queue': $task = new Tasks\Queue($this->gremlin, $this->config); $task->run($config); break; case 'test': $task = new Tasks\Test($this->gremlin, $this->config); $task->run($config); break; case 'remove': $task = new Tasks\Remove($this->gremlin, $this->config); $task->run($config); break; case 'server': $task = new Tasks\Server($this->gremlin, $this->config); $task->run($config); break; case 'upgrade': $task = new Tasks\Upgrade($this->gremlin, $this->config); $task->run($config); break; case 'version': default: $version = self::VERSION; $build = self::BUILD; $date = date('r', filemtime(__FILE__)); echo "\n ________ __ _ \n|_ __ | [ | _ / |_ \n | |_ \\_| _ __ ,--. | | / ] ,--. `| |-' \n | _| _ [ \\ [ ]`'_\\ : | '' < `'_\\ : | | \n _| |__/ | > ' < // | |, | |`\\ \\ // | |,| |, \n|________|[__]`\\_]\\'-;__/[__| \\_]\\'-;__/\\__/ \n \n\nExakat : @ 2014-2016 Damien Seguy. \nVersion : ", $version, ' - Build ', $build, ' - ', $date, "\n"; break; } }
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); }
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"); }