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

Plugin configuration to support multi-licensing scenarios #166

Merged
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
46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Available in OSS Repository: https://oss.sonatype.org/content/repositories/snap

__Plugin declaration__

```xml
<plugin>
<groupId>com.mycila</groupId>
<artifactId>license-maven-plugin</artifactId>
Expand All @@ -99,6 +100,49 @@ __Plugin declaration__
</execution>
</executions>
</plugin>
```

__Plugin declaration ([Multi-Licensing](https://en.wikipedia.org/wiki/Multi-licensing))__

If your source code makes use of multi-licensing, then instead of
a `<header>` or `<inlineHeader>` element in the configuration
you can use a `<multi>` element.

The `<multi>` element allows you to specify an optional preamble,
one or more header (or inlineHeader) and separators between them. These
options are concatenated together to produce a header template.

```xml
<plugin>
<groupId>com.mycila</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>X.Y.ga</version>
<configuration>
<multi>
<preamble><![CDATA[This product is dual-licensed under both the GPLv2 and Apache 2.0 License.]]></preamble>
<header>GPL-2.txt</header>
<separator>======================================================================</separator>
<header>com/mycila/maven/plugin/license/templates/APACHE-2.txt</header>
</multi>
<properties>
<owner>Mycila</owner>
<email>[email protected]</email>
</properties>
<excludes>
<exclude>**/README</exclude>
<exclude>src/test/resources/**</exclude>
<exclude>src/main/resources/**</exclude>
</excludes>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
```

## Documentation ##

Expand Down Expand Up @@ -150,7 +194,7 @@ You can find those license templates with preconfigured placeholders [here](http

Properties which can be used as placeholder comes from:

- Environnment variables
- Environment variables
- POM properties
- `project.groupId`
- `project.artifactId`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ public abstract class AbstractLicenseMojo extends AbstractMojo {
@Parameter
public String[] validHeaders = new String[0];

/**
* Alternative to `header`, `inlineHeader`, or `validHeaders`
* for use when code is multi-licensed.
* Whilst you could create a concatenated header yourself,
* a cleaner approach may be to specify more than one header
* and have them concatenated together by the plugin. This
* allows you to maintain each distinct license header in
* its own file and combined them in different ways.
*/
@Parameter
public Multi multi;

/**
* Allows the use of external header definitions files. These files are
* properties like files.
Expand Down Expand Up @@ -321,7 +333,7 @@ public void checkUnknown() throws MojoExecutionException {
@SuppressWarnings({"unchecked"})
public final void execute(final Callback callback) throws MojoExecutionException, MojoFailureException {
if (!skip) {
if (header == null && (this.inlineHeader == null || this.inlineHeader.isEmpty())) {
if (!hasHeader()) {
warn("No header file specified to check for license");
return;
}
Expand All @@ -338,7 +350,7 @@ public final void execute(final Callback callback) throws MojoExecutionException
}
finder.setPluginClassPath(getClass().getClassLoader());

final HeaderSource headerSource = HeaderSource.of(this.inlineHeader, this.header, this.encoding, this.finder);
final HeaderSource headerSource = HeaderSource.of(this.multi, this.inlineHeader, this.header, this.encoding, this.finder);
final Header h = new Header(headerSource, headerSections);
debug("Header: %s", h.getLocation());

Expand All @@ -347,7 +359,7 @@ public final void execute(final Callback callback) throws MojoExecutionException
}
final List<Header> validHeaders = new ArrayList<Header>(this.validHeaders.length);
for (String validHeader : this.validHeaders) {
final HeaderSource validHeaderSource = HeaderSource.of(null, validHeader, this.encoding, this.finder);
final HeaderSource validHeaderSource = HeaderSource.of(null, null, validHeader, this.encoding, this.finder);
validHeaders.add(new Header(validHeaderSource, headerSections));
}

Expand Down Expand Up @@ -455,6 +467,14 @@ public void run() {
}
}

private boolean hasHeader() {
return
(multi != null
&& ((multi.headers != null && multi.headers.length > 0)
|| (multi.inlineHeaders != null && multi.inlineHeaders.length > 0 && !multi.inlineHeaders[0].isEmpty()))
) || (header != null || (inlineHeader != null && !this.inlineHeader.isEmpty()));
}

private int getNumberOfExecutorThreads() {
return nThreads > 0 ?
nThreads :
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright (C) 2008 Mycila ([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.mycila.maven.plugin.license;

import org.apache.maven.plugins.annotations.Parameter;

public class Multi {

public static final String DEFAULT_SEPARATOR =
"---------------------------------------------------------------------";

/**
* Preamble text which if present is placed before the first header.
*/
@Parameter
String preamble;

/**
* Location of each header. It can be a relative path, absolute path,
* classpath resource, any URL. The plugin first check if the name specified
* is a relative file, then an absolute file, then in the classpath. If not
* found, it tries to construct a URL from the location.
*/
@Parameter(alias = "header")
String[] headers;

/**
* Header, as text, directly in pom file. Using a CDATA section is strongly recommended.
*/
@Parameter(alias = "inlineHeader")
String[] inlineHeaders;

/**
* One of more separators between the headers.
* If there is only one separator it is placed between each header.
* If there are multiple separators, then the first separator is placed
* between the first and second license, the second separator is placed
* between the second and third license, and so on...
*/
@Parameter(alias = "separator")
String[] separators;

public String getPreamble() {
return preamble;
}

public void setPreamble(final String preamble) {
this.preamble = preamble;
}

public String[] getHeaders() {
return headers;
}

public void setHeaders(final String[] headers) {
this.headers = headers;
}

public String[] getInlineHeaders() {
return inlineHeaders;
}

public void setInlineHeaders(final String[] inlineHeaders) {
this.inlineHeaders = inlineHeaders;
}

public String[] getSeparators() {
return separators;
}

public void setSeparators(final String[] separators) {
this.separators = separators;
}
}
Loading