Skip to content
Permalink
Browse files
Merge pull request #46 from Safe0/next
[JENKINS-31221] Resolved issue - Implement access to comments count
  • Loading branch information
mixalturek committed Nov 3, 2015
2 parents a4c8ffc + 3a12ffe commit de3d4b1428c7aaf5b2efedde044793a5498e027a
Showing 20 changed files with 182 additions and 44 deletions.
@@ -19,6 +19,12 @@ public abstract class SloccountDiff implements Comparable<SloccountDiff> {

/** Difference of files count between current and previous report. */
private final int fileCountDelta;

/** Comments count in the newer report. */
private final int commentCount;

/** Difference of comments count between current and previous report. */
private final int commentCountDelta;

/**
* Constructor.
@@ -28,18 +34,25 @@ public abstract class SloccountDiff implements Comparable<SloccountDiff> {
* @param lineCountDelta
* difference of lines count between current and previous
* report
* @param fileCount files
* count in the newer report
* @param fileCount
* files count in the newer report
* @param fileCountDelta
* difference of files count between current and previous
* report
* @param commentCount
* comments count in the newer report
* @param commentCountDelta
* difference of comments count between current and previous
* report
*/
public SloccountDiff(int lineCount,
int lineCountDelta, int fileCount, int fileCountDelta) {
int lineCountDelta, int fileCount, int fileCountDelta, int commentCount, int commentCountDelta) {
this.lineCount = lineCount;
this.lineCountDelta = lineCountDelta;
this.fileCount = fileCount;
this.fileCountDelta = fileCountDelta;
this.commentCount = commentCount;
this.commentCountDelta = commentCountDelta;
}

/**
@@ -84,6 +97,14 @@ public int getLineCount() {
public int getLineCountDelta() {
return lineCountDelta;
}

public int getCommentCount() {
return commentCount;
}

public int getCommentCountDelta() {
return commentCountDelta;
}

public int getFileCount() {
return fileCount;
@@ -106,6 +127,20 @@ public String getLineCountDeltaString() {
String result = StringUtil.grouping(lineCountDelta);
return (lineCountDelta > 0) ? "+" + result : result;
}

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

public String getCommentCountDeltaString() {
if(commentCountDelta == 0) {
return "";
}

// Negative prefix '-' is added automatically
String result = StringUtil.grouping(commentCountDelta);
return (commentCountDelta > 0) ? "+" + result : result;
}

public String getFileCountString() {
return StringUtil.grouping(fileCount);
@@ -26,10 +26,15 @@ public class SloccountDiffLanguage extends SloccountDiff {
* @param fileCountDelta
* difference of files count between current and previous
* report
* @param commentCount
* comments count in the newer report
* @param commentCountDelta
* difference of comments count between current and previous
* report
*/
public SloccountDiffLanguage(String name, int lineCount,
int lineCountDelta, int fileCount, int fileCountDelta) {
super(lineCount, lineCountDelta, fileCount, fileCountDelta);
int lineCountDelta, int fileCount, int fileCountDelta, int commentCount, int commentCountDelta) {
super(lineCount, lineCountDelta, fileCount, fileCountDelta, commentCount, commentCountDelta);
this.name = name;
}

@@ -33,12 +33,16 @@ public class SloccountDiffSummary extends SloccountDiff {
* @param fileCountDelta
* difference of files count between current and previous
* report
*
* @param commentCount
* comments count in the newer report
* @param commentCountDelta
* difference of comments count between current and previous
* report
* @see #getDiffSummary(SloccountReportStatistics, SloccountReportStatistics)
*/
private SloccountDiffSummary(List<SloccountDiffLanguage> languageDiffs,
int lineCount, int lineCountDelta, int fileCount, int fileCountDelta) {
super(lineCount, lineCountDelta, fileCount, fileCountDelta);
int lineCount, int lineCountDelta, int fileCount, int fileCountDelta, int commentCount, int commentCountDelta) {
super(lineCount, lineCountDelta, fileCount, fileCountDelta, commentCount, commentCountDelta);

// No copy, can be called only internally
this.languageDiffs = languageDiffs;
@@ -70,6 +74,8 @@ public static SloccountDiffSummary getDiffSummary(
int lineCountDelta = 0;
int fileCount = 0;
int fileCountDelta = 0;
int commentCount = 0;
int commentCountDelta = 0;

for(String language: languages) {
// Quadratic complexity can be optimized, but languages count is small
@@ -80,16 +86,21 @@ public static SloccountDiffSummary getDiffSummary(
curStats.getLineCount(),
curStats.getLineCount() - prevStats.getLineCount(),
curStats.getFileCount(),
curStats.getFileCount() - prevStats.getFileCount()));
curStats.getFileCount() - prevStats.getFileCount(),
curStats.getCommentCount(),
curStats.getCommentCount() - prevStats.getCommentCount()));

lineCount += curStats.getLineCount();
lineCountDelta += curStats.getLineCount() - prevStats.getLineCount();
fileCount += curStats.getFileCount();
fileCountDelta += curStats.getFileCount() - prevStats.getFileCount();
commentCount += curStats.getCommentCount();
commentCountDelta += curStats.getCommentCount() - prevStats.getCommentCount();
}

return new SloccountDiffSummary(result, lineCount, lineCountDelta,
fileCount, fileCountDelta);
fileCount, fileCountDelta,
commentCount, commentCountDelta);
}

/**
@@ -107,16 +118,18 @@ private static SloccountDiffSummary getDiffSummary(SloccountReportStatistics cur
List<SloccountDiffLanguage> result = new ArrayList<SloccountDiffLanguage>();
int lineCount = 0;
int fileCount = 0;
int commentCount = 0;

for(SloccountLanguageStatistics language: current.getStatistics()) {
result.add(new SloccountDiffLanguage(language.getName(),
language.getLineCount(), 0, language.getFileCount(), 0));
language.getLineCount(), 0, language.getFileCount(), 0, language.getCommentCount(), 0));

lineCount += language.getLineCount();
fileCount += language.getFileCount();
commentCount += language.getCommentCount();
}

return new SloccountDiffSummary(result, lineCount, 0, fileCount, 0);
return new SloccountDiffSummary(result, lineCount, 0, fileCount, 0, commentCount, 0);
}

/**
@@ -127,7 +140,7 @@ private static SloccountDiffSummary getDiffSummary(SloccountReportStatistics cur
*/
private static SloccountDiffSummary getDiffSummary() {
return new SloccountDiffSummary(
Collections.<SloccountDiffLanguage>emptyList(), 0, 0, 0, 0);
Collections.<SloccountDiffLanguage>emptyList(), 0, 0, 0, 0, 0, 0);
}

/**
@@ -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;
}
}
@@ -138,6 +138,6 @@ private void parseLine(String line, SloccountReportInterface report){
logger.println("module : " + moduleName);
}

report.add(filePath, languageName, moduleName, lineCount);
report.add(filePath, languageName, moduleName, lineCount, 0);
}
}
@@ -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.

0 comments on commit de3d4b1

Please sign in to comment.