Skip to content

Commit

Permalink
WIP: Add functionality marge for build extensions section (#36)
Browse files Browse the repository at this point in the history
* Add functionality marge for build extensions section

* Add functionality marge for build extensions section
  • Loading branch information
Fameing authored Apr 10, 2024
1 parent 6ebac39 commit cb4810a
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 6 deletions.
9 changes: 9 additions & 0 deletions examples/mixin-maven-plugin/mixin-example/mixin1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
<message>HELLO DEFAULT MESSAGE FROM MIXIN</message>
</properties>
<build>
<extensions>
<extension>
<groupId>org.apache.maven.extensions</groupId>
<artifactId>maven-build-cache-extension</artifactId>
<version>1.0.1</version>
</extension>
</extensions>


<pluginManagement>
<plugins>
<!-- This is a simple execution of antrun during initialize phase to echo a message from a property.
Expand Down
2 changes: 1 addition & 1 deletion examples/mixin-maven-plugin/mixin-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<name>${project.groupId}:${project.artifactId}</name>

<properties>
<version.com.playtika.maven.plugins>1.0.1</version.com.playtika.maven.plugins>
<version.com.playtika.maven.plugins>1.0.0-SNAPSHOT</version.com.playtika.maven.plugins>
</properties>
<modules>
<module>mixin1</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class Mixin {
private Boolean mergeScm;
private Boolean mergeRepositories;
private Boolean mergePluginRepositories;
private Boolean mergeBuildExtensions;
private Boolean recurse;
private Boolean activateProfiles;
private Mixins mixins;
Expand Down Expand Up @@ -113,6 +114,10 @@ public boolean isMergePluginRepositories() {
return mergePluginRepositories != null ? mergePluginRepositories : mixins.isMergePluginRepositories();
}

public boolean isMergeBuildExtensions() {
return mergeBuildExtensions != null ? mergeBuildExtensions : mixins.isMergeBuildExtensions();
}

public void setMergePluginRepositories(Boolean mergePluginRepositories) {
this.mergePluginRepositories = mergePluginRepositories;
}
Expand Down Expand Up @@ -168,11 +173,13 @@ public void merge(Model mixinModel, MavenProject mavenProject, MavenSession mave
if (isMergePluginRepositories()) {
mixinModelMerger.mergePluginRepositories(mavenProject.getModel(), mixinModel);
}
if (isMergeBuildExtensions()) {
mixinModelMerger.mergeBuildExtensions(mavenProject.getModel(), mixinModel);
}
}

@Override
public String toString() {
return getKey();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.playtika.maven.plugins;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.maven.model.Build;
import org.apache.maven.model.DistributionManagement;
import org.apache.maven.model.Model;
Expand All @@ -13,10 +17,6 @@
import org.apache.maven.model.merge.MavenModelMerger;
import org.codehaus.plexus.component.annotations.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* MixinModelMerger
* Enables pluginManagement and properties import from different pom files. Uses protected methods of MavenModelMerger, and therefore inherits from it
Expand Down Expand Up @@ -187,4 +187,10 @@ public void mergePluginRepositories(Model targetModel, Model sourceModel) {
super.mergeModelBase_PluginRepositories(targetModel, sourceModel, false, context);
}

public void mergeBuildExtensions(Model targetModel, Model sourceModel) {
Map<Object, Object> context = new HashMap<Object, Object>();
Build targetBuild = targetModel.getBuild();
Build sourceBuild = sourceModel.getBuild();
super.mergeBuild_Extensions(targetBuild, sourceBuild, false, context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class Mixins {
private List<Mixin> mixins = new ArrayList<Mixin>();
private boolean mergePlugins = true;
private boolean mergePluginManagement = true;
private boolean mergeBuildExtensions = true;
private boolean mergeProperties = true;
private boolean mergeReporting = true;
private boolean mergeDistributionManagement = true;
Expand Down Expand Up @@ -111,6 +112,10 @@ public boolean isMergePluginRepositories() {
return mergePluginRepositories;
}

public boolean isMergeBuildExtensions() {
return mergeBuildExtensions;
}

public void setMergePluginRepositories(boolean mergePluginRepositories) {
this.mergePluginRepositories = mergePluginRepositories;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.playtika.maven.plugins;

import java.util.List;

import org.apache.maven.model.Build;
import org.apache.maven.model.Extension;
import org.apache.maven.model.Model;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;


public class MixinModelMergeBuildExtensions {

private MixinModelMerger merger;
private Model buildExtensions, emptyBuildExtensions;

@BeforeEach
public void setup() {
merger = new MixinModelMerger();
buildExtensions = new Model();
buildExtensions.setBuild(new Build());
Extension extension = new Extension();
extension.setGroupId("com.test");
extension.setArtifactId("test-magre-extension");
extension.setVersion("1.0.0");
buildExtensions.getBuild().getExtensions().add(extension);

emptyBuildExtensions = new Model();
emptyBuildExtensions.setBuild(new Build());
}

@Test
public void testEmptyTarget() {
List<Extension> origExtensions = buildExtensions.getBuild().getExtensions();
assertNotNull(origExtensions);
assertEquals(origExtensions.size(), 1);
merger.mergeBuildExtensions(emptyBuildExtensions, buildExtensions);
assertEquals(origExtensions, buildExtensions.getBuild().getExtensions());
}

@Test
public void testEmptySrc() {
merger.mergeScm(buildExtensions, emptyBuildExtensions);
assertNotNull(emptyBuildExtensions.getBuild().getExtensions());
assertEquals(emptyBuildExtensions.getBuild().getExtensions().size(), 0);

assertNotNull(buildExtensions.getBuild().getExtensions());
assertEquals(buildExtensions.getBuild().getExtensions().size(), 1);
}

@Test
public void testMageFromSrc() {
emptyBuildExtensions = new Model();
emptyBuildExtensions.setBuild(new Build());
Extension extension = new Extension();
extension.setGroupId("com.test2");
extension.setArtifactId("test-magre-extension-v2");
extension.setVersion("2.0.0");
emptyBuildExtensions.getBuild().getExtensions().add(extension);

assertNotNull(buildExtensions.getBuild().getExtensions());
assertEquals(1, buildExtensions.getBuild().getExtensions().size());

assertNotNull(emptyBuildExtensions.getBuild().getExtensions());
assertEquals(1, emptyBuildExtensions.getBuild().getExtensions().size());

merger.mergeBuildExtensions(buildExtensions, emptyBuildExtensions);

assertNotNull(buildExtensions.getBuild().getExtensions());
assertEquals(2, buildExtensions.getBuild().getExtensions().size());
}
}

0 comments on commit cb4810a

Please sign in to comment.