Skip to content

Commit

Permalink
Merge pull request #170 from adamretter/feature/license-sets
Browse files Browse the repository at this point in the history
License Sets feature - allows one execution to check different licenses
  • Loading branch information
mathieucarbou authored Jun 9, 2020
2 parents e8031d7 + 390e702 commit 91b730a
Show file tree
Hide file tree
Showing 60 changed files with 1,336 additions and 342 deletions.
48 changes: 31 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,20 @@ __Plugin declaration__
<artifactId>license-maven-plugin</artifactId>
<version>X.Y.ga</version>
<configuration>
<header>com/mycila/maven/plugin/license/templates/APACHE-2.txt</header>
<licenseSets>
<licenseSet>
<header>com/mycila/maven/plugin/license/templates/APACHE-2.txt</header>
<excludes>
<exclude>**/README</exclude>
<exclude>src/test/resources/**</exclude>
<exclude>src/main/resources/**</exclude>
</excludes>
</licenseSet>
</licenseSets>
<properties>
<owner>Mycila</owner>
<email>mathieu.carbou@gmail.com</email>
</properties>
<excludes>
<exclude>**/README</exclude>
<exclude>src/test/resources/**</exclude>
<exclude>src/main/resources/**</exclude>
</excludes>
</configuration>
<executions>
<execution>
Expand Down Expand Up @@ -118,21 +122,25 @@ options are concatenated together to produce a header template.
<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>
<licenseSets>
<licenseSet>
<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>
<excludes>
<exclude>**/README</exclude>
<exclude>src/test/resources/**</exclude>
<exclude>src/main/resources/**</exclude>
</excludes>
</licenseSet>
</licenseSets>
<properties>
<owner>Mycila</owner>
<email>mathieu.carbou@gmail.com</email>
</properties>
<excludes>
<exclude>**/README</exclude>
<exclude>src/test/resources/**</exclude>
<exclude>src/main/resources/**</exclude>
</excludes>
</configuration>
<executions>
<execution>
Expand All @@ -150,6 +158,12 @@ options are concatenated together to produce a header template.

The detailed Maven Plugin Documentation generated for each build is available here:

__NOTE__: Between versions 4.0 and 3.0 the configuration syntax has been changed. The
plugin now has the concept of *License Sets*, which allow you to work with one or
more license configurations in a single execution of the plugin. In simple terms, a `<licenseSet>`
wraps the previous configuration options for a license. The previous
configuration syntax is still supported but deprecated, and may be removed in future.

- [3.0](http://code.mycila.com/license-maven-plugin/reports/3.0/plugin-info.html)
- [3.0.rc1](http://code.mycila.com/license-maven-plugin/reports/3.0.rc1/plugin-info.html)
- [2.3](http://code.mycila.com/license-maven-plugin/reports/2.3/plugin-info.html)
Expand Down
27 changes: 27 additions & 0 deletions license-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<configuration>
<excludes>
<exclude>src/test/**</exclude>
<exclude>src/it/**</exclude>
<exclude>src/main/resources/**</exclude>
</excludes>
</configuration>
Expand All @@ -69,6 +70,32 @@
</sourceFileExcludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
<configuration>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<localRepositoryPath>${project.build.directory}/it-repo</localRepositoryPath>
<preBuildHookScript>setup</preBuildHookScript>
<postBuildHookScript>verify</postBuildHookScript>
</configuration>
<executions>
<execution>
<id>integration-tests</id>
<goals>
<goal>install</goal>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals = license:format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This is the 1st
mock license
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This is the 2nd
mock license
53 changes: 53 additions & 0 deletions license-maven-plugin/src/it/legacy-config-and-license-set/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.mycila.license-maven-plugin.it</groupId>
<artifactId>legacy-config-and-license-set</artifactId>
<version>1.0.0</version>

<name>Check Legacy Configuration mixed with LicenseSet Configuration</name>
<description>Integration Test for checking legacy configuration when used with license set configuration</description>

<build>
<plugins>
<plugin>
<groupId>com.mycila</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>@project.version@</version>
<configuration>

<!-- legacy config -->
<header>mock-license-1.txt</header>
<excludes>
<exclude>invoker.properties</exclude>
<exclude>pom.xml</exclude>
<exclude>*.groovy</exclude>
<exclude>**/*.bak</exclude>
<exclude>*.log</exclude>
<exclude>mock-license-*</exclude>
<exclude>**/Unformatted2.java</exclude>
</excludes>

<!-- license sets config -->
<licenseSets>
<licenseSet>
<header>mock-license-2.txt</header>
<excludes>
<exclude>invoker.properties</exclude>
<exclude>pom.xml</exclude>
<exclude>*.groovy</exclude>
<exclude>**/*.bak</exclude>
<exclude>*.log</exclude>
<exclude>mock-license-*</exclude>
<exclude>**/Unformatted1.java</exclude>
</excludes>
</licenseSet>
</licenseSets>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import java.nio.file.Files
import java.nio.file.Path
import java.util.Arrays
import java.util.List

final Path base = basedir.toPath()

if (!Files.exists(base) || !Files.isDirectory(base)) {
System.err.println("base directory is missing.")
return false
}

