Skip to content

Commit

Permalink
Merge branch 'master' into davidmotson.config_cache
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmotson authored Apr 29, 2021
2 parents 4e985b6 + 01b2c86 commit 379ae07
Show file tree
Hide file tree
Showing 12 changed files with 468 additions and 74 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Perform a Gradle `build` which includes `assemble`, `check`, `test` of the projects.

name: CI

# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ master ]
pull_request:
branches: [ master ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Runs this job in parallel for each sub-project
strategy:
matrix:
project-dir:
- strict-version-matcher-plugin
- google-services-plugin
- oss-licenses-plugin

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
# Runs a build which includes `check` and `test` tasks
- name: Perform a Gradle build
run: ./gradlew build
working-directory: ./${{ matrix.project-dir }}
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-rc-5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

2 changes: 1 addition & 1 deletion oss-licenses-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ and add the oss-licenses plugin to your dependencies:
dependencies {
// ...
// Add this line:
classpath 'com.google.android.gms:oss-licenses-plugin:0.10.2'
classpath 'com.google.android.gms:oss-licenses-plugin:0.10.4'
}

In your app-level `build.gradle`, apply the plugin by adding the following line
Expand Down
5 changes: 4 additions & 1 deletion oss-licenses-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
apply plugin: 'groovy'
apply plugin: 'java'

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
implementation gradleApi()
implementation localGroovy()
Expand All @@ -10,7 +13,7 @@ dependencies {
}

group = 'com.google.android.gms'
version = '0.10.2'
version = '0.10.4'

apply plugin: 'maven'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ import groovy.json.JsonBuilder
import groovy.json.JsonException
import groovy.json.JsonSlurper
import org.gradle.api.DefaultTask
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.ConfigurationContainer
import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.ExternalModuleDependency
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.artifacts.ResolveException
import org.gradle.api.artifacts.ResolvedArtifact
import org.gradle.api.artifacts.ResolvedDependency
Expand Down Expand Up @@ -56,14 +60,67 @@ class DependencyTask extends DefaultTask {

private static final logger = LoggerFactory.getLogger(DependencyTask.class)

@Input
public ConfigurationContainer configurations
private Project project

@OutputDirectory
public File outputDir
File outputDir

@OutputFile
public File outputFile
File outputFile

/**
* Returns a serializable snapshot of direct dependencies from all relevant
* configurations to allow task caching. To improve performance, this does
* not resolve transitive dependencies. Direct dependencies should require a
* version bump to publish a new POM file with updated transitive
* dependencies.
*/
@Input
List<String> getDirectDependencies() {
return collectDependenciesFromConfigurations(
project.getConfigurations(),
[project] as Set<Project>
)
}

protected List<String> collectDependenciesFromConfigurations(
ConfigurationContainer configurationContainer,
Set<Project> visitedProjects
) {
Set<String> directDependencies = new HashSet<>()
Set<Project> libraryProjects = new HashSet<>()
for (Configuration configuration in configurationContainer) {
if (shouldSkipConfiguration(configuration)) {
continue
}

for (Dependency dependency in configuration.allDependencies) {
if (dependency instanceof ProjectDependency) {
libraryProjects.add(dependency.getDependencyProject())
} else if (dependency instanceof ExternalModuleDependency) {
directDependencies.add(toMavenId(dependency))
}
}
}
for (Project libraryProject in libraryProjects) {
if (libraryProject in visitedProjects) {
continue
}
visitedProjects.add(libraryProject)
logger.info("Visiting dependency ${libraryProject.displayName}")
directDependencies.addAll(
collectDependenciesFromConfigurations(
libraryProject.getConfigurations(),
visitedProjects
)
)
}
return directDependencies.sort()
}

protected static String toMavenId(Dependency dependency) {
return "${dependency.getGroup()}:${dependency.getName()}:${dependency.getVersion()}"
}

@TaskAction
void action() {
Expand All @@ -86,24 +143,25 @@ class DependencyTask extends DefaultTask {
* false otherwise
*/
protected boolean checkArtifactSet(File file) {
Set<String> artifacts = new HashSet<>(artifactSet)
try {
def previousArtifacts = new JsonSlurper().parse(file)
for (entry in previousArtifacts) {
String key = "${entry.fileLocation}"
if (artifactSet.contains(key)) {
artifactSet.remove(key)
if (artifacts.contains(key)) {
artifacts.remove(key)
} else {
return false
}
}
return artifactSet.isEmpty()
return artifacts.isEmpty()
} catch (JsonException exception) {
return false
}
}

protected void updateDependencyArtifacts() {
for (Configuration configuration : configurations) {
for (Configuration configuration : project.getConfigurations()) {
Set<ResolvedArtifact> artifacts = getResolvedArtifacts(
configuration)
if (artifacts == null) {
Expand Down Expand Up @@ -181,14 +239,8 @@ class DependencyTask extends DefaultTask {

protected Set<ResolvedArtifact> getResolvedArtifacts(
Configuration configuration) {
/**
* skip the configurations that, cannot be resolved in
* newer version of gradle api, are tests, or are not packaged dependencies.
*/

if (!canBeResolved(configuration)
|| isTest(configuration)
|| !isPackagedDependency(configuration)) {
if (shouldSkipConfiguration(configuration)) {
return null
}

Expand All @@ -203,6 +255,16 @@ class DependencyTask extends DefaultTask {
}
}

/**
* Returns true for configurations that cannot be resolved in the newer
* version of gradle API, are tests, or are not packaged dependencies.
*/
private boolean shouldSkipConfiguration(Configuration configuration) {
(!canBeResolved(configuration)
|| isTest(configuration)
|| !isPackagedDependency(configuration))
}

protected Set<ResolvedArtifact> getResolvedArtifactsFromResolvedDependencies(
Set<ResolvedDependency> resolvedDependencies) {

Expand Down Expand Up @@ -234,4 +296,8 @@ class DependencyTask extends DefaultTask {
outputDir.mkdirs()
}
}

void setProject(Project project) {
this.project = project
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,23 @@
package com.google.android.gms.oss.licenses.plugin

import org.gradle.api.DefaultTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskAction

/**
* Task to clean up the generated dependency.json, third_party_licenses and
* third_party_license_metadata files.
*/
class LicensesCleanUpTask extends DefaultTask {
@Input
public File dependencyFile

@Input
public File dependencyDir
protected File dependencyFile

@Input
public File licensesFile
protected File dependencyDir

@Input
public File metadataFile
protected File licensesFile

@Input
public File licensesDir
protected File metadataFile

protected File licensesDir

@TaskAction
void action() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ class LicensesTask extends DefaultTask {
protected Map<String, String> licensesMap = [:]

@InputFile
public File dependenciesJson
File dependenciesJson

@OutputDirectory
public File outputDir
File outputDir

@OutputFile
public File licenses
File licenses

@OutputFile
public File licensesMetadata
File licensesMetadata

@TaskAction
void action() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class OssLicensesPlugin implements Plugin<Project> {
def dependencyOutput = new File(project.buildDir,
"generated/third_party_licenses")
def generatedJson = new File(dependencyOutput, "dependencies.json")
getDependencies.configurations = project.getConfigurations()
getDependencies.setProject(project)
getDependencies.outputDir = dependencyOutput
getDependencies.outputFile = generatedJson

Expand Down
Loading

0 comments on commit 379ae07

Please sign in to comment.