org.apache.tomcat.JarScanType Java Examples
The following examples show how to use
org.apache.tomcat.JarScanType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TomEEJarScanner.java From tomee with Apache License 2.0 | 6 votes |
private void doScan(final JarScanType scanType, final JarScannerCallback callback, final Deque<URL> urls) { Method process = null; final boolean scanAllDirectories = isScanAllDirectories(); for (final URL url : urls) { final File cpe = URLs.toFile(url); if ((cpe.getName().endsWith(".jar") || scanType == JarScanType.PLUGGABILITY || scanAllDirectories) && getJarScanFilter().check(scanType, cpe.getName())) { try { if (process == null) { process = StandardJarScanner.class.getDeclaredMethod("process", JarScanType.class, JarScannerCallback.class, URL.class, String.class, boolean.class, Deque.class); if (!process.isAccessible()) { process.setAccessible(true); } } process.invoke(this, scanType, callback, url, null, true, urls); } catch (final Exception ioe) { // no-op } } } }
Example #2
Source File: TomEEJarScanner.java From tomee with Apache License 2.0 | 6 votes |
@Override public void scan(final JarScanType scanType, final ServletContext context, final JarScannerCallback callback) { super.scan(scanType, context, callback); if (!embeddedSurefireScanning(scanType, context, callback) && isScanClassPath() && !URLClassLoader.class.isInstance(getSystemClassLoader()) && !Boolean.getBoolean("tomee.classpath.scanning.disabled")) { // TODO: check on tomcat upgrade if it is fixed final String cp = System.getProperty("java.class.path"); final Collection<URL> urls = new HashSet<>(); for (final String jar : cp.split(File.pathSeparator)) { if(!jar.isEmpty()){ try { urls.add(new File(jar).toURI().toURL()); } catch (MalformedURLException e) { // no-op } } } doScan(scanType, callback, new LinkedList<>(urls)); } }
Example #3
Source File: FatJarScanner.java From oxygen with Apache License 2.0 | 6 votes |
private void processFile(JarScanType scanType, JarScannerCallback callback, URL url, String webappPath, boolean isWebapp, Deque<URL> classPathUrlsToProcess) throws IOException { try { File f = new File(url.toURI()); if (f.isFile()) { // Treat this file as a JAR try (Jar jar = JarFactory.newInstance(UriUtil.buildJarUrl(f))) { processManifest(jar, isWebapp, classPathUrlsToProcess); callback.scan(jar, webappPath, isWebapp); } } else if (f.isDirectory()) { if (scanType == JarScanType.PLUGGABILITY) { callback.scan(f, webappPath, isWebapp); } else { if (new File(f.getAbsoluteFile(), TomcatConf.META_INF).isDirectory()) { callback.scan(f, webappPath, isWebapp); } } } } catch (URISyntaxException e) { throw new IOException(e); } }
Example #4
Source File: FatJarScanner.java From oxygen with Apache License 2.0 | 6 votes |
/** * Scan the provided ServletContext and class loade r for JAR files. Each JAR file found will be * passed to the callback handle to be processed. * * @param scanType The type of JAR scan to perform. This is passed to the filter which uses it to * determine how to filter the results * @param context The ServletContext - used to locate and access WEB-INF/lib * @param callback The handle to process any JARs found */ @Override public void scan(JarScanType scanType, ServletContext context, JarScannerCallback callback) { if (log.isTraceEnabled()) { log.trace(SM.getString("jarScan.webinflibStart")); } Set<URL> processedURLs = new HashSet<>(); // Scan WEB-INF/lib doScanWebInfLib(scanType, context, callback, processedURLs); // Scan WEB-INF/classes doScanWebInf(context, callback, processedURLs); // Scan the classpath doScanClassPath(scanType, context, callback, processedURLs); }
Example #5
Source File: FatJarScanner.java From oxygen with Apache License 2.0 | 6 votes |
/** * Scan a URL for JARs with the optional extensions to look at all files and all directories. */ private void process(JarScanType scanType, JarScannerCallback callback, URL url, String webappPath, boolean isWebapp, Deque<URL> classPathUrlsToProcess) throws IOException { if (log.isTraceEnabled()) { log.trace(SM.getString("jarScan.jarUrlStart", url)); } if (Urls.URL_PROTOCOL_JAR.equals(url.getProtocol()) || url.getPath() .endsWith(TomcatConf.JAR_EXT)) { try (Jar jar = JarFactory.newInstance(url)) { processManifest(jar, isWebapp, classPathUrlsToProcess); callback.scan(jar, webappPath, isWebapp); } } else if (Urls.URL_PROTOCOL_FILE.equals(url.getProtocol())) { processFile(scanType, callback, url, webappPath, isWebapp, classPathUrlsToProcess); } }
Example #6
Source File: FatJarScanner.java From oxygen with Apache License 2.0 | 6 votes |
private void processURLs(JarScanType scanType, JarScannerCallback callback, Set<URL> processedURLs, boolean isWebapp, Deque<URL> classPathUrlsToProcess) { while (!classPathUrlsToProcess.isEmpty()) { URL url = classPathUrlsToProcess.pop(); if (processedURLs.contains(url)) { // Skip this URL it has already been processed continue; } if (log.isDebugEnabled()) { log.debug(SM.getString("jarScan.classloaderJarScan", url)); } try { processedURLs.add(url); process(scanType, callback, url, null, isWebapp, classPathUrlsToProcess); } catch (IOException ioe) { log.warn(SM.getString("jarScan.classloaderFail", url), ioe); } } }
Example #7
Source File: TomEEJarScanner.java From tomee with Apache License 2.0 | 5 votes |
@Override public boolean check(final JarScanType jarScanType, final String jarName) { if (jarScanType == JarScanType.TLD) { if (INCLUDE.accept(jarName)) { return true; } if (jarName.startsWith("tomcat-websocket") || jarName.startsWith("myfaces-impl") /* see org.apache.tomee.jasper.TomEETldScanner.scanPlatform */) { return false; } } if (jarName.startsWith("johnzon-") || jarName.startsWith("xx-arquillian-tomee-")) { return false; // but we scan it in openejb scanning } return !NewLoaderLogic.skip(jarName) && (delegate == null || delegate.check(jarScanType, jarName)); }
Example #8
Source File: ContextConfig.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Scan /WEB-INF/lib for JARs and for each one found add it and any * /META-INF/web-fragment.xml to the resulting Map. web-fragment.xml files * will be parsed before being added to the map. Every JAR will be added and * <code>null</code> will be used if no web-fragment.xml was found. Any JARs * known not contain fragments will be skipped. * * @param application The main web.xml metadata * @param webXmlParser The parser to use to process the web.xml file * @return A map of JAR name to processed web fragment (if any) */ protected Map<String,WebXml> processJarsForWebFragments(WebXml application, WebXmlParser webXmlParser) { JarScanner jarScanner = context.getJarScanner(); boolean delegate = false; if (context instanceof StandardContext) { delegate = ((StandardContext) context).getDelegate(); } boolean parseRequired = true; Set<String> absoluteOrder = application.getAbsoluteOrdering(); if (absoluteOrder != null && absoluteOrder.isEmpty() && !context.getXmlValidation()) { // Skip parsing when there is an empty absolute ordering and // validation is not enabled parseRequired = false; } FragmentJarScannerCallback callback = new FragmentJarScannerCallback(webXmlParser, delegate, parseRequired); jarScanner.scan(JarScanType.PLUGGABILITY, context.getServletContext(), callback); if (!callback.isOk()) { ok = false; } return callback.getFragments(); }
Example #9
Source File: TomEEJarScanner.java From tomee with Apache License 2.0 | 5 votes |
private boolean embeddedSurefireScanning(final JarScanType scanType, final ServletContext context, final JarScannerCallback callback) { if (isScanClassPath() && System.getProperty("surefire.real.class.path") != null) { try { final Set<URL> urls = ClassLoaders.findUrls(context.getClassLoader().getParent()); doScan(scanType, callback, new LinkedList<>(urls)); return true; } catch (final IOException e) { // no-op } } return false; }
Example #10
Source File: OWBJarScanner.java From openwebbeans-meecrowave with Apache License 2.0 | 5 votes |
@Override public void scan(final JarScanType jarScanType, final ServletContext servletContext, final JarScannerCallback callback) { switch (jarScanType) { case PLUGGABILITY: CdiArchive.class.cast(WebScannerService.class.cast(WebBeansContext.getInstance().getScannerService()).getFinder().getArchive()) .classesByUrl().keySet().stream() .filter(u -> !"jar:file://!/".equals(u)) // not a fake in memory url .forEach(u -> { try { final URL url = new URL(u); final File asFile = Files.toFile(url); if (!asFile.exists()) { return; } if (filter != null && !filter.check(jarScanType, asFile.getName())) { return; } if (asFile.getName().endsWith(Constants.JAR_EXT)) { try (final Jar jar = JarFactory.newInstance(asFile.toURI().toURL())) { callback.scan(jar, u, true); } } else if (asFile.isDirectory()) { callback.scan(asFile, asFile.getAbsolutePath(), true); } } catch (final MalformedURLException e) { // skip } catch (final IOException ioe) { throw new IllegalArgumentException(ioe); } }); return; case TLD: default: } }
Example #11
Source File: FatJarScanner.java From oxygen with Apache License 2.0 | 5 votes |
private void doScanWebInfLib(JarScanType scanType, ServletContext context, JarScannerCallback callback, Set<URL> processedURLs) { Set<String> dirList = context.getResourcePaths(TomcatConf.WEB_INF_LIB); if (dirList == null) { return; } for (String path : dirList) { if (path.endsWith(TomcatConf.JAR_EXT) && getJarScanFilter() .check(scanType, path.substring(path.lastIndexOf(Strings.SLASH) + 1))) { // Need to scan this JAR if (log.isDebugEnabled()) { log.debug(SM.getString("jarScan.webinflibJarScan", path)); } URL url = null; try { url = context.getResource(path); processedURLs.add(url); process(scanType, callback, url, path, true, null); } catch (IOException e) { log.warn(SM.getString("jarScan.webinflibFail", url), e); } } else { if (log.isTraceEnabled()) { log.trace(SM.getString("jarScan.webinflibJarNoScan", path)); } } } }
Example #12
Source File: JspCServletContext.java From Tomcat8-Source-Read with MIT License | 5 votes |
private Map<String, WebXml> scanForFragments(WebXmlParser webXmlParser) throws JasperException { StandardJarScanner scanner = new StandardJarScanner(); // TODO - enabling this means initializing the classloader first in JspC scanner.setScanClassPath(false); // TODO - configure filter rules from Ant rather then system properties scanner.setJarScanFilter(new StandardJarScanFilter()); FragmentJarScannerCallback callback = new FragmentJarScannerCallback(webXmlParser, false, true); scanner.scan(JarScanType.PLUGGABILITY, this, callback); if (!callback.isOk()) { throw new JasperException(Localizer.getMessage("jspc.error.invalidFragment")); } return callback.getFragments(); }
Example #13
Source File: TldScanner.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Scan for TLDs in JARs in /WEB-INF/lib. */ public void scanJars() { JarScanner scanner = JarScannerFactory.getJarScanner(context); TldScannerCallback callback = new TldScannerCallback(); scanner.scan(JarScanType.TLD, context, callback); if (callback.scanFoundNoTLDs()) { log.info(Localizer.getMessage("jsp.tldCache.noTldSummary")); } }
Example #14
Source File: StandardJarScanner.java From Tomcat8-Source-Read with MIT License | 5 votes |
protected void processURLs(JarScanType scanType, JarScannerCallback callback, Set<URL> processedURLs, boolean isWebapp, Deque<URL> classPathUrlsToProcess) { while (!classPathUrlsToProcess.isEmpty()) { URL url = classPathUrlsToProcess.pop(); if (processedURLs.contains(url)) { // Skip this URL it has already been processed continue; } ClassPathEntry cpe = new ClassPathEntry(url); // JARs are scanned unless the filter says not to. // Directories are scanned for pluggability scans or // if scanAllDirectories is enabled unless the // filter says not to. if ((cpe.isJar() || scanType == JarScanType.PLUGGABILITY || isScanAllDirectories()) && getJarScanFilter().check(scanType, cpe.getName())) { if (log.isDebugEnabled()) { log.debug(sm.getString("jarScan.classloaderJarScan", url)); } try { processedURLs.add(url); process(scanType, callback, url, null, isWebapp, classPathUrlsToProcess); } catch (IOException ioe) { log.warn(sm.getString("jarScan.classloaderFail", url), ioe); } } else { // JAR / directory has been skipped if (log.isTraceEnabled()) { log.trace(sm.getString("jarScan.classloaderJarNoScan", url)); } } } }
Example #15
Source File: FatJarScanner.java From oxygen with Apache License 2.0 | 4 votes |
private void doScanClassPath(JarScanType scanType, ServletContext context, JarScannerCallback callback, Set<URL> processedURLs) { if (log.isTraceEnabled()) { log.trace(SM.getString("jarScan.classloaderStart")); } ClassLoader classLoader = context.getClassLoader(); ClassLoader stopLoader = null; if (classLoader.getParent() != null) { // Stop when we reach the bootstrap class loader stopLoader = classLoader.getParent().getParent(); } // JARs are treated as application provided until the common class // loader is reached. boolean isWebapp = true; // Use a Deque so URLs can be removed as they are processed // and new URLs can be added as they are discovered during // processing. Deque<URL> classPathUrlsToProcess = new LinkedList<>(); while (classLoader != null && classLoader != stopLoader) { if (classLoader instanceof URLClassLoader) { if (isWebapp) { isWebapp = isWebappClassLoader(classLoader); } classPathUrlsToProcess.addAll(Arrays.asList(((URLClassLoader) classLoader).getURLs())); processURLs(scanType, callback, processedURLs, isWebapp, classPathUrlsToProcess); } classLoader = classLoader.getParent(); } if (JreCompat.isJre9Available()) { // The application and platform class loaders are not // instances of URLClassLoader. Use the class path in this // case. addClassPath(classPathUrlsToProcess); // Also add any modules JreCompat.getInstance().addBootModulePath(classPathUrlsToProcess); processURLs(scanType, callback, processedURLs, false, classPathUrlsToProcess); } }
Example #16
Source File: TestStandardJarScanner.java From Tomcat8-Source-Read with MIT License | 4 votes |
@Test public void testWebappClassPath() { Assume.assumeFalse("No URLClassLoader with Java 9", JreCompat.isJre9Available()); StandardJarScanner scanner = new StandardJarScanner(); scanner.setScanClassPath(true); // When running the test on Java 9, one or more URLs to jimage files may // be returned. By setting the scanAllFiles option, a callback will be // generated for these files which in turn will mean the number of URLs // and the number of call backs will agree and this test will pass. // There is a TODO in StandardJarScanner to add 'proper' Java 9 support. scanner.setScanAllFiles(true); LoggingCallback callback = new LoggingCallback(); scanner.scan(JarScanType.PLUGGABILITY, new TesterServletContext(), callback); List<String> callbacks = callback.getCallbacks(); ClassLoader cl = TesterServletContext.class.getClassLoader(); if (cl instanceof URLClassLoader) { URL[] urls = ((URLClassLoader) cl).getURLs(); int size; if (urls == null) { size = 0; } else { size = urls.length; } // Some JREs (Gump) construct a class path that includes JARs that // reference additional JARs via the Class-Path attribute of the // Manifest. These JARs are not returned in ClassLoader.getURLs(). // Therefore, this test looks for at least as many JARs as there are // URLs but it can't check for an exact match. Assert.assertTrue("[" + callbacks.size() + "] callbacks but expected at least [" + size + "]", callbacks.size() >= size); } else { Assert.fail("Unexpected class loader type: " + cl.getClass().getName()); } }
Example #17
Source File: FilterJars.java From scipio-erp with Apache License 2.0 | 4 votes |
@Override public boolean check(final JarScanType jarScanType, final String jarName) { return scanEnabledJarNames.contains(jarName); // SCIPIO: 2018-10-03: Simplified }
Example #18
Source File: KnownJarsFilter.java From openwebbeans-meecrowave with Apache License 2.0 | 4 votes |
@Override public boolean check(final JarScanType jarScanType, final String jarName) { return forceIncludes.stream().anyMatch(jarName::startsWith) || (excludes.stream().noneMatch(jarName::startsWith) && !isGeronimoSpecJar(jarName)); }
Example #19
Source File: EmptyScanner.java From tomee with Apache License 2.0 | 4 votes |
@Override public void scan(final JarScanType scanType, final ServletContext context, final JarScannerCallback callback) { // no-op }
Example #20
Source File: StandardJarScanFilter.java From Tomcat8-Source-Read with MIT License | 4 votes |
@Override public boolean check(JarScanType jarScanType, String jarName) { Lock readLock = configurationLock.readLock(); readLock.lock(); try { final boolean defaultScan; final Set<String> toSkip; final Set<String> toScan; switch (jarScanType) { case TLD: { defaultScan = defaultTldScan; toSkip = tldSkipSet; toScan = tldScanSet; break; } case PLUGGABILITY: { defaultScan = defaultPluggabilityScan; toSkip = pluggabilitySkipSet; toScan = pluggabilityScanSet; break; } case OTHER: default: { defaultScan = true; toSkip = defaultSkipSet; toScan = defaultScanSet; } } if (defaultScan) { if (Matcher.matchName(toSkip, jarName)) { if (Matcher.matchName(toScan, jarName)) { return true; } else { return false; } } return true; } else { if (Matcher.matchName(toScan, jarName)) { if (Matcher.matchName(toSkip, jarName)) { return false; } else { return true; } } return false; } } finally { readLock.unlock(); } }
Example #21
Source File: StandardJarScanner.java From Tomcat8-Source-Read with MIT License | 4 votes |
protected void doScanClassPath(JarScanType scanType, ServletContext context, JarScannerCallback callback, Set<URL> processedURLs) { if (log.isTraceEnabled()) { log.trace(sm.getString("jarScan.classloaderStart")); } ClassLoader stopLoader = null; if (!isScanBootstrapClassPath()) { // Stop when we reach the bootstrap class loader stopLoader = ClassLoader.getSystemClassLoader().getParent(); } ClassLoader classLoader = context.getClassLoader(); // JARs are treated as application provided until the common class // loader is reached. boolean isWebapp = true; // Use a Deque so URLs can be removed as they are processed // and new URLs can be added as they are discovered during // processing. Deque<URL> classPathUrlsToProcess = new LinkedList<>(); while (classLoader != null && classLoader != stopLoader) { if (classLoader instanceof URLClassLoader) { if (isWebapp) { isWebapp = isWebappClassLoader(classLoader); } classPathUrlsToProcess.addAll( Arrays.asList(((URLClassLoader) classLoader).getURLs())); processURLs(scanType, callback, processedURLs, isWebapp, classPathUrlsToProcess); } classLoader = classLoader.getParent(); } if (JreCompat.isJre9Available()) { // The application and platform class loaders are not // instances of URLClassLoader. Use the class path in this // case. addClassPath(classPathUrlsToProcess); // Also add any modules JreCompat.getInstance().addBootModulePath(classPathUrlsToProcess); processURLs(scanType, callback, processedURLs, false, classPathUrlsToProcess); } }