Skip to content

Commit

Permalink
Initial refactor of the plugin structure. (#406)
Browse files Browse the repository at this point in the history
* Initial refactor of the plugin structure.

The short-term/immediate goal is to introduce a place for projects to
indicate whether javadoc needs to be generated for them, it's done here
via `firebaseLibrary.publishJavadoc`.

The long-term vision is to move all build and release logic be
controlled via the 'firebase-library' plugin instead of it being
injected into individual projects from the root-project.

* Fixes

* Update.

* Fix formatting and license
  • Loading branch information
vkryachko committed May 6, 2019
1 parent 56e9731 commit d683101
Show file tree
Hide file tree
Showing 26 changed files with 302 additions and 96 deletions.
4 changes: 4 additions & 0 deletions buildSrc/build.gradle
Expand Up @@ -62,6 +62,10 @@ gradlePlugin {
id = 'PublishingPlugin'
implementationClass = 'com.google.firebase.gradle.plugins.publish.PublishingPlugin'
}
firebaseLibraryPlugin {
id = 'firebase-library'
implementationClass = 'com.google.firebase.gradle.plugins.FirebaseLibraryPlugin'
}
}
}

Expand Down
@@ -0,0 +1,35 @@
// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.firebase.gradle.plugins;

import com.google.firebase.gradle.plugins.ci.device.FirebaseTestLabExtension;
import javax.inject.Inject;
import org.gradle.api.Action;
import org.gradle.api.model.ObjectFactory;

public class FirebaseLibraryExtension {
public boolean publishJavadoc = true;
public boolean publishSources;
public final FirebaseTestLabExtension testLab;

@Inject
public FirebaseLibraryExtension(ObjectFactory objectFactory) {
this.testLab = new FirebaseTestLabExtension(objectFactory);
}

void testLab(Action<FirebaseTestLabExtension> action) {
action.execute(testLab);
}
}
@@ -0,0 +1,54 @@
// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.firebase.gradle.plugins;

import com.android.build.gradle.LibraryExtension;
import com.google.common.collect.ImmutableMap;
import com.google.firebase.gradle.plugins.ci.device.FirebaseTestServer;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.tasks.bundling.Jar;

public class FirebaseLibraryPlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
project.apply(ImmutableMap.of("plugin", "com.android.library"));

FirebaseLibraryExtension firebaseLibrary =
project
.getExtensions()
.create("firebaseLibrary", FirebaseLibraryExtension.class, project.getObjects());

LibraryExtension android = project.getExtensions().getByType(LibraryExtension.class);

android.testServer(new FirebaseTestServer(project, firebaseLibrary.testLab));

// TODO(vkryachko): include sources in firebasePublish
project.afterEvaluate(
p -> {
if (firebaseLibrary.publishSources) {

p.getTasks()
.create(
"sourcesJar",
Jar.class,
jar -> {
jar.from(android.getSourceSets().getByName("main").getJava().getSrcDirs());
jar.setClassifier("sources");
});
}
});
}
}

This file was deleted.

@@ -0,0 +1,53 @@
// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.firebase.gradle.plugins.ci.device;


import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.SetProperty;

import java.util.Collections;
import java.util.Set;

import javax.inject.Inject;

public class FirebaseTestLabExtension {
private final SetProperty<String> devices;
private boolean enabled;

@Inject
public FirebaseTestLabExtension(ObjectFactory objectFactory) {
devices = objectFactory.setProperty(String.class);
}

public void setEnabled(boolean value) {
enabled = value;
}

public boolean getEnabled() {
return enabled;
}

public void device(String device) {
devices.add(device);
}

Set<String> getDevices() {
if( devices.get().isEmpty()) {
return Collections.singleton("model=Pixel2,version=27,locale=en,orientation=portrait");
}
return devices.get();
}
}

This file was deleted.

@@ -0,0 +1,40 @@
// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.firebase.gradle.plugins.ci.device;

import com.android.build.gradle.BaseExtension;

import org.gradle.api.Plugin;
import org.gradle.api.Project;

