Skip to content

Commit

Permalink
Windup 2203 eap javaee rules (#370)
Browse files Browse the repository at this point in the history
* windup-2203 added rules , tests and 2 test files

* windup-2203 added more info on test files, and tweaked a bit the rule

* windup-2203 fixed typo on the rule test for JACC

* windup-2203 added rules and tests for Servlet and JSON-B

* windup-2203 added test file

* windup-2203 added iterable-filter to the rule tests in order to explicitly check the number of ocurrences

* windup-2203 [PR] fixed typo
  • Loading branch information
jonathanvila authored and mrizzi committed Mar 26, 2019
1 parent f063195 commit eaaf008
Show file tree
Hide file tree
Showing 7 changed files with 394 additions and 0 deletions.
147 changes: 147 additions & 0 deletions rules-reviewed/technology-usage/javaee-technology-usage.windup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,152 @@
</technology-identified>
</perform>
</rule>
<!-- Java Authorization Contract for Containers - JACC -->
<rule id="javaee-technology-usage-00040">
<when>
<javaclass references="javax.security.jacc.{*}">
<location>IMPORT</location>
</javaclass>
</when>
<perform>
<classification title="Java Authorization Contract for Containers" category-id="information" effort="0">
<description>The application uses JACC.</description>
</classification>
<technology-tag level="INFORMATIONAL">JACC</technology-tag>
</perform>
</rule>
<!-- Java EE Management - MEJB -->
<rule id="javaee-technology-usage-00050">
<when>
<javaclass references="javax.management.j2ee.{*}">
<location>IMPORT</location>
</javaclass>
</when>
<perform>
<classification title="Java EE Management" category-id="information" effort="0">
<description>The application uses Java EE Management.</description>
</classification>
<technology-tag level="INFORMATIONAL">MEJB</technology-tag>
</perform>
</rule>

<!-- Java EE Application Deployment - EAR -->
<rule id="javaee-technology-usage-00060">
<when>
<file filename="{*}.ear"/>
</when>
<perform>
<classification title="Java EE Application Deployment" category-id="information" effort="0">
<description>The application uses Java EE Application Deployment.</description>
</classification>
<technology-tag level="INFORMATIONAL">EAR</technology-tag>
</perform>
</rule>
<!-- Web Services Metadata -->
<rule id="javaee-technology-usage-00070">
<when>
<javaclass references="javax.jws.{*}">
<location>IMPORT</location>
</javaclass>
</when>
<perform>
<classification title="Web Services Metadata" category-id="information" effort="0">
<description>The application uses Web Services Metadata</description>
</classification>
<technology-tag level="INFORMATIONAL">WS Metadata</technology-tag>
</perform>
</rule>
<!-- Common Annotations -->
<rule id="javaee-technology-usage-00080">
<when>
<javaclass references="javax.annotation.{annotation}">
<location>IMPORT</location>
</javaclass>
</when>
<perform>
<classification title="Common Annotations" category-id="information" effort="0">
<description>The application uses Common Annotations</description>
</classification>
<technology-tag level="INFORMATIONAL">Common Annotations</technology-tag>
</perform>
<where param="annotation">
<matches pattern="PreDestroy|PostConstruct|Resource|Resources"/>
</where>
</rule>
<!-- JAXB Usage -->
<rule id="javaee-technology-usage-00090">
<when>
<javaclass references="{package}.xml.bind.{*}">
<location>IMPORT</location>
</javaclass>
</when>
<perform>
<classification title="JAXB" category-id="information" effort="0">
<description>The application uses JAXB</description>
</classification>
<technology-tag level="INFORMATIONAL">JAXB</technology-tag>
</perform>
<where param="package">
<matches pattern="java|javax"/>
</where>
</rule>
<!-- JAXR Usage -->
<rule id="javaee-technology-usage-00100">
<when>
<javaclass references="javax.xml.registry.{*}">
<location>IMPORT</location>
</javaclass>
</when>
<perform>
<classification title="JAXR" category-id="information" effort="0">
<description>The application uses JAXR</description>
</classification>
<technology-tag level="INFORMATIONAL">JAXR</technology-tag>
</perform>
</rule>
<!-- Bean Validation Usage -->
<rule id="javaee-technology-usage-00110">
<when>
<javaclass references="javax.validation.constraints.{*}">
<location>IMPORT</location>
</javaclass>
</when>
<perform>
<classification title="Bean Validation" category-id="information" effort="0">
<description>The application uses Bean Validation</description>
</classification>
<technology-tag level="INFORMATIONAL">Bean Validation</technology-tag>
</perform>
</rule>
<!-- Java Servlet -->
<rule id="javaee-technology-usage-00120">
<when>
<javaclass references="javax.servlet.{*}">
<location>IMPORT</location>
</javaclass>
</when>
<perform>
<classification title="Java Servlet" category-id="information" effort="0">
<description>The application uses Java Servlets</description>
</classification>
<technology-tag level="INFORMATIONAL">Servlet</technology-tag>
</perform>
</rule>
<!-- JSON Binding -->
<rule id="javaee-technology-usage-00130">
<when>
<javaclass references="javax.json.bind.{*}">
<location>IMPORT</location>
</javaclass>
</when>
<perform>
<classification title="JSON Binding" category-id="information" effort="0">
<description>The application uses JSON binding</description>
</classification>
<technology-tag level="INFORMATIONAL">JSON-B</technology-tag>
</perform>
</rule>


</rules>
</ruleset>
30 changes: 30 additions & 0 deletions rules-reviewed/technology-usage/tests/data/javaee/JavaServlet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.jboss.windup.test;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class JavaServlet extends HttpServlet {

/**
* Example
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">");
out.println("<html>");
out.println("<head><title>Example Title</title></head>");
out.println("<body>");
out.println("<h1>¡Hi!</h1>");
out.println("</body></html>");
}
}
29 changes: 29 additions & 0 deletions rules-reviewed/technology-usage/tests/data/javaee/JsonBinding.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.jboss.windup.test;
import javax.json.bind.annotation.JsonbProperty;
import javax.json.bind.annotation.JsonbTransient;
import javax.json.bind.annotation.JsonbDateFormat;
import javax.json.bind.annotation.JsonbNumberFormat;

public class JsonBinding {

private int id;

@JsonbProperty("person-name")
private String name;

@JsonbProperty(nillable = true)
private String email;

@JsonbTransient
private int age;

@JsonbDateFormat("dd-MM-yyyy")
private LocalDate registeredDate;

private BigDecimal salary;

@JsonbNumberFormat(locale = "en_US", value = "#0.0")
public BigDecimal getSalary() {
return salary;
}
}
28 changes: 28 additions & 0 deletions rules-reviewed/technology-usage/tests/data/javaee/Security.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.jboss.windup.test;

import javax.management.j2ee.Management;
import javax.management.j2ee.ManagementHome;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.security.jacc.PolicyConfigurationFactory;

public class MyJaccProviderService {


public PolicyConfigurationFactory getPolicyConfigurationFactory() {
PolicyConfigurationFactory pcf = null;
try {
pcf = PolicyConfigurationFactory.getPolicyConfigurationFactory();
} catch (Exception e) {
return null;
}
return pcf;
}

public static Management getMEJBRemote() {
Context context = new InitialContext(null);
ManagementHome home = (ManagementHome) context.lookup("ejb.mgmt.MEJB");
Management bean = home.create();
return bean;
}
}
40 changes: 40 additions & 0 deletions rules-reviewed/technology-usage/tests/data/javaee/WebService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.jboss.windup.test;

import javax.annotation.PostConstruct;
import javax.jws.WebService;
import javax.xml.bind.JAXBContext;
import javax.xml.registry.BulkResponse;
import javax.xml.registry.BusinessLifeCycleManager;
import javax.xml.registry.Connection;
import javax.xml.registry.ConnectionFactory;
import javax.xml.registry.JAXRException;
import javax.xml.registry.RegistryService;
import javax.xml.registry.infomodel.Key;
import javax.xml.registry.infomodel.Organization;
import javax.validation.constraints.NotNull;


@WebService()
public class Hello {
@NotNull
private String myAttribute;

private String message = new String("Hello, ");

public void Hello() {}

@WebMethod()
public String sayHello(String name) {
return message + name + ".";
}

@PostConstruct
public void postConstruct() {
JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
ConnectionFactory connectionFactory = ConnectionFactory.newInstance();
System.out.println("nothing");
}



}
Empty file.

0 comments on commit eaaf008

Please sign in to comment.