From 4cfafc94cc22d90c9065ce85f3d7b166da00b268 Mon Sep 17 00:00:00 2001 From: Jeremy Landis Date: Thu, 24 Mar 2022 13:04:53 -0400 Subject: [PATCH 1/6] [java] Use protected instead of public where noted by sonarlint --- .../license/dependencies/AbstractLicensePolicyEnforcer.java | 2 +- .../com/mycila/maven/plugin/license/header/HeaderSource.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/dependencies/AbstractLicensePolicyEnforcer.java b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/dependencies/AbstractLicensePolicyEnforcer.java index d4d9f2c18..5a3585f40 100644 --- a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/dependencies/AbstractLicensePolicyEnforcer.java +++ b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/dependencies/AbstractLicensePolicyEnforcer.java @@ -24,7 +24,7 @@ public abstract class AbstractLicensePolicyEnforcer implements LicensePolicyEnforcer { private final LicensePolicy policy; - public AbstractLicensePolicyEnforcer(final LicensePolicy policy) { + protected AbstractLicensePolicyEnforcer(final LicensePolicy policy) { this.policy = policy; } diff --git a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/header/HeaderSource.java b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/header/HeaderSource.java index ec62dd7e2..ee4baff15 100644 --- a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/header/HeaderSource.java +++ b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/header/HeaderSource.java @@ -243,7 +243,7 @@ public static HeaderSource of(Multi multi, String inlineHeader, String headerPat protected final String content; private final boolean inline; - public HeaderSource(String content, boolean inline) { + protected HeaderSource(String content, boolean inline) { super(); this.content = content; this.inline = inline; From 3be1ce5a60c3cc2fb31be26d5cb2c54c32abdfa6 Mon Sep 17 00:00:00 2001 From: Jeremy Landis Date: Thu, 24 Mar 2022 13:05:50 -0400 Subject: [PATCH 2/6] [java] Fix misplaced 'if' is this really intended to be an 'if' or was it to be an 'else'? Its confusing how its coded and flagged by sonarlint. Moved it to keep current behaviour but question lingers. --- .../com/mycila/maven/plugin/license/header/HeaderParser.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/header/HeaderParser.java b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/header/HeaderParser.java index a7bd6efe5..b469e9a91 100755 --- a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/header/HeaderParser.java +++ b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/header/HeaderParser.java @@ -238,7 +238,8 @@ private int findEndPosition() { end = fileContent.getPosition(); line = fileContent.nextLine(); } - } if (headerDefinition.getEndLine().endsWith("EOL") && line != null && "".equals(line.trim())) { + } + if (headerDefinition.getEndLine().endsWith("EOL") && line != null && "".equals(line.trim())) { end = fileContent.getPosition(); } return end; From e3018c1c8cc1ada0c0f6e8d6c8275dce8c6ba1ca Mon Sep 17 00:00:00 2001 From: Jeremy Landis Date: Thu, 24 Mar 2022 13:06:35 -0400 Subject: [PATCH 3/6] [java] Remove unnecessary cast for same object --- .../com/mycila/maven/plugin/license/AbstractLicenseMojo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/AbstractLicenseMojo.java b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/AbstractLicenseMojo.java index 562b77be9..020a92165 100755 --- a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/AbstractLicenseMojo.java +++ b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/AbstractLicenseMojo.java @@ -756,7 +756,7 @@ private String[] buildExcludes(final LicenseSet licenseSet) { List ex = new ArrayList<>(); ex.addAll(asList(licenseSet.excludes)); if (project != null && project.getModules() != null && !aggregate) { - for (String module : (List) project.getModules()) { + for (String module : project.getModules()) { ex.add(module + "/**"); } } From b4ea3d08ae1aa206c017488a144b414d9ec753f0 Mon Sep 17 00:00:00 2001 From: Jeremy Landis Date: Thu, 24 Mar 2022 13:06:48 -0400 Subject: [PATCH 4/6] [java] Add private constructor as class is final --- .../main/java/com/mycila/maven/plugin/license/Default.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/Default.java b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/Default.java index ff59c041c..bfd40ffb3 100755 --- a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/Default.java +++ b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/Default.java @@ -21,6 +21,10 @@ */ public final class Default { + private Default() { + // Prevent Instantiation + } + public static final String[] INCLUDE = new String[]{"**"}; public static final String[] EXCLUDES = { From 170c65f29fa34f692a0ba5a727f48627ebacedbc Mon Sep 17 00:00:00 2001 From: Jeremy Landis Date: Thu, 24 Mar 2022 13:07:10 -0400 Subject: [PATCH 5/6] [maven] Remove dead code on maven session getter/setter were not used. --- .../license/dependencies/MavenProjectLicenses.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/dependencies/MavenProjectLicenses.java b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/dependencies/MavenProjectLicenses.java index 628c807e4..c05ee9f85 100755 --- a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/dependencies/MavenProjectLicenses.java +++ b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/dependencies/MavenProjectLicenses.java @@ -50,7 +50,6 @@ public class MavenProjectLicenses implements LicenseMap, LicenseMessage { private Set projects; - private MavenSession session; private DependencyGraphBuilder graph; private ProjectBuilder projectBuilder; private ProjectBuildingRequest buildingRequest; @@ -177,14 +176,6 @@ private Set getDependencies() { // return project.getArtifacts(); } - private MavenSession getSession() { - return session; - } - - private void setSession(MavenSession session) { - this.session = session; - } - protected Set getProjects() { return projects; } From b12fb93ac0736290aa9bd2dcdaee9cc3eb835319 Mon Sep 17 00:00:00 2001 From: Jeremy Landis Date: Thu, 24 Mar 2022 13:34:54 -0400 Subject: [PATCH 6/6] [java] Remove unthrown or duplicate exceptions --- .../com/mycila/maven/plugin/license/git/GitLookup.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/license-maven-plugin-git/src/main/java/com/mycila/maven/plugin/license/git/GitLookup.java b/license-maven-plugin-git/src/main/java/com/mycila/maven/plugin/license/git/GitLookup.java index 0e5c965ca..a65e68dcc 100644 --- a/license-maven-plugin-git/src/main/java/com/mycila/maven/plugin/license/git/GitLookup.java +++ b/license-maven-plugin-git/src/main/java/com/mycila/maven/plugin/license/git/GitLookup.java @@ -18,7 +18,6 @@ import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Status; import org.eclipse.jgit.api.errors.GitAPIException; -import org.eclipse.jgit.api.errors.NoHeadException; import org.eclipse.jgit.diff.DiffConfig; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.PersonIdent; @@ -108,11 +107,10 @@ public GitLookup(File anyFile, DateSource dateSource, TimeZone timeZone, int che * * @param file for which the year should be retrieved * @return year of last modification of the file - * @throws NoHeadException if unable to retrieve the head of the git history * @throws IOException if unable to read the file * @throws GitAPIException if unable to process the git history */ - int getYearOfLastChange(File file) throws NoHeadException, GitAPIException, IOException { + int getYearOfLastChange(File file) throws GitAPIException, IOException { String repoRelativePath = pathResolver.relativize(file); if (isFileModifiedOrUnstaged(repoRelativePath)) { @@ -161,7 +159,7 @@ int getYearOfCreation(File file) throws IOException, GitAPIException { return commitYear; } - String getAuthorNameOfCreation(File file) throws IOException, GitAPIException { + String getAuthorNameOfCreation(File file) throws IOException { String repoRelativePath = pathResolver.relativize(file); String authorName = ""; RevWalk walk = getGitRevWalk(repoRelativePath, true); @@ -174,7 +172,7 @@ String getAuthorNameOfCreation(File file) throws IOException, GitAPIException { return authorName; } - String getAuthorEmailOfCreation(File file) throws IOException, GitAPIException { + String getAuthorEmailOfCreation(File file) throws IOException { String repoRelativePath = pathResolver.relativize(file); String authorEmail = ""; RevWalk walk = getGitRevWalk(repoRelativePath, true);