Skip to content

Commit

Permalink
Initial code commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cybersonic committed Jun 16, 2018
1 parent 1e6f7a3 commit 3a1672d
Show file tree
Hide file tree
Showing 15 changed files with 5,241 additions and 0 deletions.
95 changes: 95 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Lucee File Coverage Extension

This extension provides a debugging template that logs all the calls to script files as a user navigates your site. It then allows you to browse which files have been used and more importantly which have not

## 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

### 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


### Installing

First you need to build the project, simply go into the root and run:
```
ant
```

This will create a file in the `dist` folder called `filecoverage-extension-X.X.X.X.lex`. This extension is meant to deployed to a *web context* (versus a server context) as it installs the reporting application into your webroot in a folder called `/filecoverage` so you can access it as http://localhost/filecoverage.

1. Go to the Lucee web administrator - http://localhost/lucee/admin/web.cfm and log in
1. Click on `Applications` under *Extension*
1. Scroll to the bottom to where it says "Upload new extension (experimental)" and choose the `filecoverage-extension-X.X.X.X.lex` we created and click *Upload*
1. Since we need to use a database to store the captured data, instal the `H2` database
1. Create a datasource called `codecoverage` using the H2 Database Engine in Embedded Mode
1. Put a path in the path section (for example "db") and click save
1. Under *Debugging:Settings* click "Yes" to enable debugging.
1. Under *Debugging:Templates* enter a label such as "CodeCoverage" and select the "File Coverage" template type and click create
1. In the Datasource Name field enter 'codecoverage' and click submit ( you can also then limit to which IP ranges you want this debugging template to work with)

The site is now ready for testing. You just need to browse it. The next part is viewing the results.


### 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.


<!-- End with an example of getting some data out of the system or using it for a little demo
## Running the tests
Explain how to run the automated tests for this system
### Break down into end to end tests
Explain what these tests test and why
```
Give an example
```
### And coding style tests
Explain what these tests test and why
```
Give an example
```
-->
## Deployment

This extension should *NOT* be deployed on a live system. It's meant to be used as part of an investigation or your testing process. DO. NOT. RUN. ON. A. LIVE. SYSTEM.
You have been warned.


