Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #33 from mixalturek/master
[JENKINS-21697] New Parts panel on report page
  • Loading branch information
mixalturek committed Feb 6, 2014
2 parents 1119334 + 37bc407 commit e93822a
Show file tree
Hide file tree
Showing 13 changed files with 268 additions and 46 deletions.
39 changes: 39 additions & 0 deletions src/main/java/hudson/plugins/sloccount/SloccountResult.java
Expand Up @@ -129,6 +129,19 @@ public SloccountResult getLanguageResult(String language){
return new BreadCrumbResult(filtered, this.owner, language);
}

/**
* Get result for a specific part.
*
* @param part the part
* @return the result
*/
public SloccountResult getPartResult(String part){
SloccountReport filtered = new SloccountReport(this.getReport(),
new PartFileFilter(part));

return new BreadCrumbResult(filtered, owner, part);
}

public SloccountResult getFolderResult(String jumbledFolder){
String folder = jumbledFolder.replace("|", SloccountReport.DIRECTORY_SEPARATOR);
SloccountReport filtered = new SloccountReport(this.getReport(), new FolderFileFilter(folder));
Expand All @@ -150,6 +163,32 @@ public boolean include(File file) {
}
}

/**
* File filter for parts.
*
* @author Michal Turek
*/
private static class PartFileFilter implements FileFilter, Serializable {
/** Serial version UID. */
private static final long serialVersionUID = 0L;

/** The part name. */
private String part;

/**
* Constructor.
*
* @param part the part
*/
public PartFileFilter(String part){
this.part = part;
}

public boolean include(File file) {
return file.getPart().equals(part);
}
}

private static class FolderFileFilter implements FileFilter, Serializable {
/** Serial version UID. */
private static final long serialVersionUID = 0L;
Expand Down
20 changes: 17 additions & 3 deletions src/main/java/hudson/plugins/sloccount/model/File.java
Expand Up @@ -12,12 +12,17 @@ public class File implements Countable, Serializable {
private static final long serialVersionUID = 0L;

private String name;
private String language;
private int lineCount;
private final String language;

public File(String name, String language, int lineCount){
/** The part. */
private final String part;

private final int lineCount;

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

Expand All @@ -37,6 +42,15 @@ public String getLanguage(){
return this.language;
}

/**
* Get the part.
*
* @return the part
*/
public String getPart(){
return part;
}

public void simplifyName(String rootPath){
this.name = this.name.substring(rootPath.length());
}
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/hudson/plugins/sloccount/model/Part.java
@@ -0,0 +1,29 @@

package hudson.plugins.sloccount.model;

/**
* One of the top level directories that are passed to the SLOCCount
* utility. It is present in the third column of SLOCCount output.
*
* @author Michal Turek
*/
public class Part extends FileContainer {
/** Serial version UID. */
private static final long serialVersionUID = 0L;

/** The part name. */
private String name;

/**
* Constructor.
*
* @param name the part name
*/
public Part(String name){
this.name = name;
}

public String getName() {
return this.name;
}
}
Expand Up @@ -111,14 +111,16 @@ private void parseLine(String line, SloccountReportInterface report){

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

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

report.add(filePath, languageName, lineCount);
report.add(filePath, languageName, partName, lineCount);
}
}
Expand Up @@ -59,7 +59,7 @@ public void addSourceFile(File sourceFile){
sourceFiles.add(new SlaveFile(sourceFile));
}

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

if(stat == null){
Expand Down
86 changes: 82 additions & 4 deletions src/main/java/hudson/plugins/sloccount/model/SloccountReport.java
Expand Up @@ -20,6 +20,9 @@ public class SloccountReport extends FileContainer implements SloccountReportInt
private Map<String, Folder> folders = new LinkedHashMap<String, Folder>();
private Map<String, Language> languages = new LinkedHashMap<String, Language>();

/** The parts present in the SLOCCount report. */
private Map<String, Part> parts = new LinkedHashMap<String, Part>();

/** The longest folder path common to all folders. */
private String[] rootFolderPath = null;

Expand All @@ -31,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.getLineCount());
this.add(f.getName(), f.getLanguage(), f.getPart(), f.getLineCount());
}
}
}

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

String folderPath = extractFolder(filePath);

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

Folder folder = this.getFolder(folderPath);
Expand All @@ -58,6 +61,13 @@ public void add(String filePath, String languageName, int lineCount){
this.addLanguage(language);
}
language.addFile(file);

Part part = getPart(partName);
if(part == null){
part = new Part(partName);
this.addPart(part);
}
part.addFile(file);
}

/**
Expand Down Expand Up @@ -123,7 +133,49 @@ public int getLanguageCount(){
public String getLanguageCountString() {
return StringUtil.grouping(getLanguageCount());
}


/**
* Get part using its name.
*
* @param name the part name
* @return the part or null if not defined
*/
public Part getPart(String name) {
return parts.get(name);
}

