Opened 3 years ago

Closed 3 years ago

#2151 closed enhancement (fixed)

Pre-compile all JSP pages before releases

Reported by: Nicklas Nordborg Owned by: Nicklas Nordborg
Priority: major Milestone: BASE 3.15
Component: build Version:
Keywords: Cc:

Description

The bug in #2143 got me thinking that it would be nice if there was a way to check that all JSP files compile without error before making a release. We already have the CompileAll servlet in web.xml which can do this but we get no information about code that is using deprecated methods or other warnings.

To my surprise I also found a very old commit [1990] which added an ant task for compiling the JSP pages. It turns out that it is still present in build.xml under the name web.jsp. It still works if adding strictQuoteEscaping="false" to the <jasper2> command.

However, I think we should check the current Tomcat documentation and see if we can improve it.

https://tomcat.apache.org/tomcat-8.5-doc/jasper-howto.html#Web_Application_Compilation

We should also add a point in the release instructions to perform this check.

Change History (15)

comment:1 Changed 3 years ago by Nicklas Nordborg

Owner: set to Nicklas Nordborg
Status: newaccepted

comment:2 Changed 3 years ago by Nicklas Nordborg

In 7600:

References #2151: Pre-compile all JSP pages before releases

Added jsp target to the build-file. tomcat.home must be set and point to a directory with a Tomcat installation that includes the build tools (eg. ${tomcat.home}/bin/catalina-tasks.xml). Note that this is not included in all Tomcat distributions. We recommend using the ZIP file.

We recommend that a build.properties file is created in the root directory and that tomcat.home is set in that file.

The jsp target will load the jsp-precompile.xml file (which is an ant file), and will use <jasper> to pre-compile JSP to java and then a regular <javac> to compile the the java code. The compilation currently generates lots of warnings. The goal is to make them all go away with only Xlint:all,-serial. Currently all,-serial,-unchecked,-rawtypes,-deprecation,-cast is needed which can be specified by setting jsp.xlint in build.properties.

Use the jsp.clean ant target to clean files created by JSP compilation. This is also included in clean but it is typically overkill to have to recompile the entire BASE application.

comment:3 Changed 3 years ago by Nicklas Nordborg

In 7601:

References #2151: Pre-compile all JSP pages before releases

Getting rid of cast warnings.

comment:4 Changed 3 years ago by Nicklas Nordborg

In 7602:

References #2151: Pre-compile all JSP pages before releases

Do not compile JSP:s belonging to extensions. Unfortunately it seems to be impossible to tell jasper to ignore but we can at least skip the compilation step.

comment:5 Changed 3 years ago by Nicklas Nordborg

In 7603:

References #2151: Pre-compile all JSP pages before releases

Getting rid of deprecation warnings except those that are related to spot images since they should be fixed by #2136.

comment:6 Changed 3 years ago by Nicklas Nordborg

In 7604:

References #2151: Pre-compile all JSP pages before releases

Getting rid of rawtypes warnings. Most of them are relatively simple by adding a type parameter.

Utility functions that are used with generics are typically a bit harder.

comment:7 Changed 3 years ago by Nicklas Nordborg

In 7605:

References #2151: Pre-compile all JSP pages before releases

Getting rid of a lot of unchecked warnings. Most of them are solved by changed the API in several BASE core clases to use implict casting of return types instead of explicit (this moved the 'unchecked' warning to the API method from the caller). Example:

// Before
ItemContext cc = ...
Hardware hardware = (Hardware)cc.getObject("item");

// After
Hardware hardware = cc.getObject("item");

In most cases both the old and new version of the code will work, but if the returned object is using a "type" parameter it will not compile:

// This will not compile!
Set<AnnotatedItem> items = (Set<AnnotatedItem>)cc.getObject("AnnotatedItems");

// But this will!
Set<AnnotatedItem> items = cc.getObject("AnnotatedItems");

Note that existing compiled code will still work, but that some changes may be needed when compiling agains BASE 3.15. The issues should be easy to solve (eg. remove an explict cast).

Extensions that uses JSP files that works in BASE 3.14 may stop working in BASE 3.15 since the compilation of the JSP files happens on the BASE server as they are accessed.

Another issues is that there are still a lot of unchecked warnings related to the JSON library. This build on regular Map and List API:s but has not specified generic type parameters so there is no way to get rid of those warnings without fixing the JSON library source code. The latest released version is from 2012 so it is not likely that this should happen unless we do it ourselves (the warnings are really annoying so maybe we should!).

comment:8 Changed 3 years ago by Nicklas Nordborg

In 7606:

References #2151: Pre-compile all JSP pages before releases

Switched to JSON.simple 1.1.1-1 from http://dev.thep.lu.se/basehacks/wiki/JSON.simple

There is now only a single "unchecked" compilation warning remaining.

comment:9 Changed 3 years ago by Nicklas Nordborg

In 7607:

References #2151: Pre-compile all JSP pages before releases

Printing the path to Tomcat home when compiling.

comment:10 Changed 3 years ago by Nicklas Nordborg

In 7608:

References #2151: Pre-compile all JSP pages before releases

After testing a live Tomcat installation it was noted that some JSP files would not compile even though the pre-compilation worked. Investigations discovered that Tomcat has a default setting to compile with source/target version set to 1.7. Setting the same version when pre-compiling resulted in the same errors. To solve this we need to override the global *.jsp servlet declaration in our own web.xml. Here we can also include the 'strictQuoteEscaping' parameter so we should not have to configure this during the installation.

comment:11 Changed 3 years ago by Nicklas Nordborg

In 7609:

References #2151: Pre-compile all JSP pages before releases

Updated documentation with changes related to source code incompatibilities.

comment:12 Changed 3 years ago by Nicklas Nordborg

In 7610:

References #2151: Pre-compile all JSP pages before releases

Changed some more methods to use generic return values to get rid of the last "checked" warning in the JSP files.

comment:13 Changed 3 years ago by Nicklas Nordborg

In 7611:

References #2151: Pre-compile all JSP pages before releases

Fixes a compilation error that was not detected by Eclipse.

comment:14 Changed 3 years ago by Nicklas Nordborg

In 7634:

References #2151: Pre-compile all JSP pages before releases

Removing cast that is not needed.

comment:15 Changed 3 years ago by Nicklas Nordborg

Resolution: fixed
Status: acceptedclosed
Note: See TracTickets for help on using tickets.