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 53e2b8e
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=license:format -Dlicense.licenseSets.licenseSet=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

0 comments on commit 53e2b8e

Please sign in to comment.