Skip to content

Commit

Permalink
Fixes #395
Browse files Browse the repository at this point in the history
  • Loading branch information
Riduidel committed Oct 9, 2023
1 parent 20a99e5 commit 8dec212
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.ndx.aadarchi.inferer.maven;

import java.util.Comparator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;

import javax.enterprise.context.ApplicationScoped;
Expand All @@ -10,7 +12,6 @@

import org.ndx.aadarchi.base.AgileArchitectureSection;
import org.ndx.aadarchi.base.OutputBuilder;
import org.ndx.aadarchi.base.OutputBuilder.HandledFormat;
import org.ndx.aadarchi.base.enhancers.ModelElementAdapter;
import org.ndx.aadarchi.inferer.maven.technologies.MvnRepositoryArtifact;
import org.ndx.aadarchi.inferer.maven.technologies.MvnRepositoryArtifactsProducer;
Expand Down Expand Up @@ -49,11 +50,23 @@ protected void processElement(StaticStructureElement element, OutputBuilder buil
}
}
}

private Comparator<Map.Entry<MvnRepositoryArtifact, String>> comparator() {
return new Comparator<Map.Entry<MvnRepositoryArtifact, String>>() {

@Override
public int compare(Entry<MvnRepositoryArtifact, String> o1, Entry<MvnRepositoryArtifact, String> o2) {
return o1.getKey().compareTo(o2.getKey());
}

};
}

private void writeDependenciesArtifacts(StaticStructureElement element, Map<String, String> dependenciesVersions,
OutputBuilder builder) {
String text = dependenciesVersions.entrySet().stream()
.map(entry -> Map.entry(mvnRepositoryArtifacts.get(entry.getKey()), entry.getValue()))
.sorted(this.comparator())
.map(entry -> this.toTableRow(entry.getKey(), entry.getValue()))
.collect(Collectors.joining("\n",
"[%autowidth.stretch, cols=\"1a,1a,1a,1a\"]\n|==="
Expand All @@ -75,7 +88,7 @@ private String toTableRow(MvnRepositoryArtifact key, String version) {
if(key.categories==null || key.categories.isEmpty()) {
returned.append("{nbsp}");
} else {
returned.append(key.categories.stream().collect(Collectors.joining()));
returned.append(key.categoriesText);
}
returned
.append("|").append(key.description)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.apache.commons.lang3.builder.CompareToBuilder;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

public class MvnRepositoryArtifact {
public class MvnRepositoryArtifact implements Comparable<MvnRepositoryArtifact> {
public final String name;
public final String coordinates;
public final String description;
Expand All @@ -16,6 +19,7 @@ public class MvnRepositoryArtifact {
public final String page;
public final int ranking;
public final int users;
public final String categoriesText;

@JsonCreator
public MvnRepositoryArtifact(@JsonProperty("name") String name,
Expand All @@ -34,9 +38,20 @@ public MvnRepositoryArtifact(@JsonProperty("name") String name,
this.page = page;
this.description = description;
this.categories = categories;
this.categoriesText = categories==null ? "" : categories.stream().sorted().collect(Collectors.joining());
this.users = users;
this.ranking = ranking;
this.tags = tags;
this.versions = versions;
}

@Override
public int compareTo(MvnRepositoryArtifact o) {
return new CompareToBuilder()
.append(categoriesText, o.categoriesText)
.append(-1*ranking, -1*o.ranking)
.append(users, o.users)
.append(name, o.name)
.toComparison();
}
}

0 comments on commit 8dec212

Please sign in to comment.