Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'bradsdavis-static-ip-addresses'
- Loading branch information
Showing
11 changed files
with
321 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...ain/java/org/jboss/windup/rules/apps/java/ip/CreateStaticIPAddressReportRuleProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package org.jboss.windup.rules.apps.java.ip; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.jboss.windup.config.GraphRewrite; | ||
import org.jboss.windup.config.WindupRuleProvider; | ||
import org.jboss.windup.config.operation.GraphOperation; | ||
import org.jboss.windup.config.phase.ReportGeneration; | ||
import org.jboss.windup.config.phase.RulePhase; | ||
import org.jboss.windup.config.query.Query; | ||
import org.jboss.windup.graph.GraphContext; | ||
import org.jboss.windup.graph.model.ProjectModel; | ||
import org.jboss.windup.graph.model.WindupConfigurationModel; | ||
import org.jboss.windup.graph.model.WindupVertexFrame; | ||
import org.jboss.windup.graph.service.GraphService; | ||
import org.jboss.windup.graph.service.WindupConfigurationService; | ||
import org.jboss.windup.reporting.model.ApplicationReportModel; | ||
import org.jboss.windup.reporting.model.TemplateType; | ||
import org.jboss.windup.reporting.model.WindupVertexListModel; | ||
import org.jboss.windup.reporting.service.ApplicationReportService; | ||
import org.jboss.windup.reporting.service.ReportService; | ||
import org.ocpsoft.rewrite.config.Configuration; | ||
import org.ocpsoft.rewrite.config.ConfigurationBuilder; | ||
import org.ocpsoft.rewrite.context.EvaluationContext; | ||
|
||
/** | ||
* Finds files that contain potential static IP addresses, determined by regular expression. | ||
* | ||
* @author <a href="mailto:bradsdavis@gmail.com">Brad Davis</a> | ||
*/ | ||
public class CreateStaticIPAddressReportRuleProvider extends WindupRuleProvider | ||
{ | ||
private static final String TITLE = "Static IP Addresses"; | ||
public static final String TEMPLATE_REPORT = "/reports/templates/static_ip_addresses.ftl"; | ||
|
||
@Override | ||
public Class<? extends RulePhase> getPhase() | ||
{ | ||
return ReportGeneration.class; | ||
} | ||
|
||
@Override | ||
public Configuration getConfiguration(final GraphContext graphContext) | ||
{ | ||
|
||
return ConfigurationBuilder | ||
.begin() | ||
.addRule() | ||
// when a IP Location Model exists... | ||
.when(Query.fromType(StaticIPLocationModel.class)) | ||
// perform the write of this report once (GraphOperation)... | ||
.perform(new GraphOperation() | ||
{ | ||
|
||
@Override | ||
public void perform(GraphRewrite event, EvaluationContext context) | ||
{ | ||
// configuration of current execution | ||
WindupConfigurationModel configurationModel = WindupConfigurationService.getConfigurationModel(event.getGraphContext()); | ||
|
||
// reference to input project model | ||
ProjectModel projectModel = configurationModel.getInputPath().getProjectModel(); | ||
createIPReport(event.getGraphContext(), projectModel); | ||
} | ||
}); | ||
} | ||
|
||
private ApplicationReportModel createIPReport(GraphContext context, ProjectModel rootProjectModel) | ||
{ | ||
ApplicationReportService applicationReportService = new ApplicationReportService(context); | ||
|
||
// create a reference in the graph to the static ip location report. | ||
ApplicationReportModel applicationReport = applicationReportService.create(); | ||
|
||
applicationReport.setReportPriority(600); | ||
applicationReport.setReportName(TITLE); | ||
applicationReport.setTemplatePath(TEMPLATE_REPORT); | ||
applicationReport.setDisplayInApplicationReportIndex(true); | ||
applicationReport.setTemplateType(TemplateType.FREEMARKER); | ||
applicationReport.setProjectModel(rootProjectModel); | ||
|
||
// find all IPLocationModels | ||
GraphService<StaticIPLocationModel> ipLocationModelService = new GraphService<StaticIPLocationModel>(context, StaticIPLocationModel.class); | ||
Iterable<StaticIPLocationModel> results = ipLocationModelService.findAll(); | ||
|
||
Map<String, WindupVertexFrame> relatedData = new HashMap<>(1); | ||
WindupVertexListModel staticIPList = new GraphService<WindupVertexListModel>(context, WindupVertexListModel.class).create(); | ||
for (StaticIPLocationModel location : results) | ||
{ | ||
staticIPList.addItem(location); | ||
} | ||
relatedData.put("staticIPLocations", staticIPList); | ||
applicationReport.setRelatedResource(relatedData); | ||
|
||
// performs methods on the graph to create a unique file name. | ||
ReportService reportService = new ReportService(context); | ||
|
||
// uses project model's name for the report name. | ||
reportService.setUniqueFilename(applicationReport, "static_ips" + rootProjectModel.getName(), "html"); | ||
return applicationReport; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...rc/main/java/org/jboss/windup/rules/apps/java/ip/DiscoverStaticIPAddressRuleProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.jboss.windup.rules.apps.java.ip; | ||
|
||
import org.jboss.windup.config.GraphRewrite; | ||
import org.jboss.windup.config.WindupRuleProvider; | ||
import org.jboss.windup.config.operation.ruleelement.AbstractIterationOperation; | ||
import org.jboss.windup.config.phase.MigrationRules; | ||
import org.jboss.windup.config.phase.RulePhase; | ||
import org.jboss.windup.graph.GraphContext; | ||
import org.jboss.windup.graph.service.GraphService; | ||
import org.jboss.windup.rules.files.condition.FileContent; | ||
import org.jboss.windup.rules.files.model.FileLocationModel; | ||
import org.ocpsoft.rewrite.config.Configuration; | ||
import org.ocpsoft.rewrite.config.ConfigurationBuilder; | ||
import org.ocpsoft.rewrite.context.EvaluationContext; | ||
|
||
/** | ||
* Finds files that contain potential static IP addresses, determined by regular | ||
* expression. | ||
* | ||
* @author <a href="mailto:bradsdavis@gmail.com">Brad Davis</a> | ||
*/ | ||
public class DiscoverStaticIPAddressRuleProvider extends WindupRuleProvider { | ||
@Override | ||
public Class<? extends RulePhase> getPhase() { | ||
return MigrationRules.class; | ||
} | ||
|
||
@Override | ||
public Configuration getConfiguration(GraphContext context) { | ||
|
||
return ConfigurationBuilder | ||
.begin() | ||
.addRule() | ||
.when(FileContent.matches("{ip}").inFilesNamed("{*}.{type}")) | ||
.perform(new AbstractIterationOperation<FileLocationModel>() { | ||
public void perform(GraphRewrite event, EvaluationContext context, FileLocationModel payload) { | ||
//for all file location models that match the regular expression in the where clause, add the IP Location Model to the graph | ||
GraphService.addTypeToModel(event.getGraphContext(), payload, StaticIPLocationModel.class); | ||
}; | ||
}) | ||
.where("ip").matches("\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b") | ||
.where("type").matches("java|properties|xml"); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
rules-java/src/main/java/org/jboss/windup/rules/apps/java/ip/StaticIPLocationModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.jboss.windup.rules.apps.java.ip; | ||
|
||
import org.jboss.windup.rules.files.model.FileLocationModel; | ||
|
||
import com.tinkerpop.frames.modules.typedgraph.TypeValue; | ||
|
||
/** | ||
* Contains a Java package name | ||
* | ||
*/ | ||
@TypeValue(StaticIPLocationModel.TYPE) | ||
public interface StaticIPLocationModel extends FileLocationModel | ||
{ | ||
String TYPE = "StaticIPLocationModel"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
rules-java/src/main/resources/reports/templates/static_ip_addresses.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<#assign applicationReportIndexModel = reportModel.applicationReportIndexModel> | ||
|
||
<#macro tagRenderer tag> | ||
<span class="label label-${tag.level.name()?lower_case}"><#nested/></span> | ||
</#macro> | ||
|
||
<#macro staticIpFileRenderer reportModel> | ||
<div class="panel panel-primary"> | ||
<table class="table table-striped table-bordered" id="staticIPTable"> | ||
<tr> | ||
<th>Path</th> | ||
<th>Location</th> | ||
<th>IP Address</th> | ||
</tr> | ||
|
||
<#list reportModel.relatedResources.staticIPLocations.list.iterator() as staticIpRef> | ||
<tr> | ||
<td> <#if staticIpRef.file.prettyPath?has_content> ${staticIpRef.file.prettyPath} </#if> </td> | ||
<td> <#if staticIpRef.lineNumber?has_content>Line Number ${staticIpRef.lineNumber}, </#if><#if staticIpRef.columnNumber?has_content>Column Number ${staticIpRef.columnNumber} </#if> </td> | ||
<td> <#if staticIpRef.sourceSnippit?has_content> ${staticIpRef.sourceSnippit} </#if> </td> | ||
</tr> | ||
</#list> | ||
</table> | ||
</div> | ||
|
||
</#macro> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<title>${reportModel.projectModel.name} - Static IP Address Files</title> | ||
<link href="resources/css/bootstrap.min.css" rel="stylesheet"> | ||
<link href="resources/css/windup.css" rel="stylesheet" media="screen"> | ||
<link href="resources/css/windup.java.css" rel="stylesheet" media="screen"> | ||
</head> | ||
<body role="document"> | ||
|
||
<!-- Fixed navbar --> | ||
<div class="navbar-fixed-top windup-bar" role="navigation"> | ||
<div class="container theme-showcase" role="main"> | ||
<img src="resources/img/windup-logo.png" class="logo"/> | ||
</div> | ||
</div> | ||
|
||
<div class="container" role="main"> | ||
<div class="row"> | ||
<div class="page-header page-header-no-border"> | ||
<h1>Files Containing Static IPs for <span class="slash">/</span><small style="margin-left: 20px; font-weight: 100;">${reportModel.projectModel.name}</small></h1> | ||
<div class="navbar navbar-default"> | ||
<div class="navbar-header"> | ||
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse"> | ||
<span class="icon-bar"></span> | ||
<span class="icon-bar"></span> | ||
<span class="icon-bar"></span> | ||
</button> | ||
</div> | ||
<div class="navbar-collapse collapse navbar-responsive-collapse"> | ||
<ol class="breadcrumb top-menu"> | ||
<li><a href="../index.html">All Applications</a></li> | ||
<#include "include/breadcrumbs.ftl"> | ||
</ol> | ||
|
||
</div><!-- /.nav-collapse --> | ||
<div class="navbar-collapse collapse navbar-responsive-collapse"> | ||
<ul class="nav navbar-nav"> | ||
<#include "include/navbar.ftl"> | ||
</ul> | ||
</div><!-- /.nav-collapse --> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="container theme-showcase" role="main"> | ||
<@staticIpFileRenderer reportModel /> | ||
</div> | ||
</div> <!-- /container --> | ||
|
||
|
||
<script src="resources/js/jquery-1.10.1.min.js"></script> | ||
<script src="resources/libraries/flot/jquery.flot.min.js"></script> | ||
<script src="resources/libraries/flot/jquery.flot.pie.min.js"></script> | ||
<script src="resources/js/bootstrap.min.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
test-util/src/main/java/org/jboss/windup/testutil/html/TestStaticIPReportUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.jboss.windup.testutil.html; | ||
|
||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.WebElement; | ||
|
||
/** | ||
* Tests the contents of the static ip report | ||
*/ | ||
public class TestStaticIPReportUtil extends TestReportUtil | ||
{ | ||
|
||
/** | ||
* Checks that a sis listed with the given filename, location, and IP | ||
*/ | ||
public boolean checkStaticIPInReport(String filename, String locationInFile, String ip) | ||
{ | ||
WebElement element = getDriver().findElement(By.id("staticIPTable")); | ||
if (element == null) | ||
{ | ||
throw new CheckFailedException("Unable to find static IP table element"); | ||
} | ||
return checkValueInTable(element, filename, locationInFile, ip); | ||
} | ||
} |
Oops, something went wrong.