Finds tools.jar in JDK.

@return File for tools.jar, which may not be valid if tools.jar could
have not been located
170868
private static File findToolsJar() {
        String javaHome = System.getProperty("java.home");
        File javaHomeFile = new File(javaHome);
        File toolsJarFile = new File(javaHomeFile, "lib" + File.separator + TOOLS_JAR_NAME);

        if (!toolsJarFile.exists()) {
            toolsJarFile = new File(System.getenv("java_home"), "lib" + File.separator + TOOLS_JAR_NAME);
        }

        if (!toolsJarFile.exists() && javaHomeFile.getAbsolutePath().endsWith(File.separator + "jre")) {
            javaHomeFile = javaHomeFile.getParentFile();
            toolsJarFile = new File(javaHomeFile, "lib" + File.separator + TOOLS_JAR_NAME);
        }

        if (!toolsJarFile.exists() && isMac() && javaHomeFile.getAbsolutePath().endsWith(File.separator + "Home")) {
            javaHomeFile = javaHomeFile.getParentFile();
            toolsJarFile = new File(javaHomeFile, "Classes" + File.separator + CLASSES_JAR_NAME);
        }

        return toolsJarFile;
    }
749487
private Class lookupVirtualMachineClass() {
        try {
            return ToolsClassFinder.lookupClass("com.sun.tools.attach.VirtualMachine");
        } catch (ClassNotFoundException exp) {
            throw new ProcessingException(
                    "Cannot find classes from tools.jar. The heuristics for loading tools.jar which contains\n" +
                    "essential classes for attaching to a running JVM could locate the necessary jar file.\n" +
                    "\n" +
                    "Please call this launcher with a qualified classpath on the command line like\n" +
                    "\n" +
                    "   java -cp path/to/tools.jar:" + options.getJarFileName() + " org.jolokia.jvmagent.client.AgentLauncher [options] <command> <ppid>\n",
                    exp,
                    options);
        }
    }
507721
private void findJarEntry() throws IOException {
        if (getEntryName() == null) {
            return;
        }
        jarEntry = jarFile.getJarEntry(getEntryName());
        if (jarEntry == null) {
            throw new FileNotFoundException(getEntryName());
        }
    }
302519
public synchronized JarFile getFilteredJarFile(JarEntryFilter... filters)
            throws IOException {
        return new JarFile(this.rootFile, this.pathFromRoot, this.data, this.entries,
                filters);
    }
1320667
public static boolean isJarFile(Path path) {
        return Files.isRegularFile(path) && path.toString().toLowerCase().endsWith(".jar");
    }
1308601
protected List<File> findJarFile(String scriptLibDir) {
		List<File> files = new ArrayList<File>();
		try {
			File file = new File(scriptLibDir);
			if (file.isDirectory()) {
				for (File f : file.listFiles()) {
					if (f.isFile() && f.getName().endsWith(".jar")) {
						files.add(f);
					}
				}
			}
		} catch (Exception e) {
			_log.error(e.getMessage(), e);
		}
		return files;
	}
489336
def find_jar(jar_name, root_path=None):
    
    jar_name = os.path.basename(jar_name)
    root = root_path or os.getcwd()
    paths = (root, os.path.join(root, "build"), "/usr/share/java")
    for p in paths:
        p = os.path.join(p, jar_name)
        if os.path.exists(p):
            return p
    return None
939000
public static File getFile(String resourceOrFile, Class<?> cls,
            boolean deleteTmpOnExit) throws FileNotFoundException {
        try {

            // jar:file:/home/.../blue.jar!/path/to/file.xml
            URI uri = getURL(resourceOrFile, cls).toURI();
            String uriStr = uri.toString();
            if (uriStr.startsWith("jar")) {

                if (uriStr.endsWith("/")) {
                    throw new UnsupportedOperationException(
                            "cannot unjar directories, only files");
                }

                String jarPath = uriStr.substring(4, uriStr.indexOf("!"))
                        .replace("file:", "");
                String filePath = uriStr.substring(uriStr.indexOf("!") + 2);

                JarFile jarFile = new JarFile(jarPath);
                assert (jarFile.size() > 0) : "no jarFile at " + jarPath;

                Enumeration<JarEntry> entries = jarFile.entries();

                while (entries.hasMoreElements()) {

                    JarEntry jarEntry = entries.nextElement();
                    if (jarEntry.toString().equals(filePath)) {
                        InputStream input = jarFile.getInputStream(jarEntry);
                        assert (input != null) : "empty is for " + jarEntry;
                        return tmpFileFromStream(input, filePath,
                                deleteTmpOnExit);
                    }
                }
                assert (false) : "file" + filePath + " not found in " + jarPath;
                return null;
            } else {
                return new File(uri);
            }

        } catch (URISyntaxException e) {
            throw new FileNotFoundException(resourceOrFile);
        } catch (IOException e) {
            throw new FileNotFoundException(resourceOrFile);
        }
    }
