Skip to content
Permalink
Browse files
973: Include namespaces in census unification
Reviewed-by: rwestberg
  • Loading branch information
edvbld committed Apr 16, 2021
1 parent 64a8dc1 commit 24e7dd36dbcd81b11342d90df3bc9a83090ece4e
Showing 4 changed files with 36 additions and 6 deletions.
@@ -125,6 +125,15 @@ public Collection<WorkItem> run(Path scratch) {

file.println("</project>");
}
for (var namespace : census.namespaces()) {
file.println("<namespace name=\"" + namespace.name() + "\">");
for (var entry : namespace.entries()) {
var id = entry.getKey();
var contributor = entry.getValue();
file.println(" <user id=\"" + id + "\" census=\"" + contributor.username() + "\" />");
}
file.println("</namespace>");
}
file.println("</census>");
}
toRepo.add(censusXML);
@@ -173,7 +173,12 @@ private static Census parseDocument(Document document) throws IOException {
projects.add(Project.parse(ele, groups, contributors));
}

return new Census(contributors, groups, projects, List.of(), version);
var namespaces = new ArrayList<Namespace>();
for (var ele : XML.children(census, "namespace")) {
namespaces.add(Namespace.parse(ele, contributors));
}

return new Census(contributors, groups, projects, namespaces, version);
}

private static Census parseSingleFile(Path p) throws IOException {
@@ -27,6 +27,7 @@
import java.io.IOException;
import java.nio.file.Path;
import java.util.*;
import org.w3c.dom.Element;

public class Namespace {
private final String name;
@@ -51,15 +52,22 @@ public String get(Contributor contributor) {
return reverse.get(contributor);
}

static Namespace parse(Path p, Map<String, Contributor> contributors) throws IOException {
var mapping = new HashMap<String, Contributor>();
var reverse = new HashMap<Contributor, String>();
public Set<Map.Entry<String, Contributor>> entries() {
return mapping.entrySet();
}

static Namespace parse(Path p, Map<String, Contributor> contributors) throws IOException {
var document = XML.parse(p);
var namespace = XML.child(document, "namespace");
var name = XML.attribute(namespace, "name");
return parse(namespace, contributors);
}

static Namespace parse(Element ele, Map<String, Contributor> contributors) throws IOException {
var mapping = new HashMap<String, Contributor>();
var reverse = new HashMap<Contributor, String>();
var name = XML.attribute(ele, "name");

for (var user : XML.children(namespace, "user")) {
for (var user : XML.children(ele, "user")) {
var id = XML.attribute(user, "id");
var to = XML.attribute(user, "census");

@@ -144,6 +144,10 @@ void testParseSingleFile() throws IOException {
" <person role=\"lead\" ref=\"user1\" />",
" <person role=\"committer\" ref=\"user2\" />",
" </project>",
" <namespace name=\"reverse\" >",
" <user id=\"1resu\" census=\"user1\" />",
" <user id=\"2resu\" census=\"user2\" />",
" </namespace>",
"</census>");
var tmpFile = Files.createTempFile("census", ".xml");
Files.write(tmpFile, contents);
@@ -164,6 +168,10 @@ void testParseSingleFile() throws IOException {
assertEquals(List.of(expectedProject), census.projects());

assertEquals(0, census.version().format());
assertEquals(1, census.namespaces().size());
assertEquals(2, census.namespace("reverse").entries().size());
assertEquals("user1", census.namespace("reverse").get("1resu").username());
assertEquals("user2", census.namespace("reverse").get("2resu").username());

Files.delete(tmpFile);
}

1 comment on commit 24e7dd3

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 24e7dd3 Apr 16, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.