more cleanup
This commit is contained in:
parent
1bb79c7974
commit
e004cdef0b
@ -1,13 +1,12 @@
|
||||
/**
|
||||
Process version information for a set of Results.
|
||||
**/
|
||||
class CodeVersionInformation {
|
||||
public var final_versions : Hash<Hash<String>>;
|
||||
public var minimum_versions : Hash<String>;
|
||||
public var maximum_versions : Hash<String>;
|
||||
public var all_modules : Array<String>;
|
||||
|
||||
public static function breakdown_version_number(version : String) {
|
||||
return version.split(".");
|
||||
}
|
||||
|
||||
public static function get_version_lower_than(s : String) : String {
|
||||
var greater_than = ~/\<= (.*)$/;
|
||||
|
||||
@ -20,7 +19,7 @@ class CodeVersionInformation {
|
||||
public static function breakdown_php_version_string(s : String) {
|
||||
var parts = new Array<String>();
|
||||
|
||||
for (regexp in [ ~/^([^\ ]*) (.*)$/ ]) {
|
||||
var regexp = ~/\W*(\w*) (.*)$/;
|
||||
if (regexp.match(s)) {
|
||||
var version = regexp.matched(2).split("-").shift();
|
||||
|
||||
@ -31,8 +30,6 @@ class CodeVersionInformation {
|
||||
|
||||
parts.push(regexp.matched(1));
|
||||
parts.push(version);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return parts;
|
||||
@ -123,6 +120,10 @@ class CodeVersionInformation {
|
||||
return final_versions;
|
||||
}
|
||||
|
||||
/**
|
||||
Create a new CodeVersionInformation object based on the provided
|
||||
Result set and, optionally, while ignoring the provided modules.
|
||||
**/
|
||||
public function new(results : Array<Result>, ?ignored_modules : Hash<Bool>) {
|
||||
var start_minimum_versions = new Hash<Array<String>>();
|
||||
var start_maximum_versions = new Hash<Array<String>>();
|
||||
|
@ -12,8 +12,8 @@ class FunctionTokenProcessor extends TokenProcessor {
|
||||
var tokens_parsed = 0;
|
||||
|
||||
//
|
||||
// haXe XML parsing is slow, as it uses a custom XML parser.
|
||||
// so I'll use a custom XML parser for this data.
|
||||
// haXe XML parsing is slow, as it uses a custom XML parser...
|
||||
// ..so I'll my own custom XML parser for this particular data.
|
||||
//
|
||||
/*var start = Date.now();
|
||||
var first_element = Xml.parse(s).firstElement();
|
||||
@ -38,6 +38,12 @@ class FunctionTokenProcessor extends TokenProcessor {
|
||||
var version_regexp = ~/from=\'([^\']*)\'/i;
|
||||
var token_regexp = ~/name=\'([^\']*)\'/i;
|
||||
|
||||
var version_clean_regexps = [
|
||||
function(s) { return ~/PECL /.replace(s, ""); },
|
||||
function(s) { return ~/\:/.replace(s, " "); },
|
||||
function(s) { return ~/\, /.replace(s, ","); }
|
||||
];
|
||||
|
||||
while (i < s_length) {
|
||||
var new_i = s.indexOf("<function", i);
|
||||
if (new_i != -1) {
|
||||
@ -48,8 +54,7 @@ class FunctionTokenProcessor extends TokenProcessor {
|
||||
if (version_regexp.match(tag) && token_regexp.match(tag)) {
|
||||
var version = version_regexp.matched(1);
|
||||
var token = token_regexp.matched(1);
|
||||
version = ~/PECL /.replace(version, "");
|
||||
version = ~/\:/.replace(version, " ");
|
||||
for (rf in version_clean_regexps) { version = rf(version); }
|
||||
|
||||
this.token_hash.set(token, new FunctionToken(token, version));
|
||||
tokens_parsed++;
|
||||
|
@ -78,16 +78,9 @@ class JavaScriptTarget {
|
||||
}
|
||||
|
||||
#if js
|
||||
static public function change_result_and_redraw(result_checkbox : Dynamic) {
|
||||
var index_id_search = ~/^result-enabled-([0-9]+)$/;
|
||||
if (index_id_search.match(result_checkbox.id)) {
|
||||
var index_id = Std.parseInt(index_id_search.matched(1));
|
||||
if (change_result(index_id, !result_checkbox.checked)) {
|
||||
display_version_information();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Display code version information.
|
||||
**/
|
||||
static public function display_version_information() {
|
||||
var version_info = new CodeVersionInformation(current_results, ignored_modules);
|
||||
|
||||
@ -97,6 +90,7 @@ class JavaScriptTarget {
|
||||
|
||||
output += "<form action=\"\" onsubmit=\"return false\">";
|
||||
|
||||
// module list
|
||||
var all_modules_hash = new Hash<Bool>();
|
||||
|
||||
for (module in minimum.keys()) { all_modules_hash.set(module, true); }
|
||||
@ -163,6 +157,7 @@ class JavaScriptTarget {
|
||||
|
||||
output += "</table>";
|
||||
|
||||
// maximum version info
|
||||
var maximum = version_info.final_versions.get("maximum");
|
||||
var printed_message = false;
|
||||
|
||||
@ -180,6 +175,7 @@ class JavaScriptTarget {
|
||||
output += "<p><strong>This code may not run!</strong></p>";
|
||||
}
|
||||
|
||||
// tokens list
|
||||
output += "<table cellspacing=\"0\" id=\"results-list\">";
|
||||
|
||||
output += "<tr><th>Token</th><th>Ignore?</th>";
|
||||
@ -258,6 +254,7 @@ class JavaScriptTarget {
|
||||
|
||||
output += "</form>";
|
||||
|
||||
// update the how-to-ignore information
|
||||
var permanent_ignore_div = js.Lib.document.getElementById("permanent-ignore");
|
||||
|
||||
if ((ignored_modules_array.length > 0) || (ignored_tokens.length > 0)) {
|
||||
@ -286,6 +283,9 @@ class JavaScriptTarget {
|
||||
js.Lib.document.getElementById('output').innerHTML = output;
|
||||
}
|
||||
|
||||
/**
|
||||
Analyze the provided code and display the results.
|
||||
**/
|
||||
static public function do_analysis(textarea) {
|
||||
show_only_modules = new Hash<Bool>();
|
||||
|
||||
@ -305,11 +305,30 @@ class JavaScriptTarget {
|
||||
}, 100);
|
||||
}
|
||||
|
||||
/**
|
||||
Toggle a token's visibility and redraw the page.
|
||||
**/
|
||||
static public function change_result_and_redraw(result_checkbox : Dynamic) {
|
||||
var index_id_search = ~/^result-enabled-([0-9]+)$/;
|
||||
if (index_id_search.match(result_checkbox.id)) {
|
||||
var index_id = Std.parseInt(index_id_search.matched(1));
|
||||
if (change_result(index_id, !result_checkbox.checked)) {
|
||||
display_version_information();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Toggle a module's visibiity and redraw the page.
|
||||
**/
|
||||
static public function toggle_module_and_redraw(module : String) {
|
||||
JavaScriptTarget.toggle_module(module);
|
||||
JavaScriptTarget.display_version_information();
|
||||
}
|
||||
|
||||
/**
|
||||
Toggle a module's enabled/disabed status and redraw the page.
|
||||
**/
|
||||
static public function toggle_ignore_module_and_redraw(module : String) {
|
||||
JavaScriptTarget.toggle_ignore_module(module);
|
||||
JavaScriptTarget.display_version_information();
|
||||
|
@ -27,6 +27,7 @@ class TestCodeVersionInformation extends haxe.unit.TestCase {
|
||||
Test breakdown_version_string()
|
||||
**/
|
||||
function test_breakdown_version_string() {
|
||||
assertEquals("[PHP, 4]", CodeVersionInformation.breakdown_php_version_string("PHP 4").toString());
|
||||
assertEquals("[PHP, 4]", CodeVersionInformation.breakdown_php_version_string(" PHP 4").toString());
|
||||
assertEquals("[PHP, 5.2.0]", CodeVersionInformation.breakdown_php_version_string("PHP 5 >= 5.2.0").toString());
|
||||
assertEquals("[xmlwriter, 2.0.4]", CodeVersionInformation.breakdown_php_version_string("xmlwriter 2.0.4").toString());
|
||||
|
Loading…
Reference in New Issue
Block a user