diff --git a/.gitignore b/.gitignore index dacf81740..93ec34285 100755 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,6 @@ nb-configuration.xml .DS_Store release-pom.xml .mvn/wrapper/maven-wrapper.jar + +# VS Code +.vscode/ diff --git a/docs/reports/5.0.0-SNAPSHOT/license-maven-plugin/license-plugin-report.xml b/docs/reports/5.0.0-SNAPSHOT/license-maven-plugin/license-plugin-report.xml index 9e7cfe863..705633239 100644 --- a/docs/reports/5.0.0-SNAPSHOT/license-maven-plugin/license-plugin-report.xml +++ b/docs/reports/5.0.0-SNAPSHOT/license-maven-plugin/license-plugin-report.xml @@ -1,5 +1,5 @@ - + @@ -16,6 +16,7 @@ + diff --git a/docs/reports/5.0.0-SNAPSHOT/license-plugin-report.xml b/docs/reports/5.0.0-SNAPSHOT/license-plugin-report.xml index 84f81cfc1..0e25469c7 100644 --- a/docs/reports/5.0.0-SNAPSHOT/license-plugin-report.xml +++ b/docs/reports/5.0.0-SNAPSHOT/license-plugin-report.xml @@ -1,5 +1,5 @@ - + 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..6dea682f5 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 props = new HashMap<>(); final LicenseCheckMojo mojo = new LicenseCheckMojo(); - mojo.defaultBasedir = fsRepoRoot.toFile(); + mojo.workspace.basedir = 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..b5568352c 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 currentProperties) { - gitLookup = GitLookup.create(mojo.defaultBasedir, currentProperties); + gitLookup = GitLookup.create(mojo.workspace.basedir, 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..64d20979a 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 currentProperties) { - gitLookup = GitLookup.create(mojo.defaultBasedir, currentProperties); + gitLookup = GitLookup.create(mojo.workspace.basedir, 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..1cf3b0656 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 props = new HashMap<>(); final LicenseCheckMojo mojo = new LicenseCheckMojo(); - mojo.defaultBasedir = gitRepoRoot.toFile(); + mojo.workspace.basedir = 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..a6ca9f5ea 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 props = new HashMap<>(); final LicenseCheckMojo mojo = new LicenseCheckMojo(); - mojo.defaultBasedir = gitRepoRoot.toFile(); + mojo.workspace.basedir = 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..7374f72b6 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 @@ -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; @@ -80,11 +81,16 @@ import static java.lang.String.format; import static java.util.Arrays.asList; import static java.util.Arrays.deepToString; +import static java.util.Objects.requireNonNull; 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 +100,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} */ - @Parameter(property = "license.basedir", defaultValue = "${project.basedir}", alias = "basedir", required = true) - public File defaultBasedir; + @Deprecated + @Parameter(property = "license.basedir", alias = "basedir") + public File legacyDefaultBasedir; /** * Location of the header. It can be a relative path, absolute path, @@ -491,14 +500,45 @@ protected final void execute(final Callback callback) throws MojoExecutionExcept throw new MojoExecutionException("Use of legacy parameters has been prohibited by configuration."); } - // make default base dir canonical - this.defaultBasedir = this.getCanonicalFile(this.defaultBasedir, "license.basedir"); + // use canonical base dir + workspace.basedir = getCanonicalFile(workspace.basedir, "license.workspace.basedir"); + if (workspace.basedir == null) { + if (legacyDefaultBasedir == null) { + workspace.basedir = getCanonicalFile(project.getBasedir(), "project.basedir"); + } else { + workspace.basedir = getCanonicalFile(legacyDefaultBasedir, "license.basedir"); + } + } + requireNonNull(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 (legacyLicenseSet != null && legacyLicenseSet.basedir != null) { + legacyLicenseSet.basedir = getCanonicalFile(legacyLicenseSet.basedir, "license.basedir"); + if (!FileUtils.isSameOrSubFolder(legacyLicenseSet.basedir, workspace.basedir)) { + throw new MojoExecutionException("Legacy basedir parameter should be a subfolder of the workspace basedir."); + } + } + + if (licenseSets != null) { + for (LicenseSet licenseSet : licenseSets) { + if (licenseSet.basedir == null) { + licenseSet.basedir = workspace.basedir; + } else { + licenseSet.basedir = getCanonicalFile(licenseSet.basedir, "licenseSet.basedir"); + if (!FileUtils.isSameOrSubFolder(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}; @@ -541,8 +581,6 @@ private void executeForLicenseSets(final LicenseSet[] licenseSets, final Callbac warn("No header file specified to check for license in licenseSet: " + i); return; } - // make licenseSet baseDir canonical - licenseSet.basedir = this.getCanonicalFile(licenseSet.basedir, "licenseSet[" + i + "].basedir"); } if (!strictCheck) { warn("Property 'strictCheck' is not enabled. Please consider adding true in your pom.xml file."); @@ -556,7 +594,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 +619,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(asPath(licenseSet.basedir)); try { finder.setCompileClassPath(project.getCompileClasspathElements()); } catch (DependencyResolutionRequiredException e) { @@ -671,7 +711,7 @@ private void executeForLicenseSet(final LicenseSet licenseSet, final Callback ca }; final DocumentFactory documentFactory = new DocumentFactory( - firstNonNull(licenseSet.basedir, defaultBasedir), buildMapping(), + licenseSet.basedir, buildMapping(), buildHeaderDefinitions(licenseSet, finder), Charset.forName(encoding), licenseSet.keywords, perDocumentProperties); @@ -786,9 +826,9 @@ private Map 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, + licenseSet.basedir, licenseSet.includes, buildExcludes(licenseSet), useDefaultExcludes, getLog()); - debug("From: %s", firstNonNull(licenseSet.basedir, defaultBasedir)); + debug("From: %s", licenseSet.basedir); debug("Including: %s", deepToString(selection.getIncluded())); debug("Excluding: %s", deepToString(selection.getExcluded())); return selection.getSelectedFiles(); @@ -922,8 +962,4 @@ public Credentials findCredentials(String serverID) { } return null; } - - private static T firstNonNull(final T t1, final T t2) { - return t1 == null ? t2 : t1; - } } 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..b2fd38dc1 --- /dev/null +++ b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/WorkSpace.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2008-2024 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. + *

