public ModuleLibraryImpl(@NonNull Dependency dependency) { Preconditions.checkNotNull(dependency.getProjectPath()); this.address = dependency.getAddress().toString(); this.artifactFile = dependency.getArtifactFile(); this.projectPath = dependency.getProjectPath(); if (dependency instanceof ExtractedDependency) { variant = ((ExtractedDependency) dependency).getVariant(); } else { variant = null; } }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } if (!super.equals(o)) { return false; } JavaDependency that = (JavaDependency) o; return isLocal == that.isLocal; }
@Override public int hashCode() { return HashCodeUtils.hashCode(super.hashCode(), extractedFolder, variant); } }
if (dependency.getProjectPath() != null || dependency.isLocal()) { continue; File jarFile = dependency.getClasspathFile(); if (jarFile.isFile()) { jars.add(jarFile); List<File> additionalJarFiles = dependency.getAdditionalClasspath(); if (additionalJarFiles != null) { for (File jar : additionalJarFiles) {
@NonNull @Override public List<String> getSkippedList() { List<String> skippedList = Lists.newArrayListWithExpectedSize(dataMap.size()); for (Map.Entry<Dependency, DependencyMutableData> entry : dataMap.entrySet()) { if (entry.getValue().isSkipped()) { skippedList.add(entry.getKey().getAddress().toString()); } } return skippedList; }
/** * Returns the packaged sub-project Jars, coming from Android or Java modules. * * @return a non null, but possibly empty set. */ @NonNull public Set<File> getSubProjectPackagedJars() { final DependencyContainer packageDeps = getPackageDependencies(); Set<File> jars = Sets.newLinkedHashSetWithExpectedSize( packageDeps.getAllPackagedDependencies().size()); for (Dependency dependency : packageDeps.getAllPackagedDependencies()) { // only take the sub-project dependencies if (dependency.getProjectPath() != null) { File libJar = dependency.getClasspathFile(); if (libJar.isFile()) { jars.add(libJar); } } } return jars; }
final File classpathFile = dependency.getClasspathFile(); if (classpathFile.isFile()) { jars.add(classpathFile); List<File> otherJars = dependency.getAdditionalClasspath(); if (otherJars != null) { for (File otherJar : otherJars) {
private static Library instantiateLibrary(@NonNull Dependency dependency) { Library library; if (dependency.getProjectPath() != null) { library = new ModuleLibraryImpl(dependency); } else if (dependency instanceof AndroidDependency) { AndroidDependency androidDependency = (AndroidDependency) dependency; library = new AndroidLibraryImpl( androidDependency, DependenciesConverter.findLocalJar(androidDependency)); } else if (dependency instanceof JavaDependency) { library = new JavaLibraryImpl((JavaDependency) dependency); } else { throw new RuntimeException("unknown Dependency instance"); } return library; }
/** * collect a map of (key, library) for all libraries. * * The key is either the gradle project path or the maven coordinates. The format of each * makes it impossible to have collisions. * * This only goes through the list and not the children of the library in it, so this expects * the dependency graph to have been flattened already. * * @param dependencies the dependencies */ private static void collectSkippableLibraryMap( @NonNull Collection<Dependency> dependencies, @NonNull Map<String, AndroidDependency> androidMap, @NonNull Map<String, JavaDependency> javaMap) { for (Dependency dependency : dependencies) { if (dependency instanceof AndroidDependency) { MavenCoordinates coordinates = dependency.getCoordinates(); androidMap.put(coordinates.getVersionlessId(), (AndroidDependency) dependency); } else if (dependency instanceof JavaDependency) { MavenCoordinates coordinates = dependency.getCoordinates(); javaMap.put(coordinates.getVersionlessId(), (JavaDependency) dependency); } } }
@NonNull @Override public List<String> getProvidedList() { List<String> providedList = Lists.newArrayListWithExpectedSize(dataMap.size()); for (Map.Entry<Dependency, DependencyMutableData> entry : dataMap.entrySet()) { if (entry.getValue().isProvided()) { providedList.add(entry.getKey().getAddress().toString()); } } return providedList; }
/** * Returns the list of packaged jars for this config. If the config tests a library, this * will include the jars of the tested config * * @return a non null, but possibly empty list. */ @NonNull public Set<File> getAllPackagedJars() { final DependencyContainer packageDeps = getPackageDependencies(); Set<File> jars = Sets.newLinkedHashSetWithExpectedSize( packageDeps.getAllDependencies().size()); for (Dependency dependency : packageDeps.getAllPackagedDependencies()) { File jarFile = dependency.getClasspathFile(); if (jarFile.isFile()) { jars.add(jarFile); } List<File> additionalJarFiles = dependency.getAdditionalClasspath(); if (additionalJarFiles != null) { for (File jar : additionalJarFiles) { if (jar.isFile()) { jars.add(jar); } } } } return jars; }
private void cloneJavaLibraries( @NonNull List<DependencyNode> nodes, @NonNull Set<JavaLibrary> outLibraries) { for (DependencyNode node : nodes) { Dependency dependency = dependencyContainer.getDependencyMap().get(node.getAddress()); if (dependency.getProjectPath() != null) { continue; } switch (node.getNodeType()) { case JAVA: JavaDependency javaDep = (JavaDependency) dependency; outLibraries.add(sJarCache.get(factory.create(javaDep))); // intended fall-through case ANDROID: // dont convert but go recursively for potential java dependencies. cloneJavaLibraries(node.getDependencies(), outLibraries); break; case ATOM: // do nothing break; } } }
/** * Returns a map representing the tested dependencies. This represents only the packaged * ones as they are the one that matters when figuring out what to skip in the test * graphs. * * The map represents (dependency key, version) where the key is basically * the coordinates minus the version. * * @return the map */ private static Map<String, String> collectTestedDependencyMap( @Nullable VariantDependencies testedVariantDeps) { if (testedVariantDeps == null) { return ImmutableMap.of(); } DependencyContainer packageDeps = testedVariantDeps.getPackageDependencies(); Map<String, String> map = Maps .newHashMapWithExpectedSize(packageDeps.getAllDependencies().size()); for (Dependency dependency : packageDeps.getAllDependencies()) { MavenCoordinates coordinates = dependency.getCoordinates(); map.put(coordinates.getVersionlessId(), coordinates.getVersion()); } return map; }
/** * Returns a unique address that matches {@link DependencyNode#getAddress()}. */ @Override @NonNull public Object getAddress() { if (variant != null) { return getProjectPath() + "::" + variant; } return super.getAddress(); }
/** * Returns the compile classpath for this config. If the config tests a library, this * will include the classpath of the tested config * * @return a non null, but possibly empty set. */ @NonNull public Set<File> getCompileClasspath() { DependencyContainer compileDep = getCompileDependencies(); Set<File> classpath = Sets.newLinkedHashSetWithExpectedSize( compileDep.getAllDependencies().size()); for (Dependency dependency : compileDep.getAllDependencies()) { classpath.add(dependency.getClasspathFile()); List<File> additionalFiles = dependency.getAdditionalClasspath(); if (additionalFiles != null) { classpath.addAll(additionalFiles); } } return classpath; }
MavenCoordinates coordinates = dependency.getCoordinates(); String testedVersion = testedMap.get(coordinates.getVersionlessId());
private int computeHashCode() { return HashCodeUtils.hashCode(super.hashCode(), isLocal); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } if (!super.equals(o)) { return false; } ExtractedDependency that = (ExtractedDependency) o; return Objects.equals(extractedFolder, that.extractedFolder) && Objects.equals(variant, that.variant); }
private static Pair<Dependency, DependencyNode> createRenderscriptSupport( @NonNull Pair<File, String> pair) { Dependency dependency = new JavaDependency( pair.getFirst(), new MavenCoordinatesImpl("com.android.support", "renderscript", pair.getSecond()), "renderscript-" + pair.getSecond(), null /*projectPath*/); return Pair.of( dependency, new DependencyNode(dependency.getAddress(), JAVA, ImmutableList.of(), null)); }
alreadyCreatedDependency.getAddress(), nodeType, transitiveDependencies,