Skip to content

Commit

Permalink
adding project gav in dependencies/json (simple-dependencies goal)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmannibucau committed Mar 13, 2023
1 parent 4a8e4dc commit fccb8e9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ private String format(final List<DepArtifact> dependencies) throws MojoFailureEx
try (final var jsonb = JsonbBuilder.create(new JsonbConfig()
.withPropertyOrderStrategy(LEXICOGRAPHICAL)
.withFormatting(JSON_PRETTY.equals(format)))) {
return jsonb.toJson(new JsonWrapper(dependencies));
return jsonb.toJson(new JsonWrapper(
project.getGroupId(), project.getArtifactId(), project.getArtifactId(),
project.getPackaging(), dependencies));
} catch (final Exception e) {
throw new MojoFailureException(e.getMessage(), e);
}
Expand All @@ -108,9 +110,18 @@ private List<DepArtifact> findDependencies() {
}

public static class JsonWrapper {
public String groupId;
public String artifactId;
public String version;
public String packaging;
public Collection<DepArtifact> items;

public JsonWrapper(final Collection<DepArtifact> items) {
public JsonWrapper(final String groupId, final String artifactId, final String version, final String packaging,
final Collection<DepArtifact> items) {
this.groupId = groupId;
this.artifactId = artifactId;
this.version = version;
this.packaging = packaging;
this.items = items;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,18 @@ void run(@TempDir final Path work) throws MojoExecutionException, MojoFailureExc
format = Format.JSON_PRETTY;
scope = "all";
project = new MavenProject();
project.setGroupId("test.yupiik");
project.setArtifactId("test");
project.setVersion("1.2.3-SNAPSHOT");
project.setArtifacts(Set.of(new DefaultArtifact(
"the.group", "the.art", "the.version",
"the.scope", "the.type", "the.classifier", null)));
}};
mojo.execute();
assertEquals("" +
"{\n" +
" \"artifactId\":\"test\",\n" +
" \"groupId\":\"test.yupiik\",\n" +
" \"items\":[\n" +
" {\n" +
" \"artifactId\":\"the.art\",\n" +
Expand All @@ -54,7 +59,9 @@ void run(@TempDir final Path work) throws MojoExecutionException, MojoFailureExc
" \"type\":\"the.type\",\n" +
" \"version\":\"the.version\"\n" +
" }\n" +
" ]\n" +
" ],\n" +
" \"packaging\":\"jar\",\n" +
" \"version\":\"test\"\n" +
"}" +
"", Files.readString(file));
}
Expand Down

0 comments on commit fccb8e9

Please sign in to comment.