From 2f832ea2eda1727308adf82051afdf30bfdb247f Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Tue, 25 Jul 2017 15:44:21 +0200 Subject: Api docs: single row per VPP API message Lists all of supported CUD operations in single cell. Change-Id: I5f23200d869221f797ed8b4b5ca0512baa92486b Signed-off-by: Marek Gradzki --- .../src/main/asciidoc/api_docs/api_docs_index.adoc | 2 +- .../java/io/fd/hc2vpp/docs/api/CoverageUnit.java | 12 ++-- .../java/io/fd/hc2vpp/docs/api/JavaApiMessage.java | 14 ++--- .../io/fd/hc2vpp/docs/core/CoverageGenerator.java | 71 ++++++++++++---------- .../fd/hc2vpp/docs/core/PluginMethodReference.java | 5 ++ .../docs/scripts/ApiDocsIndexGenerator.groovy | 4 +- 6 files changed, 62 insertions(+), 46 deletions(-) diff --git a/release-notes/src/main/asciidoc/api_docs/api_docs_index.adoc b/release-notes/src/main/asciidoc/api_docs/api_docs_index.adoc index 08dfeb28f..a9029d666 100644 --- a/release-notes/src/main/asciidoc/api_docs/api_docs_index.adoc +++ b/release-notes/src/main/asciidoc/api_docs/api_docs_index.adoc @@ -1,4 +1,4 @@ -== VPP api to Yang index +== VPP API to Yang index // TODO - generate this file based on list of JVPP plugins used diff --git a/vpp-integration/api-docs/api/src/main/java/io/fd/hc2vpp/docs/api/CoverageUnit.java b/vpp-integration/api-docs/api/src/main/java/io/fd/hc2vpp/docs/api/CoverageUnit.java index 06cb59f69..e04d28304 100644 --- a/vpp-integration/api-docs/api/src/main/java/io/fd/hc2vpp/docs/api/CoverageUnit.java +++ b/vpp-integration/api-docs/api/src/main/java/io/fd/hc2vpp/docs/api/CoverageUnit.java @@ -16,8 +16,10 @@ package io.fd.hc2vpp.docs.api; +import java.util.Collection; import java.util.List; import java.util.Objects; +import java.util.Set; /** * Represents mapping between single supported VPP binary api and its binding @@ -42,11 +44,11 @@ public class CoverageUnit { /** * Operations supported for this api */ - private final List supportedOperations; + private final Collection supportedOperations; private CoverageUnit(final VppApiMessage vppApi, final JavaApiMessage javaApi, final List yangTypes, - final List supportedOperations) { + final Collection supportedOperations) { this.vppApi = vppApi; this.javaApi = javaApi; this.yangTypes = yangTypes; @@ -65,7 +67,7 @@ public class CoverageUnit { return yangTypes; } - public List getSupportedOperations() { + public Collection getSupportedOperations() { return supportedOperations; } @@ -95,7 +97,7 @@ public class CoverageUnit { private VppApiMessage vppApi; private JavaApiMessage javaApi; private List yangTypes; - private List supportedOperations; + private Set supportedOperations; public CoverageUnitBuilder setVppApi(final VppApiMessage vppApi) { this.vppApi = vppApi; @@ -112,7 +114,7 @@ public class CoverageUnit { return this; } - public CoverageUnitBuilder setSupportedOperations(final List supportedOperations) { + public CoverageUnitBuilder setSupportedOperations(final Set supportedOperations) { this.supportedOperations = supportedOperations; return this; } diff --git a/vpp-integration/api-docs/api/src/main/java/io/fd/hc2vpp/docs/api/JavaApiMessage.java b/vpp-integration/api-docs/api/src/main/java/io/fd/hc2vpp/docs/api/JavaApiMessage.java index db4575c5a..a25fdc245 100644 --- a/vpp-integration/api-docs/api/src/main/java/io/fd/hc2vpp/docs/api/JavaApiMessage.java +++ b/vpp-integration/api-docs/api/src/main/java/io/fd/hc2vpp/docs/api/JavaApiMessage.java @@ -26,14 +26,14 @@ public class JavaApiMessage { /** * Name of the call */ - private final String api; + private final String name; - public JavaApiMessage(final String api) { - this.api = api; + public JavaApiMessage(final String name) { + this.name = name; } - public String getApi() { - return api; + public String getName() { + return name; } @Override @@ -46,11 +46,11 @@ public class JavaApiMessage { } final JavaApiMessage that = (JavaApiMessage) o; - return Objects.equals(this.api, that.api); + return Objects.equals(this.name, that.name); } @Override public int hashCode() { - return Objects.hash(api); + return Objects.hash(name); } } diff --git a/vpp-integration/api-docs/core/src/main/java/io/fd/hc2vpp/docs/core/CoverageGenerator.java b/vpp-integration/api-docs/core/src/main/java/io/fd/hc2vpp/docs/core/CoverageGenerator.java index 4a8a77827..ff6c9b78b 100644 --- a/vpp-integration/api-docs/core/src/main/java/io/fd/hc2vpp/docs/core/CoverageGenerator.java +++ b/vpp-integration/api-docs/core/src/main/java/io/fd/hc2vpp/docs/core/CoverageGenerator.java @@ -34,7 +34,7 @@ import io.fd.hc2vpp.docs.api.PluginCoverage; import io.fd.hc2vpp.docs.api.YangType; import io.fd.honeycomb.translate.write.WriterFactory; import java.lang.reflect.Field; -import java.util.LinkedList; +import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -63,53 +63,62 @@ public class CoverageGenerator implements VppApiUtils { final Set coverageUnits = writerBuilder.getWriteHandlers().stream() .flatMap(handler -> { + LOG.debug("Processing writer handling nodes: {}", handler.getHandledNodes()); // extracts customizer class from handler final Class customizerClass = getCustomizerClass(handler.getWriter()); // scans within write method final Set writeReferences = new CoverageScanner(customizerClass, WRITE, pluginClass).scan(); + LOG.debug("writeReferences: {}", writeReferences); // scans within update method final Set updateReferences = new CoverageScanner(customizerClass, UPDATE, pluginClass).scan(); + LOG.debug("updateReferences: {}", updateReferences); // scans within delete method final Set deleteReferences = new CoverageScanner(customizerClass, DELETE, pluginClass).scan(); + LOG.debug("deleteReferences: {}", deleteReferences); return Stream.of(writeReferences.stream(), updateReferences.stream(), deleteReferences.stream()) - .flatMap(pluginMethodReferenceStream -> pluginMethodReferenceStream) - .map(reference -> { - final CoverageUnit.CoverageUnitBuilder builder = new CoverageUnit.CoverageUnitBuilder(); - - // binds vpp api name and generateLink bind with version - builder.setVppApi(fromJvppApi(version, reference.getName())); - - //binds java api reference - builder.setJavaApi(new JavaApiMessage(reference.getName())); - - // binds Yang types with links from pre-build index - // TODO - use deserialized yii e.g. /module:parent-node/child-node - builder.setYangTypes(handler.getHandledNodes().stream() - .map(type -> new YangType(type, yangTypeIndex.getLinkForType(type))) - .collect(Collectors.toList())); - - final String callerClassLink = classPathIndex.linkForClass(reference.getCaller()); - final List supportedOperations = new LinkedList<>(); - if (writeReferences.contains(reference)) { - supportedOperations.add(new Operation(callerClassLink, WRITE)); + .flatMap(pluginMethodReferenceStream -> pluginMethodReferenceStream) + .collect(Collectors.groupingBy(PluginMethodReference::getName)).entrySet().stream() + .map(vppMessageReferenceByName -> { + final String jvppMethodName = vppMessageReferenceByName.getKey(); + final CoverageUnit.CoverageUnitBuilder builder = new CoverageUnit.CoverageUnitBuilder(); + + // binds vpp api name and generateLink bind with version + builder.setVppApi(fromJvppApi(version, jvppMethodName)); + + //binds java api reference + builder.setJavaApi(new JavaApiMessage(jvppMethodName)); + + // binds Yang types with links from pre-build index + // TODO - use deserialized yii e.g. /module:parent-node/child-node + builder.setYangTypes(handler.getHandledNodes().stream() + .map(type -> new YangType(type, yangTypeIndex.getLinkForType(type))) + .collect(Collectors.toList())); + + + final Set supportedOperations = new HashSet<>(); + vppMessageReferenceByName.getValue().stream().forEach( + reference -> { + final String callerClassLink = classPathIndex.linkForClass(reference.getCaller()); + if (writeReferences.contains(reference)) { + supportedOperations.add(new Operation(callerClassLink, WRITE)); + } + if (updateReferences.contains(reference)) { + supportedOperations.add(new Operation(callerClassLink, UPDATE)); + } + if (deleteReferences.contains(reference)) { + supportedOperations.add(new Operation(callerClassLink, DELETE)); + } } - - if (updateReferences.contains(reference)) { - supportedOperations.add(new Operation(callerClassLink, UPDATE)); - } - - if (deleteReferences.contains(reference)) { - supportedOperations.add(new Operation(callerClassLink, DELETE)); - } - return builder.setSupportedOperations(supportedOperations).build(); - }); + ); + return builder.setSupportedOperations(supportedOperations).build(); + }); }).collect(Collectors.toSet()); return new PluginCoverage(pluginClass.getSimpleName(), coverageUnits, true); diff --git a/vpp-integration/api-docs/core/src/main/java/io/fd/hc2vpp/docs/core/PluginMethodReference.java b/vpp-integration/api-docs/core/src/main/java/io/fd/hc2vpp/docs/core/PluginMethodReference.java index 5a98639ae..4e03b4a73 100644 --- a/vpp-integration/api-docs/core/src/main/java/io/fd/hc2vpp/docs/core/PluginMethodReference.java +++ b/vpp-integration/api-docs/core/src/main/java/io/fd/hc2vpp/docs/core/PluginMethodReference.java @@ -53,4 +53,9 @@ public class PluginMethodReference { public String getName() { return name; } + + @Override + public String toString() { + return "PluginMethodReference{name=" + this.name + ", caller=" + this.caller + ", owner=" + this.owner + ", " + "}"; + } } diff --git a/vpp-integration/api-docs/scripts/src/main/groovy/io/fd/hc2vpp/docs/scripts/ApiDocsIndexGenerator.groovy b/vpp-integration/api-docs/scripts/src/main/groovy/io/fd/hc2vpp/docs/scripts/ApiDocsIndexGenerator.groovy index 238f4a25b..437def689 100644 --- a/vpp-integration/api-docs/scripts/src/main/groovy/io/fd/hc2vpp/docs/scripts/ApiDocsIndexGenerator.groovy +++ b/vpp-integration/api-docs/scripts/src/main/groovy/io/fd/hc2vpp/docs/scripts/ApiDocsIndexGenerator.groovy @@ -139,14 +139,14 @@ class ApiDocsIndexGenerator { } private static String javaApi(final JavaApiMessage javaApi) { - "$TABLE_PART_MARK${javaApi.api}$NL" + "$TABLE_PART_MARK${javaApi.name}$NL" } private static String yangTypes(final List yangTypes) { "$NL$TABLE_PART_MARK$NL ${yangTypes.stream().map { yangType -> " ${yangType.link}[${yangType.type}]" }.collect(Collectors.joining(NL))}" } - private static String supportedOperations(final List operations) { + private static String supportedOperations(final Collection operations) { "$NL$TABLE_PART_MARK${operations.stream().map { reference -> " ${reference.link}[${reference.operation}]" }.collect(Collectors.joining(NL))}" } -- cgit 1.2.3-korg