From 651de0e48b806dd76e656aa01b929205994cceec Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 13 Mar 2015 13:11:50 +0100 Subject: [PATCH] BUG-2839: remove dependencies on commons-io Replaces uses of IOUtils methods with guava/JDK equivalents. Change-Id: I16ece0feec2f4dc84c3be91ec675a0294cffcffb Signed-off-by: Robert Varga --- opendaylight/config/config-manager/pom.xml | 5 ----- .../impl/osgi/ModuleFactoryBundleTracker.java | 15 ++++++--------- .../osgi/mapping/ModuleInfoBundleTracker.java | 15 +++++++-------- .../NetconfRemoteSchemaYangSourceProvider.java | 6 +++--- .../netconf/config-persister-impl/pom.xml | 5 ----- ...pabilityStrippingConfigSnapshotHolderTest.java | 8 ++++---- opendaylight/netconf/netconf-impl/pom.xml | 5 ----- .../netconf/impl/ConcurrentClientsTest.java | 7 +++---- .../netconf/it/AbstractNetconfConfigTest.java | 5 ++--- opendaylight/netconf/netconf-tcp/pom.xml | 4 ---- 10 files changed, 25 insertions(+), 50 deletions(-) diff --git a/opendaylight/config/config-manager/pom.xml b/opendaylight/config/config-manager/pom.xml index 3ebffc65a2..71f2cabb63 100644 --- a/opendaylight/config/config-manager/pom.xml +++ b/opendaylight/config/config-manager/pom.xml @@ -26,11 +26,6 @@ guava - - commons-io - commons-io - - org.opendaylight.yangtools diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ModuleFactoryBundleTracker.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ModuleFactoryBundleTracker.java index cc71370c95..cd72a73ecf 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ModuleFactoryBundleTracker.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ModuleFactoryBundleTracker.java @@ -8,12 +8,11 @@ package org.opendaylight.controller.config.manager.impl.osgi; import static java.lang.String.format; - import com.google.common.annotations.VisibleForTesting; -import java.io.InputStream; +import com.google.common.base.Charsets; +import com.google.common.io.Resources; +import java.io.IOException; import java.net.URL; -import java.util.List; -import org.apache.commons.io.IOUtils; import org.opendaylight.controller.config.spi.ModuleFactory; import org.osgi.framework.Bundle; import org.osgi.framework.BundleEvent; @@ -22,7 +21,6 @@ import org.osgi.util.tracker.BundleTrackerCustomizer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - /** * OSGi extender that listens for bundle activation events. Reads file * META-INF/services/org.opendaylight.controller.config.spi.ModuleFactory, each @@ -46,12 +44,11 @@ public class ModuleFactoryBundleTracker implements BundleTrackerCustomizer lines = IOUtils.readLines(inputStream); - for (String factoryClassName : lines) { + try { + for (String factoryClassName : Resources.readLines(resource, Charsets.UTF_8)) { registerFactory(factoryClassName, bundle); } - } catch (Exception e) { + } catch (IOException e) { LOG.error("Error while reading {}", resource, e); throw new RuntimeException(e); } diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/mapping/ModuleInfoBundleTracker.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/mapping/ModuleInfoBundleTracker.java index 2a2a7784eb..56535e797b 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/mapping/ModuleInfoBundleTracker.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/mapping/ModuleInfoBundleTracker.java @@ -8,13 +8,13 @@ package org.opendaylight.controller.config.manager.impl.osgi.mapping; import static java.lang.String.format; - -import java.io.InputStream; +import com.google.common.base.Charsets; +import com.google.common.io.Resources; +import java.io.IOException; import java.net.URL; import java.util.Collection; import java.util.LinkedList; import java.util.List; -import org.apache.commons.io.IOUtils; import org.opendaylight.yangtools.concepts.ObjectRegistration; import org.opendaylight.yangtools.sal.binding.generator.api.ModuleInfoRegistry; import org.opendaylight.yangtools.yang.binding.YangModelBindingProvider; @@ -50,18 +50,17 @@ public final class ModuleInfoBundleTracker implements BundleTrackerCustomizer> registrations = new LinkedList<>(); - try (InputStream inputStream = resource.openStream()) { - List lines = IOUtils.readLines(inputStream); - for (String moduleInfoName : lines) { + try { + for (String moduleInfoName : Resources.readLines(resource, Charsets.UTF_8)) { LOG.trace("Retrieve ModuleInfo({}, {})", moduleInfoName, bundle); YangModuleInfo moduleInfo = retrieveModuleInfo(moduleInfoName, bundle); registrations.add(moduleInfoRegistry.registerModuleInfo(moduleInfo)); } - - } catch (Exception e) { + } catch (IOException e) { LOG.error("Error while reading {}", resource, e); throw new RuntimeException(e); } + LOG.trace("Got following registrations {}", registrations); return registrations; } diff --git a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/schema/NetconfRemoteSchemaYangSourceProvider.java b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/schema/NetconfRemoteSchemaYangSourceProvider.java index a103bbb9f0..ad82c716ce 100644 --- a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/schema/NetconfRemoteSchemaYangSourceProvider.java +++ b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/schema/NetconfRemoteSchemaYangSourceProvider.java @@ -10,7 +10,7 @@ package org.opendaylight.controller.sal.connect.netconf.schema; import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.GET_SCHEMA_QNAME; import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_DATA_QNAME; import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.toId; - +import com.google.common.base.Charsets; import com.google.common.base.Function; import com.google.common.base.MoreObjects; import com.google.common.base.Optional; @@ -18,10 +18,10 @@ import com.google.common.base.Preconditions; import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import javax.xml.transform.dom.DOMSource; -import org.apache.commons.io.IOUtils; import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult; import org.opendaylight.controller.md.sal.dom.api.DOMRpcService; import org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil; @@ -201,7 +201,7 @@ public final class NetconfRemoteSchemaYangSourceProvider implements SchemaSource @Override public InputStream openStream() throws IOException { - return IOUtils.toInputStream(schemaString.get()); + return new ByteArrayInputStream(schemaString.get().getBytes(Charsets.UTF_8)); } } } diff --git a/opendaylight/netconf/config-persister-impl/pom.xml b/opendaylight/netconf/config-persister-impl/pom.xml index 2b297fbadd..9d0fdc0e87 100644 --- a/opendaylight/netconf/config-persister-impl/pom.xml +++ b/opendaylight/netconf/config-persister-impl/pom.xml @@ -51,11 +51,6 @@ test-jar test - - commons-io - commons-io - test - org.opendaylight.controller config-persister-directory-xml-adapter diff --git a/opendaylight/netconf/config-persister-impl/src/test/java/org/opendaylight/controller/netconf/persist/impl/CapabilityStrippingConfigSnapshotHolderTest.java b/opendaylight/netconf/config-persister-impl/src/test/java/org/opendaylight/controller/netconf/persist/impl/CapabilityStrippingConfigSnapshotHolderTest.java index b22924a722..554e13487b 100644 --- a/opendaylight/netconf/config-persister-impl/src/test/java/org/opendaylight/controller/netconf/persist/impl/CapabilityStrippingConfigSnapshotHolderTest.java +++ b/opendaylight/netconf/config-persister-impl/src/test/java/org/opendaylight/controller/netconf/persist/impl/CapabilityStrippingConfigSnapshotHolderTest.java @@ -8,12 +8,12 @@ package org.opendaylight.controller.netconf.persist.impl; import static org.junit.Assert.assertEquals; - +import com.google.common.base.Charsets; import com.google.common.collect.Sets; +import com.google.common.io.Resources; import java.io.IOException; import java.util.HashSet; import java.util.Set; -import org.apache.commons.io.IOUtils; import org.junit.Test; import org.opendaylight.controller.netconf.util.xml.XmlUtil; import org.w3c.dom.Element; @@ -36,11 +36,11 @@ public class CapabilityStrippingConfigSnapshotHolderTest { } private Set readLines(String fileName) throws IOException { - return new HashSet<>(IOUtils.readLines(getClass().getResourceAsStream(fileName))); + return new HashSet<>(Resources.readLines(getClass().getResource(fileName), Charsets.UTF_8)); } private String readToString(String fileName) throws IOException { - return IOUtils.toString(getClass().getResourceAsStream(fileName)); + return Resources.toString(getClass().getResource(fileName), Charsets.UTF_8); } } diff --git a/opendaylight/netconf/netconf-impl/pom.xml b/opendaylight/netconf/netconf-impl/pom.xml index 6f19731f01..5d880c52c9 100644 --- a/opendaylight/netconf/netconf-impl/pom.xml +++ b/opendaylight/netconf/netconf-impl/pom.xml @@ -89,11 +89,6 @@ test-jar test - - commons-io - commons-io - test - xmlunit diff --git a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java index 512a127d22..f20bbda75e 100644 --- a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java +++ b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java @@ -16,10 +16,10 @@ import static org.mockito.Matchers.anySetOf; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; - import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import com.google.common.collect.Sets; +import com.google.common.io.ByteStreams; import io.netty.channel.ChannelFuture; import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; @@ -42,7 +42,6 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicLong; -import org.apache.commons.io.IOUtils; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; @@ -330,11 +329,11 @@ public class ConcurrentClientsTest { } LOG.info(sb.toString()); - outToServer.write(IOUtils.toByteArray(clientHello)); + outToServer.write(ByteStreams.toByteArray(clientHello)); outToServer.write("]]>]]>".getBytes()); outToServer.flush(); // Thread.sleep(100); - outToServer.write(IOUtils.toByteArray(getConfig)); + outToServer.write(ByteStreams.toByteArray(getConfig)); outToServer.write("]]>]]>".getBytes()); outToServer.flush(); Thread.sleep(100); diff --git a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/AbstractNetconfConfigTest.java b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/AbstractNetconfConfigTest.java index c2812dbf61..7cdcb1bd28 100644 --- a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/AbstractNetconfConfigTest.java +++ b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/AbstractNetconfConfigTest.java @@ -14,7 +14,7 @@ import static org.mockito.Matchers.anySetOf; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; - +import com.google.common.io.ByteStreams; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.EventLoopGroup; @@ -34,7 +34,6 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.concurrent.TimeUnit; -import org.apache.commons.io.IOUtils; import org.junit.After; import org.junit.Before; import org.opendaylight.controller.config.manager.impl.AbstractConfigTest; @@ -262,7 +261,7 @@ public abstract class AbstractNetconfConfigTest extends AbstractConfigTest { assertNotNull(inputStream); final byte[] content; try { - content = IOUtils.toByteArray(inputStream); + content = ByteStreams.toByteArray(inputStream); } catch (IOException e) { throw new IllegalStateException("Cannot read " + inputStream, e); } diff --git a/opendaylight/netconf/netconf-tcp/pom.xml b/opendaylight/netconf/netconf-tcp/pom.xml index cf230831b5..0a3ea5485d 100644 --- a/opendaylight/netconf/netconf-tcp/pom.xml +++ b/opendaylight/netconf/netconf-tcp/pom.xml @@ -27,10 +27,6 @@ ${project.groupId} netconf-util - - commons-io - commons-io - org.slf4j slf4j-api -- 2.36.6