Return a list of classes and jar files

@param current
currently inspected file
@param list
list of url to classes and jar files
@return list of url to classes and jar files
346031
private static List getClasses(final File current, final List list) {
		if (current.isDirectory()) {
			try {
				list.add(current.toURI().toURL());
			} catch (final Exception ignore) {
			}

			final File children[] = current.listFiles();

			for (int i = 0; i < children.length; i++) {
				final File element = children[i];
				CClassLoader.getClasses(element, list);
			}
		} else if (current.isFile()) {
			final String name = current.getName();

			if (name.endsWith(".class")) {
				try {
					list.add(current.toURI().toURL());
				} catch (final Exception ignore) {
				}
			} else if (name.endsWith(".jar")) {
				try {
					list.add(current.toURI().toURL());
				} catch (final Exception ignore) {
				}
			}
		}

		return list;
	}
59051
public static <T> List<T> immutableListView(List<T> list) {
        if (list instanceof ImmutableList<?>) {
            return list;
        }
        if (list instanceof ArrayList<?>) {
            ArrayList.class.cast(list).trimToSize();
        }
        return Collections.unmodifiableList(list);
    }
66959
@SuppressWarnings("static-method")
	protected ClassLoader createClassLoader(Iterable<File> jarsAndFolders, ClassLoader parentClassLoader) {
		return new URLClassLoader(Iterables.toArray(Iterables.transform(jarsAndFolders, from -> {
			try {
				final URL url = from.toURI().toURL();
				assert url != null;
				return url;
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}), URL.class), parentClassLoader);
	}
979536
public static List<File> extractContainedLibraries(URL jarFile) throws ProgramInvocationException {

		Random rnd = new Random();

		JarFile jar = null;
		try {
			jar = new JarFile(new File(jarFile.toURI()));
			final List<JarEntry> containedJarFileEntries = new ArrayList<JarEntry>();

			Enumeration<JarEntry> entries = jar.entries();
			while (entries.hasMoreElements()) {
				JarEntry entry = entries.nextElement();
				String name = entry.getName();

				if (name.length() > 8 && name.startsWith("lib/") && name.endsWith(".jar")) {
					containedJarFileEntries.add(entry);
				}
			}

			if (containedJarFileEntries.isEmpty()) {
				return Collections.emptyList();
			}
			else {
				// go over all contained jar files
				final List<File> extractedTempLibraries = new ArrayList<File>(containedJarFileEntries.size());
				final byte[] buffer = new byte[4096];

				boolean incomplete = true;

				try {
					for (int i = 0; i < containedJarFileEntries.size(); i++) {
						final JarEntry entry = containedJarFileEntries.get(i);
						String name = entry.getName();
						// '/' as in case of zip, jar
						// java.util.zip.ZipEntry#isDirectory always looks only for '/' not for File.separator
						name = name.replace('/', '_');

						File tempFile;
						try {
							tempFile = File.createTempFile(rnd.nextInt(Integer.MAX_VALUE) + "_", name);
							tempFile.deleteOnExit();
						}
						catch (IOException e) {
							throw new ProgramInvocationException(
								"An I/O error occurred while creating temporary file to extract nested library '" +
										entry.getName() + "'.", e);
						}

						extractedTempLibraries.add(tempFile);

						// copy the temp file contents to a temporary File
						OutputStream out = null;
						InputStream in = null;
						try {

							out = new FileOutputStream(tempFile);
							in = new BufferedInputStream(jar.getInputStream(entry));

							int numRead = 0;
							while ((numRead = in.read(buffer)) != -1) {
								out.write(buffer, 0, numRead);
							}
						}
						catch (IOException e) {
							throw new ProgramInvocationException("An I/O error occurred while extracting nested library '"
									+ entry.getName() + "' to temporary file '" + tempFile.getAbsolutePath() + "'.");
						}
						finally {
							if (out != null) {
								out.close();
							}
							if (in != null) {
								in.close();
							}
						}
					}

					incomplete = false;
				}
				finally {
					if (incomplete) {
						deleteExtractedLibraries(extractedTempLibraries);
					}
				}

				return extractedTempLibraries;
			}
		}
		catch (Throwable t) {
			throw new ProgramInvocationException("Unknown I/O error while extracting contained jar files.", t);
		}
		finally {
			if (jar != null) {
				try {
					jar.close();
				} catch (Throwable t) {}
			}
		}
	}
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]);
    }
1331290
@PublicAPI(usage = ACCESS)
    public JavaClasses importJars(JarFile... jarFiles) {
        return importJars(ImmutableList.copyOf(jarFiles));
    }
