ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gin...@apache.org
Subject ant-ivy git commit: use switch rather than a chain of if’s
Date Tue, 05 Dec 2017 15:39:05 GMT
Repository: ant-ivy
Updated Branches:
  refs/heads/master 14bdf34a9 -> da461de2d


use switch rather than a chain of if’s

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

Branch: refs/heads/master
Commit: da461de2db180f85c628552eea1a3a92ff94c8d7
Parents: 14bdf34
Author: Gintas Grigelionis <gintas@apache.org>
Authored: Tue Dec 5 16:38:51 2017 +0100
Committer: Gintas Grigelionis <gintas@apache.org>
Committed: Tue Dec 5 16:38:51 2017 +0100

----------------------------------------------------------------------
 src/java/org/apache/ivy/ant/IvyBuildList.java   |  30 ++--
 .../core/module/descriptor/Configuration.java   |  34 ++--
 .../ivy/osgi/obr/xml/CapabilityAdapter.java     |  70 +++++---
 .../ivy/osgi/obr/xml/RequirementAdapter.java    | 154 ++++++++--------
 .../parser/xml/XmlModuleDescriptorParser.java   | 115 +++++++-----
 .../parser/xml/XmlModuleDescriptorUpdater.java  | 178 ++++++++++---------
 .../ivy/plugins/resolver/BasicResolver.java     |  19 +-
 .../ivy/plugins/resolver/DualResolver.java      |  19 +-
 .../apache/ivy/util/url/AbstractURLHandler.java |  69 +++----
 .../conflict/LatestConflictManagerTest.java     |  23 ++-
 10 files changed, 407 insertions(+), 304 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/da461de2/src/java/org/apache/ivy/ant/IvyBuildList.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/ant/IvyBuildList.java b/src/java/org/apache/ivy/ant/IvyBuildList.java
