Lines 26-32
Link Here
|
26 |
|
26 |
|
27 |
private static final String INTERNAL = "x-internal"; //$NON-NLS-1$ |
27 |
private static final String INTERNAL = "x-internal"; //$NON-NLS-1$ |
28 |
private static final String FRIENDS = "x-friends"; //$NON-NLS-1$ |
28 |
private static final String FRIENDS = "x-friends"; //$NON-NLS-1$ |
29 |
|
29 |
|
|
|
30 |
private static final int NEWLINE_LIMIT = 3; |
31 |
private static final int NEWLINE_LIMIT_BOTH = 1; |
32 |
|
30 |
private static final long serialVersionUID = 1L; |
33 |
private static final long serialVersionUID = 1L; |
31 |
|
34 |
|
32 |
private TreeMap fFriends = new TreeMap(); |
35 |
private TreeMap fFriends = new TreeMap(); |
Lines 143-166
Link Here
|
143 |
// remove the Uses directive, we will make sure to put it at the end |
146 |
// remove the Uses directive, we will make sure to put it at the end |
144 |
if (table.containsKey(Constants.USES_DIRECTIVE)) |
147 |
if (table.containsKey(Constants.USES_DIRECTIVE)) |
145 |
usesValue = table.remove(Constants.USES_DIRECTIVE); |
148 |
usesValue = table.remove(Constants.USES_DIRECTIVE); |
|
|
149 |
|
150 |
Object friendsValue = null; |
151 |
// remove the friends directive, ensure it's appropriately formatted |
152 |
if (table.containsKey(FRIENDS)) { |
153 |
friendsValue = table.remove(FRIENDS); |
154 |
} |
155 |
|
146 |
super.appendValuesToBuffer(sb, table); |
156 |
super.appendValuesToBuffer(sb, table); |
|
|
157 |
|
158 |
// If only one of uses and x-friends is specified, then the directives |
159 |
// have new lines at commas if there are more than 3 of them; if they're |
160 |
// both specified then they insert new lines for more than 1. |
161 |
int newLineLimit = NEWLINE_LIMIT; |
162 |
if (friendsValue != null && usesValue != null) { |
163 |
newLineLimit = NEWLINE_LIMIT_BOTH; |
164 |
} |
165 |
|
166 |
if (friendsValue != null) { |
167 |
table.put(FRIENDS, friendsValue); |
168 |
formatDirective(FRIENDS, sb, friendsValue, newLineLimit); |
169 |
} |
170 |
|
147 |
if (usesValue != null) { |
171 |
if (usesValue != null) { |
148 |
table.put(Constants.USES_DIRECTIVE, usesValue); |
172 |
table.put(Constants.USES_DIRECTIVE, usesValue); |
149 |
formatUsesDirective(sb, usesValue); |
173 |
formatDirective(Constants.USES_DIRECTIVE, sb, usesValue, |
|
|
174 |
newLineLimit); |
150 |
} |
175 |
} |
151 |
} |
176 |
} |
152 |
|
177 |
|
153 |
private void formatUsesDirective(StringBuffer sb, Object usesValue) { |
178 |
/** |
|
|
179 |
* Format the specified directive of the Export-Package manifest header. |
180 |
* |
181 |
* @param directiveName |
182 |
* The name of the directive, e.g. x-friends or uses |
183 |
* @param sb |
184 |
* buffer to append the directives |
185 |
* @param usesValue |
186 |
* The value of the uses directive, expected to be a String or a |
187 |
* List. |
188 |
* @param newLineLimit |
189 |
* The number of items, above which, a new line would be needed |
190 |
* between all values. |
191 |
*/ |
192 |
private void formatDirective(String directiveName, StringBuffer sb, |
193 |
Object usesValue, final int newLineLimit) { |
154 |
StringTokenizer tokenizer = null; |
194 |
StringTokenizer tokenizer = null; |
155 |
if (usesValue instanceof String) |
195 |
if (usesValue instanceof String) |
156 |
tokenizer = new StringTokenizer((String)usesValue, ","); //$NON-NLS-1$ |
196 |
tokenizer = new StringTokenizer((String)usesValue, ","); //$NON-NLS-1$ |
157 |
boolean newLine = (tokenizer != null) ? tokenizer.countTokens() > 3 : |
197 |
boolean newLine = (tokenizer != null) ? tokenizer.countTokens() > newLineLimit : |
158 |
((ArrayList)usesValue).size() > 3; |
198 |
((ArrayList)usesValue).size() > newLineLimit; |
159 |
String eol = getHeader().getLineLimiter(); |
199 |
String eol = getHeader().getLineLimiter(); |
160 |
sb.append(';'); |
200 |
sb.append(';'); |
161 |
if (newLine) |
201 |
if (newLine) |
162 |
sb.append(eol).append(" "); //$NON-NLS-1$ |
202 |
sb.append(eol).append(" "); //$NON-NLS-1$ |
163 |
sb.append(Constants.USES_DIRECTIVE); |
203 |
sb.append(directiveName); |
164 |
sb.append(":=\""); //$NON-NLS-1$ |
204 |
sb.append(":=\""); //$NON-NLS-1$ |
165 |
if (tokenizer != null) |
205 |
if (tokenizer != null) |
166 |
while (tokenizer.hasMoreTokens()) { |
206 |
while (tokenizer.hasMoreTokens()) { |