1111955
public boolean scanJar(String jarname) {
        try (JarFile jf = new JarFile(jarname)) {
            out.println(Messages.get("scan.head.jar", jarname));
            finder.addJar(jarname);
            Enumeration<JarEntry> entries = jf.entries();
            while (entries.hasMoreElements()) {
                JarEntry entry = entries.nextElement();
                String name = entry.getName();
                if (name.endsWith(".class")
                        && !name.endsWith("package-info.class")
                        && !name.endsWith("module-info.class")) {
                    processClass(ClassFile.read(jf.getInputStream(entry)));
                }
            }
            return true;
        } catch (NoSuchFileException nsfe) {
            errorNoFile(jarname);
        } catch (IOException | ConstantPoolException ex) {
            errorException(ex);
        }
        return false;
    }
274949
def _get_jar(self, command, alts=None, allow_missing=False):
        
        dirs = []
        for bdir in [self._gatk_dir, self._picard_ref]:
            dirs.extend([bdir,
                         os.path.join(bdir, os.pardir, "gatk")])
        if alts is None: alts = []
        for check_cmd in [command] + alts:
            for dir_check in dirs:
                try:
                    check_file = config_utils.get_jar(check_cmd, dir_check)
                    return check_file
                except ValueError as msg:
                    if str(msg).find("multiple") > 0:
                        raise
                    else:
                        pass
        if allow_missing:
            return None
        else:
            raise ValueError("Could not find jar %s in %s:%s" % (command, self._picard_ref, self._gatk_dir))
139109
def jarSources(target, source, env, for_signature):
    """"""
    try:
        env['JARCHDIR']
    except KeyError:
        jarchdir_set = False
    else:
        jarchdir_set = True
        jarchdir = env.subst('$JARCHDIR', target=target, source=source)
        if jarchdir:
            jarchdir = env.fs.Dir(jarchdir)
    result = []
    for src in source:
        contents = src.get_text_contents()
        if contents[:16] != "Manifest-Version":
            if jarchdir_set:
                _chdir = jarchdir
            else:
                try:
                    _chdir = src.attributes.java_classdir
                except AttributeError:
                    _chdir = None
            if _chdir:
                # If we are changing the dir with -C, then sources should
                # be relative to that directory.
                src = SCons.Subst.Literal(src.get_path(_chdir))
                result.append('-C')
                result.append(_chdir)
            result.append(src)
    return result
1129883
public static File lookupJarFile() {
        try {
            return new File(OptionsAndArgs.class
                                    .getProtectionDomain()
                                    .getCodeSource()
                                    .getLocation()
                                    .toURI());
        } catch (URISyntaxException e) {
            throw new IllegalStateException("Error: Cannot lookup jar for this class: " + e,e);
        }
    }
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]);
    }
1373544
def get_jvm_path(self):
        
        for method in self._methods:
            try:
                jvm = method()

                # If found check the architecture 
                if jvm:
                    self.check(jvm)
            except NotImplementedError:
                # Ignore missing implementations
                pass
            except JVMNotFoundException:
                # Ignore not successful methods
                pass
            except JVMNotSupportedException:
                pass

            else:
                if jvm is not None:
                    return jvm

        else:
            raise JVMNotFoundException("No JVM shared library file ({0}) "
                                       "found. Try setting up the JAVA_HOME "
                                       "environment variable properly."
                                       .format(self._libfile))
344068
private static Class<?> loadVirtualMachine(File toolsJarFile) throws Exception {
        // We used to add tools.jar to SystemClassLoader but that was triggering
        // a bug in Java compiler when running some experiments (e.g.,
        // CommonsMath).
        if (toolsJarFile == null) {
            return null;
        }
        URLClassLoader loader = new URLClassLoader(new URL[] { toolsJarFile.toURI().toURL() },
                ClassLoader.getSystemClassLoader());
        return loader.loadClass("com.sun.tools.attach.VirtualMachine");
    }
1211633
private File getJarPath() {
        String decodedPath = ".";
        String jarPath = "";
        final ProtectionDomain domain = Settings.class.getProtectionDomain();
        if (domain != null && domain.getCodeSource() != null && domain.getCodeSource().getLocation() != null) {
            jarPath = Settings.class.getProtectionDomain().getCodeSource().getLocation().getPath();
        }
        try {
            decodedPath = URLDecoder.decode(jarPath, StandardCharsets.UTF_8.name());
        } catch (UnsupportedEncodingException ex) {
            LOGGER.trace("", ex);
        }

        final File path = new File(decodedPath);
        if (path.getName().toLowerCase().endsWith(".jar")) {
            return path.getParentFile();
        } else {
            return new File(".");
        }
    }
262232
public static List<String> getJreJars() {
    String javaHome = System.getProperty("java.home");
    Path libsDir = FileSystems.getDefault().getPath(javaHome, "/lib");
    List<String> retval = GosucUtil.getIbmClasspath();
    try {
      retval.addAll(Files.walk(libsDir)
              .filter( path -> path.toFile().isFile())
              .filter( path -> path.toString().endsWith(".jar"))
              .map( Path::toString )
              .collect(Collectors.toList()));
    } catch (SecurityException | IOException e) {
      e.printStackTrace();
      throw new RuntimeException(e);
    }
    return retval;
  }