Release YangParser from ProcessorModuleReactor 96/86796/2
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 7 Jan 2020 22:23:12 +0000 (23:23 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 7 Jan 2020 22:50:27 +0000 (23:50 +0100)
Once we have built the SchemaContext, we should not be retaining
the YangParser instance, as it contains a reference to
BuildGlobalContext, which in turn holds all the scratch data
used during SchemaContext assembly.

Throw all of that away as soon as we have a SchemaContext.

JIRA: YANGTOOLS-1061
Change-Id: Idbc4ab91861e3e7581daa3cebceb0fa49823a028
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/ProcessorModuleReactor.java

index 62aea1b5bac8550744d4a10867ba5199dd9399de..af0b8a85dc44be5000b029a5132ba61b655d960f 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.yangtools.yang2sources.plugin;
 
+import static com.google.common.base.Preconditions.checkState;
 import static com.google.common.base.Verify.verifyNotNull;
 import static java.util.Objects.requireNonNull;
 
@@ -42,7 +43,8 @@ final class ProcessorModuleReactor {
 
     private final Map<SourceIdentifier, YangTextSchemaSource> modelsInProject;
     private final Collection<ScannedDependency> dependencies;
-    private final YangParser parser;
+
+    private YangParser parser;
 
     ProcessorModuleReactor(final YangParser parser, final Collection<YangTextSchemaSource> modelsInProject,
         final Collection<ScannedDependency> dependencies) {
@@ -52,6 +54,8 @@ final class ProcessorModuleReactor {
     }
 
     ContextHolder toContext() throws IOException, YangParserException {
+        checkState(parser != null, "Context has already been assembled");
+
         for (YangTextSchemaSource source : toUniqueSources(dependencies)) {
             // This source is coming from a dependency:
             // - its identifier should be accurate, as it should have been processed into a file with accurate name
@@ -60,6 +64,7 @@ final class ProcessorModuleReactor {
         }
 
         final EffectiveModelContext schemaContext = verifyNotNull(parser.buildEffectiveModel());
+        parser = null;
 
         final Set<Module> modules = new HashSet<>();
         for (Module module : schemaContext.getModules()) {
@@ -104,7 +109,6 @@ final class ProcessorModuleReactor {
 
     @Override
     public String toString() {
-        return MoreObjects.toStringHelper(this).add("sources", modelsInProject.keySet()).add("parser", parser)
-                .toString();
+        return MoreObjects.toStringHelper(this).add("sources", modelsInProject.keySet()).toString();
     }
 }