X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fyang-jmx-generator-plugin%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyangjmxgenerator%2Fplugin%2Futil%2FStringUtil.java;h=02ab91b817cb20bda841c4cc671076d41cba49da;hp=265aea10c59f8f858fb036b5fb97216ccc404a35;hb=dd65a7ecf4237d0e11e01f71d2184c2bc9de2895;hpb=f776809962df87deeaa533ba995cc6fceba64d0e diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/util/StringUtil.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/util/StringUtil.java index 265aea10c5..02ab91b817 100644 --- a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/util/StringUtil.java +++ b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/util/StringUtil.java @@ -1,22 +1,26 @@ +/* + * Copyright (c) 2013, 2015 Cisco Systems, Inc. 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.controller.config.yangjmxgenerator.plugin.util; import com.google.common.base.Joiner; import com.google.common.base.Optional; import com.google.common.base.Splitter; import com.google.common.base.Strings; -import org.apache.commons.io.IOUtils; +import java.util.List; +import java.util.regex.Pattern; import org.apache.commons.lang3.StringUtils; import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; -import java.io.InputStream; -import java.util.List; -import java.util.regex.Pattern; - public class StringUtil { - private static final Logger logger = LoggerFactory.getLogger(StringUtils.class); + private static final Logger LOG = LoggerFactory.getLogger(StringUtil.class); /** * @param list of strings to be joined by ',' @@ -61,13 +65,18 @@ public class StringUtil { public static Optional loadCopyright() { - try (InputStream in = StringUtil.class.getResourceAsStream("/copyright.txt")) { - if (in != null) { - return Optional.of(IOUtils.toString(in)); + /* + * FIXME: BUG-980: this is a nice feature, but the copyright needs to come + * from the project being processed, not this one. + try (InputStream in = StringUtil.class.getResourceAsStream("/copyright.txt")) { + if (in != null) { + return Optional.of(IOUtils.toString(in)); + } + } catch (IOException e) { + LOG.warn("Cannot load copyright.txt", e); } - } catch (IOException e) { - logger.warn("Cannot load copyright.txt", e); - } + + */ return Optional.absent(); } @@ -76,14 +85,14 @@ public class StringUtil { int basicIndent = 4; StringBuilder sb = new StringBuilder(); - int intends = 0, empty = 0; + int indents = 0, empty = 0; for (String line : split) { - intends -= StringUtils.countMatches(line, "}"); - if (intends < 0) { - intends = 0; + indents -= StringUtils.countMatches(line, "}"); + if (indents < 0) { + indents = 0; } - if (line.isEmpty() == false) { - sb.append(Strings.repeat(" ", basicIndent * intends)); + if (!line.isEmpty()) { + sb.append(Strings.repeat(" ", basicIndent * indents)); sb.append(line); sb.append("\n"); empty = 0; @@ -93,7 +102,7 @@ public class StringUtil { sb.append("\n"); } } - intends += StringUtils.countMatches(line, "{"); + indents += StringUtils.countMatches(line, "{"); } return ensureEndsWithSingleNewLine(sb.toString()); }