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

Support license-maven-plugin-git #212

Open
wants to merge 2 commits 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
7 changes: 3 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ dependencies {
implementation "org.codehaus.plexus:plexus-utils:2.0.5"
implementation "com.mycila.xmltool:xmltool:3.3"
// Using implementation instead of groovy, so that it goes into the pom
implementation ('com.mycila:license-maven-plugin:3.0') {
exclude group: 'org.apache.maven', module: 'maven-plugin-api'
exclude group: 'org.apache.maven', module: 'maven-project'
}
implementation "com.mycila:license-maven-plugin:4.2.rc3"
implementation "com.mycila:license-maven-plugin-git:4.2.rc3"
implementation gradleApi()

def androidGradlePlugin = 'com.android.tools.build:gradle:4.1.0'
Expand Down Expand Up @@ -130,6 +128,7 @@ task javadocJar(type: Jar, dependsOn: javadoc) {

license {
ignoreFailures true
inceptionYear 2011
}

tasks.withType(Test).all { t ->
Expand Down
6 changes: 2 additions & 4 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ configurations.api.transitive = false
dependencies {
implementation "org.codehaus.plexus:plexus-utils:2.0.5"
implementation "com.mycila.xmltool:xmltool:3.3"
implementation ('com.mycila:license-maven-plugin:3.0') {
exclude group: 'org.apache.maven', module: 'maven-plugin-api'
exclude group: 'org.apache.maven', module: 'maven-project'
}
implementation "com.mycila:license-maven-plugin:4.2.rc3"
implementation "com.mycila:license-maven-plugin-git:4.2.rc3"
implementation gradleApi()

compileOnly 'com.android.tools.build:gradle:2.0.+'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class LicenseIntegrationTest extends IntegrationSpec {

license {
ignoreFailures = true
inceptionYear = 2011
Copy link
Author

Choose a reason for hiding this comment

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

inceptionYear is needed while using license-maven-plugin-git

}
"""
license = createLicenseFile()
Expand Down Expand Up @@ -248,7 +249,7 @@ key2 = value2
ExecutionResult r = runTasksSuccessfully("licenseFormatMain")

then:
javaFile.text == '''/**
javaFile.text == '''/*
Copy link
Author

Choose a reason for hiding this comment

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

seems the format has changed

* This is a sample license created in ${year}
*/
public class Test {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright (C)2011 - Jeroen van Erp <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hierynomus.gradle.license

import groovy.xml.XmlSlurper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class LicenseBasePlugin implements Plugin<Project> {
includes = { extension.includePatterns }
encoding = { extension.encoding }
headerDefinitions = { extension.headerDefinitions }
inceptionYear = { extension.inceptionYear }
}
}

Expand Down
37 changes: 24 additions & 13 deletions src/main/groovy/nl/javadude/gradle/plugins/license/License.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -40,36 +40,43 @@ class License extends SourceTask implements VerificationTask {
/**
* Whether or not to allow the build to continue if there are warnings.
*/
@Input boolean ignoreFailures
@Input
boolean ignoreFailures

/**
* Check determines if we doing mutation on the files or just looking
*/
@Input boolean check
@Input
boolean check

/**
* Whether to create new files which have changes or to make them inline
*/
@Input boolean dryRun = false
@Input
boolean dryRun = false

/**
* Whether to skip file where a header has been detected
*/
@Input boolean skipExistingHeaders = false
@Input
boolean skipExistingHeaders = false

// TODO useDefaultExcludes, not necessary because we're using source sets

/**
* @link {AbstractLicenseMojo.useDefaultMappings}
*/
@Input boolean useDefaultMappings
@Input
boolean useDefaultMappings

@Input boolean strictCheck
@Input
boolean strictCheck

/**
* The encoding used to open files
*/
@Input String encoding
@Input
String encoding

@Optional
@InputFile
Expand Down Expand Up @@ -97,13 +104,17 @@ class License extends SourceTask implements VerificationTask {
Map<String, String> inheritedProperties

@Optional
@Input Map<String, String> inheritedMappings
@Input
Map<String, String> inheritedMappings

// Container for all custom header definitions
@Optional
@Nested
NamedDomainObjectContainer<HeaderDefinitionBuilder> headerDefinitions

@Input
int inceptionYear;

@Inject
@Deprecated
License() {
Expand Down Expand Up @@ -135,8 +146,8 @@ class License extends SourceTask implements VerificationTask {

URI uri = resolveURI()

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

altered = callback.getAffected()
didWork = !altered.isEmpty()
Expand All @@ -161,15 +172,15 @@ class License extends SourceTask implements VerificationTask {
// Use properties on this task over the ones from the extension
private Map combineVariables() {
Map<String, String> initial = new HashMap<String, String>()
if (getInheritedProperties() != null ) { // Convention will pull these from the extension
if (getInheritedProperties() != null) { // Convention will pull these from the extension
initial.putAll(getInheritedProperties())
}
initial.putAll(ext.properties)
return initial
}

// Setup mappings
Map<String,String> combinedMappings() {
Map<String, String> combinedMappings() {
Map<String, String> combinedMappings = new HashMap<String, String>()
if (isUseDefaultMappings()) {
// Sprinkle in some other well known types, which maven-license-plugin doesn't have
Expand Down Expand Up @@ -212,7 +223,7 @@ class License extends SourceTask implements VerificationTask {
}

void mapping(Closure closure) {
Map<String,String> tmpMap = new HashMap<String,String>()
Map<String, String> tmpMap = new HashMap<String, String>()
closure.delegate = tmpMap
closure.resolveStrategy = Closure.DELEGATE_FIRST
closure()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class LicenseExtension {

boolean strictCheck

int inceptionYear

/**
* Additional header definitions
*/
Expand Down
Loading