Skip to content

Commit

Permalink
Merge pull request #35 from mixalturek/master
Browse files Browse the repository at this point in the history
[JENKINS-21697] New Modules panel on report page
  • Loading branch information
mixalturek committed Feb 8, 2014
2 parents aed45a8 + 686d066 commit eba4fce
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 82 deletions.
26 changes: 13 additions & 13 deletions src/main/java/hudson/plugins/sloccount/SloccountResult.java
Expand Up @@ -130,16 +130,16 @@ public SloccountResult getLanguageResult(String language){
}

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

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

public SloccountResult getFolderResult(String jumbledFolder){
Expand All @@ -164,28 +164,28 @@ public boolean include(File file) {
}

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

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

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

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

Expand Down
16 changes: 8 additions & 8 deletions src/main/java/hudson/plugins/sloccount/model/File.java
Expand Up @@ -14,15 +14,15 @@ public class File implements Countable, Serializable {
private String name;
private final String language;

/** The part. */
private final String part;
/** The module. */
private final String module;

private final int lineCount;

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

Expand All @@ -43,12 +43,12 @@ public String getLanguage(){
}

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

public void simplifyName(String rootPath){
Expand Down
Expand Up @@ -2,24 +2,24 @@
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.
* Module name is present in the third column of SLOCCount utility output.
* Modules are often the top level directories.
*
* @author Michal Turek
*/
public class Part extends FileContainer {
public class Module extends FileContainer {
/** Serial version UID. */
private static final long serialVersionUID = 0L;

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

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

Expand Down
Expand Up @@ -111,16 +111,16 @@ private void parseLine(String line, SloccountReportInterface report){

int lineCount = Integer.parseInt(tokens[0]);
String languageName = tokens[1];
String partName = tokens[2];
String moduleName = 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);
logger.println("module : " + moduleName);
}

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

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

if(stat == null){
Expand Down
74 changes: 37 additions & 37 deletions src/main/java/hudson/plugins/sloccount/model/SloccountReport.java
Expand Up @@ -20,8 +20,8 @@ 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 modules present in the SLOCCount report. */
private Map<String, Module> modules = new LinkedHashMap<String, Module>();

/** The longest folder path common to all folders. */
private String[] rootFolderPath = null;
Expand All @@ -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.getPart(), f.getLineCount());
this.add(f.getName(), f.getLanguage(), f.getModule(), f.getLineCount());
}
}
}

public void add(String filePath, String languageName, String partName, int lineCount){
public void add(String filePath, String languageName, String moduleName, 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, partName, lineCount);
File file = new File(filePath, languageName, moduleName, lineCount);
this.addFile(file);

Folder folder = this.getFolder(folderPath);
Expand All @@ -62,12 +62,12 @@ public void add(String filePath, String languageName, String partName, int lineC
}
language.addFile(file);

Part part = getPart(partName);
if(part == null){
part = new Part(partName);
this.addPart(part);
Module module = getModule(moduleName);
if(module == null){
module = new Module(moduleName);
this.addModule(module);
}
part.addFile(file);
module.addFile(file);
}

/**
Expand Down Expand Up @@ -135,45 +135,45 @@ public String getLanguageCountString() {
}

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

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

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

return parts.size();
return modules.size();
}

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

public void addFolder(Folder folder){
Expand All @@ -187,12 +187,12 @@ public void addLanguage(Language language){
}

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

public String getRootFolder(){
Expand Down Expand Up @@ -265,16 +265,16 @@ public Language getLongestLanguage(){
}

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

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

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

/**
* Get the root folder.
Expand Down
Expand Up @@ -7,7 +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">${%Module}</td>
<td class="pane-header" style="width:2em">${%Lines}</td>
<td class="pane-header" style="width:60%">${%Distribution}</td>
</tr>
Expand All @@ -19,7 +19,7 @@
<tr>
<td class="pane">${container.name}</td>
<td class="pane">${container.language}</td>
<td class="pane">${container.part}</td>
<td class="pane">${container.module}</td>
<td class="pane number" data="${container.lineCount}">${container.lineCountString}</td>
<td class="pane" data="${container.lineCount}"><st:include page="/tabview/distribution-graph.jelly" /></td>
</tr>
Expand Down
Expand Up @@ -2,21 +2,21 @@
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">
<table class="pane sortable" id="modules">
<thead>
<tr>
<td class="pane-header">${%Part}</td>
<td class="pane-header">${%Modules}</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}">
<j:set var="max" value="${cachedReport.longestModule.lineCount}"/>
<j:forEach var="container" items="${cachedReport.modules}">
<tr>
<td class="pane"><a href="partResult/${container.name}">${container.name}</a></td>
<td class="pane"><a href="moduleResult/${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" data="${container.lineCount}"><st:include page="/tabview/distribution-graph.jelly" /></td>
Expand All @@ -25,7 +25,7 @@
</tbody>
<tfoot>
<tr class="sortbottom">
<td class="pane-header">${%Total} ${cachedReport.partCountString}</td>
<td class="pane-header">${%Total} ${cachedReport.moduleCountString}</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" data="0"> </td>
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/tabview/main.jelly
Expand Up @@ -16,10 +16,10 @@
active: false
}), myTabs);

<j:if test="${it.report.partCount > 1}">
<j:if test="${it.report.moduleCount > 1}">
YAHOO.plugin.Dispatcher.delegate (new YAHOO.widget.Tab({
label: '${%Parts}',
dataSrc: 'parts',
label: '${%Modules}',
dataSrc: 'modules',
cacheData: true,
active: false
}), myTabs);
Expand Down

0 comments on commit eba4fce

Please sign in to comment.