~ubuntu-branches/ubuntu/trusty/ivy/trusty

« back to all changes in this revision

Viewing changes to src/java/org/apache/ivy/osgi/repo/RepoDescriptor.java

  • Committer: Package Import Robot
  • Author(s): tony mancill
  • Date: 2013-05-15 17:44:57 UTC
  • mfrom: (3.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20130515174457-ogntd0vxluwalq11
Tags: 2.3.0-2
* Team upload.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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
 
8
 *
 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
 
10
 *
 
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.
 
16
 *
 
17
 */
 
18
package org.apache.ivy.osgi.repo;
 
19
 
 
20
import java.net.URI;
 
21
import java.util.HashMap;
 
22
import java.util.HashSet;
 
23
import java.util.Iterator;
 
24
import java.util.Map;
 
25
import java.util.Set;
 
26
 
 
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;
 
35
 
 
36
public class RepoDescriptor {
 
37
 
 
38
    private final Map/* <String, Map<String, Set<ModuleDescriptor>>> */moduleByCapbilities = new HashMap();
 
39
 
 
40
    private final Set/* <ModuleDescriptor> */modules = new HashSet();
 
41
 
 
42
    private final ExecutionEnvironmentProfileProvider profileProvider;
 
43
 
 
44
    private final URI baseUri;
 
45
 
 
46
    public RepoDescriptor(URI baseUri, ExecutionEnvironmentProfileProvider profileProvider) {
 
47
        this.baseUri = baseUri;
 
48
        this.profileProvider = profileProvider;
 
49
    }
 
50
 
 
51
    public URI getBaseUri() {
 
52
        return baseUri;
 
53
    }
 
54
 
 
55
    public Set/* <ModuleDescriptor> */getModules() {
 
56
        return modules;
 
57
    }
 
58
 
 
59
    public Map/* <String, Map<String, Set<ModuleDescriptor>>> */getModuleByCapbilities() {
 
60
        return moduleByCapbilities;
 
61
    }
 
62
 
 
63
    public Set/* <ModuleDescriptor> */findModule(String requirement, String value) {
 
64
        Map/* <String, Set<ModuleDescriptor>> */modules = (Map) moduleByCapbilities
 
65
                .get(requirement);
 
66
        if (modules == null) {
 
67
            return null;
 
68
        }
 
69
        return (Set) modules.get(value);
 
70
    }
 
71
 
 
72
    public Set/* <String> */getCapabilityValues(String capabilityName) {
 
73
        Map/* <String, Set<ModuleDescriptor>> */modules = (Map) moduleByCapbilities
 
74
                .get(capabilityName);
 
75
        if (modules == null) {
 
76
            return null;
 
77
        }
 
78
        return (Set) modules.keySet();
 
79
    }
 
80
 
 
81
    public void add(String type, String value, ModuleDescriptor md) {
 
82
        modules.add(md);
 
83
        Map/* <String, Set<ModuleDescriptor>> */map = (Map) moduleByCapbilities.get(type);
 
84
        if (map == null) {
 
85
            map = new HashMap/* <String, Set<ModuleDescriptor>> */();
 
86
            moduleByCapbilities.put(type, map);
 
87
        }
 
88
        Set/* <ModuleDescriptor> */bundleReferences = (Set) map.get(value);
 
89
        if (bundleReferences == null) {
 
90
            bundleReferences = new HashSet/* <ModuleDescriptor> */();
 
91
            map.put(value, bundleReferences);
 
92
        }
 
93
        if (!bundleReferences.add(md)) {
 
94
            Message.debug("Duplicate module in the repo " + baseUri + " for " + type + " "
 
95
                    + value + ": " + md.getModuleRevisionId());
 
96
        }
 
97
    }
 
98
 
 
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);
 
107
        }
 
108
    }
 
109
 
 
110
    public String toString() {
 
111
        return modules.toString();
 
112
    }
 
113
 
 
114
    public int hashCode() {
 
115
        final int prime = 31;
 
116
        int result = 1;
 
117
        result = prime * result + ((modules == null) ? 0 : modules.hashCode());
 
118
        return result;
 
119
    }
 
120
 
 
121
    public boolean equals(Object obj) {
 
122
        if (this == obj) {
 
123
            return true;
 
124
        }
 
125
        if (obj == null) {
 
126
            return false;
 
127
        }
 
128
        if (getClass() != obj.getClass()) {
 
129
            return false;
 
130
        }
 
131
        RepoDescriptor other = (RepoDescriptor) obj;
 
132
        if (modules == null) {
 
133
            if (other.modules != null) {
 
134
                return false;
 
135
            }
 
136
        } else if (!modules.equals(other.modules)) {
 
137
            return false;
 
138
        }
 
139
        return true;
 
140
    }
 
141
 
 
142
}