Skip to content

Commit

Permalink
Merge pull request #1 from cybersonic/develop
Browse files Browse the repository at this point in the history
Keeping master up to date
  • Loading branch information
cybersonic authored Jun 17, 2018
2 parents 3a1672d + c8548db commit d1623c1
Show file tree
Hide file tree
Showing 16 changed files with 444 additions and 293 deletions.
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: java
install: ant
script: ant build
deploy:
provider: releases
api_key:
secure: VCztWP2Y9QQfbhXZvB/4GQ5yNVBLhm6Wm8fchfoFSWlEHk/CE1EcUFe2lcZRnp9kQ17aYXYpE5igrGoC/xq6iwwx+TFsFkBDLAoOuudAD41uxY1x4Lb/hlW8ex+BpRuBadgAc83xr3bfR7pSn8/0Y7WW9w4+Tj2nuotydMlLDmC78Zho1AeDpTwRwPKCzHd/uz7B/VN7MgUgOHuvHVjLL9OKbCX1BBaZN/5MY2rk5cG8uVsHYISDaraADUGxfXeiFe2GmScWt2vuCHQ+MB46WokUwwOdDbBZgr9Z6rOF2PQMNSYmPLxSEvWNFk/5v0LCjYpHpvPrqzz4TsTZ+FbUjzNPQk1DGlTkhJKWJvWi4KsBiQqjPcjZFuC9oD7ht92fYjbTge+88Wdhr3T+lwx5Yvu4VnUrGTPbpWrhhf8PbMUKh1FYyXByByj/k0BJEw7Su0JHGOZyVqQmvkx8MPX9Grxw16ohFrawJo97kKw1k/kGSeXr5ns9rW/e/yzTqqLJr+bW0H47lr5r/zxSGu8V6emVGf0D6JgZuCU/cpiPrnmcUmBdVKXsxNi83IaIc6kV1xZQ7ewuRgGkt39kd068LiJD9kJMVMOnxvYTTQy/wdaKeUbzvu/5tkddcQZfY+T1yTxaHUXj7D7INoFvlIXNO5H0k0XVE/dFOHZpa4AtrR8=
file: dist/filecoverage-extension.lex
on:
repo: cybersonic/lucee-filecoverage-extension
branch: develop
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ This extension provides a debugging template that logs all the calls to script f
## Getting Started

(We are hoping this will go onto the lucee extension store in the future).
In the meantime, you can checkout the project and run


Check out the installation guide. At the moment this is the main way of installing it until we get this everything ready to be added to the Lucee Extension "store".

I would love to be able to actually add this to http://forgebox.io too.



### Prerequisites

- Apache Ant to build the project (it is running a simple build.xml file)
- Lucee 5.x and greater.
- Currently it is also using the H2 database extension. Which can be installed
- Lucee 5.x and greater. No ACF implementation yet.
- Currently it is also using the H2 database extension. Which can be installed fropm the Extension:Applications section of the admin.


### Installing
Expand All @@ -38,7 +44,13 @@ The site is now ready for testing. You just need to browse it. The next part is

### Reports

At the moment this is pretty rough and ready and you just need to go to http://localhost/filecoverage to view how which files are being used.
At the moment this is pretty rough and ready and you just need to go to http://localhost/filecoverage to view how many hits each file gets as well as some information on which functions/methods are used in a CFC.

![Listing of files and directories](src/images/list.jpg)

![Details about a CFC](src/images/info.jpg)




