2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
18
package org.apache.ivy.osgi.repo;
21
import java.util.HashMap;
22
import java.util.HashSet;
23
import java.util.Iterator;
27
import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor;
28
import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
29
import org.apache.ivy.osgi.core.BundleCapability;
30
import org.apache.ivy.osgi.core.BundleInfo;
31
import org.apache.ivy.osgi.core.BundleInfoAdapter;
32
import org.apache.ivy.osgi.core.ExecutionEnvironmentProfileProvider;
33
import org.apache.ivy.osgi.core.OSGiManifestParser;
34
import org.apache.ivy.util.Message;
36
public class RepoDescriptor {
38
private final Map/* <String, Map<String, Set<ModuleDescriptor>>> */moduleByCapbilities = new HashMap();
40
private final Set/* <ModuleDescriptor> */modules = new HashSet();
42
private final ExecutionEnvironmentProfileProvider profileProvider;
44
private final URI baseUri;
46
public RepoDescriptor(URI baseUri, ExecutionEnvironmentProfileProvider profileProvider) {
47
this.baseUri = baseUri;
48
this.profileProvider = profileProvider;
51
public URI getBaseUri() {
55
public Set/* <ModuleDescriptor> */getModules() {
59
public Map/* <String, Map<String, Set<ModuleDescriptor>>> */getModuleByCapbilities() {
60
return moduleByCapbilities;
63
public Set/* <ModuleDescriptor> */findModule(String requirement, String value) {
64
Map/* <String, Set<ModuleDescriptor>> */modules = (Map) moduleByCapbilities
66
if (modules == null) {
69
return (Set) modules.get(value);
72
public Set/* <String> */getCapabilityValues(String capabilityName) {
73
Map/* <String, Set<ModuleDescriptor>> */modules = (Map) moduleByCapbilities
75
if (modules == null) {
78
return (Set) modules.keySet();
81
public void add(String type, String value, ModuleDescriptor md) {
83
Map/* <String, Set<ModuleDescriptor>> */map = (Map) moduleByCapbilities.get(type);
85
map = new HashMap/* <String, Set<ModuleDescriptor>> */();
86
moduleByCapbilities.put(type, map);
88
Set/* <ModuleDescriptor> */bundleReferences = (Set) map.get(value);
89
if (bundleReferences == null) {
90
bundleReferences = new HashSet/* <ModuleDescriptor> */();
91
map.put(value, bundleReferences);
93
if (!bundleReferences.add(md)) {
94
Message.debug("Duplicate module in the repo " + baseUri + " for " + type + " "
95
+ value + ": " + md.getModuleRevisionId());
99
public void addBundle(BundleInfo bundleInfo) {
100
DefaultModuleDescriptor md = BundleInfoAdapter.toModuleDescriptor(
101
OSGiManifestParser.getInstance(), baseUri, bundleInfo, profileProvider);
102
add(BundleInfo.BUNDLE_TYPE, bundleInfo.getSymbolicName(), md);
103
Iterator itCapability = bundleInfo.getCapabilities().iterator();
104
while (itCapability.hasNext()) {
105
BundleCapability capability = (BundleCapability) itCapability.next();
106
add(capability.getType(), capability.getName(), md);
110
public String toString() {
111
return modules.toString();
114
public int hashCode() {
115
final int prime = 31;
117
result = prime * result + ((modules == null) ? 0 : modules.hashCode());
121
public boolean equals(Object obj) {
128
if (getClass() != obj.getClass()) {
131
RepoDescriptor other = (RepoDescriptor) obj;
132
if (modules == null) {
133
if (other.modules != null) {
136
} else if (!modules.equals(other.modules)) {