Skip to content
Permalink
Browse files
[JENKINS-31221] Resolved issue - Implement access to comments count
  • Loading branch information
Jim committed Oct 29, 2015
1 parent a4c8ffc commit 0d502be2181b8bac381d0fef6d771a04f1d469dc
Showing 12 changed files with 100 additions and 31 deletions.
@@ -74,7 +74,7 @@ protected Object readResolve() {

for(Language language : report.getLanguages()){
languages.add(new SloccountLanguageStatistics(language.getName(),
language.getLineCount(), language.getFileCount()));
language.getLineCount(), language.getFileCount(), language.getCommentCount()));
}

statistics = new SloccountReportStatistics(languages);
@@ -17,13 +17,14 @@ public class File implements Countable, Serializable {
/** The module. */
private final String module;

private final int lineCount;
private final int lineCount, commentCount;

public File(String name, String language, String module, int lineCount){
public File(String name, String language, String module, int lineCount, int commentCount){
this.name = name;
this.language = language;
this.module = module;
this.lineCount = lineCount;
this.commentCount = commentCount;
}

public int getLineCount() {
@@ -34,6 +35,14 @@ public String getLineCountString() {
return StringUtil.grouping(getLineCount());
}

public int getCommentCount() {
return this.commentCount;
}

public String getCommentCountString() {
return StringUtil.grouping(getCommentCount());
}

public String getName() {
return this.name;
}
@@ -17,6 +17,7 @@ public abstract class FileContainer implements Countable, Serializable {

private Map<String, File> files = new LinkedHashMap<String, File>();
private int lineCount = 0;
private int commentCount = 0;

public File getFile(String name){
return this.files.get(name);
@@ -37,6 +38,7 @@ public String getFileCountString() {
public void addFile(File file){
this.files.put(file.getName(), file);
this.lineCount += file.getLineCount();
this.commentCount += file.getCommentCount();
}

public int getLineCount(){
@@ -46,4 +48,12 @@ public int getLineCount(){
public String getLineCountString() {
return StringUtil.grouping(getLineCount());
}

public int getCommentCount(){
return this.commentCount;
}

public String getCommentCountString() {
return StringUtil.grouping(getCommentCount());
}
}
@@ -23,6 +23,9 @@ public class SloccountLanguageStatistics implements Serializable {

/** Number of files containing this language. */
private final int fileCount;

/** Number of comments containing this language. */
private final int commentCount;

/**
* Constructor initializing members.
@@ -35,10 +38,11 @@ public class SloccountLanguageStatistics implements Serializable {
* number of files containing this language
*/
public SloccountLanguageStatistics(String languageName, int lineCount,
int fileCount){
int fileCount, int commentCount){
this.name = languageName;
this.lineCount = lineCount;
this.fileCount = fileCount;
this.commentCount = commentCount;
}

/**
@@ -70,4 +74,14 @@ public int getLineCount(){
public int getFileCount(){
return fileCount;
}

/**
* Get number of comments containing this language.
*
* @return the number of comments
*/
@Exported(name="comments")
public int getCommentCount(){
return commentCount;
}
}
@@ -127,17 +127,19 @@ private void parseLine(String line, SloccountReportInterface report){
}

int lineCount = Integer.parseInt(tokens[0]);
int commentCount = Integer.parseInt(tokens[1]);
String languageName = tokens[1];
String moduleName = tokens[2];
String filePath = tokens[3];

if(LOG_ENABLED && (this.logger != null)){
logger.println("lineCount: " + lineCount);
logger.println("language : " + languageName);
logger.println("commentCount: " + commentCount);
logger.println("file : " + filePath);
logger.println("module : " + moduleName);
}

report.add(filePath, languageName, moduleName, lineCount);
report.add(filePath, languageName, moduleName, lineCount, commentCount);
}
}
@@ -34,7 +34,7 @@ public SloccountReportStatistics getStatistics(){

for(Map.Entry<String, LanguageStatistics> it : statistics.entrySet()){
ret.add(new SloccountLanguageStatistics(it.getKey(),
it.getValue().numLines, it.getValue().numFiles));
it.getValue().numLines, it.getValue().numFiles, it.getValue().numComments));
}

return new SloccountReportStatistics(ret);
@@ -59,7 +59,7 @@ public void addSourceFile(File sourceFile){
sourceFiles.add(new SlaveFile(sourceFile));
}

public void add(String filePath, String languageName, String moduleName, int lineCount){
public void add(String filePath, String languageName, String moduleName, int lineCount, int commentCount){
LanguageStatistics stat = statistics.get(languageName);

if(stat == null){
@@ -68,6 +68,7 @@ public void add(String filePath, String languageName, String moduleName, int lin
}

stat.numLines += lineCount;
stat.numComments += commentCount;
++stat.numFiles;
}

@@ -90,6 +91,9 @@ public static class LanguageStatistics implements Serializable {

/** The number of files. */
int numFiles = 0;

/** The number of comments. */
int numComments = 0;
}

/**
@@ -34,18 +34,18 @@ public SloccountReport(SloccountReport old, FileFilter filter){
this();
for(File f : old.getFiles()){
if(filter.include(f)){
this.add(f.getName(), f.getLanguage(), f.getModule(), f.getLineCount());
this.add(f.getName(), f.getLanguage(), f.getModule(), f.getLineCount(), f.getCommentCount());
}
}
}

public void add(String filePath, String languageName, String moduleName, int lineCount){
public void add(String filePath, String languageName, String moduleName, int lineCount, int commentCount){
// Get rid of Microsoft's incompatibility once and forever
filePath = filePath.replace("\\", DIRECTORY_SEPARATOR);

String folderPath = extractFolder(filePath);

File file = new File(filePath, languageName, moduleName, lineCount);
File file = new File(filePath, languageName, moduleName, lineCount, commentCount);
this.addFile(file);

Folder folder = this.getFolder(folderPath);
@@ -18,8 +18,10 @@ public interface SloccountReportInterface {
* the module name
* @param lineCount
* the line count
* @param commentCount
* the comment count
*/
void add(String filePath, String languageName, String moduleName, int lineCount);
void add(String filePath, String languageName, String moduleName, int lineCount, int commentCount);

/**
* Get the root folder.
@@ -84,6 +84,22 @@ public int getFileCount() {
public int getLanguageCount() {
return statistics.size();
}

/**
* Get total comments count.
*
* @return the comments count
*/
@Exported(name="totalComments")
public int getCommentCount() {
int commentCount = 0;

for(SloccountLanguageStatistics it : statistics) {
commentCount += it.getCommentCount();
}

return commentCount;
}

/**
* Get total lines count.
@@ -102,6 +118,15 @@ public String getLineCountString() {
public String getFileCountString() {
return StringUtil.grouping(getFileCount());
}

/**
* Get total comments count.
*
* @return the comments count
*/
public String getCommentCountString() {
return StringUtil.grouping(getCommentCount());
}

/**
* Get total files count.
@@ -125,7 +150,7 @@ public SloccountLanguageStatistics getLanguage(String name) {
}
}

return new SloccountLanguageStatistics(name, 0, 0);
return new SloccountLanguageStatistics(name, 0, 0, 0);
}

/**
@@ -88,7 +88,7 @@ public void toSloccountReport(SloccountReportInterface report, boolean commentIs
lineCount += file.getComment();
}

report.add(filePath, file.getLanguage(), moduleName, lineCount);
report.add(filePath, file.getLanguage(), moduleName, lineCount, file.getComment());
}
} catch (RuntimeException e) {
throw new JAXBException("Broken cloc report file: " + e, e);
@@ -7,6 +7,7 @@
<td class="pane-header" style="width:2em">${%Language}</td>
<td class="pane-header" style="width:2em">${%Module}</td>
<td class="pane-header" style="width:2em">${%Lines}</td>
<td class="pane-header" style="width:2em">${%Comments}</td>
<td class="pane-header" style="width:60%">${%Distribution}</td>
</tr>
</thead>
@@ -19,6 +20,7 @@
<td class="pane">${container.language}</td>
<td class="pane">${container.module}</td>
<td class="pane number" data="${container.lineCount}">${container.lineCountString}</td>
<td class="pane number" data="${container.commentCount}">${container.commentCountString}</td>
<td class="pane" data="${container.lineCount}"><st:include page="/tabview/distribution-graph.jelly" /></td>
</tr>
</j:forEach>
@@ -29,6 +31,7 @@
<td class="pane-header"> </td>
<td class="pane-header"> </td>
<td class="pane-header number" data="${cachedReport.lineCount}">${cachedReport.lineCountString}</td>
<td class="pane-header number" data="${cachedReport.commentCount}">${cachedReport.commentCountString}</td>
<td class="pane-header" data="0"> </td>
</tr>
</tfoot>
@@ -45,22 +45,22 @@ public void testFileSeparator_Linux() {
SloccountReport report = new SloccountReport();
Assert.assertEquals("", report.getRootFolder());

report.add("/foo/bar/fubar/test.java", "java", "", 42);
report.add("/foo/bar/fubar/test.java", "java", "", 42, 50);
Assert.assertEquals("/foo/bar/fubar", report.getRootFolder());

report.add("/foo/bar/fubar/test.java", "java", "", 42);
report.add("/foo/bar/fubar/test.java", "java", "", 42, 50);
Assert.assertEquals("/foo/bar/fubar", report.getRootFolder());

report.add("/foo/bar/fubar/dir/test.java", "java", "", 42);
report.add("/foo/bar/fubar/dir/test.java", "java", "", 42, 50);
Assert.assertEquals("/foo/bar/fubar", report.getRootFolder());

report.add("/foo/bar/fubar/test.java", "java", "", 42);
report.add("/foo/bar/fubar/test.java", "java", "", 42, 50);
Assert.assertEquals("/foo/bar/fubar", report.getRootFolder());

report.add("/foo/bar/test.java", "java", "", 42);
report.add("/foo/bar/test.java", "java", "", 42, 50);
Assert.assertEquals("/foo/bar", report.getRootFolder());

report.add("/foo/bar/dir/test.java", "java", "", 42);
report.add("/foo/bar/dir/test.java", "java", "", 42, 50);
Assert.assertEquals("/foo/bar", report.getRootFolder());
}

@@ -69,22 +69,22 @@ public void testFileSeparator_WindowsSlash() {
SloccountReport report = new SloccountReport();
Assert.assertEquals("", report.getRootFolder());

report.add("C:/foo/bar/fubar/test.java", "java", "", 42);
report.add("C:/foo/bar/fubar/test.java", "java", "", 42, 50);
Assert.assertEquals("C:/foo/bar/fubar", report.getRootFolder());

report.add("C:/foo/bar/fubar/test.java", "java", "", 42);
report.add("C:/foo/bar/fubar/test.java", "java", "", 42, 50);
Assert.assertEquals("C:/foo/bar/fubar", report.getRootFolder());

report.add("C:/foo/bar/fubar/dir/test.java", "java", "", 42);
report.add("C:/foo/bar/fubar/dir/test.java", "java", "", 42, 50);
Assert.assertEquals("C:/foo/bar/fubar", report.getRootFolder());

report.add("C:/foo/bar/fubar/test.java", "java", "", 42);
report.add("C:/foo/bar/fubar/test.java", "java", "", 42, 50);
Assert.assertEquals("C:/foo/bar/fubar", report.getRootFolder());

report.add("C:/foo/bar/test.java", "java", "", 42);
report.add("C:/foo/bar/test.java", "java", "", 42, 50);
Assert.assertEquals("C:/foo/bar", report.getRootFolder());

report.add("C:/foo/bar/dir/test.java", "java", "", 42);
report.add("C:/foo/bar/dir/test.java", "java", "", 42, 50);
Assert.assertEquals("C:/foo/bar", report.getRootFolder());
}

@@ -93,22 +93,22 @@ public void testFileSeparator_WindowsBackSlash() {
SloccountReport report = new SloccountReport();
Assert.assertEquals("", report.getRootFolder());

report.add("C:\\foo\\bar\\fubar\\test.java", "java", "", 42);
report.add("C:\\foo\\bar\\fubar\\test.java", "java", "", 42, 50);
Assert.assertEquals("C:/foo/bar/fubar", report.getRootFolder());

report.add("C:\\foo\\bar\\fubar\\test.java", "java", "", 42);
report.add("C:\\foo\\bar\\fubar\\test.java", "java", "", 42, 50);
Assert.assertEquals("C:/foo/bar/fubar", report.getRootFolder());

report.add("C:\\foo\\bar\\fubar\\dir\\test.java", "java", "", 42);
report.add("C:\\foo\\bar\\fubar\\dir\\test.java", "java", "", 42, 50);
Assert.assertEquals("C:/foo/bar/fubar", report.getRootFolder());

report.add("C:\\foo\\bar\\fubar\\test.java", "java", "", 42);
report.add("C:\\foo\\bar\\fubar\\test.java", "java", "", 42, 50);
Assert.assertEquals("C:/foo/bar/fubar", report.getRootFolder());

report.add("C:\\foo\\bar\\test.java", "java", "", 42);
report.add("C:\\foo\\bar\\test.java", "java", "", 42, 50);
Assert.assertEquals("C:/foo/bar", report.getRootFolder());

report.add("C:\\foo\\bar\\dir\\test.java", "java", "", 42);
report.add("C:\\foo\\bar\\dir\\test.java", "java", "", 42, 50);
Assert.assertEquals("C:/foo/bar", report.getRootFolder());
}
}

0 comments on commit 0d502be

Please sign in to comment.