Skip to content

Commit

Permalink
sp-5: Provide a publicly available Groovydoc
Browse files Browse the repository at this point in the history
Cosmetics
  • Loading branch information
evgeny-goldin committed Jun 2, 2012
1 parent 0b0483d commit cae0de2
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 10 deletions.
1 change: 1 addition & 0 deletions build.gradle
Expand Up @@ -2,6 +2,7 @@ apply plugin: 'groovy'
apply plugin: 'maven'
apply plugin: 'idea'
apply plugin: 'about'
apply from: 'file:groovydoc.gradle'


defaultTasks 'clean', 'codenarc', 'build', 'about', 'install'
Expand Down
34 changes: 34 additions & 0 deletions groovydoc.gradle
@@ -0,0 +1,34 @@
import java.text.SimpleDateFormat

/**
* http://gradle.org/docs/current/dsl/org.gradle.api.tasks.javadoc.Groovydoc.html
*/

def d = new Date()
def time = new SimpleDateFormat( "HH:mm '(GMT'Z')'" ).format( d )
def date = new SimpleDateFormat( 'MMMM dd, yyyy' ).format( d )

groovydoc {
use = true
groovyClasspath = configurations.compile // http://issues.gradle.org/browse/GRADLE-1391
destinationDir = new File(( System.getProperty( 'groovydocDir' ) ?: project.buildDir.path + '/groovydoc' ),
( project.version.contains( '-SNAPSHOT' ) ? '' : project.version ))
header = '<a href="http://evgeny-goldin.com/wiki/Spock-extensions">evgeny-goldin.com/wiki/Spock-extensions</a>'
footer = '<a href="http://evgeny-goldin.com/">Evgeny Goldin</a>. GrovyDoc was generated at ' + "$time on $date." + """
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-7925869-2']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
"""
link 'http://download.oracle.com/javase/6/docs/api/', 'java.'
link 'http://evgeny-goldin.org/javadoc/spock-core/', 'spock.', 'org.spockframework'
link 'http://groovy.codehaus.org/api/', 'groovy.', 'org.codehaus.groovy.'
}
Expand Up @@ -2,8 +2,9 @@ package com.github.goldin.spock.extensions.profiler

import org.spockframework.runtime.model.NodeInfo


/**
*
* Sortable {@link NodeInfo} container.
*/
class NodeData implements Comparable<NodeData>
{
Expand Down
Expand Up @@ -10,35 +10,48 @@ import org.spockframework.runtime.model.SpecInfo
import java.util.concurrent.ConcurrentLinkedQueue
import org.spockframework.runtime.model.ErrorInfo


/**
* Global extension profiling features execution time.
*/
class ProfilerExtension implements IGlobalExtension
{
private final Collection<NodeData> data = new ConcurrentLinkedQueue<NodeData>()

/**
* Writes {@link #data} to the file.
*/
private void writeFile ()
{
final padSize = data*.description()*.size().max()

new File( 'profiler.txt' ).write(
data.sort().
collect { "${ it.description().padRight( padSize ) } : ${ it.executionTime } ms" }.
join( '\n' ), 'UTF-8' )
}


@Requires({ specInfo })
void visitSpec ( SpecInfo specInfo )
{
/**
* Feature interceptors updating {@link #data} with execution time.
*/
specInfo.features*.addInterceptor({
IMethodInvocation invocation ->

final long t = System.currentTimeMillis()

invocation.proceed()

data.add( new NodeData( method : invocation.feature,
executionTime : System.currentTimeMillis() - t ))
} as IMethodInterceptor )

final writeFile = {
final padSize = data*.description()*.size().max()

new File( 'profiler.txt' ).write(
data.sort().
collect { "${ it.description().padRight( padSize ) } : ${ it.executionTime } ms" }.
join( '\n' ), 'UTF-8' )
}

/**
* Spec listener writing the {@link #data} to the file.
*/
specInfo.addListener( new AbstractRunListener(){

@Override
Expand Down

0 comments on commit cae0de2

Please sign in to comment.