Release YangParser from ProcessorModuleReactor 99/86799/1
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 23:34:16 +0000 (00:34 +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>
(cherry picked from commit de31cd1e591ab1a83ca3fafd20220d3937463b8a)

yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/ProcessorModuleReactor.java

index 8f02a93c3af7b3805ccbf89fb10b56c8a30af492..c5a74349aa8ec62382e2fde042a75077afa39d2a 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.yangtools.yang2sources.plugin;
 
+import static com.google.common.base.Preconditions.checkState;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.base.MoreObjects;
@@ -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 SchemaContext schemaContext = Verify.verifyNotNull(parser.buildSchemaContext());
+        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();
     }
 }