Skip to content

Commit

Permalink
Merge pull request uber#10 in ANDROID/okbuck from no/merge-upstream t…
Browse files Browse the repository at this point in the history
…o master

* commit '59bc6fbe8b69da8ca16adbc600928eeafab69ed1':
  Publish v0.21.0
  Migrate to kotlin in memory compiler support in buck (uber#450)
  Change how dependencies are resolved in preparation for Andrioid Gradle Plugin 3.x (uber#451)
  Switch the ordering of build config fields. (uber#449)
  Publish v0.20.10
  Revert "Add empty resource rule if using resource union. (uber#438)"
  • Loading branch information
Nelson Osacky committed Jun 6, 2017
2 parents eda73c5 + 59bc6fb commit 24f2265
Show file tree
Hide file tree
Showing 27 changed files with 229 additions and 463 deletions.
2 changes: 1 addition & 1 deletion .buckversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18b5de7165c511070034976be0b852eeb27151ca
800d5a9669417d5a8b4bc455e34a629422ed1ff1
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.20.9'
classpath 'com.uber:okbuck:0.21.0'
}
}
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.20.9'
classpath 'com.uber:okbuck:0.21.0'
}
}
Expand Down
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ dependencies {
compile deps.external.xlogAndroidIdle
compile deps.apt.autoValue

compile project(':libraries:emptyResourceLibrary')
compile project(':libraries:emptylibrary')
compile project(':libraries:kotlinandroidlibrary')
devCompile project(path: ':dummylibrary', configuration: 'freeRelease')
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ task sourcesJar(type: Jar) {
classifier = 'sources'
}

def publishVersion = '0.20.9-SQUARE-2'
def publishVersion = '0.21.0-SQUARE-1'
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 @@ -141,8 +141,7 @@ class OkBuckGradlePlugin implements Plugin<Project> {
true,
true,
intellij.sources,
!lint.disabled,
okbuckExt.buckProjects)
!lint.disabled)

