Get all components listed in a JAR file.

@param jarFile the JAR file to parse
@return the list of component declaration (implementation class names and priorities)
@throws IOException in case of an error loading the component list resource
341595
public List<ComponentDeclaration> getDeclaredComponentsFromJAR(InputStream jarFile) throws IOException
    {
        ZipInputStream zis = new ZipInputStream(jarFile);

        List<ComponentDeclaration> componentDeclarations = null;
        List<ComponentDeclaration> componentOverrideDeclarations = null;

        for (ZipEntry entry = zis.getNextEntry(); entry != null
            && (componentDeclarations == null || componentOverrideDeclarations == null); entry = zis.getNextEntry()) {
            if (entry.getName().equals(ComponentAnnotationLoader.COMPONENT_LIST)) {
                componentDeclarations = getDeclaredComponents(zis);
            } else if (entry.getName().equals(ComponentAnnotationLoader.COMPONENT_OVERRIDE_LIST)) {
                componentOverrideDeclarations = getDeclaredComponents(zis);
            }
        }

        // Merge all overrides found with a priority of 0. This is purely for backward compatibility since the
        // override files is now deprecated.
        if (componentOverrideDeclarations != null) {
            if (componentDeclarations == null) {
                componentDeclarations = new ArrayList<>();
            }
            for (ComponentDeclaration componentOverrideDeclaration : componentOverrideDeclarations) {
                componentDeclarations.add(new ComponentDeclaration(componentOverrideDeclaration
                    .getImplementationClassName(), 0));
            }
        }

        return componentDeclarations;
    }
1245977
private static List<String> getPathList(File file) throws IOException {
        //Make sure the canonical file is being parsed
        file = file.getCanonicalFile();

        //Build a List of the parts of the path
        final List<String> pathParts = new LinkedList<String>();
        while (file != null) {
            pathParts.add(file.getName());
            file = file.getParentFile();
        }
        
        return pathParts;
    }
355669
public static void loadJar(URLClassLoader loader, File jarFile) throws UtilException {
		try {
			final Method method = ClassUtil.getDeclaredMethod(URLClassLoader.class, "addURL", URL.class);
			if (null != method) {
				method.setAccessible(true);
				final List<File> jars = loopJar(jarFile);
				for (File jar : jars) {
					ReflectUtil.invoke(loader, method, new Object[] { jar.toURI().toURL() });
				}
			}
		} catch (IOException e) {
			throw new UtilException(e);
		}
	}
574721
public synchronized JarFile getNestedJarFile(JarEntryData sourceEntry)
            throws IOException {
        try {
            if (sourceEntry.nestedJar == null) {
                sourceEntry.nestedJar = createJarFileFromEntry(sourceEntry);
            }
            return sourceEntry.nestedJar;
        } catch (IOException ex) {
            throw new IOException(
                    "Unable to open nested jar file '" + sourceEntry.getName() + "'", ex);
        }
    }
1043937
public JarClassLoader addJar(File jarFileOrDir) {
		if(isJarFile(jarFileOrDir)) {
			return addURL(jarFileOrDir);
		}
		final List<File> jars = loopJar(jarFileOrDir);
		for (File jar : jars) {
			addURL(jar);
		}
		return this;
	}
123204
@Override
    public List<URL> getJarFileUrls()
    {
        return jarUrls != null ? new ArrayList<URL>(jarUrls) : null;
    }
419892
public static List<Class<?>> getClasses(String packageName) throws IOException, ClassNotFoundException {
        List<Class<?>> classes = new ArrayList<>();
        String packageDirName = packageName.replace('.', '/');
        Enumeration<URL> dirs = Thread.currentThread().getContextClassLoader().getResources(packageDirName);
        while (dirs.hasMoreElements()) {
            URL url = dirs.nextElement();
            String protocol = url.getProtocol();
            if ("file".equals(protocol)) {
                String filePath = URLDecoder.decode(url.getFile(), "UTF-8");
                addClassesInPackageByFile(packageName, filePath, classes);
            } else if ("jar".equals(protocol)) {
                JarFile jar = ((JarURLConnection) url.openConnection()).getJarFile();
                Enumeration<JarEntry> entries = jar.entries();
                while (entries.hasMoreElements()) {
                    JarEntry entry = entries.nextElement();
                    String name = entry.getName();
                    if (name.charAt(0) == '/') {
                        name = name.substring(1);
                    }
                    if (name.startsWith(packageDirName)) {
                        int idx = name.lastIndexOf('/');
                        if (idx != -1) {
                            packageName = name.substring(0, idx).replace('/', '.');
                        }
                        if (name.endsWith(".class") && !entry.isDirectory()) {
                            String className = name.substring(packageName.length() + 1, name.length() - 6);
                            classes.add(Class.forName(packageName + '.' + className));
                        }
                    }
                }
            }
        }
        return classes;
    }
43251
public static synchronized List<Asset> getJarAssets()  {
        if (jarAssets == null) {
            jarAssets = getAssets(Asset.JAR);
        }
        return jarAssets;
    }
