Skip to content

Commit 7640e16

Browse files
kabirehsavoie
authored andcommitted
Remove runtime dependencies on MapStruct
1 parent 8f4dc25 commit 7640e16

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+149
-174
lines changed

spec-grpc/pom.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,20 @@
5050
<groupId>com.google.api.grpc</groupId>
5151
<artifactId>proto-google-common-protos</artifactId>
5252
</dependency>
53+
54+
55+
<!-- Annotation dependency for generated code -->
5356
<dependency>
5457
<groupId>org.mapstruct</groupId>
5558
<artifactId>mapstruct</artifactId>
59+
<scope>provided</scope>
5660
</dependency>
57-
58-
59-
<!-- Annotation dependency for generated code -->
6061
<dependency>
6162
<groupId>javax.annotation</groupId>
6263
<artifactId>javax.annotation-api</artifactId>
6364
<scope>provided</scope>
6465
</dependency>
66+
6567
<dependency>
6668
<groupId>org.junit.jupiter</groupId>
6769
<artifactId>junit-jupiter-api</artifactId>

spec-grpc/src/main/java/io/a2a/grpc/mapper/CommonFieldMapper.java renamed to spec-grpc/src/main/java/io/a2a/grpc/mapper/A2ACommonFieldMapper.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
package io.a2a.grpc.mapper;
22

3-
import com.google.protobuf.Struct;
4-
import com.google.protobuf.Timestamp;
5-
import com.google.protobuf.Value;
6-
import org.mapstruct.Mapper;
7-
import org.mapstruct.Named;
8-
import org.mapstruct.factory.Mappers;
9-
103
import java.time.Instant;
114
import java.time.OffsetDateTime;
125
import java.time.ZoneOffset;
136
import java.util.List;
147
import java.util.Map;
158
import java.util.stream.Collectors;
169