/**
* Get all parts.
*
* @return the parts or empty list if no part is defined
*/
public List<Part> getParts(){
return new ArrayList<Part>(parts.values());
}

/**
* Get count of all parts.
*
* @return the count
*/
public int getPartCount(){
// Backward compatibility with plugin version 1.10 and less
if(parts == null) {
return 0;
}

return parts.size();
}

/**
* Get count of all parts as string.
*
* @return the count
*/
public String getPartCountString() {
return StringUtil.grouping(getPartCount());
}

public void addFolder(Folder folder){
this.folders.put(folder.getName(), folder);

Expand All @@ -134,6 +186,15 @@ public void addLanguage(Language language){
this.languages.put(language.getName(), language);
}

/**
* Add a new part.
*
* @param part the part
*/
public void addPart(Part part){
parts.put(part.getName(), part);
}

public String getRootFolder(){
if(this.rootFolderPath == null){
// this can happen if no report files were found to match the pattern
Expand Down Expand Up @@ -203,6 +264,23 @@ public Language getLongestLanguage(){
return longest;
}

/**
* Get the longest part.
*
* @return the longest part
*/
public Part getLongestPart(){
Part longest = null;

for(Part part : getParts()){
if(longest == null || part.getLineCount() > longest.getLineCount()) {
longest = part;
}
}

return longest;
}

/**
* Simplify the names.
*/
Expand Down
Expand Up @@ -14,10 +14,12 @@ public interface SloccountReportInterface {
* the file
* @param languageName
* the language name
* @param partName
* the part name
* @param lineCount
* the line count
*/
void add(String filePath, String languageName, int lineCount);
void add(String filePath, String languageName, String partName, int lineCount);

/**
* Get the root folder.
Expand Down
Expand Up @@ -7,6 +7,7 @@
<tr>
<td class="pane-header">${%File}</td>
<td class="pane-header" style="width:2em">${%Language}</td>
<td class="pane-header" style="width:2em">${%Part}</td>
<td class="pane-header" style="width:2em">${%Lines}</td>
<td class="pane-header" style="width:60%">${%Distribution}</td>
</tr>
Expand All @@ -18,6 +19,7 @@
<tr>
<td class="pane">${container.name}</td>
<td class="pane">${container.language}</td>
<td class="pane">${container.part}</td>
<td class="pane number" data="${container.lineCount}">${container.lineCountString}</td>
<td class="pane"><st:include page="/tabview/distribution-graph.jelly" /></td>
</tr>
Expand All @@ -27,6 +29,7 @@
<tr class="sortbottom">
<td class="pane-header">${%Total} ${cachedReport.fileCountString}</td>
<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"> </td>
</tr>
Expand Down
@@ -0,0 +1,39 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"
xmlns:i="jelly:fmt" xmlns:local="local">
<st:header name="Content-Type" value="text/html;charset=UTF-8" />
<table class="pane sortable" id="parts">
<thead>
<tr>
<td class="pane-header">${%Part}</td>
<td class="pane-header" style="width:2em">${%Files}</td>
<td class="pane-header" style="width:2em">${%Lines}</td>
<td class="pane-header" style="width:60%">${%Distribution}</td>
</tr>
</thead>
<tbody>
<j:set var="cachedReport" value="${it.report}"/>
<j:set var="max" value="${cachedReport.longestPart.lineCount}"/>
<j:forEach var="container" items="${cachedReport.parts}">
<tr>
<td class="pane"><a href="partResult/${container.name}">${container.name}</a></td>
<td class="pane number" data="${container.fileCount}">${container.fileCountString}</td>
<td class="pane number" data="${container.lineCount}">${container.lineCountString}</td>
<td class="pane"><st:include page="/tabview/distribution-graph.jelly" /></td>
</tr>
</j:forEach>
</tbody>
<tfoot>
<tr class="sortbottom">
<td class="pane-header">${%Total} ${cachedReport.partCountString}</td>
<td class="pane-header number" data="${cachedReport.fileCount}">${cachedReport.fileCountString}</td>
<td class="pane-header number" data="${cachedReport.lineCount}">${cachedReport.lineCountString}</td>
<td class="pane-header"> </td>
</tr>
</tfoot>
</table>

<script type="text/javascript">
Behaviour.applySubtree(document.getElementById('statistics'));
</script>
</j:jelly>
@@ -0,0 +1,4 @@
Files=Dateien
Lines=Zeilen
Distribution=Verteilung
Total=Total
@@ -0,0 +1,4 @@
Files=\u30d5\u30a1\u30a4\u30eb
Lines=\u884c
Distribution=\u5206\u5e03
Total=\u5408\u8a08

0 comments on commit e93822a

Please sign in to comment.