Scan configured classpath packages.

@param visitor visitor to investigate found classes
196577
public void scan(final ClassVisitor visitor) {
        if (scanned == null) {
            performScan();
        }
        for (Class<?> cls : scanned) {
            visitor.visit(cls);
        }
    }
59420
public static Set<Class<?>> scanPackage(ClassLoader classLoader, Package pkg) throws IOException {
        return scanPackage(classLoader, pkg.getName());
    }
25183
@Override
	public void traverse(SchemaVisitor visitor) {
    	visitor.initialize(m_xsdpackageName, m_targetNamespace,m_classes);
    	for (Map.Entry<String,ObjectDescriptor> entry: m_elements.entrySet()) {
    		ObjectDescriptor objectDescriptor = entry.getValue();
    		// get the type and call the visitor for it.
    		objectDescriptor.traverse(visitor);
    	}
    	visitor.terminate();
    }
220781
public static Set<Class<?>> scanPackageBySuper(String packageName, final Class<?> superClass) {
		return ClassScaner.scanPackageBySuper(packageName, superClass);
	}
722579
protected void scanResourcePaths(String startPath) throws IOException, SAXException {

        Set<String> dirList = context.getResourcePaths(startPath);
        if (dirList != null) {
            for (String path : dirList) {
                if (path.startsWith("/WEB-INF/classes/")) {
                    // Skip: JSP.7.3.1
                } else if (path.startsWith("/WEB-INF/lib/")) {
                    // Skip: JSP.7.3.1
                } else if (path.endsWith("/")) {
                    scanResourcePaths(path);
                } else if (path.startsWith("/WEB-INF/tags/")) {
                    // JSP 7.3.1: in /WEB-INF/tags only consider implicit.tld
                    if (path.endsWith("/implicit.tld")) {
                        parseTld(path);
                    }
                } else if (path.endsWith(TLD_EXT)) {
                    parseTld(path);
                }
            }
        }
    }
434933
@FFDCIgnore({ AnnotationTargetsVisitor.VisitEnded.class, ArrayIndexOutOfBoundsException.class })
    protected boolean scanClass(String classSourceName,
                                String className,
                                InputStream inputStream,
                                ScanPolicy scanPolicy) {

        Object[] logParms;
        if (tc.isDebugEnabled()) {
            logParms = new Object[] { getHashText(), className, null };
            Tr.debug(tc, MessageFormat.format("[ {0} ] ENTER class [ {1} ]", logParms));
        } else {
            logParms = null;
        }

        AnnotationTargetsVisitor useVisitor = getVisitor();

        useVisitor.i_setClassSourceName(internClassSourceName(classSourceName));

        // For non-seed scans, tell the visitor to only process the
        // class relationship information.  Skip class annotations and
        // and class contents (fields and methods).

        useVisitor.setScanPolicy(scanPolicy);
        useVisitor.setExternalName(className);

        boolean failedScan;

        try {
            // Both IOException and Exception have been seen;
            // in particular ArrayindexOutOfBoundsException for a non-valid class.

            ClassReader classReader = new ClassReader(inputStream); // throws IOException, Exception

            classReader.accept(getVisitor(),
                               (ClassReader.SKIP_FRAMES | ClassReader.SKIP_DEBUG | ClassReader.SKIP_CODE));
            // 'accept' throws IOException, VisitEnded, Exception

            failedScan = false;

            if (logParms != null) {
                logParms[2] = "Success";
            }

        } catch (IOException e) {
            failedScan = true;

            // String eMsg = "[ " + getHashText() + " ] Class [ " + className + " ] Exception creating reader";
            Tr.warning(tc, "ANNO_TARGETS_FAILED_TO_CREATE_READER", className); // CWWKC0049W

        } catch (AnnotationTargetsVisitor.VisitEnded e) {
            // 'VisitEnded' is used both for a normal flow control for
            // skipping detailed scan data (which is not a failed scan)
            // and for other cases, such as duplicate scan requests
            // and name mismatch cases, which are failures.

            failedScan = !e.isDetailCase();

            if (logParms != null) {
                logParms[2] = "Halted: " + e.getEndCase();
            }

        } catch (ArrayIndexOutOfBoundsException e) {
            Tr.info(tc, "ANNO_TARGETS_CORRUPT_CLASS", className, classSourceName);
            failedScan = true;

        } catch (Exception e) {
            // String eMsg = "[ " + getHashText() + " ] Visit failure [ " + className + " ]";
            // CWWKC0044W: An exception occurred while scanning class and annotation data.
            Tr.warning(tc, "ANNO_TARGETS_SCAN_EXCEPTION", e);

            if (logParms != null) {
                logParms[2] = "Exception: " + e.getMessage();
            }

            failedScan = true;
        }

        if (logParms != null) {
            Tr.debug(tc, MessageFormat.format("[ {0} ] RETURN From class [ {1} ]: [ {2} ]", logParms));
        }

        return (!failedScan);
    }
