diff --git a/README.md b/README.md index bc96a8f..2390720 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,8 @@ Here is a general overview of the options: - mapping(String ext, String style) -- Adds a mapping between a file extension and a style type - mapping(Map mappings) -- Adds mappings between file extensions and style types - mapping(Closure) -- Adds mappings between file extensions and a style types, see example below +- exclude(String pattern) -- Add an ANT style pattern to exclude files from license absence reporting and license application +- exclude(Collection patterns) -- Add ANT style patterns to exclude files from license absence reporting and license application ### File Types Supported by default: java, groovy, js, css, xml, dtd, xsd, html, htm, xsl, fml, apt, properties, sh, txt, bat, cmd, sql, jsp, ftl, xhtml, vm, jspx, gsp, json. Complete list can be found in SupportedFormats page of the parent project. @@ -105,6 +107,18 @@ license { // or licenseMain.ext.year = 2012 ``` + +### Exclude files from license absence reporting and license application +By default all files in the sourceSets configured are required to carry a license. In order to exclude certain file(-types), you can add exclusion patterns. + +The following sample will exclude all properties, txt and conf files. +``` +license { + exclude "**/*.properties" + excludes(["**/*.txt", "**/*.conf"]) +} +``` + ## License Reporting The downloadLicense task has a set of properties, most can be set in the extension: @@ -148,4 +162,4 @@ downloadLicenses { ## v0.8.0 - Merged pull-requests [#31](https://github.com/hierynomus/license-gradle-plugin/pull/31), [#33](https://github.com/hierynomus/license-gradle-plugin/pull/33), [#42](https://github.com/hierynomus/license-gradle-plugin/pull/42) -- \ No newline at end of file +- diff --git a/src/main/groovy/nl/javadude/gradle/plugins/license/License.groovy b/src/main/groovy/nl/javadude/gradle/plugins/license/License.groovy index c1dc275..f619e26 100644 --- a/src/main/groovy/nl/javadude/gradle/plugins/license/License.groovy +++ b/src/main/groovy/nl/javadude/gradle/plugins/license/License.groovy @@ -63,7 +63,7 @@ public class License extends SourceTask implements VerificationTask { boolean useDefaultMappings boolean strictCheck - + @InputFile File header @@ -78,6 +78,10 @@ public class License extends SourceTask implements VerificationTask { @TaskAction protected void process() { + // Plain weird, but this ensures that the lazy closure from the extension is properly wired into the excludes field of the SourceTask. + logger.info("$path: ${getExcludes()}") + excludes = getExcludes() + if (!enabled) { didWork = false; return; diff --git a/src/main/groovy/nl/javadude/gradle/plugins/license/LicenseExtension.groovy b/src/main/groovy/nl/javadude/gradle/plugins/license/LicenseExtension.groovy index 824e197..3478811 100644 --- a/src/main/groovy/nl/javadude/gradle/plugins/license/LicenseExtension.groovy +++ b/src/main/groovy/nl/javadude/gradle/plugins/license/LicenseExtension.groovy @@ -21,7 +21,7 @@ import org.gradle.api.tasks.SourceSet /** * Extension in the license namespace, which drives the License tasks. - * + * * @author jryan */ class LicenseExtension { @@ -35,6 +35,11 @@ class LicenseExtension { */ Collection sourceSets // Probably should be final SourceSetContainer, so that it doesn't turn out null at anytime + /** + * Path patterns to exclude while applying licenses or reporting missing licenses + */ + Collection excludePatterns = new HashSet() + /** * Whether or not to allow the build to continue if there are warnings. */ @@ -42,7 +47,7 @@ class LicenseExtension { /** * Whether to create new files which have changes or to make them inline - * + * */ boolean dryRun; @@ -55,7 +60,7 @@ class LicenseExtension { * @link {AbstractLicenseMojo.useDefaultMappings} */ boolean useDefaultMappings - + boolean strictCheck Map internalMappings = new HashMap(); @@ -75,4 +80,12 @@ class LicenseExtension { internalMappings.putAll(tmpMap); } + public void exclude(String pattern) { + excludePatterns.add(pattern) + } + + public void excludes(Collection patterns) { + excludePatterns.addAll(patterns) + } + } diff --git a/src/main/groovy/nl/javadude/gradle/plugins/license/LicensePlugin.groovy b/src/main/groovy/nl/javadude/gradle/plugins/license/LicensePlugin.groovy index d6f1051..f02b244 100644 --- a/src/main/groovy/nl/javadude/gradle/plugins/license/LicensePlugin.groovy +++ b/src/main/groovy/nl/javadude/gradle/plugins/license/LicensePlugin.groovy @@ -133,11 +133,11 @@ class LicensePlugin implements Plugin { */ protected void configureTaskRule() { project.tasks.withType(License) { License task -> - logger.info("Applying license defaults to tasks"); + logger.info("Applying license defaults to task: ${task.path}"); configureTaskDefaults(task) } project.tasks.withType(DownloadLicenses) { DownloadLicenses task -> - logger.info("Applying defaults to DownloadLicenses"); + logger.info("Applying defaults to download task: ${task.path}"); configureTaskDefaults(task) } } @@ -178,6 +178,7 @@ class LicensePlugin implements Plugin { strictCheck = { extension.strictCheck } inheritedProperties = { extension.ext.properties } inheritedMappings = { extension.internalMappings } + excludes = { extension.excludePatterns } } } @@ -221,7 +222,6 @@ class LicensePlugin implements Plugin { // Default to all source files from SourceSet task.source = sourceSet.allSource - } } diff --git a/src/test/groovy/nl/javadude/gradle/plugins/license/LicenseIntegTest.groovy b/src/test/groovy/nl/javadude/gradle/plugins/license/LicenseIntegTest.groovy index 361f970..f3f4b68 100644 --- a/src/test/groovy/nl/javadude/gradle/plugins/license/LicenseIntegTest.groovy +++ b/src/test/groovy/nl/javadude/gradle/plugins/license/LicenseIntegTest.groovy @@ -117,6 +117,22 @@ class LicenseIntegTest { licenseTask.execute() } + @Test + public void shouldNotFailOnExcludedFileWithMissingHeader_1() { + project.license.ignoreFailures = false + project.license.excludes(["**/*.properties"]) + createPropertiesFile() + licenseTask.execute() + } + + @Test + public void shouldNotFailOnExcludedFileWithMissingHeader_2() { + project.license.ignoreFailures = false + project.license.exclude "**/*.properties" + createPropertiesFile() + licenseTask.execute() + } + @Test public void canAddHeader() { File propFile = createPropertiesFile()