X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fyang-jmx-generator-plugin%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyangjmxgenerator%2Fplugin%2FJMXGenerator.java;h=3cbbb28ab4f270e02f7344dc852252f0559b67e7;hb=69011f0833c2d383536c2ac61f2b0edc83d119e9;hp=e40ca8b18b176869509f8c897b169bf5450b33c2;hpb=a92d9d6a21a0f6ca8d2153795721f500eaf29ee9;p=controller.git diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGenerator.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGenerator.java index e40ca8b18b..3cbbb28ab4 100644 --- a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGenerator.java +++ b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGenerator.java @@ -12,6 +12,16 @@ 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; import org.apache.commons.io.FileUtils; import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; @@ -22,6 +32,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; @@ -29,13 +40,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.impl.StaticLoggerBinder; -import java.io.File; -import java.io.IOException; -import java.util.*; -import java.util.Map.Entry; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - /** * This class interfaces with yang-maven-plugin. Gets parsed yang modules in * {@link SchemaContext}, and parameters form the plugin configuration, and @@ -49,7 +53,7 @@ public class JMXGenerator implements CodeGenerator { private PackageTranslator packageTranslator; private final CodeWriter codeWriter; - private static final Logger logger = LoggerFactory + private static final Logger LOG = LoggerFactory .getLogger(JMXGenerator.class); private Map namespaceToPackageMapping; private File resourceBaseDir; @@ -57,7 +61,7 @@ public class JMXGenerator implements CodeGenerator { private boolean generateModuleFactoryFile = true; public JMXGenerator() { - this.codeWriter = new FreeMarkerCodeWriterImpl(); + this.codeWriter = new CodeWriter(); } public JMXGenerator(CodeWriter codeWriter) { @@ -66,7 +70,7 @@ public class JMXGenerator implements CodeGenerator { @Override public Collection generateSources(SchemaContext context, - File outputBaseDir, Set yangModulesInCurrentMavenModule) { + File outputBaseDir, Set yangModulesInCurrentMavenModule) { Preconditions.checkArgument(context != null, "Null context received"); Preconditions.checkArgument(outputBaseDir != null, @@ -78,28 +82,30 @@ public class JMXGenerator implements CodeGenerator { packageTranslator = new PackageTranslator(namespaceToPackageMapping); - if (!outputBaseDir.exists()) + if (!outputBaseDir.exists()) { outputBaseDir.mkdirs(); + } GeneratedFilesTracker generatedFiles = new GeneratedFilesTracker(); + // create SIE structure qNamesToSIEs Map qNamesToSIEs = new HashMap<>(); - // create SIE structure qNamesToSIEs + + Map knownSEITracker = new HashMap<>(); for (Module module : context.getModules()) { String packageName = packageTranslator.getPackageName(module); Map namesToSIEntries = ServiceInterfaceEntry - .create(module, packageName); + .create(module, packageName, knownSEITracker); for (Entry 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)) { @@ -121,7 +127,7 @@ public class JMXGenerator implements CodeGenerator { Preconditions.checkNotNull(resourceBaseDir, "resource base dir attribute was null"); - StringBuffer fullyQualifiedNamesOfFactories = new StringBuffer(); + StringBuilder fullyQualifiedNamesOfFactories = new StringBuilder(); // create MBEs for (Module module : yangModulesInCurrentMavenModule) { String packageName = packageTranslator.getPackageName(module); @@ -134,7 +140,7 @@ public class JMXGenerator implements CodeGenerator { ModuleMXBeanEntry mbe = mbeEntry.getValue(); try { List files1 = codeWriter.writeMbe(mbe, outputBaseDir, - mainBaseDir, resourceBaseDir); + mainBaseDir); generatedFiles.addFile(files1); } catch (Exception e) { throw new RuntimeException( @@ -160,7 +166,7 @@ public class JMXGenerator implements CodeGenerator { fullyQualifiedNamesOfFactories.toString()); } catch (IOException e) { String message = "Cannot write to " + serviceLoaderFile; - logger.error(message); + LOG.error(message); throw new RuntimeException(message, e); } } @@ -178,10 +184,11 @@ public class JMXGenerator implements CodeGenerator { @Override public void setAdditionalConfig(Map additionalCfg) { - if (logger != null) - logger.debug(getClass().getCanonicalName(), + if (LOG != null) { + LOG.debug(getClass().getCanonicalName(), ": Additional configuration received: ", additionalCfg.toString()); + } this.namespaceToPackageMapping = extractNamespaceMapping(additionalCfg); this.generateModuleFactoryFile = extractModuleFactoryBoolean(additionalCfg); } @@ -189,16 +196,18 @@ public class JMXGenerator implements CodeGenerator { private boolean extractModuleFactoryBoolean( Map additionalCfg) { String bool = additionalCfg.get(MODULE_FACTORY_FILE_BOOLEAN); - if (bool == null) + if (bool == null) { return true; - if (bool.equals("false")) + } + if ("false".equals(bool)) { return false; + } return true; } @Override public void setLog(Log log) { - StaticLoggerBinder.getSingleton().setLog(log); + StaticLoggerBinder.getSingleton().setMavenLog(log); } private static Map extractNamespaceMapping( @@ -244,8 +253,8 @@ public class JMXGenerator implements CodeGenerator { public void setMavenProject(MavenProject project) { this.projectBaseDir = project.getBasedir(); - if (logger != null) - logger.debug(getClass().getCanonicalName(), " project base dir: ", + if (LOG != null) + LOG.debug(getClass().getCanonicalName(), " project base dir: ", projectBaseDir); } @@ -262,7 +271,7 @@ public class JMXGenerator implements CodeGenerator { } } if (undeletedFiles.isEmpty() == false) { - logger.error( + LOG.error( "Illegal state occurred: Unable to delete already generated files, undeleted files: {}", undeletedFiles); }