Skip to content

Commit 6afd1e8

Browse files
committed
Output artifact list during local publishing.
This effort replaces #494.
1 parent 63232fc commit 6afd1e8

File tree

5 files changed

+118
-9
lines changed

5 files changed

+118
-9
lines changed

buildSrc/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ dependencies {
3737
implementation 'org.jsoup:jsoup:1.11.2'
3838
implementation 'digital.wup:android-maven-publish:3.6.2'
3939
implementation 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.20'
40+
implementation 'org.json:json:20180813'
4041

4142
implementation 'io.opencensus:opencensus-api:0.18.0'
4243
implementation 'io.opencensus:opencensus-exporter-stats-stackdriver:0.18.0'
4344
runtime 'io.opencensus:opencensus-impl:0.18.0'
4445

4546
implementation 'com.android.tools.build:gradle:3.2.1'
4647
testImplementation 'junit:junit:4.12'
47-
testImplementation 'org.json:json:20180813'
4848
testImplementation('org.spockframework:spock-core:1.1-groovy-2.4') {
4949
exclude group: 'org.codehaus.groovy'
5050
}

buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/ci/AffectedProjectFinder.groovy

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ class AffectedProjectFinder {
2525
Set<String> changedPaths;
2626

2727
@Builder
28+
AffectedProjectFinder(Project project, List<Pattern> ignorePaths) {
29+
this(project, changedPaths(project.rootDir), ignorePaths)
30+
}
31+
2832
AffectedProjectFinder(Project project,
2933
Set<String> changedPaths,
3034
List<Pattern> ignorePaths) {
@@ -49,6 +53,13 @@ class AffectedProjectFinder {
4953
return project.subprojects
5054
}
5155

56+
private static Set<String> changedPaths(File workDir) {
57+
return 'git diff --name-only --submodule=diff HEAD@{0} HEAD@{1}'
58+
.execute([], workDir)
59+
.text
60+
.readLines()
61+
}
62+
5263
/**
5364
* Performs a post-order project tree traversal and returns a set of projects that own the
5465
* 'changedPaths'.

buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/ci/ContinuousIntegrationPlugin.groovy

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ class ContinuousIntegrationPlugin implements Plugin<Project> {
9797

9898
def affectedProjects = AffectedProjectFinder.builder()
9999
.project(project)
100-
.changedPaths(changedPaths(project.rootDir))
101100
.ignorePaths(extension.ignorePaths)
102101
.build()
103102
.find()
@@ -143,13 +142,6 @@ class ContinuousIntegrationPlugin implements Plugin<Project> {
143142
}
144143
}
145144

146-
private static Set<String> changedPaths(File workDir) {
147-
return 'git diff --name-only --submodule=diff HEAD@{0} HEAD@{1}'
148-
.execute([], workDir)
149-
.text
150-
.readLines()
151-
}
152-
153145
private static final ANDROID_PLUGINS = ["com.android.application", "com.android.library",
154146
"com.android.test"]
155147

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Copyright 2018 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.gradle.plugins.ci
16+
17+
import com.google.firebase.gradle.plugins.FirebaseLibraryExtension
18+
import com.google.firebase.gradle.plugins.ci.AffectedProjectFinder
19+
import org.gradle.api.Plugin
20+
import org.gradle.api.Project
21+
import org.gradle.api.artifacts.ProjectDependency
22+
import org.json.JSONArray
23+
import org.json.JSONObject
24+
25+
/** Builds Firebase libraries for consumption by the smoke tests. */
26+
class SmokeTestsPlugin implements Plugin<Project> {
27+
@Override
28+
public void apply(Project project) {
29+
def assembleAllTask = project.task("assembleAllForSmokeTests")
30+
31+
// Wait until after the projects have been evaluated or else we might skip projects.
32+
project.gradle.projectsEvaluated {
33+
def changedProjects = getChangedProjects(project)
34+
def changedArtifacts = new HashSet<String>()
35+
def allArtifacts = new HashSet<String>()
36+
37+
// Visit each project and add the artifacts to the appropriate sets.
38+
project.subprojects {
39+
def firebaseLibrary = it.extensions.findByType(FirebaseLibraryExtension)
40+
if (firebaseLibrary == null) {
41+
return
42+
}
43+
44+
def groupId = firebaseLibrary.groupId.get()
45+
def artifactId = firebaseLibrary.artifactId.get()
46+
def artifact = "$groupId:$artifactId:$it.version-SNAPSHOT"
47+
allArtifacts.add(artifact)
48+
49+
if (changedProjects.contains(it)) {
50+
changedArtifacts.add(artifact)
51+
}
52+
}
53+
54+
// Reuse the publish task for building the libraries.
55+
def publishAllTask = project.tasks.getByPath("publishAllToBuildDir")
56+
assembleAllTask.dependsOn(publishAllTask)
57+
58+
// Generate a JSON file listing the artifacts after everything is complete.
59+
assembleAllTask.doLast {
60+
def changed = new JSONArray()
61+
changedArtifacts.each { changed.put(it) }
62+
63+
def all = new JSONArray()
64+
allArtifacts.each { all.put(it) }
65+
66+
def json = new JSONObject()
67+
json.put("all", all)
68+
json.put("changed", changed)
69+
70+
def path = project.buildDir.toPath()
71+
path.resolve("m2repository/changed-artifacts.json").write(json.toString())
72+
}
73+
}
74+
}
75+
76+
private static Set<Project> getChangedProjects(Project p) {
77+
Set<Project> roots = new AffectedProjectFinder(p, []).find()
78+
HashSet<Project> changed = new HashSet<>()
79+
80+
getChangedProjectsLoop(roots, changed)
81+
return changed
82+
}
83+
84+
private static void getChangedProjectsLoop(Collection<Project> projects, Set<Project> changed) {
85+
for (Project p : projects) {
86+
// Skip project if it is not a Firebase library.
87+
if (p.extensions.findByType(FirebaseLibraryExtension) == null) {
88+
continue;
89+
}
90+
91+
// Skip processing and recursion if this project has already been added to the set.
92+
if (!changed.add(p)) {
93+
continue;
94+
}
95+
96+
// Find all (head) dependencies to other projects in this respository.
97+
def all = p.configurations.releaseRuntimeClasspath.allDependencies
98+
def affected =
99+
all.findAll { it instanceof ProjectDependency }.collect { it.getDependencyProject() }
100+
101+
// Recurse with the new dependencies.
102+
getChangedProjectsLoop(affected, changed)
103+
}
104+
}
105+
}

root-project.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ ext {
5252

5353
apply plugin: com.google.firebase.gradle.plugins.publish.PublishingPlugin
5454
apply plugin: com.google.firebase.gradle.plugins.ci.ContinuousIntegrationPlugin
55+
apply plugin: com.google.firebase.gradle.plugins.ci.SmokeTestsPlugin
5556
apply plugin: com.google.firebase.gradle.plugins.ci.metrics.MetricsPlugin
5657

5758
firebaseContinuousIntegration {

0 commit comments

Comments
 (0)