FlexPMD Violations Viewer - how to view results directly - actionscript-3

So I started using FlexPMD for static code analysis, and I want to add it to my team's build process. I have it running nicely from a shell script, and can view the results by clicking a button and uploading the desired (pmd.xml) output file in the Violations Viewer that comes with it (note there is also one online here: http://opensource.adobe.com/svn/opensource/flexpmd/bin/flex-pmd-violations-viewer.html).
But I'd like to view the results directly without having to take the extra step of clicking the upload button. I imagine there is some black magic URL parameter that works, but (if so) what is it? This site:
http://blogs.adobe.com/xagnetti/2009/09/load_pmd_results_directly_in_t.html
mentions referencing pmd.xml with a "report" URL param, like so:
http://opensource.adobe.com/svn/opensource/flexpmd/bin/flex-pmd-violations-viewer.html?report=path/to/my/pmd.xml
but it's not working for me. Has anyone encountered this problem and triumphed, by chance?
EDIT: More info...
The latter (opensource.adobe.com...) webpage has the following JavaScript:
function getReport()
{
if ( window.location.href.indexOf('=') == -1 )
{
return "";
}
var hashes = window.location.href.slice(window.location.href.indexOf('=') + 1);
return hashes;
}
var report = getReport();
which it passes into flashvars. Perhaps the format with which I'm passing pmd.xml is incorrect?

Okay, figured it out. The version of the violations viewer that ships with the open source FlexPMD does not allow for automatic viewing of reports (the HTML wrapper doesn't pass in the report filepath, and the SWF doesn't take it in). The solution that worked for me was to download the files from the online violations viewer here:
http://opensource.adobe.com/svn/opensource/flexpmd/bin/flex-pmd-violations-viewer.html?report=path/to/my/pmd.xml
by using your browser to just save the webpage, and then curl to save the SWF file (directly trying to save from the browser will not work - appears to redirect to a null address) to like so:
curl -O http://opensource.adobe.com/svn/opensource/flexpmd/bin/flex-pmd-violations-viewer-1.1.swf
and place in the same directory as the violations viewer html file you downloaded. Then you can read your reports automatically! Here is an example (absolute filepath on Mac):
file:///path/to/your/violations-viewer/ViolationsViewer.html?report=/Users/joverton/some/project/path/bin-debug/pmd_reports/pmd.xml

Related

Firefox Addon : parse/save loaded jsons as HAR or text file

I'm trying out to build my first firefox addon, to solve a problem that I have at work :
I'm trying to automate a part of my daily work on a website I'm using (not developping). I have to crawl several lists on the website, dig an item in the list, to check some values, and do it again and again ...
Im used to developping in Powershell and python, not with a web browser. I have limited rights on the machine I'm working on. The only solution I can easily deploy is a firefox addon on a firefox portable. I'd like to use this to catch the json answers of the website (all of them), parse the answers for some values, and automate some kind of popup "Hey, This item in the list is between 90 and 100 !"
The network console allows me to see the jsons, and I know how to parse it well (I'm actually using a powershell script for this, but I can't connect it to the network console AFAIK)
I found a way to trigger the work at the right time :
function logJson(requestDetails) {
console.log("Chargement : " + requestDetails.url);
}
browser.webRequest.onCompleted.addListener(
logRequests,
{urls: ["*://*.crappywebsi.te/*"],
types: ["xmlhttprequest"]
}
);
This code logs the url at the right moment (every time a json is loaded)
Is it possible to catch the json on the fly, to parse it, look for specific values in a path, calculate something, and popup the result ?
Or just save the json somewhere ?
How ?
I dont want to add a button on the webpage. I want a signal that some values are right. a popup or console log is an good solution for me.
Thanks for your help !

Why does my file download link seem to work, but is unable to find the file?

