diff --git a/license-maven-plugin-fs/src/test/java/com/mycila/maven/plugin/license/fs/CopyrightRangeProviderTest.java b/license-maven-plugin-fs/src/test/java/com/mycila/maven/plugin/license/fs/CopyrightRangeProviderTest.java index df2e8614f..a2085b6e8 100644 --- a/license-maven-plugin-fs/src/test/java/com/mycila/maven/plugin/license/fs/CopyrightRangeProviderTest.java +++ b/license-maven-plugin-fs/src/test/java/com/mycila/maven/plugin/license/fs/CopyrightRangeProviderTest.java @@ -42,7 +42,7 @@ class CopyrightRangeProviderTest { void copyrightRange() { Map<String, String> props = new HashMap<>(); final LicenseCheckMojo mojo = new LicenseCheckMojo(); - mojo.defaultBasedir = fsRepoRoot.toFile(); + mojo.legacyDefaultBasedir = fsRepoRoot.toFile(); try (CopyrightRangeProvider provider = new CopyrightRangeProvider()) { provider.init(mojo, props); diff --git a/license-maven-plugin-git/src/main/java/com/mycila/maven/plugin/license/git/CopyrightAuthorProvider.java b/license-maven-plugin-git/src/main/java/com/mycila/maven/plugin/license/git/CopyrightAuthorProvider.java index d0ca8f8b3..9275bb947 100644 --- a/license-maven-plugin-git/src/main/java/com/mycila/maven/plugin/license/git/CopyrightAuthorProvider.java +++ b/license-maven-plugin-git/src/main/java/com/mycila/maven/plugin/license/git/CopyrightAuthorProvider.java @@ -18,8 +18,8 @@ import com.mycila.maven.plugin.license.AbstractLicenseMojo; import com.mycila.maven.plugin.license.PropertiesProvider; import com.mycila.maven.plugin.license.document.Document; -import com.mycila.maven.plugin.license.util.LazyMap; import com.mycila.maven.plugin.license.util.Fn; +import com.mycila.maven.plugin.license.util.LazyMap; import java.io.IOException; import java.io.UncheckedIOException; @@ -40,7 +40,7 @@ public class CopyrightAuthorProvider implements PropertiesProvider { @Override public void init(AbstractLicenseMojo mojo, Map<String, String> currentProperties) { - gitLookup = GitLookup.create(mojo.defaultBasedir, currentProperties); + gitLookup = GitLookup.create(mojo.legacyDefaultBasedir, currentProperties); // One-time warning for shallow repo if (mojo.warnIfShallow && gitLookup.isShallowRepository()) { diff --git a/license-maven-plugin-git/src/main/java/com/mycila/maven/plugin/license/git/CopyrightRangeProvider.java b/license-maven-plugin-git/src/main/java/com/mycila/maven/plugin/license/git/CopyrightRangeProvider.java index f6a4d84ef..68be2765a 100644 --- a/license-maven-plugin-git/src/main/java/com/mycila/maven/plugin/license/git/CopyrightRangeProvider.java +++ b/license-maven-plugin-git/src/main/java/com/mycila/maven/plugin/license/git/CopyrightRangeProvider.java @@ -15,17 +15,16 @@ */ package com.mycila.maven.plugin.license.git; -import java.io.IOException; -import java.io.UncheckedIOException; -import java.util.Map; - -import org.eclipse.jgit.api.errors.GitAPIException; - import com.mycila.maven.plugin.license.AbstractLicenseMojo; import com.mycila.maven.plugin.license.PropertiesProvider; import com.mycila.maven.plugin.license.document.Document; -import com.mycila.maven.plugin.license.util.LazyMap; import com.mycila.maven.plugin.license.util.Fn; +import com.mycila.maven.plugin.license.util.LazyMap; +import org.eclipse.jgit.api.errors.GitAPIException; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.util.Map; /** * An implementation of {@link PropertiesProvider} that adds {@value #COPYRIGHT_LAST_YEAR_KEY} and @@ -44,7 +43,7 @@ public class CopyrightRangeProvider implements PropertiesProvider { @Override public void init(AbstractLicenseMojo mojo, Map<String, String> currentProperties) { - gitLookup = GitLookup.create(mojo.defaultBasedir, currentProperties); + gitLookup = GitLookup.create(mojo.legacyDefaultBasedir, currentProperties); // One-time warning for shallow repo if (mojo.warnIfShallow && gitLookup.isShallowRepository()) { diff --git a/license-maven-plugin-git/src/test/java/com/mycila/maven/plugin/license/git/CopyrightAuthorProviderTest.java b/license-maven-plugin-git/src/test/java/com/mycila/maven/plugin/license/git/CopyrightAuthorProviderTest.java index 305a126c2..606b3ec63 100644 --- a/license-maven-plugin-git/src/test/java/com/mycila/maven/plugin/license/git/CopyrightAuthorProviderTest.java +++ b/license-maven-plugin-git/src/test/java/com/mycila/maven/plugin/license/git/CopyrightAuthorProviderTest.java @@ -41,7 +41,7 @@ class CopyrightAuthorProviderTest { void copyrightAuthor() { Map<String, String> props = new HashMap<>(); final LicenseCheckMojo mojo = new LicenseCheckMojo(); - mojo.defaultBasedir = gitRepoRoot.toFile(); + mojo.legacyDefaultBasedir = gitRepoRoot.toFile(); try (CopyrightAuthorProvider provider = new CopyrightAuthorProvider()) { provider.init(mojo, props); diff --git a/license-maven-plugin-git/src/test/java/com/mycila/maven/plugin/license/git/CopyrightRangeProviderTest.java b/license-maven-plugin-git/src/test/java/com/mycila/maven/plugin/license/git/CopyrightRangeProviderTest.java index 52a9bcec0..792bafc87 100644 --- a/license-maven-plugin-git/src/test/java/com/mycila/maven/plugin/license/git/CopyrightRangeProviderTest.java +++ b/license-maven-plugin-git/src/test/java/com/mycila/maven/plugin/license/git/CopyrightRangeProviderTest.java @@ -41,7 +41,7 @@ class CopyrightRangeProviderTest { void copyrightRange() { Map<String, String> props = new HashMap<>(); final LicenseCheckMojo mojo = new LicenseCheckMojo(); - mojo.defaultBasedir = gitRepoRoot.toFile(); + mojo.legacyDefaultBasedir = gitRepoRoot.toFile(); try (CopyrightRangeProvider provider = new CopyrightRangeProvider()) { provider.init(mojo, props); 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 e135d61db..d93688611 100644 --- 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2024 Mycila (mathieu.carbou@gmail.com) + * Copyright (C) 2008-2025 Mycila (mathieu.carbou@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -26,6 +26,7 @@ import com.mycila.maven.plugin.license.header.HeaderDefinition; import com.mycila.maven.plugin.license.header.HeaderSource; import com.mycila.maven.plugin.license.header.HeaderType; +import com.mycila.maven.plugin.license.util.FileUtils; import com.mycila.maven.plugin.license.util.LazyMap; import com.mycila.maven.plugin.license.util.Selection; import com.mycila.maven.plugin.license.util.resource.ResourceFinder; @@ -85,6 +86,10 @@ public abstract class AbstractLicenseMojo extends AbstractMojo { private static final String[] DEFAULT_KEYWORDS = {"copyright"}; + @Parameter(property = "license.workspace", alias = "workspace") + public WorkSpace workspace = new WorkSpace(); + + @Parameter(property = "license.licenseSets", alias = "licenseSets") public LicenseSet[] licenseSets; @@ -94,9 +99,12 @@ public abstract class AbstractLicenseMojo extends AbstractMojo { * This is named `defaultBaseDirectory` as it will be used as the default * value for the base directory. This default value can be overridden * in each LicenseSet by setting {@link LicenseSet#basedir}. + * + * @deprecated use {@link WorkSpace#basedir} */ + @Deprecated @Parameter(property = "license.basedir", defaultValue = "${project.basedir}", alias = "basedir", required = true) - public File defaultBasedir; + public File legacyDefaultBasedir; /** * Location of the header. It can be a relative path, absolute path, @@ -492,13 +500,29 @@ protected final void execute(final Callback callback) throws MojoExecutionExcept } // make default base dir canonical - this.defaultBasedir = this.getCanonicalFile(this.defaultBasedir, "license.basedir"); + workspace.basedir = getCanonicalFile(firstNonNull(workspace.basedir, legacyDefaultBasedir), "license.workspace.basedir"); // collect all the license sets together final LicenseSet[] allLicenseSets; // if we abandon the legacy config this contiguous block can be removed final LicenseSet legacyLicenseSet = convertLegacyConfigToLicenseSet(); + + if (workspace.basedir != null) { + if (legacyLicenseSet != null && legacyLicenseSet.basedir != null) { + if (!FileUtils.isSubfolder(legacyLicenseSet.basedir, workspace.basedir)) { + throw new MojoExecutionException("Legacy basedir parameter should be a subfolder of the workspace basedir."); + } + } + for (LicenseSet licenseSet : licenseSets) { + if (licenseSet.basedir != null) { + if (!FileUtils.isSubfolder(licenseSet.basedir, workspace.basedir)) { + throw new MojoExecutionException(String.format("LicenseSet basedir parameter [%s] should be a subfolder of the workspace basedir.", licenseSet.basedir.getPath())); + } + } + } + } + if (legacyLicenseSet != null) { if (licenseSets == null) { allLicenseSets = new LicenseSet[]{legacyLicenseSet}; @@ -556,7 +580,8 @@ private void executeForLicenseSets(final LicenseSet[] licenseSets, final Callbac } private boolean detectLegacyUse() { - return legacyConfigHeader != null + return legacyDefaultBasedir != null + || legacyConfigHeader != null || legacyConfigInlineHeader != null || (legacyConfigValidHeaders != null && legacyConfigValidHeaders.length > 0) || legacyConfigMulti != null @@ -580,11 +605,12 @@ private LicenseSet convertLegacyConfigToLicenseSet() { legacyLicenseSet.includes = legacyConfigIncludes; legacyLicenseSet.excludes = legacyConfigExcludes; legacyLicenseSet.keywords = legacyConfigKeywords; + legacyLicenseSet.basedir = legacyDefaultBasedir; return legacyLicenseSet; } private void executeForLicenseSet(final LicenseSet licenseSet, final Callback callback) throws MojoExecutionException, MojoFailureException { - final ResourceFinder finder = new ResourceFinder(firstNonNull(asPath(licenseSet.basedir), asPath(defaultBasedir))); + final ResourceFinder finder = new ResourceFinder(firstNonNull(asPath(licenseSet.basedir), asPath(workspace.basedir))); try { finder.setCompileClassPath(project.getCompileClasspathElements()); } catch (DependencyResolutionRequiredException e) { @@ -671,7 +697,7 @@ private void executeForLicenseSet(final LicenseSet licenseSet, final Callback ca }; final DocumentFactory documentFactory = new DocumentFactory( - firstNonNull(licenseSet.basedir, defaultBasedir), buildMapping(), + firstNonNull(licenseSet.basedir, workspace.basedir), buildMapping(), buildHeaderDefinitions(licenseSet, finder), Charset.forName(encoding), licenseSet.keywords, perDocumentProperties); @@ -786,9 +812,9 @@ private Map<String, String> getDefaultProperties() { private String[] listSelectedFiles(final LicenseSet licenseSet) { final boolean useDefaultExcludes = (licenseSet.useDefaultExcludes != null ? licenseSet.useDefaultExcludes : defaultUseDefaultExcludes); final Selection selection = new Selection( - firstNonNull(licenseSet.basedir, defaultBasedir), licenseSet.includes, buildExcludes(licenseSet), useDefaultExcludes, + firstNonNull(licenseSet.basedir, workspace.basedir), licenseSet.includes, buildExcludes(licenseSet), useDefaultExcludes, getLog()); - debug("From: %s", firstNonNull(licenseSet.basedir, defaultBasedir)); + debug("From: %s", firstNonNull(licenseSet.basedir, workspace.basedir)); debug("Including: %s", deepToString(selection.getIncluded())); debug("Excluding: %s", deepToString(selection.getExcluded())); return selection.getSelectedFiles(); diff --git a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/LicenseSet.java b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/LicenseSet.java index 6c3fe12af..bc3ce02d6 100644 --- a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/LicenseSet.java +++ b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/LicenseSet.java @@ -24,7 +24,8 @@ public class LicenseSet { /** - * The base directory, in which to search for project files. + * The base directory, in which to search for project files. If {@link WokrSpace#basedir} + * is defined, then this base directory should be one of it's subfolders. */ @Parameter(property = "license.basedir") public File basedir; diff --git a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/WorkSpace.java b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/WorkSpace.java new file mode 100644 index 000000000..48b9db5a2 --- /dev/null +++ b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/WorkSpace.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2008-2025 Mycila (mathieu.carbou@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.mycila.maven.plugin.license; + +import org.apache.maven.plugins.annotations.Parameter; + +import java.io.File; + +public class WorkSpace { + + /** + * The base directory, in which to search for project files. + * <p> + * It will be used as the default value for the base directory of each LicenseSet. + * This default value can be overridden in each LicenseSet by setting {@link LicenseSet#basedir}. + */ + + @Parameter(property = "license.workspace.basedir", defaultValue = "${project.basedir}", alias = "basedir") + File basedir; + + @Parameter + String[] includes = new String[0]; + + @Parameter + String[] excludes = new String[0]; +} diff --git a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/util/FileUtils.java b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/util/FileUtils.java index f92c0d73b..d90863f86 100755 --- a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/util/FileUtils.java +++ b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/util/FileUtils.java @@ -23,12 +23,12 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; -import java.io.InputStreamReader; import java.io.IOException; +import java.io.InputStreamReader; import java.io.Reader; import java.io.UncheckedIOException; -import java.net.URL; import java.net.URISyntaxException; +import java.net.URL; import java.nio.ByteBuffer; import java.nio.channels.Channels; import java.nio.channels.FileChannel; @@ -133,4 +133,10 @@ public static void copyFilesToFolder(File src, File dst) { } }); } + + public static boolean isSubfolder(File subfolder, File folder) { + String subfolderPath = subfolder.getAbsolutePath(); + String folderPath = folder.getAbsolutePath(); + return subfolderPath.startsWith(folderPath) && subfolderPath.length() > folderPath.length() && subfolderPath.charAt(folderPath.length()) == File.separatorChar; + } } diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/AdditionalHeaderMojoTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/AdditionalHeaderMojoTest.java index 3edcfb9fe..e034ee033 100755 --- a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/AdditionalHeaderMojoTest.java +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/AdditionalHeaderMojoTest.java @@ -28,7 +28,7 @@ class AdditionalHeaderMojoTest { @Test void test_additionalHeaderDefinitions() throws Exception { LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/check/def"); + check.legacyDefaultBasedir = new File("src/test/resources/check/def"); check.legacyConfigHeader = "src/test/resources/check/header.txt"; check.project = new MavenProjectStub(); check.legacyConfigExcludes = new String[]{"*.xml"}; @@ -48,7 +48,7 @@ void test_additionalHeaderDefinitions() throws Exception { @Test void test_inline() throws Exception { LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/check/def"); + check.legacyDefaultBasedir = new File("src/test/resources/check/def"); check.legacyConfigHeader = "src/test/resources/check/header.txt"; check.project = new MavenProjectStub(); check.legacyConfigExcludes = new String[]{"*.xml"}; diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/AggregateMojoTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/AggregateMojoTest.java index 90b00d8fe..df366871b 100755 --- a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/AggregateMojoTest.java +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/AggregateMojoTest.java @@ -34,7 +34,7 @@ public List<String> getModules() { } }; LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/check/modules"); + check.legacyDefaultBasedir = new File("src/test/resources/check/modules"); check.legacyConfigHeader = "header.txt"; check.project = project; check.strictCheck = true; @@ -51,7 +51,7 @@ public List<String> getModules() { }; LicenseCheckMojo check = new LicenseCheckMojo(); check.project = project; - check.defaultBasedir = new File("src/test/resources/check/modules"); + check.legacyDefaultBasedir = new File("src/test/resources/check/modules"); check.legacyConfigHeader = "header.txt"; check.aggregate = true; check.strictCheck = true; diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/CheckTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/CheckTest.java index a8f01fb88..0425740a1 100755 --- a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/CheckTest.java +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/CheckTest.java @@ -37,7 +37,7 @@ void test_line_wrapping() throws Exception { MavenProjectStub project = new MavenProjectStub(); LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/check/linewrap"); + check.legacyDefaultBasedir = new File("src/test/resources/check/linewrap"); check.legacyConfigHeader = "header.txt"; check.project = project; @@ -59,7 +59,7 @@ void test_line_wrapping() throws Exception { FileUtils.copyFileToFolder(new File("src/test/resources/check/linewrap/testconfig.xml"), tmp); LicenseFormatMojo updater = new LicenseFormatMojo(); - updater.defaultBasedir = tmp; + updater.legacyDefaultBasedir = tmp; updater.legacyConfigHeader = "src/test/resources/check/linewrap/header.txt"; updater.project = project; updater.strictCheck = true; @@ -67,7 +67,7 @@ void test_line_wrapping() throws Exception { // the check again, strictly. should work now check = new LicenseCheckMojo(); - check.defaultBasedir = tmp; + check.legacyDefaultBasedir = tmp; check.legacyConfigHeader = "src/test/resources/check/linewrap/header.txt"; check.project = project; diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/CompleteMojoTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/CompleteMojoTest.java index c2f86590d..d0178a55b 100755 --- a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/CompleteMojoTest.java +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/CompleteMojoTest.java @@ -135,7 +135,7 @@ void test_add(HeaderType headerType, String extension) throws Exception { AbstractLicenseMojo plugin = new LicenseFormatMojo(); plugin.project = new MavenProjectStub(); - plugin.defaultBasedir = tmp; + plugin.legacyDefaultBasedir = tmp; plugin.legacyConfigHeader = "src/test/resources/complete/header1.txt"; plugin.legacyConfigIncludes = new String[]{"file." + extension}; plugin.mapping = Collections.singletonMap(extension, headerType.name()); @@ -155,7 +155,7 @@ void test_update(HeaderType headerType, String extension) throws Exception { AbstractLicenseMojo plugin = new LicenseFormatMojo(); plugin.project = new MavenProjectStub(); - plugin.defaultBasedir = tmp; + plugin.legacyDefaultBasedir = tmp; plugin.legacyConfigHeader = "src/test/resources/complete/header1.txt"; plugin.legacyConfigIncludes = new String[]{"file." + extension}; plugin.mapping = Collections.singletonMap(extension, headerType.name()); @@ -164,7 +164,7 @@ void test_update(HeaderType headerType, String extension) throws Exception { plugin = new LicenseFormatMojo(); plugin.project = new MavenProjectStub(); - plugin.defaultBasedir = tmp; + plugin.legacyDefaultBasedir = tmp; plugin.legacyConfigHeader = "src/test/resources/complete/header2.txt"; plugin.legacyConfigIncludes = new String[]{"file." + extension}; plugin.mapping = Collections.singletonMap(extension, headerType.name()); @@ -184,7 +184,7 @@ void test_remove(HeaderType headerType, String extension) throws Exception { AbstractLicenseMojo plugin = new LicenseFormatMojo(); plugin.project = new MavenProjectStub(); - plugin.defaultBasedir = tmp; + plugin.legacyDefaultBasedir = tmp; plugin.legacyConfigHeader = "src/test/resources/complete/header1.txt"; plugin.legacyConfigIncludes = new String[]{"file." + extension}; plugin.mapping = Collections.singletonMap(extension, headerType.name()); @@ -193,7 +193,7 @@ void test_remove(HeaderType headerType, String extension) throws Exception { plugin = new LicenseRemoveMojo(); plugin.project = new MavenProjectStub(); - plugin.defaultBasedir = tmp; + plugin.legacyDefaultBasedir = tmp; plugin.legacyConfigHeader = "src/test/resources/complete/header1.txt"; plugin.legacyConfigIncludes = new String[]{"file." + extension}; plugin.mapping = Collections.singletonMap(extension, headerType.name()); @@ -214,7 +214,7 @@ void test_check_failed(HeaderType headerType, String extension) throws Exception AbstractLicenseMojo plugin = new LicenseCheckMojo(); plugin.project = new MavenProjectStub(); - plugin.defaultBasedir = tmp; + plugin.legacyDefaultBasedir = tmp; plugin.legacyConfigHeader = "src/test/resources/complete/header1.txt"; plugin.legacyConfigIncludes = new String[]{"file." + extension}; plugin.mapping = Collections.singletonMap(extension, headerType.name()); @@ -236,7 +236,7 @@ void test_check_success(HeaderType headerType, String extension) throws Exceptio AbstractLicenseMojo plugin = new LicenseFormatMojo(); plugin.project = new MavenProjectStub(); - plugin.defaultBasedir = tmp; + plugin.legacyDefaultBasedir = tmp; plugin.legacyConfigHeader = "src/test/resources/complete/header1.txt"; plugin.legacyConfigIncludes = new String[]{"file." + extension}; plugin.mapping = Collections.singletonMap(extension, headerType.name()); @@ -245,7 +245,7 @@ void test_check_success(HeaderType headerType, String extension) throws Exceptio plugin = new LicenseCheckMojo(); plugin.project = new MavenProjectStub(); - plugin.defaultBasedir = tmp; + plugin.legacyDefaultBasedir = tmp; plugin.legacyConfigHeader = "src/test/resources/complete/header1.txt"; plugin.legacyConfigIncludes = new String[]{"file." + extension}; plugin.mapping = Collections.singletonMap(extension, headerType.name()); @@ -276,7 +276,7 @@ public static void main(String[] args) { AbstractLicenseMojo plugin = new LicenseFormatMojo(); plugin.project = new MavenProjectStub(); - plugin.defaultBasedir = root; + plugin.legacyDefaultBasedir = root; plugin.legacyConfigHeader = "src/test/resources/complete/header1.txt"; plugin.legacyConfigIncludes = new String[]{"expected1." + extension}; plugin.mapping = Collections.singletonMap(extension, headerType.name()); @@ -288,7 +288,7 @@ public static void main(String[] args) { plugin = new LicenseFormatMojo(); plugin.project = new MavenProjectStub(); - plugin.defaultBasedir = root; + plugin.legacyDefaultBasedir = root; plugin.legacyConfigHeader = "src/test/resources/complete/header2.txt"; plugin.legacyConfigIncludes = new String[]{"expected2." + extension}; plugin.mapping = Collections.singletonMap(extension, headerType.name()); diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/ExcludesMojoTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/ExcludesMojoTest.java index 27801ff7a..ff5aa8a7c 100755 --- a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/ExcludesMojoTest.java +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/ExcludesMojoTest.java @@ -27,7 +27,7 @@ class ExcludesMojoTest { @Test void test_no_exclusions() throws Exception { LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/check"); + check.legacyDefaultBasedir = new File("src/test/resources/check"); check.legacyConfigHeader = "header.txt"; check.project = new MavenProjectStub(); check.legacyConfigExcludes = new String[0]; @@ -40,7 +40,7 @@ void test_no_exclusions() throws Exception { @Test void test_exclusions() throws Exception { LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/check"); + check.legacyDefaultBasedir = new File("src/test/resources/check"); check.legacyConfigHeader = "header.txt"; check.project = new MavenProjectStub(); check.legacyConfigExcludes = new String[]{"**/*.txt", "**/*.xml", "**/*.java", "**/*.apt.vm"}; diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/FailIfMissingMojoTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/FailIfMissingMojoTest.java index 5e5c2a5f5..8268b280b 100755 --- a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/FailIfMissingMojoTest.java +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/FailIfMissingMojoTest.java @@ -27,7 +27,7 @@ class FailIfMissingMojoTest { @Test void test_fail() throws Exception { LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/check"); + check.legacyDefaultBasedir = new File("src/test/resources/check"); check.legacyConfigHeader = "header.txt"; check.project = new MavenProjectStub(); check.strictCheck = true; @@ -39,7 +39,7 @@ void test_fail() throws Exception { @Test void test_not_fail() throws Exception { LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/check"); + check.legacyDefaultBasedir = new File("src/test/resources/check"); check.legacyConfigHeader = "header.txt"; check.project = new MavenProjectStub(); check.failIfMissing = false; diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/HeaderMojoTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/HeaderMojoTest.java index 3749837b0..393955256 100755 --- a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/HeaderMojoTest.java +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/HeaderMojoTest.java @@ -28,7 +28,7 @@ class HeaderMojoTest { void test_create() throws Exception { MavenProjectStub project = new MavenProjectStub(); LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/main/resources/check"); + check.legacyDefaultBasedir = new File("src/main/resources/check"); check.project = project; check.strictCheck = true; check.execute(); @@ -38,7 +38,7 @@ void test_create() throws Exception { void test_load_header_from_relative_file() throws Exception { MavenProjectStub project = new MavenProjectStub(); LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/check"); + check.legacyDefaultBasedir = new File("src/test/resources/check"); check.legacyConfigHeader = "header.txt"; check.project = project; check.failIfMissing = false; @@ -50,7 +50,7 @@ void test_load_header_from_relative_file() throws Exception { void test_load_header_from_absolute_file() throws Exception { MavenProjectStub project = new MavenProjectStub(); LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/check"); + check.legacyDefaultBasedir = new File("src/test/resources/check"); check.legacyConfigHeader = "src/test/resources/check/header.txt"; check.project = project; check.failIfMissing = false; @@ -63,7 +63,7 @@ void test_load_header_from_project_classpath() throws Exception { MavenProjectStub project = new MavenProjectStub(); project.addCompileSourceRoot("src/test/resources/check/cp"); LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/check"); + check.legacyDefaultBasedir = new File("src/test/resources/check"); check.legacyConfigHeader = "header-in-cp.txt"; check.project = project; check.failIfMissing = false; @@ -75,7 +75,7 @@ void test_load_header_from_project_classpath() throws Exception { void test_load_header_from_plugin_classpath() throws Exception { MavenProjectStub project = new MavenProjectStub(); LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/check"); + check.legacyDefaultBasedir = new File("src/test/resources/check"); check.legacyConfigHeader = "test-header1.txt"; check.project = project; check.failIfMissing = false; @@ -87,7 +87,7 @@ void test_load_header_from_plugin_classpath() throws Exception { void test_inlineHeader() throws Exception { MavenProjectStub project = new MavenProjectStub(); LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/check"); + check.legacyDefaultBasedir = new File("src/test/resources/check"); check.legacyConfigInlineHeader = FileUtils.read(new File("src/test/resources/check/header.txt"), StandardCharsets.UTF_8); check.project = project; check.failIfMissing = false; @@ -99,7 +99,7 @@ void test_inlineHeader() throws Exception { void test_load_multi_headers_from_relative_file() throws Exception { final MavenProjectStub project = new MavenProjectStub(); final LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/check"); + check.legacyDefaultBasedir = new File("src/test/resources/check"); final Multi multi = new Multi(); multi.setHeaders(new String[]{"header.txt", "header2.txt"}); check.legacyConfigMulti = multi; @@ -113,7 +113,7 @@ void test_load_multi_headers_from_relative_file() throws Exception { void test_load_multi_headers_from_absolute_file() throws Exception { final MavenProjectStub project = new MavenProjectStub(); final LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/check"); + check.legacyDefaultBasedir = new File("src/test/resources/check"); final Multi multi = new Multi(); multi.setHeaders(new String[]{"src/test/resources/check/header.txt", "src/test/resources/check/header2.txt"}); check.legacyConfigMulti = multi; @@ -128,7 +128,7 @@ void test_load_multi_headers_from_project_classpath() throws Exception { final MavenProjectStub project = new MavenProjectStub(); project.addCompileSourceRoot("src/test/resources/check/cp"); final LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/check"); + check.legacyDefaultBasedir = new File("src/test/resources/check"); final Multi multi = new Multi(); multi.setHeaders(new String[]{"header-in-cp.txt", "header-in-cp.txt"}); check.legacyConfigMulti = multi; @@ -142,7 +142,7 @@ void test_load_multi_headers_from_project_classpath() throws Exception { void test_load_multi_headers_from_plugin_classpath() throws Exception { final MavenProjectStub project = new MavenProjectStub(); final LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/check"); + check.legacyDefaultBasedir = new File("src/test/resources/check"); final Multi multi = new Multi(); multi.setHeaders(new String[]{"test-header1.txt", "test-header2.txt"}); check.legacyConfigMulti = multi; @@ -156,7 +156,7 @@ void test_load_multi_headers_from_plugin_classpath() throws Exception { void test_multi_inlineHeader() throws Exception { final MavenProjectStub project = new MavenProjectStub(); final LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/check"); + check.legacyDefaultBasedir = new File("src/test/resources/check"); final Multi multi = new Multi(); multi.setInlineHeaders(new String[]{ FileUtils.read(new File("src/test/resources/check/header.txt"), StandardCharsets.UTF_8), diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/IncludesMojoTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/IncludesMojoTest.java index 9e2013200..1efafbb03 100755 --- a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/IncludesMojoTest.java +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/IncludesMojoTest.java @@ -27,7 +27,7 @@ class IncludesMojoTest { @Test void test_include() throws Exception { LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/check"); + check.legacyDefaultBasedir = new File("src/test/resources/check"); check.legacyConfigHeader = "header.txt"; check.project = new MavenProjectStub(); check.legacyConfigIncludes = new String[]{"inexisting"}; @@ -38,7 +38,7 @@ void test_include() throws Exception { @Test void test_include_and_fail() throws Exception { LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/check"); + check.legacyDefaultBasedir = new File("src/test/resources/check"); check.legacyConfigHeader = "header.txt"; check.project = new MavenProjectStub(); check.legacyConfigIncludes = new String[]{"doc1.txt"}; @@ -51,7 +51,7 @@ void test_include_and_fail() throws Exception { @Test void test_include_overrides_default_exclusion() throws Exception { LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/issues/issue-71"); + check.legacyDefaultBasedir = new File("src/test/resources/issues/issue-71"); check.legacyConfigHeader = "../../check/header.txt"; check.project = new MavenProjectStub(); check.legacyConfigIncludes = new String[]{"**/.travis.yml"}; diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/LicenseSetTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/LicenseSetTest.java index 2ab069c89..aa6bd8346 100644 --- a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/LicenseSetTest.java +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/LicenseSetTest.java @@ -47,7 +47,7 @@ void multipleLicenseSets() throws Exception { check.licenseSets = licenseSets; check.project = new MavenProjectStub(); check.strictCheck = false; - check.defaultBasedir = new File("src/test/resources/unknown"); + check.legacyDefaultBasedir = new File("src/test/resources"); final MockedLog logger = new MockedLog(); check.setLog(new DefaultLog(logger)); check.execute(); @@ -85,7 +85,7 @@ void multipleLicenseSetsWithRelativePaths() throws Exception { check.licenseSets = licenseSets; check.project = new MavenProjectStub(); check.strictCheck = false; - check.defaultBasedir = new File("src/test/resources/unknown/../unknown"); + check.legacyDefaultBasedir = new File("src/test/resources/unknown/../unknown"); final MockedLog logger = new MockedLog(); check.setLog(new DefaultLog(logger)); check.execute(); diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/MappingMojoTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/MappingMojoTest.java index 8f46d1871..8d9987e81 100755 --- a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/MappingMojoTest.java +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/MappingMojoTest.java @@ -33,7 +33,7 @@ void test_mapping() throws Exception { LicenseCheckMojo check = new LicenseCheckMojo(); MockedLog logger = new MockedLog(); check.setLog(new DefaultLog(logger)); - check.defaultBasedir = new File("src/test/resources/check"); + check.legacyDefaultBasedir = new File("src/test/resources/check"); check.legacyConfigHeader = "header.txt"; check.project = new MavenProjectStub(); check.useDefaultMapping = true; @@ -70,7 +70,7 @@ void test_mapping_composed_extension() throws Exception { MockedLog logger = new MockedLog(); check.setLog(new DefaultLog(logger)); //check.setLog(new SystemStreamLog()); - check.defaultBasedir = new File("src/test/resources/check"); + check.legacyDefaultBasedir = new File("src/test/resources/check"); check.legacyConfigHeader = "header.txt"; check.project = new MavenProjectStub(); check.legacyConfigIncludes = new String[]{"test.apt.vm"}; @@ -101,7 +101,7 @@ void test_mapping_composed_extension_ordered() throws Exception { MockedLog logger = new MockedLog(); check.setLog(new DefaultLog(logger)); //check.setLog(new SystemStreamLog()); - check.defaultBasedir = new File("src/test/resources/check/issue107"); + check.legacyDefaultBasedir = new File("src/test/resources/check/issue107"); check.legacyConfigHeader = "header.txt"; check.project = new MavenProjectStub(); check.legacyConfigIncludes = new String[]{"test.xml.tmpl"}; @@ -127,7 +127,7 @@ void test_mapping_extension_less_file() throws Exception { MockedLog logger = new MockedLog(); check.setLog(new DefaultLog(logger)); //check.setLog(new SystemStreamLog()); - check.defaultBasedir = new File("src/test/resources/extensionless"); + check.legacyDefaultBasedir = new File("src/test/resources/extensionless"); check.legacyConfigHeader = "header.txt"; check.project = new MavenProjectStub(); check.legacyConfigIncludes = new String[]{"extensionless-file"}; @@ -164,7 +164,7 @@ void test_mapping_unknown_file() throws Exception { MockedLog logger = new MockedLog(); check.setLog(new DefaultLog(logger)); //check.setLog(new SystemStreamLog()); - check.defaultBasedir = new File("src/test/resources/unknown"); + check.legacyDefaultBasedir = new File("src/test/resources/unknown"); check.legacyConfigHeader = "header.txt"; check.project = new MavenProjectStub(); check.legacyConfigIncludes = new String[]{"file.unknown"}; diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/QuietMojoTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/QuietMojoTest.java index 04872d2ff..a3047aca2 100755 --- a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/QuietMojoTest.java +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/QuietMojoTest.java @@ -15,21 +15,21 @@ */ package com.mycila.maven.plugin.license; -import java.io.File; - import org.apache.maven.monitor.logging.DefaultLog; import org.apache.maven.plugin.testing.stubs.MavenProjectStub; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import java.io.File; + class QuietMojoTest { @Test @Disabled("Unstable test to fix: https://github.com/mathieucarbou/license-maven-plugin/issues/834") void test_load_header_from_relative_file() throws Exception { LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/check"); + check.legacyDefaultBasedir = new File("src/test/resources/check"); check.legacyConfigHeader = "header.txt"; check.project = new MavenProjectStub(); check.failIfMissing = false; diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/RemoveMojoTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/RemoveMojoTest.java index 617268535..e6c252679 100755 --- a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/RemoveMojoTest.java +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/RemoveMojoTest.java @@ -37,7 +37,7 @@ void test_remove() throws Exception { FileUtils.copyFileToFolder(new File("src/test/resources/remove/doc2.txt"), tmp); LicenseRemoveMojo remove = new LicenseRemoveMojo(); - remove.defaultBasedir = tmp; + remove.legacyDefaultBasedir = tmp; remove.legacyConfigHeader = "src/test/resources/remove/header.txt"; remove.project = new MavenProjectStub(); remove.execute(); @@ -54,7 +54,7 @@ void test_remove_xml_txt() throws Exception { FileUtils.copyFileToFolder(new File("src/test/resources/doc/doc3.txt"), tmp); LicenseRemoveMojo remove = new LicenseRemoveMojo(); - remove.defaultBasedir = tmp; + remove.legacyDefaultBasedir = tmp; remove.legacyConfigHeader = "src/test/resources/remove/header.txt"; remove.project = new MavenProjectStub(); remove.execute(); @@ -78,7 +78,7 @@ void test_remove_script_style() throws Exception { FileUtils.copyFileToFolder(new File("src/test/resources/remove/issue44-3.rb"), tmp); LicenseRemoveMojo remove = new LicenseRemoveMojo(); - remove.defaultBasedir = tmp; + remove.legacyDefaultBasedir = tmp; remove.legacyConfigHeader = "src/test/resources/remove/header.txt"; remove.project = new MavenProjectStub(); remove.execute(); @@ -95,7 +95,7 @@ void test_remove_multiline() throws Exception { FileUtils.copyFileToFolder(new File("src/test/resources/remove/test.xml"), tmp); LicenseRemoveMojo remove = new LicenseRemoveMojo(); - remove.defaultBasedir = tmp; + remove.legacyDefaultBasedir = tmp; remove.legacyConfigHeader = "src/test/resources/remove/header.txt"; remove.project = new MavenProjectStub(); remove.execute(); @@ -112,7 +112,7 @@ void test_js_1() throws Exception { FileUtils.copyFileToFolder(new File("src/test/resources/remove/test1.js"), tmp); LicenseRemoveMojo remove = new LicenseRemoveMojo(); - remove.defaultBasedir = tmp; + remove.legacyDefaultBasedir = tmp; remove.legacyConfigHeader = "src/test/resources/remove/header.txt"; remove.project = new MavenProjectStub(); remove.execute(); @@ -131,7 +131,7 @@ void test_js_2() throws Exception { FileUtils.copyFileToFolder(new File("src/test/resources/remove/test2.js"), tmp); LicenseRemoveMojo remove = new LicenseRemoveMojo(); - remove.defaultBasedir = tmp; + remove.legacyDefaultBasedir = tmp; remove.legacyConfigHeader = "src/test/resources/remove/header.txt"; remove.project = new MavenProjectStub(); remove.execute(); @@ -151,7 +151,7 @@ void test_issue30_RemoveSucceedsOnAOneLineCommentFile() throws Exception { FileUtils.copyFileToFolder(new File("src/test/resources/remove/issue-30/one-line-comment.ftl"), tmp); LicenseRemoveMojo remove = new LicenseRemoveMojo(); - remove.defaultBasedir = tmp; + remove.legacyDefaultBasedir = tmp; remove.legacyConfigHeader = "src/test/resources/remove/header.txt"; remove.project = new MavenProjectStub(); remove.execute(); @@ -171,14 +171,14 @@ void test_issue41_cannotRemoveEmptyHeader() throws Exception { // Let's apply the licene LicenseFormatMojo format = new LicenseFormatMojo(); - format.defaultBasedir = tmp; + format.legacyDefaultBasedir = tmp; format.legacyConfigHeader = "com/mycila/maven/plugin/license/templates/GPL-3.txt"; format.project = new MavenProjectStub(); format.execute(); // Let's try to remove it LicenseRemoveMojo remove = new LicenseRemoveMojo(); - remove.defaultBasedir = tmp; + remove.legacyDefaultBasedir = tmp; remove.legacyConfigHeader = "com/mycila/maven/plugin/license/templates/GPL-3.txt"; remove.project = new MavenProjectStub(); // remove.keywords = new String[]{"GNU"}; diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/ReportTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/ReportTest.java index eba8aca4e..35f6ae135 100755 --- a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/ReportTest.java +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/ReportTest.java @@ -55,7 +55,7 @@ void test_check_xml() throws Exception { AbstractLicenseMojo plugin = new LicenseCheckMojo(); plugin.clock = Clock.fixed(Instant.ofEpochMilli(1631615047644L), ZoneId.systemDefault()); plugin.project = mavenProjectStub; - plugin.defaultBasedir = tmp; + plugin.legacyDefaultBasedir = tmp; plugin.legacyConfigHeader = "src/test/resources/issues/issue-122/header.txt"; plugin.legacyConfigIncludes = new String[]{"file*.*"}; plugin.reportLocation = new File(tmp, "report/license-plugin-report.xml"); @@ -79,7 +79,7 @@ void test_check_json() throws Exception { AbstractLicenseMojo plugin = new LicenseCheckMojo(); plugin.clock = Clock.fixed(Instant.ofEpochMilli(1631615047644L), ZoneId.systemDefault()); plugin.project = mavenProjectStub; - plugin.defaultBasedir = tmp; + plugin.legacyDefaultBasedir = tmp; plugin.legacyConfigHeader = "src/test/resources/issues/issue-122/header.txt"; plugin.legacyConfigIncludes = new String[]{"file*.*"}; plugin.reportLocation = new File(tmp, "report/license-plugin-report.json"); @@ -103,7 +103,7 @@ void test_format_xml() throws Exception { AbstractLicenseMojo plugin = new LicenseFormatMojo(); plugin.clock = Clock.fixed(Instant.ofEpochMilli(1631615047644L), ZoneId.systemDefault()); plugin.project = mavenProjectStub; - plugin.defaultBasedir = tmp; + plugin.legacyDefaultBasedir = tmp; plugin.legacyConfigHeader = "src/test/resources/issues/issue-122/header.txt"; plugin.legacyConfigIncludes = new String[]{"file*.*"}; plugin.reportLocation = new File(tmp, "report/license-plugin-report.xml"); @@ -123,7 +123,7 @@ void test_format_json() throws Exception { AbstractLicenseMojo plugin = new LicenseFormatMojo(); plugin.clock = Clock.fixed(Instant.ofEpochMilli(1631615047644L), ZoneId.systemDefault()); plugin.project = mavenProjectStub; - plugin.defaultBasedir = tmp; + plugin.legacyDefaultBasedir = tmp; plugin.legacyConfigHeader = "src/test/resources/issues/issue-122/header.txt"; plugin.legacyConfigIncludes = new String[]{"file*.*"}; plugin.reportLocation = new File(tmp, "report/license-plugin-report.json"); @@ -143,7 +143,7 @@ void test_remove_xml() throws Exception { AbstractLicenseMojo plugin = new LicenseRemoveMojo(); plugin.clock = Clock.fixed(Instant.ofEpochMilli(1631615047644L), ZoneId.systemDefault()); plugin.project = mavenProjectStub; - plugin.defaultBasedir = tmp; + plugin.legacyDefaultBasedir = tmp; plugin.legacyConfigHeader = "src/test/resources/issues/issue-122/header.txt"; plugin.legacyConfigIncludes = new String[]{"file*.*"}; plugin.reportLocation = new File(tmp, "report/license-plugin-report.xml"); @@ -163,7 +163,7 @@ void test_remove_json() throws Exception { AbstractLicenseMojo plugin = new LicenseRemoveMojo(); plugin.clock = Clock.fixed(Instant.ofEpochMilli(1631615047644L), ZoneId.systemDefault()); plugin.project = mavenProjectStub; - plugin.defaultBasedir = tmp; + plugin.legacyDefaultBasedir = tmp; plugin.legacyConfigHeader = "src/test/resources/issues/issue-122/header.txt"; plugin.legacyConfigIncludes = new String[]{"file*.*"}; plugin.reportLocation = new File(tmp, "report/license-plugin-report.json"); diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/StrictTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/StrictTest.java index f74de51e4..1871ccc90 100755 --- a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/StrictTest.java +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/StrictTest.java @@ -36,7 +36,7 @@ void test_strict() throws Exception { // all the headers are by default checked not strictlty LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/check/issue76"); + check.legacyDefaultBasedir = new File("src/test/resources/check/issue76"); check.legacyConfigHeader = "src/test/resources/test-header1.txt"; check.project = project; check.strictCheck = false; @@ -65,7 +65,7 @@ void test_space() throws Exception { // all the headers are by default checked not strictlty LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/check/strict"); + check.legacyDefaultBasedir = new File("src/test/resources/check/strict"); check.legacyConfigHeader = "src/test/resources/test-header1-diff.txt"; check.project = project; check.execute(); diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/UpdateMojoTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/UpdateMojoTest.java index c9602e3fa..673094de8 100755 --- a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/UpdateMojoTest.java +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/UpdateMojoTest.java @@ -45,7 +45,7 @@ void test_update() throws Exception { FileUtils.copyFileToFolder(new File("src/test/resources/update/doc2.txt"), tmp); LicenseFormatMojo updater = new LicenseFormatMojo(); - updater.defaultBasedir = tmp; + updater.legacyDefaultBasedir = tmp; updater.legacyConfigHeader = "src/test/resources/update/header.txt"; updater.project = new MavenProjectStub(); updater.defaultProperties = ImmutableMap.of("year", "2008"); @@ -63,7 +63,7 @@ void test_update_inlineHeader() throws Exception { FileUtils.copyFileToFolder(new File("src/test/resources/update/doc2.txt"), tmp); LicenseFormatMojo updater = new LicenseFormatMojo(); - updater.defaultBasedir = tmp; + updater.legacyDefaultBasedir = tmp; updater.legacyConfigInlineHeader = FileUtils.read(new File("src/test/resources/update/header.txt"), StandardCharsets.UTF_8); updater.project = new MavenProjectStub(); updater.defaultProperties = ImmutableMap.of("year", "2008"); @@ -82,7 +82,7 @@ void test_skipExistingHeaders() throws Exception { // only update those files without a copyright header LicenseFormatMojo updater = new LicenseFormatMojo(); - updater.defaultBasedir = tmp; + updater.legacyDefaultBasedir = tmp; updater.legacyConfigHeader = "src/test/resources/update/header.txt"; updater.project = new MavenProjectStub(); updater.defaultProperties = ImmutableMap.of("year", "2008"); @@ -94,7 +94,7 @@ void test_skipExistingHeaders() throws Exception { // expect unchanged header to fail check against new header LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = tmp; + check.legacyDefaultBasedir = tmp; check.legacyConfigHeader = "src/test/resources/update/header.txt"; check.project = new MavenProjectStub(); check.defaultProperties = ImmutableMap.of("year", "2008"); @@ -122,7 +122,7 @@ void test_issue50() throws Exception { FileUtils.copyFileToFolder(new File("src/test/resources/update/issue50/test3.properties"), tmp); LicenseFormatMojo updater = new LicenseFormatMojo(); - updater.defaultBasedir = tmp; + updater.legacyDefaultBasedir = tmp; updater.legacyConfigHeader = "src/test/resources/update/header.txt"; updater.defaultProperties = ImmutableMap.of("year", "2008"); updater.mapping = new LinkedHashMap<String, String>() {{ @@ -147,7 +147,7 @@ void test_issue48() throws Exception { FileUtils.copyFileToFolder(new File("src/test/resources/update/issue48/test2.php"), tmp); LicenseFormatMojo updater = new LicenseFormatMojo(); - updater.defaultBasedir = tmp; + updater.legacyDefaultBasedir = tmp; updater.legacyConfigHeader = "src/test/resources/update/header.txt"; updater.defaultProperties = ImmutableMap.of("year", "2008"); updater.mapping = new LinkedHashMap<String, String>() {{ @@ -186,7 +186,7 @@ void test_issue44() throws Exception { FileUtils.copyFileToFolder(new File("src/test/resources/update/issue44/test.asp"), tmp); LicenseFormatMojo updater = new LicenseFormatMojo(); - updater.defaultBasedir = tmp; + updater.legacyDefaultBasedir = tmp; updater.legacyConfigHeader = "src/test/resources/update/header.txt"; updater.defaultProperties = ImmutableMap.of("year", "2008"); updater.project = new MavenProjectStub(); @@ -213,7 +213,7 @@ void test_issue_14() throws Exception { FileUtils.copyFileToFolder(new File("src/test/resources/update/issue14/test.properties"), tmp); LicenseFormatMojo updater = new LicenseFormatMojo(); - updater.defaultBasedir = tmp; + updater.legacyDefaultBasedir = tmp; updater.legacyConfigHeader = "src/test/resources/update/issue14/header.txt"; updater.project = new MavenProjectStub(); updater.execute(); @@ -251,7 +251,7 @@ void test_issue71_canSkipSeveralLines() throws Exception { FileUtils.copyFileToFolder(new File("src/test/resources/issues/issue-71/issue-71.txt.extended"), tmp); LicenseFormatMojo updater = new LicenseFormatMojo(); - updater.defaultBasedir = tmp; + updater.legacyDefaultBasedir = tmp; updater.legacyConfigHeader = "src/test/resources/issues/issue-71/issue-71-header.txt"; updater.project = new MavenProjectStub(); updater.mapping = new LinkedHashMap<String, String>() {{ @@ -274,7 +274,7 @@ void test_issue37_RunningUpdaterTwiceMustNotChangeTheFile() throws Exception { FileUtils.copyFileToFolder(new File("src/test/resources/update/issue37/xwiki.xml"), tmp); LicenseFormatMojo execution1 = new LicenseFormatMojo(); - execution1.defaultBasedir = tmp; + execution1.legacyDefaultBasedir = tmp; execution1.legacyConfigHeader = "src/test/resources/update/issue37/xwiki-license.txt"; execution1.project = new MavenProjectStub(); execution1.execute(); @@ -282,7 +282,7 @@ void test_issue37_RunningUpdaterTwiceMustNotChangeTheFile() throws Exception { String execution1FileContent = FileUtils.read(new File(tmp, "xwiki.xml"), Charset.defaultCharset()); LicenseFormatMojo execution2 = new LicenseFormatMojo(); - execution2.defaultBasedir = tmp; + execution2.legacyDefaultBasedir = tmp; execution2.legacyConfigHeader = "src/test/resources/update/issue37/xwiki-license.txt"; execution2.project = new MavenProjectStub(); execution2.execute(); @@ -299,7 +299,7 @@ void test_UpdateWorksHasExpectedOnAOneLineCommentFile_relatesTo_issue30() throws FileUtils.copyFileToFolder(new File("src/test/resources/update/issue30/one-line-comment.ftl"), tmp); LicenseFormatMojo updater = new LicenseFormatMojo(); - updater.defaultBasedir = tmp; + updater.legacyDefaultBasedir = tmp; updater.legacyConfigHeader = "src/test/resources/single-line-header.txt"; updater.project = new MavenProjectStub(); updater.execute(); @@ -322,7 +322,7 @@ void test_issue213() throws Exception { FileUtils.copyFileToFolder(new File("src/test/resources/update/issue213/test.xml"), tmp); LicenseFormatMojo updater = new LicenseFormatMojo(); - updater.defaultBasedir = tmp; + updater.legacyDefaultBasedir = tmp; LicenseSet licenseSet = new LicenseSet(); licenseSet.basedir = tmp; @@ -355,7 +355,7 @@ void test_issue71_underscore_in_package_name() throws Exception { FileUtils.copyFileToFolder(new File("src/test/resources/update/issue-187/Main.java"), tmp); LicenseFormatMojo updater = new LicenseFormatMojo(); - updater.defaultBasedir = tmp; + updater.legacyDefaultBasedir = tmp; updater.legacyConfigHeader = "src/test/resources/update/issue-187/header.txt"; updater.project = new MavenProjectStub(); updater.mapping = new LinkedHashMap<String, String>() {{ diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/UseDefaultExcludesMojoTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/UseDefaultExcludesMojoTest.java index f762824e3..6a507c451 100755 --- a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/UseDefaultExcludesMojoTest.java +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/UseDefaultExcludesMojoTest.java @@ -27,7 +27,7 @@ class UseDefaultExcludesMojoTest { void test_include_and_fail() throws Exception { try { LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/check"); + check.legacyDefaultBasedir = new File("src/test/resources/check"); check.legacyConfigHeader = "header.txt"; check.project = new MavenProjectStub(); check.legacyConfigExcludes = new String[]{"doc1.txt"}; @@ -42,7 +42,7 @@ void test_include_and_fail() throws Exception { @Test void check_defaultExcludes_exclude_Netbeans_Configuration() throws Exception { LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/excludes/issue-68"); + check.legacyDefaultBasedir = new File("src/test/resources/excludes/issue-68"); check.legacyConfigHeader = "header.txt"; check.project = new MavenProjectStub(); check.defaultUseDefaultExcludes = true; @@ -54,7 +54,7 @@ void check_defaultExcludes_exclude_Netbeans_Configuration() throws Exception { void check_withoutDefaultExcludes_Netbeans_Configuration_Is_Reported() { try { LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/excludes/issue-68"); + check.legacyDefaultBasedir = new File("src/test/resources/excludes/issue-68"); check.legacyConfigHeader = "header.txt"; check.project = new MavenProjectStub(); check.defaultUseDefaultExcludes = false; diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/UseDefaultMappingMojoTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/UseDefaultMappingMojoTest.java index 895266180..f39a642a7 100755 --- a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/UseDefaultMappingMojoTest.java +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/UseDefaultMappingMojoTest.java @@ -27,7 +27,7 @@ class UseDefaultMappingMojoTest { @Test void test_not_useDefaultMapping() throws Exception { LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/check"); + check.legacyDefaultBasedir = new File("src/test/resources/check"); check.legacyConfigHeader = "header.txt"; check.project = new MavenProjectStub(); check.useDefaultMapping = false; @@ -44,7 +44,7 @@ void test_not_useDefaultMapping() throws Exception { @Test void test_useDefaultMapping() throws Exception { LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/check"); + check.legacyDefaultBasedir = new File("src/test/resources/check"); check.legacyConfigHeader = "header.txt"; check.project = new MavenProjectStub(); check.useDefaultMapping = true; diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/ValidHeaderMojoTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/ValidHeaderMojoTest.java index 926b0c447..6d565a415 100755 --- a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/ValidHeaderMojoTest.java +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/ValidHeaderMojoTest.java @@ -32,7 +32,7 @@ void test_validHeader() throws Exception { format.execute();*/ LicenseCheckMojo check = new LicenseCheckMojo(); - check.defaultBasedir = new File("src/test/resources/check/valid"); + check.legacyDefaultBasedir = new File("src/test/resources/check/valid"); check.legacyConfigHeader = "src/test/resources/test-header1.txt"; check.project = new MavenProjectStub(); check.strictCheck = true; diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/WorkSpaceTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/WorkSpaceTest.java new file mode 100644 index 000000000..2cca343ef --- /dev/null +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/WorkSpaceTest.java @@ -0,0 +1,83 @@ +package com.mycila.maven.plugin.license; + +import org.apache.maven.monitor.logging.DefaultLog; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.testing.stubs.MavenProjectStub; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.io.File; + +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class WorkSpaceTest { + @Test + void test_workspace_basedir_check() throws MojoExecutionException, MojoFailureException { + final WorkSpace workspace = new WorkSpace(); + workspace.basedir = new File("src/test/resources/check/modules"); + + final LicenseSet licenseSet = new LicenseSet(); + licenseSet.basedir = new File("src/test/resources/check/issue76"); + licenseSet.header = "src/test/resources/test-header1.txt"; + + final LicenseSet[] licenseSets = { + licenseSet + }; + + final LicenseCheckMojo check = new LicenseCheckMojo(); + check.licenseSets = licenseSets; + check.project = new MavenProjectStub(); + + check.workspace = workspace; + check.licenseSets = licenseSets; + + final MockedLog logger = new MockedLog(); + check.setLog(new DefaultLog(logger)); + MojoExecutionException thrown = assertThrows(MojoExecutionException.class, () -> check.execute()); + assertTrue(thrown.getMessage().startsWith("LicenseSet basedir parameter")); + } + + @Test + public void test_multipleLicenseSets() throws Exception { + final LicenseSet licenseSet1 = new LicenseSet(); + licenseSet1.basedir = new File("src/test/resources/check/strict"); + licenseSet1.header = "src/test/resources/test-header1-diff.txt"; + + final LicenseSet licenseSet2 = new LicenseSet(); + licenseSet2.basedir = new File("src/test/resources/check/issue76"); + licenseSet2.header = "src/test/resources/test-header1.txt"; + + final LicenseSet licenseSetWithoutBaseDir = new LicenseSet(); + licenseSetWithoutBaseDir.header = "test-header1.txt"; + + final LicenseSet[] licenseSets = { + licenseSet1, + licenseSet2, + licenseSetWithoutBaseDir + }; + + final LicenseCheckMojo check = new LicenseCheckMojo(); + check.licenseSets = licenseSets; + check.project = new MavenProjectStub(); + check.strictCheck = false; + check.workspace = new WorkSpace(); + check.workspace.basedir = new File("src/test/resources"); + final MockedLog logger = new MockedLog(); + check.setLog(new DefaultLog(logger)); + check.execute(); + + final String log = logger.getContent(); + final String fileFromFirstSet = new File("src/test/resources/check/strict/space.java").getCanonicalPath() + .replace('\\', '/'); + final String fileFromSecondSet = new File("src/test/resources/check/issue76/after.xml").getCanonicalPath() + .replace('\\', '/'); + final String fileFromDefaultBaseDirSet = new File("src/test/resources/unknown/header.txt").getCanonicalPath() + .replace('\\', '/'); + + Assertions.assertTrue(log.contains("Header OK in: " + fileFromFirstSet)); + Assertions.assertTrue(log.contains("Header OK in: " + fileFromSecondSet)); + Assertions.assertTrue(log.contains("Header OK in: " + fileFromDefaultBaseDirSet)); + } +}