1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package io.wcm.tooling.commons.packmgr.httpaction;
21
22 import java.util.Set;
23 import java.util.regex.Pattern;
24
25
26
27
28 public final class BundleStatus {
29
30 private final String statusLine;
31 private final int total;
32 private final int active;
33 private final int activeFragment;
34 private final int resolved;
35 private final int installed;
36 private final int ignored;
37 private final Set<String> bundleSymbolicNames;
38
39 BundleStatus(String statusLine, int total, int active, int activeFragment,
40 int resolved, int installed, int ignored,
41 Set<String> bundleSymbolicNames) {
42 this.statusLine = statusLine;
43 this.total = total;
44 this.active = active;
45 this.activeFragment = activeFragment;
46 this.resolved = resolved;
47 this.installed = installed;
48 this.ignored = ignored;
49 this.bundleSymbolicNames = bundleSymbolicNames;
50 }
51
52
53
54
55
56 @Deprecated
57 public String getStatusLine() {
58 return this.statusLine;
59 }
60
61
62
63
64 public String getStatusLineCompact() {
65 StringBuilder sb = new StringBuilder();
66 sb.append(total).append(" total");
67 if (active > 0) {
68 sb.append(", ").append(active).append(" active");
69 }
70 if (activeFragment > 0) {
71 sb.append(", ").append(activeFragment).append(" fragment");
72 }
73 if (resolved > 0) {
74 sb.append(", ").append(resolved).append(" resolved");
75 }
76 if (installed > 0) {
77 sb.append(", ").append(installed).append(" installed");
78 }
79 if (ignored > 0) {
80 sb.append(", ").append(ignored).append(" ignored");
81 }
82 return sb.toString();
83 }
84
85 public int getTotal() {
86 return this.total;
87 }
88
89 public int getActive() {
90 return this.active;
91 }
92
93 public int getActiveFragment() {
94 return this.activeFragment;
95 }
96
97 public int getResolved() {
98 return this.resolved;
99 }
100
101 public int getInstalled() {
102 return this.installed;
103 }
104
105 public int getIgnored() {
106 return ignored;
107 }
108
109
110
111
112 public boolean isAllBundlesRunning() {
113 return getInstalled() + getResolved() == 0;
114 }
115
116
117
118
119
120 public boolean containsBundle(String symbolicName) {
121 return bundleSymbolicNames.contains(symbolicName);
122 }
123
124
125
126
127
128
129 public String getMatchingBundle(Pattern symbolicNamePattern) {
130 for (String bundleSymbolicName : bundleSymbolicNames) {
131 if (symbolicNamePattern.matcher(bundleSymbolicName).matches()) {
132 return bundleSymbolicName;
133 }
134 }
135 return null;
136 }
137
138 }