Merge "Resolve Bug:717 - Remove fragment version requirement from config-persister-*"
[controller.git] / opendaylight / config / yang-jmx-generator-plugin / src / main / java / org / opendaylight / controller / config / yangjmxgenerator / plugin / JMXGenerator.java
index 743ffba739c97399a6a73556ab01a3061eed6816..1b8905b9871c0a1334ebacbc28a1f6dd52d41492 100644 (file)
@@ -7,17 +7,11 @@
  */
 package org.opendaylight.controller.config.yangjmxgenerator.plugin;
 
-import java.io.File;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
 import org.apache.commons.io.FileUtils;
 import org.apache.maven.plugin.logging.Log;
 import org.apache.maven.project.MavenProject;
@@ -28,6 +22,7 @@ import org.opendaylight.controller.config.yangjmxgenerator.ServiceInterfaceEntry
 import org.opendaylight.controller.config.yangjmxgenerator.TypeProviderWrapper;
 import org.opendaylight.yangtools.sal.binding.yang.types.TypeProviderImpl;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang2sources.spi.CodeGenerator;
@@ -35,11 +30,16 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.impl.StaticLoggerBinder;
 
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
+import java.io.File;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * This class interfaces with yang-maven-plugin. Gets parsed yang modules in
@@ -62,7 +62,7 @@ public class JMXGenerator implements CodeGenerator {
     private boolean generateModuleFactoryFile = true;
 
     public JMXGenerator() {
-        this.codeWriter = new FreeMarkerCodeWriterImpl();
+        this.codeWriter = new CodeWriter();
     }
 
     public JMXGenerator(CodeWriter codeWriter) {
@@ -71,7 +71,7 @@ public class JMXGenerator implements CodeGenerator {
 
     @Override
     public Collection<File> generateSources(SchemaContext context,
-            File outputBaseDir, Set<Module> yangModulesInCurrentMavenModule) {
+                                            File outputBaseDir, Set<Module> yangModulesInCurrentMavenModule) {
 
         Preconditions.checkArgument(context != null, "Null context received");
         Preconditions.checkArgument(outputBaseDir != null,
@@ -87,24 +87,25 @@ public class JMXGenerator implements CodeGenerator {
             outputBaseDir.mkdirs();
 
         GeneratedFilesTracker generatedFiles = new GeneratedFilesTracker();
+        // create SIE structure qNamesToSIEs
         Map<QName, ServiceInterfaceEntry> qNamesToSIEs = new HashMap<>();
 
-        // create SIE structure qNamesToSIEs
+
+        Map<IdentitySchemaNode, ServiceInterfaceEntry> knownSEITracker = new HashMap<>();
         for (Module module : context.getModules()) {
             String packageName = packageTranslator.getPackageName(module);
             Map<QName, ServiceInterfaceEntry> namesToSIEntries = ServiceInterfaceEntry
-                    .create(module, packageName);
+                    .create(module, packageName, knownSEITracker);
 
             for (Entry<QName, ServiceInterfaceEntry> sieEntry : namesToSIEntries
                     .entrySet()) {
-
                 // merge value into qNamesToSIEs
                 if (qNamesToSIEs.containsKey(sieEntry.getKey()) == false) {
                     qNamesToSIEs.put(sieEntry.getKey(), sieEntry.getValue());
                 } else {
                     throw new IllegalStateException(
-                            "Cannot add two SIE with same qname "
-                                    + sieEntry.getValue());
+                        "Cannot add two SIE  with same qname "
+                                + sieEntry.getValue());
                 }
             }
             if (yangModulesInCurrentMavenModule.contains(module)) {
@@ -139,7 +140,7 @@ public class JMXGenerator implements CodeGenerator {
                 ModuleMXBeanEntry mbe = mbeEntry.getValue();
                 try {
                     List<File> files1 = codeWriter.writeMbe(mbe, outputBaseDir,
-                            mainBaseDir, resourceBaseDir);
+                            mainBaseDir);
                     generatedFiles.addFile(files1);
                 } catch (Exception e) {
                     throw new RuntimeException(
@@ -203,7 +204,7 @@ public class JMXGenerator implements CodeGenerator {
 
     @Override
     public void setLog(Log log) {
-        StaticLoggerBinder.getSingleton().setLog(log);
+        StaticLoggerBinder.getSingleton().setMavenLog(log);
     }
 
     private static Map<String, String> extractNamespaceMapping(