/**
* Firebase Test Lab Integration plugin.
*
* @deprecated For library projects use 'firebase-library' plugin instead. App projects should still
* use this plugin.
*/
@Deprecated
public class FirebaseTestLabPlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
FirebaseTestLabExtension extension =
project
.getExtensions()
.create("firebaseTestLab", FirebaseTestLabExtension.class, project.getObjects());
extension.setEnabled(true);
BaseExtension android = (BaseExtension) project.getExtensions().getByName("android");
android.testServer(new FirebaseTestServer(project, extension));
}
}
Expand Up @@ -60,7 +60,7 @@ class FirebaseTestServer extends TestServer {

@Override
boolean isConfigured() {
return true
return extension.enabled
}

private List<String> getResultUploadArgs() {
Expand Down
6 changes: 4 additions & 2 deletions firebase-common-ktx/firebase-common-ktx.gradle
Expand Up @@ -12,8 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
plugins {
id 'firebase-library'
id 'kotlin-android'
}

android {
compileSdkVersion project.targetSdkVersion
Expand Down
12 changes: 9 additions & 3 deletions firebase-common/firebase-common.gradle
Expand Up @@ -12,8 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

apply plugin: 'com.android.library'
apply plugin: com.google.firebase.gradle.plugins.ci.device.FirebaseTestLabPlugin
plugins {
id 'firebase-library'
}

firebaseLibrary {
testLab.enabled = true
publishJavadoc = true
}

android {
adbOptions {
Expand Down Expand Up @@ -80,4 +86,4 @@ dependencies {
}

annotationProcessor 'com.google.auto.value:auto-value:1.6'
}
}
Expand Up @@ -12,7 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

apply plugin: 'com.android.library'
plugins {
id 'firebase-library'
}

firebaseLibrary {
publishJavadoc = true
}

android {
compileSdkVersion project.targetSdkVersion
Expand Down
10 changes: 8 additions & 2 deletions firebase-database/firebase-database.gradle
Expand Up @@ -12,8 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

apply plugin: 'com.android.library'
apply plugin: com.google.firebase.gradle.plugins.ci.device.FirebaseTestLabPlugin
plugins {
id 'firebase-library'
}

firebaseLibrary {
testLab.enabled = true
publishJavadoc = true
}

android {
adbOptions {
Expand Down
8 changes: 6 additions & 2 deletions firebase-datatransport/firebase-datatransport.gradle
Expand Up @@ -12,7 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

apply plugin: 'com.android.library'
plugins {
id 'firebase-library'
}

firebaseLibrary.publishJavadoc = false

android {
adbOptions {
Expand Down Expand Up @@ -48,4 +52,4 @@ dependencies {
testImplementation "org.robolectric:robolectric:$robolectricVersion"
testImplementation 'junit:junit:4.12'
testImplementation "com.google.truth:truth:$googleTruthVersion"
}
}
3 changes: 2 additions & 1 deletion firebase-datatransport/gradle.properties
@@ -1,2 +1,3 @@
version=16.0.0
android.enableUnitTestBinaryResources=true
android.enableUnitTestBinaryResources=true
firebaseJavadoc=false
6 changes: 4 additions & 2 deletions firebase-firestore-ktx/firebase-firestore-ktx.gradle
Expand Up @@ -12,8 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
plugins {
id 'firebase-library'
id 'kotlin-android'
}

android {
compileSdkVersion project.targetSdkVersion
Expand Down
12 changes: 9 additions & 3 deletions firebase-firestore/firebase-firestore.gradle
Expand Up @@ -12,9 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

apply plugin: 'com.android.library'
apply plugin: 'com.google.protobuf'
apply plugin: com.google.firebase.gradle.plugins.ci.device.FirebaseTestLabPlugin
plugins {
id 'firebase-library'
id 'com.google.protobuf'
}

firebaseLibrary {
testLab.enabled = true
publishJavadoc = true
}

protobuf {
// Configure the protoc executable
Expand Down
10 changes: 8 additions & 2 deletions firebase-functions/firebase-functions.gradle
Expand Up @@ -12,8 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

apply plugin: 'com.android.library'
apply plugin: com.google.firebase.gradle.plugins.ci.device.FirebaseTestLabPlugin
plugins {
id 'firebase-library'
}

firebaseLibrary {
testLab.enabled = true
publishJavadoc = true
}

android {
adbOptions {
Expand Down

0 comments on commit d683101

Please sign in to comment.