Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* FindBugs - Find Bugs in Java programs
* Copyright (C) 2003-2008 University of Maryland
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package edu.umd.cs.findbugs.classfile.impl;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Stream;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import edu.umd.cs.findbugs.classfile.ClassDescriptor;
import edu.umd.cs.findbugs.classfile.DescriptorFactory;
import edu.umd.cs.findbugs.classfile.ICodeBaseEntry;
import edu.umd.cs.findbugs.classfile.ICodeBaseIterator;
import edu.umd.cs.findbugs.classfile.ICodeBaseLocator;
import edu.umd.cs.findbugs.classfile.InvalidClassFileFormatException;
import edu.umd.cs.findbugs.classfile.ResourceNotFoundException;
/**
*
* Code base supporting Java 9 new jimage packed modules
*
* @author andrey
*/
public class JrtfsCodeBase extends AbstractScannableCodeBase {
private static final int PRIME = 31;
private FileSystem fs;
private final String fileName;
private Path root;
/**
* Key is package name in bytecode notation (e.g. 'java/lang').
*
* Values are either plain Strings for single-module packages, or sets of
* Strings for packages spread over multiple modules
*/
private Map packageToModuleMap;
public JrtfsCodeBase(ICodeBaseLocator codeBaseLocator, @Nonnull String fileName) {
super(codeBaseLocator);
this.fileName = fileName;
URL url;
try {
url = Paths.get(fileName).toUri().toURL();
URLClassLoader loader = new URLClassLoader(new URL[] { url });
fs = FileSystems.newFileSystem(URI.create("jrt:/"), Collections.emptyMap(), loader);
root = fs.getPath("modules");
packageToModuleMap = createPackageToModuleMap(fs);
} catch (IOException e) {
e.printStackTrace();
}
}
public Map createPackageToModuleMap(FileSystem fs) throws IOException {
HashMap packageToModule = new LinkedHashMap<>();
Path path = fs.getPath("packages");
try (Stream packList = Files.list(path)) {
packList.forEach(p -> {
try (Stream pList = Files.list(p)) {
Iterator modIter = pList.iterator();
while (modIter.hasNext()) {
Path module = modIter.next();
String packageKey = fileName(p).replace('.', '/');
String modulePath = fileName(module);
if (!modIter.hasNext() && !packageToModule.containsKey(packageKey)) {
packageToModule.put(packageKey, modulePath);
} else {
@SuppressWarnings("unchecked")
Set