Skip to content

Commit

Permalink
WINDUP-900: The application list should display effort categories
Browse files Browse the repository at this point in the history
  • Loading branch information
jsight committed Feb 5, 2016
1 parent 8a413fc commit ee9f9f0
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 33 deletions.
Expand Up @@ -5,6 +5,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand All @@ -25,9 +26,9 @@
import org.ocpsoft.rewrite.context.EvaluationContext;

import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapperBuilder;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import java.util.Arrays;

/**
* This class is used to produce a freemarker report from inside of a Windup {@link Iteration}.
Expand Down Expand Up @@ -100,6 +101,10 @@ public void perform(final GraphRewrite event, final EvaluationContext context, f
LOG.info("Reporting: Writing template \"" + templatePath + "\" to output file \"" + outputPath.toAbsolutePath().toString() + "\"");

Configuration freemarkerConfig = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
DefaultObjectWrapperBuilder objectWrapperBuilder = new DefaultObjectWrapperBuilder(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
objectWrapperBuilder.setUseAdaptersForContainers(true);
freemarkerConfig.setObjectWrapper(objectWrapperBuilder.build());
freemarkerConfig.setAPIBuiltinEnabled(true);
freemarkerConfig.setTemplateLoader(new FurnaceFreeMarkerTemplateLoader());
freemarkerConfig.setTemplateUpdateDelayMilliseconds(3600);

Expand Down
Expand Up @@ -19,6 +19,8 @@
import org.jboss.windup.util.exception.WindupException;
import org.ocpsoft.rewrite.context.EvaluationContext;

import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapperBuilder;
import freemarker.template.Template;
import freemarker.template.TemplateException;

Expand Down Expand Up @@ -70,10 +72,14 @@ public void perform(GraphRewrite event, EvaluationContext context)
LOG.info("Reporting: Writing template \"" + templatePath + "\" to output file \""
+ outputPath.toAbsolutePath().toString() + "\"");

freemarker.template.Configuration cfg = new freemarker.template.Configuration();
cfg.setTemplateLoader(new FurnaceFreeMarkerTemplateLoader());
cfg.setTemplateUpdateDelay(500);
Template template = cfg.getTemplate(templatePath);
freemarker.template.Configuration freemarkerConfig = new freemarker.template.Configuration();
DefaultObjectWrapperBuilder objectWrapperBuilder = new DefaultObjectWrapperBuilder(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
objectWrapperBuilder.setUseAdaptersForContainers(true);
freemarkerConfig.setObjectWrapper(objectWrapperBuilder.build());

freemarkerConfig.setTemplateLoader(new FurnaceFreeMarkerTemplateLoader());
freemarkerConfig.setTemplateUpdateDelayMilliseconds(3600);
Template template = freemarkerConfig.getTemplate(templatePath);

Variables varStack = Variables.instance(event);

Expand Down
@@ -1,6 +1,8 @@
package org.jboss.windup.reporting.service;

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

import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -40,7 +42,7 @@ public ClassificationService(GraphContext context)
/**
* Returns the total effort points in all of the {@link ClassificationModel}s associated with the provided {@link FileModel}.
*/
public int getMigrationEffortPoints(FileModel fileModel)
public int getMigrationEffortDetails(FileModel fileModel)
{
GremlinPipeline<Vertex, Vertex> classificationPipeline = new GremlinPipeline<>(fileModel.asVertex());
classificationPipeline.in(ClassificationModel.FILE_MODEL);
Expand Down Expand Up @@ -87,8 +89,11 @@ public Iterable<ClassificationModel> getClassificationByName(FileModel model, St
*
* If set to recursive, then also include the effort points from child projects.
*/
public int getMigrationEffortPoints(ProjectModel initialProject, Set<String> includeTags, Set<String> excludeTags, boolean recursive)
public Map<Integer, Integer> getMigrationEffortDetails(ProjectModel initialProject, Set<String> includeTags, Set<String> excludeTags,
boolean recursive)
{
Map<Integer, Integer> results = new HashMap<>();

final Set<Vertex> initialVertices = new HashSet<>();
if (recursive)
{
Expand Down Expand Up @@ -118,7 +123,6 @@ public Boolean compute(Vertex argument)
});
classificationPipeline.back("classification");

int classificationEffort = 0;
for (Vertex v : classificationPipeline)
{
Integer migrationEffort = v.getProperty(ClassificationModel.EFFORT);
Expand All @@ -132,9 +136,13 @@ public Boolean compute(Vertex argument)
if (!TagUtil.checkMatchingTags(classificationModel.getTags(), includeTags, excludeTags))
continue;
}
classificationEffort += migrationEffort;

if (!results.containsKey(migrationEffort))
results.put(migrationEffort, 1);
else
results.put(migrationEffort, results.get(migrationEffort) + 1);
}
return classificationEffort;
return results;
}

