Skip to content

Commit 5548c4f

Browse files
authored
1 parent 2471d8d commit 5548c4f

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

utils/maven-plugin/src/main/java/io/apicurio/registry/maven/RegisterRegistryMojo.java

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import io.apicurio.registry.rest.v2.beans.ArtifactMetaData;
2929
import io.apicurio.registry.rest.v2.beans.ArtifactReference;
3030
import io.apicurio.registry.rest.v2.beans.IfExists;
31+
import io.apicurio.registry.rest.v2.beans.VersionMetaData;
3132
import io.apicurio.registry.types.ArtifactType;
3233
import io.apicurio.registry.types.ContentTypes;
3334
import io.apicurio.registry.types.provider.ArtifactTypeUtilProvider;
@@ -137,9 +138,7 @@ protected void executeInternal() throws MojoExecutionException {
137138
else if (artifact.getAnalyzeDirectory() != null
138139
&& artifact.getAnalyzeDirectory()) { //Auto register selected, we must figure out if the artifact has reference using the directory structure
139140
registerDirectory(artifact);
140-
}
141-
else {
142-
141+
} else {
143142
List<ArtifactReference> references = new ArrayList<>();
144143
//First, we check if the artifact being processed has references defined
145144
if (hasReferences(artifact)) {
@@ -243,8 +242,7 @@ private ArtifactMetaData registerArtifact(RegisterArtifact artifact, List<Artifa
243242
FileNotFoundException {
244243
if (artifact.getFile() != null) {
245244
return registerArtifact(artifact, new FileInputStream(artifact.getFile()), references);
246-
}
247-
else {
245+
} else {
248246
return getArtifactMetadata(artifact);
249247
}
250248
}
@@ -253,10 +251,34 @@ private ArtifactMetaData getArtifactMetadata(RegisterArtifact artifact) {
253251
String groupId = artifact.getGroupId();
254252
String artifactId = artifact.getArtifactId();
255253

256-
ArtifactMetaData amd = this.getClient().getArtifactMetaData(groupId, artifactId);
257-
getLog().info(String.format("Successfully processed artifact [%s] / [%s]. GlobalId is [%d]", groupId, artifactId, amd.getGlobalId()));
258-
259-
return amd;
254+
if (artifact.getVersion() != null) {
255+
String version = artifact.getVersion();
256+
VersionMetaData vmd = this.getClient().getArtifactVersionMetaData(groupId, artifactId, version);
257+
getLog().info(String.format("Successfully processed artifact [%s] / [%s] / [%s]. GlobalId is [%d]",
258+
groupId, artifactId, version, vmd.getGlobalId()));
259+
ArtifactMetaData amd = new ArtifactMetaData();
260+
amd.setGlobalId(vmd.getGlobalId());
261+
amd.setContentId(vmd.getContentId());
262+
amd.setGroupId(vmd.getGroupId());
263+
amd.setId(vmd.getId());
264+
amd.setVersion(vmd.getVersion());
265+
amd.setName(vmd.getName());
266+
amd.setDescription(vmd.getDescription());
267+
amd.setType(vmd.getType());
268+
amd.setCreatedBy(vmd.getCreatedBy());
269+
amd.setCreatedOn(vmd.getCreatedOn());
270+
amd.setModifiedBy(vmd.getCreatedBy());
271+
amd.setModifiedOn(vmd.getCreatedOn());
272+
amd.setProperties(vmd.getProperties());
273+
amd.setLabels(vmd.getLabels());
274+
amd.setState(vmd.getState());
275+
return amd;
276+
} else {
277+
ArtifactMetaData amd = this.getClient().getArtifactMetaData(groupId, artifactId);
278+
getLog().info(String.format("Successfully processed artifact [%s] / [%s]. GlobalId is [%d]",
279+
groupId, artifactId, amd.getGlobalId()));
280+
return amd;
281+
}
260282
}
261283

262284
private ArtifactMetaData registerArtifact(RegisterArtifact artifact, InputStream artifactContent, List<ArtifactReference> references) {

0 commit comments

Comments
 (0)