Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Add support for library variants #36

Merged
merged 1 commit into from
Apr 21, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package com.novoda.sqlite.generator

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.ProjectConfigurationException

class SqliteAnalyzerPlugin implements Plugin<Project> {
void apply(Project project) {
ensurePluginDependencies(project)
def extension = project.extensions.create('sqliteAccess', SqliteAnalyzerExtension, project)
project.afterEvaluate {
project.android.applicationVariants.all { variant ->
project.android[variants(project)].all { variant ->
File sourceFolder = project.file("${project.buildDir}/generated/source/sqlite/${variant.dirName}")
def javaGenerationTask = project.tasks.create(name: "generate${variant.name.capitalize()}SqliteAccess", type: GenerateDBAccess) {
dbConnection extension.dbConnector
Expand All @@ -23,9 +24,26 @@ class SqliteAnalyzerPlugin implements Plugin<Project> {
}

private static void ensurePluginDependencies(Project project) {
def hasAndroid = project.plugins.hasPlugin('android') || project.plugins.hasPlugin('android-library')
if (!hasAndroid) {
throw new RuntimeException("The 'android' or 'android-library' plugin is required.")
if (!isApplication(project) && !isLibrary(project)) {
throw new ProjectConfigurationException("The 'android' or 'android-library' plugin is required.", null)
}
}

private static String variants(Project project) {
if (isApplication(project)) {
return 'applicationVariants'
} else if (isLibrary(project)) {
return 'libraryVariants'
}
throw new ProjectConfigurationException("The 'android' or 'android-library' plugin is required.", null)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the name of the plugins has been deprecated in favour of com.android.application and com.android.library. We should align logs with that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 good point

}

private static boolean isLibrary(Project project) {
project.plugins.hasPlugin('com.android.library') || project.plugins.hasPlugin('android-library')
}

private static boolean isApplication(Project project) {
project.plugins.hasPlugin('com.android.application') || project.plugins.hasPlugin('android')
}

}