diff --git a/reporting/api/src/main/java/org/jboss/windup/reporting/service/ClassificationService.java b/reporting/api/src/main/java/org/jboss/windup/reporting/service/ClassificationService.java index 2aa90b7d93..fbbd748600 100644 --- a/reporting/api/src/main/java/org/jboss/windup/reporting/service/ClassificationService.java +++ b/reporting/api/src/main/java/org/jboss/windup/reporting/service/ClassificationService.java @@ -24,6 +24,30 @@ public ClassificationService(GraphContext context) super(context, ClassificationModel.class); } + /** + * Returns the total effort points in all of the {@link ClassificationModel}s associated with the provided + * {@link FileModel}. + * + */ + public int getMigrationEffortPoints(FileModel fileModel) + { + // 1. Get all classification models + GremlinPipeline classificationPipeline = new GremlinPipeline<>(fileModel.asVertex()); + classificationPipeline.in(ClassificationModel.FILE_MODEL); + classificationPipeline.has(WindupVertexFrame.TYPE_PROP, Text.CONTAINS, ClassificationModel.TYPE); + + int classificationEffort = 0; + for (Vertex v : classificationPipeline) + { + Integer migrationEffort = v.getProperty(ClassificationModel.PROPERTY_EFFORT); + if (migrationEffort != null) + { + classificationEffort += migrationEffort; + } + } + return classificationEffort; + } + /** * Returns the total effort points in all of the {@link ClassificationModel}s associated with the files in this * project. diff --git a/reporting/api/src/main/java/org/jboss/windup/reporting/service/InlineHintService.java b/reporting/api/src/main/java/org/jboss/windup/reporting/service/InlineHintService.java index 2f815234fd..ef6510a9c1 100644 --- a/reporting/api/src/main/java/org/jboss/windup/reporting/service/InlineHintService.java +++ b/reporting/api/src/main/java/org/jboss/windup/reporting/service/InlineHintService.java @@ -39,6 +39,24 @@ public Iterable getHintsForFile(FileModel file) InlineHintModel.class); } + /** + * Returns the total effort points in all of the {@link InlineHintModel}s associated with the provided + * {@link FileModel}. + */ + public int getMigrationEffortPoints(FileModel fileModel) + { + GremlinPipeline inlineHintPipeline = new GremlinPipeline<>(fileModel.asVertex()); + inlineHintPipeline.in(InlineHintModel.FILE_MODEL); + inlineHintPipeline.has(WindupVertexFrame.TYPE_PROP, Text.CONTAINS, InlineHintModel.TYPE); + + int hintEffort = 0; + for (Vertex v : inlineHintPipeline) + { + hintEffort += (Integer) v.getProperty(InlineHintModel.EFFORT); + } + return hintEffort; + } + /** * Returns the total effort points in all of the {@link InlineHintModel}s associated with the files in this project. * diff --git a/reporting/impl/src/main/java/org/jboss/windup/reporting/freemarker/GetEffortForFile.java b/reporting/impl/src/main/java/org/jboss/windup/reporting/freemarker/GetEffortForFile.java new file mode 100644 index 0000000000..c503abbe76 --- /dev/null +++ b/reporting/impl/src/main/java/org/jboss/windup/reporting/freemarker/GetEffortForFile.java @@ -0,0 +1,55 @@ +package org.jboss.windup.reporting.freemarker; + +import java.util.List; + +import org.jboss.windup.graph.GraphContext; +import org.jboss.windup.graph.model.resource.FileModel; +import org.jboss.windup.reporting.service.ClassificationService; +import org.jboss.windup.reporting.service.InlineHintService; + +import freemarker.ext.beans.StringModel; +import freemarker.template.TemplateModelException; + +/** + * Gets the number of effort points involved in migrating this particular file + * + * Called from a freemarker template as follows: + * + * getMigrationEffortPointsForFile(FileModel):int + * + * @author jsightler + * + */ +public class GetEffortForFile implements WindupFreeMarkerMethod +{ + private ClassificationService classificationService; + private InlineHintService inlineHintService; + + @Override + public void setGraphContext(GraphContext context) + { + this.classificationService = new ClassificationService(context); + this.inlineHintService = new InlineHintService(context); + } + + @Override + public String getMethodName() + { + return "getMigrationEffortPointsForFile"; + } + + @Override + public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException + { + if (arguments.size() != 1) + { + throw new TemplateModelException( + "Error, method expects two arguments (FileModel)"); + } + StringModel fileModelArg = (StringModel) arguments.get(0); + FileModel fileModel = (FileModel) fileModelArg.getWrappedObject(); + + return classificationService.getMigrationEffortPoints(fileModel) + + inlineHintService.getMigrationEffortPoints(fileModel); + } +} diff --git a/reporting/impl/src/main/resources/reports/templates/source.ftl b/reporting/impl/src/main/resources/reports/templates/source.ftl index 221bdb1cf1..9c4da76461 100644 --- a/reporting/impl/src/main/resources/reports/templates/source.ftl +++ b/reporting/impl/src/main/resources/reports/templates/source.ftl @@ -63,6 +63,7 @@

Classification

    +
  • Estimated Story Points: ${getMigrationEffortPointsForFile(reportModel.sourceFileModel)}
  • <#list getTechnologyTagsForFile(reportModel.sourceFileModel).iterator() as techTag> ${techTag.name} diff --git a/reporting/tests/src/test/java/org/jboss/windup/reporting/ClassificationServiceTest.java b/reporting/tests/src/test/java/org/jboss/windup/reporting/ClassificationServiceTest.java index afa2d8f112..fdd46963f6 100644 --- a/reporting/tests/src/test/java/org/jboss/windup/reporting/ClassificationServiceTest.java +++ b/reporting/tests/src/test/java/org/jboss/windup/reporting/ClassificationServiceTest.java @@ -58,7 +58,27 @@ public void testHintEffort() throws Exception ProjectModel projectModel = fillData(context); int totalEffort = classificationService.getMigrationEffortPoints(projectModel, true); - Assert.assertEquals(140, totalEffort); + Assert.assertEquals(143, totalEffort); + + boolean foundF1Effort = false; + boolean foundF2Effort = false; + for (FileModel fm : projectModel.getFileModels()) + { + if (fm.getFilePath().equals("/f1")) + { + int fileEffort = classificationService.getMigrationEffortPoints(fm); + Assert.assertEquals(140, fileEffort); + foundF1Effort = true; + } + else if (fm.getFilePath().equals("/f2")) + { + int fileEffort = classificationService.getMigrationEffortPoints(fm); + Assert.assertEquals(3, fileEffort); + foundF2Effort = true; + } + } + Assert.assertTrue(foundF1Effort); + Assert.assertTrue(foundF2Effort); } } @@ -78,6 +98,10 @@ private ProjectModel fillData(GraphContext context) b1b.addFileModel(f1); b1b.setEffort(120); + ClassificationModel b2 = classificationService.create(); + b2.addFileModel(f2); + b2.setEffort(3); + ProjectModel projectModel = context.getFramed().addVertex(null, ProjectModel.class); projectModel.addFileModel(f1); f1.setProjectModel(projectModel); diff --git a/reporting/tests/src/test/java/org/jboss/windup/reporting/InlineHintServiceTest.java b/reporting/tests/src/test/java/org/jboss/windup/reporting/InlineHintServiceTest.java index 2f73fe352f..c70cc09a72 100644 --- a/reporting/tests/src/test/java/org/jboss/windup/reporting/InlineHintServiceTest.java +++ b/reporting/tests/src/test/java/org/jboss/windup/reporting/InlineHintServiceTest.java @@ -58,7 +58,27 @@ public void testHintEffort() throws Exception ProjectModel projectModel = fillData(context); int totalEffort = inlineHintService.getMigrationEffortPoints(projectModel, true); - Assert.assertEquals(150, totalEffort); + Assert.assertEquals(153, totalEffort); + + boolean foundF1Effort = false; + boolean foundF2Effort = false; + for (FileModel fm : projectModel.getFileModels()) + { + if (fm.getFilePath().equals("/f1")) + { + int fileEffort = inlineHintService.getMigrationEffortPoints(fm); + Assert.assertEquals(150, fileEffort); + foundF1Effort = true; + } + else if (fm.getFilePath().equals("/f2")) + { + int fileEffort = inlineHintService.getMigrationEffortPoints(fm); + Assert.assertEquals(3, fileEffort); + foundF2Effort = true; + } + } + Assert.assertTrue(foundF1Effort); + Assert.assertTrue(foundF2Effort); } } @@ -78,6 +98,10 @@ private ProjectModel fillData(GraphContext context) b1b.setFile(f1); b1b.setEffort(100); + InlineHintModel b2 = inlineHintService.create(); + b2.setEffort(3); + b2.setFile(f2); + ProjectModel projectModel = context.getFramed().addVertex(null, ProjectModel.class); projectModel.addFileModel(f1); f1.setProjectModel(projectModel); diff --git a/rules-java/src/main/resources/reports/templates/java_application.ftl b/rules-java/src/main/resources/reports/templates/java_application.ftl index c3bd78409f..904dced1a0 100644 --- a/rules-java/src/main/resources/reports/templates/java_application.ftl +++ b/rules-java/src/main/resources/reports/templates/java_application.ftl @@ -33,6 +33,10 @@
+ + <#assign fileEffort = getMigrationEffortPointsForFile(sourceReportModel.sourceFileModel)> + ${fileEffort} + @@ -42,6 +46,13 @@

${projectModel.rootFileModel.prettyPath}

+
+
+ ${getMigrationEffortPoints(projectModel, false)} +
+
Story Points
+
+
@@ -49,7 +60,7 @@
- + <#list sortFilesByPathAscending(projectModel.fileModelsNoDirectories) as fileModel> <@fileModelRenderer fileModel/> diff --git a/test-util/src/main/java/org/jboss/windup/testutil/html/TestJavaApplicationOverviewUtil.java b/test-util/src/main/java/org/jboss/windup/testutil/html/TestJavaApplicationOverviewUtil.java index 77f96fd1e3..1cd59a9c6b 100644 --- a/test-util/src/main/java/org/jboss/windup/testutil/html/TestJavaApplicationOverviewUtil.java +++ b/test-util/src/main/java/org/jboss/windup/testutil/html/TestJavaApplicationOverviewUtil.java @@ -15,6 +15,50 @@ public class TestJavaApplicationOverviewUtil extends TestReportUtil { + /** + * Checks if the given App section, filepath, and effort level can be seen in the report. + * + * For example checkFilePathEffort("src_example", "src/main/resources/test.properties", 13) will ensure that an + * application called "src_example" is in the report, with a line referencing "src/main/resources/test.properties" + * and that this line contains the effort level 13). + */ + public boolean checkFilePathEffort(String appSection, String filePath, int effort) + { + WebElement appSectionEl = getAppSectionElement(appSection); + if (appSectionEl == null) + { + return false; + } + + WebElement fileRowElement = getFileRowElement(appSection, filePath); + if (fileRowElement == null) + { + return false; + } + + List elements = fileRowElement.findElements(By.xpath("./td[position() = 4]")); + for (WebElement element : elements) + { + if (element.getText() != null) + { + try + { + int number = Integer.parseInt(element.getText()); + if (number == effort) + { + return true; + } + } + catch (NumberFormatException e) + { + // ignore + } + + } + } + return false; + } + /** * Checks if the given App section, filepath, and tag can be found in the report. * diff --git a/tests/src/test/java/org/jboss/windup/tests/application/WindupArchitectureMediumBinaryModeTest.java b/tests/src/test/java/org/jboss/windup/tests/application/WindupArchitectureMediumBinaryModeTest.java index ef68678637..ab5ace711d 100644 --- a/tests/src/test/java/org/jboss/windup/tests/application/WindupArchitectureMediumBinaryModeTest.java +++ b/tests/src/test/java/org/jboss/windup/tests/application/WindupArchitectureMediumBinaryModeTest.java @@ -1,6 +1,8 @@ package org.jboss.windup.tests.application; import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; @@ -10,8 +12,12 @@ import org.jboss.forge.furnace.repositories.AddonDependencyEntry; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.windup.graph.GraphContext; +import org.jboss.windup.reporting.model.ReportModel; +import org.jboss.windup.reporting.service.ReportService; import org.jboss.windup.rules.apps.java.model.JarManifestModel; +import org.jboss.windup.rules.apps.java.reporting.rules.CreateJavaApplicationOverviewReportRuleProvider; import org.jboss.windup.rules.apps.java.service.JarManifestService; +import org.jboss.windup.testutil.html.TestJavaApplicationOverviewUtil; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -26,6 +32,8 @@ public class WindupArchitectureMediumBinaryModeTest extends WindupArchitectureTe @AddonDependency(name = "org.jboss.windup.reporting:windup-reporting"), @AddonDependency(name = "org.jboss.windup.exec:windup-exec"), @AddonDependency(name = "org.jboss.windup.rules.apps:rules-java"), + @AddonDependency(name = "org.jboss.windup.rules.apps:rules-java-ee"), + @AddonDependency(name = "org.jboss.windup.tests:test-util"), @AddonDependency(name = "org.jboss.windup.ext:windup-config-groovy"), @AddonDependency(name = "org.jboss.forge.furnace.container:cdi"), }) @@ -40,6 +48,8 @@ public static ForgeArchive getDeployment() AddonDependencyEntry.create("org.jboss.windup.reporting:windup-reporting"), AddonDependencyEntry.create("org.jboss.windup.exec:windup-exec"), AddonDependencyEntry.create("org.jboss.windup.rules.apps:rules-java"), + AddonDependencyEntry.create("org.jboss.windup.rules.apps:rules-java-ee"), + AddonDependencyEntry.create("org.jboss.windup.tests:test-util"), AddonDependencyEntry.create("org.jboss.windup.ext:windup-config-groovy"), AddonDependencyEntry.create("org.jboss.forge.furnace.container:cdi") ); @@ -55,6 +65,7 @@ public void testRunWindupMedium() throws Exception { super.runTest(context, path, false); validateManifestEntries(context); + validateReports(context); } } @@ -80,4 +91,25 @@ private void validateManifestEntries(GraphContext context) throws Exception Assert.assertEquals(9, numberFound); Assert.assertTrue(warManifestFound); } + + /** + * Validate that the report pages were generated correctly + */ + private void validateReports(GraphContext context) + { + ReportService reportService = new ReportService(context); + ReportModel reportModel = reportService.getUniqueByProperty( + ReportModel.TEMPLATE_PATH, + CreateJavaApplicationOverviewReportRuleProvider.TEMPLATE_APPLICATION_REPORT); + Path appReportPath = Paths.get(reportService.getReportDirectory(), reportModel.getReportFilename()); + + TestJavaApplicationOverviewUtil util = new TestJavaApplicationOverviewUtil(); + util.loadPage(appReportPath); + Assert.assertTrue(util.checkFilePathAndTag("Windup1x-javaee-example.war", + "META-INF/maven/javaee/javaee/pom.properties", "Properties")); + Assert.assertTrue(util.checkFilePathEffort("Windup1x-javaee-example.war", + "META-INF/maven/javaee/javaee/pom.properties", 0)); + Assert.assertTrue(util.checkFilePathEffort("Windup1x-javaee-example.war/WEB-INF/lib/joda-time-2.0.jar", + "org.joda.time.tz.DateTimeZoneBuilder", 48)); + } }
NameTechnologyIssuesNameTechnologyIssuesEstimated Story Points