/** build a complete set of local files, files from referenced projects, and dependencies. */ private Set<File> findThriftFiles() throws IOException { final File thriftSourceRoot = getThriftSourceRoot(); Set<File> thriftFiles = new HashSet<File>(); if (thriftSourceRoot != null && thriftSourceRoot.exists()) { thriftFiles.addAll(findThriftFilesInDirectory(thriftSourceRoot)); } getLog().info("finding thrift files in dependencies"); extractFilesFromDependencies( findThriftDependencies(dependencyIncludes), getResourcesOutputDirectory()); if (getResourcesOutputDirectory().exists()) { thriftFiles.addAll(findThriftFilesInDirectory(getResourcesOutputDirectory())); } getLog().info("finding thrift files in referenced (reactor) projects"); thriftFiles.addAll(getReferencedThriftFiles()); return thriftFiles; }
/** Iterate through dependencies, find those specified in the whitelist */ private Set<Artifact> findThriftDependencies(Set<String> whitelist) throws IOException { Set<Artifact> thriftDependencies = new HashSet<Artifact>(); Set<Artifact> deps = new HashSet<Artifact>(); deps.addAll(project.getArtifacts()); deps.addAll(project.getDependencyArtifacts()); Map<String, Artifact> depsMap = new HashMap<String, Artifact>(); for (Artifact dep : deps) { depsMap.put(dep.getId(), dep); } for (Artifact artifact : deps) { // This artifact is on the whitelist directly. if (whitelist.contains(artifact.getArtifactId())) { thriftDependencies.add(artifact); // Check if this artifact is being pulled in by an idl jar that's been whitelisted } else { List<String> depTrail = artifact.getDependencyTrail(); // depTrail can be null sometimes, which seems like a maven bug if (depTrail != null) { for (String name : depTrail) { Artifact dep = depsMap.get(name); if (dep != null && "idl".equals(dep.getClassifier()) && whitelist.contains(dep.getArtifactId())) { thriftDependencies.add(artifact); break; } } } } } return thriftDependencies; }