I added this HTML to a page that I render via a REST call:
StringBuilder builder = new StringBuilder();
. . .
builder.Append("<p></p>");
builder.Append("<a href=\"/App_Data/MinimalSpreadsheetLight.xlsx\" download>");
builder.Append("<p></p>");
. . .
return builder.ToString();
My ASP.NET Web API project has a folder named "App_Data" which does contain a file named "MinimalSpreadsheetLight.xlsx"
The download link is indeed rendered on the page, and clicking it does appear, at first, to download the file (it has the Excel icon, and it bears the file name), but beneath that it says "Failed - No file":
Is the problem with my HTML, or the path I'm using, or file permissions, or what?
I've only tested this with Chrome, so far, BTW. IOW, it's not an IE issue.
UPDATE
I tried it with a leading squiggly, too:
builder.Append("<a href=\"~/App_Data/MinimalSpreadsheetLight.xlsx\" download=\"Spreadsheet file\">");
...yet, alas, to no avail.
UPDATE 2
I changed the pertinent line of HTML to this:
builder.Append("<a href=\"App_Data/MinimalSpreadsheetLight.xlsx\" download=\"Minimal Spreadsheet file\">");
...and it displays in the source like so (with some context):
<p>(Invoice Count excludes credits and re-delivery invoices)</p><p></p><p></p><a href="App_Data/MinimalSpreadsheetLight.xlsx" download="Minimal Spreadsheet file">
...but the link does not appear at all.
UPDATE 3
I was misled by this reference, which showed no text being added; I changed the code to this:
builder.Append("Spreadsheet file");
...(adding "Spreadsheet file" and closing out the anchor tag), and now the link appears; however, I still get the "Failed - No file" msg, and 2-clicking the "downloaded file" does nothing.
UPDATE 4
I tried two other permutations of what's seen in Update 3, namely with the forward whack reintroduced prior to "App_Data":
builder.Append("Spreadsheet file");
...and with both the squiggly prepended and the forward whack:
builder.Append("Spreadsheet file");
...but the results are the same in any of these permutations ("Failed - no file").
UPDATE 5
I also tried it without the "App_Data" at all, on the off change that is not needed:
builder.Append("Spreadsheet file");
...but the same "Failed - No file" is the result of that attempt, too.
UPDATE 6
Okay, so I tried this, too (single quotes):
builder.Append("<a href='/App_Data/MinimalSpreadsheetLight.xlsx' download='Minimal Spreadsheet file'>Spreadsheet file</a>");
...but no change. The file is there:
...so why is it not seen or accessible?
UPDATE 7
This:
string fullPath = HttpContext.Server.MapPath("~/App_Data/MinimalSpreadsheetLight.xlsx");
... (which I got from here) fails to compile with, "An object reference is required for the non-static field, method, or property 'System.Web.HttpContext.Server.get'
2-clicking the err msg highlights just "Server"
UPDATE 8
This (which I got from the same place as what I tried in Update 7):
string justDataDir = AppDomain.CurrentDomain.GetData("DataDirectory").ToString();
string url2 = string.Format("Spreadsheet file</button>", justDataDir);
builder.Append(url2);
...does nothing; clicking the link doesn't even give me a fake/failed download now...
justDataDir is:
C:\Projects\ProActWebReports\ProActWebReports\App_Data
url2 is:
Spreadsheet file</button>
UPDATE 9
I noticed on further fine-tooth-combing that url2 had a forward whack in it; I changed it so that all the whacks were back, but it made no difference to Update 8's results: clicking the link does nothing whatsoever.
If somebody solves this, it will definitely get bountified after the fact.
UPDATE 10
Maybe what I really need to do is, instead of the simple html, add some jQuery that will download the file. But the question is, can jQuery access the App_Data folder any better than raw/simple html can?
The app_data folder is used by iis and asp.net as a private area in which to put database files which can only be accessed by code running on the server.
If you try to access the folder directly via your browser you will get a permissions error.
In order to make the files available for download, move them the a folder under 'Content' (if you have an mvc site) and ensure that your web.config allows the .xlsx exention to be downloaded.
It may depend on what version of iis you are using.
Downloading Docx from IE - Setting MIME Types in IIS

AS3 flash.net.FileReferenceList.browse() accepts an array of FileFilter objects but seems Mac OS is using only the first element

