Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Set<String> getClassNames(Collection<TransformInput> inputs) {
- Set<String> classNames = new HashSet<>();
- for (TransformInput input : inputs) {
- classNames.addAll(getDirectoryInputs(input.getDirectoryInputs()));
- classNames.addAll(getJarInputs(input.getJarInputs()));
- }
- return classNames;
- }
- Set<String> getDirectoryInputs(Collection<DirectoryInput> directoryInputs) {
- Set<String> classNames = new HashSet<>();
- for (DirectoryInput input : directoryInputs) {
- try {
- classNames.addAll(processDirectoryInput(input));
- } catch (IOException e) {
- throw new GradleException(e.getMessage());
- }
- }
- return classNames;
- }
- Set<String> processDirectoryInput(DirectoryInput input) throws IOException {
- String dirPath = input.getFile().getAbsolutePath();
- return Files.walk(input.getFile().toPath())
- .map(file -> file.toAbsolutePath().toString())
- .filter(path -> path.endsWith(SdkConstants.DOT_CLASS))
- .map(path -> path.substring(dirPath.length() + 1,
- path.length() - SdkConstants.DOT_CLASS.length()))
- .map(path -> path.replaceAll(File.separator, "."))
- .collect(Collectors.toSet());
- }
- Set<String> getJarInputs(Collection<JarInput> jarInputs) {
- return jarInputs.stream().map(QualifiedContent::getFile)
- .map(this::toJar)
- .map(JarFile::entries)
- .flatMap(this::toStream)
- .filter(entry -> !entry.isDirectory() && entry.getName().endsWith(SdkConstants.DOT_CLASS))
- .map(ZipEntry::getName)
- .map(name -> name.substring(0, name.length() - SdkConstants.DOT_CLASS.length()))
- .map(name -> name.replaceAll(File.separator, "."))
- .collect(Collectors.toSet());
- }
- ClassPool createClassPool(Collection<TransformInput> inputs,
- Collection<TransformInput> referencedInputs) {
- ClassPool classPool = new ClassPool();
- classPool.appendSystemPath();
- classPool.appendClassPath(new LoaderClassPath(getClass().getClassLoader()));
- Stream.concat(inputs.stream(), referencedInputs.stream())
- .flatMap(input -> Stream.concat(input.getDirectoryInputs().stream(),
- input.getJarInputs().stream()))
- .map(input -> input.getFile().getAbsolutePath())
- .forEach(entry -> {
- try {
- classPool.appendClassPath(entry);
- } catch (NotFoundException e) {
- throw new GradleException(e.getMessage());
- }
- });
- return classPool;
- }
Add Comment
Please, Sign In to add comment