<!-- End with an example of getting some data out of the system or using it for a little demo
Expand Down Expand Up @@ -75,6 +87,7 @@ Please read [CONTRIBUTING.md](https://gist.github.com/PurpleBooth/b24679402957c6
-->
## Versioning


We use [SemVer](http://semver.org/) for versioning. <!-- For the versions available, see the [tags on this repository](https://github.com/your/project/tags). -->

## Authors
Expand Down
4 changes: 2 additions & 2 deletions build.number
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
#Sat Jun 16 12:38:21 BST 2018
build.number=9
#Sat Jun 16 13:10:23 BST 2018
build.number=11
10 changes: 7 additions & 3 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ trial: false
</copy>

<copy todir="${build}/extension/applications">
<fileset dir="${src}/filecoverage">
<fileset dir="filecoverage">
<include name="**/*.*"/>
</fileset>
</copy>
Expand All @@ -74,11 +74,15 @@ trial: false
</copy>


<!-- Zip everything -->
<!-- Zip everything with version-->
<zip destfile="${dist}/${name}-${bundleversion}${build.number}.lex">
<zipfileset dir="${build}/extension"/>
</zip>


<!-- Create the release file -->
<zip destfile="${dist}/${name}.lex">
<zipfileset dir="${build}/extension"/>
</zip>
</target>

</project>
14 changes: 14 additions & 0 deletions demo/Person.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,18 @@ component accessors="true" {
property name="age";


function uncalled(){

// Nothing here.
//Nothing
echo("THis method should not be called");
}

function called(){
privateCalled();
}

function privateCalled(){

}
}
2 changes: 2 additions & 0 deletions demo/index.cfm
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<cfscript>
Person = new Person(name="Mark", age=44);
Person.called();
</cfscript><cfoutput>Hello #Person.getName()# #Person.getAge()# #Person.getName()#</cfoutput>
11 changes: 11 additions & 0 deletions filecoverage/Application.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
component {
this.name = "FileCoverage_" & Hash(getCurrentTemplatePath());
this.datasource = "codecoverage";



function onRequestStart(targetPage){
request.basePath = contractPath(getDirectoryFromPath(getCurrentTemplatePath()));
}

}
189 changes: 189 additions & 0 deletions filecoverage/FCReporter.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
component {

variables.tablename = "lucee_filecoverage_extension";
variables.extensionfilter = "*.cf*";

//TODO: Add ignored foldders etc.

public any function getCoverageForDirectory(String path, boolean recurse=false){

var delimiter = Right(Path,1) EQ "/"? "" : "/";



var files = DirectoryList(path,recurse,"query",variables.extensionfilter,"Name");



var results = {
total: files.recordcount,
accessed: 0
}


loop query="files"{
//See if any of these have hits!
var hitsForThisScript = getTotalHits(directory & "/" & name);

if(hitsForThisScript){
results.accessed++;
}

}
return results;
}


public any function getReportForDirectory(String path, boolean recurse=false){


//Directories need to be calculated differently, as we get a roll up of all files accesed underneath them rather than an exact match.

var ret_files = [];
var ret_dirs = [];

var files = DirectoryList(path,recurse,"query",variables.extensionfilter,"name","all")

for(file in files){


file["hits"] = getTotalHits(file.directory & "/" & file.name);
ret_files.append(file);
}



var directories = DirectoryList(path,recurse, "query", "*","name", "dir");

for(dir in directories){

dir["hits"] = findTotalHits(dir.directory & "/" & dir.name);
ret_dirs.append(dir);
}



return {
files:ret_files,
directories:ret_dirs
}
}

function getInfoForFile(PathToFind){
var raw = queryExecute(sql:"SELECT * FROM #variables.tablename# WHERE FILEPATH = '#PathToFind#'");

var type = ListLast(PathToFind,".") EQ "cfc" ? "Component" : "Script";

var methods = {};
//Get metadata
if(type EQ "Component"){

var dotPath = getDotPathFromPath(PathToFind);
var componentMetaData = getComponentMetadata(dotPath);

for(func in componentMetaData.functions){
methods[func.name] = 0;
}

raw.each(function(item, index, query){

if(Len(Trim(item.method))){
methods[item.method] = methods[item.method]+item.count;
}

});

}





var count = raw.reduce(function(hits=0,cols,index,query){
return hits + cols.count;
});



return {
raw: raw,
summary: {
name: getFileFromPath(PathToFind),
directory: getDirectoryFromPath(PathToFind),
type: type,
methods: methods,
hits: count,
source: FileRead(PathToFind)
}
}
}


function getDotPathFromPath(PathToFind){
var dotPath = contractPath(PathToFind);
dotPath = listDeleteAt(dotPath, ListLen(dotPath, "."),".");
dotPath = listTrim(dotPath,"/");
dotPath = Replace(dotPath, "/", ".", "all");

return dotPath;
}

//Exact match for a file search
function getTotalHits(PathToFind){

var found = queryExecute(sql:"SELECT SUM(count) AS hits FROM #variables.tablename# WHERE FILEPATH = '#PathToFind#'");


if(!isNumeric(found.hits)){
return 0;
}
return found.hits;
}

//Finds all the matches of path% rather than an exact match
function findTotalHits(PathToFind){

var found = queryExecute(sql:"SELECT SUM(count) AS hits FROM #variables.tablename# WHERE FILEPATH LIKE '#PathToFind#%'");

if(!isNumeric(found.hits)){
return 0;
}
return found.hits;
}

function deleteCoverage(){
var found = queryExecute(sql:"DELETE FROM #variables.tablename#");
writeDump(getAll());

}

function createCoverageTable(){
var createDBTable = queryExecute(
sql:"DROP TABLE IF EXISTS PUBLIC.#variables.tablename#"
);

var createDBTable = queryExecute(
sql:"CREATE CACHED TABLE IF NOT EXISTS PUBLIC.#variables.tablename#(
ID BIGINT auto_increment,
SRC VARCHAR(500),
FILEPATH VARCHAR(500),
METHOD VARCHAR(255),
COUNT INT,
MIN INT,
MAX INT,
AVG INT,
APP INT,
LOAD INT,
QUERY INT,
TOTAL INT,
HASH VARCHAR(100)
)
"
);
}

function getAll(){
return queryExecute(sql:"SELECT * FROM #variables.tablename#");
}

}
Loading

0 comments on commit d1623c1

Please sign in to comment.