I have a file upload component written in ActionScript 3. The component is using the FileReferenceList.browse() to let the user select the files to upload. This method accepts an array of FileFilter objects to narrow down the selectable file types.
Until this time I passed only one FileFilter element in the array - if I passed any. This worked well for years without any problem. But recently I ran into a situation when I thought I understand why this method takes an array of FileFilters. Probably I was wrong...
I have a service which designed (and used) to present visual material mainly (images), but it can deal with non-visual files too like .xls, .doc, .zip, etc. This means in practice that my admin will upload almost only images (99%) to this service BUT sometimes (s)he will upload 1-2 .xls, .doc or .zip, etc.
So from this point I didn't want to really block files outside the (image) filter. Just tried to "show" my admin user that the preferred files are images here, but at the end of the day (s)he must be able to upload any file type.
So, I did this:
var fileReferenceList : FileReferenceList = new FileReferenceList();
var imgFilefilter : FileFilter = new FileFilter("Images", "*.jpg;*.jpeg;*.gif;*.png");
var allFilesFilter : FileFilter = new FileFilter("All files", "*");
fileReferenceList.browse([imgFileFilter, allFilesFilter]);
This worked well - on Windows. When the file browser window comes up my user sees the image files only. But (s)he can switch to "all files" view and upload other files too.
But now it turned out my Mac users are screwed this way... The file browser window doesn't offer the possibility to switch to "All files" view, so they can not upload non-image files :-) arghhhh!
I'm wondering what could be the best solution for the problem I tried to describe above? A trivial solution could be that for Mac users I skip the FileFilter stuff entirely. But it is not the way I would prefer... OR did I missed something? Is it possible to somehow "convince" Mac file browser window to offer the possibility let my admin choose between the filters like Win file selector does?

How do I insert HTML to a onenote page using VBA

Background
I use Onenote at work like a scrapbook, keeping track of assigned tasks and my progress through those tasks. Tasks are assigned via an automated email (outlook) typically these tasks involve manually reading web pages and filling in other webpages with results.
So far I've used the email arrival to trigger a VBA script which use uses data in the email to save the "requirements.html" page and the "ingredients.html" page locally. I then use python to parse and do some initial verification on the ingredients.html. This results in an augmented "requirements.html" containg colour coded status of parts.
my question
I've pretty much cut'n'pasted this code and managed to add a new page to section X of notebook Y (where x and y are strings passed to the function) or creating a new section by copying section.one file into the notebook folder DEST = "C:\Documents and Settings\Me\My Documents\OneNote Notebooks\Tasks\" + rqst_section + ".one"
while the code adds plain text to the page adding raw html source code in place of the plain text results in a object error when line
oneNote.UpdatePageContent doc.XML
is executed.
Has anyone managed to get the same result using VBA as this manual sequence,
select all text in browser window and copy 'n' paste it into a page in onenote.
I was getting a "UpdatePageContent" in "IApplication" failed error message, found out I had a Form Feed (chr(12) or vbFormFeed) character in a textfile I was trying to insert text into a page. Stripped that out and everything else seemed to work fine. Run the offending data through a hex editor, or strip it down little-by-little until you find the problem area.
Hope this helps.

Save the console.log in Chrome to a file