481572
public static void visitClassHierarchy(ClassVisitor visitor, Class<?> subClass) {
        Class<?> visitedClass = subClass;
        while (visitedClass.getSuperclass() != null) {
            visitor.visit(visitedClass);
            visitedClass = visitedClass.getSuperclass();
        }
    }
295889
@Override
    protected Class<?> findClass(final String className)
            throws ClassNotFoundException, LinkageError, SecurityException {
        final Class<?> loadedClass = findLoadedClass(className);
        if (loadedClass != null) {
            return loadedClass;
        }

        // Get ClassInfo for named class
        final ClassInfo classInfo = scanResult.getClassInfo(className);

        // Try environment classloaders first
        boolean triedClassInfoLoader = false;
        final ClassLoader[] classLoaderOrder = scanResult.getClassLoaderOrderRespectingParentDelegation();
        if (classLoaderOrder != null) {
            // Try environment classloaders
            for (final ClassLoader envClassLoader : classLoaderOrder) {
                try {
                    return Class.forName(className, scanResult.scanSpec.initializeLoadedClasses, envClassLoader);
                } catch (ReflectiveOperationException | LinkageError e) {
                    // Ignore
                }
                if (classInfo != null && envClassLoader == classInfo.classLoader) {
                    triedClassInfoLoader = true;
                }
            }
        }

        // Try specific classloader for the classpath element that the classfile was obtained from
        if (!triedClassInfoLoader && classInfo != null && classInfo.classLoader != null) {
            try {
                return Class.forName(className, scanResult.scanSpec.initializeLoadedClasses, classInfo.classLoader);
            } catch (final ReflectiveOperationException | LinkageError e) {
                // Ignore
            }
        }

        // If class came from a module, and it was not able to be loaded by the environment classloader,
        // then it is possible it was a non-public class, and ClassGraph found it by ignoring class visibility
        // when reading the resources in exported packages directly. Force ClassGraph to respect JPMS
        // encapsulation rules by refusing to load modular classes that the context/system classloaders
        // could not load. (A SecurityException should be thrown above, but this is here for completeness.)
        if (classInfo != null && classInfo.classpathElement instanceof ClasspathElementModule
                && !classInfo.isPublic()) {
            throw new ClassNotFoundException("Classfile for class " + className + " was found in a module, "
                    + "but the context and system classloaders could not load the class, probably because "
                    + "the class is not public.");
        }

        // Try obtaining the classfile as a resource, and defining the class from the resource content
        final ResourceList classfileResources = scanResult
                .getResourcesWithPath(JarUtils.classNameToClassfilePath(className));
        if (classfileResources != null) {
            for (final Resource resource : classfileResources) {
                // Iterate through resources (only loading of first resource in the list will be attempted)
                try {
                    // Load the content of the resource, and define a class from it
                    final ByteBuffer resourceByteBuffer = resource.read();
                    return defineClass(className, resourceByteBuffer, null);
                } catch (final IOException e) {
                    throw new ClassNotFoundException("Could not load classfile for class " + className + " : " + e);
                } finally {
                    resource.close();
                }
            }
        }
        throw new ClassNotFoundException("Could not load classfile for class " + className);
    }
