Skip to content

Commit

Permalink
[MNG-7598] Fix compatibility issues with toolchains and settings (apa…
Browse files Browse the repository at this point in the history
…che#971)

* Split the header on two lines
* Properly delegates equals/hashCode to the v4 models
* Introduce object tracking in settings / toolchains
* Get back to a single template for v3 models
* Switch settings / toolchains mergers to deep merge
* Fix binary compatibility with 3.x
  • Loading branch information
gnodet authored Jan 27, 2023
1 parent 74cf7ea commit f153ac1
Show file tree
Hide file tree
Showing 46 changed files with 823 additions and 714 deletions.
9 changes: 8 additions & 1 deletion api/maven-api-model/src/main/mdo/maven.mdo
Original file line number Diff line number Diff line change
Expand Up @@ -2527,6 2527,13 @@
return groupId ":" artifactId;
}
]]>
</code>
</codeSegment>
<codeSegment>
<version>4.2.0 </version>
<code>
<![CDATA[
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
Expand Down Expand Up @@ -3240,7 3247,7 @@
</fields>
<codeSegments>
<codeSegment>
<version>4.0.0 </version>
<version>4.2.0 </version>
<code>
<![CDATA[
/**
Expand Down
6 changes: 4 additions & 2 deletions api/maven-api-settings/src/main/mdo/settings.mdo
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 825,8 @@
<field>
<name>id</name>
<version>1.0.0 </version>
<required>true</required>
<identifier>true</identifier>
<description>
<![CDATA[
A unique identifier for a repository.
Expand Down Expand Up @@ -865,7 867,7 @@
</fields>
<codeSegments>
<codeSegment>
<version>1.0.0 </version>
<version>1.0.0/1.1.0</version>
<code>
<![CDATA[
/**
Expand Down Expand Up @@ -920,7 922,7 @@
<!-- prevent Modello generation of an incorrect equals method. Could be avoided by using <identity/> tags to mark ID as the only identity field -->
<codeSegments>
<codeSegment>
<version>1.0.0 </version>
<version>1.0.0/1.1.0</version>
<code>
<![CDATA[
/**
Expand Down
2 changes: 1 addition & 1 deletion api/maven-api-toolchain/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 50,7 @@ under the License.
<goal>velocity</goal>
</goals>
<configuration>
<version>1.1.0</version>
<version>1.2.0</version>
<velocityBasedir>${project.basedir}/../../src/mdo</velocityBasedir>
<models>
<model>src/main/mdo/toolchains.mdo</model>
Expand Down
2 changes: 1 addition & 1 deletion api/maven-api-toolchain/src/main/mdo/toolchains.mdo
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 176,7 @@
</fields>
<codeSegments>
<codeSegment>
<version>1.1.0 </version>
<version>1.2.0 </version>
<comment>Generated hashCode() and equals() based on identifier also calls its super, which breaks comparison</comment>
<code>
<![CDATA[
Expand Down
24 changes: 24 additions & 0 deletions maven-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 279,30 @@ under the License.
<artifactId>japicmp-maven-plugin</artifactId>
<configuration>
<parameter>
<includes>
<include>org.apache.maven.artifact</include>
<include>org.apache.maven.classrealm</include>
<include>org.apache.maven.cli</include>
<include>org.apache.maven.configuration</include>
<include>org.apache.maven.exception</include>
<include>org.apache.maven.execution</include>
<include>org.apache.maven.execution.scope</include>
<include>org.apache.maven.feature</include>
<include>org.apache.maven.graph</include>
<include>org.apache.maven.lifecycle</include>
<include>org.apache.maven.model</include>
<include>org.apache.maven.monitor</include>
<include>org.apache.maven.plugin</include>
<include>org.apache.maven.profiles</include>
<include>org.apache.maven.project</include>
<include>org.apache.maven.reporting</include>
<include>org.apache.maven.repository</include>
<include>org.apache.maven.rtinfo</include>
<include>org.apache.maven.rtinfo.internal</include>
<include>org.apache.maven.settings</include>
<include>org.apache.maven.toolchain</include>
<include>org.apache.maven.usability</include>
</includes>
<!-- allowed non-binary backwards compatible changes -->
<excludes>
<!-- START default constructor on Plexus/JSR 330 components -->
Expand Down
62 changes: 62 additions & 0 deletions maven-model-builder/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 108,68 @@ under the License.
<groupId>org.eclipse.sisu</groupId>
<artifactId>sisu-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.github.siom79.japicmp</groupId>
<artifactId>japicmp-maven-plugin</artifactId>
<configuration>
<oldVersion>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${maven.baseline}</version>
</dependency>
</oldVersion>
<parameter>
<excludes>
<exclude>org.apache.maven.model.building.DefaultModelBuilder#DefaultModelBuilder():CONSTRUCTOR_REMOVED</exclude>
<exclude>org.apache.maven.model.building.DefaultModelProcessor#setModelLocator(org.apache.maven.model.locator.ModelLocator):METHOD_REMOVED</exclude>
<exclude>org.apache.maven.model.building.DefaultModelProcessor#setModelReader(org.apache.maven.model.io.ModelReader):METHOD_REMOVED</exclude>
<exclude>org.apache.maven.model.building.DefaultModelProcessor#DefaultModelProcessor():CONSTRUCTOR_REMOVED</exclude>
<exclude>org.apache.maven.model.building.ModelCache#get(org.apache.maven.building.Source,java.lang.String):METHOD_NEW_DEFAULT</exclude>
<exclude>org.apache.maven.model.building.ModelCache#get(org.apache.maven.building.Source,org.apache.maven.model.building.ModelCacheTag):METHOD_NEW_DEFAULT</exclude>
<exclude>org.apache.maven.model.building.ModelCache#get(java.lang.String,java.lang.String,java.lang.String,org.apache.maven.model.building.ModelCacheTag):METHOD_NEW_DEFAULT</exclude>
<exclude>org.apache.maven.model.building.ModelCache#put(org.apache.maven.building.Source,java.lang.String,java.lang.Object):METHOD_NEW_DEFAULT</exclude>
<exclude>org.apache.maven.model.building.ModelCache#put(org.apache.maven.building.Source,org.apache.maven.model.building.ModelCacheTag,java.lang.Object):METHOD_NEW_DEFAULT</exclude>
<exclude>org.apache.maven.model.building.ModelCache#put(java.lang.String,java.lang.String,java.lang.String,org.apache.maven.model.building.ModelCacheTag,java.lang.Object):METHOD_NEW_DEFAULT</exclude>
<exclude>org.apache.maven.model.composition.DependencyManagementImporter#importManagement(org.apache.maven.model.Model,java.util.List,org.apache.maven.model.building.ModelBuildingRequest,org.apache.maven.model.building.ModelProblemCollector):METHOD_REMOVED</exclude>
<exclude>org.apache.maven.model.composition.DefaultDependencyManagementImporter#importManagement(org.apache.maven.model.Model,java.util.List,org.apache.maven.model.building.ModelBuildingRequest,org.apache.maven.model.building.ModelProblemCollector):METHOD_REMOVED</exclude>
<exclude>org.apache.maven.model.inheritance.DefaultInheritanceAssembler</exclude>
<exclude>org.apache.maven.model.inheritance.InheritanceAssembler#assembleModelInheritance(org.apache.maven.model.Model,org.apache.maven.model.Model,org.apache.maven.model.building.ModelBuildingRequest,org.apache.maven.model.building.ModelProblemCollector):METHOD_REMOVED</exclude>
<exclude>org.apache.maven.model.interpolation.AbstractStringBasedModelInterpolator</exclude>
<exclude>org.apache.maven.model.interpolation.StringSearchModelInterpolator</exclude>
<exclude>org.apache.maven.model.interpolation.StringVisitorModelInterpolator</exclude>
<exclude>org.apache.maven.model.io.DefaultModelReader#DefaultModelReader():CONSTRUCTOR_REMOVED</exclude>
<exclude>org.apache.maven.model.management.DefaultDependencyManagementInjector$ManagementModelMerger</exclude>
<exclude>org.apache.maven.model.management.DefaultPluginManagementInjector$ManagementModelMerger</exclude>
<exclude>org.apache.maven.model.merge.MavenModelMerger</exclude>
<exclude>org.apache.maven.model.normalization.DefaultModelNormalizer$DuplicateMerger#mergePlugin(org.apache.maven.model.Plugin,org.apache.maven.model.Plugin):METHOD_REMOVED</exclude>
<exclude>org.apache.maven.model.normalization.DefaultModelNormalizer$DuplicateMerger:METHOD_REMOVED_IN_SUPERCLASS</exclude>
<exclude>org.apache.maven.model.path.DefaultModelPathTranslator#setPathTranslator(org.apache.maven.model.path.PathTranslator):METHOD_REMOVED</exclude>
<exclude>org.apache.maven.model.path.DefaultModelPathTranslator#DefaultModelPathTranslator():CONSTRUCTOR_REMOVED</exclude>
<exclude>org.apache.maven.model.path.DefaultModelUrlNormalizer#setUrlNormalizer(org.apache.maven.model.path.UrlNormalizer):METHOD_REMOVED</exclude>
<exclude>org.apache.maven.model.path.DefaultModelUrlNormalizer#DefaultModelUrlNormalizer():CONSTRUCTOR_REMOVED</exclude>
<exclude>org.apache.maven.model.path.ProfileActivationFilePathInterpolator#setPathTranslator(org.apache.maven.model.path.PathTranslator):METHOD_REMOVED</exclude>
<exclude>org.apache.maven.model.path.ProfileActivationFilePathInterpolator#ProfileActivationFilePathInterpolator():CONSTRUCTOR_REMOVED</exclude>
<exclude>org.apache.maven.model.profile.activation.FileProfileActivator#setProfileActivationFilePathInterpolator(org.apache.maven.model.path.ProfileActivationFilePathInterpolator):METHOD_REMOVED</exclude>
<exclude>org.apache.maven.model.profile.activation.FileProfileActivator#FileProfileActivator():CONSTRUCTOR_REMOVED</exclude>
<exclude>org.apache.maven.model.profile.DefaultProfileInjector</exclude>
<exclude>org.apache.maven.model.resolution.InvalidRepositoryException#getRepository():METHOD_RETURN_TYPE_CHANGED</exclude>
<exclude>org.apache.maven.model.resolution.InvalidRepositoryException#InvalidRepositoryException(java.lang.String,org.apache.maven.model.Repository,java.lang.Throwable):CONSTRUCTOR_REMOVED</exclude>
<exclude>org.apache.maven.model.resolution.InvalidRepositoryException#InvalidRepositoryException(java.lang.String,org.apache.maven.model.Repository):CONSTRUCTOR_REMOVED</exclude>
<exclude>org.apache.maven.model.resolution.ModelResolver#addRepository(org.apache.maven.api.model.Repository):METHOD_NEW_DEFAULT</exclude>
<exclude>org.apache.maven.model.resolution.ModelResolver#addRepository(org.apache.maven.api.model.Repository,boolean):METHOD_NEW_DEFAULT</exclude>
<exclude>org.apache.maven.model.resolution.ModelResolver#resolveModel(org.apache.maven.api.model.Parent,java.util.concurrent.atomic.AtomicReference):METHOD_NEW_DEFAULT</exclude>
<exclude>org.apache.maven.model.resolution.ModelResolver#resolveModel(org.apache.maven.api.model.Dependency,java.util.concurrent.atomic.AtomicReference):METHOD_NEW_DEFAULT</exclude>
<exclude>org.apache.maven.model.superpom.DefaultSuperPomProvider#getSuperModel(java.lang.String):METHOD_RETURN_TYPE_CHANGED</exclude>
<exclude>org.apache.maven.model.superpom.DefaultSuperPomProvider#setModelProcessor(org.apache.maven.model.building.ModelProcessor):METHOD_REMOVED</exclude>
<exclude>org.apache.maven.model.superpom.DefaultSuperPomProvider#DefaultSuperPomProvider():CONSTRUCTOR_REMOVED</exclude>
<exclude>org.apache.maven.model.superpom.SuperPomProvider#getSuperModel(java.lang.String):METHOD_RETURN_TYPE_CHANGED</exclude>
<exclude>org.apache.maven.model.validation.DefaultModelValidator#validateDependencyVersion(org.apache.maven.model.building.ModelProblemCollector,org.apache.maven.model.Dependency,java.lang.String):METHOD_REMOVED</exclude>
<exclude>org.apache.maven.model.validation.ModelValidator#validateFileModel(org.apache.maven.model.Model,org.apache.maven.model.building.ModelBuildingRequest,org.apache.maven.model.building.ModelProblemCollector):METHOD_NEW_DEFAULT</exclude>
</excludes>
</parameter>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 20,7 @@

import java.io.File;

import org.apache.maven.api.model.Model;
import org.apache.maven.model.Model;
import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.model.building.ModelProblemCollector;

Expand All @@ -46,8 46,8 @@ public interface ModelInterpolator {
*/
Model interpolateModel(Model model, File projectDir, ModelBuildingRequest request, ModelProblemCollector problems);

org.apache.maven.model.Model interpolateModel(
org.apache.maven.model.Model model,
org.apache.maven.api.model.Model interpolateModel(
org.apache.maven.api.model.Model model,
File projectDir,
ModelBuildingRequest request,
ModelProblemCollector problems);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 23,7 @@
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import org.apache.maven.api.model.BuildBase;
Expand Down Expand Up @@ -66,6 67,39 @@ public class MavenModelMerger extends MavenMerger {
*/
public static final String ARTIFACT_ID = "artifact-id";

public MavenModelMerger() {
super(false);
}

/**
* Merges the specified source object into the given target object.
*
* @param target The target object whose existing contents should be merged with the source, must not be
* <code>null</code>.
* @param source The (read-only) source object that should be merged into the target object, may be
* <code>null</code>.
* @param sourceDominant A flag indicating whether either the target object or the source object provides the
* dominant data.
* @param hints A set of key-value pairs that customized merger implementations can use to carry domain-specific
* information along, may be <code>null</code>.
*/
public void merge(
org.apache.maven.model.Model target,
org.apache.maven.model.Model source,
boolean sourceDominant,
Map<?, ?> hints) {
Objects.requireNonNull(target, "target cannot be null");
if (source == null) {
return;
}
target.update(merge(target.getDelegate(), source.getDelegate(), sourceDominant, hints));
}

@Override
public Model merge(Model target, Model source, boolean sourceDominant, Map<?, ?> hints) {
return super.merge(target, source, sourceDominant, hints);
}

@Override
protected Model mergeModel(Model target, Model source, boolean sourceDominant, Map<Object, Object> context) {
context.put(ARTIFACT_ID, target.getArtifactId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 48,18 @@ public class DefaultModelNormalizer implements ModelNormalizer {

private DuplicateMerger merger = new DuplicateMerger();

@Override
public void mergeDuplicates(
org.apache.maven.model.Model model, ModelBuildingRequest request, ModelProblemCollector problems) {
model.update(mergeDuplicates(model.getDelegate(), request, problems));
}

@Override
public void injectDefaultValues(
org.apache.maven.model.Model model, ModelBuildingRequest request, ModelProblemCollector problems) {
model.update(injectDefaultValues(model.getDelegate(), request, problems));
}

@Override
public Model mergeDuplicates(Model model, ModelBuildingRequest request, ModelProblemCollector problems) {
Model.Builder builder = Model.newBuilder(model);
Expand Down Expand Up @@ -127,9 139,7 @@ private Plugin injectPlugin(Plugin p) {

private Dependency injectDependency(Dependency d) {
// we cannot set this directly in the MDO due to the interactions with dependency management
return StringUtils.isEmpty(d.getScope())
? Dependency.newBuilder(d).scope("compile").build()
: d;
return StringUtils.isEmpty(d.getScope()) ? d.withScope("compile") : d;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 18,7 @@
*/
package org.apache.maven.model.normalization;

import org.apache.maven.api.model.Model;
import org.apache.maven.model.Model;
import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.model.building.ModelProblemCollector;

Expand All @@ -37,7 37,7 @@ public interface ModelNormalizer {
* @param request The model building request that holds further settings, must not be {@code null}.
* @param problems The container used to collect problems that were encountered, must not be {@code null}.
*/
Model mergeDuplicates(Model model, ModelBuildingRequest request, ModelProblemCollector problems);
void mergeDuplicates(Model model, ModelBuildingRequest request, ModelProblemCollector problems);

/**
* Sets default values in the specified model that for technical reasons cannot be set directly in the Modello
Expand All @@ -47,5 47,11 @@ public interface ModelNormalizer {
* @param request The model building request that holds further settings, must not be {@code null}.
* @param problems The container used to collect problems that were encountered, must not be {@code null}.
*/
Model injectDefaultValues(Model model, ModelBuildingRequest request, ModelProblemCollector problems);
void injectDefaultValues(Model model, ModelBuildingRequest request, ModelProblemCollector problems);

org.apache.maven.api.model.Model mergeDuplicates(
org.apache.maven.api.model.Model model, ModelBuildingRequest request, ModelProblemCollector problems);

org.apache.maven.api.model.Model injectDefaultValues(
org.apache.maven.api.model.Model model, ModelBuildingRequest request, ModelProblemCollector problems);
}
Loading

0 comments on commit f153ac1

Please sign in to comment.