Does anyone know of a way to save the console.log output in Chrome to a file? Or how to copy the text out of the console?
Say you are running a few hours of functional tests and you've got thousands of lines of console.log output in Chrome. How do you save it or export it?
Good news
Chrome dev tools now allows you to save the console output to a file natively
Open the console
Right-click
Select "save as.."
Chrome Developer instructions here.
I needed to do the same thing and this is the solution I found:
Enable logging from the command line using the flags:
--enable-logging --v=1
This logs everything Chrome does internally, but it also logs all the console.log() messages as well. The log file is called chrome_debug.log and is located in the User Data Directory which can be overridden by supplying --user-data-dir=PATH (more info here).
Filter the log file you get for lines with CONSOLE(\d+).
Note that console logs do not appear with --incognito.
I have found a great and easy way for this.
In the console - right click on the console logged object
Click on 'Store as global variable'
See the name of the new variable - e.g. it is variableName1
Type in the console: JSON.stringify(variableName1)
Copy the variable string content: e.g. {"a":1,"b":2,"c":3}
Go to some JSON online editor:
e.g. https://jsoneditoronline.org/
There is an open-source javascript plugin that does just that, but for any browser - debugout.js
Debugout.js records and save console.logs so your application can access them. Full disclosure, I wrote it. It formats different types appropriately, can handle nested objects and arrays, and can optionally put a timestamp next to each log. You can also toggle live-logging in one place, and without having to remove all your logging statements.
For better log file (without the Chrome-debug nonsense) use:
--enable-logging --log-level=0
instead of
--v=1 which is just too much info.
It will still provide the errors and warnings like you would typically see in the Chrome console.
update May 18, 2020: Actually, I think this is no longer true. I couldn't find the console messages within whatever this logging level is.
This may or may not be helpful but on Windows you can read the console log using Event Tracing for Windows
http://msdn.microsoft.com/en-us/library/ms751538.aspx
Our integration tests are run in .NET so I use this method to add the console log to our test output. I've made a sample console project to demonstrate here: https://github.com/jkells/chrome-trace
--enable-logging --v=1 doesn't seem to work on the latest version of Chrome.
For Google Chrome Version 84.0.4147.105 and higher,
just right click and click 'Save as' and 'Save'
then, txt file will be saved
A lot of good answers but why not just use JSON.stringify(your_variable) ? Then take the contents via copy and paste (remove outer quotes). I posted this same answer also at: How to save the output of a console.log(object) to a file?
There is another open-source tool which allows you to save all console.log output in a file on your server - JS LogFlush (plug!).
JS LogFlush is an integrated JavaScript logging solution which include:
cross-browser UI-less replacement of console.log - on client side.
log storage system - on server side.
Demo
If you're running an Apache server on your localhost (don't do this on a production server), you can also post the results to a script instead of writing it to console.
So instead of console.log, you can write:
JSONP('http://localhost/save.php', {fn: 'filename.txt', data: json});
Then save.php can do this
<?php
$fn = $_REQUEST['fn'];
$data = $_REQUEST['data'];
file_put_contents("path/$fn", $data);
Right-click directly on the logged value you want to copy
In the right-click menu, select "Store as global variable"
You'll see the value saved as something like "temp1" on the next line in the console
In the console, type copy(temp1) and hit return (replace temp1 with the variable name from the previous step). Now the logged value is copied to your clipboard.
Paste the values to wherever you want
This is especially good as an approach if you don't want to mess with changing flags/settings in Chrome and don't want to deal with JSON stringifying and parsing etc.
Update: I just found this explanation of what I suggested with images that's easier to follow https://scottwhittaker.net/chrome-devtools/2016/02/29/chrome-devtools-copy-object.html
These days it's very easy - right click any item displayed in the console log and select save as and save the whole log output to a file on your computer.
On Linux (at least) you can set CHROME_LOG_FILE in the environment to have chrome write a log of the Console activity to the named file each time it runs. The log is overwritten every time chrome starts. This way, if you have an automated session that runs chrome, you don't have a to change the way chrome is started, and the log is there after the session ends.
export CHROME_LOG_FILE=chrome.log
the other solutions in this thread weren't working on my mac. Here's a logger that saves a string representation intermittently using ajax. use it with console.save instead of console.log
var logFileString="";
var maxLogLength=1024*128;
console.save=function(){
var logArgs={};
for(var i=0; i<arguments.length; i++) logArgs['arg'+i]=arguments[i];
console.log(logArgs);
// keep a string representation of every log
logFileString+=JSON.stringify(logArgs,null,2)+'\n';
// save the string representation when it gets big
if(logFileString.length>maxLogLength){
// send a copy in case race conditions change it mid-save
saveLog(logFileString);
logFileString="";
}
};
depending on what you need, you can save that string or just console.log it and copy and paste. here's an ajax for you in case you want to save it:
function saveLog(data){
// do some ajax stuff with data.
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function(){
if (this.readyState == 4 && this.status == 200) {}
}
xhttp.open("POST", 'saveLog.php', true);
xhttp.send(data);
}
the saveLog.php should append the data to a log file somewhere. I didn't need that part so I'm not including it here. :)
https://www.google.com/search?q=php+append+to+log
This answer might seem specifically related, but specifically for Network Log, you can visit the following link.
The reason I've post this answer is because in my case, the console.log printed a long truncated text so I couldn't get the value from the console. I solved by getting the api response I was printing directly from the network log.
chrome://net-export/
There you may see a similar windows to this, just press the Start Logging to Disk button and that's it:
Create a batch file using below command and save it as ChromeDebug.bat in your desktop.
start chrome --enable-logging --v=1
Close all other Chrome tabs and windows.
Double click ChromeDebug.bat file which will open Chrome and a command prompt with Chrome icon in taskbar.
All the web application logs will be stored in below path.
Run the below path in Run command to open chrome log file
%LocalAppData%\Google\Chrome\User Data\chrome_debug.log