Skip to content

Commit

Permalink
WINDUP-835: Create an index/table of content as the default
Browse files Browse the repository at this point in the history
  • Loading branch information
jsight committed Jan 8, 2016
1 parent 17706ac commit bc4e1ca
Show file tree
Hide file tree
Showing 41 changed files with 5,143 additions and 180 deletions.
@@ -1,5 +1,6 @@
package org.jboss.windup.reporting.freemarker;

import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand Down Expand Up @@ -32,6 +33,9 @@ public class FreeMarkerUtil
*/
public static Set<String> simpleSequenceToSet(SimpleSequence simpleSequence)
{
if (simpleSequence == null)
return Collections.emptySet();

Set<String> result = new HashSet<>();
for (int i = 0; i < simpleSequence.size(); i++)
{
Expand Down
@@ -1,8 +1,10 @@
package org.jboss.windup.reporting.freemarker;

import java.util.List;
import java.util.Map;

import org.jboss.windup.config.GraphRewrite;
import org.jboss.windup.reporting.service.EffortReportService;
import org.jboss.windup.util.ExecutionStatistics;

import freemarker.template.SimpleNumber;
Expand Down Expand Up @@ -38,28 +40,9 @@ public Object exec(List arguments) throws TemplateModelException
throw new TemplateModelException("Error, method expects one argument (Integer)");
}
SimpleNumber simpleNumber = (SimpleNumber) arguments.get(0);
String result = "";
switch (simpleNumber.getAsNumber().intValue())
{
case 0:
result = "Info";
break;
case 1:
result = "Trivial";
break;
case 3:
result = "Complex";
break;
case 5:
result = "Redesign";
break;
case 7:
result = "Requires Architectural Change";
break;
case 13:
default:
result = "Unknown";
}
int effort = simpleNumber.getAsNumber().intValue();
Map<Integer, String> effortToDescription = EffortReportService.getEffortLevelDescriptionMappings();
String result = effortToDescription.containsKey(effort) ? effortToDescription.get(effort) : EffortReportService.UNKNOWN;

ExecutionStatistics.get().end(NAME);
return result;
Expand Down
@@ -0,0 +1,80 @@
package org.jboss.windup.reporting.freemarker.problemsummary;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.jboss.windup.config.GraphRewrite;
import org.jboss.windup.graph.GraphContext;
import org.jboss.windup.graph.model.ProjectModel;
import org.jboss.windup.reporting.freemarker.FreeMarkerUtil;
import org.jboss.windup.reporting.freemarker.WindupFreeMarkerMethod;
import org.jboss.windup.reporting.model.Severity;

import freemarker.ext.beans.StringModel;
import freemarker.template.SimpleSequence;
import freemarker.template.TemplateModelException;

/**
* @author <a href="mailto:jesse.sightler@gmail.com">Jesse Sightler</a>
*/
public class GetProblemSummariesMethod implements WindupFreeMarkerMethod
{
public static final String NAME = "getProblemSummaries";

private GraphContext context;

@Override
public String getMethodName()
{
return NAME;
}

@Override
public String getDescription()
{
return "Returns a summary of all classification and hints found during analysis in the form of a List<"
+ ProblemSummary.class.getSimpleName() + ">.";
}

@Override
public Object exec(List arguments) throws TemplateModelException
{
// Get the project if one was passed in
final ProjectModel projectModel;
if (arguments.size() > 0)
{
StringModel projectModelArg = (StringModel) arguments.get(0);
if (projectModelArg == null)
projectModel = null;
else
projectModel = (ProjectModel) projectModelArg.getWrappedObject();
}
else
{
projectModel = null;
}

Set<String> includeTags = FreeMarkerUtil.simpleSequenceToSet((SimpleSequence) arguments.get(1));
Set<String> excludeTags = FreeMarkerUtil.simpleSequenceToSet((SimpleSequence) arguments.get(2));

Map<Severity, List<ProblemSummary>> problemSummaries = ProblemSummaryService.getProblemSummaries(context, projectModel, includeTags,
excludeTags);

// Convert the keys to String to make Freemarker happy
Map<String, List<ProblemSummary>> primarySummariesByString = new HashMap<>(problemSummaries.size());
for (Map.Entry<Severity, List<ProblemSummary>> entry : problemSummaries.entrySet())
{
String severityString = entry.getKey() == null ? null : entry.getKey().toString();
primarySummariesByString.put(severityString, entry.getValue());
}
return primarySummariesByString;
}

@Override
public void setContext(GraphRewrite event)
{
this.context = event.getGraphContext();
}
}
Expand Up @@ -4,13 +4,14 @@
import java.util.Map;

import org.jboss.windup.graph.model.resource.FileModel;
import org.jboss.windup.reporting.model.Severity;

/**
* @author <a href="mailto:jesse.sightler@gmail.com">Jesse Sightler</a>
*/
public class ProblemSummary
{
private final String severity;
private final Severity severity;
private final String ruleID;
private final String issueName;
private int numberFound;
Expand All @@ -20,7 +21,7 @@ public class ProblemSummary
/**
* Creates a new instance with the given information.
*/
public ProblemSummary(String severity, String ruleID, String issueName, int numberFound, int effortPerIncident)
public ProblemSummary(Severity severity, String ruleID, String issueName, int numberFound, int effortPerIncident)
{
this.severity = severity;
this.ruleID = ruleID;
Expand All @@ -33,7 +34,7 @@ public ProblemSummary(String severity, String ruleID, String issueName, int numb
* Returns the severity as a String (the String type makes integration with freemarker easier, as freemarker doesn't always retain type
* information on enums).
*/
public String getSeverity()
public Severity getSeverity()
{
return severity;
}
Expand Down
Expand Up @@ -8,82 +8,34 @@
import java.util.Set;
import java.util.TreeMap;

import org.jboss.windup.config.GraphRewrite;
import org.jboss.windup.graph.GraphContext;
import org.jboss.windup.graph.model.ProjectModel;
import org.jboss.windup.graph.model.resource.FileModel;
import org.jboss.windup.reporting.TagUtil;
import org.jboss.windup.reporting.freemarker.FreeMarkerUtil;
import org.jboss.windup.reporting.freemarker.WindupFreeMarkerMethod;
import org.jboss.windup.reporting.model.ClassificationModel;
import org.jboss.windup.reporting.model.InlineHintModel;
import org.jboss.windup.reporting.model.Severity;
import org.jboss.windup.reporting.service.ClassificationService;
import org.jboss.windup.reporting.service.InlineHintService;

import freemarker.ext.beans.StringModel;
import freemarker.template.SimpleSequence;
import freemarker.template.TemplateModelException;

/**
* Gets {@link ProblemSummary}s for display to the user.
*
* @author <a href="mailto:jesse.sightler@gmail.com">Jesse Sightler</a>
*/
public class GetProblemSummariesMethod implements WindupFreeMarkerMethod
public class ProblemSummaryService
{
public static final String NAME = "getProblemSummaries";

private GraphContext context;

@Override
public String getMethodName()
{
return NAME;
}

@Override
public String getDescription()
{
return "Returns a summary of all classification and hints found during analysis in the form of a List<"
+ ProblemSummary.class.getSimpleName() + ">.";
}

@Override
public Object exec(List arguments) throws TemplateModelException
public static Map<Severity, List<ProblemSummary>> getProblemSummaries(GraphContext context, ProjectModel projectModel, Set<String> includeTags,
Set<String> excludeTags)
{
// Get the project if one was passed in
final ProjectModel projectModel;
if (arguments.size() > 0)
{
StringModel projectModelArg = (StringModel) arguments.get(0);
if (projectModelArg == null)
projectModel = null;
else
projectModel = (ProjectModel) projectModelArg.getWrappedObject();
}
else
{
projectModel = null;
}

Set<String> includeTags = FreeMarkerUtil.simpleSequenceToSet((SimpleSequence) arguments.get(1));
Set<String> excludeTags = FreeMarkerUtil.simpleSequenceToSet((SimpleSequence) arguments.get(2));

// get all classifications
// get all hints
// group them by title (classification and hint title)

// The key is the severity as a String
Map<String, List<ProblemSummary>> results = new TreeMap<>(new Comparator<String>()
Map<Severity, List<ProblemSummary>> results = new TreeMap<>(new Comparator<Severity>()
{
@Override
public int compare(String severity1, String severity2)
public int compare(Severity severity1, Severity severity2)
{
return Severity.valueOf(severity1).ordinal() - Severity.valueOf(severity2).ordinal();
return severity1.ordinal() - severity2.ordinal();
}
});
Map<RuleSummaryKey, ProblemSummary> ruleIDToSummary = new HashMap<>();
Map<RuleSummaryKey, ProblemSummary> ruleToSummary = new HashMap<>();

InlineHintService hintService = new InlineHintService(context);
final Iterable<InlineHintModel> hints = projectModel == null ? hintService.findAll() : hintService.getHintsForProject(projectModel, true);
Expand All @@ -95,11 +47,11 @@ public int compare(String severity1, String severity2)

RuleSummaryKey key = new RuleSummaryKey(hint.getRuleID(), hint.getTitle());

ProblemSummary summary = ruleIDToSummary.get(key);
ProblemSummary summary = ruleToSummary.get(key);
if (summary == null)
{
summary = new ProblemSummary(hint.getSeverity().toString(), hint.getRuleID(), hint.getTitle(), 1, hint.getEffort());
ruleIDToSummary.put(key, summary);
summary = new ProblemSummary(hint.getSeverity(), hint.getRuleID(), hint.getTitle(), 1, hint.getEffort());
ruleToSummary.put(key, summary);
addToResults(results, summary);
}
else
Expand Down Expand Up @@ -143,13 +95,13 @@ public int compare(String severity1, String severity2)
continue;

RuleSummaryKey key = new RuleSummaryKey(classification.getRuleID(), classification.getClassification());
ProblemSummary summary = ruleIDToSummary.get(key);
ProblemSummary summary = ruleToSummary.get(key);
if (summary == null)
{
summary = new ProblemSummary(classification.getSeverity().toString(), classification.getRuleID(), classification.getClassification(),
summary = new ProblemSummary(classification.getSeverity(), classification.getRuleID(), classification.getClassification(),
0,
classification.getEffort());
ruleIDToSummary.put(key, summary);
ruleToSummary.put(key, summary);
addToResults(results, summary);
}

Expand All @@ -162,7 +114,7 @@ public int compare(String severity1, String severity2)
return results;
}

private void addToResults(Map<String, List<ProblemSummary>> results, ProblemSummary summary)
private static void addToResults(Map<Severity, List<ProblemSummary>> results, ProblemSummary summary)
{
List<ProblemSummary> list = results.get(summary.getSeverity());
if (list == null)
Expand All @@ -172,46 +124,4 @@ private void addToResults(Map<String, List<ProblemSummary>> results, ProblemSumm
}
list.add(summary);
}

@Override
public void setContext(GraphRewrite event)
{
this.context = event.getGraphContext();
}

private class RuleSummaryKey
{
private final String ruleID;
private final String title;

public RuleSummaryKey(String ruleID, String title)
{
this.ruleID = ruleID;
this.title = title;
}

@Override
public boolean equals(Object o)
{
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;

RuleSummaryKey that = (RuleSummaryKey) o;

if (ruleID != null ? !ruleID.equals(that.ruleID) : that.ruleID != null)
return false;
return !(title != null ? !title.equals(that.title) : that.title != null);

}

@Override
public int hashCode()
{
int result = ruleID != null ? ruleID.hashCode() : 0;
result = 31 * result + (title != null ? title.hashCode() : 0);
return result;
}
}
}

0 comments on commit bc4e1ca

Please sign in to comment.