sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [sling-org-apache-sling-feature-resolver] branch master updated: Improve some exception messages and change equals of Bundle and Feature Resource Impl to be based on their artifact ids.
Date Wed, 02 May 2018 14:03:45 GMT
This is an automated email from the ASF dual-hosted git repository.

pauls pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-resolver.git


The following commit(s) were added to refs/heads/master by this push:
     new 0115a68  Improve some exception messages and change equals of Bundle and Feature
Resource Impl to be based on their artifact ids.
0115a68 is described below

commit 0115a687023b409a8a5c5a4889b6515e09ab1146
Author: Karl Pauls <karlpauls@gmail.com>
AuthorDate: Wed May 2 16:03:38 2018 +0200

    Improve some exception messages and change equals of Bundle and Feature Resource Impl
to be based on their artifact ids.
---
 .../resolver/ApplicationResolverAssembler.java     |  9 ++-
 .../sling/feature/resolver/FrameworkResolver.java  | 21 +++---
 .../feature/resolver/impl/BundleResourceImpl.java  | 76 ++--------------------
 .../feature/resolver/impl/FeatureResourceImpl.java | 61 ++---------------
 4 files changed, 31 insertions(+), 136 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/resolver/ApplicationResolverAssembler.java
b/src/main/java/org/apache/sling/feature/resolver/ApplicationResolverAssembler.java
index 84c1e42..85d1b4f 100644
--- a/src/main/java/org/apache/sling/feature/resolver/ApplicationResolverAssembler.java
+++ b/src/main/java/org/apache/sling/feature/resolver/ApplicationResolverAssembler.java
@@ -46,7 +46,6 @@ public class ApplicationResolverAssembler {
      * @param fr
      * @return The assembled application
      * @throws IOException If a feature can't be read or no feature is found.
-     * @see #getFeatureFiles(File, String...)
      */
     public static Application assembleApplication(
             Application app,
@@ -56,8 +55,12 @@ public class ApplicationResolverAssembler {
     throws IOException {
         final List<Feature> features = new ArrayList<>();
         for(final String initFile : featureFiles) {
-            final Feature f = IOUtils.getFeature(initFile, artifactManager, SubstituteVariables.RESOLVE);
-            features.add(f);
+            try {
+                final Feature f = IOUtils.getFeature(initFile, artifactManager, SubstituteVariables.RESOLVE);
+                features.add(f);
+            } catch (Exception ex) {
+                throw new IOException("Error reading feature: " + initFile, ex);
+            }
         }
 
         return assembleApplication(app, artifactManager, fr, features.toArray(new Feature[0]));
diff --git a/src/main/java/org/apache/sling/feature/resolver/FrameworkResolver.java b/src/main/java/org/apache/sling/feature/resolver/FrameworkResolver.java
index da09e69..2478bd5 100644
--- a/src/main/java/org/apache/sling/feature/resolver/FrameworkResolver.java
+++ b/src/main/java/org/apache/sling/feature/resolver/FrameworkResolver.java
@@ -144,14 +144,19 @@ public class FrameworkResolver implements FeatureResolver {
         Map<Feature, FeatureResource> featureMap = new HashMap<>();
         Map<FeatureResource, Feature> resourceMap = new HashMap<>();
         for (Feature f : features) {
-            FeatureResourceImpl fr = new FeatureResourceImpl(f);
-            resourceMap.put(fr, f);
-            featureMap.put(f, fr);
-
-            for (Artifact b : f.getBundles()) {
-                BundleDescriptor bd = getBundleDescriptor(artifactManager, b);
-                FeatureResource r = new BundleResourceImpl(bd, f);
-                resourceMap.put(r, f);
+            try {
+                FeatureResourceImpl fr = new FeatureResourceImpl(f);
+                resourceMap.put(fr, f);
+                featureMap.put(f, fr);
+
+                for (Artifact b : f.getBundles())
+                {
+                    BundleDescriptor bd = getBundleDescriptor(artifactManager, b);
+                    FeatureResource r = new BundleResourceImpl(bd, f);
+                    resourceMap.put(r, f);
+                }
+            } catch (Exception ex) {
+                throw new IOException("Error processing feature: " + f.getLocation(), ex);
             }
         }
 
diff --git a/src/main/java/org/apache/sling/feature/resolver/impl/BundleResourceImpl.java
b/src/main/java/org/apache/sling/feature/resolver/impl/BundleResourceImpl.java
index e196145..5cde17e 100644
--- a/src/main/java/org/apache/sling/feature/resolver/impl/BundleResourceImpl.java
+++ b/src/main/java/org/apache/sling/feature/resolver/impl/BundleResourceImpl.java
@@ -146,79 +146,17 @@ public class BundleResourceImpl extends AbstractResourceImpl implements
FeatureR
     }
 
     @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((artifact == null) ? 0 : artifact.hashCode());
-        result = prime * result + ((bsn == null) ? 0 : bsn.hashCode());
-
-        if (capabilities != null) {
-            // Don't delegate to the capabilities to compute their hashcode since that results
in an endless loop
-            for (List<Capability> lc : capabilities.values()) {
-                for (Capability c : lc) {
-                    result = prime * result + c.getNamespace().hashCode();
-                    result = prime * result + c.getAttributes().hashCode();
-                    result = prime * result + c.getDirectives().hashCode();
-                }
-            }
-        }
-
-        if (requirements != null) {
-            // Don't delegate to the requirements to compute their hashcode since that results
in an endless loop
-            for (List<Requirement> lr : requirements.values()) {
-                for (Requirement r : lr) {
-                    result = prime * result + r.getNamespace().hashCode();
-                    result = prime * result + r.getAttributes().hashCode();
-                    result = prime * result + r.getDirectives().hashCode();
-                }
-            }
+    public boolean equals(Object obj) {
+        if ( obj instanceof BundleResourceImpl ) {
+            return bsn.equals(((BundleResourceImpl)obj).bsn) && version.equals(((BundleResourceImpl)obj).version);
         }
-
-        result = prime * result + ((feature == null) ? 0 : feature.hashCode());
-        result = prime * result + ((version == null) ? 0 : version.hashCode());
-        return result;
+        return false;
     }
 
     @Override
-    public boolean equals(Object obj) {
-        if (this == obj)
-            return true;
-        if (obj == null)
-            return false;
-        if (getClass() != obj.getClass())
-            return false;
-        BundleResourceImpl other = (BundleResourceImpl) obj;
-        if (artifact == null) {
-            if (other.artifact != null)
-                return false;
-        } else if (!artifact.equals(other.artifact))
-            return false;
-        if (bsn == null) {
-            if (other.bsn != null)
-                return false;
-        } else if (!bsn.equals(other.bsn))
-            return false;
-        if (capabilities == null) {
-            if (other.capabilities != null)
-                return false;
-        } else if (!capabilities.equals(other.capabilities))
-            return false;
-        if (feature == null) {
-            if (other.feature != null)
-                return false;
-        } else if (!feature.equals(other.feature))
-            return false;
-        if (requirements == null) {
-            if (other.requirements != null)
-                return false;
-        } else if (!requirements.equals(other.requirements))
-            return false;
-        if (version == null) {
-            if (other.version != null)
-                return false;
-        } else if (!version.equals(other.version))
-            return false;
-        return true;
+    public int hashCode() {
+        return (bsn + ':' + version).hashCode();
+
     }
 
     @Override
diff --git a/src/main/java/org/apache/sling/feature/resolver/impl/FeatureResourceImpl.java
b/src/main/java/org/apache/sling/feature/resolver/impl/FeatureResourceImpl.java
index 4acee42..e13ed49 100644
--- a/src/main/java/org/apache/sling/feature/resolver/impl/FeatureResourceImpl.java
+++ b/src/main/java/org/apache/sling/feature/resolver/impl/FeatureResourceImpl.java
@@ -105,66 +105,15 @@ public class FeatureResourceImpl extends AbstractResourceImpl implements
Feature
 
     @Override
     public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((artifact == null) ? 0 : artifact.hashCode());
-
-        if (capabilities != null) {
-            // Don't delegate to the capabilities to compute their hashcode since that results
in an endless loop
-            for (List<Capability> lc : capabilities.values()) {
-                for (Capability c : lc) {
-                    result = prime * result + c.getNamespace().hashCode();
-                    result = prime * result + c.getAttributes().hashCode();
-                    result = prime * result + c.getDirectives().hashCode();
-                }
-            }
-        }
-
-        if (requirements != null) {
-            // Don't delegate to the requirements to compute their hashcode since that results
in an endless loop
-            for (List<Requirement> lr : requirements.values()) {
-                for (Requirement r : lr) {
-                    result = prime * result + r.getNamespace().hashCode();
-                    result = prime * result + r.getAttributes().hashCode();
-                    result = prime * result + r.getDirectives().hashCode();
-                }
-            }
-        }
-
-        result = prime * result + ((feature == null) ? 0 : feature.hashCode());
-        return result;
+        return feature.hashCode();
     }
 
     @Override
     public boolean equals(Object obj) {
-        if (this == obj)
-            return true;
-        if (obj == null)
-            return false;
-        if (getClass() != obj.getClass())
-            return false;
-        FeatureResourceImpl other = (FeatureResourceImpl) obj;
-        if (artifact == null) {
-            if (other.artifact != null)
-                return false;
-        } else if (!artifact.equals(other.artifact))
-            return false;
-        if (capabilities == null) {
-            if (other.capabilities != null)
-                return false;
-        } else if (!capabilities.equals(other.capabilities))
-            return false;
-        if (feature == null) {
-            if (other.feature != null)
-                return false;
-        } else if (!feature.equals(other.feature))
-            return false;
-        if (requirements == null) {
-            if (other.requirements != null)
-                return false;
-        } else if (!requirements.equals(other.requirements))
-            return false;
-        return true;
+        if (obj instanceof FeatureResourceImpl) {
+            return feature.equals(((FeatureResourceImpl) obj).feature);
+        }
+        return false;
     }
 
     @Override

-- 
To stop receiving notification emails like this one, please contact
pauls@apache.org.

Mime
View raw message