/**
Expand Down
Expand Up @@ -3,8 +3,10 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.tools.ant.taskdefs.Length.FileMode;
Expand Down Expand Up @@ -62,7 +64,7 @@ public Iterable<InlineHintModel> getHintsForFile(FileModel file)
/**
* Returns the total effort points in all of the {@link InlineHintModel} instances associated with the provided {@link FileModel}.
*/
public int getMigrationEffortPoints(FileModel fileModel)
public int getMigrationEffortDetails(FileModel fileModel)
{
GremlinPipeline<Vertex, Vertex> inlineHintPipeline = new GremlinPipeline<>(fileModel.asVertex());
inlineHintPipeline.in(InlineHintModel.FILE_MODEL);
Expand Down Expand Up @@ -120,8 +122,11 @@ public Iterable<InlineHintModel> getHintsForProject(ProjectModel projectModel, b
* <p/>
* If set to recursive, then also include the effort points from child projects.
*/
public int getMigrationEffortPoints(ProjectModel initialProject, Set<String> includeTags, Set<String> excludeTags, boolean recursive)
public Map<Integer, Integer> getMigrationEffortDetails(ProjectModel initialProject, Set<String> includeTags, Set<String> excludeTags,
boolean recursive)
{
Map<Integer, Integer> results = new HashMap<>();

final Set<Vertex> initialVertices = new HashSet<>();
if (recursive)
{
Expand Down Expand Up @@ -151,7 +156,6 @@ public Boolean compute(Vertex argument)
});
inlineHintPipeline.back("hint");

int hintEffort = 0;
for (Vertex v : inlineHintPipeline)
{
// only check tags if we have some passed in
Expand All @@ -162,8 +166,13 @@ public Boolean compute(Vertex argument)
continue;
}

hintEffort += (Integer) v.getProperty(EffortReportModel.EFFORT);
int migrationEffort = (Integer) v.getProperty(EffortReportModel.EFFORT);

if (!results.containsKey(migrationEffort))
results.put(migrationEffort, 1);
else
results.put(migrationEffort, results.get(migrationEffort) + 1);
}
return hintEffort;
return results;
}
}
@@ -1,7 +1,9 @@
package org.jboss.windup.reporting.freemarker;

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

import org.jboss.windup.config.GraphRewrite;
Expand All @@ -27,9 +29,9 @@
* @author <a href="mailto:jesse.sightler@gmail.com">Jesse Sightler</a>
*
*/
public class GetEffortForProjectMethod implements WindupFreeMarkerMethod
public class GetEffortDetailsForProjectMethod implements WindupFreeMarkerMethod
{
private static final String NAME = "getMigrationEffortPoints";
private static final String NAME = "getEffortDetailsForProject";
private ClassificationService classificationService;
private InlineHintService inlineHintService;

Expand Down Expand Up @@ -80,9 +82,21 @@ public Object exec(@SuppressWarnings("rawtypes") List arguments) throws Template
excludeTags = FreeMarkerUtil.simpleSequenceToSet((SimpleSequence) arguments.get(3));
}

Object result = classificationService.getMigrationEffortPoints(projectModel, includeTags, excludeTags, recursive)
+ inlineHintService.getMigrationEffortPoints(projectModel, includeTags, excludeTags, recursive);
Map<Integer, Integer> classificationEffortDetails = classificationService.getMigrationEffortDetails(projectModel, includeTags, excludeTags,
recursive);
Map<Integer, Integer> hintEffortDetails = inlineHintService.getMigrationEffortDetails(projectModel, includeTags, excludeTags, recursive);

