|
20 | 20 | */
|
21 | 21 | package proguard;
|
22 | 22 |
|
23 |
| -import proguard.classfile.*; |
| 23 | +import proguard.classfile.AccessConstants; |
| 24 | +import proguard.classfile.ClassConstants; |
| 25 | +import proguard.classfile.JavaAccessConstants; |
| 26 | +import proguard.classfile.JavaTypeConstants; |
| 27 | +import proguard.classfile.TypeConstants; |
24 | 28 | import proguard.classfile.util.ClassUtil;
|
25 |
| -import proguard.util.*; |
26 |
| - |
27 |
| -import java.io.*; |
28 |
| -import java.net.*; |
29 |
| -import java.util.*; |
| 29 | +import proguard.util.ListUtil; |
| 30 | +import proguard.util.StringUtil; |
| 31 | + |
| 32 | +import java.io.File; |
| 33 | +import java.io.IOException; |
| 34 | +import java.io.LineNumberReader; |
| 35 | +import java.io.StringReader; |
| 36 | +import java.net.MalformedURLException; |
| 37 | +import java.net.URL; |
| 38 | +import java.util.ArrayList; |
| 39 | +import java.util.List; |
| 40 | +import java.util.Properties; |
| 41 | +import java.util.function.BiConsumer; |
| 42 | +import java.util.function.BiFunction; |
30 | 43 |
|
31 | 44 |
|
32 | 45 | /**
|
@@ -139,9 +152,24 @@ public ConfigurationParser(WordReader reader,
|
139 | 152 | * @throws IOException if an IO error occurs while reading a configuration.
|
140 | 153 | */
|
141 | 154 | public void parse(Configuration configuration)
|
| 155 | + throws ParseException, IOException { |
| 156 | + parse(configuration, null); |
| 157 | + } |
| 158 | + |
| 159 | + /** |
| 160 | + * Parses and returns the configuration. |
| 161 | + * |
| 162 | + * @param configuration the configuration that is updated as a side-effect. |
| 163 | + * @param unknownOptionHandler optional handler for unknown options; if null then a {@link ParseException} |
| 164 | + * is thrown when encountering an unknown option. |
| 165 | + * @throws ParseException if the any of the configuration settings contains |
| 166 | + * a syntax error. |
| 167 | + * @throws IOException if an IO error occurs while reading a configuration. |
| 168 | + */ |
| 169 | + public void parse(Configuration configuration, BiConsumer<String, String> unknownOptionHandler) |
142 | 170 | throws ParseException, IOException
|
143 | 171 | {
|
144 |
| - while (nextWord != null) |
| 172 | + parseWord: while (nextWord != null) |
145 | 173 | {
|
146 | 174 | lastComments = reader.lastComments();
|
147 | 175 |
|
@@ -234,7 +262,15 @@ else if (ConfigurationConstants.REPACKAGE_CLASSES_OPTION
|
234 | 262 | else if (ConfigurationConstants.IDENTIFIER_NAME_STRING .startsWith(nextWord)) parseUnsupportedR8Rules(ConfigurationConstants.IDENTIFIER_NAME_STRING, true);
|
235 | 263 | else
|
236 | 264 | {
|
237 |
| - throw new ParseException("Unknown option " + reader.locationDescription()); |
| 265 | + if (unknownOptionHandler != null) { |
| 266 | + unknownOptionHandler.accept(nextWord, reader.lineLocationDescription()); |
| 267 | + while (nextWord != null) { |
| 268 | + readNextWord(); |
| 269 | + if (nextWord != null && nextWord.startsWith("-")) { |
| 270 | + continue parseWord; |
| 271 | + } |
| 272 | + } |
| 273 | + } else throw new ParseException("Unknown option " + reader.locationDescription()); |
238 | 274 | }
|
239 | 275 | }
|
240 | 276 | }
|
|
0 commit comments