import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
+import com.google.common.io.Files;
import java.io.File;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.apache.commons.io.FileUtils;
import org.apache.maven.project.MavenProject;
import org.opendaylight.controller.config.spi.ModuleFactory;
import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
private static final Logger LOG = LoggerFactory.getLogger(JMXGenerator.class);
private static final Pattern NAMESPACE_MAPPING_PATTERN = Pattern.compile("(.+)" + NAMESPACE_TO_PACKAGE_DIVIDER + "(.+)");
- private PackageTranslator packageTranslator;
private final CodeWriter codeWriter;
private Map<String, String> namespaceToPackageMapping;
private File resourceBaseDir;
.checkArgument(namespaceToPackageMapping != null && !namespaceToPackageMapping.isEmpty(),
"No namespace to package mapping provided in additionalConfiguration");
- packageTranslator = new PackageTranslator(namespaceToPackageMapping);
+ PackageTranslator packageTranslator = new PackageTranslator(namespaceToPackageMapping);
if (!outputBaseDir.exists()) {
outputBaseDir.mkdirs();
for (Entry<QName, ServiceInterfaceEntry> sieEntry : namesToSIEntries
.entrySet()) {
// merge value into qNamesToSIEs
- if (qNamesToSIEs.containsKey(sieEntry.getKey()) == false) {
- qNamesToSIEs.put(sieEntry.getKey(), sieEntry.getValue());
- } else {
+ if (qNamesToSIEs.put(sieEntry.getKey(), sieEntry.getValue()) != null) {
throw new IllegalStateException(
- "Cannot add two SIE with same qname "
+ "Cannot add two SIE with same qname "
+ sieEntry.getValue());
}
}
serviceLoaderFile.getParentFile().mkdirs();
try {
serviceLoaderFile.createNewFile();
- FileUtils.write(serviceLoaderFile,
- fullyQualifiedNamesOfFactories.toString());
+ Files.write(fullyQualifiedNamesOfFactories.toString(), serviceLoaderFile, StandardCharsets.UTF_8);
} catch (IOException e) {
String message = "Cannot write to " + serviceLoaderFile;
- LOG.error(message);
+ LOG.error(message, e);
throw new RuntimeException(message, e);
}
}
@VisibleForTesting
static File concatFolders(final File projectBaseDir, final String... folderNames) {
- StringBuilder b = new StringBuilder();
- for (String folder : folderNames) {
- b.append(folder);
- b.append(File.separator);
+ File result = projectBaseDir;
+ for (String folder: folderNames) {
+ result = new File(result, folder);
}
- return new File(projectBaseDir, b.toString());
+ return result;
}
@Override
this.generateModuleFactoryFile = extractModuleFactoryBoolean(additionalCfg);
}
- private boolean extractModuleFactoryBoolean(
- final Map<String, String> additionalCfg) {
+ private static 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;
+ return !"false".equals(bool);
}
private static Map<String, String> extractNamespaceMapping(
if (files.contains(file)) {
List<File> undeletedFiles = Lists.newArrayList();
for (File presentFile : files) {
- if (presentFile.delete() == false) {
+ if (!presentFile.delete()) {
undeletedFiles.add(presentFile);
}
}
- if (undeletedFiles.isEmpty() == false) {
+ if (!undeletedFiles.isEmpty()) {
LOG.error(
"Illegal state occurred: Unable to delete already generated files, undeleted files: {}",
undeletedFiles);