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(since = "1.6.0")
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
86
87
88 public int getTotal() {
89 return this.total;
90 }
91
92
93
94
95 public int getActive() {
96 return this.active;
97 }
98
99
100
101
102 public int getActiveFragment() {
103 return this.activeFragment;
104 }
105
106
107
108
109 public int getResolved() {
110 return this.resolved;
111 }
112
113
114
115
116 public int getInstalled() {
117 return this.installed;
118 }
119
120
121
122
123 public int getIgnored() {
124 return ignored;
125 }
126
127
128
129
130 public boolean isAllBundlesRunning() {
131 return getInstalled() + getResolved() == 0;
132 }
133
134
135
136
137
138 public boolean containsBundle(String symbolicName) {
139 return bundleSymbolicNames.contains(symbolicName);
140 }
141
142
143
144
145
146
147 public String getMatchingBundle(Pattern symbolicNamePattern) {
148 for (String bundleSymbolicName : bundleSymbolicNames) {
149 if (symbolicNamePattern.matcher(bundleSymbolicName).matches()) {
150 return bundleSymbolicName;
151 }
152 }
153 return null;
154 }
155
156 }