Skip to content

Commit

Permalink
Added excludes to extension (Fixes #39)
Browse files Browse the repository at this point in the history
  • Loading branch information
hierynomus committed Jul 15, 2014
1 parent 9367454 commit c0472e3
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 8 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<String,String> 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<String> 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 <a href="http://code.google.com/p/maven-license-plugin/wiki/SupportedFormats">SupportedFormats</a> page of the parent project.
Expand Down Expand Up @@ -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:

Expand Down Expand Up @@ -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)
-
-
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class License extends SourceTask implements VerificationTask {
boolean useDefaultMappings

boolean strictCheck

@InputFile
File header

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import org.gradle.api.tasks.SourceSet

/**
* Extension in the license namespace, which drives the License tasks.
*
*
* @author jryan
*/
class LicenseExtension {
Expand All @@ -35,14 +35,19 @@ class LicenseExtension {
*/
Collection<SourceSet> 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<String> excludePatterns = new HashSet<String>()

/**
* Whether or not to allow the build to continue if there are warnings.
*/
boolean ignoreFailures

/**
* Whether to create new files which have changes or to make them inline
*
*
*/
boolean dryRun;

Expand All @@ -55,7 +60,7 @@ class LicenseExtension {
* @link {AbstractLicenseMojo.useDefaultMappings}
*/
boolean useDefaultMappings

boolean strictCheck

Map<String, String> internalMappings = new HashMap<String, String>();
Expand All @@ -75,4 +80,12 @@ class LicenseExtension {
internalMappings.putAll(tmpMap);
}

public void exclude(String pattern) {
excludePatterns.add(pattern)
}

public void excludes(Collection<String> patterns) {
excludePatterns.addAll(patterns)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ class LicensePlugin implements Plugin<Project> {
*/
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)
}
}
Expand Down Expand Up @@ -178,6 +178,7 @@ class LicensePlugin implements Plugin<Project> {
strictCheck = { extension.strictCheck }
inheritedProperties = { extension.ext.properties }
inheritedMappings = { extension.internalMappings }
excludes = { extension.excludePatterns }
}
}

Expand Down Expand Up @@ -221,7 +222,6 @@ class LicensePlugin implements Plugin<Project> {

// Default to all source files from SourceSet
task.source = sourceSet.allSource

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit c0472e3

Please sign in to comment.