2002-09-06 20:09:30 +00:00
#!/usr/bin/perl
2002-09-25 14:21:55 +00:00
$| = 1 ;
2002-09-06 20:09:30 +00:00
use CGI qw( :standard escapeHTML ) ;
use CGI::Carp qw( fatalsToBrowser ) ;
2002-09-25 19:32:39 +00:00
use Time::localtime ;
2002-10-04 16:41:15 +00:00
use PMD::Project ;
2002-09-06 20:09:30 +00:00
$ query = new CGI ( ) ;
print $ query - > header ( ) ;
sub nopage () {
print $ query - > p ( "How'd we get here?" ) ;
}
2002-09-25 14:21:55 +00:00
sub default () {
2003-01-31 15:36:00 +00:00
print start_html ( "Run PMD on your Sourceforge project" ) ;
2002-09-25 19:32:39 +00:00
2002-09-26 20:45:49 +00:00
print "<center><a href=\"http://pmd.sourceforge.net/\"><img src=\"http://sourceforge.net/sflogo.php?group_id=56262&type=5\" alt=\"Project Ultra*Log @ DARPA\" border=\"0\" /></a></center>" ;
2002-09-25 19:32:39 +00:00
print h3 ( "<center>PMD-WEB</center>" ) ;
2003-03-05 16:20:48 +00:00
print "PMD is a Java source code analysis tool - it checks your code for unused fields, empty try/catch/finally/if/while blocks, unused method parameters, and stuff like that. There's much more info <a href=\"http://pmd.sf.net/\">here</a>.<p>This table contains the results of running PMD's <a href=\"http://pmd.sourceforge.net/rules/unusedcode.html\">unused code ruleset</a> against a bunch of Sourceforge projects. The JavaNCSS column contains the lines of code analyzed as reported by the excellent <a href=\"http://www.kclee.com/clemens/java/javancss/\">JavaNCSS</a> utility." ;
2003-03-06 02:58:34 +00:00
print "<p>Comments? Questions? Please post them <a href=\"http://sourceforge.net/forum/forum.php?forum_id=188192\">here</a>.<br>" ;
2003-02-28 03:46:20 +00:00
open ( FILE , "lastruntime.txt" ) ;
my $ lastruntime = <FILE> ;
close ( FILE ) ;
print br ( ) ;
2003-03-06 02:58:34 +00:00
print "This report is run 10 minutes past the hour at midnight, 3, 6, 9, 12, 15, 18, and 21 hours U.S. Pacific Standard Time.<br>The last run finished at " , $ lastruntime , ". Right now it's " , ctime ( ) , "." ;
print "<p><b>1/31/03: The jakarta.apache.org and xml.apache.org projects have been moved <a href=\"http://cvs.apache.org/~tcopeland/pmdweb/\">here</a></b>" ;
print br ( ) ;
2002-11-27 16:52:35 +00:00
print hr ( ) ;
2002-09-25 19:32:39 +00:00
2003-02-28 03:46:20 +00:00
if ( param ( "unixname" ) ) {
my $ project = PMD::Project - > new ( "Sourceforge" , param ( "title" ) , param ( "unixname" ) , param ( "moduledirectory" ) , param ( "srcdir" ) ) ;
2002-10-04 16:41:15 +00:00
addProject ( $ project ) ;
2002-10-04 17:52:56 +00:00
print p ( ) , b ( "Added " ) , b ( $ project - > getTitle ( ) ) , b ( " to the schedule" ) , p ( ) ;
2002-09-25 14:21:55 +00:00
}
2002-09-26 20:45:49 +00:00
2002-09-27 01:29:55 +00:00
print loadProjectList ( ) ;
2002-09-25 19:32:39 +00:00
print hr ( ) ;
2003-01-31 15:36:00 +00:00
print "Want to run PMD on your Java Sourceforge project? Fill in the blanks and hit go:" ;
2002-09-06 20:09:30 +00:00
print start_form ( ) ;
2002-09-27 01:29:55 +00:00
print "Project title (i.e., PMD): " , textfield ( - name = > 'title' , - default = > '' , - override = > 1 ) ;
print br ( ) , "Project's Unix name (i.e., pmd): " , textfield ( - name = > 'unixname' , - default = > '' , - override = > 1 ) ;
print br ( ) , "Module directory (i.e., pmd-dcpd): " , textfield ( - name = > 'moduledirectory' , - default = > '' , - override = > 1 ) ;
2002-10-24 15:02:16 +00:00
print br ( ) , "Source directory (including module directory, i.e., pmd-dcpd/src): " , textfield ( - name = > 'srcdir' , - default = > '' , - override = > 1 ) ;
2002-09-06 20:09:30 +00:00
my $ cachebuster = `date` ;
print $ query - > hidden ( - name = > 'cachebuster' , - value = > $ { cachebuster } ) ;
2002-09-27 01:29:55 +00:00
print br ( ) , submit ( - value = > 'Go' ) ;
2002-09-06 20:09:30 +00:00
print end_form ( ) ;
2002-09-26 20:21:20 +00:00
print hr ( ) ;
2002-09-27 01:29:55 +00:00
}
2002-09-25 14:21:55 +00:00
sub loadProjectList () {
2002-11-20 20:03:51 +00:00
my @ projects = ( ) ;
2002-09-25 14:21:55 +00:00
opendir ( DIR , "jobs/" ) or return "can't open jobs directory!" ;
while ( defined ( $ file = readdir ( DIR ) ) ) {
if ( $ file =~ /txt/ ) {
open ( FILE , "jobs/${file}" ) ;
my $ jobdata = <FILE> ;
2002-10-04 17:52:56 +00:00
close ( FILE ) ;
2002-10-09 18:59:38 +00:00
my $ project = PMD::Project - > new ( $ jobdata ) ;
2002-11-20 20:03:51 +00:00
push ( @ projects , $ project ) ;
}
}
2002-11-27 16:52:35 +00:00
@ newprojects = sort { $ b - > getLocation ( ) cmp $ a - > getLocation ( ) || $ a - > getTitle ( ) cmp $ b - > getTitle ( ) } @ projects ;
2002-11-20 20:03:51 +00:00
2003-07-12 01:58:04 +00:00
my $ result = "<table align=center><tr><th>Project</th><th></th><th>Home page</th><th>NCSS</th><th>Problems</th><th>Percentage Unused Code</th></tr>" ;
2002-11-20 20:03:51 +00:00
foreach $ project ( @ newprojects ) {
2002-11-27 16:52:35 +00:00
my $ jobLink = $ project - > getTitle ( ) ;
2002-11-20 20:03:51 +00:00
if ( - e $ project - > getRptFile ( ) ) {
2002-11-27 16:52:35 +00:00
$ jobLink = "<a href=\"@{[$project->getRptURL]}\">@{[$project->getTitle()]}</a>" ;
}
$ result = "${result}<tr><td>${jobLink}</td><td></td><td>@{[$project->getHomePage()]}</td>" ;
2003-03-05 16:20:48 +00:00
$ result = "${result}<td>@{[$project->getNCSS()]}</td>" ;
2003-07-12 01:58:04 +00:00
my $ ncss = $ project - > getNCSS ( ) ;
if ( $ ncss == 0 ) {
$ ncss = 1 ;
}
my $ rounded = ( int ( ( $ project - > getLines ( ) /$ncss)*10000))/ 100 ;
2002-11-27 16:52:35 +00:00
my $ color = "red" ;
2003-07-12 01:58:04 +00:00
if ( $ rounded < .2 ) {
2002-12-09 15:41:11 +00:00
$ color = "#00ff00" ;
2003-07-12 01:58:04 +00:00
} elsif ( $ rounded < .8 ) {
2002-11-27 16:52:35 +00:00
$ color = "yellow" ;
2002-09-25 14:21:55 +00:00
}
2003-07-12 01:58:04 +00:00
$ rounded = sprintf ( "%0.2f" , $ rounded ) ;
if ( $ project - > getNCSS ( ) == "TBD" ) {
$ rounded = "N/A" ;
$ color = "white" ;
}
$ result = "${result}<td align=center>@{[$project->getLines()]}</td><td bgcolor=$color align=center>$rounded</td></tr>" ;
2002-09-25 14:21:55 +00:00
}
$ result = "${result}</table>" ;
return $ result ;
}
sub addProject () {
2002-10-04 16:41:15 +00:00
my ( $ project ) = @ _ ;
2002-10-09 18:59:38 +00:00
my $ cmd = "echo \"@{[$project->getString()]}\" > @{[$project->getJobsFile()]}" ;
2002-11-12 16:45:46 +00:00
eval {
# for some reason this succeeds, but the CGI script fails. Very odd.
`${cmd}` ;
}
2002-09-06 20:09:30 +00:00
}
$ page = param ( "state" ) || "default" ;
% states = (
2002-09-25 14:21:55 +00:00
'default' = > \ & default
2002-09-06 20:09:30 +00:00
) ;
if ( $ states { $ page } ) {
$ states { $ page } - > ( ) ;
} else {
nopage ( ) ;
}
print $ query - > end_html ( ) ;