Map<Integer, Integer> results = new HashMap<>(classificationEffortDetails.size() + hintEffortDetails.size());
results.putAll(classificationEffortDetails);
for (Map.Entry<Integer, Integer> entry : hintEffortDetails.entrySet())
{
if (!results.containsKey(entry.getKey()))
results.put(entry.getKey(), entry.getValue());
else
results.put(entry.getKey(), results.get(entry.getKey()) + entry.getValue());
}

ExecutionStatistics.get().end(NAME);
return result;
return results;
}
}
Expand Up @@ -58,7 +58,7 @@ public Object exec(@SuppressWarnings("rawtypes") List arguments) throws Template
StringModel fileModelArg = (StringModel) arguments.get(0);
FileModel fileModel = (FileModel) fileModelArg.getWrappedObject();

Object result = classificationService.getMigrationEffortPoints(fileModel) + inlineHintService.getMigrationEffortPoints(fileModel);
Object result = classificationService.getMigrationEffortDetails(fileModel) + inlineHintService.getMigrationEffortDetails(fileModel);
ExecutionStatistics.get().end(NAME);
return result;
}
Expand Down
Expand Up @@ -12,6 +12,7 @@
import org.jboss.windup.util.exception.WindupException;

import freemarker.ext.beans.BeanModel;
import freemarker.template.DefaultListAdapter;
import freemarker.template.SimpleSequence;
import freemarker.template.TemplateModelException;

