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

Expose the keywords option #209

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ most of which can also be set on the extension to configure them for all tasks.
|dryRun |Show what would happen if the task was run, defaults to false but also inherits from `--dryRun`
|skipExistingHeaders |Skip over files that have some header already, which might not be the one specified in the header parameter, defaults to false
|useDefaultMappings |Use a long list of standard mapping, defaults to true. See http://code.mycila.com/license-maven-plugin/#supported-comment-types[] for the complete list
|keywords |Specify the list of keywords to use to detect a header. A header must include all keywords to be valid. By default, the word 'copyright' is used. Detection is case insensitive.
|strictCheck |Be extra strict in the formatting of existing headers, defaults to false
|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
Expand All @@ -137,6 +138,7 @@ most of which can also be set on the extension to configure them for all tasks.
|dryRun |Show what would happen if the task was run, defaults to false but also inherits from `--dryRun`
|skipExistingHeaders |Skip over files that have some header already, which might not be the one specified in the header parameter, defaults to false
|useDefaultMappings |Use a long list of standard mapping, defaults to true. See http://code.mycila.com/license-maven-plugin/#supported-comment-types[] for the complete list
|keywords |Specify the list of keywords to use to detect a header. A header must include all keywords to be valid. By default, the word 'copyright' is used. Detection is case insensitive.
|strictCheck |Be extra strict in the formatting of existing headers, defaults to false
|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
Expand Down Expand Up @@ -168,6 +170,7 @@ Here is a general overview of the options:
|dryRun |Show what would happen if the task was run, defaults to false but also inherits from `--dryRun`
|skipExistingHeaders |Skip over files that have some header already, which might not be the one specified in the header parameter, defaults to false
|useDefaultMappings |Use a long list of standard mapping, defaults to true. See http://code.mycila.com/license-maven-plugin/#supported-comment-types[] for the complete list
|keywords |Specify the list of keywords to use to detect a header. A header must include all keywords to be valid. By default, the word 'copyright' is used. Detection is case insensitive.
|strictCheck |Be extra strict in the formatting of existing headers, defaults to false
|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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class LicenseBasePlugin implements Plugin<Project> {
dryRun = false
skipExistingHeaders = false
useDefaultMappings = true
keywords = ['copyright']
strictCheck = false
encoding = System.properties['file.encoding']
sourceSets = project.container(SourceSet)
Expand Down Expand Up @@ -113,6 +114,7 @@ class LicenseBasePlugin implements Plugin<Project> {
dryRun = { extension.dryRun }
skipExistingHeaders = { extension.skipExistingHeaders }
useDefaultMappings = { extension.useDefaultMappings }
keywords = { extension.keywords }
strictCheck = { extension.strictCheck }
inheritedProperties = { extension.ext.properties }
inheritedMappings = { extension.internalMappings }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ class License extends SourceTask implements VerificationTask {
*/
@Input boolean useDefaultMappings

/**
* Specify the list of keywords to use to detect a header. A header must
* include all keywords to be valid. Detection is case insensitive.
*/
@Input Collection<String> keywords;

@Input boolean strictCheck

/**
Expand Down Expand Up @@ -135,7 +141,7 @@ class License extends SourceTask implements VerificationTask {

URI uri = resolveURI()

new AbstractLicenseMojo(validHeaders, getProject().rootDir, initial, isDryRun(), isSkipExistingHeaders(), isUseDefaultMappings(), isStrictCheck(), uri, source, combinedMappings, getEncoding(), buildHeaderDefinitions())
new AbstractLicenseMojo(validHeaders, getProject().rootDir, initial, isDryRun(), isSkipExistingHeaders(), isUseDefaultMappings(), isStrictCheck(), uri, source, combinedMappings, getEncoding(), buildHeaderDefinitions(), getKeywords())
.execute(callback)

altered = callback.getAffected()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ class LicenseExtension {
*/
boolean useDefaultMappings

/**
* Specify the list of keywords to use to detect a header. A header must
* include all keywords to be valid. Detection is case insensitive.
*/
Collection<String> keywords

boolean strictCheck

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class AbstractLicenseMojo {
File rootDir;
Map<String, String> initial;

protected String[] keywords = new String[] { "copyright" };
protected String[] keywords;
protected List<HeaderDefinition> headerDefinitions;
protected HeaderSection[] headerSections = new HeaderSection[0];
protected String encoding;
Expand All @@ -75,7 +75,8 @@ public class AbstractLicenseMojo {

public AbstractLicenseMojo(Collection<File> validHeaders, File rootDir, Map<String, String> initial,
boolean dryRun, boolean skipExistingHeaders, boolean useDefaultMappings, boolean strictCheck,
URI header, FileCollection source, Map<String, String> mapping, String encoding, List<HeaderDefinition> headerDefinitions) {
URI header, FileCollection source, Map<String, String> mapping, String encoding, List<HeaderDefinition> headerDefinitions,
Collection<String> keywords) {
this.validHeaders = validHeaders;
this.rootDir = rootDir;
this.initial = initial;
Expand All @@ -88,6 +89,7 @@ public AbstractLicenseMojo(Collection<File> validHeaders, File rootDir, Map<Stri
this.mapping = mapping;
this.encoding = encoding;
this.headerDefinitions = headerDefinitions;
this.keywords = keywords.toArray(new String[0]);
}

protected void execute(final Callback callback) throws MalformedURLException, IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ class LicensePluginTest {
assertThat project.license.strictCheck, is(false)
}

@Test
public void extensionKeywordsDefaults() {
assertThat project.license.keywords, is(['copyright'])
}

@Test
public void extensionShouldNotHaveSourceSets() {
assertThat project.license.sourceSets, is(notNullValue())
Expand Down