1 package com.atlassian.plugin.osgi.factory.transform.model;
2
3 import com.atlassian.plugin.osgi.util.OsgiHeaderUtil;
4 import com.google.common.collect.ImmutableMap;
5
6 import java.util.LinkedHashMap;
7 import java.util.Map;
8
9 import static com.google.common.collect.Maps.transformValues;
10
11
12
13
14
15
16 public class SystemExports {
17 private final Map<String, Map<String, String>> exports;
18
19 public static final SystemExports NONE = new SystemExports("");
20
21
22
23
24
25
26 public SystemExports(String exportsLine) {
27 if (exportsLine == null) {
28 exportsLine = "";
29 }
30
31 this.exports = internAttributeKeys(OsgiHeaderUtil.parseHeader(exportsLine));
32 }
33
34
35
36
37
38 private static Map<String, Map<String, String>> internAttributeKeys(final Map<String, Map<String, String>> map) {
39 return transformValues(map, SystemExports::internKeys);
40 }
41
42 private static Map<String, String> internKeys(final Map<String, String> innerMap) {
43
44 final ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
45 for (Map.Entry<String, String> entry : innerMap.entrySet()) {
46 builder.put(
47 entry.getKey().intern(),
48 entry.getValue()
49 );
50 }
51
52 return builder.build();
53 }
54
55
56
57
58
59
60
61
62 public String getFullExport(String pkg) {
63 if (exports.containsKey(pkg)) {
64 Map<String, String> attrs = new LinkedHashMap<>(exports.get(pkg));
65 if (attrs.containsKey("version")) {
66 final String version = attrs.get("version");
67 attrs.put("version", "[" + version + "," + version + "]");
68 }
69 return OsgiHeaderUtil.buildHeader(pkg, attrs);
70 }
71 return pkg;
72 }
73
74
75
76
77
78 public boolean isExported(String pkg) {
79 return exports.containsKey(pkg);
80 }
81 }