Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<feat> add versionRange for adaptor; support to customize adapter-mapping; support to install a few adapter #211

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@


<dependencies>

<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-util</artifactId>
<version>1.9.18</version>
</dependency>
Comment on lines +20 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Update maven-resolver-util to latest version 2.0.4

The current version 1.9.18 is outdated. Maven Central shows version 2.0.4 is available. Since this project uses modern Maven dependencies (maven-core 3.9.6), it's recommended to use the latest version for better compatibility and security.

  • Update maven-resolver-util version from 1.9.18 to 2.0.4 in koupleless-base-build-plugin/pom.xml
🔗 Analysis chain

Verify maven-resolver-util version selection

The addition of this dependency aligns well with the PR objective of adding version range support. Let's verify the version choice.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check latest version and compatibility of maven-resolver-util

# Check latest version on Maven Central
curl -s "https://search.maven.org/solrsearch/select?q=g:org.apache.maven.resolver+AND+a:maven-resolver-util&rows=1&wt=json" | jq -r '.response.docs[0].latestVersion'

# Check compatibility with existing Maven dependencies
rg -A 1 "maven-core|maven-aether-provider" pom.xml

Length of output: 426


<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.resolution.ArtifactRequest;
import org.eclipse.aether.resolution.ArtifactResult;
import org.eclipse.aether.util.version.GenericVersionScheme;
import org.eclipse.aether.version.InvalidVersionSpecificationException;

import java.io.File;
import java.io.InputStream;
Expand All @@ -78,28 +80,30 @@
@Mojo(name = "add-patch", defaultPhase = LifecyclePhase.PROCESS_CLASSES)
public class KouplelessBaseBuildPrePackageMojo extends AbstractMojo {

String MAPPING_FILE = "adapter-mapping.yaml";
String MAPPING_FILE = "adapter-mapping.yaml";

@Parameter(defaultValue = "${project.build.directory}", readonly = true)
File outputDirectory;
File outputDirectory;

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

@Parameter(defaultValue = "${session}", required = true, readonly = true)
MavenSession session;
MavenSession session;

@Component
RepositorySystem repositorySystem;
RepositorySystem repositorySystem;

private ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory());
private ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory());

KouplelessAdapterConfig kouplelessAdapterConfig;
KouplelessAdapterConfig kouplelessAdapterConfig;

AdapterCopyService adapterCopyService = new AdapterCopyService();
AdapterCopyService adapterCopyService = new AdapterCopyService();

String defaultGroupId = "";
String defaultVersion = "";
String defaultGroupId = "";
String defaultVersion = "";

private GenericVersionScheme versionScheme = new GenericVersionScheme();

