diff --git a/maven-core/pom.xml b/maven-core/pom.xml index 8b94467d48..7983e10742 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -274,6 +274,45 @@ under the License. + + com.github.siom79.japicmp + japicmp-maven-plugin + + + + + + org.apache.maven.lifecycle.DefaultLifecycleExecutor#DefaultLifecycleExecutor() + org.apache.maven.plugin.DefaultBuildPluginManager#DefaultBuildPluginManager() + org.apache.maven.project.DefaultMavenProjectHelper#DefaultMavenProjectHelper() + org.apache.maven.project.DefaultProjectBuilder#DefaultProjectBuilder() + org.apache.maven.project.DefaultProjectBuildingHelper#DefaultProjectBuildingHelper() + org.apache.maven.project.DefaultProjectDependenciesResolver#DefaultProjectDependenciesResolver() + org.apache.maven.rtinfo.internal.DefaultRuntimeInformation#DefaultRuntimeInformation() + org.apache.maven.settings.DefaultMavenSettingsBuilder#DefaultMavenSettingsBuilder() + org.apache.maven.toolchain.DefaultToolchainManager#DefaultToolchainManager():CONSTRUCTOR_REMOVED + org.apache.maven.toolchain.DefaultToolchainManagerPrivate#DefaultToolchainManagerPrivate() + + + org.apache.maven.project.DefaultProjectBuilder#DISABLE_GLOBAL_MODEL_CACHE_SYSTEM_PROPERTY + + org.apache.maven.plugin.DefaultBuildPluginManager#setMojoExecutionListeners(java.util.List) + + org.apache.maven.classrealm.DefaultClassRealmManager#DefaultClassRealmManager(org.codehaus.plexus.logging.Logger,org.codehaus.plexus.PlexusContainer,java.util.List,org.apache.maven.extension.internal.CoreExportsProvider) + + org.apache.maven.graph.DefaultGraphBuilder#projectBuilder + + org.apache.maven.plugin.MavenPluginValidator + + org.apache.maven.plugin.PluginParameterExpressionEvaluator#PluginParameterExpressionEvaluator(org.apache.maven.execution.MavenSession,org.apache.maven.plugin.MojoExecution,org.apache.maven.project.path.PathTranslator,org.codehaus.plexus.logging.Logger,org.apache.maven.project.MavenProject,java.util.Properties):CONSTRUCTOR_REMOVED + org.apache.maven.toolchain.DefaultToolchain#getLog():METHOD_RETURN_TYPE_CHANGED + org.apache.maven.toolchain.DefaultToolchain#DefaultToolchain(org.apache.maven.toolchain.model.ToolchainModel,org.codehaus.plexus.logging.Logger):CONSTRUCTOR_REMOVED + org.apache.maven.toolchain.DefaultToolchain#DefaultToolchain(org.apache.maven.toolchain.model.ToolchainModel,java.lang.String,org.codehaus.plexus.logging.Logger):CONSTRUCTOR_REMOVED + org.apache.maven.toolchain.DefaultToolchainManager#logger + + + + diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java index 370ad944d0..de2e7103a7 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java +++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java @@ -235,7 +235,7 @@ public class DefaultMavenExecutionRequestPopulator implements MavenExecutionRequ request.setActiveProfiles(settings.getActiveProfiles()); for (org.apache.maven.settings.Profile rawProfile : settings.getProfiles()) { - request.addProfile(SettingsUtils.convertFromSettingsProfile(rawProfile.getDelegate())); + request.addProfile(SettingsUtils.convertFromSettingsProfile(rawProfile)); if (settings.getActiveProfiles().contains(rawProfile.getId())) { List remoteRepositories = rawProfile.getRepositories(); diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java b/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java index 1b6af0075a..b508355695 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java @@ -30,6 +30,7 @@ import java.util.stream.Collectors; import org.apache.maven.api.Session; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.RepositoryCache; +import org.apache.maven.model.Profile; import org.apache.maven.monitor.event.EventDispatcher; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.MavenProject; @@ -38,7 +39,7 @@ import org.apache.maven.settings.Mirror; import org.apache.maven.settings.Proxy; import org.apache.maven.settings.Server; import org.apache.maven.settings.Settings; -import org.apache.maven.settings.SettingsUtils; +import org.apache.maven.settings.SettingsUtilsV4; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.eclipse.aether.RepositorySystemSession; @@ -372,7 +373,8 @@ public class MavenSession implements Cloneable { .servers(request.getServers().stream().map(Server::getDelegate).collect(Collectors.toList())) .mirrors(request.getMirrors().stream().map(Mirror::getDelegate).collect(Collectors.toList())) .profiles(request.getProfiles().stream() - .map(SettingsUtils::convertToSettingsProfile) + .map(Profile::getDelegate) + .map(SettingsUtilsV4::convertToSettingsProfile) .collect(Collectors.toList())) .activeProfiles(request.getActiveProfiles()) .pluginGroups(request.getPluginGroups()) diff --git a/maven-core/src/main/java/org/apache/maven/graph/DefaultGraphBuilder.java b/maven-core/src/main/java/org/apache/maven/graph/DefaultGraphBuilder.java index d7edbe7d0c..f342d0577b 100644 --- a/maven-core/src/main/java/org/apache/maven/graph/DefaultGraphBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/graph/DefaultGraphBuilder.java @@ -68,6 +68,15 @@ public class DefaultGraphBuilder implements GraphBuilder { private final RequestPomCollectionStrategy requestPomCollectionStrategy; private final ProjectSelector projectSelector; + /** + * @deprecated Use {@link #DefaultGraphBuilder(BuildResumptionDataRepository, PomlessCollectionStrategy, + * MultiModuleCollectionStrategy, RequestPomCollectionStrategy)} instead or rely on JSR 330 + */ + @Deprecated + public DefaultGraphBuilder() { + this(null, null, null, null); + } + @Inject public DefaultGraphBuilder( BuildResumptionDataRepository buildResumptionDataRepository, diff --git a/maven-core/src/main/java/org/apache/maven/graph/DefaultProjectDependencyGraph.java b/maven-core/src/main/java/org/apache/maven/graph/DefaultProjectDependencyGraph.java index 233d56f7c0..3269b38b0a 100644 --- a/maven-core/src/main/java/org/apache/maven/graph/DefaultProjectDependencyGraph.java +++ b/maven-core/src/main/java/org/apache/maven/graph/DefaultProjectDependencyGraph.java @@ -70,6 +70,22 @@ public class DefaultProjectDependencyGraph implements ProjectDependencyGraph { * @throws DuplicateProjectException * @throws CycleDetectedException * @since 3.5.0 + * @deprecated Use {@link #DefaultProjectDependencyGraph(Collection, Collection)} instead. + */ + @Deprecated + public DefaultProjectDependencyGraph(List allProjects, Collection projects) + throws CycleDetectedException, DuplicateProjectException { + this((Collection) allProjects, projects); + } + + /** + * Creates a new project dependency graph based on the specified projects. + * + * @param allProjects All collected projects. + * @param projects The projects to create the dependency graph with. + * @throws DuplicateProjectException + * @throws CycleDetectedException + * @since 4.0.0 */ public DefaultProjectDependencyGraph(Collection allProjects, Collection projects) throws CycleDetectedException, DuplicateProjectException { diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java index c43ea01768..421be28872 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java @@ -20,6 +20,7 @@ package org.apache.maven.lifecycle; import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.Set; import javax.inject.Inject; import javax.inject.Named; @@ -103,6 +104,13 @@ public class DefaultLifecycleExecutor implements LifecycleExecutor { return lifeCyclePluginAnalyzer.getPluginsBoundByDefaultToAllLifecycles(packaging); } + // USED BY MAVEN HELP PLUGIN + + @Deprecated + public Map getPhaseToLifecycleMap() { + return defaultLifeCycles.getPhaseToLifecycleMap(); + } + // Used by m2eclipse @SuppressWarnings({"UnusedDeclaration"}) diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycles.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycles.java index 2c3af74a73..f3f90e4f71 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycles.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycles.java @@ -51,10 +51,21 @@ public class DefaultLifecycles { private final PlexusContainer plexusContainer; + private Map customLifecycles; + public DefaultLifecycles() { this.plexusContainer = null; } + /** + * @deprecated Rely on {@link #DefaultLifecycles(PlexusContainer)} instead + */ + @Deprecated + public DefaultLifecycles(Map lifecycles, org.codehaus.plexus.logging.Logger logger) { + this.customLifecycles = lifecycles; + this.plexusContainer = null; + } + @Inject public DefaultLifecycles(PlexusContainer plexusContainer) { this.plexusContainer = plexusContainer; @@ -132,7 +143,7 @@ public class DefaultLifecycles { // TODO: Remove the following code when maven-compat is gone // This code is here to ensure maven-compat's EmptyLifecycleExecutor keeps on working. if (plexusContainer == null) { - return new HashMap<>(); + return customLifecycles != null ? customLifecycles : new HashMap<>(); } // Lifecycles cannot be cached as extensions might add custom lifecycles later in the execution. diff --git a/maven-core/src/main/java/org/apache/maven/plugin/CycleDetectedInPluginGraphException.java b/maven-core/src/main/java/org/apache/maven/plugin/CycleDetectedInPluginGraphException.java index a2fe3c4fa4..26f26226a7 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/CycleDetectedInPluginGraphException.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/CycleDetectedInPluginGraphException.java @@ -18,7 +18,7 @@ */ package org.apache.maven.plugin; -import org.apache.maven.api.model.Plugin; +import org.apache.maven.model.Plugin; import org.codehaus.plexus.component.composition.CycleDetectedInComponentGraphException; /** diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DebugConfigurationListener.java b/maven-core/src/main/java/org/apache/maven/plugin/DebugConfigurationListener.java index 80bfdff9d1..dd3edf6177 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DebugConfigurationListener.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DebugConfigurationListener.java @@ -21,6 +21,7 @@ package org.apache.maven.plugin; import java.lang.reflect.Array; import org.codehaus.plexus.component.configurator.ConfigurationListener; import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Log at debug level the mojo configuration. @@ -31,6 +32,14 @@ import org.slf4j.Logger; public class DebugConfigurationListener implements ConfigurationListener { private final Logger logger; + /** + * @deprecated Use {@link #DebugConfigurationListener(Logger)} instead. + */ + @Deprecated + public DebugConfigurationListener(org.codehaus.plexus.logging.Logger logger) { + this(LoggerFactory.getLogger(logger.getName())); + } + public DebugConfigurationListener(Logger logger) { this.logger = logger; } diff --git a/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginManager.java index 88bed8e4fb..dec00d5986 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginManager.java @@ -66,10 +66,20 @@ public interface MavenPluginManager { throws MojoNotFoundException, PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException; + /** + * Verifies the specified plugin is compatible with the current Maven runtime. + * + * @param pluginDescriptor The descriptor of the plugin to check, must not be {@code null}. + * @deprecated Use {@link #checkPrerequisites(PluginDescriptor)} instead. + */ + @Deprecated + void checkRequiredMavenVersion(PluginDescriptor pluginDescriptor) throws PluginIncompatibleException; + /** * Verifies that the specified plugin's prerequisites are met. * * @param pluginDescriptor The descriptor of the plugin to check, must not be {@code null}. + * @since 4.0.0 */ void checkPrerequisites(PluginDescriptor pluginDescriptor) throws PluginIncompatibleException; diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java index 7a92acfb8a..75745b9ef5 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java @@ -306,6 +306,12 @@ public class DefaultMavenPluginManager implements MavenPluginManager { } } + @Override + @Deprecated + public void checkRequiredMavenVersion(PluginDescriptor pluginDescriptor) throws PluginIncompatibleException { + checkPrerequisites(pluginDescriptor); + } + public void setupPluginRealm( PluginDescriptor pluginDescriptor, MavenSession session, diff --git a/maven-core/src/main/java/org/apache/maven/settings/SettingsUtils.java b/maven-core/src/main/java/org/apache/maven/settings/SettingsUtils.java index f60f83b416..b4f4ab724f 100644 --- a/maven-core/src/main/java/org/apache/maven/settings/SettingsUtils.java +++ b/maven-core/src/main/java/org/apache/maven/settings/SettingsUtils.java @@ -18,19 +18,6 @@ */ package org.apache.maven.settings; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; -import org.apache.maven.api.model.ActivationFile; -import org.apache.maven.api.settings.Activation; -import org.apache.maven.api.settings.ActivationOS; -import org.apache.maven.api.settings.ActivationProperty; -import org.apache.maven.api.settings.Profile; -import org.apache.maven.api.settings.Repository; -import org.apache.maven.api.settings.RepositoryPolicy; -import org.apache.maven.api.settings.Settings; -import org.apache.maven.settings.merge.MavenSettingsMerger; - /** * Several convenience methods to handle settings * @@ -47,8 +34,10 @@ public final class SettingsUtils { * @param recessive * @param recessiveSourceLevel */ - public static Settings merge(Settings dominant, Settings recessive, String recessiveSourceLevel) { - return new MavenSettingsMerger().merge(dominant, recessive, recessiveSourceLevel); + public static void merge(Settings dominant, Settings recessive, String recessiveSourceLevel) { + if (dominant != null && recessive != null) { + dominant.delegate = SettingsUtilsV4.merge(dominant.getDelegate(), recessive.getDelegate()); + } } /** @@ -56,80 +45,7 @@ public final class SettingsUtils { * @return a profile */ public static Profile convertToSettingsProfile(org.apache.maven.model.Profile modelProfile) { - Profile.Builder profile = Profile.newBuilder(); - - profile.id(modelProfile.getId()); - - org.apache.maven.model.Activation modelActivation = modelProfile.getActivation(); - - if (modelActivation != null) { - Activation.Builder activation = Activation.newBuilder(); - - activation.activeByDefault(modelActivation.isActiveByDefault()); - - activation.jdk(modelActivation.getJdk()); - - org.apache.maven.model.ActivationProperty modelProp = modelActivation.getProperty(); - - if (modelProp != null) { - ActivationProperty prop = ActivationProperty.newBuilder() - .name(modelProp.getName()) - .value(modelProp.getValue()) - .build(); - activation.property(prop); - } - - org.apache.maven.model.ActivationOS modelOs = modelActivation.getOs(); - - if (modelOs != null) { - ActivationOS os = ActivationOS.newBuilder() - .arch(modelOs.getArch()) - .family(modelOs.getFamily()) - .name(modelOs.getName()) - .version(modelOs.getVersion()) - .build(); - - activation.os(os); - } - - org.apache.maven.model.ActivationFile modelFile = modelActivation.getFile(); - - if (modelFile != null) { - org.apache.maven.api.settings.ActivationFile file = - org.apache.maven.api.settings.ActivationFile.newBuilder() - .exists(modelFile.getExists()) - .missing(modelFile.getMissing()) - .build(); - - activation.file(file); - } - - profile.activation(activation.build()); - } - - profile.properties(modelProfile.getProperties().entrySet().stream() - .collect(Collectors.toMap( - e -> e.getKey().toString(), e -> e.getValue().toString()))); - - List repos = modelProfile.getRepositories(); - if (repos != null) { - List repositories = new ArrayList<>(); - for (org.apache.maven.model.Repository repo : repos) { - repositories.add(convertToSettingsRepository(repo)); - } - profile.repositories(repositories); - } - - List pluginRepos = modelProfile.getPluginRepositories(); - if (pluginRepos != null) { - List repositories = new ArrayList<>(); - for (org.apache.maven.model.Repository pluginRepo : pluginRepos) { - repositories.add(convertToSettingsRepository(pluginRepo)); - } - profile.pluginRepositories(repositories); - } - - return profile.build(); + return new Profile(SettingsUtilsV4.convertToSettingsProfile(modelProfile.getDelegate())); } /** @@ -137,144 +53,32 @@ public final class SettingsUtils { * @return a profile */ public static org.apache.maven.model.Profile convertFromSettingsProfile(Profile settingsProfile) { - org.apache.maven.api.model.Profile.Builder profile = org.apache.maven.api.model.Profile.newBuilder(); - - profile.id(settingsProfile.getId()); - - Activation settingsActivation = settingsProfile.getActivation(); - - if (settingsActivation != null) { - org.apache.maven.api.model.Activation.Builder activation = - org.apache.maven.api.model.Activation.newBuilder(); - - activation.activeByDefault(settingsActivation.isActiveByDefault()); - - activation.jdk(settingsActivation.getJdk()); - - ActivationProperty settingsProp = settingsActivation.getProperty(); - if (settingsProp != null) { - activation.property(org.apache.maven.api.model.ActivationProperty.newBuilder() - .name(settingsProp.getName()) - .value(settingsProp.getValue()) - .build()); - } - - ActivationOS settingsOs = settingsActivation.getOs(); - if (settingsOs != null) { - activation.os(org.apache.maven.api.model.ActivationOS.newBuilder() - .arch(settingsOs.getArch()) - .family(settingsOs.getFamily()) - .name(settingsOs.getName()) - .version(settingsOs.getVersion()) - .build()); - } - - org.apache.maven.api.settings.ActivationFile settingsFile = settingsActivation.getFile(); - if (settingsFile != null) { - activation.file(ActivationFile.newBuilder() - .exists(settingsFile.getExists()) - .missing(settingsFile.getMissing()) - .build()); - } - - profile.activation(activation.build()); - } - - profile.properties(settingsProfile.getProperties()); - - List repos = settingsProfile.getRepositories(); - if (repos != null) { - profile.repositories(repos.stream() - .map(SettingsUtils::convertFromSettingsRepository) - .collect(Collectors.toList())); - } - - List pluginRepos = settingsProfile.getPluginRepositories(); - if (pluginRepos != null) { - profile.pluginRepositories(pluginRepos.stream() - .map(SettingsUtils::convertFromSettingsRepository) - .collect(Collectors.toList())); - } - - org.apache.maven.model.Profile value = new org.apache.maven.model.Profile(profile.build()); - value.setSource("settings.xml"); - return value; - } - - /** - * @param settingsRepo - * @return a repository - */ - private static org.apache.maven.api.model.Repository convertFromSettingsRepository(Repository settingsRepo) { - org.apache.maven.api.model.Repository.Builder repo = org.apache.maven.api.model.Repository.newBuilder(); - - repo.id(settingsRepo.getId()); - repo.layout(settingsRepo.getLayout()); - repo.name(settingsRepo.getName()); - repo.url(settingsRepo.getUrl()); - - if (settingsRepo.getSnapshots() != null) { - repo.snapshots(convertRepositoryPolicy(settingsRepo.getSnapshots())); - } - if (settingsRepo.getReleases() != null) { - repo.releases(convertRepositoryPolicy(settingsRepo.getReleases())); - } - - return repo.build(); - } - - /** - * @param settingsPolicy - * @return a RepositoryPolicy - */ - private static org.apache.maven.api.model.RepositoryPolicy convertRepositoryPolicy( - RepositoryPolicy settingsPolicy) { - org.apache.maven.api.model.RepositoryPolicy policy = org.apache.maven.api.model.RepositoryPolicy.newBuilder() - .enabled(Boolean.toString(settingsPolicy.isEnabled())) - .updatePolicy(settingsPolicy.getUpdatePolicy()) - .checksumPolicy(settingsPolicy.getChecksumPolicy()) - .build(); - return policy; - } - - /** - * @param modelRepo - * @return a repository - */ - private static Repository convertToSettingsRepository(org.apache.maven.model.Repository modelRepo) { - Repository repo = Repository.newBuilder() - .id(modelRepo.getId()) - .layout(modelRepo.getLayout()) - .name(modelRepo.getName()) - .url(modelRepo.getUrl()) - .snapshots(modelRepo.getSnapshots() != null ? convertRepositoryPolicy(modelRepo.getSnapshots()) : null) - .releases(modelRepo.getReleases() != null ? convertRepositoryPolicy(modelRepo.getReleases()) : null) - .build(); - - return repo; - } - - /** - * @param modelPolicy - * @return a RepositoryPolicy - */ - private static RepositoryPolicy convertRepositoryPolicy(org.apache.maven.model.RepositoryPolicy modelPolicy) { - RepositoryPolicy policy = RepositoryPolicy.newBuilder() - .enabled(modelPolicy.isEnabled()) - .updatePolicy(modelPolicy.getUpdatePolicy()) - .checksumPolicy(modelPolicy.getUpdatePolicy()) - .build(); - return policy; + return new org.apache.maven.model.Profile( + SettingsUtilsV4.convertFromSettingsProfile(settingsProfile.getDelegate())); } /** * @param settings could be null * @return a new instance of settings or null if settings was null. */ - public static org.apache.maven.settings.Settings copySettings(org.apache.maven.settings.Settings settings) { + public static Settings copySettings(Settings settings) { if (settings == null) { return null; } - return new org.apache.maven.settings.Settings(settings.getDelegate()); + + Settings clone = new Settings(); + clone.setActiveProfiles(settings.getActiveProfiles()); + clone.setInteractiveMode(settings.isInteractiveMode()); + clone.setLocalRepository(settings.getLocalRepository()); + clone.setMirrors(settings.getMirrors()); + clone.setOffline(settings.isOffline()); + clone.setPluginGroups(settings.getPluginGroups()); + clone.setProfiles(settings.getProfiles()); + clone.setProxies(settings.getProxies()); + clone.setServers(settings.getServers()); + clone.setSourceLevel(settings.getSourceLevel()); + clone.setUsePluginRegistry(settings.isUsePluginRegistry()); + + return clone; } } diff --git a/maven-core/src/main/java/org/apache/maven/settings/SettingsUtilsV4.java b/maven-core/src/main/java/org/apache/maven/settings/SettingsUtilsV4.java new file mode 100644 index 0000000000..d271decb5c --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/settings/SettingsUtilsV4.java @@ -0,0 +1,299 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +package org.apache.maven.settings; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +import org.apache.maven.api.model.ActivationFile; +import org.apache.maven.api.settings.Activation; +import org.apache.maven.api.settings.ActivationOS; +import org.apache.maven.api.settings.ActivationProperty; +import org.apache.maven.api.settings.Profile; +import org.apache.maven.api.settings.Repository; +import org.apache.maven.api.settings.RepositoryPolicy; +import org.apache.maven.api.settings.Settings; +import org.apache.maven.settings.v4.SettingsMerger; + +/** + * Several convenience methods to handle settings + * + * @author Vincent Siveton + */ +public final class SettingsUtilsV4 { + + private SettingsUtilsV4() { + // don't allow construction. + } + + /** + * @param dominant + * @param recessive + */ + public static Settings merge(Settings dominant, Settings recessive) { + return new SettingsMerger().merge(dominant, recessive, true, Collections.emptyMap()); + } + + /** + * @param modelProfile + * @return a profile + */ + public static Profile convertToSettingsProfile(org.apache.maven.api.model.Profile modelProfile) { + Profile.Builder profile = Profile.newBuilder(); + + profile.id(modelProfile.getId()); + + org.apache.maven.api.model.Activation modelActivation = modelProfile.getActivation(); + + if (modelActivation != null) { + Activation.Builder activation = Activation.newBuilder(); + + activation.activeByDefault(modelActivation.isActiveByDefault()); + + activation.jdk(modelActivation.getJdk()); + + org.apache.maven.api.model.ActivationProperty modelProp = modelActivation.getProperty(); + + if (modelProp != null) { + ActivationProperty prop = ActivationProperty.newBuilder() + .name(modelProp.getName()) + .value(modelProp.getValue()) + .build(); + activation.property(prop); + } + + org.apache.maven.api.model.ActivationOS modelOs = modelActivation.getOs(); + + if (modelOs != null) { + ActivationOS os = ActivationOS.newBuilder() + .arch(modelOs.getArch()) + .family(modelOs.getFamily()) + .name(modelOs.getName()) + .version(modelOs.getVersion()) + .build(); + + activation.os(os); + } + + org.apache.maven.api.model.ActivationFile modelFile = modelActivation.getFile(); + + if (modelFile != null) { + org.apache.maven.api.settings.ActivationFile file = + org.apache.maven.api.settings.ActivationFile.newBuilder() + .exists(modelFile.getExists()) + .missing(modelFile.getMissing()) + .build(); + + activation.file(file); + } + + profile.activation(activation.build()); + } + + profile.properties(modelProfile.getProperties().entrySet().stream() + .collect(Collectors.toMap( + e -> e.getKey().toString(), e -> e.getValue().toString()))); + + List repos = modelProfile.getRepositories(); + if (repos != null) { + List repositories = new ArrayList<>(); + for (org.apache.maven.api.model.Repository repo : repos) { + repositories.add(convertToSettingsRepository(repo)); + } + profile.repositories(repositories); + } + + List pluginRepos = modelProfile.getPluginRepositories(); + if (pluginRepos != null) { + List repositories = new ArrayList<>(); + for (org.apache.maven.api.model.Repository pluginRepo : pluginRepos) { + repositories.add(convertToSettingsRepository(pluginRepo)); + } + profile.pluginRepositories(repositories); + } + + return profile.build(); + } + + /** + * @param settingsProfile + * @return a profile + */ + public static org.apache.maven.api.model.Profile convertFromSettingsProfile(Profile settingsProfile) { + org.apache.maven.api.model.Profile.Builder profile = org.apache.maven.api.model.Profile.newBuilder(); + + profile.id(settingsProfile.getId()); + + Activation settingsActivation = settingsProfile.getActivation(); + + if (settingsActivation != null) { + org.apache.maven.api.model.Activation.Builder activation = + org.apache.maven.api.model.Activation.newBuilder(); + + activation.activeByDefault(settingsActivation.isActiveByDefault()); + + activation.jdk(settingsActivation.getJdk()); + + ActivationProperty settingsProp = settingsActivation.getProperty(); + if (settingsProp != null) { + activation.property(org.apache.maven.api.model.ActivationProperty.newBuilder() + .name(settingsProp.getName()) + .value(settingsProp.getValue()) + .build()); + } + + ActivationOS settingsOs = settingsActivation.getOs(); + if (settingsOs != null) { + activation.os(org.apache.maven.api.model.ActivationOS.newBuilder() + .arch(settingsOs.getArch()) + .family(settingsOs.getFamily()) + .name(settingsOs.getName()) + .version(settingsOs.getVersion()) + .build()); + } + + org.apache.maven.api.settings.ActivationFile settingsFile = settingsActivation.getFile(); + if (settingsFile != null) { + activation.file(ActivationFile.newBuilder() + .exists(settingsFile.getExists()) + .missing(settingsFile.getMissing()) + .build()); + } + + profile.activation(activation.build()); + } + + profile.properties(settingsProfile.getProperties()); + + List repos = settingsProfile.getRepositories(); + if (repos != null) { + profile.repositories(repos.stream() + .map(SettingsUtilsV4::convertFromSettingsRepository) + .collect(Collectors.toList())); + } + + List pluginRepos = settingsProfile.getPluginRepositories(); + if (pluginRepos != null) { + profile.pluginRepositories(pluginRepos.stream() + .map(SettingsUtilsV4::convertFromSettingsRepository) + .collect(Collectors.toList())); + } + + org.apache.maven.api.model.Profile value = profile.build(); + value.setSource("settings.xml"); + return value; + } + + /** + * @param settingsRepo + * @return a repository + */ + private static org.apache.maven.api.model.Repository convertFromSettingsRepository(Repository settingsRepo) { + org.apache.maven.api.model.Repository.Builder repo = org.apache.maven.api.model.Repository.newBuilder(); + + repo.id(settingsRepo.getId()); + repo.layout(settingsRepo.getLayout()); + repo.name(settingsRepo.getName()); + repo.url(settingsRepo.getUrl()); + + if (settingsRepo.getSnapshots() != null) { + repo.snapshots(convertRepositoryPolicy(settingsRepo.getSnapshots())); + } + if (settingsRepo.getReleases() != null) { + repo.releases(convertRepositoryPolicy(settingsRepo.getReleases())); + } + + return repo.build(); + } + + /** + * @param settingsPolicy + * @return a RepositoryPolicy + */ + private static org.apache.maven.api.model.RepositoryPolicy convertRepositoryPolicy( + RepositoryPolicy settingsPolicy) { + org.apache.maven.api.model.RepositoryPolicy policy = org.apache.maven.api.model.RepositoryPolicy.newBuilder() + .enabled(Boolean.toString(settingsPolicy.isEnabled())) + .updatePolicy(settingsPolicy.getUpdatePolicy()) + .checksumPolicy(settingsPolicy.getChecksumPolicy()) + .build(); + return policy; + } + + /** + * @param modelRepo + * @return a repository + */ + private static Repository convertToSettingsRepository(org.apache.maven.api.model.Repository modelRepo) { + Repository repo = Repository.newBuilder() + .id(modelRepo.getId()) + .layout(modelRepo.getLayout()) + .name(modelRepo.getName()) + .url(modelRepo.getUrl()) + .snapshots(modelRepo.getSnapshots() != null ? convertRepositoryPolicy(modelRepo.getSnapshots()) : null) + .releases(modelRepo.getReleases() != null ? convertRepositoryPolicy(modelRepo.getReleases()) : null) + .build(); + + return repo; + } + + /** + * @param modelPolicy + * @return a RepositoryPolicy + */ + private static RepositoryPolicy convertRepositoryPolicy(org.apache.maven.api.model.RepositoryPolicy modelPolicy) { + RepositoryPolicy policy = RepositoryPolicy.newBuilder() + .enabled(modelPolicy.isEnabled()) + .updatePolicy(modelPolicy.getUpdatePolicy()) + .checksumPolicy(modelPolicy.getUpdatePolicy()) + .build(); + return policy; + } + + /** + * @param settings could be null + * @return a new instance of settings or null if settings was null. + */ + public static org.apache.maven.settings.Settings copySettings(org.apache.maven.settings.Settings settings) { + if (settings == null) { + return null; + } + return new org.apache.maven.settings.Settings(settings.getDelegate()); + } +} diff --git a/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchainsBuilder.java b/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchainsBuilder.java index 5a254a1bc8..e4e1f75999 100644 --- a/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchainsBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchainsBuilder.java @@ -22,7 +22,7 @@ import java.io.File; import java.io.Reader; import javax.inject.Named; import javax.inject.Singleton; -import org.apache.maven.api.toolchain.PersistedToolchains; +import org.apache.maven.toolchain.model.PersistedToolchains; import org.apache.maven.toolchain.v4.MavenToolchainsXpp3Reader; import org.codehaus.plexus.util.ReaderFactory; import org.slf4j.Logger; @@ -43,7 +43,7 @@ public class DefaultToolchainsBuilder implements ToolchainsBuilder { if (userToolchainsFile != null && userToolchainsFile.isFile()) { try (Reader in = ReaderFactory.newXmlReader(userToolchainsFile)) { - toolchains = new MavenToolchainsXpp3Reader().read(in); + toolchains = new PersistedToolchains(new MavenToolchainsXpp3Reader().read(in)); } catch (Exception e) { throw new MisconfiguredToolchainException( "Cannot read toolchains file at " + userToolchainsFile.getAbsolutePath(), e); diff --git a/maven-core/src/main/java/org/apache/maven/toolchain/ToolchainsBuilder.java b/maven-core/src/main/java/org/apache/maven/toolchain/ToolchainsBuilder.java index 37fadd9c7c..9f416ce450 100644 --- a/maven-core/src/main/java/org/apache/maven/toolchain/ToolchainsBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/toolchain/ToolchainsBuilder.java @@ -19,7 +19,7 @@ package org.apache.maven.toolchain; import java.io.File; -import org.apache.maven.api.toolchain.PersistedToolchains; +import org.apache.maven.toolchain.model.PersistedToolchains; /** * Builds the toolchains model from a previously configured filesystem path to the toolchains file. diff --git a/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java b/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java index 8af4ff2a44..a10520a823 100644 --- a/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java +++ b/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java @@ -97,7 +97,7 @@ public class PomConstructionWithSettingsTest { ProjectBuildingRequest config = new DefaultProjectBuildingRequest(); for (org.apache.maven.settings.Profile rawProfile : settings.getProfiles()) { - Profile profile = SettingsUtils.convertFromSettingsProfile(rawProfile.getDelegate()); + Profile profile = SettingsUtils.convertFromSettingsProfile(rawProfile); config.addProfile(profile); } diff --git a/maven-core/src/test/java/org/apache/maven/settings/SettingsUtilsTest.java b/maven-core/src/test/java/org/apache/maven/settings/SettingsUtilsTest.java index 9e0d2d9d15..b260c85800 100644 --- a/maven-core/src/test/java/org/apache/maven/settings/SettingsUtilsTest.java +++ b/maven-core/src/test/java/org/apache/maven/settings/SettingsUtilsTest.java @@ -48,7 +48,7 @@ public class SettingsUtilsTest { .pluginGroups(Arrays.asList("org.codehaus.plexus")) .build(); - Settings merged = SettingsUtils.merge(dominant, recessive, Settings.GLOBAL_LEVEL); + Settings merged = SettingsUtilsV4.merge(dominant, recessive); List pluginGroups = merged.getPluginGroups(); @@ -116,7 +116,7 @@ public class SettingsUtilsTest { .pluginRepositories(pluginRepos) .build(); - Profile clone = SettingsUtils.convertToSettingsProfile(SettingsUtils.convertFromSettingsProfile(p)); + Profile clone = SettingsUtilsV4.convertToSettingsProfile(SettingsUtilsV4.convertFromSettingsProfile(p)); assertEquals(p.getId(), clone.getId()); assertEquals(p.getActivation().getJdk(), clone.getActivation().getJdk()); diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/configuration/SettingsXmlConfigurationProcessor.java b/maven-embedder/src/main/java/org/apache/maven/cli/configuration/SettingsXmlConfigurationProcessor.java index 2d03404ab8..c5c47d1315 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/configuration/SettingsXmlConfigurationProcessor.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/configuration/SettingsXmlConfigurationProcessor.java @@ -202,7 +202,7 @@ public class SettingsXmlConfigurationProcessor implements ConfigurationProcessor request.setActiveProfiles(settings.getActiveProfiles()); for (Profile rawProfile : settings.getProfiles()) { - request.addProfile(SettingsUtils.convertFromSettingsProfile(rawProfile.getDelegate())); + request.addProfile(SettingsUtils.convertFromSettingsProfile(rawProfile)); if (settings.getActiveProfiles().contains(rawProfile.getId())) { List remoteRepositories = rawProfile.getRepositories(); diff --git a/maven-plugin-api/pom.xml b/maven-plugin-api/pom.xml index 296ba3b4b8..3735068b86 100644 --- a/maven-plugin-api/pom.xml +++ b/maven-plugin-api/pom.xml @@ -112,6 +112,10 @@ under the License. + + com.github.siom79.japicmp + japicmp-maven-plugin + diff --git a/maven-settings-builder/src/main/java/org/apache/maven/settings/merge/MavenSettingsMerger.java b/maven-settings-builder/src/main/java/org/apache/maven/settings/merge/MavenSettingsMerger.java index 38efd4807a..0e6aaf7a63 100644 --- a/maven-settings-builder/src/main/java/org/apache/maven/settings/merge/MavenSettingsMerger.java +++ b/maven-settings-builder/src/main/java/org/apache/maven/settings/merge/MavenSettingsMerger.java @@ -33,7 +33,9 @@ import org.codehaus.plexus.util.StringUtils; /** * @author Vincent Siveton * @author Benjamin Bentmann + * @deprecated use {@link org.apache.maven.settings.v4.SettingsMerger} */ +@Deprecated public class MavenSettingsMerger { /** diff --git a/pom.xml b/pom.xml index a82b8548b7..990b12c1b1 100644 --- a/pom.xml +++ b/pom.xml @@ -560,6 +560,55 @@ under the License. buildnumber-maven-plugin 1.4 + + + com.github.siom79.japicmp + japicmp-maven-plugin + 0.16.0 + + + + cmp + + verify + + + + 3.8.6 + true + true + + + org.apache.maven.artifact + org.apache.maven.classrealm + org.apache.maven.cli + org.apache.maven.configuration + org.apache.maven.exception + org.apache.maven.execution + org.apache.maven.execution.scope + org.apache.maven.feature + org.apache.maven.graph + org.apache.maven.lifecycle + org.apache.maven.model + org.apache.maven.monitor + org.apache.maven.plugin + org.apache.maven.profiles + org.apache.maven.project + org.apache.maven.reporting + org.apache.maven.repository + org.apache.maven.rtinfo + org.apache.maven.rtinfo.internal + org.apache.maven.settings + org.apache.maven.toolchain + org.apache.maven.usability + + true + + + + + +