final List<String> ALL_FILES = Arrays.asList("Unformatted1.java", "Unformatted2.java")

for (final String filename : ALL_FILES) {
final Path unformattedJavaFile = base.resolve("src/main/java/com/mycilla/it/" + filename)
if (!Files.exists(unformattedJavaFile)) {
System.err.println(filename + " file is missing.")
return false
}

Files.copy(unformattedJavaFile, unformattedJavaFile.resolveSibling(filename + ".bak"))
}

return true;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.mycila.it;

public class Unformatted1 {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.mycila.it;

public class Unformatted2 {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import java.nio.file.Files
import java.nio.file.Path
import java.util.Arrays
import java.util.List

import static org.junit.Assert.*


final Path base = basedir.toPath()

if (!Files.exists(base) || !Files.isDirectory(base)) {
System.err.println("base directory is missing.")
return false
}

for (int i = 1; i <= 2; i++) {

final Path license = base.resolve("mock-license-" + i + ".txt")
if (!Files.exists(license)) {
System.err.println(license.getFileName() + " file is missing.")
return false
}

final String filename = "Unformatted" + i + ".java"

final Path unformattedJavaFile = base.resolve("src/main/java/com/mycilla/it/" + filename + ".bak")
if (!Files.exists(unformattedJavaFile)) {
System.err.println(unformattedJavaFile.getFileName() + " file is missing (should have been created by setup.groovy).")
return false
}

final Path formattedJavaFile = base.resolve("src/main/java/com/mycilla/it/" + filename)
if (!Files.exists(formattedJavaFile)) {
System.err.println(formattedJavaFile.getFileName() + " file is missing.")
return false
}

final StringBuilder expected = new StringBuilder();
expected.append("/*\n");
license.withReader { reader ->
while ((line = reader.readLine()) != null) {
expected.append(" * ").append(line).append('\n')
}
}
expected.append(" */\n")
expected.append(new String(Files.readAllBytes(unformattedJavaFile)))

final String actual = new String(Files.readAllBytes(formattedJavaFile))

assertEquals(expected.toString(), actual)
}

return true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals = license:format
2 changes: 2 additions & 0 deletions license-maven-plugin/src/it/legacy-config/mock-license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This is a
mock license
33 changes: 33 additions & 0 deletions license-maven-plugin/src/it/legacy-config/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.mycila.license-maven-plugin.it</groupId>
<artifactId>legacy-config</artifactId>
<version>1.0.0</version>

<name>Check Legacy Configuration</name>
<description>Integration Test for checking legacy configuration</description>

<build>
<plugins>
<plugin>
<groupId>com.mycila</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<header>mock-license.txt</header>
<excludes>
<exclude>invoker.properties</exclude>
<exclude>pom.xml</exclude>
<exclude>*.groovy</exclude>
<exclude>**/*.bak</exclude>
<exclude>*.log</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>

</project>
19 changes: 19 additions & 0 deletions license-maven-plugin/src/it/legacy-config/setup.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import java.nio.file.Files
import java.nio.file.Path

final Path base = basedir.toPath()

if (!Files.exists(base) || !Files.isDirectory(base)) {
System.err.println("base directory is missing.")
return false
}

final Path unformattedJavaFile = base.resolve("src/main/java/com/mycilla/it/Unformatted1.java")
if (!Files.exists(unformattedJavaFile)) {
System.err.println("Unformatted1.java file is missing.")
return false
}

Files.copy(unformattedJavaFile, unformattedJavaFile.resolveSibling("Unformatted1.java.bak"))

return true;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.mycila.it;

public class Unformatted1 {
}
46 changes: 46 additions & 0 deletions license-maven-plugin/src/it/legacy-config/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import java.nio.file.Files
import java.nio.file.Path

import static org.junit.Assert.*


final Path base = basedir.toPath()

if (!Files.exists(base) || !Files.isDirectory(base)) {
System.err.println("base directory is missing.")
return false
}

final Path license = base.resolve("mock-license.txt")
if (!Files.exists(license)) {
System.err.println("license file is missing.")
return false
}

final Path unformattedJavaFile = base.resolve("src/main/java/com/mycilla/it/Unformatted1.java.bak")
if (!Files.exists(unformattedJavaFile)) {
System.err.println(unformattedJavaFile.getFileName() + " file is missing (should have been created by setup.groovy).")
return false
}

final Path formattedJavaFile = base.resolve("src/main/java/com/mycilla/it/Unformatted1.java")
if (!Files.exists(formattedJavaFile)) {
System.err.println(formattedJavaFile.getFileName() + " file is missing.")
return false
}

final StringBuilder expected = new StringBuilder();
expected.append("/*\n");
license.withReader { reader ->
while ((line = reader.readLine()) != null) {
expected.append(" * ").append(line).append('\n')
}
}
expected.append(" */\n")
expected.append(new String(Files.readAllBytes(unformattedJavaFile)))

final String actual = new String(Files.readAllBytes(formattedJavaFile))

assertEquals(expected.toString(), actual)

return true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals = license:format
2 changes: 2 additions & 0 deletions license-maven-plugin/src/it/multi-license/mock-license-1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This is the 1st
mock license
Loading

0 comments on commit 91b730a

Please sign in to comment.