Skip to content

Commit

Permalink
Use forced external deps everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
Gautam Korlam committed Aug 2, 2017
1 parent a7f86d4 commit dc31fbc
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.uber:okbuck:0.24.3'
classpath 'com.uber:okbuck:0.24.4'
}
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.uber:okbuck:0.24.3'
classpath 'com.uber:okbuck:0.24.4'
}
}
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ task sourcesJar(type: Jar) {
classifier = 'sources'
}

def publishVersion = '0.24.3'
def publishVersion = '0.24.4'
group = 'com.uber'
version = publishVersion
def siteUrl = 'https://github.com/uber/okbuck'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ class OkBuckGradlePlugin implements Plugin<Project> {
// Create configurations
project.configurations.maybeCreate(TransformUtil.CONFIGURATION_TRANSFORM)
Configuration forced = project.configurations.maybeCreate(FORCED_OKBUCK)
forced.transitive = false

// Create tasks
Task setupOkbuck = project.task('setupOkbuck')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class DependencyCache {
private final Set<File> created = new HashSet<>()
private final Set<ExternalDependency> requested = ConcurrentHashMap.newKeySet()

private final Map<String, ExternalDependency> forcedDeps = new HashMap<>()
private final Map<ExternalDependency.VersionlessDependency, ExternalDependency> forcedDeps = new HashMap<>()

DependencyCache(Project project, File cacheDir, String forcedConfiguration = null) {
this.rootProject = project.rootProject
Expand All @@ -50,7 +50,7 @@ class DependencyCache {
if (forcedConfiguration) {
new Scope(project, Collections.singleton(forcedConfiguration)).external.each {
get(it)
forcedDeps.put(it.group + ":" + it.name, it)
forcedDeps.put(it.versionless, it)
}
}
}
Expand Down Expand Up @@ -81,9 +81,7 @@ class DependencyCache {
}

String get(ExternalDependency externalDependency, boolean resolveOnly = false) {
ExternalDependency dependency =
forcedDeps.getOrDefault(externalDependency.group + ":" + externalDependency.name, externalDependency)

ExternalDependency dependency = forcedDeps.getOrDefault(externalDependency.versionless, externalDependency)
File cachedCopy = new File(cacheDir, dependency.getCacheName(!resolveOnly))
String key = FileUtil.getRelativePath(rootProject.projectDir, cachedCopy)
createLink(Paths.get(key), dependency.depFile.toPath())
Expand All @@ -99,9 +97,10 @@ class DependencyCache {
/**
* Gets the sources jar path for a dependency if it exists.
*
* @param dependency The dependency.
* @param externalDependency The dependency.
*/
void getSources(ExternalDependency dependency) {
void getSources(ExternalDependency externalDependency) {
ExternalDependency dependency = forcedDeps.getOrDefault(externalDependency.versionless, externalDependency)
String key = dependency.cacheName
String sourcesJarPath = sources.get(key)
if (sourcesJarPath == null || !Files.exists(Paths.get(sourcesJarPath))) {
Expand Down Expand Up @@ -135,10 +134,11 @@ class DependencyCache {
/**
* Get the list of annotation processor classes provided by a dependency.
*
* @param dependency The dependency
* @param externalDependency The dependency
* @return The list of annotation processor classes available in the manifest
*/
List<String> getAnnotationProcessors(ExternalDependency dependency) {
List<String> getAnnotationProcessors(ExternalDependency externalDependency) {
ExternalDependency dependency = forcedDeps.getOrDefault(externalDependency.versionless, externalDependency)
String key = dependency.cacheName
String processorsList = processors.get(key)
if (processorsList == null) {
Expand Down Expand Up @@ -166,20 +166,22 @@ class DependencyCache {
/**
* Get the packaged lint jar of an aar dependency if any.
*
* @param dependency The depenency
* @param externalDependency The depenency
* @return path to the lint jar in the cache.
*/
String getLintJar(ExternalDependency dependency) {
String getLintJar(ExternalDependency externalDependency) {
ExternalDependency dependency = forcedDeps.getOrDefault(externalDependency.versionless, externalDependency)
return getAarEntry(dependency, lintJars, "lint.jar", "-lint.jar")
}

/**
* Get the packaged proguard config of an aar dependency if any.
*
* @param dependency The depenency
* @param externalDependency The depenency
* @return path to the proguard config in the cache.
*/
File getProguardConfig(ExternalDependency dependency) {
File getProguardConfig(ExternalDependency externalDependency) {
ExternalDependency dependency = forcedDeps.getOrDefault(externalDependency.versionless, externalDependency)
String entry = getAarEntry(dependency, proguardConfigs, "proguard.txt", "-proguard.pro")
if (entry) {
return new File(entry)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public final class ExternalDependency {
public final File depFile;
public final String group;
public final String name;
public final VersionlessDependency versionless;

public ExternalDependency(String group, String name, String version, File depFile) {
this(group, name, version, depFile, false);
Expand All @@ -32,20 +33,16 @@ public boolean equals(Object o) {

ExternalDependency that = (ExternalDependency) o;

if (isLocal != that.isLocal) { return false; }
if (version != null ? !version.equals(that.version) : that.version != null) { return false; }
if (depFile != null ? !depFile.equals(that.depFile) : that.depFile != null) { return false; }
if (group != null ? !group.equals(that.group) : that.group != null) { return false; }
return name != null ? name.equals(that.name) : that.name == null;
if (!version.equals(that.version)) { return false; }
if (!group.equals(that.group)) { return false; }
return name.equals(that.name);
}

@Override
public int hashCode() {
int result = (isLocal ? 1 : 0);
result = 31 * result + (version != null ? version.hashCode() : 0);
result = 31 * result + (depFile != null ? depFile.hashCode() : 0);
result = 31 * result + (group != null ? group.hashCode() : 0);
result = 31 * result + (name != null ? name.hashCode() : 0);
int result = version.hashCode();
result = 31 * result + group.hashCode();
result = 31 * result + name.hashCode();
return result;
}

Expand Down Expand Up @@ -86,10 +83,28 @@ private ExternalDependency(String group, String name, String version, File depFi
}

this.depFile = depFile;
this.versionless = new VersionlessDependency(group, name);
}

public static ExternalDependency fromLocal(File localDep) {
String baseName = FilenameUtils.getBaseName(localDep.getName());
return new ExternalDependency(baseName, baseName, LOCAL_DEP_VERSION, localDep, true);
}

public static class VersionlessDependency {
private final String group;
private final String name;

VersionlessDependency(String group, String name) {
this.group = group;
this.name = name;
}

@Override
public int hashCode() {
int result = group.hashCode();
result = 31 * result + name.hashCode();
return result;
}
}
}

0 comments on commit dc31fbc

Please sign in to comment.