Skip to content

Commit

Permalink
feat: Added a test to specify licenseSet includes from CLI
Browse files Browse the repository at this point in the history
This one fails
  • Loading branch information
mathieu committed Jan 8, 2025
1 parent fceb1b2 commit c110f26
Show file tree
Hide file tree
Showing 15 changed files with 163 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .config/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
<suppress files="[/\\]src[/\\]main[/\\]resources" checks=".*"/>
<suppress files="[/\\]src[/\\]test[/\\]resources" checks=".*"/>

</suppressions>
</suppressions>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<licensePluginReport goal="CHECK" timestamp="1727255571509">
<licensePluginReport goal="CHECK" timestamp="1736345660464">
<module artifactId="license-maven-plugin" groupId="com.mycila" version="5.0.0-SNAPSHOT"/>
<files>
<file path="pom.xml" result="PRESENT"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=license:format -Dlicense.licenseSets.licenseSet.includes=src/main/java/com/mycila/it/Unformatted2.java
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This is the 3rd
mock license
59 changes: 59 additions & 0 deletions license-maven-plugin/src/it/tri-license-set-with-includes/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<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>tri-license-set</artifactId>
<version>1.0.0</version>

<name>Check a Triple License Set</name>
<description>Integration Test for checking a triple license set</description>

<build>
<plugins>
<plugin>
<groupId>com.mycila</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<licenseSets>
<licenseSet>
<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>
<exclude>**/Unformatted3.java</exclude>
</excludes>
</licenseSet>
<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>
<exclude>**/Unformatted3.java</exclude>
</excludes>
</licenseSet>
<licenseSet>
<header>mock-license-3.txt</header>
<includes>
<include>**/Unformatted3.java</include>
</includes>
</licenseSet>
</licenseSets>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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 List<String> ALL_FILES = Arrays.asList("Unformatted1.java", "Unformatted2.java", "Unformatted3.java")

for (final String filename : ALL_FILES) {
final Path unformattedJavaFile = base.resolve("src/main/java/com/mycila/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,4 @@
package com.mycila.it;

public class Unformatted3 {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import java.nio.file.Files
import java.nio.file.Path

import static org.junit.jupiter.api.Assertions.assertEquals


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 <= 3; 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/mycila/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/mycila/it/" + filename)
if (!Files.exists(formattedJavaFile)) {
System.err.println(formattedJavaFile.getFileName() + " file is missing.")
return false
}

final StringBuilder expected = new StringBuilder();
if (i == 2) {
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
Expand Up @@ -84,7 +84,7 @@ public abstract class AbstractLicenseMojo extends AbstractMojo {

private static final String[] DEFAULT_KEYWORDS = {"copyright"};

@Parameter
@Parameter(property = "license.licenseSets", alias = "licenseSets")
public LicenseSet[] licenseSets;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,8 @@ public class LicenseSet {
@Parameter(property = "license.useDefaultExcludes")
public Boolean useDefaultExcludes;

@Override
public String toString() {
return header;
}
}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ limitations under the License.
<exclude>.config/**</exclude>
<!-- TODO: Remove after 4.4 release -->
<exclude>**/*.checkstyle</exclude>
<exclude>.vscode/**</exclude>
</excludes>
</licenseSet>
</licenseSets>
Expand Down

0 comments on commit c110f26

Please sign in to comment.