+ * 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", alias = "basedir") + public File basedir; + + @Parameter + public String[] includes = new String[0]; + + @Parameter + public 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..4feb6397a 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; @@ -39,6 +39,7 @@ import java.util.stream.Stream; import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; +import static java.util.Objects.requireNonNull; public final class FileUtils { @@ -133,4 +134,10 @@ public static void copyFilesToFolder(File src, File dst) { } }); } + + public static boolean isSameOrSubFolder(File subfolder, File folder) { + requireNonNull(subfolder); + requireNonNull(folder); + return subfolder.toPath().startsWith(folder.toPath()); + } } 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 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 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..e1827ff56 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 @@ -134,8 +134,9 @@ void test_add(HeaderType headerType, String extension) throws Exception { FileUtils.copyFilesToFolder(new File("src/test/resources/complete/" + headerType), tmp); AbstractLicenseMojo plugin = new LicenseFormatMojo(); + plugin.workspace.basedir = tmp; 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 +156,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 +165,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 +185,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 +194,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 +215,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 +237,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 +246,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 +277,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 +289,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..a999002a3 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 @@ -19,22 +19,25 @@ import org.apache.maven.plugin.testing.stubs.MavenProjectStub; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import java.io.File; class LicenseSetTest { @Test - void multipleLicenseSets() throws Exception { + void multipleLicenseSets(@TempDir File folder) throws Exception { final LicenseSet licenseSet1 = new LicenseSet(); - licenseSet1.basedir = new File("src/test/resources/check/strict"); + licenseSet1.basedir = new File("src/test/resources/check/multi-license/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.basedir = new File("src/test/resources/check/multi-license/issue76"); licenseSet2.header = "src/test/resources/test-header1.txt"; final LicenseSet licenseSetWithoutBaseDir = new LicenseSet(); + licenseSetWithoutBaseDir.excludes = new String[] { "strict/**", "issue76/**" }; + licenseSetWithoutBaseDir.header = "test-header1.txt"; final LicenseSet[] licenseSets = { @@ -47,15 +50,15 @@ 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/check/multi-license"); 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('\\', '/'); + final String fileFromFirstSet = new File("src/test/resources/check/multi-license/strict/space.java").getCanonicalPath().replace('\\', '/'); + final String fileFromSecondSet = new File("src/test/resources/check/multi-license/issue76/after.xml").getCanonicalPath().replace('\\', '/'); + final String fileFromDefaultBaseDirSet = new File("src/test/resources/check/multi-license/unknown/header.txt").getCanonicalPath().replace('\\', '/'); Assertions.assertTrue(log.contains("Header OK in: " + fileFromFirstSet)); Assertions.assertTrue(log.contains("Header OK in: " + fileFromSecondSet)); @@ -65,15 +68,16 @@ void multipleLicenseSets() throws Exception { @Test void multipleLicenseSetsWithRelativePaths() throws Exception { final LicenseSet licenseSet1 = new LicenseSet(); - licenseSet1.basedir = new File("src/test/resources/check/def/../strict"); + licenseSet1.basedir = new File("src/test/resources/check/multi-license/unknown/../strict"); licenseSet1.header = "src/test/resources/test-header1-diff.txt"; final LicenseSet licenseSet2 = new LicenseSet(); - licenseSet2.basedir = new File("src/test/resources/check/def/../issue76"); + licenseSet2.basedir = new File("src/test/resources/check/multi-license/unknown/../issue76"); licenseSet2.header = "src/test/resources/test-header1.txt"; final LicenseSet licenseSetWithoutBaseDir = new LicenseSet(); licenseSetWithoutBaseDir.header = "test-header1.txt"; + licenseSetWithoutBaseDir.excludes = new String[] { "strict/**", "issue76/**" }; final LicenseSet[] licenseSets = { licenseSet1, @@ -85,15 +89,15 @@ 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/check/multi-license/unknown/../"); 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('\\', '/'); + final String fileFromFirstSet = new File("src/test/resources/check/multi-license/strict/space.java").getCanonicalPath().replace('\\', '/'); + final String fileFromSecondSet = new File("src/test/resources/check/multi-license/issue76/after.xml").getCanonicalPath().replace('\\', '/'); + final String fileFromDefaultBaseDirSet = new File("src/test/resources/check/multi-license/unknown/header.txt").getCanonicalPath().replace('\\', '/'); Assertions.assertTrue(log.contains("Header OK in: " + fileFromFirstSet)); Assertions.assertTrue(log.contains("Header OK in: " + fileFromSecondSet)); 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() {{ @@ -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() {{ @@ -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() {{ @@ -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() {{ 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..cd110bf91 --- /dev/null +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/WorkSpaceTest.java @@ -0,0 +1,40 @@ +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.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")); + } +} diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/util/FileUtilsTest.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/util/FileUtilsTest.java index 09d569333..27c30a1f6 100755 --- a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/util/FileUtilsTest.java +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/util/FileUtilsTest.java @@ -17,8 +17,10 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import java.io.File; +import java.io.IOException; import java.net.URL; import java.nio.ByteBuffer; import java.nio.charset.Charset; @@ -51,4 +53,39 @@ void test_read_first_lines() throws Exception { Assertions.assertTrue(s.contains("c")); Assertions.assertFalse(s.contains("d")); } + + @Test + void test_IsSameOrSubFolder_folder_is_direct_child_of_folder(@TempDir File folder) throws IOException { + Assertions.assertTrue(FileUtils.isSameOrSubFolder(folder, folder)); + } + + @Test + void test_IsSameOrSubFolder_subfolder_is_direct_child_of_folder(@TempDir File folder) throws IOException { + File subfolder = createSubfolder(folder, "subfolder"); + + Assertions.assertTrue(FileUtils.isSameOrSubFolder(subfolder, folder)); + } + + @Test + void test_IsSameOrSubFolder_subfolder_is_indirect_child_of_folder(@TempDir File folder) throws IOException { + File subfolder = createSubfolder(folder, "subfolder/subsubfolder"); + + Assertions.assertTrue(FileUtils.isSameOrSubFolder(subfolder, folder)); + } + + @Test + void test_IsSameOrSubFolder_subfolder_is_not_child_of_folder(@TempDir File folder, @TempDir File otherFolder) + throws IOException { + File subfolder = createSubfolder(folder, "subfolder"); + + Assertions.assertFalse(FileUtils.isSameOrSubFolder(subfolder, otherFolder)); + } + + private File createSubfolder(File parent, String path) throws IOException { + File subfolder = new File(parent, path); + if (!subfolder.mkdirs()) { + throw new IOException("Failed to create subfolder"); + } + return subfolder; + } } diff --git a/license-maven-plugin/src/test/resources/check/multi-license/issue76/after.txt b/license-maven-plugin/src/test/resources/check/multi-license/issue76/after.txt new file mode 100755 index 000000000..7d4e1f769 --- /dev/null +++ b/license-maven-plugin/src/test/resources/check/multi-license/issue76/after.txt @@ -0,0 +1,17 @@ +==== + Copyright (C) ${year} http://code.google.com/p/maven-license-plugin/ + + 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 + + http://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. + AFTER +==== + diff --git a/license-maven-plugin/src/test/resources/check/multi-license/issue76/after.xml b/license-maven-plugin/src/test/resources/check/multi-license/issue76/after.xml new file mode 100755 index 000000000..ecd12c767 --- /dev/null +++ b/license-maven-plugin/src/test/resources/check/multi-license/issue76/after.xml @@ -0,0 +1,21 @@ + + + + diff --git a/license-maven-plugin/src/test/resources/check/multi-license/issue76/before.txt b/license-maven-plugin/src/test/resources/check/multi-license/issue76/before.txt new file mode 100755 index 000000000..bfa0cb0d6 --- /dev/null +++ b/license-maven-plugin/src/test/resources/check/multi-license/issue76/before.txt @@ -0,0 +1,17 @@ +==== + BEFORE + Copyright (C) ${year} http://code.google.com/p/maven-license-plugin/ + + 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 + + http://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. +==== + diff --git a/license-maven-plugin/src/test/resources/check/multi-license/issue76/before.xml b/license-maven-plugin/src/test/resources/check/multi-license/issue76/before.xml new file mode 100755 index 000000000..b07baca60 --- /dev/null +++ b/license-maven-plugin/src/test/resources/check/multi-license/issue76/before.xml @@ -0,0 +1,21 @@ + + + + diff --git a/license-maven-plugin/src/test/resources/check/multi-license/issue76/std.txt b/license-maven-plugin/src/test/resources/check/multi-license/issue76/std.txt new file mode 100755 index 000000000..9fb44f90d --- /dev/null +++ b/license-maven-plugin/src/test/resources/check/multi-license/issue76/std.txt @@ -0,0 +1,16 @@ +==== + Copyright (C) ${year} http://code.google.com/p/maven-license-plugin/ + + 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 + + http://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. +==== + diff --git a/license-maven-plugin/src/test/resources/check/multi-license/issue76/std.xml b/license-maven-plugin/src/test/resources/check/multi-license/issue76/std.xml new file mode 100755 index 000000000..f94d74d11 --- /dev/null +++ b/license-maven-plugin/src/test/resources/check/multi-license/issue76/std.xml @@ -0,0 +1,20 @@ + + + + diff --git a/license-maven-plugin/src/test/resources/check/multi-license/strict/nospace.java b/license-maven-plugin/src/test/resources/check/multi-license/strict/nospace.java new file mode 100755 index 000000000..94238b778 --- /dev/null +++ b/license-maven-plugin/src/test/resources/check/multi-license/strict/nospace.java @@ -0,0 +1,17 @@ +/* + * Copyright (C) ${year} http://code.google.com/p/maven-license-plugin/ + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * DIFF 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. + * DIFF + */ +package check.strict; diff --git a/license-maven-plugin/src/test/resources/check/multi-license/strict/space.java b/license-maven-plugin/src/test/resources/check/multi-license/strict/space.java new file mode 100755 index 000000000..94238b778 --- /dev/null +++ b/license-maven-plugin/src/test/resources/check/multi-license/strict/space.java @@ -0,0 +1,17 @@ +/* + * Copyright (C) ${year} http://code.google.com/p/maven-license-plugin/ + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * DIFF 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. + * DIFF + */ +package check.strict; diff --git a/license-maven-plugin/src/test/resources/check/multi-license/unknown/file.unknown b/license-maven-plugin/src/test/resources/check/multi-license/unknown/file.unknown new file mode 100644 index 000000000..e69de29bb diff --git a/license-maven-plugin/src/test/resources/check/multi-license/unknown/header.txt b/license-maven-plugin/src/test/resources/check/multi-license/unknown/header.txt new file mode 100755 index 000000000..a4d2ac474 --- /dev/null +++ b/license-maven-plugin/src/test/resources/check/multi-license/unknown/header.txt @@ -0,0 +1,13 @@ +Copyright (C) ${year} http://code.google.com/p/maven-license-plugin/ + +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 + + http://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. \ No newline at end of file