Skip to content

Commit

Permalink
remove unnecessary diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
frank-wagner-ibm committed Jan 8, 2025
1 parent 6fec332 commit aef796a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ public abstract class AbstractLicenseMojo extends AbstractMojo {
public String legacyConfigHeader;

/**
* Header, as text, directly in pom file. Using a CDATA section is strongly
* recommended.
* Header, as text, directly in pom file. Using a CDATA section is strongly recommended.
*
* @deprecated use {@link LicenseSet#inlineHeader}
*/
Expand Down Expand Up @@ -157,9 +156,8 @@ public abstract class AbstractLicenseMojo extends AbstractMojo {
* <p>
* This is named `defaultHeaderDefinitions` as it will be used as the default
* value for the header definitions. This default value can be overridden
* in each LicenseSet by setting {@link LicenseSet#headerDefinitions} or
* {@link LicenseSet#inlineHeaderStyles} and is overridden by
* {@link #defaultInlineHeaderStyles}.
* in each LicenseSet by setting {@link LicenseSet#headerDefinitions} or
* {@link LicenseSet#inlineHeaderStyles} and is overridden by {@link #defaultInlineHeaderStyles}.
*/
@Parameter(alias = "headerDefinitions")
public String[] defaultHeaderDefinitions = new String[0];
Expand All @@ -171,8 +169,7 @@ public abstract class AbstractLicenseMojo extends AbstractMojo {
* value for the header definitions.
* <p>
* This default value can be overridden
* in each LicenseSet by setting {@link LicenseSet#headerDefinitions} or
* {@link LicenseSet#inlineHeaderStyles}.
* in each LicenseSet by setting {@link LicenseSet#headerDefinitions} or {@link LicenseSet#inlineHeaderStyles}.
* <p>
* Inline styles overrides those read from file
*/
Expand Down Expand Up @@ -240,8 +237,7 @@ public abstract class AbstractLicenseMojo extends AbstractMojo {
* and so on.
* <p>
* This is named `defaultUseDefaultExcludes` as it will be used as the default
* value for whether to use default excludes. This default value can be
* overridden
* value for whether to use default excludes. This default value can be overridden
* in each LicenseSet by setting {@link LicenseSet#useDefaultExcludes}.
*/
@Parameter(property = "license.useDefaultExcludes", defaultValue = "true", alias = "useDefaultExcludes")
Expand Down Expand Up @@ -278,29 +274,26 @@ public abstract class AbstractLicenseMojo extends AbstractMojo {
* Maven license plugin uses concurrency to check license headers. This
* factor is used to control the number of threads used to check. The rule
* is:
* <br>
* {@code <nThreads> = <number of cores> * concurrencyFactor}
* <br> {@code <nThreads> = <number of cores> * concurrencyFactor}
* <br>
* The default is 1.5.
*/
@Parameter(property = "license.concurrencyFactor", defaultValue = "1.5")
public float concurrencyFactor = 1.5f;


/**
* Maven license plugin uses concurrency to check license headers. With this
* option the number of threads used to check can be specified. If given
* it take precedence over <code>concurrencyFactor</code>
* <p>
* The default is 0 which implies that the default for
* <code>concurrencyFactor</code>
* The default is 0 which implies that the default for <code>concurrencyFactor</code>
* is used.
*/
@Parameter(property = "license.nThreads", defaultValue = "0")
public int nThreads;

/**
* Whether to skip the plugin execution.
*/
/** Whether to skip the plugin execution. */
@Parameter(property = "license.skip", defaultValue = "false")
public boolean skip;

Expand All @@ -314,10 +307,7 @@ public abstract class AbstractLicenseMojo extends AbstractMojo {
@Parameter(property = "license.warnIfShallow", defaultValue = "true")
public boolean warnIfShallow = true;

/**
* If you do not want to see the list of file having a missing header, you can
* add the quiet flag that will shorten the output.
*/
/** If you do not want to see the list of file having a missing header, you can add the quiet flag that will shorten the output. */
@Parameter(property = "license.quiet", defaultValue = "false")
public boolean quiet;

Expand Down Expand Up @@ -387,19 +377,18 @@ public abstract class AbstractLicenseMojo extends AbstractMojo {
protected boolean dependencyEnforce;

/**
* Block of {@link LicensePolicy} configuration for enforcing license adherence
* in dependencies.
* Block of {@link LicensePolicy} configuration for enforcing license adherence in dependencies.
*/
@Parameter(property = "license.dependencies.policies")
protected Set<LicensePolicy> dependencyPolicies;

/**
* Exception message prefix to display when an artifact is denied by one of the
* license policies.
* Exception message prefix to display when an artifact is denied by one of the license policies.
*/
@Parameter(property = "license.dependencies.exceptionMessage", required = true, defaultValue = LicenseMessage.WARN_POLICY_DENIED)
protected String dependencyExceptionMessage;


@Parameter(defaultValue = "${project}", required = true)
protected MavenProject project;

Expand All @@ -424,8 +413,7 @@ public abstract class AbstractLicenseMojo extends AbstractMojo {
public MavenSession session;

/**
* The location where to write the report of the plugin execution (file
* processed, action taken, etc).
* The location where to write the report of the plugin execution (file processed, action taken, etc).
* <p>
* "PRESENT" means the file has a header (check goal)
* <p>
Expand Down Expand Up @@ -497,7 +485,7 @@ public void checkUnknown() throws MojoExecutionException {

protected final void execute(final Callback callback) throws MojoExecutionException, MojoFailureException {
if (skip) {
getLog().info("License Plugin is Skipped");
getLog().info("License Plugin is Skipped");
} else {
if (prohibitLegacyUse && detectLegacyUse()) {
throw new MojoExecutionException("Use of legacy parameters has been prohibited by configuration.");
Expand Down Expand Up @@ -540,8 +528,7 @@ private File getCanonicalFile(final File file, final String description) throws
}
}

private void executeForLicenseSets(final LicenseSet[] licenseSets, final Callback callback)
throws MojoFailureException, MojoExecutionException {
private void executeForLicenseSets(final LicenseSet[] licenseSets, final Callback callback) throws MojoFailureException, MojoExecutionException {
if (licenseSets == null || licenseSets.length == 0) {
warn("At least one licenseSet must be specified");
return;
Expand Down Expand Up @@ -570,18 +557,17 @@ private void executeForLicenseSets(final LicenseSet[] licenseSets, final Callbac

private boolean detectLegacyUse() {
return legacyConfigHeader != null
|| legacyConfigInlineHeader != null
|| (legacyConfigValidHeaders != null && legacyConfigValidHeaders.length > 0)
|| legacyConfigMulti != null
|| (legacyConfigHeaderSections != null && legacyConfigHeaderSections.length > 0)
|| (legacyConfigIncludes != null && legacyConfigIncludes.length > 0)
|| (legacyConfigExcludes != null && legacyConfigExcludes.length > 0)
|| (legacyConfigKeywords != null && !Arrays.equals(legacyConfigKeywords, DEFAULT_KEYWORDS));
|| legacyConfigInlineHeader != null
|| (legacyConfigValidHeaders != null && legacyConfigValidHeaders.length > 0)
|| legacyConfigMulti != null
|| (legacyConfigHeaderSections != null && legacyConfigHeaderSections.length > 0)
|| (legacyConfigIncludes != null && legacyConfigIncludes.length > 0)
|| (legacyConfigExcludes != null && legacyConfigExcludes.length > 0)
|| (legacyConfigKeywords != null && !Arrays.equals(legacyConfigKeywords, DEFAULT_KEYWORDS));
}

private LicenseSet convertLegacyConfigToLicenseSet() {
if (legacyConfigHeader == null
&& (this.legacyConfigInlineHeader == null || this.legacyConfigInlineHeader.isEmpty())) {
if (legacyConfigHeader == null && (this.legacyConfigInlineHeader == null || this.legacyConfigInlineHeader.isEmpty())) {
return null;
}

Expand All @@ -597,19 +583,16 @@ private LicenseSet convertLegacyConfigToLicenseSet() {
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)));
private void executeForLicenseSet(final LicenseSet licenseSet, final Callback callback) throws MojoExecutionException, MojoFailureException {
final ResourceFinder finder = new ResourceFinder(firstNonNull(asPath(licenseSet.basedir), asPath(defaultBasedir)));
try {
finder.setCompileClassPath(project.getCompileClasspathElements());
} catch (DependencyResolutionRequiredException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
finder.setPluginClassPath(getClass().getClassLoader());

final HeaderSource headerSource = HeaderSource.of(licenseSet.multi, licenseSet.inlineHeader, licenseSet.header,
Charset.forName(this.encoding), finder);
final HeaderSource headerSource = HeaderSource.of(licenseSet.multi, licenseSet.inlineHeader, licenseSet.header, Charset.forName(this.encoding), finder);
final Header header = new Header(headerSource, licenseSet.headerSections);
debug("Header: %s", header.getLocation());

Expand All @@ -618,8 +601,7 @@ private void executeForLicenseSet(final LicenseSet licenseSet, final Callback ca
}
final List<Header> validHeaders = new ArrayList<>(licenseSet.validHeaders.length);
for (final String validHeader : licenseSet.validHeaders) {
final HeaderSource validHeaderSource = HeaderSource.of(null, null, validHeader,
Charset.forName(this.encoding),
final HeaderSource validHeaderSource = HeaderSource.of(null, null, validHeader, Charset.forName(this.encoding),
finder);
validHeaders.add(new Header(validHeaderSource, licenseSet.headerSections));
}
Expand Down Expand Up @@ -759,17 +741,17 @@ private void executeForLicenseSet(final LicenseSet licenseSet, final Callback ca
}

private boolean hasHeader(final LicenseSet licenseSet) {
return (licenseSet.multi != null
&& ((licenseSet.multi.headers != null && licenseSet.multi.headers.length > 0)
|| (licenseSet.multi.inlineHeaders != null && licenseSet.multi.inlineHeaders.length > 0
&& !licenseSet.multi.inlineHeaders[0].isEmpty())))
|| (licenseSet.header != null
|| (licenseSet.inlineHeader != null && !licenseSet.inlineHeader.isEmpty()));
return
(licenseSet.multi != null
&& ((licenseSet.multi.headers != null && licenseSet.multi.headers.length > 0)
|| (licenseSet.multi.inlineHeaders != null && licenseSet.multi.inlineHeaders.length > 0 && !licenseSet.multi.inlineHeaders[0].isEmpty()))
) || (licenseSet.header != null || (licenseSet.inlineHeader != null && !licenseSet.inlineHeader.isEmpty()));
}

private int getNumberOfExecutorThreads() {
return nThreads > 0 ? nThreads
: Math.max(1, (int) (Runtime.getRuntime().availableProcessors() * concurrencyFactor));
return nThreads > 0 ?
nThreads :
Math.max(1, (int) (Runtime.getRuntime().availableProcessors() * concurrencyFactor));
}

private Map<String, String> getDefaultProperties() {
Expand Down Expand Up @@ -806,11 +788,9 @@ private Map<String, String> getDefaultProperties() {
}

private String[] listSelectedFiles(final LicenseSet licenseSet) {
final boolean useDefaultExcludes = (licenseSet.useDefaultExcludes != null ? licenseSet.useDefaultExcludes
: defaultUseDefaultExcludes);
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, defaultBasedir), licenseSet.includes, buildExcludes(licenseSet), useDefaultExcludes,
getLog());
debug("From: %s", firstNonNull(licenseSet.basedir, defaultBasedir));
debug("Including: %s", deepToString(selection.getIncluded()));
Expand Down Expand Up @@ -864,8 +844,7 @@ private Map<String, String> buildMapping() {
return extensionMapping;
}

private Map<String, HeaderDefinition> buildHeaderDefinitions(final LicenseSet licenseSet,
final ResourceFinder finder) throws MojoFailureException {
private Map<String, HeaderDefinition> buildHeaderDefinitions(final LicenseSet licenseSet, final ResourceFinder finder) throws MojoFailureException {
// like mappings, first get default definitions
final Map<String, HeaderDefinition> headers = new HashMap<>(HeaderType.defaultDefinitions());

Expand Down Expand Up @@ -893,13 +872,11 @@ private Map<String, HeaderDefinition> buildHeaderDefinitions(final LicenseSet li
return headers;
}

private Map<String, HeaderDefinition> loadHeaderDefinition(final String headerDefinition,
final ResourceFinder finder) throws MojoFailureException {
private Map<String, HeaderDefinition> loadHeaderDefinition(final String headerDefinition, final ResourceFinder finder) throws MojoFailureException {
try {
final InputSource source = new InputSource(finder.findResource(headerDefinition).openStream());
source.setEncoding(encoding);
final AdditionalHeaderDefinition fileDefinitions = new AdditionalHeaderDefinition(
XMLDoc.from(source, true));
final AdditionalHeaderDefinition fileDefinitions = new AdditionalHeaderDefinition(XMLDoc.from(source, true));
final Map<String, HeaderDefinition> map = fileDefinitions.getDefinitions();
debug("%d header definitions loaded from '%s'", map.size(), headerDefinition);
return map;
Expand Down Expand Up @@ -945,7 +922,7 @@ public Credentials findCredentials(String serverID) {
}

if (getLog().isDebugEnabled()) {
getLog().debug("no credentials found for server: " + serverID);
getLog().debug("no credentials found for server: " + serverID);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@

import java.util.Collections;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;

/**
*
*/
public interface PropertiesProvider extends AutoCloseable {

default void init(AbstractLicenseMojo mojo, Map<String, String> currentProperties) {
// Do nothing on default
// Do nothing on default
}

default Map<String, String> adjustProperties(AbstractLicenseMojo mojo,
Expand All @@ -38,20 +36,15 @@ default Map<String, String> adjustProperties(AbstractLicenseMojo mojo,
return Collections.emptyMap();
}

default Map<String, Supplier<String>> adjustLazyProperties(AbstractLicenseMojo mojo,
Map<String, String> currentProperties, Document document) {
return adjustProperties(mojo, null, document)
.entrySet().stream()
.collect(Collectors.toMap(
Map.Entry::getKey,
e -> () -> e.getValue(),
(a, b) -> {
throw new UnsupportedOperationException();
}));
}
default Map<String, Supplier<String>> adjustLazyProperties(AbstractLicenseMojo mojo, Map<String, String> currentProperties, Document document) {
return adjustProperties(mojo, null, document).entrySet().stream().collect(Collectors.toMap(
Map.Entry::getKey, e -> () -> e.getValue(), (a, b) -> {
throw new UnsupportedOperationException();
}));
}

@Override
default void close() {
// Do nothing on default
}
@Override
default void close() {
// Do nothing on default
}
}

0 comments on commit aef796a

Please sign in to comment.