Skip to content

Commit

Permalink
add profile covering javax.servlet only
Browse files Browse the repository at this point in the history
For my application I'd like to migrate javax.servlet only.
Other packages, such as javax.mail are part of the web application,
thus no affected by the tomcat upgrade.
  • Loading branch information
rw7 committed Aug 9, 2024
1 parent cd6cd7d commit 8a844ff
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/org/apache/tomcat/jakartaee/EESpecProfiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
*/
public enum EESpecProfiles implements EESpecProfile {

/**
* Specification profile matching the Jakarta Servlet API only.
*/
SERVLET("javax", "jakarta",
"javax([/\\.](servlet))"),

/**
* Specification profile matching the packages provided with Tomcat.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ where options includes:\n\
\ -profile=<profile name>\n\
\ TOMCAT (default) to convert Java EE APIs provided by Tomcat\n\
\ EE to convert all Java EE APIs\n\
\ SERVLET to convert the Jakarta Servlet API only\n\
\ JEE8 to convert back to old Java EE8 APIs. Note that the\n\
\ resulting classes will not work if the classes to be\n\
\ migrated use any APIs added in Jakarta EE 10 onwards.\n\
Expand Down
60 changes: 60 additions & 0 deletions src/test/java/org/apache/tomcat/jakartaee/EESpecProfileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,66 @@

public class EESpecProfileTest {

@Test
public void testProfileServlet() {
EESpecProfile profile = EESpecProfiles.SERVLET;

assertEquals("javax.annotation.PostConstruct", profile.convert("javax.annotation.PostConstruct"));
assertEquals("javax.annotation.security.DeclareRoles", profile.convert("javax.annotation.security.DeclareRoles"));
assertEquals("javax.ejb", profile.convert("javax.ejb"));
assertEquals("javax.el", profile.convert("javax.el"));
assertEquals("javax.mail", profile.convert("javax.mail"));
assertEquals("javax.persistence", profile.convert("javax.persistence"));
assertEquals("javax.security.auth.message", profile.convert("javax.security.auth.message"));
assertEquals("jakarta.servlet", profile.convert("javax.servlet"));
assertEquals("javax.transaction", profile.convert("javax.transaction"));
assertEquals("javax.websocket", profile.convert("javax.websocket"));

// not converted EE packages
assertEquals("javax.activation", profile.convert("javax.activation"));
assertEquals("javax.batch", profile.convert("javax.batch"));
assertEquals("javax.decorator", profile.convert("javax.decorator"));
assertEquals("javax.enterprise", profile.convert("javax.enterprise"));
assertEquals("javax.faces", profile.convert("javax.faces"));
assertEquals("javax.jms", profile.convert("javax.jms"));
assertEquals("javax.json", profile.convert("javax.json"));
assertEquals("javax.jws", profile.convert("javax.jws"));
assertEquals("javax.interceptor", profile.convert("javax.interceptor"));
assertEquals("javax.inject", profile.convert("javax.inject"));
assertEquals("javax.management.j2ee", profile.convert("javax.management.j2ee"));
assertEquals("javax.resource", profile.convert("javax.resource"));
assertEquals("javax.security.enterprise", profile.convert("javax.security.enterprise"));
assertEquals("javax.security.jacc", profile.convert("javax.security.jacc"));
assertEquals("javax.validation", profile.convert("javax.validation"));
assertEquals("javax.ws.rs", profile.convert("javax.ws.rs"));
assertEquals("javax.xml.bind", profile.convert("javax.xml.bind"));
assertEquals("javax.xml.rpc", profile.convert("javax.xml.rpc"));
assertEquals("javax.xml.registry", profile.convert("javax.xml.registry"));
assertEquals("javax.xml.soap", profile.convert("javax.xml.soap"));
assertEquals("javax.xml.ws", profile.convert("javax.xml.ws"));

// non EE javax packages
assertEquals("javax.annotation", profile.convert("javax.annotation"));
assertEquals("javax.management", profile.convert("javax.management"));
assertEquals("javax.security", profile.convert("javax.security"));
assertEquals("javax.security.auth", profile.convert("javax.security.auth"));
assertEquals("javax.swing", profile.convert("javax.swing"));
assertEquals("javax.transaction.xa", profile.convert("javax.transaction.xa"));
assertEquals("javax.xml.stream", profile.convert("javax.xml.stream"));
assertEquals("javax.xml.namespace", profile.convert("javax.xml.namespace"));
assertEquals("javax.xml.xpath.XPathConstants", profile.convert("javax.xml.xpath.XPathConstants"));
assertEquals("javax.xml.XMLConstants", profile.convert("javax.xml.XMLConstants"));

// Findbugs JSR-305 packages and classes
assertEquals("javax.annotation.concurrent", profile.convert("javax.annotation.concurrent"));
assertEquals("javax.annotation.meta", profile.convert("javax.annotation.meta"));
assertEquals("javax.annotation.PropertyKey", profile.convert("javax.annotation.PropertyKey"));

// Annotation classes that overlap between earlier and later annotations implementations
assertEquals("javax.annotation.Nonnull", profile.convert("javax.annotation.Nonnull"));
assertEquals("javax.annotation.Nullable", profile.convert("javax.annotation.Nullable"));
}

@Test
public void testProfileTomcat() {
EESpecProfile profile = EESpecProfiles.TOMCAT;
Expand Down

0 comments on commit 8a844ff

Please sign in to comment.