Skip to content

Commit

Permalink
Re-enable checkstyle plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Sep 15, 2024
1 parent d3080a5 commit 1ad2298
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 82 deletions.
2 changes: 0 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<!-- TODO enable with spotless -->
<skip>true</skip>
<headerLocation>config/checkstyle-header.txt</headerLocation>
<!-- these are generated -->
<excludes>**/HelpMojo.java,**/SpdxLicenseListData.java</excludes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ private static Color convertToOdfColor(final int[] color) {
return new Color(color[0], color[1], color[2]);
}

@SuppressWarnings("checkstyle:MethodLength")
private static void createHeader(
List<ProjectLicenseInfo> projectLicenseInfos, OdfSpreadsheetDocument spreadsheet, OdfTable table) {
boolean hasExtendedInfo = false;
Expand Down Expand Up @@ -474,6 +475,7 @@ private static void createHeaderStyle(OdfSpreadsheetDocument spreadsheet) {
Reduce parameters, complicated parameters/DTO pattern.
But keep it still threadsafe.
*/
@SuppressWarnings("checkstyle:MethodLength")
private static void writeData(
List<ProjectLicenseInfo> projectLicenseInfos,
OdfSpreadsheetDocument wb,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public static void write(List<ProjectLicenseInfo> projectLicenseInfos, final Fil
}
}

@SuppressWarnings("checkstyle:MethodLength")
private static void createHeader(List<ProjectLicenseInfo> projectLicenseInfos, Workbook wb, Sheet sheet) {
boolean hasExtendedInfo = false;
for (ProjectLicenseInfo projectLicenseInfo : projectLicenseInfos) {
Expand Down Expand Up @@ -354,6 +355,7 @@ private static void createHeader(List<ProjectLicenseInfo> projectLicenseInfos, W
Clean this method up.
Reduce parameters, complicated parameters/DTO pattern.
But keep it still threadsafe. */
@SuppressWarnings("checkstyle:MethodLength")
private static void writeData(
List<ProjectLicenseInfo> projectLicenseInfos,
XSSFWorkbook wb,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

import org.junit.Test;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

public class LicenseMojoUtilsTest {
private String resolvedUrl;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/codehaus/mojo/license/MockLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public class MockLogger implements LoggerFacade {
private static final Pattern PLACEHOLDER_PATTERN = Pattern.compile("\\Q{}\\E");

private static final String format(String template, Object param) {
private static String format(String template, Object param) {
return PLACEHOLDER_PATTERN.matcher(template).replaceFirst(Matcher.quoteReplacement(String.valueOf(param)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,55 +115,49 @@ public void testWriteReadLicenseSummary()
licSummary.add(dep3);
licSummary.add(dep4);

{
File licenseSummaryFile = File.createTempFile("licSummary", "tmp");
LicenseSummaryWriter.writeLicenseSummary(
licSummary, licenseSummaryFile, StandardCharsets.UTF_8, Eol.LF, true);

assertTrue(licenseSummaryFile.exists());
FileInputStream fis = new FileInputStream(licenseSummaryFile);
List<ProjectLicenseInfo> list = LicenseSummaryReader.parseLicenseSummary(fis);
fis.close();
ProjectLicenseInfo dep = list.get(0);
Assert.assertEquals("org.test", dep.getGroupId());
Assert.assertEquals("test1", dep.getArtifactId());
Assert.assertEquals("1.0", dep.getVersion());

List<ProjectLicense> licenses = dep.getLicenses();
Assert.assertEquals(1, licenses.size());
ProjectLicense lic0 = dep.getLicenses().get(0);
Assert.assertEquals("lgpl", lic0.getName());
Assert.assertEquals("http://www.gnu.org/licenses/lgpl-3.0.txt", lic0.getUrl());
Assert.assertEquals("lgpl-3.0.txt", lic0.getFile());
Assert.assertEquals("lgpl version 3.0", lic0.getComments());

validateXml(licenseSummaryFile);
}
File licenseSummaryFile = File.createTempFile("licSummary", "tmp");
LicenseSummaryWriter.writeLicenseSummary(licSummary, licenseSummaryFile, StandardCharsets.UTF_8, Eol.LF, true);

{
File licenseSummaryFile = File.createTempFile("licSummaryNoVersionNoXsd", "tmp");
LicenseSummaryWriter.writeLicenseSummary(
licSummary, licenseSummaryFile, StandardCharsets.UTF_8, Eol.LF, false);

assertTrue(licenseSummaryFile.exists());
FileInputStream fis = new FileInputStream(licenseSummaryFile);
List<ProjectLicenseInfo> list = LicenseSummaryReader.parseLicenseSummary(fis);
fis.close();
ProjectLicenseInfo dep = list.get(0);
Assert.assertEquals("org.test", dep.getGroupId());
Assert.assertEquals("test1", dep.getArtifactId());
Assert.assertNull(dep.getVersion());

List<ProjectLicense> licenses = dep.getLicenses();
Assert.assertEquals(1, licenses.size());
ProjectLicense lic0 = dep.getLicenses().get(0);
Assert.assertEquals("lgpl", lic0.getName());
Assert.assertEquals("http://www.gnu.org/licenses/lgpl-3.0.txt", lic0.getUrl());
Assert.assertEquals("lgpl-3.0.txt", lic0.getFile());
Assert.assertEquals("lgpl version 3.0", lic0.getComments());

validateXml(licenseSummaryFile);
}
assertTrue(licenseSummaryFile.exists());
FileInputStream fis = new FileInputStream(licenseSummaryFile);
List<ProjectLicenseInfo> list = LicenseSummaryReader.parseLicenseSummary(fis);
fis.close();
ProjectLicenseInfo dep = list.get(0);
Assert.assertEquals("org.test", dep.getGroupId());
Assert.assertEquals("test1", dep.getArtifactId());
Assert.assertEquals("1.0", dep.getVersion());

List<ProjectLicense> licenses = dep.getLicenses();
Assert.assertEquals(1, licenses.size());
ProjectLicense lic0 = dep.getLicenses().get(0);
Assert.assertEquals("lgpl", lic0.getName());
Assert.assertEquals("http://www.gnu.org/licenses/lgpl-3.0.txt", lic0.getUrl());
Assert.assertEquals("lgpl-3.0.txt", lic0.getFile());
Assert.assertEquals("lgpl version 3.0", lic0.getComments());

validateXml(licenseSummaryFile);

licenseSummaryFile = File.createTempFile("licSummaryNoVersionNoXsd", "tmp");
LicenseSummaryWriter.writeLicenseSummary(licSummary, licenseSummaryFile, StandardCharsets.UTF_8, Eol.LF, false);

assertTrue(licenseSummaryFile.exists());
fis = new FileInputStream(licenseSummaryFile);
list = LicenseSummaryReader.parseLicenseSummary(fis);
fis.close();
dep = list.get(0);
Assert.assertEquals("org.test", dep.getGroupId());
Assert.assertEquals("test1", dep.getArtifactId());
Assert.assertNull(dep.getVersion());

licenses = dep.getLicenses();
Assert.assertEquals(1, licenses.size());
lic0 = dep.getLicenses().get(0);
Assert.assertEquals("lgpl", lic0.getName());
Assert.assertEquals("http://www.gnu.org/licenses/lgpl-3.0.txt", lic0.getUrl());
Assert.assertEquals("lgpl-3.0.txt", lic0.getFile());
Assert.assertEquals("lgpl version 3.0", lic0.getComments());

validateXml(licenseSummaryFile);

Path licensesExcelOutputFile = Files.createTempFile("licExcel", ".xlsx");
ExcelFileWriter.write(licSummary, licensesExcelOutputFile.toFile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
import org.junit.Test;

import static org.codehaus.mojo.license.header.transformer.AbstractFileHeaderTransformer.COPYRIGHT_PATTERN;
import static org.codehaus.mojo.license.header.transformer.FileHeaderTransformer.*;
import static org.codehaus.mojo.license.header.transformer.FileHeaderTransformer.DEFAULT_PROCESS_END_TAG;
import static org.codehaus.mojo.license.header.transformer.FileHeaderTransformer.DEFAULT_PROCESS_START_TAG;
import static org.codehaus.mojo.license.header.transformer.FileHeaderTransformer.DEFAULT_SECTION_DELIMITER;
import static org.codehaus.mojo.license.header.transformer.FileHeaderTransformer.LINE_SEPARATOR;

/**
* Tests the {@link AbstractFileHeaderTransformer}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,25 @@ public void mimeTypes() {

@Test
public void extraAliases() {
final Map<String, SpdxLicenseInfo> lics = SpdxLicenseList.getLatest().getLicenses();
{
final Map<String, UrlInfo> urlInfos =
lics.get("Apache-2.0").getAttachments().getUrlInfos();
Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/apache2.0"));
Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/apache2.0.php"));
Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/apache2.0.html"));
}
{
final Map<String, UrlInfo> urlInfos =
lics.get("BSD-2-Clause").getAttachments().getUrlInfos();
Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/bsd-license"));
Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/bsd-license.php"));
Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/bsd-license.html"));
}
{
final Map<String, UrlInfo> urlInfos =
lics.get("CDDL-1.0").getAttachments().getUrlInfos();
Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/cddl1"));
Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/cddl1.php"));
Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/cddl1.html"));
}
{
final Map<String, UrlInfo> urlInfos =
lics.get("MIT").getAttachments().getUrlInfos();
Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/mit-license"));
Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/mit-license.php"));
Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/mit-license.html"));
}
Map<String, SpdxLicenseInfo> lics = SpdxLicenseList.getLatest().getLicenses();
Map<String, UrlInfo> urlInfos = lics.get("Apache-2.0").getAttachments().getUrlInfos();
Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/apache2.0"));
Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/apache2.0.php"));
Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/apache2.0.html"));

urlInfos = lics.get("BSD-2-Clause").getAttachments().getUrlInfos();
Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/bsd-license"));
Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/bsd-license.php"));
Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/bsd-license.html"));

urlInfos = lics.get("CDDL-1.0").getAttachments().getUrlInfos();
Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/cddl1"));
Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/cddl1.php"));
Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/cddl1.html"));

urlInfos = lics.get("MIT").getAttachments().getUrlInfos();
Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/mit-license"));
Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/mit-license.php"));
Assert.assertTrue(urlInfos.containsKey("https://opensource.org/licenses/mit-license.html"));
}
}

0 comments on commit 1ad2298

Please sign in to comment.