// Fetch Lint deps if needed
if (!lint.disabled && lint.version != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public final class DotBuckConfigLocalFile extends BuckConfigFile {
private final String target;
private final List<String> ignore;
private final String groovyHome;
private final String kotlinCompiler;
private final String kotlinRuntime;
private final String kotlinHome;
private final String proguardJar;
private final Set<String> defs;

Expand All @@ -25,17 +24,15 @@ public DotBuckConfigLocalFile(
String target,
List<String> ignore,
String groovyHome,
String kotlinCompiler,
String kotlinRuntime,
String kotlinHome,
String proguardJar,
Set<String> defs) {
this.aliases = aliases;
this.buildToolVersion = buildToolVersion;
this.target = target;
this.ignore = ignore;
this.groovyHome = groovyHome;
this.kotlinCompiler = kotlinCompiler;
this.kotlinRuntime = kotlinRuntime;
this.kotlinHome = kotlinHome;
this.proguardJar = proguardJar;
this.defs = defs;
}
Expand Down Expand Up @@ -67,10 +64,9 @@ public final void print(PrintStream printer) {
printer.println();
}

if (!StringUtils.isEmpty(kotlinCompiler) && !StringUtils.isEmpty(kotlinRuntime)) {
if (!StringUtils.isEmpty(kotlinHome)) {
printer.println("[kotlin]");
printer.println("\tcompiler = " + kotlinCompiler);
printer.println("\truntime_jar = " + kotlinRuntime);
printer.println("\tkotlin_home = " + kotlinHome);
printer.println();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import org.gradle.api.Project
import org.gradle.api.artifacts.ComponentSelection
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.ResolvedArtifact
import org.gradle.api.artifacts.component.ComponentIdentifier
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
import org.gradle.api.artifacts.result.ResolvedArtifactResult
import org.gradle.plugins.ide.internal.IdeDependenciesExtractor

import java.nio.file.FileSystem
Expand Down Expand Up @@ -35,7 +37,6 @@ class DependencyCache {
private final Map<VersionlessDependency, Set<String>> annotationProcessors = [:]

private final Map<VersionlessDependency, ExternalDependency> externalDeps = [:]
private final Map<VersionlessDependency, ProjectDependency> projectDeps = [:]

DependencyCache(
String name,
Expand All @@ -46,8 +47,7 @@ class DependencyCache {
boolean cleanup = true,
boolean useFullDepName = false,
boolean fetchSources = false,
boolean extractLintJars = false,
Set<Project> depProjects = null) {
boolean extractLintJars = false) {

this.rootProject = rootProject
this.cacheDir = new File(rootProject.projectDir, cacheDirPath)
Expand All @@ -62,11 +62,12 @@ class DependencyCache {
this.useFullDepName = useFullDepName
this.fetchSources = fetchSources
this.extractLintJars = extractLintJars
build(cleanup, depProjects)
build(cleanup)
}

String get(VersionlessDependency dependency) {
ExternalDependency externalDependency = externalDeps.get(dependency)
ExternalDependency externalDependency = dependency.isLocal ?
(ExternalDependency) dependency : externalDeps.get(dependency)
if (externalDependency == null) {
throw new IllegalStateException("Could not find dependency path for ${dependency}")
}
Expand All @@ -91,22 +92,56 @@ class DependencyCache {
}
}

private void build(boolean cleanup, Set<Project> depProjects) {
Set<File> resolvedFiles = [] as Set
String getLintJar(VersionlessDependency dependency) {
return lintJars.get(dependency)
}

if (depProjects) {
depProjects.each { Project project ->
ProjectDependency dependency = new ProjectDependency(project)
projectDeps.put(dependency, dependency)
private File fetchSourcesFor(ExternalDependency dependency) {
// We do not have sources for these dependencies
if (isWhiteListed(dependency.depFile)) {
return null
}

File cachedCopy = new File(cacheDir, dependency.getSourceCacheName(useFullDepName))

if (!cachedCopy.exists()) {
String sourcesJarName = dependency.getSourceCacheName(false)
File sourcesJar = new File(dependency.depFile.parentFile, sourcesJarName)

if (!sourcesJar.exists()) {
def sourceJars = rootProject.fileTree(
dir: dependency.depFile.parentFile.parentFile.absolutePath,
includes: ["**/${sourcesJarName}"]) as List
if (sourceJars.size() == 1) {
sourcesJar = sourceJars[0]
} else if (sourceJars.size() > 1) {
throw new IllegalStateException("Found multiple source jars: ${sourceJars} for ${dependency}")
}
}
if (sourcesJar.exists()) {
Files.createSymbolicLink(cachedCopy.toPath(), sourcesJar.toPath())
}
}

superConfiguration.resolvedConfiguration.resolvedArtifacts.each { ResolvedArtifact artifact ->
ExternalDependency dependency = new ExternalDependency(artifact.moduleVersion.id, artifact.file,
artifact.classifier)
if (!projectDeps.containsKey(dependency.withoutClassifier())) {
externalDeps.put(dependency, dependency)
return cachedCopy.exists() ? cachedCopy : null
}

private void build(boolean cleanup) {
Set<File> resolvedFiles = [] as Set

superConfiguration.incoming.artifacts.each { ResolvedArtifactResult artifact ->
ComponentIdentifier identifier = artifact.id.componentIdentifier
ExternalDependency dependency
if (identifier instanceof ModuleComponentIdentifier) {
dependency = new ExternalDependency(
identifier.group,
identifier.module,
identifier.version,
artifact.file)
} else {
dependency = ExternalDependency.fromLocal(artifact.file)
}
externalDeps.put(dependency, dependency)
resolvedFiles.add(artifact.file)
}

Expand Down Expand Up @@ -173,17 +208,43 @@ class DependencyCache {
}
}

Project getProject(VersionlessDependency dependency) {
ProjectDependency targetDependency = projectDeps.get(dependency.withoutClassifier())
if (targetDependency) {
return targetDependency.project
static boolean isWhiteListed(File depFile) {
return WHITELIST_LOCAL_PATTERNS.find { depFile.absolutePath.contains(it) } != null
}

static File getPackagedLintJarFrom(File aar) {
File lintJar = new File(aar.parentFile, aar.name.replaceFirst(/\.aar$/, '-lint.jar'))
if (lintJar.exists()) {
return lintJar
}
FileSystem zipFile = FileSystems.newFileSystem(aar.toPath(), null)
Path packagedLintJar = zipFile.getPath("lint.jar")
if (Files.exists(packagedLintJar)) {
Files.copy(packagedLintJar, lintJar.toPath(), StandardCopyOption.REPLACE_EXISTING)
return lintJar
} else {
return null
}
}

boolean isWhiteListed(File depFile) {
return WHITELIST_LOCAL_PATTERNS.find { depFile.absolutePath.contains(it) } != null
static File getAnnotationProcessorsFile(File jar) {
File processors = new File(jar.parentFile, jar.name.replaceFirst(/\.jar$/, '.processors'))
if (processors.exists()) {
return processors
}

JarFile jarFile = new JarFile(jar)
JarEntry jarEntry = (JarEntry) jarFile.getEntry("META-INF/services/javax.annotation.processing.Processor")
if (jarEntry) {
List<String> processorClasses = IOUtils.toString(jarFile.getInputStream(jarEntry))
.trim().split("\\n").findAll { String entry ->
!entry.startsWith('#') && !entry.trim().empty // filter out comments and empty lines
}
processors.text = processorClasses.join('\n')
} else {
processors.createNewFile()
}
return processors
}

private static Configuration createSuperConfiguration(Project project,
Expand Down Expand Up @@ -222,73 +283,4 @@ class DependencyCache {
println "\n${message}\n"
}
}

String getLintJar(VersionlessDependency dependency) {
return lintJars.get(dependency)
}

private File fetchSourcesFor(ExternalDependency dependency) {
// We do not have sources for these dependencies
if (isWhiteListed(dependency.depFile)) {
return null
}

File cachedCopy = new File(cacheDir, dependency.getSourceCacheName(useFullDepName))

if (!cachedCopy.exists()) {
String sourcesJarName = dependency.getSourceCacheName(false)
File sourcesJar = new File(dependency.depFile.parentFile, sourcesJarName)

if (!sourcesJar.exists()) {
def sourceJars = rootProject.fileTree(
dir: dependency.depFile.parentFile.parentFile.absolutePath,
includes: ["**/${sourcesJarName}"]) as List
if (sourceJars.size() == 1) {
sourcesJar = sourceJars[0]
} else if (sourceJars.size() > 1) {
throw new IllegalStateException("Found multiple source jars: ${sourceJars} for ${dependency}")
}
}
if (sourcesJar.exists()) {
Files.createSymbolicLink(cachedCopy.toPath(), sourcesJar.toPath())
}
}

return cachedCopy.exists() ? cachedCopy : null
}

static File getPackagedLintJarFrom(File aar) {
File lintJar = new File(aar.parentFile, aar.name.replaceFirst(/\.aar$/, '-lint.jar'))
if (lintJar.exists()) {
return lintJar
}
FileSystem zipFile = FileSystems.newFileSystem(aar.toPath(), null)
Path packagedLintJar = zipFile.getPath("lint.jar")
if (Files.exists(packagedLintJar)) {
Files.copy(packagedLintJar, lintJar.toPath(), StandardCopyOption.REPLACE_EXISTING)
return lintJar
} else {
return null
}
}

static File getAnnotationProcessorsFile(File jar) {
File processors = new File(jar.parentFile, jar.name.replaceFirst(/\.jar$/, '.processors'))
if (processors.exists()) {
return processors
}

JarFile jarFile = new JarFile(jar)
JarEntry jarEntry = (JarEntry) jarFile.getEntry("META-INF/services/javax.annotation.processing.Processor")
if (jarEntry) {
List<String> processorClasses = IOUtils.toString(jarFile.getInputStream(jarEntry))
.trim().split("\\n").findAll { String entry ->
!entry.startsWith('#') && !entry.trim().empty // filter out comments and empty lines
}
processors.text = processorClasses.join('\n')
} else {
processors.createNewFile()
}
return processors
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package com.uber.okbuck.core.dependency

import org.apache.commons.io.FilenameUtils
import org.apache.maven.artifact.versioning.DefaultArtifactVersion
import org.gradle.api.artifacts.ModuleIdentifier
import org.gradle.api.artifacts.ModuleVersionIdentifier

class ExternalDependency extends VersionlessDependency {

Expand All @@ -13,22 +11,23 @@ class ExternalDependency extends VersionlessDependency {
final DefaultArtifactVersion version
final File depFile

ExternalDependency(ModuleVersionIdentifier identifier, File depFile, String classifier) {
super(identifier, classifier)
if (identifier.version) {
version = new DefaultArtifactVersion(identifier.version)
ExternalDependency(String group, String name, String version, File depFile) {
this(group, name, version, depFile, false)
}

private ExternalDependency(String group, String name, String version, File depFile, boolean isLocal) {
super(group, name, isLocal)
if (version) {
this.version = new DefaultArtifactVersion(version)
} else {
version = new DefaultArtifactVersion(LOCAL_DEP_VERSION)
this.version = new DefaultArtifactVersion(LOCAL_DEP_VERSION)
}

this.depFile = depFile
}

@Override
String toString() {
if (classifier) {
return "${this.group}:${this.name}:${this.version}-${this.classifier} -> ${this.depFile.toString()}"
}
return "${this.group}:${this.name}:${this.version} -> ${this.depFile.toString()}"
}

Expand All @@ -50,10 +49,6 @@ class ExternalDependency extends VersionlessDependency {

static ExternalDependency fromLocal(File localDep) {
String baseName = FilenameUtils.getBaseName(localDep.name)
ModuleVersionIdentifier identifier = getDepIdentifier(
baseName,
baseName,
LOCAL_DEP_VERSION)
return new ExternalDependency(identifier, localDep, null)
return new ExternalDependency(baseName, baseName, LOCAL_DEP_VERSION, localDep, true)
}
}
Loading

0 comments on commit 24f2265

Please sign in to comment.