878975
public void visitFiles(final FileVisitor visitor) {
    final Project p = getProject();
    if (p == null) {
      throw new java.lang.IllegalStateException("project must be set before this call");
    }
    if (isReference()) {
      ((ProcessorDef) getCheckedRef(ProcessorDef.class, "ProcessorDef")).visitFiles(visitor);
    }
    //
    // if this processor extends another,
    // visit its files first
    //
    final ProcessorDef extendsDef = getExtends();
    if (extendsDef != null) {
      extendsDef.visitFiles(visitor);
    }

    for (int i = 0; i < this.srcSets.size(); i++) {
      final ConditionalFileSet srcSet = (ConditionalFileSet) this.srcSets.elementAt(i);
      if (srcSet.isActive()) {
        // Find matching source files
        final DirectoryScanner scanner = srcSet.getDirectoryScanner(p);
        // Check each source file - see if it needs compilation
        final String[] fileNames = scanner.getIncludedFiles();
        final File parentDir = scanner.getBasedir();
        for (final String currentFile : fileNames) {
          visitor.visit(parentDir, currentFile);
        }
      }
    }
  }
1330170
private void processClasspath(String classpathElement) throws ResourceNotFoundException, ParseErrorException, Exception {
//        getLog().info("Classpath is " + classpathElement);
        if (classpathElement.endsWith(".jar")) {
            // TODO: implement JAR scanning
        } else {
            final File dir = new File(classpathElement);

            processPackage(dir, dir);
        }
    }
16380
@Override
    void scanPaths(final LogNode log) {
        if (skipClasspathElement) {
            return;
        }
        if (scanned.getAndSet(true)) {
            // Should not happen
            throw new IllegalArgumentException("Already scanned classpath element " + toString());
        }

        final LogNode subLog = log == null ? null
                : log.log(classpathEltDir.getPath(), "Scanning directory classpath element " + classpathEltDir);

        scanDirRecursively(classpathEltDir, subLog);

        finishScanPaths(subLog);
    }
870518
private void scanClasses() throws PersistenceUnitScannerException {
        try {
            for (URL url : urlSet) {
                final HashSet<ClassInfoType> citSet = new HashSet<ClassInfoType>();
                final String urlProtocol = url.getProtocol();
                if ("file".equalsIgnoreCase(urlProtocol)) {
                    // Protocol is "file", which either addresses a jar file or an exploded jar file
                    final Path taPath = Paths.get(url.toURI());
                    if (Files.isDirectory(taPath)) {
                        // Exploded Archive
                        citSet.addAll(processExplodedJarFormat(taPath));
                    } else {
                        // Unexploded Archive
                        citSet.addAll(processUnexplodedFile(taPath));
                    }
                } else if (url.toString().startsWith("jar:file")) {
                    citSet.addAll(processJarFileURL(url));
                } else {
                    // InputStream will be in jar format.
                    citSet.addAll(processJarFormatInputStreamURL(url));
                }

                processInnerClasses(citSet);
                scannedClassesMap.put(url, citSet);
            }
        } catch (Exception e) {
            FFDCFilter.processException(e, PersistenceUnitScanner.class.getName() + ".scanClasses", "118");
            throw new PersistenceUnitScannerException(e);
        }
    }
645611
@Nonnull
    public BugInstance addSuperclass(PreorderVisitor visitor) {
        String className = ClassName.toDottedClassName(visitor.getSuperclassName());
        addClass(className);
        return this;
    }
875778
public void scanAllPackages(ClassProject classProject)
    {
        this.setProperty("projectID", classProject.getField(ClassProject.ID).toString());
        
        this.scanPackages(classProject, ClassProject.CodeType.RESOURCE_CODE);
        this.scanPackages(classProject, ClassProject.CodeType.RESOURCE_PROPERTIES);
        this.scanPackages(classProject, ClassProject.CodeType.THIN);
        this.scanPackages(classProject, ClassProject.CodeType.INTERFACE);
        this.scanPackages(classProject, ClassProject.CodeType.THICK);
    }
