import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.apache.maven.project.MavenProject;
import org.opendaylight.controller.config.spi.ModuleFactory;
import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
import org.opendaylight.controller.config.yangjmxgenerator.PackageTranslator;
import org.opendaylight.controller.config.yangjmxgenerator.ServiceInterfaceEntry;
import org.opendaylight.controller.config.yangjmxgenerator.TypeProviderWrapper;
import org.apache.maven.project.MavenProject;
import org.opendaylight.controller.config.spi.ModuleFactory;
import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
import org.opendaylight.controller.config.yangjmxgenerator.PackageTranslator;
import org.opendaylight.controller.config.yangjmxgenerator.ServiceInterfaceEntry;
import org.opendaylight.controller.config.yangjmxgenerator.TypeProviderWrapper;
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.common.QName;
import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
private static final Logger LOG = LoggerFactory.getLogger(JMXGenerator.class);
private static final Pattern NAMESPACE_MAPPING_PATTERN = Pattern.compile("(.+)" + NAMESPACE_TO_PACKAGE_DIVIDER + "(.+)");
private static final Logger LOG = LoggerFactory.getLogger(JMXGenerator.class);
private static final Pattern NAMESPACE_MAPPING_PATTERN = Pattern.compile("(.+)" + NAMESPACE_TO_PACKAGE_DIVIDER + "(.+)");
private final CodeWriter codeWriter;
private Map<String, String> namespaceToPackageMapping;
private File resourceBaseDir;
private final CodeWriter codeWriter;
private Map<String, String> namespaceToPackageMapping;
private File resourceBaseDir;
- Map<IdentitySchemaNode, ServiceInterfaceEntry> knownSEITracker = new HashMap<>();
- for (Module module : context.getModules()) {
- String packageName = packageTranslator.getPackageName(module);
- Map<QName, ServiceInterfaceEntry> namesToSIEntries = ServiceInterfaceEntry
+ final Map<IdentitySchemaNode, ServiceInterfaceEntry> knownSEITracker = new HashMap<>();
+ for (final Module module : context.getModules()) {
+ final String packageName = packageTranslator.getPackageName(module);
+ final Map<QName, ServiceInterfaceEntry> namesToSIEntries = ServiceInterfaceEntry
throw new RuntimeException(
"Error occurred during SIE source generate phase",
e);
throw new RuntimeException(
"Error occurred during SIE source generate phase",
e);
- File mainBaseDir = concatFolders(projectBaseDir, "src", "main", "java");
- Preconditions.checkNotNull(resourceBaseDir,
+ final File mainBaseDir = concatFolders(this.projectBaseDir, "src", "main", "java");
+ Preconditions.checkNotNull(this.resourceBaseDir,
- for (Module module : yangModulesInCurrentMavenModule) {
- String packageName = packageTranslator.getPackageName(module);
- Map<String /* MB identity local name */, ModuleMXBeanEntry> namesToMBEs = ModuleMXBeanEntry
+ for (final Module module : yangModulesInCurrentMavenModule) {
+ final String packageName = packageTranslator.getPackageName(module);
+ final Map<String /* MB identity local name */, ModuleMXBeanEntry> namesToMBEs = ModuleMXBeanEntry
.create(module, qNamesToSIEs, context, new TypeProviderWrapper(new TypeProviderImpl(context)),
packageName);
.create(module, qNamesToSIEs, context, new TypeProviderWrapper(new TypeProviderImpl(context)),
packageName);
throw new RuntimeException(
"Error occurred during MBE source generate phase",
e);
throw new RuntimeException(
"Error occurred during MBE source generate phase",
e);
- if (fullyQualifiedNamesOfFactories.length() > 0
- && generateModuleFactoryFile) {
- File serviceLoaderFile = JMXGenerator.concatFolders(
- resourceBaseDir, "META-INF", "services",
+ if ((fullyQualifiedNamesOfFactories.length() > 0)
+ && this.generateModuleFactoryFile) {
+ final File serviceLoaderFile = JMXGenerator.concatFolders(
+ this.resourceBaseDir, "META-INF", "services",
ModuleFactory.class.getName());
// if this file does not exist, create empty file
serviceLoaderFile.getParentFile().mkdirs();
try {
serviceLoaderFile.createNewFile();
ModuleFactory.class.getName());
// if this file does not exist, create empty file
serviceLoaderFile.getParentFile().mkdirs();
try {
serviceLoaderFile.createNewFile();
- FileUtils.write(serviceLoaderFile,
- fullyQualifiedNamesOfFactories.toString());
- } catch (IOException e) {
- String message = "Cannot write to " + serviceLoaderFile;
- LOG.error(message);
+ Files.write(fullyQualifiedNamesOfFactories.toString(), serviceLoaderFile, StandardCharsets.UTF_8);
+ } catch (final IOException e) {
+ final String message = "Cannot write to " + serviceLoaderFile;
+ LOG.error(message, e);
- StringBuilder b = new StringBuilder();
- for (String folder : folderNames) {
- b.append(folder);
- b.append(File.separator);
+ File result = projectBaseDir;
+ for (final String folder: folderNames) {
+ result = new File(result, folder);
- private boolean extractModuleFactoryBoolean(
- final Map<String, String> additionalCfg) {
- String bool = additionalCfg.get(MODULE_FACTORY_FILE_BOOLEAN);
- if (bool == null) {
- return true;
- }
- if ("false".equals(bool)) {
- return false;
- }
- return true;
+ private static boolean extractModuleFactoryBoolean(final Map<String, String> additionalCfg) {
+ final String bool = additionalCfg.get(MODULE_FACTORY_FILE_BOOLEAN);
+ return !"false".equals(bool);
}
private static Map<String, String> extractNamespaceMapping(
final Map<String, String> additionalCfg) {
}
private static Map<String, String> extractNamespaceMapping(
final Map<String, String> additionalCfg) {
- Map<String, String> namespaceToPackage = Maps.newHashMap();
- for (String key : additionalCfg.keySet()) {
+ final Map<String, String> namespaceToPackage = Maps.newHashMap();
+ for (final String key : additionalCfg.keySet()) {
- String mapping = additionalCfg.get(key);
- NamespaceMapping mappingResolved = extractNamespaceMapping(mapping);
+ final String mapping = additionalCfg.get(key);
+ final NamespaceMapping mappingResolved = extractNamespaceMapping(mapping);
namespaceToPackage.put(mappingResolved.namespace,
mappingResolved.packageName);
}
namespaceToPackage.put(mappingResolved.namespace,
mappingResolved.packageName);
}
Preconditions.checkArgument(matcher.matches(),
"Namespace to package mapping:%s is in invalid format, requested format is: %s",
mapping, NAMESPACE_MAPPING_PATTERN);
Preconditions.checkArgument(matcher.matches(),
"Namespace to package mapping:%s is in invalid format, requested format is: %s",
mapping, NAMESPACE_MAPPING_PATTERN);
@Override
public void setMavenProject(final MavenProject project) {
this.projectBaseDir = project.getBasedir();
@Override
public void setMavenProject(final MavenProject project) {
this.projectBaseDir = project.getBasedir();
- if (files.contains(file)) {
- List<File> undeletedFiles = Lists.newArrayList();
- for (File presentFile : files) {
- if (presentFile.delete() == false) {
+ if (this.files.contains(file)) {
+ final List<File> undeletedFiles = Lists.newArrayList();
+ for (final File presentFile : this.files) {
+ if (!presentFile.delete()) {