Bug 8153: Enforce check-style rules for netconf - netconf-tcp 74/55974/2
authormatus.kubica <matus.kubica@pantheon.tech>
Tue, 25 Apr 2017 10:49:43 +0000 (12:49 +0200)
committerTomas Cere <tcere@cisco.com>
Thu, 27 Apr 2017 12:58:22 +0000 (12:58 +0000)
    Organize Imports for Checkstyle compliance.
    Checkstyle compliance: line length.
    Checkstyle compliance: various types of small changes.
    Checkstyle compliant Exception handling.
    Checkstyle final clean up & enforcement.
    Add the fail on violation flag into the pom.xml .

Change-Id: Ib65a129cf1f715c4ba37c70a177eea021090eac6
Signed-off-by: matus.kubica <matus.kubica@pantheon.tech>
netconf/netconf-tcp/pom.xml
netconf/netconf-tcp/src/main/java/org/opendaylight/netconf/tcp/NetconfNorthboundTcpServer.java
netconf/netconf-tcp/src/main/java/org/opendaylight/netconf/tcp/netty/ProxyClientHandler.java [new file with mode: 0644]
netconf/netconf-tcp/src/main/java/org/opendaylight/netconf/tcp/netty/ProxyServerHandler.java
netconf/netconf-tcp/src/main/java/org/opendaylight/netconf/tcp/osgi/NetconfTCPActivator.java

index 6d0b9fb0fd68d3752befc248ee3ab3f3588755fa..9466d17e301835a3cc11612778d873991738e646 100644 (file)
           </instructions>
         </configuration>
       </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-checkstyle-plugin</artifactId>
+        <configuration>
+          <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+        </configuration>
+      </plugin>
     </plugins>
   </build>
 
index 5792ebb61e31c805b2678afb9cfde6959ca8dc22..f45f7ba80f5a073328ad612b53364926e03d244d 100644 (file)
@@ -44,8 +44,8 @@ public class NetconfNorthboundTcpServer implements AutoCloseable {
     private InetSocketAddress getInetAddress(final String bindingAddress, final String portNumber) {
         try {
             IpAddress ipAddress = IpAddressBuilder.getDefaultInstance(bindingAddress);
-            final InetAddress inetAd = InetAddress.getByName(ipAddress.getIpv4Address() == null ?
-                    ipAddress.getIpv6Address().getValue() : ipAddress.getIpv4Address().getValue());
+            final InetAddress inetAd = InetAddress.getByName(ipAddress.getIpv4Address() == null
+                    ipAddress.getIpv6Address().getValue() : ipAddress.getIpv4Address().getValue());
             return new InetSocketAddress(inetAd, Integer.valueOf(portNumber));
         } catch (final UnknownHostException e) {
             throw new IllegalArgumentException("Unable to bind netconf tcp endpoint to address " + bindingAddress, e);
diff --git a/netconf/netconf-tcp/src/main/java/org/opendaylight/netconf/tcp/netty/ProxyClientHandler.java b/netconf/netconf-tcp/src/main/java/org/opendaylight/netconf/tcp/netty/ProxyClientHandler.java
new file mode 100644 (file)
index 0000000..2cde077
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netconf.tcp.netty;
+
+import static com.google.common.base.Preconditions.checkState;
+
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+class ProxyClientHandler extends ChannelInboundHandlerAdapter {
+    private static final Logger LOG = LoggerFactory.getLogger(ProxyClientHandler.class);
+
+    private final ChannelHandlerContext remoteCtx;
+    private ChannelHandlerContext localCtx;
+
+    ProxyClientHandler(ChannelHandlerContext remoteCtx) {
+        this.remoteCtx = remoteCtx;
+    }
+
+    @Override
+    public void channelActive(ChannelHandlerContext ctx) {
+        checkState(this.localCtx == null);
+        LOG.trace("Client channel active");
+        this.localCtx = ctx;
+    }
+
+    @Override
+    public void channelRead(ChannelHandlerContext ctx, Object msg) {
+        LOG.trace("Forwarding message");
+        remoteCtx.write(msg);
+    }
+
+    @Override
+    public void channelReadComplete(ChannelHandlerContext ctx) {
+        LOG.trace("Flushing remote ctx");
+        remoteCtx.flush();
+    }
+
+    @Override
+    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
+        // Close the connection when an exception is raised.
+        LOG.warn("Unexpected exception from downstream", cause);
+        checkState(this.localCtx.equals(ctx));
+        ctx.close();
+    }
+
+    // called both when local or remote connection dies
+    @Override
+    public void channelInactive(ChannelHandlerContext ctx) {
+        LOG.trace("channelInactive() called, closing remote client ctx");
+        remoteCtx.close();
+    }
+
+}
index 971fd1592c67aa11a8c47892a1bdc2f0869f976f..4731b0fed965b899fc36fb35cf8b174c41697021 100644 (file)
@@ -8,8 +8,6 @@
 
 package org.opendaylight.netconf.tcp.netty;
 
-import static com.google.common.base.Preconditions.checkState;
-
 import io.netty.bootstrap.Bootstrap;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
@@ -72,48 +70,3 @@ public class ProxyServerHandler extends ChannelInboundHandlerAdapter {
     }
 }
 
-class ProxyClientHandler extends ChannelInboundHandlerAdapter {
-    private static final Logger LOG = LoggerFactory.getLogger(ProxyClientHandler.class);
-
-    private final ChannelHandlerContext remoteCtx;
-    private ChannelHandlerContext localCtx;
-
-    public ProxyClientHandler(ChannelHandlerContext remoteCtx) {
-        this.remoteCtx = remoteCtx;
-    }
-
-    @Override
-    public void channelActive(ChannelHandlerContext ctx) {
-        checkState(this.localCtx == null);
-        LOG.trace("Client channel active");
-        this.localCtx = ctx;
-    }
-
-    @Override
-    public void channelRead(ChannelHandlerContext ctx, Object msg) {
-        LOG.trace("Forwarding message");
-        remoteCtx.write(msg);
-    }
-
-    @Override
-    public void channelReadComplete(ChannelHandlerContext ctx) {
-        LOG.trace("Flushing remote ctx");
-        remoteCtx.flush();
-    }
-
-    @Override
-    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
-        // Close the connection when an exception is raised.
-        LOG.warn("Unexpected exception from downstream", cause);
-        checkState(this.localCtx.equals(ctx));
-        ctx.close();
-    }
-
-    // called both when local or remote connection dies
-    @Override
-    public void channelInactive(ChannelHandlerContext ctx) {
-        LOG.trace("channelInactive() called, closing remote client ctx");
-        remoteCtx.close();
-    }
-
-}
index 232d9177846634e76ee4680fbbc5daadd98af5c4..d95d2b84a2a793bce5f9b10309385e3695bd3c88 100644 (file)
@@ -32,8 +32,8 @@ public class NetconfTCPActivator implements BundleActivator {
         final InetSocketAddress address = netconfConfiguration.getTcpServerAddress();
 
         if (address.getAddress().isAnyLocalAddress()) {
-            LOG.warn("Unprotected netconf TCP address is configured to ANY local address. This is a security risk. " +
-                            "Consider changing tcp-address in netconf.cfg to 127.0.0.1");
+            LOG.warn("Unprotected netconf TCP address is configured to ANY local address. This is a security risk. "
+                    + "Consider changing tcp-address in netconf.cfg to 127.0.0.1");
         }
         LOG.info("Starting TCP netconf server at {}", address);
         proxyServer = new ProxyServer(address, NetconfConfiguration.NETCONF_LOCAL_ADDRESS);