407518
public void scanJars() throws IOException {

        ClassLoader webappLoader = Thread.currentThread().getContextClassLoader();

        ClassLoader parentLoader = webappLoader.getParent();

        ResourceDelegatingBundleClassLoader classLoader = null;
        if (webappLoader instanceof ResourceDelegatingBundleClassLoader) {
            classLoader = (ResourceDelegatingBundleClassLoader) webappLoader;
        } else if (parentLoader instanceof ResourceDelegatingBundleClassLoader) {
            classLoader = (ResourceDelegatingBundleClassLoader) parentLoader;
        } else if (isTomcatWebLoader()) {
            ClassLoader parent = ((org.apache.catalina.loader.WebappClassLoader) webappLoader).getParent();
            if (parent instanceof ResourceDelegatingBundleClassLoader) {
                classLoader = (ResourceDelegatingBundleClassLoader) parent;
            }
        }

        List<Bundle> bundles = classLoader == null ? Collections.<Bundle>emptyList() : classLoader.getBundles();
        for (Bundle bundle : bundles) {
            Collection<Enumeration<URL>> enumerations;
            BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
            if (bundleWiring == null) {
                Enumeration<URL> urls = bundle.findEntries("META-INF", "*.tld", true);
                enumerations = Collections.singleton(urls);
            } else {
                Collection<String> resources = bundleWiring.listResources("META-INF", "*.tld",
                        BundleWiring.LISTRESOURCES_RECURSE);
                enumerations = new ArrayList<>(resources.size());
                for (String resource : resources) {
                    Enumeration<URL> urls = bundle.getResources(resource);
                    enumerations.add(urls);
                }
            }
            for (Enumeration<URL> urls : enumerations) {
                if (urls != null) {
                    while (urls.hasMoreElements()) {
                        URL url = urls.nextElement();
                        LOG.info("found TLD {}", url);
                        TldResourcePath tldResourcePath = new TldResourcePath(url, null, null);
                        try {
                            parseTld(tldResourcePath);
                        } catch (SAXException e) {
                            throw new IOException(e);
                        }
                    }
                }
            }
        }
    }
931602
private void scanJarManifestForClassPathEntries(LinkedList<WorkListItem> workList, ICodeBase codeBase) throws IOException {
        // See if this codebase has a jar manifest
        ICodeBaseEntry manifestEntry = codeBase.lookupResource("META-INF/MANIFEST.MF");
        if (manifestEntry == null) {
            // Do nothing - no Jar manifest found
            return;
        }

        // Try to read the manifest
        InputStream in = null;
        try {
            in = manifestEntry.openResource();
            Manifest manifest = new Manifest(in);

            Attributes mainAttrs = manifest.getMainAttributes();
            String classPath = mainAttrs.getValue("Class-Path");
            if (classPath != null) {
                String[] pathList = classPath.split("\\s+");

                for (String path : pathList) {
                    // Create a codebase locator for the classpath entry
                    // relative to the codebase in which we discovered the Jar
                    // manifest
                    ICodeBaseLocator relativeCodeBaseLocator = codeBase.getCodeBaseLocator().createRelativeCodeBaseLocator(path);

                    // Codebases found in Class-Path entries are always
                    // added to the aux classpath, not the application.
                    addToWorkList(workList, new WorkListItem(relativeCodeBaseLocator, false, ICodeBase.Discovered.IN_JAR_MANIFEST));
                }
            }
        } finally {
            if (in != null) {
                IO.close(in);
            }
        }
    }
917191
public static Set<Class<?>> scanPackageByAnnotation(String packageName, final Class<? extends Annotation> annotationClass) {
		return ClassScaner.scanPackageByAnnotation(packageName, annotationClass);
	}