small cleanups

Project: http://git-wip-us.apache.org/repos/asf/ant-ivy/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant-ivy/commit/f6377533
Tree: http://git-wip-us.apache.org/repos/asf/ant-ivy/tree/f6377533
Diff: http://git-wip-us.apache.org/repos/asf/ant-ivy/diff/f6377533

Branch: refs/heads/xooki2asciidoc
Commit: f6377533645ca415addf9e1c428600e10053d72d
Parents: 8ff6e5a
Author: Matt Benson <[email protected]>
Authored: Fri Apr 21 09:15:34 2017 -0500
Committer: Matt Benson <[email protected]>
Committed: Fri Apr 21 09:15:34 2017 -0500

----------------------------------------------------------------------
 .../cache/DefaultRepositoryCacheManager.java    | 137 ++++++++-----------
 .../org/apache/ivy/core/resolve/IvyNode.java    | 117 +++++++---------
 .../ivy/plugins/resolver/BasicResolver.java     | 103 +++++++-------
 3 files changed, 152 insertions(+), 205 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f6377533/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
----------------------------------------------------------------------
diff --git 
a/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java 
b/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
index d6f33b7..6fe13c7 100644
--- a/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
+++ b/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
@@ -27,7 +27,6 @@ import java.security.NoSuchAlgorithmException;
 import java.text.ParseException;
 import java.util.Date;
 import java.util.Map;
-import java.util.Map.Entry;
 import java.util.regex.Pattern;
 
 import org.apache.ivy.Ivy;
