From: Tomas Cere Date: Tue, 2 Jun 2015 14:36:57 +0000 (+0200) Subject: BUG 2839: Config: remove dependencies on commons-io X-Git-Tag: release/beryllium~437 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=b2a7e1a511100f0512095da585c2b717bb0101b5;hp=eab5d830cad56a1bb3c796e0aae8f1bb1974499a BUG 2839: Config: remove dependencies on commons-io Migrated commons-io users to guava and custom solutions when there were no alternatives in guava. Change-Id: I399030df1fbd7ea6e40b2591346802068e32f681 Signed-off-by: Tomas Cere --- diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/AbstractConfigTest.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/AbstractConfigTest.java index 30da27f1a1..ab44bb3495 100644 --- a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/AbstractConfigTest.java +++ b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/AbstractConfigTest.java @@ -14,6 +14,8 @@ import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; import com.google.common.base.Preconditions; +import java.io.File; +import java.io.IOException; import java.lang.management.ManagementFactory; import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; @@ -288,4 +290,27 @@ public abstract class AbstractConfigTest extends return (T) proxy; } + /** + * removes contents of the directory + * @param dir to be cleaned + * @throws IOException + */ + protected void cleanDirectory(File dir) throws IOException { + if (!dir.isDirectory()) { + throw new IllegalStateException("dir must be a directory"); + } + + final File[] files = dir.listFiles(); + if (files == null) { + throw new IOException("Failed to list contents of " + dir); + } + + for (File file : files) { + if (file.isDirectory()) { + cleanDirectory(dir); + } + file.delete(); + } + } + } diff --git a/opendaylight/config/config-persister-directory-xml-adapter/pom.xml b/opendaylight/config/config-persister-directory-xml-adapter/pom.xml index accf9600b4..9a49ffbed4 100644 --- a/opendaylight/config/config-persister-directory-xml-adapter/pom.xml +++ b/opendaylight/config/config-persister-directory-xml-adapter/pom.xml @@ -21,10 +21,6 @@ com.google.guava guava - - commons-io - commons-io - org.apache.commons commons-lang3 @@ -77,7 +73,6 @@ org.opendaylight.controller.config.persister.storage.adapter com.google.common.base, com.google.common.io, - org.apache.commons.io, org.opendaylight.controller.config.persist.api, org.slf4j, com.google.common.collect, diff --git a/opendaylight/config/logback-config/pom.xml b/opendaylight/config/logback-config/pom.xml index 82e1fa8ea3..4bc76211c6 100644 --- a/opendaylight/config/logback-config/pom.xml +++ b/opendaylight/config/logback-config/pom.xml @@ -30,10 +30,6 @@ com.google.guava guava - - commons-io - commons-io - org.apache.commons commons-lang3 diff --git a/opendaylight/config/logback-config/src/test/java/org/opendaylight/controller/config/yang/logback/config/LogbackModuleWithInitialConfigurationTest.java b/opendaylight/config/logback-config/src/test/java/org/opendaylight/controller/config/yang/logback/config/LogbackModuleWithInitialConfigurationTest.java index 999d8346e6..f467bc504d 100644 --- a/opendaylight/config/logback-config/src/test/java/org/opendaylight/controller/config/yang/logback/config/LogbackModuleWithInitialConfigurationTest.java +++ b/opendaylight/config/logback-config/src/test/java/org/opendaylight/controller/config/yang/logback/config/LogbackModuleWithInitialConfigurationTest.java @@ -28,7 +28,6 @@ import javax.management.InstanceNotFoundException; import javax.management.JMX; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; -import org.apache.commons.io.FileUtils; import org.junit.Before; import org.junit.Test; import org.opendaylight.controller.config.api.ConflictingVersionException; @@ -151,8 +150,9 @@ public class LogbackModuleWithInitialConfigurationTest extends AbstractConfigTes configurator.setContext(lc); configurator.doConfigure("src/test/resources/simple_config_logback.xml"); File f = new File("target/it"); - if (f.exists()) - FileUtils.cleanDirectory(f); + if (f.exists()) { + cleanDirectory(f); + } ch.qos.logback.classic.Logger logger = lc.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME); ch.qos.logback.core.rolling.RollingFileAppender fileAppender = (ch.qos.logback.core.rolling.RollingFileAppender) logger .getAppender("VARLOGFILE"); diff --git a/opendaylight/config/logback-config/src/test/java/org/opendaylight/controller/config/yang/logback/config/LogbackWithXmlConfigModuleTest.java b/opendaylight/config/logback-config/src/test/java/org/opendaylight/controller/config/yang/logback/config/LogbackWithXmlConfigModuleTest.java index 9fcd38976e..1c784a938d 100644 --- a/opendaylight/config/logback-config/src/test/java/org/opendaylight/controller/config/yang/logback/config/LogbackWithXmlConfigModuleTest.java +++ b/opendaylight/config/logback-config/src/test/java/org/opendaylight/controller/config/yang/logback/config/LogbackWithXmlConfigModuleTest.java @@ -22,7 +22,6 @@ import javax.management.InstanceNotFoundException; import javax.management.JMX; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; -import org.apache.commons.io.FileUtils; import org.junit.Before; import org.junit.Test; import org.opendaylight.controller.config.api.ConflictingVersionException; @@ -50,7 +49,7 @@ public class LogbackWithXmlConfigModuleTest extends AbstractConfigTest { configurator.doConfigure("src/test/resources/simple_config_logback.xml"); File f = new File("target/it"); if (f.exists()) - FileUtils.cleanDirectory(f); + cleanDirectory(f); } /** diff --git a/opendaylight/config/yang-jmx-generator-plugin/pom.xml b/opendaylight/config/yang-jmx-generator-plugin/pom.xml index 0b08ba3f5d..7e1a7c52fa 100644 --- a/opendaylight/config/yang-jmx-generator-plugin/pom.xml +++ b/opendaylight/config/yang-jmx-generator-plugin/pom.xml @@ -21,11 +21,6 @@ guava - - commons-io - commons-io - - org.apache.commons commons-lang3 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 1f1776f0a5..4ad8fd79c4 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,8 +12,10 @@ 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 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; @@ -22,7 +24,6 @@ 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.project.MavenProject; import org.opendaylight.controller.config.spi.ModuleFactory; import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry; @@ -173,8 +174,7 @@ public class JMXGenerator implements BasicCodeGenerator, MavenProjectAware { 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); diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/java/GeneratedObject.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/java/GeneratedObject.java index 4d8bd3e5b4..5eb58d5a1e 100644 --- a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/java/GeneratedObject.java +++ b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/java/GeneratedObject.java @@ -4,10 +4,11 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.Optional; import com.google.common.collect.Maps; +import com.google.common.io.Files; import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.Map.Entry; -import org.apache.commons.io.FileUtils; import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.StringUtil; public class GeneratedObject { @@ -30,8 +31,10 @@ public class GeneratedObject { public Optional> persist(File srcDirectory, boolean overwrite) throws IOException { File dstFile = fqn.toFile(srcDirectory); - if (overwrite == true || dstFile.exists() == false) { - FileUtils.write(dstFile, content); + if (overwrite || !dstFile.exists()) { + Files.createParentDirs(dstFile); + Files.touch(dstFile); + Files.write(content, dstFile, StandardCharsets.UTF_8); return Optional.of(Maps.immutableEntry(fqn, dstFile)); } else { return Optional.absent(); @@ -60,11 +63,8 @@ public class GeneratedObject { GeneratedObject that = (GeneratedObject) o; - if (!fqn.equals(that.fqn)) { - return false; - } + return fqn.equals(that.fqn); - return true; } @Override diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/AbstractGeneratorTest.java b/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/AbstractGeneratorTest.java index 2eae8b6b09..fb5cd2e989 100644 --- a/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/AbstractGeneratorTest.java +++ b/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/AbstractGeneratorTest.java @@ -8,7 +8,6 @@ package org.opendaylight.controller.config.yangjmxgenerator.plugin; import java.io.File; -import org.apache.commons.io.FileUtils; import org.junit.Before; import org.opendaylight.controller.config.yangjmxgenerator.AbstractYangTest; @@ -24,7 +23,21 @@ public abstract class AbstractGeneratorTest extends AbstractYangTest { @Before public void cleanUpDirectory() throws Exception { - FileUtils.deleteDirectory(generatorOutputPath); + deleteFolder(generatorOutputPath); + } + + public void deleteFolder(File folder) { + File[] files = folder.listFiles(); + if (files != null) { + for (File f: files) { + if (f.isDirectory()) { + deleteFolder(f); + } else { + f.delete(); + } + } + } + folder.delete(); } } diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGeneratorTest.java b/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGeneratorTest.java index 56cd615a39..c7a12a3917 100644 --- a/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGeneratorTest.java +++ b/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGeneratorTest.java @@ -18,6 +18,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; + import com.google.common.base.Predicate; import com.google.common.collect.Collections2; import com.google.common.collect.Lists; @@ -27,6 +28,7 @@ import com.google.common.io.Files; import java.io.File; import java.io.IOException; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -38,7 +40,6 @@ import java.util.Map; import java.util.Set; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; -import org.apache.commons.io.FileUtils; import org.apache.maven.project.MavenProject; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.compiler.IProblem; @@ -324,8 +325,8 @@ public class JMXGeneratorTest extends AbstractGeneratorTest { generatedResourcesDir, "META-INF", "services", ModuleFactory.class.getName()); assertThat(moduleFactoryFile.exists(), is(true)); - Set lines = Sets.newHashSet(FileUtils - .readLines(moduleFactoryFile)); + Set lines = Sets.newHashSet(Files + .readLines(moduleFactoryFile, StandardCharsets.UTF_8)); Set expectedLines = Sets.newHashSet(// PackageTranslatorTest.EXPECTED_PACKAGE_PREFIX + ".threads.java.EventBusModuleFactory",// diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/module/AbstractGeneratedObjectTest.java b/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/module/AbstractGeneratedObjectTest.java index c3ca077bcc..34b38bfa50 100644 --- a/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/module/AbstractGeneratedObjectTest.java +++ b/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/module/AbstractGeneratedObjectTest.java @@ -11,14 +11,15 @@ package org.opendaylight.controller.config.yangjmxgenerator.plugin.module; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import com.google.common.io.Files; import java.io.File; import java.io.FileReader; import java.io.IOException; +import java.nio.charset.StandardCharsets; import net.sourceforge.pmd.lang.Parser; import net.sourceforge.pmd.lang.ParserOptions; import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.java.Java17Parser; -import org.apache.commons.io.FileUtils; import org.opendaylight.controller.config.yangjmxgenerator.plugin.AbstractGeneratorTest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,7 +35,7 @@ public class AbstractGeneratedObjectTest extends AbstractGeneratorTest { protected Node parse(File dstFile) throws IOException { assertNotNull(dstFile); - LOG.debug(FileUtils.readFileToString(dstFile)); + LOG.debug(Files.toString(dstFile, StandardCharsets.UTF_8)); Parser parser = new Java17Parser(new ParserOptions()); return parser.parse(dstFile.toString(), new FileReader(dstFile)); } diff --git a/opendaylight/config/yang-test-plugin/pom.xml b/opendaylight/config/yang-test-plugin/pom.xml index b437e77b9d..451e4dce57 100644 --- a/opendaylight/config/yang-test-plugin/pom.xml +++ b/opendaylight/config/yang-test-plugin/pom.xml @@ -14,10 +14,6 @@ Remove generated source files, after new files generation, implementation is inserted. - - commons-io - commons-io - org.apache.maven maven-plugin-api diff --git a/opendaylight/config/yang-test-plugin/src/main/java/org/opendaylight/controller/config/yang/test/plugin/ProcessSources.java b/opendaylight/config/yang-test-plugin/src/main/java/org/opendaylight/controller/config/yang/test/plugin/ProcessSources.java index 4e392304a0..054edffe68 100644 --- a/opendaylight/config/yang-test-plugin/src/main/java/org/opendaylight/controller/config/yang/test/plugin/ProcessSources.java +++ b/opendaylight/config/yang-test-plugin/src/main/java/org/opendaylight/controller/config/yang/test/plugin/ProcessSources.java @@ -7,10 +7,11 @@ */ package org.opendaylight.controller.config.yang.test.plugin; +import com.google.common.io.Files; import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.regex.Pattern; -import org.apache.commons.io.FileUtils; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -46,7 +47,7 @@ public class ProcessSources extends AbstractMojo{ if (sourceFile.getName().endsWith(".java")) { String sourceContent; try { - sourceContent = FileUtils.readFileToString(sourceFile); + sourceContent = Files.toString(sourceFile, StandardCharsets.UTF_8); } catch (IOException e) { getLog().error(String.format("Cannot read %s", sourceFile.getAbsolutePath()), e); continue; @@ -56,7 +57,7 @@ public class ProcessSources extends AbstractMojo{ if (stubFile.exists()) { String stubContent = null; try { - stubContent = FileUtils.readFileToString(stubFile); + stubContent = Files.toString(stubFile, StandardCharsets.UTF_8); } catch (IOException e) { getLog().error(String.format("Cannot read %s", stubFile.getAbsolutePath()), e); } @@ -70,7 +71,7 @@ public class ProcessSources extends AbstractMojo{ // replace the file content try { - FileUtils.write(sourceFile, sourceContent); + Files.write(sourceContent, sourceFile, StandardCharsets.UTF_8); } catch (IOException e) { getLog().error(String.format("Cannot write %s", sourceFile.getAbsolutePath()), e); } diff --git a/opendaylight/md-sal/sal-binding-it/pom.xml b/opendaylight/md-sal/sal-binding-it/pom.xml index 622ce0f9a3..37bf67d193 100644 --- a/opendaylight/md-sal/sal-binding-it/pom.xml +++ b/opendaylight/md-sal/sal-binding-it/pom.xml @@ -119,6 +119,10 @@ pax-exam-link-mvn compile + + commons-io + commons-io + org.slf4j log4j-over-slf4j