Repository: karaf Updated Branches: refs/heads/master 66eeed510 -> 54b46154c
Fix to allow for relative URLs from a Cave repository. Project: http://git-wip-us.apache.org/repos/asf/karaf/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/7df43b1a Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/7df43b1a Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/7df43b1a Branch: refs/heads/master Commit: 7df43b1a4e152c2b1759fe6b909d64ddb5528cff Parents: 9ebb25a Author: David Leangen <[email protected]> Authored: Tue Nov 24 14:54:56 2015 +0900 Committer: David Leangen <[email protected]> Committed: Tue Nov 24 14:54:56 2015 +0900 ---------------------------------------------------------------------- .../region/SubsystemResolveContext.java | 12 +++++-- .../internal/resolver/ResourceUtils.java | 36 ++++++++++++++++++-- 2 files changed, 44 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf/blob/7df43b1a/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolveContext.java ---------------------------------------------------------------------- diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolveContext.java b/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolveContext.java index 0a8405f..c8547b9 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolveContext.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolveContext.java @@ -30,6 +30,7 @@ import java.util.Set; import org.apache.karaf.features.FeaturesService; import org.apache.karaf.features.internal.download.Downloader; import org.apache.karaf.features.internal.repository.BaseRepository; +import org.apache.karaf.features.internal.repository.XmlRepository; import org.apache.karaf.features.internal.resolver.CapabilityImpl; import org.apache.karaf.features.internal.resolver.RequirementImpl; import org.apache.karaf.features.internal.resolver.ResolverUtil; @@ -50,6 +51,7 @@ import org.osgi.service.resolver.HostedCapability; import org.osgi.service.resolver.ResolveContext; import static org.apache.karaf.features.internal.resolver.ResourceUtils.addIdentityRequirement; +import static org.apache.karaf.features.internal.resolver.ResourceUtils.addRepoLocation; import static org.apache.karaf.features.internal.resolver.ResourceUtils.getUri; import static org.eclipse.equinox.region.RegionFilter.VISIBLE_BUNDLE_NAMESPACE; import static org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE; @@ -371,8 +373,14 @@ public class SubsystemResolveContext extends ResolveContext { } addIdentityRequirement(wrapped, subsystem, false); resToSub.put(wrapped, subsystem); - // TODO: use RepositoryContent ? - try { + // If the repository if of type XmlRepository, then it is our own internal format + if (repository instanceof XmlRepository) { + XmlRepository xmlRepository = (XmlRepository)repository; + String url = xmlRepository.getUrl(); + String location = url.substring(0, url.lastIndexOf( "/" ) + 1); + addRepoLocation( wrapped, location ); + } + try { downloader.download(getUri(wrapped), null); } catch (MalformedURLException e) { throw new IllegalStateException("Unable to download resource: " + getUri(wrapped)); http://git-wip-us.apache.org/repos/asf/karaf/blob/7df43b1a/features/core/src/main/java/org/apache/karaf/features/internal/resolver/ResourceUtils.java ---------------------------------------------------------------------- diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/resolver/ResourceUtils.java b/features/core/src/main/java/org/apache/karaf/features/internal/resolver/ResourceUtils.java index 8c7c406..e6d7ea2 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/resolver/ResourceUtils.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/resolver/ResourceUtils.java @@ -16,6 +16,8 @@ */ package org.apache.karaf.features.internal.resolver; +import java.net.MalformedURLException; +import java.net.URL; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -42,6 +44,8 @@ public final class ResourceUtils { public static final String TYPE_FEATURE = "karaf.feature"; + public static final String REPO_NAMESPACE = "karaf.repo"; + private ResourceUtils() { } @@ -55,14 +59,42 @@ public final class ResourceUtils { return null; } + public static void addRepoLocation(ResourceImpl resource, String location) + { + Map<String, String> dirs = new HashMap<>(); + Map<String, Object> attrs = new HashMap<>(); + attrs.put(CAPABILITY_URL_ATTRIBUTE, location); + CapabilityImpl capability = new CapabilityImpl( resource, REPO_NAMESPACE, dirs, attrs ); + resource.addCapability( capability ); + } + + // TODO: Correct name should probably be toUrl public static String getUri(Resource resource) { List<Capability> caps = resource.getCapabilities(null); + String location = null; + String url = null; for (Capability cap : caps) { + if (cap.getNamespace().equals(REPO_NAMESPACE)) { + location = cap.getAttributes().get(CAPABILITY_URL_ATTRIBUTE).toString(); + } if (cap.getNamespace().equals(CONTENT_NAMESPACE)) { - return cap.getAttributes().get(CAPABILITY_URL_ATTRIBUTE).toString(); + url = cap.getAttributes().get(CAPABILITY_URL_ATTRIBUTE).toString(); } } - return null; + + // If there is no location value, then just return the saved URL + if (location == null) { + return url; + } + + // If the saved is absolute (i.e. well-formed), then return it + try { + new URL(url); + return url; + } catch (MalformedURLException e) { + // The URL is relative, so return the absolute URL + return location + url; + } } public static String getFeatureId(Resource resource) {