@@ -188,17 +187,17 @@ public class DefaultRepositoryCacheManager implements 
RepositoryCacheManager, Iv
 
     public long getDefaultTTL() {
         if (defaultTTL == null) {
-            defaultTTL = new 
Long(parseDuration(settings.getVariable("ivy.cache.ttl.default")));
+            defaultTTL = 
Long.valueOf(parseDuration(settings.getVariable("ivy.cache.ttl.default")));
         }
         return defaultTTL.longValue();
     }
 
     public void setDefaultTTL(long defaultTTL) {
-        this.defaultTTL = new Long(defaultTTL);
+        this.defaultTTL = Long.valueOf(defaultTTL);
     }
 
     public void setDefaultTTL(String defaultTTL) {
-        this.defaultTTL = new Long(parseDuration(defaultTTL));
+        this.defaultTTL = Long.valueOf(parseDuration(defaultTTL));
     }
 
     public String getDataFilePattern() {
@@ -295,10 +294,9 @@ public class DefaultRepositoryCacheManager implements 
RepositoryCacheManager, Iv
 
             return days * MILLIS_IN_DAY + hours * MILLIS_IN_HOUR + minutes * 
MILLIS_IN_MINUTES
                     + seconds * MILLIS_IN_SECONDS + millis;
-        } else {
-            throw new IllegalArgumentException("invalid duration '" + duration
-                    + "': it must match " + DURATION_PATTERN.pattern() + " or 
'eternal'");
         }
+        throw new IllegalArgumentException("invalid duration '" + duration
+                + "': it must match " + DURATION_PATTERN.pattern() + " or 
'eternal'");
     }
 
     private int getGroupIntValue(java.util.regex.Matcher m, int groupNumber) {
@@ -309,19 +307,14 @@ public class DefaultRepositoryCacheManager implements 
RepositoryCacheManager, Iv
     /**
      * True if this cache should check lastmodified date to know if ivy files 
are up to date.
      * 
-     * @return
+     * @return boolean
      */
     public boolean isCheckmodified() {
         if (checkmodified == null) {
-            if (getSettings() != null) {
-                String check = 
getSettings().getVariable("ivy.resolver.default.check.modified");
-                return check != null ? Boolean.valueOf(check).booleanValue() : 
false;
-            } else {
-                return false;
-            }
-        } else {
-            return checkmodified.booleanValue();
+            return getSettings() != null && Boolean
+                    
.parseBoolean(getSettings().getVariable("ivy.resolver.default.check.modified"));
         }
+        return checkmodified.booleanValue();
     }
 
     public void setCheckmodified(boolean check) {
@@ -334,14 +327,9 @@ public class DefaultRepositoryCacheManager implements 
RepositoryCacheManager, Iv
      */
     public boolean isUseOrigin() {
         if (useOrigin == null) {
-            if (getSettings() != null) {
-                return getSettings().isDefaultUseOrigin();
-            } else {
-                return false;
-            }
-        } else {
-            return useOrigin.booleanValue();
+            return getSettings() != null && getSettings().isDefaultUseOrigin();
         }
+        return useOrigin.booleanValue();
     }
 
     public void setUseOrigin(boolean b) {
@@ -384,9 +372,8 @@ public class DefaultRepositoryCacheManager implements 
RepositoryCacheManager, Iv
     private File getArchiveFileInCache(Artifact artifact, ArtifactOrigin 
origin, boolean useOrigin) {
         if (useOrigin && !ArtifactOrigin.isUnknown(origin) && 
origin.isLocal()) {
             return Checks.checkAbsolute(origin.getLocation(), artifact + " 
origin location");
-        } else {
-            return new File(getRepositoryCacheRoot(), 
getArchivePathInCache(artifact, origin));
         }
+        return new File(getRepositoryCacheRoot(), 
getArchivePathInCache(artifact, origin));
     }
 
     public String getArchivePathInCache(Artifact artifact) {
@@ -396,9 +383,8 @@ public class DefaultRepositoryCacheManager implements 
RepositoryCacheManager, Iv
     public String getArchivePathInCache(Artifact artifact, ArtifactOrigin 
origin) {
         if (isOriginalMetadataArtifact(artifact)) {
             return IvyPatternHelper.substitute(getIvyPattern() + ".original", 
artifact, origin);
-        } else {
-            return IvyPatternHelper.substitute(getArtifactPattern(), artifact, 
origin);
         }
+        return IvyPatternHelper.substitute(getArtifactPattern(), artifact, 
origin);
     }
 
     /**
@@ -532,7 +518,7 @@ public class DefaultRepositoryCacheManager implements 
RepositoryCacheManager, Iv
                     // origin. We must parse the key as we do not know for 
sure what the original
                     // artifact is named.
                     String ownLocationKey = getLocationKey(artifact);
-                    for (Entry<Object, Object> entry : cdf.entrySet()) {
+                    for (Map.Entry<Object, Object> entry : cdf.entrySet()) {
                         if (entry.getValue().equals(location)
                                 && !ownLocationKey.equals(entry.getKey())) {
                             // found a match, key is
@@ -574,7 +560,7 @@ public class DefaultRepositoryCacheManager implements 
RepositoryCacheManager, Iv
                 origin.setLastChecked(Long.valueOf(lastChecked));
             }
             if (exists != null) {
-                origin.setExist(Boolean.valueOf(exists).booleanValue());
+                origin.setExist(Boolean.parseBoolean(exists));
             }
 
             return origin;
@@ -705,24 +691,23 @@ public class DefaultRepositoryCacheManager implements 
RepositoryCacheManager, Iv
         try {
             if (settings.getVersionMatcher().isDynamic(mrid)) {
                 String resolvedRevision = 
getResolvedRevision(expectedResolver, mrid, options);
-                if (resolvedRevision != null) {
-                    Message.verbose("found resolved revision in cache: " + 
mrid + " => "
-                            + resolvedRevision);
-
-                    // we have found another module in the cache, make sure we 
unlock
-                    // the original module
-                    unlockMetadataArtifact(mrid);
-                    mrid = ModuleRevisionId.newInstance(mrid, 
resolvedRevision);
-
-                    // don't forget to request a lock on the new module!
-                    if (!lockMetadataArtifact(mrid)) {
-                        Message.error("impossible to acquire lock for " + 
mrid);
-
-                        // we couldn't lock the new module, so no need to 
unlock it
-                        unlock = false;
-                        return null;
-                    }
-                } else {
+                if (resolvedRevision == null) {
+                    return null;
+                }
+                Message.verbose("found resolved revision in cache: " + mrid + 
" => "
+                        + resolvedRevision);
+
+                // we have found another module in the cache, make sure we 
unlock
+                // the original module
+                unlockMetadataArtifact(mrid);
+                mrid = ModuleRevisionId.newInstance(mrid, resolvedRevision);
+
+                // don't forget to request a lock on the new module!
+                if (!lockMetadataArtifact(mrid)) {
+                    Message.error("impossible to acquire lock for " + mrid);
+
+                    // we couldn't lock the new module, so no need to unlock it
+                    unlock = false;
                     return null;
                 }
             }
@@ -775,11 +760,10 @@ public class DefaultRepositoryCacheManager implements 
RepositoryCacheManager, Iv
                                 }
                             }
                             return new ResolvedModuleRevision(resolver, 
artResolver, depMD, madr);
-                        } else {
-                            Message.debug("found module in cache but with a 
different resolver: "
-                                    + "discarding: " + mrid + "; expected 
resolver="
-                                    + expectedResolver + "; resolver=" + 
resolver.getName());
                         }
+                        Message.debug("found module in cache but with a 
different resolver: "
+                                + "discarding: " + mrid + "; expected 
resolver="
+                                + expectedResolver + "; resolver=" + 
resolver.getName());
                     } else {
                         Message.debug("\tresolver not found: " + resolverName
                                 + " => cannot use cached ivy file for " + 
mrid);
@@ -853,7 +837,6 @@ public class DefaultRepositoryCacheManager implements 
RepositoryCacheManager, Iv
             return null;
         }
         try {
-            String resolvedRevision = null;
             if (options.isForce()) {
                 Message.verbose("refresh mode: no check for cached resolved 
revision for " + mrid);
                 return null;
@@ -865,7 +848,7 @@ public class DefaultRepositoryCacheManager implements 
RepositoryCacheManager, Iv
             } else {
                 cachedResolvedRevision = getCachedDataFile(mrid);
             }
-            resolvedRevision = 
cachedResolvedRevision.getProperty("resolved.revision");
+            String resolvedRevision = 
cachedResolvedRevision.getProperty("resolved.revision");
             if (resolvedRevision == null) {
                 Message.verbose(getName() + ": no cached resolved revision for 
" + mrid);
                 return null;
@@ -1173,13 +1156,12 @@ public class DefaultRepositoryCacheManager implements 
RepositoryCacheManager, Iv
      * @return the hash
      */
     private String computeResourceNameHash(Resource resource) {
-        byte[] shaDigest;
         try {
-            shaDigest = 
SHA_DIGEST.digest(resource.getName().getBytes("UTF-8"));
+            byte[] shaDigest = 
SHA_DIGEST.digest(resource.getName().getBytes("UTF-8"));
+            return HexEncoder.encode(shaDigest);
         } catch (UnsupportedEncodingException e) {
             throw new RuntimeException("UTF-8 not supported", e);
         }
-        return HexEncoder.encode(shaDigest);
     }
 
     /**
@@ -1203,18 +1185,13 @@ public class DefaultRepositoryCacheManager implements 
RepositoryCacheManager, Iv
         if (savedOrigin.getLastChecked() != null
                 && (time - savedOrigin.getLastChecked().longValue()) < ttl) {
             // still in the ttl period, no need to check, trust the cache
-            if (!archiveFile.exists()) {
-                // but if the local archive doesn't exist, trust the cache 
only if the cached origin
-                // says that the remote resource doesn't exist either
-                return !savedOrigin.isExists();
-            }
-            return true;
+            return archiveFile.exists() || !savedOrigin.isExists();
         }
         if (!archiveFile.exists()) {
             // the the file doesn't exist in the cache, obviously not up to 
date
             return false;
         }
-        origin.setLastChecked(new Long(time));
+        origin.setLastChecked(Long.valueOf(time));
         // check if the local resource is up to date regarding the remote one
         return archiveFile.lastModified() >= resource.getLastModified();
     }
@@ -1317,16 +1294,15 @@ public class DefaultRepositoryCacheManager implements 
RepositoryCacheManager, Iv
                                 + mrid);
                         rmr.getReport().setSearched(true);
                         return rmr;
-                    } else {
-                        Message.verbose("\t" + getName()
-                                + ": revision in cache is not up to date: " + 
mrid);
-                        if (isChanging(dd, mrid, options)) {
-                            // ivy file has been updated, we should see if it 
has a new publication
-                            // date to see if a new download is required (in 
case the dependency is
-                            // a changing one)
-                            cachedPublicationDate = rmr.getDescriptor()
-                                    .getResolvedPublicationDate();
-                        }
+                    }
+                    Message.verbose("\t" + getName()
+                            + ": revision in cache is not up to date: " + 
mrid);
+                    if (isChanging(dd, mrid, options)) {
+                        // ivy file has been updated, we should see if it has 
a new publication
+                        // date to see if a new download is required (in case 
the dependency is
+                        // a changing one)
+                        cachedPublicationDate = rmr.getDescriptor()
+                                .getResolvedPublicationDate();
                     }
                 }
             }
@@ -1359,9 +1335,8 @@ public class DefaultRepositoryCacheManager implements 
RepositoryCacheManager, Iv
                     parserSettings);
                 if (md == null) {
                     throw new IllegalStateException(
-                            "module descriptor parser returned a null module 
descriptor, "
-                                    + "which is not allowed. " + "parser=" + 
parser
-                                    + "; parser class=" + 
parser.getClass().getName()
+                            "module descriptor parser returned a null module 
descriptor, which is not allowed. parser="
+                                    + parser + "; parser class=" + 
parser.getClass().getName()
                                     + "; module descriptor resource=" + 
mdRef.getResource());
                 }
                 Message.debug("\t" + getName() + ": parsed downloaded md file 
for " + mrid
@@ -1376,11 +1351,9 @@ public class DefaultRepositoryCacheManager implements 
RepositoryCacheManager, Iv
                     deleteOldArtifacts = true;
                 }
                 if (deleteOldArtifacts) {
-                    String[] confs = md.getConfigurationsNames();
-                    for (int i = 0; i < confs.length; i++) {
-                        Artifact[] arts = md.getArtifacts(confs[i]);
-                        for (int j = 0; j < arts.length; j++) {
-                            Artifact transformedArtifact = 
NameSpaceHelper.transform(arts[j],
+                    for (String conf : md.getConfigurationsNames()) {
+                        for (Artifact art : md.getArtifacts(conf)) {
+                            Artifact transformedArtifact = 
NameSpaceHelper.transform(art,
                                 
options.getNamespace().getToSystemTransformer());
                             ArtifactOrigin origin = 
getSavedArtifactOrigin(transformedArtifact);
                             File artFile = 
getArchiveFileInCache(transformedArtifact, origin, false);
@@ -1462,7 +1435,7 @@ public class DefaultRepositoryCacheManager implements 
RepositoryCacheManager, Iv
         return new DefaultArtifact(mrid, new Date(), "metadata", "metadata", 
"ivy", true);
     }
 
-    // not used any more, but maybe useful for finer grain locking when 
downloading artifacts
+    // not used any more, but may be useful for finer grained locking when 
downloading artifacts
     // private boolean lockArtifact(Artifact artifact) {
     // try {
     // return getLockStrategy().lockArtifact(artifact,

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f6377533/src/java/org/apache/ivy/core/resolve/IvyNode.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/core/resolve/IvyNode.java 
b/src/java/org/apache/ivy/core/resolve/IvyNode.java
index f4e7702..48b23db 100644
--- a/src/java/org/apache/ivy/core/resolve/IvyNode.java
+++ b/src/java/org/apache/ivy/core/resolve/IvyNode.java
@@ -20,6 +20,7 @@ package org.apache.ivy.core.resolve;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -191,8 +192,7 @@ public class IvyNode implements Comparable<IvyNode> {
                         if (settings.getVersionMatcher().isDynamic(getId())
                                 && 
settings.getVersionMatcher().isDynamic(module.getId())) {
                             Message.error("impossible to resolve dynamic 
revision for " + getId()
-                                    + ": check your configuration and "
-                                    + "make sure revision is part of your 
pattern");
+                                    + ": check your configuration and make 
sure revision is part of your pattern");
                             problem = new RuntimeException("impossible to 
resolve dynamic revision");
                             return false;
                         }
@@ -254,13 +254,12 @@ public class IvyNode implements Comparable<IvyNode> {
         if (hasProblem()) {
             Message.debug("problem : " + problem.getMessage());
             return false;
-        } else {
-            DependencyDescriptor dd = getDependencyDescriptor(parent);
-            if (dd != null) {
-                usage.addUsage(rootModuleConf, dd, parentConf);
-            }
-            return loaded;
         }
+        DependencyDescriptor dd = getDependencyDescriptor(parent);
+        if (dd != null) {
+            usage.addUsage(rootModuleConf, dd, parentConf);
+        }
+        return loaded;
     }
 
     private void moveToRealNode(String rootModuleConf, IvyNode parent, String 
parentConf,
@@ -320,7 +319,7 @@ public class IvyNode implements Comparable<IvyNode> {
      *            the configuration to load of this node
      * @param requestedConf
      *            the actual node conf requested, possibly extending the 
<code>conf</code> one.
-     * @return
+     * @return {@link Collection} of {@link IvyNode}
      */
     public Collection<IvyNode> getDependencies(String rootModuleConf, String 
conf,
             String requestedConf) {
@@ -331,8 +330,8 @@ public class IvyNode implements Comparable<IvyNode> {
         DependencyDescriptor[] dds = md.getDependencies();
         // it's important to respect order => LinkedHashMap
         Map<ModuleRevisionId, IvyNode> dependencies = new 
LinkedHashMap<ModuleRevisionId, IvyNode>();
-        for (int i = 0; i < dds.length; i++) {
-            DependencyDescriptor dd = data.mediate(dds[i]);
+        for (DependencyDescriptor dependencyDescriptor : dds) {
+            DependencyDescriptor dd = data.mediate(dependencyDescriptor);
             String[] dependencyConfigurations = 
dd.getDependencyConfigurations(conf, requestedConf);
             if (dependencyConfigurations.length == 0) {
                 // no configuration of the dependency is required for current 
confs :
@@ -416,9 +415,8 @@ public class IvyNode implements Comparable<IvyNode> {
                 return null;
             }
             return Boolean.valueOf(c.doesCallersExclude(rootModuleConf, 
artifact, callersStack));
-        } else {
-            return Boolean.FALSE;
         }
+        return Boolean.FALSE;
     }
 
     public boolean hasConfigurationsToLoad() {
@@ -438,23 +436,24 @@ public class IvyNode implements Comparable<IvyNode> {
         if (md != null) {
             String[] confs = getRealConfs(conf);
             addRootModuleConfigurations(usage, rootModuleConf, confs);
-            for (int i = 0; i < confs.length; i++) {
-                Configuration c = md.getConfiguration(confs[i]);
+            for (String realConf : confs) {
+                Configuration c = md.getConfiguration(realConf);
                 if (c == null) {
                     confsToFetch.remove(conf);
                     if (isConfRequiredByMergedUsageOnly(rootModuleConf, conf)) 
{
                         Message.verbose("configuration required by evicted 
revision is not available in "
                                 + "selected revision. skipping " + conf + " in 
" + this);
-                    } else if (!conf.equals(confs[i])) {
+                    } else if (!conf.equals(realConf)) {
                         problem = new RuntimeException("configuration not 
found in " + this + ": '"
-                                + conf + "'. Missing configuration: '" + 
confs[i]
+                                + conf + "'. Missing configuration: '" + 
realConf
                                 + "'. It was required from " + parent + " " + 
parentConf);
                     } else {
                         problem = new RuntimeException("configuration not 
found in " + this + ": '"
-                                + confs[i] + "'. It was required from " + 
parent + " " + parentConf);
+                                + realConf + "'. It was required from " + 
parent + " " + parentConf);
                     }
                     return false;
-                } else if (shouldBePublic && !isRoot()
+                }
+                if (shouldBePublic && !isRoot()
                         && c.getVisibility() != 
Configuration.Visibility.PUBLIC) {
                     confsToFetch.remove(conf);
                     if (isConfRequiredByMergedUsageOnly(rootModuleConf, conf)) 
{
@@ -479,20 +478,12 @@ public class IvyNode implements Comparable<IvyNode> {
 
     private String getDefaultConf(String conf) {
         Matcher m = FALLBACK_CONF_PATTERN.matcher(conf);
-        if (m.matches()) {
-            return m.group(2);
-        } else {
-            return conf;
-        }
+        return m.matches() ? m.group(2) : conf;
     }
 
     private String getMainConf(String conf) {
         Matcher m = FALLBACK_CONF_PATTERN.matcher(conf);
-        if (m.matches()) {
-            return m.group(1);
-        } else {
-            return null;
-        }
+        return m.matches() ? m.group(1) : null;
     }
 
     public void updateConfsToFetch(Collection<String> confs) {
@@ -526,7 +517,7 @@ public class IvyNode implements Comparable<IvyNode> {
      * returns the required configurations from the given node
      * 
      * @param in
-     * @return
+     * @return array of configuration names
      */
     public String[] getRequiredConfigurations(IvyNode in, String inConf) {
         Collection<String> req = new LinkedHashSet<String>();
@@ -534,7 +525,7 @@ public class IvyNode implements Comparable<IvyNode> {
         for (IvyNodeUsage usage : mergedUsages.values()) {
             addAllIfNotNull(req, usage.getRequiredConfigurations(in, inConf));
         }
-        return req == null ? new String[0] : req.toArray(new 
String[req.size()]);
+        return req.toArray(new String[req.size()]);
     }
 
     private <T> void addAllIfNotNull(Collection<T> into, Collection<T> col) {
@@ -546,7 +537,7 @@ public class IvyNode implements Comparable<IvyNode> {
     /**
      * returns all the current required configurations of the node
      * 
-     * @return
+     * @return array of configuration names
      */
     public String[] getRequiredConfigurations() {
         Collection<String> required = new ArrayList<String>(confsToFetch.size()
@@ -574,7 +565,7 @@ public class IvyNode implements Comparable<IvyNode> {
      * Returns the configurations of the dependency required in a given root 
module configuration.
      * 
      * @param rootModuleConf
-     * @return
+     * @return array of configuration names
      */
     public String[] getConfigurations(String rootModuleConf) {
         Set<String> depConfs = new LinkedHashSet<String>();
@@ -613,29 +604,23 @@ public class IvyNode implements Comparable<IvyNode> {
 
     private void addRootModuleConfigurations(IvyNodeUsage usage, String 
rootModuleConf,
             String[] dependencyConfs) {
-        Set<String> depConfs = usage.addAndGetConfigurations(rootModuleConf);
         if (md != null) {
             // add all given dependency configurations to the set + extended 
ones
-            for (int i = 0; i < dependencyConfs.length; i++) {
-                depConfs.add(dependencyConfs[i]);
-                Configuration conf = md.getConfiguration(dependencyConfs[i]);
+            for (String dependencyConf : dependencyConfs) {
+                Configuration conf = md.getConfiguration(dependencyConf);
                 if (conf != null) {
-                    String[] exts = conf.getExtends();
                     // recursive add of extended
-                    addRootModuleConfigurations(usage, rootModuleConf, exts);
+                    addRootModuleConfigurations(usage, rootModuleConf, 
conf.getExtends());
                 }
             }
-        } else {
-            for (int i = 0; i < dependencyConfs.length; i++) {
-                depConfs.add(dependencyConfs[i]);
-            }
         }
+        Collections.addAll(usage.addAndGetConfigurations(rootModuleConf), 
dependencyConfs);
     }
 
     /**
      * Returns the root module configurations in which this dependency is 
required
      * 
-     * @return
+     * @return array of configuration names
      */
     public String[] getRootModuleConfigurations() {
         Set<String> confs = getRootModuleConfigurationsSet();
@@ -645,7 +630,7 @@ public class IvyNode implements Comparable<IvyNode> {
     /**
      * Returns the root module configurations in which this dependency is 
required
      * 
-     * @return
+     * @return {@link Set} of configuration names
      */
     public Set<String> getRootModuleConfigurationsSet() {
         Set<String> confs = new LinkedHashSet<String>();
@@ -674,9 +659,10 @@ public class IvyNode implements Comparable<IvyNode> {
             }
             conf = defaultConf;
         }
-        if (conf.startsWith("*")) {
+        if (conf.charAt(0) == '*') {
             return resolveSpecialConfigurations(new String[] {conf});
-        } else if (conf.indexOf(',') != -1) {
+        }
+        if (conf.indexOf(',') != -1) {
             String[] confs = conf.split(",");
             for (int i = 0; i < confs.length; i++) {
                 confs[i] = confs[i].trim();
@@ -705,8 +691,9 @@ public class IvyNode implements Comparable<IvyNode> {
         }
         if (path.contains(parent)) {
             path.add(0, parent);
-            Message.verbose("circular dependency found while looking for the 
path for another one: "
-                    + "was looking for " + from + " as a caller of " + 
path.get(path.size() - 1));
+            Message.verbose(
+                "circular dependency found while looking for the path for 
another one: was looking for "
+                        + from + " as a caller of " + path.get(path.size() - 
1));
             return path;
         }
         path.add(0, parent);
@@ -761,7 +748,7 @@ public class IvyNode implements Comparable<IvyNode> {
     /**
      * Returns all the artifacts of this dependency required in all the root 
module configurations
      * 
-     * @return
+     * @return array of {@link Artifact}s
      */
     public Artifact[] getAllArtifacts() {
         Set<Artifact> ret = new HashSet<Artifact>();
@@ -776,7 +763,7 @@ public class IvyNode implements Comparable<IvyNode> {
      * which the node is not evicted nor blacklisted
      * 
      * @param artifactFilter
-     * @return
+     * @return array of {@link Artifact}s
      */
     public Artifact[] getSelectedArtifacts(Filter<Artifact> artifactFilter) {
         Collection<Artifact> ret = new HashSet<Artifact>();
@@ -794,7 +781,7 @@ public class IvyNode implements Comparable<IvyNode> {
      * in the given root module configuration
      * 
      * @param rootModuleConf
-     * @return
+     * @return array of {@link Artifact}s
      */
     public Artifact[] getArtifacts(String rootModuleConf) {
         // first we look for the dependency configurations required
@@ -807,7 +794,7 @@ public class IvyNode implements Comparable<IvyNode> {
         if (md == null) {
             throw new IllegalStateException(
                     "impossible to get artifacts when data has not been 
loaded. IvyNode = "
-                            + this.toString());
+                            + this);
         }
 
         Set<Artifact> artifacts = new HashSet<Artifact>(); // the set we fill 
before returning
@@ -966,7 +953,7 @@ public class IvyNode implements Comparable<IvyNode> {
         if (md == null) {
             throw new IllegalStateException(
                     "impossible to get conflict manager when data has not been 
loaded. IvyNode = "
-                            + this.toString());
+                            + this);
         }
         ConflictManager cm = md.getConflictManager(mid);
         return cm == null ? settings.getConflictManager(mid) : cm;
@@ -1020,11 +1007,11 @@ public class IvyNode implements Comparable<IvyNode> {
     public ModuleRevisionId getResolvedId() {
         if (md != null && md.getResolvedModuleRevisionId().getRevision() != 
null) {
             return md.getResolvedModuleRevisionId();
-        } else if (module != null) {
+        }
+        if (module != null) {
             return module.getId();
-        } else {
-            return getId();
         }
+        return getId();
     }
 
     /**
@@ -1039,9 +1026,8 @@ public class IvyNode implements Comparable<IvyNode> {
     // 
/////////////////////////////////////////////////////////////////////////////
 
     boolean canExclude(String rootModuleConf) {
-        Caller[] callers = getCallers(rootModuleConf);
-        for (int i = 0; i < callers.length; i++) {
-            if (callers[i].canExclude()) {
+        for (Caller caller : getCallers(rootModuleConf)) {
+            if (caller.canExclude()) {
                 return true;
             }
         }
@@ -1250,10 +1236,8 @@ public class IvyNode implements Comparable<IvyNode> {
     }
 
     private void clearEvictionDataInAllCallers(String rootModuleConf, 
Stack<IvyNode> callerStack) {
-        IvyNode node = callerStack.peek();
-        Caller[] callers = node.getCallers(rootModuleConf);
-        for (int i = 0; i < callers.length; i++) {
-            IvyNode callerNode = findNode(callers[i].getModuleRevisionId());
+        for (Caller caller : callerStack.peek().getCallers(rootModuleConf)) {
+            IvyNode callerNode = findNode(caller.getModuleRevisionId());
             if (callerNode != null) {
                 callerNode.eviction = new IvyNodeEviction(callerNode);
                 if (!callerStack.contains(callerNode)) {
@@ -1291,9 +1275,8 @@ public class IvyNode implements Comparable<IvyNode> {
         if (isRoot()) {
             return false;
         }
-        String[] rootModuleConfigurations = getRootModuleConfigurations();
-        for (int i = 0; i < rootModuleConfigurations.length; i++) {
-            if (!isBlacklisted(rootModuleConfigurations[i])) {
+        for (String rootModuleConfiguration : getRootModuleConfigurations()) {
+            if (!isBlacklisted(rootModuleConfiguration)) {
                 return false;
             }
         }

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f6377533/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 2980d0c..389998d 100644
--- a/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java
+++ b/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java
@@ -34,7 +34,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.ListIterator;
 import java.util.Map;
-import java.util.Map.Entry;
 
 import org.apache.ivy.core.IvyContext;
 import org.apache.ivy.core.IvyPatternHelper;
@@ -97,6 +96,8 @@ public abstract class BasicResolver extends AbstractResolver {
      * </p>
      */
     private static class UnresolvedDependencyException extends 
RuntimeException {
+        private static final long serialVersionUID = 1L;
+
         private boolean error;
 
         /**
@@ -204,8 +205,7 @@ public abstract class BasicResolver extends 
AbstractResolver {
             boolean isDynamic = getAndCheckIsDynamic(systemMrid);
 
             // we first search for the dependency in cache
-            ResolvedModuleRevision rmr = null;
-            rmr = findModuleInCache(systemDd, data);
+            ResolvedModuleRevision rmr = findModuleInCache(systemDd, data);
             if (rmr != null) {
                 if (rmr.getDescriptor().isDefault() && rmr.getResolver() != 
this) {
                     Message.verbose("\t" + getName() + ": found revision in 
cache: " + systemMrid
@@ -277,30 +277,29 @@ public abstract class BasicResolver extends 
AbstractResolver {
                 }
                 if (!rmr.getReport().isDownloaded() && 
rmr.getReport().getLocalFile() != null) {
                     return checkLatest(systemDd, 
checkForcedResolvedModuleRevision(rmr), data);
-                } else {
-                    nsMd = rmr.getDescriptor();
+                }
+                nsMd = rmr.getDescriptor();
 
-                    // check descriptor data is in sync with resource revision 
and names
-                    systemMd = toSystem(nsMd);
-                    if (isCheckconsistency()) {
-                        checkDescriptorConsistency(systemMrid, systemMd, 
ivyRef);
-                        checkDescriptorConsistency(nsMrid, nsMd, ivyRef);
+                // check descriptor data is in sync with resource revision and 
names
+                systemMd = toSystem(nsMd);
+                if (isCheckconsistency()) {
+                    checkDescriptorConsistency(systemMrid, systemMd, ivyRef);
+                    checkDescriptorConsistency(nsMrid, nsMd, ivyRef);
+                } else {
+                    if (systemMd instanceof DefaultModuleDescriptor) {
+                        DefaultModuleDescriptor defaultMd = 
(DefaultModuleDescriptor) systemMd;
+                        ModuleRevisionId revision = getRevision(ivyRef, 
systemMrid, systemMd);
+                        defaultMd.setModuleRevisionId(revision);
+                        defaultMd.setResolvedModuleRevisionId(revision);
                     } else {
-                        if (systemMd instanceof DefaultModuleDescriptor) {
-                            DefaultModuleDescriptor defaultMd = 
(DefaultModuleDescriptor) systemMd;
-                            ModuleRevisionId revision = getRevision(ivyRef, 
systemMrid, systemMd);
-                            defaultMd.setModuleRevisionId(revision);
-                            defaultMd.setResolvedModuleRevisionId(revision);
-                        } else {
-                            Message.warn("consistency disabled with instance 
of non DefaultModuleDescriptor..."
-                                    + " module info can't be updated, so 
consistency check will be done");
-                            checkDescriptorConsistency(nsMrid, nsMd, ivyRef);
-                            checkDescriptorConsistency(systemMrid, systemMd, 
ivyRef);
-                        }
+                        Message.warn(
+                            "consistency disabled with instance of non 
DefaultModuleDescriptor... module info can't be updated, so consistency check 
will be done");
+                        checkDescriptorConsistency(nsMrid, nsMd, ivyRef);
+                        checkDescriptorConsistency(systemMrid, systemMd, 
ivyRef);
                     }
-                    rmr = new ResolvedModuleRevision(this, this, systemMd,
-                            toSystem(rmr.getReport()), isForce());
                 }
+                rmr = new ResolvedModuleRevision(this, this, systemMd,
+                        toSystem(rmr.getReport()), isForce());
             }
 
             resolveAndCheckRevision(systemMd, systemMrid, ivyRef, isDynamic);
@@ -390,9 +389,7 @@ public abstract class BasicResolver extends 
AbstractResolver {
             DefaultModuleDescriptor dmd = (DefaultModuleDescriptor) systemMd;
             if (dmd.isNamespaceUseful()) {
                 Message.warn("the module descriptor " + ivyRef.getResource()
-                        + " has information which can't be converted into "
-                        + "the system namespace. "
-                        + "It will require the availability of the namespace '"
+                        + " has information which can't be converted into the 
system namespace. It will require the availability of the namespace '"
                         + getNamespace().getName() + "' to be fully usable.");
             }
         }
@@ -407,7 +404,8 @@ public abstract class BasicResolver extends 
AbstractResolver {
                 throw new UnresolvedDependencyException("\t" + getName()
                         + ": unacceptable publication date => was=" + new 
Date(pubDate)
                         + " required=" + data.getDate());
-            } else if (pubDate == -1) {
+            }
+            if (pubDate == -1) {
                 throw new UnresolvedDependencyException("\t" + getName()
                         + ": impossible to guess publication date: artifact 
missing for "
                         + systemMrid);
@@ -437,7 +435,7 @@ public abstract class BasicResolver extends 
AbstractResolver {
 
     private void checkRevision(ModuleRevisionId systemMrid) {
         // check revision
-        int index = systemMrid.getRevision().indexOf("@");
+        int index = systemMrid.getRevision().indexOf('@');
         if (index != -1 && !systemMrid.getRevision().substring(index + 
1).equals(workspaceName)) {
             throw new UnresolvedDependencyException("\t" + getName() + ": 
unhandled revision => "
                     + systemMrid.getRevision());
@@ -545,15 +543,13 @@ public abstract class BasicResolver extends 
AbstractResolver {
                 try {
                     ResolvedModuleRevision rmr = BasicResolver.this.parse(new 
ResolvedResource(
                             resource, rev), dd, data);
-                    if (rmr == null) {
-                        return null;
-                    } else {
+                    if (rmr != null) {
                         return new MDResolvedResource(resource, rev, rmr);
                     }
                 } catch (ParseException e) {
                     Message.warn("Failed to parse the file '" + resource + 
"'", e);
-                    return null;
                 }
+                return null;
             }
 
         };
@@ -582,7 +578,7 @@ public abstract class BasicResolver extends 
AbstractResolver {
     private void checkDescriptorConsistency(ModuleRevisionId mrid, 
ModuleDescriptor md,
             ResolvedResource ivyRef) throws ParseException {
         boolean ok = true;
-        StringBuffer errors = new StringBuffer();
+        StringBuilder errors = new StringBuilder();
         if 
(!mrid.getOrganisation().equals(md.getModuleRevisionId().getOrganisation())) {
             Message.error("\t" + getName() + ": bad organisation found in " + 
ivyRef.getResource()
                     + ": expected='" + mrid.getOrganisation() + "' found='"
@@ -626,7 +622,7 @@ public abstract class BasicResolver extends 
AbstractResolver {
             errors.append("bad status: '" + md.getStatus() + "'; ");
             ok = false;
         }
-        for (Entry<String, String> extra : 
mrid.getExtraAttributes().entrySet()) {
+        for (Map.Entry<String, String> extra : 
mrid.getExtraAttributes().entrySet()) {
             if (extra.getValue() != null
                     && 
!extra.getValue().equals(md.getExtraAttribute(extra.getKey()))) {
                 String errorMsg = "bad " + extra.getKey() + " found in " + 
ivyRef.getResource()
@@ -721,13 +717,13 @@ public abstract class BasicResolver extends 
AbstractResolver {
                             + "requiring module descriptor: " + rres);
                     rejected.add(rres.getRevision() + " (MD)");
                     continue;
-                } else if (!versionMatcher.accept(mrid, md)) {
+                }
+                if (!versionMatcher.accept(mrid, md)) {
                     Message.debug("\t" + name + ": md rejected by version 
matcher: " + rres);
                     rejected.add(rres.getRevision() + " (MD)");
                     continue;
-                } else {
-                    found = r;
                 }
+                found = r;
             } else {
                 found = rres;
             }
@@ -801,7 +797,7 @@ public abstract class BasicResolver extends 
AbstractResolver {
         for (String m : ivyattempts) {
             Message.warn("  " + m);
         }
-        for (Entry<Artifact, List<String>> entry : artattempts.entrySet()) {
+        for (Map.Entry<Artifact, List<String>> entry : artattempts.entrySet()) 
{
             Artifact art = entry.getKey();
             List<String> attempts = entry.getValue();
             if (attempts != null) {
@@ -865,15 +861,14 @@ public abstract class BasicResolver extends 
AbstractResolver {
                 public ResolvedResource resolve(Artifact artifact) {
                     try {
                         Resource resource = getResource(origin.getLocation());
-                        if (resource == null) {
-                            return null;
+                        if (resource != null) {
+                            String revision = 
origin.getArtifact().getModuleRevisionId().getRevision();
+                            return new ResolvedResource(resource, revision);
                         }
-                        String revision = 
origin.getArtifact().getModuleRevisionId().getRevision();
-                        return new ResolvedResource(resource, revision);
                     } catch (IOException e) {
                         Message.debug(e);
-                        return null;
                     }
+                    return null;
                 }
             }, downloader, getCacheDownloadOptions(options));
     }
@@ -969,12 +964,9 @@ public abstract class BasicResolver extends 
AbstractResolver {
 
     protected ResolvedResource findFirstArtifactRef(ModuleDescriptor md, 
DependencyDescriptor dd,
             ResolveData data) {
-        ResolvedResource ret = null;
-        String[] conf = md.getConfigurationsNames();
-        for (int i = 0; i < conf.length; i++) {
-            Artifact[] artifacts = md.getArtifacts(conf[i]);
-            for (int j = 0; j < artifacts.length; j++) {
-                ret = getArtifactRef(artifacts[j], data.getDate());
+        for (String configName : md.getConfigurationsNames()) {
+            for (Artifact artifact : md.getArtifacts(configName)) {
+                ResolvedResource ret = getArtifactRef(artifact, 
data.getDate());
                 if (ret != null) {
                     return ret;
                 }
@@ -985,10 +977,10 @@ public abstract class BasicResolver extends 
AbstractResolver {
 
     protected long getAndCheck(Resource resource, File dest) throws 
IOException {
         long size = get(resource, dest);
-        String[] checksums = getChecksumAlgorithms();
-        boolean checked = false;
-        for (int i = 0; i < checksums.length && !checked; i++) {
-            checked = check(resource, dest, checksums[i]);
+        for (String checksum : getChecksumAlgorithms()) {
+            if (check(resource, dest, checksum)) {
+                break;
+            }
         }
         return size;
     }
@@ -1123,10 +1115,9 @@ public abstract class BasicResolver extends 
AbstractResolver {
         }
         // csDef is a comma separated list of checksum algorithms to use with 
this resolver
         // we parse and return it as a String[]
-        String[] checksums = csDef.split(",");
         List<String> algos = new ArrayList<String>();
-        for (int i = 0; i < checksums.length; i++) {
-            String cs = checksums[i].trim();
+        for (String checksum : csDef.split(",")) {
+            String cs = checksum.trim();
             if (!"".equals(cs) && !"none".equals(cs)) {
                 algos.add(cs);
             }

Reply via email to