Bug 63691 - Add a no-op JarScanner
Summary: Add a no-op JarScanner
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 9
Classification: Unclassified
Component: Catalina (show other bugs)
Version: unspecified
Hardware: PC All
: P2 enhancement (vote)
Target Milestone: -----
Assignee: Tomcat Developers Mailing List
URL:
Keywords: Beginner
Depends on:
Blocks:
 
Reported: 2019-08-24 19:45 UTC by Igal Sapir
Modified: 2020-03-23 22:11 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Igal Sapir 2019-08-24 19:45:49 UTC
When running Tomcat in embedded mode it is many times desired to skip all of the jar scanning in favor of a faster startup.  While it's possible to create an anonymous class, I propose to add a simple NoOp class, e.g. 
org.apache.tomcat.util.scan.NoopJarScanner, possibly with a Singleton instance, which will have do nothing.

Then we'd be able to easily call `context.setJarScanner(NoopJarScanner.INSTANCE)`.

If approved, I'd be happy to implement it.
Comment 1 Mark Thomas 2019-08-30 18:14:15 UTC
Why not just do

System.setProperty("tomcat.util.scan.StandardJarScanFilter.jarsToSkip","*.jar") ?

Untested but you get the idea. Still one line of code for end users and no need to add an entire new class to Tomcat.
Comment 2 Igal Sapir 2019-08-30 18:29:50 UTC
(In reply to Mark Thomas from comment #1)
> Why not just do
> 
> System.setProperty("tomcat.util.scan.StandardJarScanFilter.jarsToSkip","*.
> jar") ?

IIRC then that still reads the directories and then filters them out.  Currently I am using the following:

  context.setJarScanner(
    new JarScanner() {
      @Override
      public void scan(JarScanType scanType, ServletContext context, JarScannerCallback callback) {}

       @Override
       public JarScanFilter getJarScanFilter() { return null; }

       @Override
       public void setJarScanFilter(JarScanFilter jarScanFilter) {}
      }
  );

It might be negligible compared to the System property that you cited but then again the addition is very minor as well.

If you still think that it's not useful then that's fine and we can just close this ticket as rejected.
Comment 3 Mark Thomas 2019-09-01 19:39:24 UTC
It is a balance. I'm on the fence as to whether this is worth adding or not. If you think it adds value then I'm not going to object.
Comment 4 Chuck Caldarale 2019-09-02 01:24:26 UTC
Could the standard jar scanner recognize the "*.jar" pattern and simply short-circuit all the directory scanning?
Comment 5 Igal Sapir 2019-09-02 16:21:20 UTC
(In reply to Chuck Caldarale from comment #4)
> Could the standard jar scanner recognize the "*.jar" pattern and simply
> short-circuit all the directory scanning?

I can see benefit in that solution for users who use Tomcat regularly (as opposed to Embedded) so I actually like that idea.
Comment 6 Mark Thomas 2019-10-04 16:58:48 UTC
Marking as an enhancement
Comment 7 Mark Thomas 2020-01-07 11:16:50 UTC
Fixed (by isapir) in:
- master for 9.0.31 onwards
- 8.5.x for 8.5.51 onwards
Comment 8 Joshua Lipstone 2020-03-06 16:54:54 UTC
Can you please either undo this or change it so that the Jars are only scanned if they match the inclusion filter.
As of 9.0.30, if you wanted to set the logic so that it only scans a short list of jars, you could do:
jarsToSkip=*
jarsToScan=jar1.jar,jar2.jar
As of 9.0.31, this now causes cascading startup failures.
Comment 9 Remy Maucherat 2020-03-06 17:03:20 UTC
This is an enhancement that got implemented, so don't reopen this BZ. If you have an issue, you need to open a new BZ. If you are unsure about it, you can also ask on the users list.
Comment 10 quaff 2020-03-20 03:59:47 UTC
(In reply to Joshua Lipstone from comment #8)
> Can you please either undo this or change it so that the Jars are only
> scanned if they match the inclusion filter.
> As of 9.0.30, if you wanted to set the logic so that it only scans a short
> list of jars, you could do:
> jarsToSkip=*
> jarsToScan=jar1.jar,jar2.jar
> As of 9.0.31, this now causes cascading startup failures.

I have encounter the same problem, Tomcat breaks back compatibility.
Comment 11 Gustavo Stachera 2020-03-23 22:11:05 UTC
(In reply to Joshua Lipstone from comment #8)
> Can you please either undo this or change it so that the Jars are only
> scanned if they match the inclusion filter.
> As of 9.0.30, if you wanted to set the logic so that it only scans a short
> list of jars, you could do:
> jarsToSkip=*
> jarsToScan=jar1.jar,jar2.jar
> As of 9.0.31, this now causes cascading startup failures.

I've implemented a workaround using de wildcard "?" in the beginning, followed by "*" and it works:

tomcat.util.scan.StandardJarScanFilter.jarsToSkip=?*