void initKouplelessAdapterConfig() throws Exception {
if (kouplelessAdapterConfig == null) {
Expand Down Expand Up @@ -149,22 +153,55 @@ List<Dependency> getDependenciesToAdd() throws Exception {
for (org.apache.maven.artifact.Artifact artifact : resolvedArtifacts) {
for (MavenDependencyAdapterMapping adapterMapping : adapterMappings) {
MavenDependencyMatcher matcher = adapterMapping.getMatcher();
if (matcher != null && matcher.getRegexp() != null) {
String regexp = matcher.getRegexp();
String dependencyId = getArtifactFullId(artifact);
if (Pattern.compile(regexp).matcher(dependencyId).matches()) {
adapterDependencies.add(adapterMapping.getAdapter());
getLog().info(String.format("koupleless adapter matched %s with %s", regexp,
artifact));
break;
}
if (matches(matcher, artifact)) {
adapterDependencies.add(adapterMapping.getAdapter());
getLog().info(
String.format("koupleless adapter matched %s with %s", matcher, artifact));
}
}
}

return adapterDependencies;
}

boolean matches(MavenDependencyMatcher matcher,
org.apache.maven.artifact.Artifact artifact) throws InvalidVersionSpecificationException {
if (null == matcher) {
return false;
}

// match with regexp
if (regexpMatches(matcher, artifact)) {
return true;
}

// match with versionRange
return versionRangeMatches(matcher, artifact);
}
gaosaroma marked this conversation as resolved.
Show resolved Hide resolved

private boolean regexpMatches(MavenDependencyMatcher matcher,
org.apache.maven.artifact.Artifact artifact) {
if (null == matcher || null == matcher.getRegexp()) {
return false;
}

String regexp = matcher.getRegexp();
String dependencyId = getArtifactFullId(artifact);
return Pattern.compile(regexp).matcher(dependencyId).matches();
}

private boolean versionRangeMatches(MavenDependencyMatcher matcher,
org.apache.maven.artifact.Artifact artifact) throws InvalidVersionSpecificationException {
if (null == matcher || null == matcher.getGenericVersionRange()) {
return false;
}

return StringUtils.equals(matcher.getGroupId(), artifact.getGroupId())
&& StringUtils.equals(matcher.getArtifactId(), artifact.getArtifactId())
&& matcher.getGenericVersionRange()
.containsVersion(versionScheme.parseVersion(artifact.getVersion()));
}

void addDependenciesDynamically() throws Exception {
if (kouplelessAdapterConfig == null) {
getLog().info("kouplelessAdapterConfig is null, skip adding dependencies.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@
*/
package com.alipay.sofa.koupleless.base.build.plugin.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.aether.util.version.GenericVersionScheme;
import org.eclipse.aether.version.InvalidVersionSpecificationException;
import org.eclipse.aether.version.VersionRange;

/**
* <p>MavenDependencyMatcher class.</p>
Expand All @@ -29,12 +33,63 @@
* @version 1.0.0
*/
@NoArgsConstructor
@AllArgsConstructor
@Data
@Builder
public class MavenDependencyMatcher {
/**
* 用正则表达式匹配用户的依赖。
*/
private String regexp;
@Getter
@Setter
private String regexp;

/**
* 依赖的groupId,如:org.springframework.boot
*/
@Getter
@Setter
private String groupId;

/**
* 依赖的artifactId,如:spring-boot
*/
@Getter
@Setter
private String artifactId;

/**
* 适配的版本范围,比如:
* [1.0,2.0) 表示从 1.0(包含)到 2.0(不包含)的版本。
* [1.0,2.0] 表示从 1.0(包含)到 2.0(包含)的版本。
* (,1.0] 表示小于或等于 1.0 的版本。
* [2.0,) 表示大于或等于 2.0 的版本。
*/
@Getter
private String versionRange;

@Getter
private VersionRange genericVersionRange;

private final GenericVersionScheme versionScheme = new GenericVersionScheme();

@Builder
public MavenDependencyMatcher(String regexp, String groupId, String artifactId,
String versionRange) throws InvalidVersionSpecificationException {
this.regexp = regexp;
this.groupId = groupId;
this.artifactId = artifactId;
this.versionRange = versionRange;
this.genericVersionRange = initGenericVersionRange();
}
Comment on lines +73 to +81
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Refactor to handle checked exceptions with Lombok's @Builder

The constructor MavenDependencyMatcher is annotated with @Builder and throws InvalidVersionSpecificationException. Lombok's @Builder does not support checked exceptions, which can lead to compilation issues or make the builder unusable.

Consider removing the @Builder annotation or refactoring to handle the exception internally. Alternatively, you can modify the design to avoid throwing checked exceptions from the constructor.

Apply this diff to remove the @Builder annotation:

-    @Builder
     public MavenDependencyMatcher(String regexp, String groupId, String artifactId,
                                   String versionRange) throws InvalidVersionSpecificationException {

Or handle the exception within the constructor:

     public MavenDependencyMatcher(String regexp, String groupId, String artifactId,
-                                  String versionRange) throws InvalidVersionSpecificationException {
+                                  String versionRange) {
         this.regexp = regexp;
         this.groupId = groupId;
         this.artifactId = artifactId;
         this.versionRange = versionRange;
-        this.genericVersionRange = initGenericVersionRange();
+        try {
+            this.genericVersionRange = initGenericVersionRange();
+        } catch (InvalidVersionSpecificationException e) {
+            // Handle exception or rethrow as unchecked
+            throw new RuntimeException("Invalid version range specification", e);
+        }
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@Builder
public MavenDependencyMatcher(String regexp, String groupId, String artifactId,
String versionRange) throws InvalidVersionSpecificationException {
this.regexp = regexp;
this.groupId = groupId;
this.artifactId = artifactId;
this.versionRange = versionRange;
this.genericVersionRange = initGenericVersionRange();
}
public MavenDependencyMatcher(String regexp, String groupId, String artifactId,
String versionRange) throws InvalidVersionSpecificationException {
this.regexp = regexp;
this.groupId = groupId;
this.artifactId = artifactId;
this.versionRange = versionRange;
this.genericVersionRange = initGenericVersionRange();
}
```
Option 2 (Handling exception internally):
```suggestion
@Builder
public MavenDependencyMatcher(String regexp, String groupId, String artifactId,
String versionRange) {
this.regexp = regexp;
this.groupId = groupId;
this.artifactId = artifactId;
this.versionRange = versionRange;
try {
this.genericVersionRange = initGenericVersionRange();
} catch (InvalidVersionSpecificationException e) {
// Handle exception or rethrow as unchecked
throw new RuntimeException("Invalid version range specification", e);
}
}


public void setVersionRange(String versionRange) throws InvalidVersionSpecificationException {
this.versionRange = versionRange;
this.genericVersionRange = initGenericVersionRange();
}
gaosaroma marked this conversation as resolved.
Show resolved Hide resolved

private VersionRange initGenericVersionRange() throws InvalidVersionSpecificationException {
if (StringUtils.isEmpty(versionRange)) {
return null;
}

return versionScheme.parseVersionRange(versionRange);
}
}
Original file line number Diff line number Diff line change
@@ -1,66 +1,120 @@
version: 1.2.2
adapterMappings:
- matcher:
regexp: ".*com\\.ctrip\\.framework\\.apollo:apollo-client.*"
regexp: ".*spring-boot-starter-logging:3.*"
adapter:
artifactId: koupleless-adapter-logback-spring-starter-3.2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Convert regex matcher to structured format for consistency

The regex-based matcher for spring-boot-starter-logging should be converted to the structured format used by other mappings for better maintainability and consistency.

  - matcher:
-     regexp: ".*spring-boot-starter-logging:3.*"
+     groupId: org.springframework.boot
+     artifactId: spring-boot-starter-logging
+     versionRange: "[3.0.0,4.0.0)"
    adapter:
      artifactId: koupleless-adapter-logback-spring-starter-3.2
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
regexp: ".*spring-boot-starter-logging:3.*"
adapter:
artifactId: koupleless-adapter-logback-spring-starter-3.2
- matcher:
groupId: org.springframework.boot
artifactId: spring-boot-starter-logging
versionRange: "[3.0.0,4.0.0)"
adapter:
artifactId: koupleless-adapter-logback-spring-starter-3.2

- matcher:
groupId: org.springframework.boot
artifactId: spring-boot
versionRange: "[2.5.1,2.7.14]"
adapter:
artifactId: koupleless-adapter-spring-boot-logback-2.7.14
- matcher:
groupId: org.springframework.boot
artifactId: spring-boot-starter-logging
versionRange: "(,)"
adapter:
artifactId: koupleless-adapter-logback
- matcher:
groupId: org.springframework
artifactId: spring-aop
versionRange: "[6.0.8,6.0.9]"
adapter:
artifactId: koupleless-adapter-spring-aop-6.0.8
- matcher:
groupId: org.springframework
artifactId: spring-aop
versionRange: "[5.3.27,5.3.27]"
adapter:
artifactId: koupleless-adapter-spring-aop-5.3.27
- matcher:
groupId: org.apache.rocketmq
artifactId: rocketmq-client
versionRange: "[4.4.0,4.4.0]"
adapter:
artifactId: koupleless-adapter-rocketmq-4.4
- matcher:
groupId: com.ctrip.framework.apollo
artifactId: apollo-client
versionRange: "(,)"
adapter:
artifactId: koupleless-adapter-apollo-1.6
- matcher:
regexp: ".*(com\\.alibaba:dubbo-dependencies-bom:2\\.6|com\\.alibaba:dubbo:2\\.6).*"
groupId: com.alibaba
artifactId: dubbo-dependencies-bom
versionRange: "[2.6.1,2.7.0)"
adapter:
artifactId: koupleless-adapter-dubbo-2.6
- matcher:
regexp: ".*(dubbo-spring-boot-starter:2\\.7|com\\.alibaba:dubbo:2\\.7).*"
groupId: com.alibaba
artifactId: dubbo
versionRange: "[2.6.0,2.7.0)"
adapter:
artifactId: koupleless-adapter-dubbo-2.7
artifactId: koupleless-adapter-dubbo-2.6
- matcher:
regexp: ".*(org\\.apache\\.dubbo:dubbo.*:3\\.2).*"
groupId: org.apache.dubbo
artifactId: dubbo-spring-boot-starter
versionRange: "[2.7.0,2.8.0)"
adapter:
artifactId: koupleless-adapter-dubbo-3.2
artifactId: koupleless-adapter-dubbo-2.7
- matcher:
regexp: ".*(org\\.apache\\.dubbo:dubbo.*:3\\.1).*"
groupId: org.apache.dubbo
artifactId: dubbo
versionRange: "[2.7.0,2.8.0)"
adapter:
artifactId: koupleless-adapter-dubbo-3.1
artifactId: koupleless-adapter-dubbo-2.7
- matcher:
regexp: ".*spring-boot-starter-log4j2:3\\.(0|1).*"
groupId: org.apache.dubbo
artifactId: dubbo-common
versionRange: "[3.2.0,3.3.0)"
adapter:
artifactId: koupleless-adapter-log4j2-spring-starter-3.0
artifactId: koupleless-adapter-dubbo-3.2
- matcher:
regexp: ".*spring-boot-starter-log4j2:3.*"
groupId: org.apache.dubbo
artifactId: dubbo-common
versionRange: "[3.1.0,3.2.0)"
adapter:
artifactId: koupleless-adapter-log4j2-spring-starter-3.2
artifactId: koupleless-adapter-dubbo-3.1
- matcher:
regexp: ".*spring-boot-starter-log4j2:2\\.(1|2|3).*"
groupId: org.springframework.boot
artifactId: spring-boot-starter-log4j2
versionRange: "[2.1.0,2.4.0)"
adapter:
artifactId: koupleless-adapter-log4j2-spring-starter-2.1
- matcher:
regexp: ".*spring-boot-starter-log4j2:2\\.(4|5|6).*"
groupId: org.springframework.boot
artifactId: spring-boot-starter-log4j2
versionRange: "[2.4.0,2.7.0)"
adapter:
artifactId: koupleless-adapter-log4j2-spring-starter-2.4
- matcher:
regexp: ".*spring-boot-starter-log4j2.*"
groupId: org.springframework.boot
artifactId: spring-boot-starter-log4j2
versionRange: "[2.7.0,3.0.0)"
adapter:
artifactId: koupleless-adapter-log4j2-spring-starter-2.7
- matcher:
regexp: ".*spring-boot-starter-logging:3\\.(0|1).*"
adapter:
artifactId: koupleless-adapter-logback-spring-starter-3.0
- matcher:
regexp: ".*spring-boot-starter-logging:3.*"
groupId: org.springframework.boot
artifactId: spring-boot-starter-log4j2
versionRange: "[3.0.0,3.2.0)"
adapter:
artifactId: koupleless-adapter-logback-spring-starter-3.2
- matcher:
regexp: ".*spring-boot-starter-logging:.*"
adapter:
artifactId: koupleless-adapter-logback
artifactId: koupleless-adapter-log4j2-spring-starter-3.0
- matcher:
regexp: ".*(org\\.apache\\.rocketmq:rocketmq-client:4\\.4\\.0).*"
groupId: org.springframework.boot
artifactId: spring-boot-starter-log4j2
versionRange: "[3.2.0,)"
adapter:
artifactId: koupleless-adapter-rocketmq-4.4
artifactId: koupleless-adapter-log4j2-spring-starter-3.2
- matcher:
regexp: ".*(org\\.springframework:spring-aop:5\\.3\\.27).*"
groupId: org.springframework.boot
artifactId: spring-boot-starter-logging
versionRange: "[3.0.0,3.2.0)"
adapter:
artifactId: koupleless-adapter-spring-aop-5.3.27
artifactId: koupleless-adapter-logback-spring-starter-3.0
- matcher:
regexp: ".*(org\\.springframework:spring-aop:6\\.0\\.(8|9)).*"
groupId: org.springframework.boot
artifactId: spring-boot-starter-logging
versionRange: "[3.2.0,)"
adapter:
artifactId: koupleless-adapter-spring-aop-6.0.8
artifactId: koupleless-adapter-logback-spring-starter-3.2
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*/
package com.alipay.sofa.koupleless.base.build.plugin;

import com.alipay.sofa.koupleless.base.build.plugin.model.MavenDependencyAdapterMapping;
import com.alipay.sofa.koupleless.base.build.plugin.model.KouplelessAdapterConfig;
import com.alipay.sofa.koupleless.base.build.plugin.model.MavenDependencyAdapterMapping;
import com.alipay.sofa.koupleless.base.build.plugin.model.MavenDependencyMatcher;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Dependency;
Expand Down Expand Up @@ -92,7 +92,13 @@ public void testLazyInitKouplelessAdapterConfig() throws Exception {
KouplelessAdapterConfig expected = KouplelessAdapterConfig.builder()
.commonDependencies(commonDependencies).adapterMappings(mappings).build();

Assert.assertEquals(expected.toString(), mojo.kouplelessAdapterConfig.toString());
Assert.assertEquals(expected.getCommonDependencies().toString(), mojo.kouplelessAdapterConfig.getCommonDependencies().toString());

Assert.assertEquals(expected.getAdapterMappings().stream().map(MavenDependencyAdapterMapping::getMatcher).findFirst().get().getRegexp(),
mojo.kouplelessAdapterConfig.getAdapterMappings().stream().map(MavenDependencyAdapterMapping::getMatcher).findFirst().get().getRegexp());

Assert.assertEquals(expected.getAdapterMappings().stream().map(MavenDependencyAdapterMapping::getAdapter).findFirst().get().toString(),
mojo.kouplelessAdapterConfig.getAdapterMappings().stream().map(MavenDependencyAdapterMapping::getAdapter).findFirst().get().toString());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve test assertions robustness

The current assertions have several potential issues:

  1. Using toString() for comparisons can be fragile and may not catch semantic differences
  2. The stream operations with findFirst().get() could throw NoSuchElementException if lists are empty
  3. Individual component comparisons might miss structural differences in the collections

Consider refactoring to:

-        Assert.assertEquals(expected.getCommonDependencies().toString(), mojo.kouplelessAdapterConfig.getCommonDependencies().toString());
-
-        Assert.assertEquals(expected.getAdapterMappings().stream().map(MavenDependencyAdapterMapping::getMatcher).findFirst().get().getRegexp(),
-            mojo.kouplelessAdapterConfig.getAdapterMappings().stream().map(MavenDependencyAdapterMapping::getMatcher).findFirst().get().getRegexp());
-
-        Assert.assertEquals(expected.getAdapterMappings().stream().map(MavenDependencyAdapterMapping::getAdapter).findFirst().get().toString(),
-                mojo.kouplelessAdapterConfig.getAdapterMappings().stream().map(MavenDependencyAdapterMapping::getAdapter).findFirst().get().toString());
+        // Compare common dependencies
+        Assert.assertEquals("Common dependencies size mismatch",
+            expected.getCommonDependencies().size(),
+            mojo.kouplelessAdapterConfig.getCommonDependencies().size());
+        for (int i = 0; i < expected.getCommonDependencies().size(); i++) {
+            Dependency expectedDep = expected.getCommonDependencies().get(i);
+            Dependency actualDep = mojo.kouplelessAdapterConfig.getCommonDependencies().get(i);
+            Assert.assertEquals("GroupId mismatch", expectedDep.getGroupId(), actualDep.getGroupId());
+            Assert.assertEquals("ArtifactId mismatch", expectedDep.getArtifactId(), actualDep.getArtifactId());
+            Assert.assertEquals("Version mismatch", expectedDep.getVersion(), actualDep.getVersion());
+        }
+
+        // Compare adapter mappings
+        Assert.assertEquals("Adapter mappings size mismatch",
+            expected.getAdapterMappings().size(),
+            mojo.kouplelessAdapterConfig.getAdapterMappings().size());
+        for (int i = 0; i < expected.getAdapterMappings().size(); i++) {
+            MavenDependencyAdapterMapping expectedMapping = expected.getAdapterMappings().get(i);
+            MavenDependencyAdapterMapping actualMapping = mojo.kouplelessAdapterConfig.getAdapterMappings().get(i);
+            
+            // Compare matchers
+            Assert.assertEquals("Matcher regexp mismatch",
+                expectedMapping.getMatcher().getRegexp(),
+                actualMapping.getMatcher().getRegexp());
+            
+            // Compare adapters
+            Assert.assertEquals("Adapter groupId mismatch",
+                expectedMapping.getAdapter().getGroupId(),
+                actualMapping.getAdapter().getGroupId());
+            Assert.assertEquals("Adapter artifactId mismatch",
+                expectedMapping.getAdapter().getArtifactId(),
+                actualMapping.getAdapter().getArtifactId());
+            Assert.assertEquals("Adapter version mismatch",
+                expectedMapping.getAdapter().getVersion(),
+                actualMapping.getAdapter().getVersion());
+        }

This refactoring:

  1. Adds proper size checks for collections
  2. Compares individual fields instead of using toString()
  3. Provides better error messages for failures
  4. Handles all elements in the collections, not just the first one
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Assert.assertEquals(expected.getCommonDependencies().toString(), mojo.kouplelessAdapterConfig.getCommonDependencies().toString());
Assert.assertEquals(expected.getAdapterMappings().stream().map(MavenDependencyAdapterMapping::getMatcher).findFirst().get().getRegexp(),
mojo.kouplelessAdapterConfig.getAdapterMappings().stream().map(MavenDependencyAdapterMapping::getMatcher).findFirst().get().getRegexp());
Assert.assertEquals(expected.getAdapterMappings().stream().map(MavenDependencyAdapterMapping::getAdapter).findFirst().get().toString(),
mojo.kouplelessAdapterConfig.getAdapterMappings().stream().map(MavenDependencyAdapterMapping::getAdapter).findFirst().get().toString());
// Compare common dependencies
Assert.assertEquals("Common dependencies size mismatch",
expected.getCommonDependencies().size(),
mojo.kouplelessAdapterConfig.getCommonDependencies().size());
for (int i = 0; i < expected.getCommonDependencies().size(); i++) {
Dependency expectedDep = expected.getCommonDependencies().get(i);
Dependency actualDep = mojo.kouplelessAdapterConfig.getCommonDependencies().get(i);
Assert.assertEquals("GroupId mismatch", expectedDep.getGroupId(), actualDep.getGroupId());
Assert.assertEquals("ArtifactId mismatch", expectedDep.getArtifactId(), actualDep.getArtifactId());
Assert.assertEquals("Version mismatch", expectedDep.getVersion(), actualDep.getVersion());
}
// Compare adapter mappings
Assert.assertEquals("Adapter mappings size mismatch",
expected.getAdapterMappings().size(),
mojo.kouplelessAdapterConfig.getAdapterMappings().size());
for (int i = 0; i < expected.getAdapterMappings().size(); i++) {
MavenDependencyAdapterMapping expectedMapping = expected.getAdapterMappings().get(i);
MavenDependencyAdapterMapping actualMapping = mojo.kouplelessAdapterConfig.getAdapterMappings().get(i);
// Compare matchers
Assert.assertEquals("Matcher regexp mismatch",
expectedMapping.getMatcher().getRegexp(),
actualMapping.getMatcher().getRegexp());
// Compare adapters
Assert.assertEquals("Adapter groupId mismatch",
expectedMapping.getAdapter().getGroupId(),
actualMapping.getAdapter().getGroupId());
Assert.assertEquals("Adapter artifactId mismatch",
expectedMapping.getAdapter().getArtifactId(),
actualMapping.getAdapter().getArtifactId());
Assert.assertEquals("Adapter version mismatch",
expectedMapping.getAdapter().getVersion(),
actualMapping.getAdapter().getVersion());
}

}

@Test
Expand Down
Loading
Loading