Guest User

Untitled

a guest
Jul 19th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. Set<String> getClassNames(Collection<TransformInput> inputs) {
  2. Set<String> classNames = new HashSet<>();
  3.  
  4. for (TransformInput input : inputs) {
  5. classNames.addAll(getDirectoryInputs(input.getDirectoryInputs()));
  6. classNames.addAll(getJarInputs(input.getJarInputs()));
  7. }
  8. return classNames;
  9. }
  10.  
  11. Set<String> getDirectoryInputs(Collection<DirectoryInput> directoryInputs) {
  12. Set<String> classNames = new HashSet<>();
  13. for (DirectoryInput input : directoryInputs) {
  14. try {
  15. classNames.addAll(processDirectoryInput(input));
  16. } catch (IOException e) {
  17. throw new GradleException(e.getMessage());
  18. }
  19. }
  20. return classNames;
  21. }
  22.  
  23. Set<String> processDirectoryInput(DirectoryInput input) throws IOException {
  24. String dirPath = input.getFile().getAbsolutePath();
  25.  
  26. return Files.walk(input.getFile().toPath())
  27. .map(file -> file.toAbsolutePath().toString())
  28. .filter(path -> path.endsWith(SdkConstants.DOT_CLASS))
  29. .map(path -> path.substring(dirPath.length() + 1,
  30. path.length() - SdkConstants.DOT_CLASS.length()))
  31. .map(path -> path.replaceAll(File.separator, "."))
  32. .collect(Collectors.toSet());
  33. }
  34.  
  35. Set<String> getJarInputs(Collection<JarInput> jarInputs) {
  36. return jarInputs.stream().map(QualifiedContent::getFile)
  37. .map(this::toJar)
  38. .map(JarFile::entries)
  39. .flatMap(this::toStream)
  40. .filter(entry -> !entry.isDirectory() && entry.getName().endsWith(SdkConstants.DOT_CLASS))
  41. .map(ZipEntry::getName)
  42. .map(name -> name.substring(0, name.length() - SdkConstants.DOT_CLASS.length()))
  43. .map(name -> name.replaceAll(File.separator, "."))
  44. .collect(Collectors.toSet());
  45. }
  46.  
  47. ClassPool createClassPool(Collection<TransformInput> inputs,
  48. Collection<TransformInput> referencedInputs) {
  49. ClassPool classPool = new ClassPool();
  50. classPool.appendSystemPath();
  51. classPool.appendClassPath(new LoaderClassPath(getClass().getClassLoader()));
  52.  
  53. Stream.concat(inputs.stream(), referencedInputs.stream())
  54. .flatMap(input -> Stream.concat(input.getDirectoryInputs().stream(),
  55. input.getJarInputs().stream()))
  56. .map(input -> input.getFile().getAbsolutePath())
  57. .forEach(entry -> {
  58. try {
  59. classPool.appendClassPath(entry);
  60. } catch (NotFoundException e) {
  61. throw new GradleException(e.getMessage());
  62. }
  63. });
  64.  
  65. return classPool;
  66. }
Add Comment
Please, Sign In to add comment