forked from mathieucarbou/license-maven-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: mathieucarbou#887 Added WorkSpace class
- Loading branch information
Showing
28 changed files
with
260 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2008-2024 Mycila ([email protected]) | ||
* Copyright (C) 2008-2025 Mycila ([email protected]) | ||
* | ||
* 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(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/WorkSpace.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (C) 2008-2025 Mycila ([email protected]) | ||
* | ||
* 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]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.