Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android source sets configured for LibraryPlugin #82

Merged
merged 3 commits into from
Sep 21, 2015
Merged
Show file tree
Hide file tree
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 @@ -17,6 +17,7 @@

package nl.javadude.gradle.plugins.license

import com.android.build.gradle.LibraryPlugin
import com.android.build.gradle.api.AndroidSourceSet
import com.android.build.gradle.AppPlugin
import org.gradle.api.Action
Expand Down Expand Up @@ -67,7 +68,11 @@ class LicensePlugin implements Plugin<Project> {
}

withOptionalPlugin('com.android.build.gradle.AppPlugin') {
configureAndroid()
configureAndroid(AppPlugin)
}

withOptionalPlugin('com.android.build.gradle.LibraryPlugin') {
configureAndroid(LibraryPlugin)
}
}

Expand Down Expand Up @@ -259,20 +264,20 @@ class LicensePlugin implements Plugin<Project> {
task.source = sourceSet.allSource
}

private void configureAndroid() {
configureExtensionRule(AppPlugin)
private void configureAndroid(Class pluginType) {
configureExtensionRule(pluginType)
project.afterEvaluate {
// Since we're going to look at the extension, we need to run late enough to let the user configure it
configureAndroidSourceSetRule()
configureAndroidSourceSetRule(pluginType)
}
}

/**
* Dynamically create a task for each sourceSet, and register with check
*/
private void configureAndroidSourceSetRule() {
private void configureAndroidSourceSetRule(Class pluginType) {
// This follows the other check task pattern
project.plugins.withType(AppPlugin) {
project.plugins.withType(pluginType) {
extension.sourceSets.all { AndroidSourceSet sourceSet ->
def sourceSetTaskName = (taskBaseName + 'Android' + sourceSet.name.capitalize())
logger.info("[AndroidLicensePlugin] Adding license tasks for sourceSet ${sourceSetTaskName}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,48 @@

package nl.javadude.gradle.plugins.license

import com.android.build.gradle.AppPlugin
import com.android.build.gradle.LibraryPlugin
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.testfixtures.ProjectBuilder
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized

import static org.hamcrest.CoreMatchers.*
import static org.junit.Assert.assertThat
import static org.junit.Assert.assertFalse
import static org.junit.Assert.assertThat

@RunWith(Parameterized.class)
class AndroidLicensePluginTest {
Project project
String pluginName
Class pluginClass

@Parameterized.Parameters(name = "Plugin {0}")
public static Collection<Object[]> pluginTypes() {
Object[][] params = [
[ 'com.android.application', AppPlugin ],
[ 'com.android.library', LibraryPlugin ]
];
return Arrays.asList(params);
}

public AndroidLicensePluginTest(pluginName, pluginClass) {
this.pluginName = pluginName
this.pluginClass = pluginClass
}

@Before
public void setupProject() {
project = ProjectBuilder.builder().withProjectDir(new File("testProject")).build()
def plugin = project.plugins.apply(LicensePlugin)
project.apply plugin: 'com.android.application'
project.apply plugin: pluginName

// Otherwise we'd need a project.evaluate() which would trigger Android SDK detection
plugin.configureAndroidSourceSetRule()
plugin.configureAndroidSourceSetRule(pluginClass)
}

@Test
Expand Down