index 7eacfed..8340065 100644
--- a/src/java/org/apache/ivy/ant/IvyBuildList.java
+++ b/src/java/org/apache/ivy/ant/IvyBuildList.java
@@ -290,21 +290,25 @@ public class IvyBuildList extends IvyTask {
     }
 
     private void onMissingDescriptor(File buildFile, File ivyFile, List<File> noDescriptor) {
-        if (OnMissingDescriptor.SKIP.equals(onMissingDescriptor)) {
-            Message.debug("skipping " + buildFile + ": descriptor " + ivyFile + " doesn't exist");
-        } else if (OnMissingDescriptor.FAIL.equals(onMissingDescriptor)) {
-            throw new BuildException(
-                    "a module has no module descriptor and onMissingDescriptor=fail. "
-                            + "Build file: " + buildFile + ". Expected descriptor: " + ivyFile);
-        } else {
-            if (OnMissingDescriptor.WARN.equals(onMissingDescriptor)) {
+        switch (onMissingDescriptor) {
+            case OnMissingDescriptor.FAIL:
+                throw new BuildException("a module has no module descriptor and"
+                        + " onMissingDescriptor=fail. Build file: " + buildFile
+                        + ". Expected descriptor: " + ivyFile);
+            case OnMissingDescriptor.SKIP:
+                Message.debug("skipping " + buildFile + ": descriptor " + ivyFile
+                        + " doesn't exist");
+                break;
+            case OnMissingDescriptor.WARN:
                 Message.warn("a module has no module descriptor. " + "Build file: " + buildFile
                         + ". Expected descriptor: " + ivyFile);
-            }
-            Message.verbose(String.format("no descriptor for %s: descriptor=%s: adding it at the %s of the path",
-                    buildFile, ivyFile, (OnMissingDescriptor.TAIL.equals(onMissingDescriptor) ? "tail" : "head")));
-            Message.verbose("\t(change onMissingDescriptor if you want to take another action");
-            noDescriptor.add(buildFile);
+                // fall through
+            default:
+                Message.verbose(String.format("no descriptor for %s: descriptor=%s: adding it at the %s of the path",
+                        buildFile, ivyFile, (OnMissingDescriptor.TAIL.equals(onMissingDescriptor) ? "tail" : "head")));
+                Message.verbose("\t(change onMissingDescriptor if you want to take another action");
+                noDescriptor.add(buildFile);
+                break;
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/da461de2/src/java/org/apache/ivy/core/module/descriptor/Configuration.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/core/module/descriptor/Configuration.java b/src/java/org/apache/ivy/core/module/descriptor/Configuration.java
index d5ff9c7..b053518 100644
--- a/src/java/org/apache/ivy/core/module/descriptor/Configuration.java
+++ b/src/java/org/apache/ivy/core/module/descriptor/Configuration.java
@@ -38,12 +38,13 @@ public class Configuration extends DefaultExtendableItem implements InheritableI
         public static final Visibility PRIVATE = new Visibility("private");
 
         public static Visibility getVisibility(String name) {
-            if ("private".equals(name)) {
-                return PRIVATE;
-            } else if ("public".equals(name)) {
-                return PUBLIC;
-            } else {
-                throw new IllegalArgumentException("unknown visibility " + name);
+            switch (name) {
+                case "private":
+                    return PRIVATE;
+                case "public":
+                    return PUBLIC;
+                default:
+                    throw new IllegalArgumentException("unknown visibility " + name);
             }
         }
 
@@ -222,14 +223,19 @@ public class Configuration extends DefaultExtendableItem implements InheritableI
 
         Set<String> newExtends = new LinkedHashSet<>();
         for (String extend : extendsFrom) {
-            if ("*".equals(extend)) {
-                addOther(configs, null, newExtends);
-            } else if ("*(public)".equals(extend)) {
-                addOther(configs, Visibility.PUBLIC, newExtends);
-            } else if ("*(private)".equals(extend)) {
-                addOther(configs, Visibility.PRIVATE, newExtends);
-            } else {
-                newExtends.add(extend);
+            switch (extend) {
+                case "*":
+                    addOther(configs, null, newExtends);
+                    break;
+                case "*(public)":
+                    addOther(configs, Visibility.PUBLIC, newExtends);
+                    break;
+                case "*(private)":
+                    addOther(configs, Visibility.PRIVATE, newExtends);
+                    break;
+                default:
+                    newExtends.add(extend);
+                    break;
             }
         }
 

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/da461de2/src/java/org/apache/ivy/osgi/obr/xml/CapabilityAdapter.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/osgi/obr/xml/CapabilityAdapter.java b/src/java/org/apache/ivy/osgi/obr/xml/CapabilityAdapter.java
index 2294838..52e9a72 100644
--- a/src/java/org/apache/ivy/osgi/obr/xml/CapabilityAdapter.java
+++ b/src/java/org/apache/ivy/osgi/obr/xml/CapabilityAdapter.java
@@ -31,17 +31,20 @@ public class CapabilityAdapter {
 
     public static void adapt(BundleInfo bundleInfo, Capability capability) throws ParseException {
         String name = capability.getName();
-        if (BundleInfo.PACKAGE_TYPE.equals(name)) {
-            ExportPackage exportPackage = getExportPackage(bundleInfo, capability);
-            bundleInfo.addCapability(exportPackage);
-        } else if (BundleInfo.BUNDLE_TYPE.equals(name)) {
-            // nothing to do, already handled at the resource tag level
-        } else if (BundleInfo.SERVICE_TYPE.equals(name)) {
-            BundleCapability service = getOSGiService(bundleInfo, capability);
-            bundleInfo.addCapability(service);
-        } else {
-            Message.warn("Unsupported capability '" + name + "' on the bundle '"
-                    + bundleInfo.getSymbolicName() + "'");
+        switch (name) {
+            case BundleInfo.PACKAGE_TYPE:
+                bundleInfo.addCapability(getExportPackage(bundleInfo, capability));
+                break;
+            case BundleInfo.BUNDLE_TYPE:
+                // nothing to do, already handled at the resource tag level
+                break;
+            case BundleInfo.SERVICE_TYPE:
+                bundleInfo.addCapability(getOSGiService(bundleInfo, capability));
+                break;
+            default:
+                Message.warn("Unsupported capability '" + name + "' on the bundle '"
+                        + bundleInfo.getSymbolicName() + "'");
+                break;
         }
     }
 
@@ -52,16 +55,21 @@ public class CapabilityAdapter {
         String uses = null;
         for (CapabilityProperty property : capability.getProperties()) {
             String propName = property.getName();
-            if ("package".equals(propName)) {
-                pkgName = property.getValue();
-            } else if ("version".equals(propName)) {
-                version = new Version(property.getValue());
-            } else if ("uses".equals(propName)) {
-                uses = property.getValue();
-            } else {
-                Message.warn("Unsupported property '" + propName
-                        + "' on the 'package' capability of the bundle '"
-                        + bundleInfo.getSymbolicName() + "'");
+            switch (propName) {
+                case "package":
+                    pkgName = property.getValue();
+                    break;
+                case "uses":
+                    uses = property.getValue();
+                    break;
+                case "version":
+                    version = new Version(property.getValue());
+                    break;
+                default:
+                    Message.warn("Unsupported property '" + propName
+                            + "' on the 'package' capability of the bundle '"
+                            + bundleInfo.getSymbolicName() + "'");
+                    break;
             }
         }
         if (pkgName == null) {
@@ -83,14 +91,18 @@ public class CapabilityAdapter {
 
         for (CapabilityProperty property : capability.getProperties()) {
             String propName = property.getName();
-            if ("service".equals(propName)) {
-                name = property.getValue();
-            } else if ("version".equals(propName)) {
-                version = new Version(property.getValue());
-            } else {
-                Message.warn("Unsupported property '" + propName
-                        + "' on the 'package' capability of the bundle '"
-                        + bundleInfo.getSymbolicName() + "'");
+            switch (propName) {
+                case "service":
+                    name = property.getValue();
+                    break;
+                case "version":
+                    version = new Version(property.getValue());
+                    break;
+                default:
+                    Message.warn("Unsupported property '" + propName
+                            + "' on the 'package' capability of the bundle '"
+                            + bundleInfo.getSymbolicName() + "'");
+                    break;
             }
         }
 

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/da461de2/src/java/org/apache/ivy/osgi/obr/xml/RequirementAdapter.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/osgi/obr/xml/RequirementAdapter.java b/src/java/org/apache/ivy/osgi/obr/xml/RequirementAdapter.java
index f453cf2..659cba3 100644
--- a/src/java/org/apache/ivy/osgi/obr/xml/RequirementAdapter.java
+++ b/src/java/org/apache/ivy/osgi/obr/xml/RequirementAdapter.java
@@ -95,84 +95,98 @@ public class RequirementAdapter {
     private void parseCompareFilter(CompareFilter compareFilter, boolean not)
             throws UnsupportedFilterException {
         String att = compareFilter.getLeftValue();
-        if (BundleInfo.PACKAGE_TYPE.equals(att) || BundleInfo.BUNDLE_TYPE.equals(att)
-                || BundleInfo.EXECUTION_ENVIRONMENT_TYPE.equals(att) || "symbolicname".equals(att)
-                || BundleInfo.SERVICE_TYPE.equals(att)) {
-            if (not) {
-                throw new UnsupportedFilterException(
-                        "Not filter on requirement comparison is not supported");
-            }
-            if (type != null) {
-                throw new UnsupportedFilterException("Multiple requirement type are not supported");
-            }
-            if ("symbolicname".equals(att)) {
-                type = BundleInfo.BUNDLE_TYPE;
-            } else {
-                type = att;
-            }
-            if (compareFilter.getOperator() != Operator.EQUALS) {
-                throw new UnsupportedFilterException(
-                        "Filtering is only supported with the operator '='");
-            }
-            name = compareFilter.getRightValue();
-        } else if ("version".equals(att)) {
-            String v = compareFilter.getRightValue();
-            Version version = new Version(v);
-            Operator operator = compareFilter.getOperator();
-            if (not) {
-                if (operator == Operator.EQUALS) {
-                    throw new UnsupportedFilterException(
-                            "Not filter on equals comparison is not supported");
-                } else if (operator == Operator.GREATER_OR_EQUAL) {
-                    operator = Operator.LOWER_THAN;
-                } else if (operator == Operator.GREATER_THAN) {
-                    operator = Operator.LOWER_OR_EQUAL;
-                } else if (operator == Operator.LOWER_OR_EQUAL) {
-                    operator = Operator.GREATER_THAN;
-                } else if (operator == Operator.LOWER_THAN) {
-                    operator = Operator.GREATER_OR_EQUAL;
-                }
-            }
-            if (operator == Operator.EQUALS) {
-                if (startVersion != null || endVersion != null) {
+        if ("symbolicname".equals(att)) {
+            att = BundleInfo.BUNDLE_TYPE;
+        }
+        switch (att) {
+            case BundleInfo.BUNDLE_TYPE:
+            case BundleInfo.EXECUTION_ENVIRONMENT_TYPE:
+            case BundleInfo.PACKAGE_TYPE:
+            case BundleInfo.SERVICE_TYPE:
+                if (not) {
                     throw new UnsupportedFilterException(
-                            "Multiple version matching is not supported");
+                            "Not filter on requirement comparison is not supported");
                 }
-                startVersion = version;
-                startExclusive = false;
-                endVersion = version;
-                endExclusive = false;
-            } else if (operator == Operator.GREATER_OR_EQUAL) {
-                if (startVersion != null) {
+                if (compareFilter.getOperator() != Operator.EQUALS) {
                     throw new UnsupportedFilterException(
-                            "Multiple version matching is not supported");
+                            "Filtering is only supported with the operator '='");
                 }
-                startVersion = version;
-                startExclusive = false;
-            } else if (operator == Operator.GREATER_THAN) {
-                if (startVersion != null) {
+                if (type != null) {
                     throw new UnsupportedFilterException(
-                            "Multiple version matching is not supported");
+                            "Multiple requirement type are not supported");
                 }
-                startVersion = version;
-                startExclusive = true;
-            } else if (operator == Operator.LOWER_OR_EQUAL) {
-                if (endVersion != null) {
-                    throw new UnsupportedFilterException(
-                            "Multiple version matching is not supported");
+                type = att;
+                name = compareFilter.getRightValue();
+                break;
+            case "version":
+                Version version = new Version(compareFilter.getRightValue());
+                Operator operator = compareFilter.getOperator();
+                if (not) {
+                    switch (operator) {
+                        case EQUALS:
+                            throw new UnsupportedFilterException(
+                                    "Not filter on equals comparison is not supported");
+                        case GREATER_OR_EQUAL:
+                            operator = Operator.LOWER_THAN;
+                            break;
+                        case GREATER_THAN:
+                            operator = Operator.LOWER_OR_EQUAL;
+                            break;
+                        case LOWER_OR_EQUAL:
+                            operator = Operator.GREATER_THAN;
+                            break;
+                        case LOWER_THAN:
+                            operator = Operator.GREATER_OR_EQUAL;
+                            break;
+                    }
                 }
-                endVersion = version;
-                endExclusive = false;
-            } else if (operator == Operator.LOWER_THAN) {
-                if (endVersion != null) {
-                    throw new UnsupportedFilterException(
-                            "Multiple version matching is not supported");
+                switch (operator) {
+                    case EQUALS:
+                        if (startVersion != null || endVersion != null) {
+                            throw new UnsupportedFilterException(
+                                    "Multiple version matching is not supported");
+                        }
+                        startVersion = version;
+                        startExclusive = false;
+                        endVersion = version;
+                        endExclusive = false;
+                        break;
+                    case GREATER_OR_EQUAL:
+                        if (startVersion != null) {
+                            throw new UnsupportedFilterException(
+                                    "Multiple version matching is not supported");
+                        }
+                        startVersion = version;
+                        startExclusive = false;
+                        break;
+                    case GREATER_THAN:
+                        if (startVersion != null) {
+                            throw new UnsupportedFilterException(
+                                    "Multiple version matching is not supported");
+                        }
+                        startVersion = version;
+                        startExclusive = true;
+                        break;
+                    case LOWER_OR_EQUAL:
+                        if (endVersion != null) {
+                            throw new UnsupportedFilterException(
+                                    "Multiple version matching is not supported");
+                        }
+                        endVersion = version;
+                        endExclusive = false;
+                        break;
+                    case LOWER_THAN:
+                        if (endVersion != null) {
+                            throw new UnsupportedFilterException(
+                                    "Multiple version matching is not supported");
+                        }
+                        endVersion = version;
+                        endExclusive = true;
+                        break;
                 }
-                endVersion = version;
-                endExclusive = true;
-            }
-        } else {
-            throw new UnsupportedFilterException("Unsupported attribute: " + att);
+                break;
+            default:
+                throw new UnsupportedFilterException("Unsupported attribute: " + att);
         }
 
     }

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/da461de2/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 17b2d23..e81ecbd 100644
--- a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java
+++ b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java
@@ -745,9 +745,13 @@ public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser {
 
         protected void managerStarted(Attributes attributes, String managerAtt) {
             String org = settings.substitute(attributes.getValue("org"));
-            org = (org == null) ? PatternMatcher.ANY_EXPRESSION : org;
+            if (org == null) {
+                org = PatternMatcher.ANY_EXPRESSION;
+            }
             String mod = settings.substitute(attributes.getValue("module"));
-            mod = (mod == null) ? PatternMatcher.ANY_EXPRESSION : mod;
+            if (mod == null) {
+                mod = PatternMatcher.ANY_EXPRESSION;
+            }
             ConflictManager cm;
             String name = settings.substitute(attributes.getValue(managerAtt));
             String rev = settings.substitute(attributes.getValue("rev"));
@@ -764,8 +768,8 @@ public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser {
                 return;
             }
             String matcherName = settings.substitute(attributes.getValue("matcher"));
-            PatternMatcher matcher = matcherName == null ? defaultMatcher : settings
-                    .getMatcher(matcherName);
+            PatternMatcher matcher = (matcherName == null) ? defaultMatcher
+                    : settings.getMatcher(matcherName);
             if (matcher == null) {
                 addError("unknown matcher: " + matcherName);
                 return;
@@ -775,14 +779,18 @@ public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser {
 
         protected void mediationOverrideStarted(Attributes attributes) {
             String org = settings.substitute(attributes.getValue("org"));
-            org = org == null ? PatternMatcher.ANY_EXPRESSION : org;
+            if (org == null) {
+                org = PatternMatcher.ANY_EXPRESSION;
+            }
             String mod = settings.substitute(attributes.getValue("module"));
-            mod = mod == null ? PatternMatcher.ANY_EXPRESSION : mod;
+            if (mod == null) {
+                mod = PatternMatcher.ANY_EXPRESSION;
+            }
             String rev = settings.substitute(attributes.getValue("rev"));
             String branch = settings.substitute(attributes.getValue("branch"));
             String matcherName = settings.substitute(attributes.getValue("matcher"));
-            PatternMatcher matcher = matcherName == null ? defaultMatcher : settings
-                    .getMatcher(matcherName);
+            PatternMatcher matcher = (matcherName == null) ? defaultMatcher
+                    : settings.getMatcher(matcherName);
             if (matcher == null) {
                 addError("unknown matcher: " + matcherName);
                 return;
@@ -805,8 +813,8 @@ public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser {
             // the specified file.
             Parser parser = new Parser(getModuleDescriptorParser(), settings);
             parser.setInput(url);
-            parser.setMd(new DefaultModuleDescriptor(getModuleDescriptorParser(), new URLResource(
-                    url)));
+            parser.setMd(new DefaultModuleDescriptor(getModuleDescriptorParser(),
+                    new URLResource(url)));
             XMLHelper.parse(url, null, parser);
 
             // add the configurations from this temporary parser to this module descriptor
@@ -945,11 +953,17 @@ public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser {
             if (state == State.PUB) {
                 // this is a published artifact
                 String artName = settings.substitute(attributes.getValue("name"));
-                artName = artName == null ? getMd().getModuleRevisionId().getName() : artName;
+                if (artName == null) {
+                    artName = getMd().getModuleRevisionId().getName();
+                }
                 String type = settings.substitute(attributes.getValue("type"));
-                type = type == null ? "jar" : type;
+                if (type == null) {
+                    type = "jar";
+                }
                 String ext = settings.substitute(attributes.getValue("ext"));
-                ext = ext != null ? ext : type;
+                if (ext == null) {
+                    ext = type;
+                }
                 String url = settings.substitute(attributes.getValue("url"));
                 artifact = new MDArtifact(getMd(), artName, type, ext, url == null ? null
                         : new URL(url), ExtendableItemHelper.getExtraAttributes(settings,
@@ -1102,35 +1116,52 @@ public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser {
                 type = "artifact".equals(tag) ? "jar" : PatternMatcher.ANY_EXPRESSION;
             }
             String ext = settings.substitute(attributes.getValue("ext"));
-            ext = ext != null ? ext : type;
-            if (state == State.DEP_ARTIFACT) {
-                String url = settings.substitute(attributes.getValue("url"));
-                Map<String, String> extraAtt = ExtendableItemHelper.getExtraAttributes(settings,
-                    attributes, Arrays.asList("name", "type", "ext", "url", "conf"));
-                confAware = new DefaultDependencyArtifactDescriptor(dd, name, type, ext,
-                        url == null ? null : new URL(url), extraAtt);
-            } else if (state == State.ARTIFACT_INCLUDE) {
-                PatternMatcher matcher = getPatternMatcher(attributes.getValue("matcher"));
-                String org = settings.substitute(attributes.getValue("org"));
-                org = org == null ? PatternMatcher.ANY_EXPRESSION : org;
-                String module = settings.substitute(attributes.getValue("module"));
-                module = module == null ? PatternMatcher.ANY_EXPRESSION : module;
-                ArtifactId aid = new ArtifactId(new ModuleId(org, module), name, type, ext);
-                Map<String, String> extraAtt = ExtendableItemHelper.getExtraAttributes(settings,
-                    attributes, Arrays.asList("org", "module", "name", "type", "ext", "matcher",
-                            "conf"));
-                confAware = new DefaultIncludeRule(aid, matcher, extraAtt);
-            } else { // _state == ARTIFACT_EXCLUDE || EXCLUDE
-                PatternMatcher matcher = getPatternMatcher(attributes.getValue("matcher"));
-                String org = settings.substitute(attributes.getValue("org"));
-                org = org == null ? PatternMatcher.ANY_EXPRESSION : org;
-                String module = settings.substitute(attributes.getValue("module"));
-                module = module == null ? PatternMatcher.ANY_EXPRESSION : module;
-                ArtifactId aid = new ArtifactId(new ModuleId(org, module), name, type, ext);
-                Map<String, String> extraAtt = ExtendableItemHelper.getExtraAttributes(settings,
-                    attributes, Arrays.asList("org", "module", "name", "type", "ext", "matcher",
-                            "conf"));
-                confAware = new DefaultExcludeRule(aid, matcher, extraAtt);
+            if (ext == null) {
+                ext = type;
+            }
+            switch (state) {
+                case State.DEP_ARTIFACT: {
+                    String url = settings.substitute(attributes.getValue("url"));
+                    Map<String, String> extraAtt = ExtendableItemHelper.getExtraAttributes(settings,
+                            attributes, Arrays.asList("name", "type", "ext", "url", "conf"));
+                    confAware = new DefaultDependencyArtifactDescriptor(dd, name, type, ext,
+                            url == null ? null : new URL(url), extraAtt);
+                    break;
+                }
+                case State.ARTIFACT_INCLUDE: {
+                    PatternMatcher matcher = getPatternMatcher(attributes.getValue("matcher"));
+                    String org = settings.substitute(attributes.getValue("org"));
+                    if (org == null) {
+                        org = PatternMatcher.ANY_EXPRESSION;
+                    }
+                    String module = settings.substitute(attributes.getValue("module"));
+                    if (module == null) {
+                        module = PatternMatcher.ANY_EXPRESSION;
+                    }
+                    ArtifactId aid = new ArtifactId(new ModuleId(org, module), name, type, ext);
+                    Map<String, String> extraAtt = ExtendableItemHelper.getExtraAttributes(settings,
+                            attributes, Arrays.asList("org", "module", "name", "type", "ext", "matcher",
+                                    "conf"));
+                    confAware = new DefaultIncludeRule(aid, matcher, extraAtt);
+                    break;
+                }
+                default: { // _state == ARTIFACT_EXCLUDE || EXCLUDE
+                    PatternMatcher matcher = getPatternMatcher(attributes.getValue("matcher"));
+                    String org = settings.substitute(attributes.getValue("org"));
+                    if (org == null) {
+                        org = PatternMatcher.ANY_EXPRESSION;
+                    }
+                    String module = settings.substitute(attributes.getValue("module"));
+                    if (module == null) {
+                        module = PatternMatcher.ANY_EXPRESSION;
+                    }
+                    ArtifactId aid = new ArtifactId(new ModuleId(org, module), name, type, ext);
+                    Map<String, String> extraAtt = ExtendableItemHelper.getExtraAttributes(settings,
+                            attributes, Arrays.asList("org", "module", "name", "type", "ext", "matcher",
+                                    "conf"));
+                    confAware = new DefaultExcludeRule(aid, matcher, extraAtt);
+                    break;
+                }
             }
             String confs = settings.substitute(attributes.getValue("conf"));
             // only add confs if they are specified. if they aren't, endElement will handle this

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/da461de2/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 fde1a55..f52c132 100644
--- a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java
+++ b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java
@@ -432,29 +432,34 @@ public final class XmlModuleDescriptorUpdater {
                 String name = attributes.getQName(i);
                 String value = null;
 
-                if ("revision".equals(name)) {
-                    // replace inline revision with resolved parent revision
-                    ModuleDescriptor merged = options.getMergedDescriptor();
-                    if (merged != null) {
-                        for (ExtendsDescriptor parent : merged.getInheritedDescriptors()) {
-                            ModuleRevisionId resolvedId = parent.getResolvedParentRevisionId();
-                            if (parentId.equals(resolvedId.getModuleId())) {
-                                value = resolvedId.getRevision();
-                                if (value != null) {
-                                    break;
+                switch (name) {
+                    case "revision":
+                        // replace inline revision with resolved parent revision
+                        ModuleDescriptor merged = options.getMergedDescriptor();
+                        if (merged != null) {
+                            for (ExtendsDescriptor parent : merged.getInheritedDescriptors()) {
+                                ModuleRevisionId resolvedId = parent.getResolvedParentRevisionId();
+                                if (parentId.equals(resolvedId.getModuleId())) {
+                                    value = resolvedId.getRevision();
+                                    if (value != null) {
+                                        break;
+                                    }
                                 }
                             }
                         }
-                    }
-                    if (value == null) {
+                        if (value == null) {
+                            value = substitute(settings, attributes.getValue(i));
+                        }
+                        break;
+                    case "organisation":
+                        value = org;
+                        break;
+                    case "module":
+                        value = module;
+                        break;
+                    default:
                         value = substitute(settings, attributes.getValue(i));
-                    }
-                } else if ("organisation".equals(name)) {
-                    value = org;
-                } else if ("module".equals(name)) {
-                    value = module;
-                } else {
-                    value = substitute(settings, attributes.getValue(i));
+                        break;
                 }
                 write(" " + name + "=\"" + value + "\"");
             }
@@ -578,50 +583,59 @@ public final class XmlModuleDescriptorUpdater {
 
             for (int i = 0; i < attributes.getLength(); i++) {
                 String attName = attributes.getQName(i);
-                if ("rev".equals(attName)) {
-                    String rev = resolvedRevisions.get(systemMrid);
-                    if (rev != null) {
-                        write(" rev=\"" + rev + "\"");
-                        if (attributes.getIndex("branchConstraint") == -1
-                                && branchConstraint != null) {
-                            write(" branchConstraint=\"" + branchConstraint + "\"");
+                switch (attName) {
+                    case "rev":
+                        String rev = resolvedRevisions.get(systemMrid);
+                        if (rev == null) {
+                            write(" rev=\"" + systemMrid.getRevision() + "\"");
+                        } else {
+                            write(" rev=\"" + rev + "\"");
+                            if (attributes.getIndex("branchConstraint") == -1
+                                    && branchConstraint != null) {
+                                write(" branchConstraint=\"" + branchConstraint + "\"");
+                            }
+                            if (generateRevConstraint && attributes.getIndex("revConstraint") == -1
+                                    && !rev.equals(systemMrid.getRevision())) {
+                                write(" revConstraint=\"" + systemMrid.getRevision() + "\"");
+                            }
                         }
-                        if (generateRevConstraint && attributes.getIndex("revConstraint") == -1
-                                && !rev.equals(systemMrid.getRevision())) {
-                            write(" revConstraint=\"" + systemMrid.getRevision() + "\"");
+                        break;
+                    case "revConstraint":
+                        write(" revConstraint=\"" + revisionConstraint + "\"");
+                        break;
+                    case "org":
+                        write(" org=\"" + systemMrid.getOrganisation() + "\"");
+                        break;
+                    case "name":
+                        write(" name=\"" + systemMrid.getName() + "\"");
+                        break;
+                    case "branch":
+                        if (newBranch != null) {
+                            write(" branch=\"" + newBranch + "\"");
+                        } else if (!resolvedBranches.containsKey(systemMrid)) {
+                            write(" branch=\"" + systemMrid.getBranch() + "\"");
+                        } else {
+                            // if resolvedBranches contains the systemMrid, but the new branch is null,
+                            // the branch attribute will be removed altogether
                         }
-                    } else {
-                        write(" rev=\"" + systemMrid.getRevision() + "\"");
-                    }
-                } else if ("revConstraint".equals(attName)) {
-                    write(" revConstraint=\"" + revisionConstraint + "\"");
-                } else if ("org".equals(attName)) {
-                    write(" org=\"" + systemMrid.getOrganisation() + "\"");
-                } else if ("name".equals(attName)) {
-                    write(" name=\"" + systemMrid.getName() + "\"");
-                } else if ("branch".equals(attName)) {
-                    if (newBranch != null) {
-                        write(" branch=\"" + newBranch + "\"");
-                    } else if (!resolvedBranches.containsKey(systemMrid)) {
-                        write(" branch=\"" + systemMrid.getBranch() + "\"");
-                    } else {
-                        // if resolvedBranches contains the systemMrid, but the new branch is null,
-                        // the branch attribute will be removed altogether
-                    }
-                } else if ("branchConstraint".equals(attName)) {
-                    write(" branchConstraint=\"" + branchConstraint + "\"");
-                } else if ("conf".equals(attName)) {
-                    String oldMapping = substitute(settings, attributes.getValue("conf"));
-                    if (!oldMapping.isEmpty()) {
-                        String newMapping = removeConfigurationsFromMapping(oldMapping);
-                        if (!newMapping.isEmpty()) {
-                            write(" conf=\"" + newMapping + "\"");
-                            buffers.peek().setPrint(true);
+                        break;
+                    case "branchConstraint":
+                        write(" branchConstraint=\"" + branchConstraint + "\"");
+                        break;
+                    case "conf":
+                        String oldMapping = substitute(settings, attributes.getValue("conf"));
+                        if (!oldMapping.isEmpty()) {
+                            String newMapping = removeConfigurationsFromMapping(oldMapping);
+                            if (!newMapping.isEmpty()) {
+                                write(" conf=\"" + newMapping + "\"");
+                                buffers.peek().setPrint(true);
+                            }
                         }
-                    }
-                } else {
-                    write(" " + attName + "=\""
-                            + substitute(settings, attributes.getValue(attName)) + "\"");
+                        break;
+                    default:
+                        write(" " + attName + "=\""
+                                + substitute(settings, attributes.getValue(attName)) + "\"");
+                        break;
                 }
             }
 
@@ -642,11 +656,7 @@ public final class XmlModuleDescriptorUpdater {
             buffers.push(buffer);
             try {
                 URL url;
-                if (settings != null) {
-                    url = settings.getRelativeUrlResolver().getURL(relativePathCtx,
-                        settings.substitute(attributes.getValue("file")),
-                        settings.substitute(attributes.getValue("url")));
-                } else {
+                if (settings == null) {
                     // TODO : settings can be null, but I don't why.
                     // Check if the following code is correct in that case
                     String fileName = attributes.getValue("file");
@@ -656,6 +666,10 @@ public final class XmlModuleDescriptorUpdater {
                     } else {
                         url = Checks.checkAbsolute(fileName, "settings.include").toURI().toURL();
                     }
+                } else {
+                    url = settings.getRelativeUrlResolver().getURL(relativePathCtx,
+                        settings.substitute(attributes.getValue("file")),
+                        settings.substitute(attributes.getValue("url")));
                 }
                 XMLHelper.parse(url, null, new DefaultHandler() {
                     private boolean insideConfigurations = false;
@@ -1147,21 +1161,25 @@ public final class XmlModuleDescriptorUpdater {
             String path = getContext();
             if (options.isMerge()) {
                 ModuleDescriptor merged = options.getMergedDescriptor();
-
-                if ("ivy-module/info".equals(path)) {
-                    // guarantee that inherited description has been written before
-                    // info element closes.
-                    writeInheritedDescription(merged);
-                } else if ("ivy-module/configurations".equals(path)) {
-                    // write inherited configurations after all child configurations
-                    writeInheritedConfigurations(merged);
-                } else if ("ivy-module/dependencies".equals(path)) {
-                    // write inherited dependencies after all child dependencies
-                    writeInheritedDependencies(merged);
-                } else if ("ivy-module".equals(path)) {
-                    // write any remaining inherited data before we close the
-                    // descriptor.
-                    flushAllMergedElements();
+                switch (path) {
+                    case "ivy-module/info":
+                        // guarantee that inherited description has been written before
+                        // info element closes.
+                        writeInheritedDescription(merged);
+                        break;
+                    case "ivy-module/configurations":
+                        // write inherited configurations after all child configurations
+                        writeInheritedConfigurations(merged);
+                        break;
+                    case "ivy-module/dependencies":
+                        // write inherited dependencies after all child dependencies
+                        writeInheritedDependencies(merged);
+                        break;
+                    case "ivy-module":
+                        // write any remaining inherited data before we close the
+                        // descriptor.
+                        flushAllMergedElements();
+                        break;
                 }
             }
 

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/da461de2/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 71e7bd5..b68b465 100644
--- a/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java
+++ b/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java
@@ -1095,14 +1095,17 @@ public abstract class BasicResolver extends AbstractResolver {
      *            the descriptor rule to use with this resolver.
      */
     public void setDescriptor(String descriptorRule) {
-        if (DESCRIPTOR_REQUIRED.equals(descriptorRule)) {
-            allownomd = false;
-        } else if (DESCRIPTOR_OPTIONAL.equals(descriptorRule)) {
-            allownomd = true;
-        } else {
-            throw new IllegalArgumentException("unknown descriptor rule '" + descriptorRule
-                    + "'. Allowed rules are: "
-                    + Arrays.asList(DESCRIPTOR_REQUIRED, DESCRIPTOR_OPTIONAL));
+        switch (descriptorRule) {
+            case DESCRIPTOR_REQUIRED:
+                allownomd = false;
+                break;
+            case DESCRIPTOR_OPTIONAL:
+                allownomd = true;
+                break;
+            default:
+                throw new IllegalArgumentException("unknown descriptor rule '" + descriptorRule
+                        + "'. Allowed rules are: "
+                        + Arrays.asList(DESCRIPTOR_REQUIRED, DESCRIPTOR_OPTIONAL));
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/da461de2/src/java/org/apache/ivy/plugins/resolver/DualResolver.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/resolver/DualResolver.java b/src/java/org/apache/ivy/plugins/resolver/DualResolver.java
index 4f816ba..3889ed9 100644
--- a/src/java/org/apache/ivy/plugins/resolver/DualResolver.java
+++ b/src/java/org/apache/ivy/plugins/resolver/DualResolver.java
@@ -211,14 +211,17 @@ public class DualResolver extends AbstractResolver {
      *            the descriptor rule to use with this resolver.
      */
     public void setDescriptor(String descriptorRule) {
-        if (DESCRIPTOR_REQUIRED.equals(descriptorRule)) {
-            allownomd = false;
-        } else if (DESCRIPTOR_OPTIONAL.equals(descriptorRule)) {
-            allownomd = true;
-        } else {
-            throw new IllegalArgumentException("unknown descriptor rule '" + descriptorRule
-                    + "'. Allowed rules are: "
-                    + Arrays.asList(DESCRIPTOR_REQUIRED, DESCRIPTOR_OPTIONAL));
+        switch (descriptorRule) {
+            case DESCRIPTOR_REQUIRED:
+                allownomd = false;
+                break;
+            case DESCRIPTOR_OPTIONAL:
+                allownomd = true;
+                break;
+            default:
+                throw new IllegalArgumentException("unknown descriptor rule '" + descriptorRule
+                        + "'. Allowed rules are: "
+                        + Arrays.asList(DESCRIPTOR_REQUIRED, DESCRIPTOR_OPTIONAL));
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/da461de2/src/java/org/apache/ivy/util/url/AbstractURLHandler.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/util/url/AbstractURLHandler.java b/src/java/org/apache/ivy/util/url/AbstractURLHandler.java
index c951ff1..3eaa35d 100644
--- a/src/java/org/apache/ivy/util/url/AbstractURLHandler.java
+++ b/src/java/org/apache/ivy/util/url/AbstractURLHandler.java
@@ -154,38 +154,45 @@ public abstract class AbstractURLHandler implements URLHandler {
 
     protected InputStream getDecodingInputStream(String encoding, InputStream in)
             throws IOException {
+        if (encoding == null) {
+            return in;
+        }
         InputStream result = null;
-
-        if ("gzip".equals(encoding) || "x-gzip".equals(encoding)) {
-            result = new GZIPInputStream(in);
-        } else if ("deflate".equals(encoding)) {
-            // There seems to be 2 variants of the "deflate"-encoding.
-            // I couldn't find a way to auto-detect which variant was
-            // used, so as (a not really good) work-around we try do
-            // decompress the first 100 bytes using the "zlib"-variant.
-            BufferedInputStream bStream = new BufferedInputStream(in);
-            bStream.mark(100);
-            byte[] bytes = new byte[100];
-            int nbBytes = bStream.read(bytes);
-            bStream.reset();
-
-            Inflater inflater = new Inflater();
-            inflater.setInput(bytes, 0, nbBytes);
-            try {
-                inflater.inflate(new byte[1000]);
-
-                // no error decompressing the first 100 bytes, so we
-                // assume the "zlib"-variant was used.
-                result = new InflaterInputStream(bStream);
-            } catch (DataFormatException e) {
-                // there was an error decompressing the first 100 bytes,
-                // so we assume the "gzip/raw"-variant was used.
-                result = new InflaterInputStream(bStream, new Inflater(true));
-            } finally {
-                inflater.end();
-            }
-        } else {
-            result = in;
+        switch (encoding) {
+            case "gzip":
+            case "x-gzip":
+                result = new GZIPInputStream(in);
+                break;
+            case "deflate":
+                // There seems to be 2 variants of the "deflate"-encoding.
+                // I couldn't find a way to auto-detect which variant was
+                // used, so as (a not really good) work-around we try do
+                // decompress the first 100 bytes using the "zlib"-variant.
+                BufferedInputStream bStream = new BufferedInputStream(in);
+                bStream.mark(100);
+                byte[] bytes = new byte[100];
+                int nbBytes = bStream.read(bytes);
+                bStream.reset();
+
+                Inflater inflater = new Inflater();
+                inflater.setInput(bytes, 0, nbBytes);
+                try {
+                    inflater.inflate(new byte[1000]);
+
+                    // no error decompressing the first 100 bytes, so we
+                    // assume the "zlib"-variant was used.
+                    result = new InflaterInputStream(bStream);
+                } catch (DataFormatException e) {
+                    // there was an error decompressing the first 100 bytes,
+                    // so we assume the "gzip/raw"-variant was used.
+                    result = new InflaterInputStream(bStream, new Inflater(true));
+                } finally {
+                    inflater.end();
+                }
+                break;
+            default:
+                result = in;
+                break;
         }
 
         return result;

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/da461de2/test/java/org/apache/ivy/plugins/conflict/LatestConflictManagerTest.java
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/plugins/conflict/LatestConflictManagerTest.java b/test/java/org/apache/ivy/plugins/conflict/LatestConflictManagerTest.java
index efda2b9..98ab93c 100644
--- a/test/java/org/apache/ivy/plugins/conflict/LatestConflictManagerTest.java
+++ b/test/java/org/apache/ivy/plugins/conflict/LatestConflictManagerTest.java
@@ -195,15 +195,20 @@ public class LatestConflictManagerTest {
             getResolveOptions());
         ConfigurationResolveReport defaultReport = report.getConfigurationReport("default");
         for (ModuleRevisionId mrid : defaultReport.getModuleRevisionIds()) {
-            if (mrid.getName().equals("A")) {
-                assertEquals("A revision should be 1.0.0", "1.0.0", mrid.getRevision());
-            } else if (mrid.getName().equals("D")) {
-                assertEquals("D revision should be 1.0.0", "1.0.0", mrid.getRevision());
-            } else if (mrid.getName().equals("B")) {
-                // by transitivity
-                assertEquals("B revision should be 1.0.0", "1.0.0", mrid.getRevision());
-            } else if (mrid.getName().equals("C")) {
-                assertEquals("C revision should be 1.0.2", "1.0.2", mrid.getRevision());
+            switch (mrid.getName()) {
+                case "A":
+                    assertEquals("A revision should be 1.0.0", "1.0.0", mrid.getRevision());
+                    break;
+                case "D":
+                    assertEquals("D revision should be 1.0.0", "1.0.0", mrid.getRevision());
+                    break;
+                case "B":
+                    // by transitivity
+                    assertEquals("B revision should be 1.0.0", "1.0.0", mrid.getRevision());
+                    break;
+                case "C":
+                    assertEquals("C revision should be 1.0.2", "1.0.2", mrid.getRevision());
+                    break;
             }
         }
     }


Mime
View raw message