<!-- ## Contributing
Please read [CONTRIBUTING.md](https://gist.github.com/PurpleBooth/b24679402957c63ec426) for details on our code of conduct, and the process for submitting pull requests to us.
-->
## 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

* **Mark Drew** - *Initial work* - [cybersonic](https://github.com/cybersonic)

<!-- See also the list of [contributors](https://github.com/your/project/contributors) who participated in this project. -->

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
<!--
## Acknowledgments
* Hat tip to anyone whose code was used
* Inspiration
* etc
-->
3 changes: 3 additions & 0 deletions build.number
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#Build Number for ANT. Do not edit!
#Sat Jun 16 12:38:21 BST 2018
build.number=9
12 changes: 12 additions & 0 deletions build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
bundlename: filecoverage.extension
bundleversion: 0.0.1.
codename: filedoverage
camelname: FileCoverage
author: Mark Drew
category: Code Analysis
id: 57BD5ECF-8EB2-467C-B91ED1585B459BE8
label: File Coverage Analysis
luceeCoreVersion: 5.0.0.150
releaseType: web
description: This extension adds a debug template that you can use to log all the script files that are touched. This allows you to see which files don't have test coverage (for example) or files that should be safe to delete. It is very useful when dealing with unknown or legacy code.

84 changes: 84 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<project default="build" basedir="." name="FileCoverage-extension">
<description>
Build the FileCoverage Extension
</description>

<property name="build" location="build"/>
<property name="dist" location="dist"/>

<property name="src" location="src"/>
<property name="name" value="filecoverage-extension" />
<buildnumber file="build.number"/>
<property file="build.properties"/>

<target name="init">
<!-- Create the time stamp -->
<tstamp/>

<delete dir="${dist}"/>
<delete dir="${build}"/>

<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}/"/>
<mkdir dir="${build}/extension"/>



<tstamp>
<format property="NOW" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
</target>


<!--
<import file="build-compile.xml"/>
-->
<target name="makeManifest" depends="init" description="create the manifest file" >

<echo file="${build}/extension/META-INF/MANIFEST.MF">Manifest-Version: 1.0
Built-Date: ${NOW}
version: "${bundleversion}${build.number}"
id: "${id}"
name: "${label}"
lucee-core-version: "${luceeCoreVersion}
release-type: ${releaseType}
description: "${description}"
start-bundles: false
trial: false
</echo>


</target>


<target name="build" depends="makeManifest" description="generate the build" >

<!-- copy the logo -->
<copy todir="${build}/extension/META-INF">
<fileset dir="${src}/images">
<include name="logo.png"/>
</fileset>
</copy>

<copy todir="${build}/extension/applications">
<fileset dir="${src}/filecoverage">
<include name="**/*.*"/>
</fileset>
</copy>

<copy todir="${build}/extension/context">
<fileset dir="${src}/context">
<include name="**/*.*"/>
</fileset>
</copy>


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

</target>

</project>
3 changes: 3 additions & 0 deletions demo/Application.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
component {
this.name = "CodeCoverage";
}
7 changes: 7 additions & 0 deletions demo/Person.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
component accessors="true" {

property name="name";
property name="age";


}
3 changes: 3 additions & 0 deletions demo/index.cfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<cfscript>
Person = new Person(name="Mark", age=44);
</cfscript><cfoutput>Hello #Person.getName()# #Person.getAge()# #Person.getName()#</cfoutput>
118 changes: 118 additions & 0 deletions filecoverage/index.cfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<!DOCTYPE html>
<html>
<head>
<title>Code Coverage</title>

</head>
<body>
<cfparam name="url.dir" default="#expandPath('/')#">

<cfscript>
path = url.dir;
delimiter = Right(Path,1) EQ "/"? "" : "/";
files = DirectoryList(path,false,"name","*.cf*","Name");
directories = DirectoryList(path,false,"name","*","Name","dir");
output = [];
dircount = [];
for(file in files){
item = {
path: path & delimiter & file,
hitCount: getTotalHits(path & delimiter & file),
pathQuery: path & delimiter & file
};
output.append(item);
}
for(dir in directories){
dirPath = expandPath(path & delimiter & dir);
item = {
name: dir,
path: dirPath,
hitCount: getTotalHits(dirPath),
pathQuery: dirPath
};
dircount.append(item);
}
function getTotalHits(PathToFind){
var found = queryExecute(sql:"SELECT SUM(count) AS hits FROM FILEACCESS WHERE SRC LIKE '#PathToFind#%'", options:{datasource="codecoverage"});
if(!isNumeric(found.hits)){
return 0;
}
return found.hits;
}
</cfscript>
<div class="container">

<div class="row">
<a href="/codecoverage" class="btn btn-default">Back</a>
<table class="table table-striped">
<thead>
<tr>
<th>Hits</th>
<th>Name</th>
<th>#</th>
</tr>
</thead>
<tbody>


<cfloop array="#dircount#" item="directory">
<cfoutput>

<cfset FoundCSS = directory.hitCount? "bg-success" : "bg-danger">
<tr>
<td class="#FoundCSS#">#directory.hitCount#</td>
<td><a href="#CGI.SCRIPT_NAME#?dir=#directory.path#">#directory.name# (#directory.pathQuery#)</a></td>
<td><a href="info.cfm?dir=#directory.pathQuery#">Info</a></td>
</tr>
</cfoutput>
</cfloop>

<cfloop array="#output#" item="item">
<cfoutput> <tr>
<cfset FoundCSS = item.hitCount? "bg-success" : "bg-danger">
<td class="#FoundCSS#">#item.hitCount#</td>
<td>#item.path# (#item.pathQuery#)</td>
<td><a href="info.cfm?dir=#item.pathQuery#">Info</a></td>
</tr>
</cfoutput>
</cfloop>

</tbody>
</table>

</div>

</div>
<cfscript>
// found = queryExecute(sql:"SELECT * FROM FILEACCESS", options:{datasource="codecoverage"});
</cfscript>


<!--- <cfdump var="#queryExecute(sql:'SELECT * FROM FILEACCESS', options:{datasource='codecoverage'})#"> --->

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

</body>
</html>
29 changes: 29 additions & 0 deletions filecoverage/info.cfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<cfparam name="url.dir" default="#expandPath('/')#">
<cfscript>
found = queryExecute(sql:"SELECT * FROM FILEACCESS WHERE SRC LIKE '#url.dir#%'", options:{datasource="codecoverage"});
</cfscript>


<div class="container">
<div class="row">
<cfoutput><a href="index.cfm?dir=#ListFirst(url.dir, '$')#" class="btn btn-default">Back</a></cfoutput>
<cfdump var="#found#">

</div>
</div>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</body>
</html>
Loading

0 comments on commit 3a1672d

Please sign in to comment.