15953
public Iterable<? extends CompilationUnitTree> parse() throws IOException {
        try {
            prepareCompiler();
            List<JCCompilationUnit> units = compiler.parseFiles(fileObjects);
            for (JCCompilationUnit unit: units) {
                JavaFileObject file = unit.getSourceFile();
                if (notYetEntered.containsKey(file))
                    notYetEntered.put(file, unit);
            }
            return units;
        }
        finally {
            parsed = true;
            if (compiler != null && compiler.log != null)
                compiler.log.flush();
        }
    }
832565
protected ArrayList<String> getLabels(String textResource) throws IOException {
        ArrayList<String> labels = new ArrayList<>();
        File resourceFile = getResourceFile();  //Download if required
        try (InputStream is = new BufferedInputStream(new FileInputStream(resourceFile)); Scanner s = new Scanner(is)) {
            while (s.hasNextLine()) {
                labels.add(s.nextLine());
            }
        }
        return labels;
    }
199856
private void addJarFileUrl(String jarFile)
    {
        if (jarUrls == null)
        {
            jarUrls = new HashSet<URL>();
        }
        try
        {
            jarUrls.add(new File(jarFile).toURI().toURL());
        }
        catch (MalformedURLException e)
        {
            log.error("Error while mapping jar-file url" + jarFile + "caused by:" + e.getMessage());
            throw new IllegalArgumentException("Invalid jar-file URL:" + jarFile + "Caused by: " + e);
        }
    }
1244157
protected JarFile getJarFile(String jarFileUrl) throws IOException {
        if (jarFileUrl.startsWith(ResourceUtils.FILE_URL_PREFIX)) {
            try {
                return new JarFile(ResourceUtils.toURI(jarFileUrl).getSchemeSpecificPart());
            } catch (URISyntaxException ex) {
                // Fallback for URLs that are not valid URIs (should hardly ever happen).
                return new JarFile(jarFileUrl.substring(ResourceUtils.FILE_URL_PREFIX.length()));
            }
        }
        return new JarFile(jarFileUrl);
    }
751567
@Override
  protected void buildClassPath(ArrayList<String> pathList)
  {
    for (int i = 0; i < _jarList.size(); i++) {
      JarEntry jarEntry = _jarList.get(i);
      JarPath jar = jarEntry.getJarPath();
      
      String path = jar.getContainer().getNativePath();

      if (! pathList.contains(path)) {
        pathList.add(path);
      }
    }
  }
143959
boolean doJarFile(String jarname) throws IOException {
        try (JarFile jf = new JarFile(jarname)) {
            Stream<String> files =
                jf.stream()
                  .map(JarEntry::getName);
            return doFileNames(files);
        }
    }
1147362
public static ImmutableSet<File> findJarFiles(ClassLoader first, ClassLoader... rest)
      throws IOException {
    Scanner scanner = new Scanner();
    Map<URI, ClassLoader> map = Maps.newLinkedHashMap();
    for (ClassLoader classLoader : Lists.asList(first, rest)) {
      map.putAll(getClassPathEntries(classLoader));
    }
    for (Map.Entry<URI, ClassLoader> entry : map.entrySet()) {
      scanner.scan(entry.getKey(), entry.getValue());
    }
    return scanner.jarFiles();
  }
164241
public static String[] getJars() {
        final ArrayList<String> list = new ArrayList<>();
        final FileExtFileFilter filter = new FileExtFileFilter(JAR_EXT);

        for (final String part : System.getProperty(CLASSPATH).split(File.pathSeparator)) {
            final File file = new File(part);

            if (filter.accept(file.getParentFile(), file.getName())) {
                list.add(file.getAbsolutePath());
            }
        }

        return list.toArray(new String[0]);
    }
734468
protected List<JavaFileObject> listClassesFromUrl(URL base, String packageName) throws IOException {
        //TODO this will only work with file:// not jar://

        if (base == null) {
            throw new NullPointerException("base == null");
        }

        List<JavaFileObject> list = new ArrayList<JavaFileObject>();

        URLConnection connection = base.openConnection();
        connection.connect();
        String encoding = connection.getContentEncoding();
        if (encoding == null) {
            encoding = "UTF-8";
        }
        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), encoding));
        try {
            String curLine;
            do {
                curLine = reader.readLine();
                if (curLine != null && curLine.endsWith(".class")) {
                    try {
                        String curSimpleName = curLine.substring(0, curLine.length() - ".class".length());
                        String binaryName;
                        if (packageName == null) {
                            binaryName = curSimpleName;
                        } else {
                            binaryName = packageName + "." + curSimpleName;
                        }
                        list.add(new UrlJavaFileObject(curLine, new URL(base, curLine), Kind.CLASS, binaryName));
                    } catch (URISyntaxException e) {
                        throw new IOException("Error parsing URL " + curLine + ".", e);
                    }
                }
            } while (curLine != null);
        } finally {
            reader.close();
        }
        return list;
    }