ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gin...@apache.org
Subject [1/2] ant-ivy git commit: IVY-309 refactor all those split-trim-join and unwrap some logic
Date Fri, 10 Nov 2017 17:52:41 GMT
Repository: ant-ivy
Updated Branches:
  refs/heads/master cc6ace189 -> f36294048


http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f3629404/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java
index 9c71ea6..c43873e 100644
--- a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java
+++ b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java
@@ -83,6 +83,8 @@ import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
 
 import static org.apache.ivy.core.module.descriptor.Configuration.Visibility.getVisibility;
+import static org.apache.ivy.util.StringUtils.isNullOrEmpty;
+import static org.apache.ivy.util.StringUtils.splitToArray;
 
 /**
  * Parses an xml ivy file and output a ModuleDescriptor. For dependency and performance reasons, it
@@ -412,20 +414,19 @@ public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser {
         protected void extendsStarted(Attributes attributes) throws ParseException {
             String parentOrganisation = settings.substitute(attributes.getValue("organisation"));
             String parentModule = settings.substitute(attributes.getValue("module"));
-            String parentRevision = attributes.getValue("revision") != null ? settings
-                    .substitute(attributes.getValue("revision")) : Ivy.getWorkingRevision();
-            String location = attributes.getValue("location") != null ? settings
-                    .substitute(attributes.getValue("location")) : getDefaultParentLocation();
-            ModuleDescriptor parent = null;
-
-            String extendType = attributes.getValue("extendType") != null ? settings
-                    .substitute(attributes.getValue("extendType").toLowerCase(Locale.US)) : "all";
+            String parentRevision = (attributes.getValue("revision") == null) ? Ivy.getWorkingRevision()
+                    : settings.substitute(attributes.getValue("revision"));
+            String location = (attributes.getValue("location") == null) ? getDefaultParentLocation()
+                    : settings.substitute(attributes.getValue("location"));
+            String extendType = (attributes.getValue("extendType") == null) ? "all"
+                    : settings.substitute(attributes.getValue("extendType").toLowerCase(Locale.US));
 
             List<String> extendTypes = Arrays.asList(extendType.split(","));
             ModuleId parentMid = new ModuleId(parentOrganisation, parentModule);
             ModuleRevisionId parentMrid = new ModuleRevisionId(parentMid, parentRevision);
 
             // check on filesystem based on location attribute (for dev ONLY)
+            ModuleDescriptor parent = null;
             boolean local = false;
             try {
                 parent = parseParentModuleOnFilesystem(location);
@@ -503,9 +504,11 @@ public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser {
                 if (extendTypes.contains("description")) {
                     mergeDescription(parent.getDescription());
                 }
+
                 if (extendTypes.contains("licenses")) {
                     mergeLicenses(parent.getLicenses());
                 }
+
                 if (extendTypes.contains("excludes")) {
                     mergeExcludes(parent.getAllExcludeRules());
                 }
@@ -625,7 +628,7 @@ public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser {
          */
         protected void mergeDescription(String description) {
             String current = getMd().getDescription();
-            if (current == null || current.trim().length() == 0) {
+            if (isNullOrEmpty(current)) {
                 getMd().setDescription(description);
             }
         }
@@ -733,27 +736,23 @@ public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser {
         }
 
         protected void setPublicationsDefaultConf(String defaultConf) {
-            this.publicationsDefaultConf = defaultConf == null ? null : defaultConf.split(",");
+            this.publicationsDefaultConf = (defaultConf == null) ? null : splitToArray(defaultConf);
         }
 
         protected boolean isOtherNamespace(String qName) {
-            return qName.indexOf(':') != -1;
+            return qName.contains(":");
         }
 
         protected void managerStarted(Attributes attributes, String managerAtt) {
             String org = settings.substitute(attributes.getValue("org"));
-            org = org == null ? PatternMatcher.ANY_EXPRESSION : org;
+            org = (org == null) ? PatternMatcher.ANY_EXPRESSION : org;
             String mod = settings.substitute(attributes.getValue("module"));
-            mod = mod == null ? PatternMatcher.ANY_EXPRESSION : mod;
+            mod = (mod == null) ? PatternMatcher.ANY_EXPRESSION : mod;
             ConflictManager cm;
             String name = settings.substitute(attributes.getValue(managerAtt));
             String rev = settings.substitute(attributes.getValue("rev"));
             if (rev != null) {
-                String[] revs = rev.split(",");
-                for (int i = 0; i < revs.length; i++) {
-                    revs[i] = revs[i].trim();
-                }
-                cm = new FixedConflictManager(revs);
+                cm = new FixedConflictManager(splitToArray(rev));
             } else if (name != null) {
                 cm = settings.getConflictManager(name);
                 if (cm == null) {
@@ -864,8 +863,8 @@ public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser {
                     this.conf = conf;
                     String mappeds = settings.substitute(attributes.getValue("mapped"));
                     if (mappeds != null) {
-                        for (String mapped : mappeds.split(",")) {
-                            dd.addDependencyConfiguration(conf, mapped.trim());
+                        for (String mapped : splitToArray(mappeds)) {
+                            dd.addDependencyConfiguration(conf, mapped);
                         }
                     }
                     break;
@@ -961,10 +960,10 @@ public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser {
                 // only if there are no conf defined in sub elements
                 if (confs != null && confs.length() > 0) {
                     String[] configs = "*".equals(confs) ? getMd().getConfigurationsNames()
-                            : confs.split(",");
+                            : splitToArray(confs);
                     for (String config : configs) {
-                        artifact.addConfiguration(config.trim());
-                        getMd().addArtifact(config.trim(), artifact);
+                        artifact.addConfiguration(config);
+                        getMd().addArtifact(config, artifact);
                     }
                 }
             } else if (state == State.DEP) {
@@ -1138,9 +1137,9 @@ public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser {
             // only if there are no conf defined in sub elements
             if (confs != null && confs.length() > 0) {
                 String[] configs = "*".equals(confs) ? getMd().getConfigurationsNames()
-                        : confs.split(",");
+                        : splitToArray(confs);
                 for (String config : configs) {
-                    addConfiguration(config.trim());
+                    addConfiguration(config);
                 }
             }
         }
@@ -1185,11 +1184,11 @@ public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser {
         public void endElement(String uri, String localName, String qName) throws SAXException {
             if (state == State.PUB && "artifact".equals(qName)
                     && artifact.getConfigurations().length == 0) {
-                String[] configs = publicationsDefaultConf == null ? getMd().getConfigurationsNames()
-                        : publicationsDefaultConf;
+                String[] configs = (publicationsDefaultConf == null)
+                        ? getMd().getConfigurationsNames() : publicationsDefaultConf;
                 for (String config : configs) {
-                    artifact.addConfiguration(config.trim());
-                    getMd().addArtifact(config.trim(), artifact);
+                    artifact.addConfiguration(config);
+                    getMd().addArtifact(config, artifact);
                 }
             } else if ("configurations".equals(qName)) {
                 checkConfigurations();

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f3629404/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java
index 60c33b5..3751cf4 100644
--- a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java
+++ b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java
@@ -36,7 +36,6 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Stack;
-import java.util.StringTokenizer;
 
 import javax.xml.parsers.ParserConfigurationException;
 
@@ -66,6 +65,10 @@ import org.xml.sax.SAXParseException;
 import org.xml.sax.ext.LexicalHandler;
 import org.xml.sax.helpers.DefaultHandler;
 
+import static org.apache.ivy.util.StringUtils.isNullOrEmpty;
+import static org.apache.ivy.util.StringUtils.joinArray;
+import static org.apache.ivy.util.StringUtils.splitToArray;
+
 /**
  * Used to update ivy files. Uses ivy file as source and not ModuleDescriptor to preserve as much as
  * possible the original syntax
@@ -464,9 +467,8 @@ public final class XmlModuleDescriptorUpdater {
                 buffers.peek().setPrint(true);
                 String extend = substitute(settings, attributes.getValue("extends"));
                 if (extend != null) {
-                    StringTokenizer tok = new StringTokenizer(extend, ", ");
-                    while (tok.hasMoreTokens()) {
-                        if (confs.contains(tok.nextToken())) {
+                    for (String tok : splitToArray(extend)) {
+                        if (confs.contains(tok)) {
                             throw new IllegalArgumentException(
                                     "Cannot exclude a configuration which is extended.");
                         }
@@ -538,11 +540,12 @@ public final class XmlModuleDescriptorUpdater {
             ExtendedBuffer buffer = new ExtendedBuffer(getContext());
             buffers.push(buffer);
             confAttributeBuffers.push(buffer);
-            buffer.setDefaultPrint(attributes.getValue("conf") == null
-                    || attributes.getValue("conf").trim().length() == 0);
+            buffer.setDefaultPrint(isNullOrEmpty(attributes.getValue("conf")));
             write("<dependency");
             String org = substitute(settings, attributes.getValue("org"));
-            org = org == null ? organisation : org;
+            if (org == null) {
+                org = organisation;
+            }
             String module = substitute(settings, attributes.getValue("name"));
             String branch = substitute(settings, attributes.getValue("branch"));
             String branchConstraint = substitute(settings, attributes.getValue("branchConstraint"));
@@ -623,11 +626,9 @@ public final class XmlModuleDescriptorUpdater {
             }
 
             if (attributes.getIndex("branch") == -1) {
-                if (newBranch != null) {
-                    // erase an existing branch attribute if its new value is blank
-                    if (!newBranch.trim().equals("")) {
-                        write(" branch=\"" + newBranch + "\"");
-                    }
+                // erase an existing branch attribute if its new value is blank
+                if (!isNullOrEmpty(newBranch)) {
+                    write(" branch=\"" + newBranch + "\"");
                 } else if (options.isUpdateBranch() && systemMrid.getBranch() != null) {
                     // this dependency is on a specific branch, we set it explicitly in the updated
                     // file
@@ -689,14 +690,12 @@ public final class XmlModuleDescriptorUpdater {
                                 }
                                 String extend = substitute(settings, attributes.getValue("extends"));
                                 if (extend != null) {
-                                    StringTokenizer tok = new StringTokenizer(extend, ", ");
-                                    while (tok.hasMoreTokens()) {
-                                        if (confs.contains(tok.nextToken())) {
-                                            throw new IllegalArgumentException("Cannot exclude a "
-                                                    + "configuration which is extended.");
+                                    for (String tok : splitToArray(extend)) {
+                                        if (confs.contains(tok)) {
+                                            throw new IllegalArgumentException(
+                                                    "Cannot exclude a configuration which is extended.");
                                         }
                                     }
-
                                 }
 
                                 write("<" + qName);
@@ -824,42 +823,35 @@ public final class XmlModuleDescriptorUpdater {
         }
 
         private String getContext() {
-            StringBuilder buf = new StringBuilder();
-            for (String ctx : context) {
-                buf.append(ctx).append("/");
-            }
-            if (buf.length() > 0) {
-                buf.setLength(buf.length() - 1);
-            }
-            return buf.toString();
+            return joinArray(context.toArray(new String[context.size()]), "/");
         }
 
         private String substitute(ParserSettings ivy, String value) {
-            String result = ivy == null ? value : ivy.substitute(value);
+            String result = (ivy == null) ? value : ivy.substitute(value);
             return XMLHelper.escape(result);
         }
 
         private String removeConfigurationsFromMapping(String mapping, List<String> confsToRemove) {
             StringBuilder newMapping = new StringBuilder();
             String mappingSep = "";
-            StringTokenizer tokenizer = new StringTokenizer(mapping, ";");
-            while (tokenizer.hasMoreTokens()) {
-                String[] ops = tokenizer.nextToken().split("->");
+            for (String groups : mapping.split(";")) {
+                String[] ops = groups.split("->");
                 List<String> confsToWrite = new ArrayList<>();
-                for (String lh : ops[0].split(",")) {
-                    if (!confs.contains(lh.trim())) {
+                for (String lh : splitToArray(ops[0])) {
+                    if (!confs.contains(lh)) {
                         confsToWrite.add(lh);
                     }
                 }
                 if (!confsToWrite.isEmpty()) {
                     newMapping.append(mappingSep);
                     String sep = "";
+                    String listSep = groups.contains(" ") ? ", " : ",";
                     for (String confToWrite : confsToWrite) {
                         newMapping.append(sep).append(confToWrite);
-                        sep = ",";
+                        sep = listSep;
                     }
                     if (ops.length == 2) {
-                        newMapping.append("->").append(ops[1]);
+                        newMapping.append("->").append(joinArray(splitToArray(ops[1]), sep));
                     }
                     mappingSep = ";";
                 }
@@ -869,13 +861,12 @@ public final class XmlModuleDescriptorUpdater {
 
         private String removeConfigurationsFromList(String list, List<String> confsToRemove) {
             StringBuilder newList = new StringBuilder();
-            String listSep = "";
-            StringTokenizer tokenizer = new StringTokenizer(list, ",");
-            while (tokenizer.hasMoreTokens()) {
-                String current = tokenizer.nextToken();
-                if (!confsToRemove.contains(current.trim())) {
-                    newList.append(listSep).append(current);
-                    listSep = ",";
+            String sep = "";
+            String listSep = list.contains(" ") ? ", " : ",";
+            for (String current : splitToArray(list)) {
+                if (!confsToRemove.contains(current)) {
+                    newList.append(sep).append(current);
+                    sep = listSep;
                 }
             }
             return newList.toString();

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f3629404/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorWriter.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorWriter.java b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorWriter.java
index 6f0f0ad..2a043d0 100644
--- a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorWriter.java
+++ b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorWriter.java
@@ -44,10 +44,12 @@ import org.apache.ivy.core.module.id.ModuleRevisionId;
 import org.apache.ivy.plugins.matcher.MapMatcher;
 import org.apache.ivy.util.DateUtil;
 import org.apache.ivy.util.Message;
-import org.apache.ivy.util.StringUtils;
 import org.apache.ivy.util.XMLHelper;
 import org.apache.ivy.util.extendable.ExtendableItem;
 
+import static org.apache.ivy.util.StringUtils.isNullOrEmpty;
+import static org.apache.ivy.util.StringUtils.joinArray;
+
 /**
  *
  */
@@ -421,7 +423,7 @@ public final class XmlModuleDescriptorWriter {
                 if (location != null) {
                     out.print(" location=\"" + XMLHelper.escape(location) + "\"");
                 }
-                out.print(" extendType=\"" + StringUtils.join(parent.getExtendsTypes(), ",") + "\"");
+                out.print(" extendType=\"" + joinArray(parent.getExtendsTypes(), ",") + "\"");
                 out.println("/>");
             }
             License[] licenses = md.getLicenses();
@@ -440,12 +442,12 @@ public final class XmlModuleDescriptorWriter {
                 if (md.getHomePage() != null) {
                     out.print(" homepage=\"" + XMLHelper.escape(md.getHomePage()) + "\"");
                 }
-                if (md.getDescription() != null && md.getDescription().trim().length() > 0) {
+                if (isNullOrEmpty(md.getDescription())) {
+                    out.println(" />");
+                } else {
                     out.println(">");
                     out.println("\t\t" + XMLHelper.escape(md.getDescription()));
                     out.println("\t\t</description>");
-                } else {
-                    out.println(" />");
                 }
             }
             for (ExtraInfoHolder extraInfo : md.getExtraInfos()) {
@@ -468,7 +470,7 @@ public final class XmlModuleDescriptorWriter {
             out.print(String.format(" %s=\"%s\"", entry.getKey(), entry.getValue()));
         }
         boolean requireClosingTag = false;
-        if (extraInfo.getContent() != null && extraInfo.getContent().trim().length() > 0) {
+        if (!isNullOrEmpty(extraInfo.getContent())) {
             out.print(">");
             out.print(XMLHelper.escape(extraInfo.getContent()));
             requireClosingTag = true;
@@ -495,7 +497,7 @@ public final class XmlModuleDescriptorWriter {
 
     private static boolean requireInnerInfoElement(ModuleDescriptor md) {
         return md.getExtraInfos().size() > 0 || md.getHomePage() != null
-                || (md.getDescription() != null && md.getDescription().trim().length() > 0)
+                || !isNullOrEmpty(md.getDescription())
                 || md.getLicenses().length > 0 || md.getInheritedDescriptors().length > 0;
     }
 

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f3629404/src/java/org/apache/ivy/plugins/report/XmlReportWriter.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/report/XmlReportWriter.java b/src/java/org/apache/ivy/plugins/report/XmlReportWriter.java
index 23a1d34..3da3a5b 100644
--- a/src/java/org/apache/ivy/plugins/report/XmlReportWriter.java
+++ b/src/java/org/apache/ivy/plugins/report/XmlReportWriter.java
@@ -41,9 +41,10 @@ import org.apache.ivy.core.resolve.IvyNode;
 import org.apache.ivy.core.resolve.IvyNodeCallers.Caller;
 import org.apache.ivy.core.resolve.IvyNodeEviction.EvictionData;
 import org.apache.ivy.util.DateUtil;
-import org.apache.ivy.util.StringUtils;
 import org.apache.ivy.util.XMLHelper;
 
+import static org.apache.ivy.util.StringUtils.joinArray;
+
 /**
  * XmlReportWriter allows to write ResolveReport in an xml format.
  */
@@ -78,7 +79,7 @@ public class XmlReportWriter {
         }
         out.println(extraToString(mrid.getExtraAttributes(), "\t\t"));
         out.println("\t\tconf=\"" + XMLHelper.escape(report.getConfiguration()) + "\"");
-        out.println("\t\tconfs=\"" + XMLHelper.escape(StringUtils.join(confs, ", ")) + "\"");
+        out.println("\t\tconfs=\"" + XMLHelper.escape(joinArray(confs, ", ")) + "\"");
         out.println("\t\tdate=\"" + DateUtil.format(report.getDate()) + "\"/>");
 
         out.println("\t<dependencies>");
@@ -148,7 +149,7 @@ public class XmlReportWriter {
                 details, dep.isDownloaded(), dep.isSearched(),
                 (dep.getDescriptor() == null) ? "" : " default=\""
                 + dep.getDescriptor().isDefault() + "\"",
-                toString(dep.getConfigurations(report.getConfiguration())),
+                XMLHelper.escape(joinArray(dep.getConfigurations(report.getConfiguration()), ", ")),
                 dependencies.indexOf(dep.getResolvedId())));
         if (md != null) {
             License[] licenses = md.getLicenses();
@@ -226,7 +227,7 @@ public class XmlReportWriter {
             out.println(String.format("\t\t\t\t<caller organisation=\"%s\" name=\"%s\" conf=\"%s\" rev=\"%s\" rev-constraint-default=\"%s\" rev-constraint-dynamic=\"%s\" callerrev=\"%s\"%s/>",
                     XMLHelper.escape(caller.getModuleRevisionId().getOrganisation()),
                     XMLHelper.escape(caller.getModuleRevisionId().getName()),
-                    XMLHelper.escape(toString(caller.getCallerConfigurations())),
+                    XMLHelper.escape(joinArray(caller.getCallerConfigurations(), ", ")),
                     XMLHelper.escape(caller.getAskedDependencyId(dep.getData()).getRevision()),
                     XMLHelper.escape(dependencyDescriptor.getDependencyRevisionId().getRevision()),
                     XMLHelper.escape(dependencyDescriptor.getDynamicConstraintDependencyRevisionId().getRevision()),
@@ -269,14 +270,4 @@ public class XmlReportWriter {
         out.println("\t\t\t\t</artifacts>");
     }
 
-    private String toString(String[] strs) {
-        StringBuilder buf = new StringBuilder();
-        for (String str : strs) {
-            if (buf.length() > 0) {
-                buf.append(", ");
-            }
-            buf.append(str);
-        }
-        return XMLHelper.escape(buf.toString());
-    }
 }

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f3629404/src/java/org/apache/ivy/plugins/repository/RepositoryCopyProgressListener.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/repository/RepositoryCopyProgressListener.java b/src/java/org/apache/ivy/plugins/repository/RepositoryCopyProgressListener.java
index 1a11636..e816fc3 100644
--- a/src/java/org/apache/ivy/plugins/repository/RepositoryCopyProgressListener.java
+++ b/src/java/org/apache/ivy/plugins/repository/RepositoryCopyProgressListener.java
@@ -30,10 +30,10 @@ public class RepositoryCopyProgressListener implements CopyProgressListener {
     private Long totalLength = null;
 
     public void start(CopyProgressEvent evt) {
-        if (totalLength != null) {
-            repository.fireTransferStarted(totalLength);
-        } else {
+        if (totalLength == null) {
             repository.fireTransferStarted();
+        } else {
+            repository.fireTransferStarted(totalLength);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f3629404/src/java/org/apache/ivy/plugins/repository/file/FileRepository.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/repository/file/FileRepository.java b/src/java/org/apache/ivy/plugins/repository/file/FileRepository.java
index 853b5fe..5df7462 100644
--- a/src/java/org/apache/ivy/plugins/repository/file/FileRepository.java
+++ b/src/java/org/apache/ivy/plugins/repository/file/FileRepository.java
@@ -109,11 +109,10 @@ public class FileRepository extends AbstractRepository {
     }
 
     File getFile(String source) {
-        if (baseDir != null) {
-            return FileUtil.resolveFile(baseDir, source);
-        } else {
+        if (baseDir == null) {
             return Checks.checkAbsolute(source, "source");
         }
+        return FileUtil.resolveFile(baseDir, source);
     }
 
     public boolean isLocal() {
@@ -134,11 +133,10 @@ public class FileRepository extends AbstractRepository {
     }
 
     public String standardize(String source) {
-        if (baseDir != null) {
-            return FileUtil.resolveFile(baseDir, source).getPath();
-        } else {
+        if (baseDir == null) {
             return FileUtil.normalize(source).getPath();
         }
+        return FileUtil.resolveFile(baseDir, source).getPath();
     }
 
     public String getFileSeparator() {

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f3629404/src/java/org/apache/ivy/plugins/repository/ssh/SshCache.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/repository/ssh/SshCache.java b/src/java/org/apache/ivy/plugins/repository/ssh/SshCache.java
index 004b390..01bff5f 100644
--- a/src/java/org/apache/ivy/plugins/repository/ssh/SshCache.java
+++ b/src/java/org/apache/ivy/plugins/repository/ssh/SshCache.java
@@ -191,7 +191,7 @@ public final class SshCache {
         if (port != -1 && port != SSH_DEFAULT_PORT) {
             portToUse = Integer.toString(port);
         }
-        return user.toLowerCase(Locale.US).trim() + "@" + host.toLowerCase(Locale.US).trim() + ":"
+        return user.trim().toLowerCase(Locale.US) + "@" + host.trim().toLowerCase(Locale.US) + ":"
                 + portToUse;
     }
 
@@ -232,7 +232,7 @@ public final class SshCache {
             oldSession.disconnect();
             Message.verbose(":: SSH :: ssh connection closed from " + oldhost);
         }
-        if ((newSession == null) && (entry != null)) {
+        if (newSession == null && entry != null) {
             uriCacheMap.remove(createCacheKey(user, host, port));
             if (entry.getSession() != null) {
                 sessionCacheMap.remove(entry.getSession());

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f3629404/src/java/org/apache/ivy/plugins/repository/vfs/VfsRepository.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/repository/vfs/VfsRepository.java b/src/java/org/apache/ivy/plugins/repository/vfs/VfsRepository.java
index 691a998..80b1562 100644
--- a/src/java/org/apache/ivy/plugins/repository/vfs/VfsRepository.java
+++ b/src/java/org/apache/ivy/plugins/repository/vfs/VfsRepository.java
@@ -176,8 +176,7 @@ public class VfsRepository extends AbstractRepository {
         Message.debug("resourceImpl.exists()" + resourceImpl.exists());
         Message.debug("resourceImpl.getType()" + resourceImpl.getType());
         Message.debug("FileType.FOLDER" + FileType.FOLDER);
-        if ((resourceImpl != null) && resourceImpl.exists()
-                && (resourceImpl.getType() == FileType.FOLDER)) {
+        if (resourceImpl.exists() && resourceImpl.getType() == FileType.FOLDER) {
             List<FileObject> children = Arrays.asList(resourceImpl.getChildren());
             for (FileObject child : children) {
                 Message.debug("child " + children.indexOf(child) + child.getName().getURI());

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f3629404/src/java/org/apache/ivy/plugins/repository/vfs/VfsResource.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/repository/vfs/VfsResource.java b/src/java/org/apache/ivy/plugins/repository/vfs/VfsResource.java
index 8fcc302..4f3e599 100644
--- a/src/java/org/apache/ivy/plugins/repository/vfs/VfsResource.java
+++ b/src/java/org/apache/ivy/plugins/repository/vfs/VfsResource.java
@@ -88,8 +88,8 @@ public class VfsResource implements Resource {
         init();
         List<String> list = new ArrayList<>();
         try {
-            if ((resourceImpl != null) && resourceImpl.exists()
-                    && (resourceImpl.getType() == FileType.FOLDER)) {
+            if (resourceImpl != null && resourceImpl.exists()
+                    && resourceImpl.getType() == FileType.FOLDER) {
                 for (FileObject child : resourceImpl.getChildren()) {
                     list.add(normalize(child.getName().getURI()));
                 }

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f3629404/src/java/org/apache/ivy/plugins/repository/vsftp/VsftpRepository.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/repository/vsftp/VsftpRepository.java b/src/java/org/apache/ivy/plugins/repository/vsftp/VsftpRepository.java
index f776143..7615b91 100644
--- a/src/java/org/apache/ivy/plugins/repository/vsftp/VsftpRepository.java
+++ b/src/java/org/apache/ivy/plugins/repository/vsftp/VsftpRepository.java
@@ -242,7 +242,7 @@ public class VsftpRepository extends AbstractRepository {
                 while (line.endsWith("\r") || line.endsWith("\n")) {
                     line = line.substring(0, line.length() - 1);
                 }
-                if (line.trim().length() != 0) {
+                if (!line.trim().isEmpty()) {
                     ret.add(parent + line.substring(line.lastIndexOf(' ') + 1));
                 }
             }

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f3629404/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java b/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java
index 9eb4eb5..81344d4 100644
--- a/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java
+++ b/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java
@@ -80,6 +80,8 @@ import org.apache.ivy.util.ChecksumHelper;
 import org.apache.ivy.util.HostUtil;
 import org.apache.ivy.util.Message;
 
+import static org.apache.ivy.util.StringUtils.splitToArray;
+
 /**
  *
  */
@@ -180,10 +182,8 @@ public abstract class BasicResolver extends AbstractResolver {
         IvyContext context = IvyContext.pushNewCopyContext();
         try {
             ResolvedModuleRevision mr = data.getCurrentResolvedModuleRevision();
-            if (mr != null) {
-                if (shouldReturnResolvedModule(dd, mr)) {
-                    return mr;
-                }
+            if (mr != null && shouldReturnResolvedModule(dd, mr)) {
+                return mr;
             }
 
             if (isForce()) {
@@ -238,33 +238,35 @@ public abstract class BasicResolver extends AbstractResolver {
                     throw new UnresolvedDependencyException("\t" + getName()
                             + ": no ivy file found for " + systemMrid, false);
                 }
+
                 nsMd = DefaultModuleDescriptor.newDefaultInstance(nsMrid,
                     nsDd.getAllDependencyArtifacts());
                 ResolvedResource artifactRef = findFirstArtifactRef(nsMd, nsDd, data);
                 checkInterrupted();
+
                 if (artifactRef == null) {
                     throw new UnresolvedDependencyException("\t" + getName()
                             + ": no ivy file nor artifact found for " + systemMrid, false);
-                } else {
-                    long lastModified = artifactRef.getLastModified();
-                    if (lastModified != 0 && nsMd instanceof DefaultModuleDescriptor) {
-                        ((DefaultModuleDescriptor) nsMd).setLastModified(lastModified);
-                    }
-                    Message.verbose("\t" + getName() + ": no ivy file found for " + systemMrid
-                            + ": using default data");
-                    if (isDynamic) {
-                        nsMd.setResolvedModuleRevisionId(ModuleRevisionId.newInstance(nsMrid,
-                            artifactRef.getRevision()));
-                    }
-                    systemMd = toSystem(nsMd);
-                    MetadataArtifactDownloadReport madr = new MetadataArtifactDownloadReport(
-                            systemMd.getMetadataArtifact());
-                    madr.setDownloadStatus(DownloadStatus.NO);
-                    madr.setSearched(true);
-                    rmr = new ResolvedModuleRevision(this, this, systemMd, madr, isForce());
-                    getRepositoryCacheManager().cacheModuleDescriptor(this, artifactRef,
-                        toSystem(dd), systemMd.getAllArtifacts()[0], null, getCacheOptions(data));
                 }
+
+                long lastModified = artifactRef.getLastModified();
+                if (lastModified != 0 && nsMd instanceof DefaultModuleDescriptor) {
+                    ((DefaultModuleDescriptor) nsMd).setLastModified(lastModified);
+                }
+                Message.verbose("\t" + getName() + ": no ivy file found for " + systemMrid
+                        + ": using default data");
+                if (isDynamic) {
+                    nsMd.setResolvedModuleRevisionId(ModuleRevisionId.newInstance(nsMrid,
+                        artifactRef.getRevision()));
+                }
+                systemMd = toSystem(nsMd);
+                MetadataArtifactDownloadReport madr = new MetadataArtifactDownloadReport(
+                        systemMd.getMetadataArtifact());
+                madr.setDownloadStatus(DownloadStatus.NO);
+                madr.setSearched(true);
+                rmr = new ResolvedModuleRevision(this, this, systemMd, madr, isForce());
+                getRepositoryCacheManager().cacheModuleDescriptor(this, artifactRef,
+                    toSystem(dd), systemMd.getAllArtifacts()[0], null, getCacheOptions(data));
             } else {
                 if (ivyRef instanceof MDResolvedResource) {
                     rmr = ((MDResolvedResource) ivyRef).getResolvedModuleRevision();
@@ -356,10 +358,10 @@ public abstract class BasicResolver extends AbstractResolver {
         final ModuleDescriptorParser parser = systemMd.getParser();
 
         // the metadata artifact which was used to cache the original metadata file
-        Artifact requestedMetadataArtifact = ivyRef == null ? systemMd.getMetadataArtifact()
+        Artifact requestedMetadataArtifact = (ivyRef == null) ? systemMd.getMetadataArtifact()
                 : parser.getMetadataArtifact(
-                    ModuleRevisionId.newInstance(systemMrid, systemMd.getRevision()),
-                    ivyRef.getResource());
+                        ModuleRevisionId.newInstance(systemMrid, systemMd.getRevision()),
+                ivyRef.getResource());
 
         cacheManager.originalToCachedModuleDescriptor(this, ivyRef, requestedMetadataArtifact, rmr,
             new ModuleDescriptorWriter() {
@@ -397,21 +399,22 @@ public abstract class BasicResolver extends AbstractResolver {
 
     private void resolveAndCheckPublicationDate(DependencyDescriptor systemDd,
             ModuleDescriptor systemMd, ModuleRevisionId systemMrid, ResolveData data) {
+        if (data.getDate() == null) {
+            return;
+        }
         // resolve and check publication date
-        if (data.getDate() != null) {
-            long pubDate = getPublicationDate(systemMd, systemDd, data);
-            if (pubDate > data.getDate().getTime()) {
-                throw new UnresolvedDependencyException("\t" + getName()
-                        + ": unacceptable publication date => was=" + new Date(pubDate)
-                        + " required=" + data.getDate());
-            }
-            if (pubDate == -1) {
-                throw new UnresolvedDependencyException("\t" + getName()
-                        + ": impossible to guess publication date: artifact missing for "
-                        + systemMrid);
-            }
-            systemMd.setResolvedPublicationDate(new Date(pubDate));
+        long pubDate = getPublicationDate(systemMd, systemDd, data);
+        if (pubDate > data.getDate().getTime()) {
+            throw new UnresolvedDependencyException("\t" + getName()
+                    + ": unacceptable publication date => was=" + new Date(pubDate)
+                    + " required=" + data.getDate());
         }
+        if (pubDate == -1) {
+            throw new UnresolvedDependencyException("\t" + getName()
+                    + ": impossible to guess publication date: artifact missing for "
+                    + systemMrid);
+        }
+        systemMd.setResolvedPublicationDate(new Date(pubDate));
     }
 
     protected void checkModuleDescriptorRevision(ModuleDescriptor systemMd,
@@ -519,16 +522,15 @@ public abstract class BasicResolver extends AbstractResolver {
             IvyNode node = data.getNode(resolvedMrid);
             if (node != null && node.getModuleRevision() != null) {
                 // this revision has already be resolved : return it
-                if (node.getDescriptor() != null && node.getDescriptor().isDefault()) {
-                    Message.verbose("\t" + getName() + ": found already resolved revision: "
-                            + resolvedMrid
-                            + ": but it's a default one, maybe we can find a better one");
-                } else {
+                if (node.getDescriptor() == null || !node.getDescriptor().isDefault()) {
                     Message.verbose("\t" + getName() + ": revision already resolved: "
                             + resolvedMrid);
                     node.getModuleRevision().getReport().setSearched(true);
                     return node.getModuleRevision();
                 }
+                Message.verbose("\t" + getName() + ": found already resolved revision: "
+                        + resolvedMrid
+                        + ": but it's a default one, maybe we can find a better one");
             }
         }
 
@@ -693,7 +695,7 @@ public abstract class BasicResolver extends AbstractResolver {
                 rejected.add(rres.getRevision() + " (unreachable)");
                 continue;
             }
-            if ((date != null && rres.getLastModified() > date.getTime())) {
+            if (date != null && rres.getLastModified() > date.getTime()) {
                 Message.verbose("\t" + name + ": too young: " + rres);
                 rejected.add(rres.getRevision() + " (" + rres.getLastModified() + ")");
                 continue;
@@ -780,10 +782,10 @@ public abstract class BasicResolver extends AbstractResolver {
 
     protected void logAttempt(String attempt) {
         Artifact currentArtifact = IvyContext.getContext().get(getName() + ".artifact");
-        if (currentArtifact != null) {
-            logArtifactAttempt(currentArtifact, attempt);
-        } else {
+        if (currentArtifact == null) {
             logIvyAttempt(attempt);
+        } else {
+            logArtifactAttempt(currentArtifact, attempt);
         }
     }
 
@@ -1098,16 +1100,15 @@ public abstract class BasicResolver extends AbstractResolver {
     }
 
     public String[] getChecksumAlgorithms() {
-        String csDef = checksums == null ? getSettings().getVariable("ivy.checksums") : checksums;
+        String csDef = (checksums == null) ? getSettings().getVariable("ivy.checksums") : checksums;
         if (csDef == null) {
             return new String[0];
         }
         // csDef is a comma separated list of checksum algorithms to use with this resolver
         // we parse and return it as a String[]
         List<String> algos = new ArrayList<>();
-        for (String checksum : csDef.split(",")) {
-            String cs = checksum.trim();
-            if (!"".equals(cs) && !"none".equals(cs)) {
+        for (String cs : splitToArray(csDef)) {
+            if (!cs.isEmpty() && !"none".equals(cs)) {
                 algos.add(cs);
             }
         }

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f3629404/src/java/org/apache/ivy/plugins/resolver/BintrayResolver.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/resolver/BintrayResolver.java b/src/java/org/apache/ivy/plugins/resolver/BintrayResolver.java
index 9466d18..45b33f9 100644
--- a/src/java/org/apache/ivy/plugins/resolver/BintrayResolver.java
+++ b/src/java/org/apache/ivy/plugins/resolver/BintrayResolver.java
@@ -17,6 +17,8 @@
  */
 package org.apache.ivy.plugins.resolver;
 
+import static org.apache.ivy.util.StringUtils.isNullOrEmpty;
+
 /**
  * BintrayResolver is a resolver which can be used to resolve dependencies found in the Bintray
  * artifacts repository.
@@ -55,7 +57,7 @@ public class BintrayResolver extends IBiblioResolver {
     }
 
     private void updateRoot() {
-        if (isEmpty(subject) || isEmpty(repo)) {
+        if (isNullOrEmpty(subject) || isNullOrEmpty(repo)) {
             return;
         }
 
@@ -64,16 +66,12 @@ public class BintrayResolver extends IBiblioResolver {
     }
 
     private void updateName(String defaultName) {
-        if (isEmpty(defaultName)) {
+        if (isNullOrEmpty(defaultName)) {
             throw new IllegalArgumentException("Default resolver name must not be null or empty");
         }
-        if (isEmpty(getName()) || isNameUpdatable) {
+        if (isNullOrEmpty(getName()) || isNameUpdatable) {
             isNameUpdatable = true;
             setName(defaultName);
         }
     }
-
-    private boolean isEmpty(String s) {
-        return ((s == null) || (s.trim().length() < 1));
-    }
 }

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f3629404/src/java/org/apache/ivy/plugins/resolver/JarResolver.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/resolver/JarResolver.java b/src/java/org/apache/ivy/plugins/resolver/JarResolver.java
index b02830b..c254006 100644
--- a/src/java/org/apache/ivy/plugins/resolver/JarResolver.java
+++ b/src/java/org/apache/ivy/plugins/resolver/JarResolver.java
@@ -76,28 +76,29 @@ public class JarResolver extends RepositoryResolver {
     @Override
     public void setSettings(ResolverSettings settings) {
         super.setSettings(settings);
+        if (url == null) {
+            return;
+        }
         // let's resolve the url
-        if (url != null) {
-            ArtifactDownloadReport report;
-            EventManager eventManager = getEventManager();
-            try {
-                if (eventManager != null) {
-                    getRepository().addTransferListener(eventManager);
-                }
-                Resource jarResource = new URLResource(url, this.getTimeoutConstraint());
-                CacheResourceOptions options = new CacheResourceOptions();
-                report = getRepositoryCacheManager().downloadRepositoryResource(jarResource,
-                    "jarrepository", "jar", "jar", options, new URLRepository());
-            } finally {
-                if (eventManager != null) {
-                    getRepository().removeTransferListener(eventManager);
-                }
+        ArtifactDownloadReport report;
+        EventManager eventManager = getEventManager();
+        try {
+            if (eventManager != null) {
+                getRepository().addTransferListener(eventManager);
             }
-            if (report.getDownloadStatus() == DownloadStatus.FAILED) {
-                throw new RuntimeException("The jar file " + url.toExternalForm()
-                        + " could not be downloaded (" + report.getDownloadDetails() + ")");
+            Resource jarResource = new URLResource(url, this.getTimeoutConstraint());
+            CacheResourceOptions options = new CacheResourceOptions();
+            report = getRepositoryCacheManager().downloadRepositoryResource(jarResource,
+                "jarrepository", "jar", "jar", options, new URLRepository());
+        } finally {
+            if (eventManager != null) {
+                getRepository().removeTransferListener(eventManager);
             }
-            setJarFile(report.getLocalFile());
         }
+        if (report.getDownloadStatus() == DownloadStatus.FAILED) {
+            throw new RuntimeException("The jar file " + url.toExternalForm()
+                    + " could not be downloaded (" + report.getDownloadDetails() + ")");
+        }
+        setJarFile(report.getLocalFile());
     }
 }

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f3629404/src/java/org/apache/ivy/plugins/resolver/util/FileURLLister.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/resolver/util/FileURLLister.java b/src/java/org/apache/ivy/plugins/resolver/util/FileURLLister.java
index bab3476..7e36028 100644
--- a/src/java/org/apache/ivy/plugins/resolver/util/FileURLLister.java
+++ b/src/java/org/apache/ivy/plugins/resolver/util/FileURLLister.java
@@ -49,7 +49,7 @@ public class FileURLLister implements URLLister {
             // unexpected try to get the best of it
             path = url.getPath();
         }
-        File file = basedir == null ? new File(path) : new File(basedir, path);
+        File file = (basedir == null) ? new File(path) : new File(basedir, path);
         if (file.exists() && file.isDirectory()) {
             String[] files = file.list();
             List<URL> ret = new ArrayList<>(files.length);

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f3629404/src/java/org/apache/ivy/plugins/resolver/util/ResolverHelper.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/resolver/util/ResolverHelper.java b/src/java/org/apache/ivy/plugins/resolver/util/ResolverHelper.java
index 0f78e7f..bcee925 100644
--- a/src/java/org/apache/ivy/plugins/resolver/util/ResolverHelper.java
+++ b/src/java/org/apache/ivy/plugins/resolver/util/ResolverHelper.java
@@ -54,42 +54,40 @@ public final class ResolverHelper {
             // the searched token is a whole name
             String root = pattern.substring(0, index);
             return listAll(rep, root);
-        } else {
-            int slashIndex = pattern.substring(0, index).lastIndexOf(fileSep);
-            String root = slashIndex == -1 ? "" : pattern.substring(0, slashIndex);
+        }
 
-            try {
-                Message.debug("\tusing " + rep + " to list all in " + root);
-                String[] all = listAll(rep, root);
-                if (all != null) {
-                    Message.debug("\t\tfound " + all.length + " urls");
-                    List<String> ret = new ArrayList<>(all.length);
-                    int endNameIndex = pattern.indexOf(fileSep, slashIndex + 1);
-                    String namePattern;
-                    if (endNameIndex != -1) {
-                        namePattern = pattern.substring(slashIndex + 1, endNameIndex);
-                    } else {
-                        namePattern = pattern.substring(slashIndex + 1);
-                    }
-                    namePattern = namePattern.replaceAll("\\.", "\\\\.");
-                    namePattern = IvyPatternHelper.substituteToken(namePattern, token, "(.+)");
-                    Pattern p = Pattern.compile(namePattern);
-                    for (String path : all) {
-                        Matcher m = p.matcher(path);
-                        if (m.matches()) {
-                            String value = m.group(1);
-                            ret.add(value);
-                        }
-                    }
-                    Message.debug("\t\t" + ret.size() + " matched " + pattern);
-                    return ret.toArray(new String[ret.size()]);
-                } else {
-                    return null;
-                }
-            } catch (Exception e) {
-                Message.warn("problem while listing resources in " + root + " with " + rep, e);
+        int slashIndex = pattern.substring(0, index).lastIndexOf(fileSep);
+        String root = (slashIndex == -1) ? "" : pattern.substring(0, slashIndex);
+        try {
+            Message.debug("\tusing " + rep + " to list all in " + root);
+            String[] all = listAll(rep, root);
+            if (all == null) {
                 return null;
             }
+            Message.debug("\t\tfound " + all.length + " urls");
+            List<String> ret = new ArrayList<>(all.length);
+            int endNameIndex = pattern.indexOf(fileSep, slashIndex + 1);
+            String namePattern;
+            if (endNameIndex != -1) {
+                namePattern = pattern.substring(slashIndex + 1, endNameIndex);
+            } else {
+                namePattern = pattern.substring(slashIndex + 1);
+            }
+            namePattern = namePattern.replaceAll("\\.", "\\\\.");
+            namePattern = IvyPatternHelper.substituteToken(namePattern, token, "(.+)");
+            Pattern p = Pattern.compile(namePattern);
+            for (String path : all) {
+                Matcher m = p.matcher(path);
+                if (m.matches()) {
+                    String value = m.group(1);
+                    ret.add(value);
+                }
+            }
+            Message.debug("\t\t" + ret.size() + " matched " + pattern);
+            return ret.toArray(new String[ret.size()]);
+        } catch (Exception e) {
+            Message.warn("problem while listing resources in " + root + " with " + rep, e);
+            return null;
         }
     }
 
@@ -98,21 +96,20 @@ public final class ResolverHelper {
             String fileSep = rep.getFileSeparator();
             Message.debug("\tusing " + rep + " to list all in " + parent);
             List<String> all = rep.list(parent);
-            if (all != null) {
-                Message.debug("\t\tfound " + all.size() + " resources");
-                List<String> names = new ArrayList<>(all.size());
-                for (String path : all) {
-                    if (path.endsWith(fileSep)) {
-                        path = path.substring(0, path.length() - 1);
-                    }
-                    int slashIndex = path.lastIndexOf(fileSep);
-                    names.add(path.substring(slashIndex + 1));
-                }
-                return names.toArray(new String[names.size()]);
-            } else {
+            if (all == null) {
                 Message.debug("\t\tno resources found");
                 return null;
             }
+            Message.debug("\t\tfound " + all.size() + " resources");
+            List<String> names = new ArrayList<>(all.size());
+            for (String path : all) {
+                if (path.endsWith(fileSep)) {
+                    path = path.substring(0, path.length() - 1);
+                }
+                int slashIndex = path.lastIndexOf(fileSep);
+                names.add(path.substring(slashIndex + 1));
+            }
+            return names.toArray(new String[names.size()]);
         } catch (IOException e) {
             Message.verbose("problem while listing resources in " + parent + " with " + rep, e);
             return null;
@@ -156,7 +153,9 @@ public final class ResolverHelper {
                 Message.debug("\tfound resolved res: " + ret);
             }
             return ret.toArray(new ResolvedResource[ret.size()]);
-        } else if (!partiallyResolvedPattern.contains("[" + IvyPatternHelper.REVISION_KEY + "]")) {
+        }
+
+        if (!partiallyResolvedPattern.contains("[" + IvyPatternHelper.REVISION_KEY + "]")) {
             // the partially resolved pattern is completely resolved, check the resource
             try {
                 Resource res = rep.getResource(partiallyResolvedPattern);

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f3629404/src/java/org/apache/ivy/plugins/version/MavenTimedSnapshotVersionMatcher.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/version/MavenTimedSnapshotVersionMatcher.java b/src/java/org/apache/ivy/plugins/version/MavenTimedSnapshotVersionMatcher.java
index ed71262..a10f4c9 100644
--- a/src/java/org/apache/ivy/plugins/version/MavenTimedSnapshotVersionMatcher.java
+++ b/src/java/org/apache/ivy/plugins/version/MavenTimedSnapshotVersionMatcher.java
@@ -22,6 +22,8 @@ import org.apache.ivy.core.module.id.ModuleRevisionId;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import static org.apache.ivy.util.StringUtils.isNullOrEmpty;
+
 /**
  * A {@link VersionMatcher} which understands {@code Maven timestamped snapshots}.
  */
@@ -80,7 +82,7 @@ public class MavenTimedSnapshotVersionMatcher extends AbstractVersionMatcher {
      * @return
      */
     public static MavenSnapshotRevision computeIfSnapshot(final String revision) {
-        if (revision == null || revision.trim().isEmpty()) {
+        if (isNullOrEmpty(revision)) {
             return null;
         }
         final boolean regularSnapshot = revision.endsWith(SNAPSHOT_SUFFIX);

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f3629404/src/java/org/apache/ivy/util/ContextualSAXHandler.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/util/ContextualSAXHandler.java b/src/java/org/apache/ivy/util/ContextualSAXHandler.java
index cc8b513..e036b27 100644
--- a/src/java/org/apache/ivy/util/ContextualSAXHandler.java
+++ b/src/java/org/apache/ivy/util/ContextualSAXHandler.java
@@ -23,6 +23,8 @@ import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.DefaultHandler;
 
+import static org.apache.ivy.util.StringUtils.joinArray;
+
 public class ContextualSAXHandler extends DefaultHandler {
 
     private Stack<String> contextStack = new Stack<>();
@@ -48,14 +50,7 @@ public class ContextualSAXHandler extends DefaultHandler {
     }
 
     protected String getContext() {
-        StringBuilder buf = new StringBuilder();
-        for (String ctx : contextStack) {
-            buf.append(ctx).append("/");
-        }
-        if (buf.length() > 0) {
-            buf.setLength(buf.length() - 1);
-        }
-        return buf.toString();
+        return joinArray(contextStack.toArray(new String[contextStack.size()]), "/");
     }
 
     protected String getText() {

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f3629404/src/java/org/apache/ivy/util/Credentials.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/util/Credentials.java b/src/java/org/apache/ivy/util/Credentials.java
index 6e70d63..7d27f88 100644
--- a/src/java/org/apache/ivy/util/Credentials.java
+++ b/src/java/org/apache/ivy/util/Credentials.java
@@ -17,6 +17,8 @@
  */
 package org.apache.ivy.util;
 
+import static org.apache.ivy.util.StringUtils.isNullOrEmpty;
+
 /**
  *
  */
@@ -53,11 +55,10 @@ public class Credentials {
     }
 
     public static String buildKey(String realm, String host) {
-        if (realm == null || "".equals(realm.trim())) {
+        if (isNullOrEmpty(realm)) {
             return host;
-        } else {
-            return realm + "@" + host;
         }
+        return realm + "@" + host;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f3629404/src/java/org/apache/ivy/util/StringUtils.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/util/StringUtils.java b/src/java/org/apache/ivy/util/StringUtils.java
index 5c596d4..2cd5ffc 100644
--- a/src/java/org/apache/ivy/util/StringUtils.java
+++ b/src/java/org/apache/ivy/util/StringUtils.java
@@ -82,24 +82,34 @@ public final class StringUtils {
         return sw.getBuffer().toString();
     }
 
+    @Deprecated
+    public static String join(Object[] objs, String sep) {
+        for (int i = 0; i < objs.length; i++) {
+            if (!(objs[i] instanceof String)) {
+                objs[i] = objs[i].toString();
+            }
+        }
+        return joinArray((String[]) objs, sep);
+    }
+
     /**
-     * Joins the given object array in one string, each separated by the given separator.
+     * Joins the given string array in one string, each separated by the given separator.
      *
      * Example:
      *
      * <pre>
-     * join(new String[] {"one", "two", "three"}, ", ") -&gt; "one, two, three"
+     * joinArray(new String[] {"one", "two", "three"}, ", ") -&gt; "one, two, three"
      * </pre>
      *
      * @param objs
-     *            The array of objects (<code>toString()</code> is used).
+     *            The array of strings.
      * @param sep
      *            The separator to use.
      * @return The concatenated string.
      */
-    public static String join(Object[] objs, String sep) {
+    public static String joinArray(String[] objs, String sep) {
         StringBuilder buf = new StringBuilder();
-        for (Object obj : objs) {
+        for (String obj : objs) {
             buf.append(obj).append(sep);
         }
         if (objs.length > 0) {
@@ -108,6 +118,56 @@ public final class StringUtils {
         return buf.toString();
     }
 
+    /**
+     * Splits the given string into a string array using comma as a separator.
+     * Every array member gets {@link String#trim() trimmed}.
+     *
+     * @param list the string
+     * @return String[]
+     */
+    public static String[] splitToArray(String list) {
+        if (list == null) {
+            return null;
+        }
+        String[] parts = list.split(",");
+        for (int i = 0; i < parts.length; i++) {
+            parts[i] = parts[i].trim();
+        }
+        return parts;
+    }
+
+    /**
+     * Checks that a string is not null or consists of whitespace by {@link String#trim() trimming}
+     * and checking the {@link String#isEmpty() length} of the result.
+     *
+     * @param s the string to check
+     * @return boolean
+     */
+    public static boolean isNullOrEmpty(String s) {
+        return s == null || s.trim().isEmpty();
+    }
+
+    /**
+     * Asserts that the passed <code>value</code> is not null and not an empty {@link String}.
+     * The implementation of this method {@link String#trim() trims} the (non-null)
+     * <code>value</code> to check whether the value is an empty string. If the <code>value</code>
+     * is either null or empty, then this method throws an {@link IllegalArgumentException}
+     * with the passed <code>errorMessage</code> as the message in the exception.
+     *
+     * @param value        The value to check for
+     * @param errorMessage The error message
+     */
+    public static void assertNotNullNorEmpty(final String value, final String errorMessage) {
+        if (isNullOrEmpty(value)) {
+            throw new IllegalArgumentException(errorMessage);
+        }
+    }
+
+    @Deprecated
+    public static void assertNotNullNotEmpty(final String value, final String errorMessage) {
+        assertNotNullNorEmpty(value, errorMessage);
+    }
+
     // basic string codec (same algo as CVS passfile, inspired by ant CVSPass class
     /**
      * Array containing char conversion data
@@ -188,19 +248,4 @@ public final class StringUtils {
         }
         return sb.toString();
     }
-
-    /**
-     * Asserts that the passed <code>value</code> is not null and not an empty {@link String}. The implementation
-     * of this method {@link String#trim() trims} the (non-null) <code>value</code> to check whether the value is an
-     * empty string. If the <code>value</code> is either null or empty, then this method throws an {@link IllegalArgumentException}
-     * with the passed <code>errorMessage</code> as the message in the exception.
-     *
-     * @param value        The value to check for
-     * @param errorMessage The error message
-     */
-    public static void assertNotNullNotEmpty(final String value, final String errorMessage) {
-        if (value == null || value.trim().isEmpty()) {
-            throw new IllegalArgumentException(errorMessage);
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f3629404/src/java/org/apache/ivy/util/XMLHelper.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/util/XMLHelper.java b/src/java/org/apache/ivy/util/XMLHelper.java
index 679a214..f99ee0a 100644
--- a/src/java/org/apache/ivy/util/XMLHelper.java
+++ b/src/java/org/apache/ivy/util/XMLHelper.java
@@ -64,7 +64,7 @@ public abstract class XMLHelper {
         }
         SAXParser parser = parserFactory.newSAXParser();
 
-        if (canUseSchemaValidation && (schema != null)) {
+        if (canUseSchemaValidation && schema != null) {
             try {
                 parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
                 parser.setProperty(JAXP_SCHEMA_SOURCE, schemaStream);

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f3629404/src/java/org/apache/ivy/util/url/IvyAuthenticator.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/util/url/IvyAuthenticator.java b/src/java/org/apache/ivy/util/url/IvyAuthenticator.java
index 8df0150..0b0ce6b 100644
--- a/src/java/org/apache/ivy/util/url/IvyAuthenticator.java
+++ b/src/java/org/apache/ivy/util/url/IvyAuthenticator.java
@@ -24,6 +24,8 @@ import java.net.PasswordAuthentication;
 import org.apache.ivy.util.Credentials;
 import org.apache.ivy.util.Message;
 
+import static org.apache.ivy.util.StringUtils.isNullOrEmpty;
+
 /**
  *
  */
@@ -81,7 +83,7 @@ public final class IvyAuthenticator extends Authenticator {
 
         if (isProxyAuthentication()) {
             String proxyUser = System.getProperty("http.proxyUser");
-            if ((proxyUser != null) && (proxyUser.trim().length() > 0)) {
+            if (!isNullOrEmpty(proxyUser)) {
                 String proxyPass = System.getProperty("http.proxyPassword", "");
                 Message.debug("authenticating to proxy server with username [" + proxyUser + "]");
                 result = new PasswordAuthentication(proxyUser, proxyPass.toCharArray());
@@ -98,7 +100,7 @@ public final class IvyAuthenticator extends Authenticator {
             }
         }
 
-        if ((result == null) && (original != null)) {
+        if (result == null && original != null) {
             Authenticator.setDefault(original);
             try {
                 result = Authenticator.requestPasswordAuthentication(getRequestingHost(),

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f3629404/test/java/org/apache/ivy/TestHelper.java
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/TestHelper.java b/test/java/org/apache/ivy/TestHelper.java
index 909ddba..a006bb1 100644
--- a/test/java/org/apache/ivy/TestHelper.java
+++ b/test/java/org/apache/ivy/TestHelper.java
@@ -437,10 +437,7 @@ public class TestHelper {
         final com.sun.net.httpserver.Authenticator authenticator = new BasicAuthenticator(realm) {
             @Override
             public boolean checkCredentials(final String user, final String pass) {
-                if (validCredentials == null) {
-                    return false;
-                }
-                if (!validCredentials.containsKey(user)) {
+                if (validCredentials == null || !validCredentials.containsKey(user)) {
                     return false;
                 }
                 final String expectedPass = validCredentials.get(user);

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f3629404/test/java/org/apache/ivy/ant/AntCallTriggerTest.java
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/ant/AntCallTriggerTest.java b/test/java/org/apache/ivy/ant/AntCallTriggerTest.java
index 1892ac3..91f8351 100644
--- a/test/java/org/apache/ivy/ant/AntCallTriggerTest.java
+++ b/test/java/org/apache/ivy/ant/AntCallTriggerTest.java
@@ -129,10 +129,8 @@ public class AntCallTriggerTest {
                 ProjectHelper.configureProject(project, buildFile);
 
                 // make sure that we have a target to execute
-                if (targets.size() == 0) {
-                    if (project.getDefaultTarget() != null) {
-                        targets.addElement(project.getDefaultTarget());
-                    }
+                if (targets.size() == 0 && project.getDefaultTarget() != null) {
+                    targets.addElement(project.getDefaultTarget());
                 }
 
                 project.executeTargets(targets);

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f3629404/test/java/org/apache/ivy/ant/IvyInfoTest.java
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/ant/IvyInfoTest.java b/test/java/org/apache/ivy/ant/IvyInfoTest.java
index 5d52a22..0ddcad7 100644
--- a/test/java/org/apache/ivy/ant/IvyInfoTest.java
+++ b/test/java/org/apache/ivy/ant/IvyInfoTest.java
@@ -86,7 +86,7 @@ public class IvyInfoTest {
         info.setFile(new File("test/java/org/apache/ivy/ant/ivy-info-all.xml"));
         info.execute();
 
-        assertTrue(info.getProject().getProperty("ivy.extra.branch") == null);
+        assertNull(info.getProject().getProperty("ivy.extra.branch"));
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f3629404/test/java/org/apache/ivy/ant/IvyPublishTest.java
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/ant/IvyPublishTest.java b/test/java/org/apache/ivy/ant/IvyPublishTest.java
index 4109c2c..317e5e7 100644
--- a/test/java/org/apache/ivy/ant/IvyPublishTest.java
+++ b/test/java/org/apache/ivy/ant/IvyPublishTest.java
@@ -147,7 +147,7 @@ public class IvyPublishTest {
                         mergeLine = mergeLine.replaceFirst("\\s?publication=\"\\d+\"", "");
                     }
                     // discard whitespace-only lines
-                    if (!(mergeLine.trim().equals("") && expectedLine.trim().equals(""))) {
+                    if (!(mergeLine.trim().isEmpty() && expectedLine.trim().isEmpty())) {
                         assertEquals("published descriptor matches at line[" + lineNo + "]", expectedLine,
                                 mergeLine);
                     }

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f3629404/test/java/org/apache/ivy/core/resolve/ResolveTest.java
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/core/resolve/ResolveTest.java b/test/java/org/apache/ivy/core/resolve/ResolveTest.java
index 73cf685..53ae7cf 100644
--- a/test/java/org/apache/ivy/core/resolve/ResolveTest.java
+++ b/test/java/org/apache/ivy/core/resolve/ResolveTest.java
@@ -50,7 +50,6 @@ import org.apache.ivy.plugins.resolver.FileSystemResolver;
 import org.apache.ivy.util.CacheCleaner;
 import org.apache.ivy.util.FileUtil;
 import org.apache.ivy.util.MockMessageLogger;
-import org.apache.ivy.util.StringUtils;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
@@ -75,6 +74,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import static org.apache.ivy.util.StringUtils.joinArray;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -2500,7 +2500,7 @@ public class ResolveTest {
         ResolveReport report = ivy.resolve(new File("test/repositories/2/mod6.1/ivy-1.5.xml"),
             getResolveOptions(new String[] {"*"}));
         assertTrue("missing conf should have raised an error in report", report.hasError());
-        assertTrue(StringUtils.join(report.getAllProblemMessages().toArray(), "\n").contains("'unknown'"));
+        assertTrue(joinArray(report.getAllProblemMessages().toArray(new String[0]), "\n").contains("'unknown'"));
     }
 
     @Test
@@ -3797,27 +3797,27 @@ public class ResolveTest {
             new File("test/repositories/badfile/ivys/ivy-badorg.xml"),
             getResolveOptions(new String[] {"*"}));
         assertTrue("bad org should have raised an error in report", report.hasError());
-        assertTrue(StringUtils.join(report.getAllProblemMessages().toArray(), "\n").contains("'badorg'"));
+        assertTrue(joinArray(report.getAllProblemMessages().toArray(new String[0]), "\n").contains("'badorg'"));
 
         report = ivy.resolve(new File("test/repositories/badfile/ivys/ivy-badmodule.xml"),
             getResolveOptions(new String[] {"*"}));
         assertTrue("bad module should have raised an error in report", report.hasError());
-        assertTrue(StringUtils.join(report.getAllProblemMessages().toArray(), "\n").contains("'badmodule'"));
+        assertTrue(joinArray(report.getAllProblemMessages().toArray(new String[0]), "\n").contains("'badmodule'"));
 
         report = ivy.resolve(new File("test/repositories/badfile/ivys/ivy-badbranch.xml"),
             getResolveOptions(new String[] {"*"}));
         assertTrue("bad branch should have raised an error in report", report.hasError());
-        assertTrue(StringUtils.join(report.getAllProblemMessages().toArray(), "\n").contains("'badbranch'"));
+        assertTrue(joinArray(report.getAllProblemMessages().toArray(new String[0]), "\n").contains("'badbranch'"));
 
         report = ivy.resolve(new File("test/repositories/badfile/ivys/ivy-badrevision.xml"),
             getResolveOptions(new String[] {"*"}));
         assertTrue("bad revision should have raised an error in report", report.hasError());
-        assertTrue(StringUtils.join(report.getAllProblemMessages().toArray(), "\n").contains("'badrevision'"));
+        assertTrue(joinArray(report.getAllProblemMessages().toArray(new String[0]), "\n").contains("'badrevision'"));
 
         report = ivy.resolve(new File("test/repositories/badfile/ivys/ivy-badxml.xml"),
             getResolveOptions(new String[] {"*"}));
         assertTrue("bad xml should have raised an error in report", report.hasError());
-        assertTrue(StringUtils.join(report.getAllProblemMessages().toArray(), "\n").contains("badatt"));
+        assertTrue(joinArray(report.getAllProblemMessages().toArray(new String[0]), "\n").contains("badatt"));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f3629404/test/java/org/apache/ivy/plugins/repository/vfs/VfsURI.java
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/plugins/repository/vfs/VfsURI.java b/test/java/org/apache/ivy/plugins/repository/vfs/VfsURI.java
index 1a5ced9..bfcf3c7 100644
--- a/test/java/org/apache/ivy/plugins/repository/vfs/VfsURI.java
+++ b/test/java/org/apache/ivy/plugins/repository/vfs/VfsURI.java
@@ -19,6 +19,8 @@ package org.apache.ivy.plugins.repository.vfs;
 
 import org.apache.ivy.Ivy;
 
+import static org.apache.ivy.util.StringUtils.isNullOrEmpty;
+
 public class VfsURI {
     private String host;
 
@@ -135,10 +137,10 @@ public class VfsURI {
         uri.append(this.scheme).append("://");
 
         // not all resource identifiers include user/passwd specifiers
-        if (user != null && user.trim().length() > 0) {
+        if (!isNullOrEmpty(user)) {
             uri.append(this.user).append(":");
 
-            if (passwd != null && passwd.trim().length() > 0) {
+            if (!isNullOrEmpty(passwd)) {
                 this.passwd = passwd.trim();
             } else {
                 this.passwd = "";
@@ -147,7 +149,7 @@ public class VfsURI {
         }
 
         // not all resource identifiers include a host specifier
-        if (host != null && host.trim().length() > 0) {
+        if (!isNullOrEmpty(host)) {
             this.host = host.trim();
             uri.append(this.host);
         }


Mime
View raw message