10+
import com.google.protobuf.Struct;
11+
import com.google.protobuf.Timestamp;
12+
import com.google.protobuf.Value;
13+
import org.mapstruct.Mapper;
14+
import org.mapstruct.Named;
15+
1716
/**
1817
* Common field mapping utilities shared across all mappers.
1918
* <p>
@@ -27,10 +26,10 @@
2726
* <li>Enum → null conversion (protobuf UNSPECIFIED/UNKNOWN handling)</li>
2827
* </ul>
2928
*/
30-
@Mapper(config = ProtoMapperConfig.class, uses = {TaskStateMapper.class})
31-
public interface CommonFieldMapper {
29+
@Mapper(config = A2AProtoMapperConfig.class, uses = {TaskStateMapper.class})
30+
public interface A2ACommonFieldMapper {
3231

33-
CommonFieldMapper INSTANCE = Mappers.getMapper(CommonFieldMapper.class);
32+
A2ACommonFieldMapper INSTANCE = A2AMappers.getMapper(A2ACommonFieldMapper.class);
3433

3534
/**
3635
* Converts protobuf empty strings to null for optional fields.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package io.a2a.grpc.mapper;
2+
3+
import java.lang.reflect.Constructor;
4+
import java.lang.reflect.InvocationTargetException;
5+
6+
public class A2AMappers {
7+
private static final String IMPLEMENTATION_SUFFIX = "Impl";
8+
9+
static <T> T getMapper(Class<T> iface) {
10+
try {
11+
@SuppressWarnings( "unchecked" )
12+
Class<T> implementation =
13+
(Class<T>) iface.getClassLoader().loadClass( iface.getName() + IMPLEMENTATION_SUFFIX );
14+
Constructor<T> constructor = implementation.getDeclaredConstructor();
15+
constructor.setAccessible( true );
16+
17+
return constructor.newInstance();
18+
19+
} catch (ClassNotFoundException |
20+
NoSuchMethodException |
21+
InstantiationException |
22+
IllegalAccessException |
23+
InvocationTargetException e) {
24+
throw new RuntimeException(e);
25+
}
26+
}
27+
}

spec-grpc/src/main/java/io/a2a/grpc/mapper/ProtoMapperConfig.java renamed to spec-grpc/src/main/java/io/a2a/grpc/mapper/A2AProtoMapperConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
// 3. IGNORE null values when mapping to protobuf (builders don't accept null)
3131
nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE
3232
)
33-
public interface ProtoMapperConfig {
33+
public interface A2AProtoMapperConfig {
3434

3535
// ========================================================================
3636
// 1. Enum Conversions

spec-grpc/src/main/java/io/a2a/grpc/mapper/APIKeySecuritySchemeMapper.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
import org.mapstruct.CollectionMappingStrategy;
44
import org.mapstruct.Mapper;
55
import org.mapstruct.Mapping;
6-
import org.mapstruct.factory.Mappers;
76

87
/**
98
* Mapper between {@link io.a2a.spec.APIKeySecurityScheme} and {@link io.a2a.grpc.APIKeySecurityScheme}.
109
*/
11-
@Mapper(config = ProtoMapperConfig.class,
10+
@Mapper(config = A2AProtoMapperConfig.class,
1211
collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED)
1312
public interface APIKeySecuritySchemeMapper {
1413

15-
APIKeySecuritySchemeMapper INSTANCE = Mappers.getMapper(APIKeySecuritySchemeMapper.class);
14+
APIKeySecuritySchemeMapper INSTANCE = A2AMappers.getMapper(APIKeySecuritySchemeMapper.class);
1615

1716
// location enum is converted to string via ProtoMapperConfig.map(Location)
1817
@Mapping(target = "description", source = "description", conditionExpression = "java(domain.getDescription() != null)")

spec-grpc/src/main/java/io/a2a/grpc/mapper/AgentCapabilitiesMapper.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22

33
import org.mapstruct.CollectionMappingStrategy;
44
import org.mapstruct.Mapper;
5-
import org.mapstruct.factory.Mappers;
65

76
/**
87
* Mapper between {@link io.a2a.spec.AgentCapabilities} and {@link io.a2a.grpc.AgentCapabilities}.
98
*/
10-
@Mapper(config = ProtoMapperConfig.class,
9+
@Mapper(config = A2AProtoMapperConfig.class,
1110
collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
1211
uses = {AgentExtensionMapper.class})
1312
public interface AgentCapabilitiesMapper {
1413

15-
AgentCapabilitiesMapper INSTANCE = Mappers.getMapper(AgentCapabilitiesMapper.class);
14+
AgentCapabilitiesMapper INSTANCE = A2AMappers.getMapper(AgentCapabilitiesMapper.class);
1615

1716
io.a2a.grpc.AgentCapabilities toProto(io.a2a.spec.AgentCapabilities domain);
1817
}

spec-grpc/src/main/java/io/a2a/grpc/mapper/AgentCardMapper.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
import org.mapstruct.CollectionMappingStrategy;
44
import org.mapstruct.Mapper;
55
import org.mapstruct.Mapping;
6-
import org.mapstruct.factory.Mappers;
76

87
/**
98
* Mapper between {@link io.a2a.spec.AgentCard} and {@link io.a2a.grpc.AgentCard}.
109
*/
11-
@Mapper(config = ProtoMapperConfig.class,
10+
@Mapper(config = A2AProtoMapperConfig.class,
1211
collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
1312
uses = {
1413
AgentProviderMapper.class,
@@ -21,7 +20,7 @@
2120
})
2221
public interface AgentCardMapper {
2322

24-
AgentCardMapper INSTANCE = Mappers.getMapper(AgentCardMapper.class);
23+
AgentCardMapper INSTANCE = A2AMappers.getMapper(AgentCardMapper.class);
2524

2625
@Mapping(target = "provider", source = "provider", conditionExpression = "java(domain.provider() != null)")
2726
@Mapping(target = "documentationUrl", source = "documentationUrl", conditionExpression = "java(domain.documentationUrl() != null)")

spec-grpc/src/main/java/io/a2a/grpc/mapper/AgentCardSignatureMapper.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@
33
import org.mapstruct.CollectionMappingStrategy;
44
import org.mapstruct.Mapper;
55
import org.mapstruct.Mapping;
6-
import org.mapstruct.factory.Mappers;
76

87
/**
98
* Mapper between {@link io.a2a.spec.AgentCardSignature} and {@link io.a2a.grpc.AgentCardSignature}.
109
* <p>
1110
* Uses CommonFieldMapper for struct conversion (header field).
1211
*/
13-
@Mapper(config = ProtoMapperConfig.class,
12+
@Mapper(config = A2AProtoMapperConfig.class,
1413
collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
15-
uses = {CommonFieldMapper.class})
14+
uses = {A2ACommonFieldMapper.class})
1615
public interface AgentCardSignatureMapper {
1716

18-
AgentCardSignatureMapper INSTANCE = Mappers.getMapper(AgentCardSignatureMapper.class);
17+
AgentCardSignatureMapper INSTANCE = A2AMappers.getMapper(AgentCardSignatureMapper.class);
1918

2019
/**
2120
* Converts domain AgentCardSignature to proto AgentCardSignature.

spec-grpc/src/main/java/io/a2a/grpc/mapper/AgentExtensionMapper.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@
33
import org.mapstruct.CollectionMappingStrategy;
44
import org.mapstruct.Mapper;
55
import org.mapstruct.Mapping;
6-
import org.mapstruct.factory.Mappers;
76

87
/**
98
* Mapper between {@link io.a2a.spec.AgentExtension} and {@link io.a2a.grpc.AgentExtension}.
109
* <p>
1110
* Uses CommonFieldMapper for struct conversion (params field).
1211
*/
13-
@Mapper(config = ProtoMapperConfig.class,
12+
@Mapper(config = A2AProtoMapperConfig.class,
1413
collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
15-
uses = {CommonFieldMapper.class})
14+
uses = {A2ACommonFieldMapper.class})
1615
public interface AgentExtensionMapper {
1716

18-
AgentExtensionMapper INSTANCE = Mappers.getMapper(AgentExtensionMapper.class);
17+
AgentExtensionMapper INSTANCE = A2AMappers.getMapper(AgentExtensionMapper.class);
1918

2019
/**
2120
* Converts domain AgentExtension to proto AgentExtension.

spec-grpc/src/main/java/io/a2a/grpc/mapper/AgentInterfaceMapper.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22

33
import org.mapstruct.CollectionMappingStrategy;
44
import org.mapstruct.Mapper;
5-
import org.mapstruct.Mapping;
6-
import org.mapstruct.factory.Mappers;
75

86
/**
97
* Mapper between {@link io.a2a.spec.AgentInterface} and {@link io.a2a.grpc.AgentInterface}.
108
*/
11-
@Mapper(config = ProtoMapperConfig.class,
9+
@Mapper(config = A2AProtoMapperConfig.class,
1210
collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED)
1311
public interface AgentInterfaceMapper {
1412

15-
AgentInterfaceMapper INSTANCE = Mappers.getMapper(AgentInterfaceMapper.class);
13+
AgentInterfaceMapper INSTANCE = A2AMappers.getMapper(AgentInterfaceMapper.class);
1614

1715
io.a2a.grpc.AgentInterface toProto(io.a2a.spec.AgentInterface domain);
1816

0 commit comments

Comments
 (0)