692906
private static URL[] getUrls(File directory) throws MalformedURLException, IOException
   {
      List<URL> list = new LinkedList<URL>();

      if (directory.exists() && directory.isDirectory())
      {
         // Add directory
         list.add(directory.toURI().toURL());

         // Add the contents of the directory too
         File[] jars = directory.listFiles(new FilenameFilter()
         {
            /**
             * Accept
             * @param dir The directory
             * @param name The name
             * @return True if accepts; otherwise false
             */
            public boolean accept(File dir, String name)
            {
               return name.endsWith(".jar");
            }
         });

         if (jars != null)
         {
            for (int j = 0; j < jars.length; j++)
            {
               list.add(jars[j].getCanonicalFile().toURI().toURL());
            }
         }
      }
      return list.toArray(new URL[list.size()]);
   }
843522
public static List<Field> getClassFields(Class<?> beanClass) {
		Map<String, Field> resultMap = new HashMap<>();
		LinkedList<Field> results = new LinkedList<>();

		Class<?> currentClass = beanClass;
		while (currentClass != null && currentClass != Object.class) {
			for (Field field : currentClass.getDeclaredFields()) {
				if (!field.isSynthetic()) {
					Field v = resultMap.get(field.getName());
					if (v == null) {
						resultMap.put(field.getName(), field);
						results.add(field);
					}
				}
			}
			currentClass = currentClass.getSuperclass();
		}

		return results;
	}
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();
  }
1189289
public static <T> List<T> getNullableList(final List list, final Class<T> clazz, final Integer... path) {
        return (List<T>) getNullable(list, List.class, path);
    }
800780
public static <T> List<T> getListUnsafe(final List list, final Class<T> clazz, final Integer... path) {
        return (List<T>) getUnsafe(list, List.class, path);
    }
245905
protected <T> List<T> toArrayList(List<T> list) {
        if (list == null) {
            return null;
        }
        if (!list.getClass().equals(ArrayList.class)) {
            list = new ArrayList<>(list);
        }
        return list;
    }
834150
public static URL[] findClassPaths()
   {
      List<URL> list = new ArrayList<URL>();
      String classpath = System.getProperty("java.class.path");
      StringTokenizer tokenizer = new StringTokenizer(classpath, File.pathSeparator);

      while (tokenizer.hasMoreTokens())
      {
         String path = tokenizer.nextToken();
         File fp = new File(path);
         if (!fp.exists()) {
        	 throw new RuntimeException("File in java.class.path does not exist: " + fp);
         }
         try
         {
            list.add(fp.toURL());
         }
         catch (MalformedURLException e)
         {
            throw new RuntimeException(e);
         }
      }
      return list.toArray(new URL[list.size()]);
   }
1177441
public List<String> scan() {
        try {
            JarFile jar = new JarFile(jarURL.getFile());
            try {
                List<String> result = new ArrayList<>();
                Enumeration<JarEntry> en = jar.entries();
                while (en.hasMoreElements()) {
                    JarEntry entry = en.nextElement();
                    String path = entry.getName();
                    boolean match = includes.size() == 0;
                    if (!match) {
                        for (String pattern : includes) {
                            if ( patternMatches(pattern, path)) {
                                match = true;
                                break;
                            }
                        }
                    }
                    if (match) {
                        for (String pattern : excludes) {
                            if ( patternMatches(pattern, path)) {
                                match = false;
                                break;
                            }
                        }
                    }
                    if (match) {
                        result.add(path);
                    }
                }
                return result;
            } finally {
                jar.close();
            }
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    }
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;
    }
925123
public static List<String> readFileFromClassPathAsList(String _fileName) {
    	List<String> result = readFileFromClassPathAsList(_fileName, Charset.defaultCharset(), false);
        return result == null ? new ArrayList<String>() : result;
    }
931153
private List<Archive> getClassPathArchives(String cpaths, List<Path> initialArchives)
            throws IOException
    {
        List<Archive> result = new ArrayList<>();
        if (cpaths.isEmpty()) {
            return result;
        }

        List<Path> paths = new ArrayList<>();
        for (String p : cpaths.split(File.pathSeparator)) {
            if (p.length() > 0) {
                // wildcard to parse all JAR files e.g. -classpath dir/*
                int i = p.lastIndexOf(".*");
                if (i > 0) {
                    Path dir = Paths.get(p.substring(0, i));
                    try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "*.jar")) {
                        for (Path entry : stream) {
                            paths.add(entry);
                        }
                    }
                } else {
                    paths.add(Paths.get(p));
                }
            }
        }
        for (Path p : paths) {
            if (Files.exists(p) && !hasSameFile(initialArchives, p)) {
                result.add(Archive.getInstance(p));
            }
        }
        return result;
    }