Expand Down Expand Up @@ -97,6 +98,11 @@ else if (arg instanceof SimpleSequence)
SimpleSequence simpleSequence = (SimpleSequence) arg;
return (Iterable<FileModel>) simpleSequence.toList();
}
else if (arg instanceof DefaultListAdapter)
{
DefaultListAdapter defaultListAdapter = (DefaultListAdapter) arg;
return (Iterable<FileModel>) defaultListAdapter.getWrappedObject();
}
else
{
throw new WindupException("Unrecognized type passed to: " + getMethodName() + ": "
Expand Down
Expand Up @@ -16,6 +16,10 @@
</#macro>

<#macro applicationReportRenderer applicationReport>
<#assign effortLevels = getEffortDetailsForProject(applicationReport.projectModel, true)>
<#assign totalEffort = 0>
<#assign totalIncidents = 0>

<tr>
<td>
<a href="reports/${applicationReport.reportFilename}">${applicationReport.projectModel.rootFileModel.fileName}</a>
Expand All @@ -32,7 +36,17 @@
</#list>
</td>
<td>
${getMigrationEffortPoints(applicationReport.projectModel, true)} Story Points
<#list effortLevels?keys as effortLevel>
<div class="col-sm-1">${effortLevels?api.get(effortLevel)}</div>
<div class="col-sm-11">${getEffortDescriptionForPoints(effortLevel, true)}</div>
<#assign totalEffort = totalEffort + (effortLevel * effortLevels?api.get(effortLevel)) >
<#assign totalIncidents = totalIncidents + effortLevels?api.get(effortLevel) >
</#list>
<div class="col-sm-1">${totalIncidents}</div>
<div class="col-sm-11">Total</div>
</td>
<td>
${totalEffort}
</td>
</tr>
</#macro>
Expand Down Expand Up @@ -101,7 +115,10 @@
<!-- Table -->
<table class="table table-striped table-bordered">
<tr>
<th>Name</th><th>Technology</th><th>Effort</th>
<th>Name</th>
<th>Technology</th>
<th>Incident Count</th>
<th>Total Effort Points</th>
</tr>

<#list reportModel.relatedResources.applications.list.iterator() as applicationReport>
Expand Down
@@ -0,0 +1,8 @@
<#function getMigrationEffortPointsForProject projectModel recursive includeTags excludeTags>
<#assign effortLevels = getEffortDetailsForProject(projectModel, recursive, includeTags, excludeTags)>
<#assign totalEffort = 0>
<#list effortLevels?keys as effortLevel>
<#assign totalEffort = totalEffort + (effortLevel * effortLevels?api.get(effortLevel)) >
</#list>
<#return totalEffort>
</#function>
Expand Up @@ -2,6 +2,7 @@

import java.io.File;
import java.util.Collections;
import java.util.Map;
import java.util.Set;

import javax.inject.Inject;
Expand Down Expand Up @@ -53,7 +54,11 @@ public void testHintEffort() throws Exception

ProjectModel projectModel = fillData(context);
Set<String> emptySet = Collections.emptySet();
int totalEffort = classificationService.getMigrationEffortPoints(projectModel, emptySet, emptySet, true);
final Map<Integer, Integer> effortByCategory = classificationService.getMigrationEffortDetails(projectModel, emptySet, emptySet, true);
int totalEffort = 0;
for (Map.Entry<Integer, Integer> effortEntry : effortByCategory.entrySet())
totalEffort += effortEntry.getKey() * effortEntry.getValue();

Assert.assertEquals(143, totalEffort);

boolean foundF1Effort = false;
Expand All @@ -62,13 +67,13 @@ public void testHintEffort() throws Exception
{
if (fm.getFilePath().equals("/f1"))
{
int fileEffort = classificationService.getMigrationEffortPoints(fm);
int fileEffort = classificationService.getMigrationEffortDetails(fm);
Assert.assertEquals(140, fileEffort);
foundF1Effort = true;
}
else if (fm.getFilePath().equals("/f2"))
{
int fileEffort = classificationService.getMigrationEffortPoints(fm);
int fileEffort = classificationService.getMigrationEffortDetails(fm);
Assert.assertEquals(3, fileEffort);
foundF2Effort = true;
}
Expand Down
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import javax.inject.Inject;
Expand Down Expand Up @@ -58,7 +59,10 @@ public void testHintEffort() throws Exception

ProjectModel projectModel = fillData(context);
Set<String> emptySet = Collections.emptySet();
int totalEffort = inlineHintService.getMigrationEffortPoints(projectModel, emptySet, emptySet, true);
final Map<Integer, Integer> effortByCategory = inlineHintService.getMigrationEffortDetails(projectModel, emptySet, emptySet, true);
int totalEffort = 0;
for (Map.Entry<Integer, Integer> effortEntry : effortByCategory.entrySet())
totalEffort += effortEntry.getKey() * effortEntry.getValue();
Assert.assertEquals(153, totalEffort);

boolean foundF1Effort = false;
Expand All @@ -67,13 +71,13 @@ public void testHintEffort() throws Exception
{
if (fm.getFilePath().equals("/f1"))
{
int fileEffort = inlineHintService.getMigrationEffortPoints(fm);
int fileEffort = inlineHintService.getMigrationEffortDetails(fm);
Assert.assertEquals(150, fileEffort);
foundF1Effort = true;
}
else if (fm.getFilePath().equals("/f2"))
{
int fileEffort = inlineHintService.getMigrationEffortPoints(fm);
int fileEffort = inlineHintService.getMigrationEffortDetails(fm);
Assert.assertEquals(3, fileEffort);
foundF2Effort = true;
}
Expand Down
Expand Up @@ -9,6 +9,7 @@

import freemarker.core.CollectionAndSequence;
import freemarker.ext.beans.BeanModel;
import freemarker.template.DefaultListAdapter;
import freemarker.template.SimpleSequence;
import freemarker.template.TemplateModelException;

Expand Down Expand Up @@ -55,11 +56,16 @@ private boolean hasContent(Object arg) throws TemplateModelException
else if (arg instanceof SimpleSequence)
{
SimpleSequence simpleSequence = (SimpleSequence) arg;
return (simpleSequence.toList().size() > 0);
return simpleSequence.toList().size() > 0;
}
else if (arg instanceof DefaultListAdapter)
{
DefaultListAdapter defaultListAdapter = (DefaultListAdapter) arg;
return defaultListAdapter.size() > 0;
}
else if (arg instanceof CollectionAndSequence) {
CollectionAndSequence sequence = (CollectionAndSequence)arg;
return (sequence.size() > 0);
return sequence.size() > 0;
}
else
{
Expand Down

0 comments on commit ee9f9f0

Please sign in to comment.