1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.extension.internal.converter; |
21 |
|
|
22 |
|
import java.lang.reflect.Type; |
23 |
|
import java.util.ArrayList; |
24 |
|
import java.util.Collection; |
25 |
|
import java.util.List; |
26 |
|
|
27 |
|
import javax.inject.Singleton; |
28 |
|
|
29 |
|
import org.apache.commons.lang3.StringUtils; |
30 |
|
import org.xwiki.component.annotation.Component; |
31 |
|
import org.xwiki.extension.ExtensionId; |
32 |
|
import org.xwiki.extension.version.Version; |
33 |
|
import org.xwiki.extension.version.internal.DefaultVersion; |
34 |
|
import org.xwiki.properties.converter.AbstractConverter; |
35 |
|
|
36 |
|
|
37 |
|
@link |
38 |
|
|
39 |
|
@version |
40 |
|
@since |
41 |
|
|
42 |
|
@Component |
43 |
|
@Singleton |
|
|
| 93.9% |
Uncovered Elements: 4 (66) |
Complexity: 16 |
Complexity Density: 0.36 |
|
44 |
|
public class ExtensionIdConverter extends AbstractConverter<ExtensionId> |
45 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
46 |
39 |
private static int countBackslashes(String str, int index)... |
47 |
|
{ |
48 |
46 |
for (int i = index - 1; i >= 0; --i) { |
49 |
45 |
if (str.charAt(i) != '\\') { |
50 |
38 |
return index - i - 1; |
51 |
|
} |
52 |
|
} |
53 |
|
|
54 |
1 |
return index; |
55 |
|
} |
56 |
|
|
57 |
|
|
58 |
|
@param |
59 |
|
@param@link |
60 |
|
|
61 |
|
@return@link |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
63 |
985 |
public static List<ExtensionId> toExtensionIdList(Collection<?> values, Version defaultVersion)... |
64 |
|
{ |
65 |
985 |
List<ExtensionId> list = new ArrayList<>(values.size()); |
66 |
|
|
67 |
985 |
for (Object value : values) { |
68 |
1093 |
list.add(toExtensionId(value, defaultVersion)); |
69 |
|
} |
70 |
|
|
71 |
985 |
return list; |
72 |
|
} |
73 |
|
|
74 |
|
|
75 |
|
@param |
76 |
|
@param@link |
77 |
|
|
78 |
|
@return@link |
79 |
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
80 |
1112 |
public static ExtensionId toExtensionId(Object value, Version defaultVersion)... |
81 |
|
{ |
82 |
1112 |
if (value != null) { |
83 |
1112 |
String valueString = value.toString(); |
84 |
1112 |
return toExtensionId(valueString, valueString.length() - 1, defaultVersion); |
85 |
|
} |
86 |
|
|
87 |
0 |
return null; |
88 |
|
} |
89 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (26) |
Complexity: 5 |
Complexity Density: 0.25 |
|
90 |
1115 |
private static ExtensionId toExtensionId(String value, int end, Version defaultVersion)... |
91 |
|
{ |
92 |
1115 |
String valueString = value; |
93 |
|
|
94 |
1115 |
int index = valueString.lastIndexOf('/'); |
95 |
1115 |
String id = valueString; |
96 |
1115 |
Version version; |
97 |
1115 |
if (index > 0 && index < end) { |
98 |
39 |
int backslashes = countBackslashes(valueString, index); |
99 |
39 |
if (backslashes > 0) { |
100 |
4 |
StringBuilder builder = new StringBuilder(); |
101 |
4 |
builder.append(valueString.substring(0, index - backslashes)); |
102 |
4 |
builder.append(StringUtils.repeat('\\', backslashes / 2)); |
103 |
4 |
builder.append(valueString.substring(index)); |
104 |
|
|
105 |
4 |
valueString = builder.toString(); |
106 |
4 |
index -= backslashes - (backslashes / 2); |
107 |
|
|
108 |
4 |
if (backslashes % 2 == 1) { |
109 |
3 |
return toExtensionId(valueString, index - backslashes - 1, defaultVersion); |
110 |
|
} |
111 |
|
} |
112 |
|
|
113 |
36 |
id = valueString.substring(0, index); |
114 |
36 |
version = new DefaultVersion(valueString.substring(index + 1)); |
115 |
|
} else { |
116 |
1076 |
id = valueString; |
117 |
1076 |
version = defaultVersion; |
118 |
|
} |
119 |
|
|
120 |
1112 |
return new ExtensionId(id, version); |
121 |
|
} |
122 |
|
|
123 |
|
|
124 |
|
@param@link |
125 |
|
@return@link |
126 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
127 |
459 |
public static String toString(ExtensionId value)... |
128 |
|
{ |
129 |
459 |
StringBuilder builder = new StringBuilder(); |
130 |
|
|
131 |
459 |
builder.append(value.getId()); |
132 |
|
|
133 |
459 |
if (value.getVersion() != null) { |
134 |
453 |
builder.append('/'); |
135 |
453 |
builder.append(value.getVersion()); |
136 |
|
} |
137 |
|
|
138 |
459 |
return builder.toString(); |
139 |
|
} |
140 |
|
|
141 |
|
|
142 |
|
@param@link |
143 |
|
@return@link |
144 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
145 |
3085 |
public static List<String> toStringList(Collection<ExtensionId> values)... |
146 |
|
{ |
147 |
3085 |
List<String> list = new ArrayList<>(values.size()); |
148 |
|
|
149 |
3085 |
for (ExtensionId value : values) { |
150 |
453 |
list.add(toString(value)); |
151 |
|
} |
152 |
|
|
153 |
3085 |
return list; |
154 |
|
} |
155 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
156 |
6 |
@Override... |
157 |
|
protected ExtensionId convertToType(Type targetType, Object value) |
158 |
|
{ |
159 |
6 |
return toExtensionId(value, null); |
160 |
|
} |
161 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
162 |
0 |
@Override... |
163 |
|
protected String convertToString(ExtensionId value) |
164 |
|
{ |
165 |
0 |
return toString(value); |
166 |
|
} |
167 |
|
} |