@@ -263,8 +263,9 @@ private void parseEbuild(final File ebuild) {
263
263
String groupId = null ;
264
264
String artifactId = null ;
265
265
String mavenVersion = null ;
266
- String [] mavenProvide = null ;
266
+ List < String > mavenProvide = new ArrayList <>() ;
267
267
268
+ boolean readingMultiLineMavenProvide = false ;
268
269
try (final BufferedReader reader = new BufferedReader (
269
270
new InputStreamReader (Files .newInputStream (ebuild .toPath (),
270
271
StandardOpenOption .READ )))) {
@@ -282,31 +283,55 @@ private void parseEbuild(final File ebuild) {
282
283
}
283
284
284
285
if (!line .isEmpty ()) {
285
- final Matcher matcher = PATTERN_VARIABLE .matcher (line );
286
-
287
- if (matcher .matches ()) {
288
- variables .put (matcher .group (1 ),
289
- matcher .group (2 ).replaceAll ("(^\" |\" $)" , "" ));
290
- }
286
+ // Check if a multi-line MAVEN_PROVIDES declaration is
287
+ // being read
288
+ if (readingMultiLineMavenProvide ) {
289
+ if (!line .startsWith ("\" " )) {
290
+ // Line contains an artifact ID
291
+ mavenProvide .add (line .replace ("\" " , "" ));
292
+ }
293
+ if (line .contains ("\" " )) {
294
+ // Closing double quote
295
+ readingMultiLineMavenProvide = false ;
296
+ }
297
+ } else {
298
+ // Check if the line contains variable declaration
299
+ final Matcher matcher = PATTERN_VARIABLE .matcher (line );
291
300
292
- if (line .startsWith ("inherit " )) {
293
- eclasses = getJavaInheritEclasses (line );
301
+ if (matcher .matches ()) {
302
+ variables .put (matcher .group (1 ),
303
+ matcher .group (2 ).replaceAll ("(^\" |\" $)" , "" ));
304
+ }
294
305
295
- if (eclasses == null || eclasses .isEmpty ()) {
296
- return ;
306
+ if (line .startsWith ("inherit " )) {
307
+ eclasses = getJavaInheritEclasses (line );
308
+
309
+ if (eclasses == null || eclasses .isEmpty ()) {
310
+ return ;
311
+ }
312
+ } else if (line .startsWith ("SLOT=" )) {
313
+ slot = line .substring ("SLOT=" .length ()).replace (
314
+ "\" " , "" ).replaceAll ("/.*" , "" );
315
+ } else if (line .startsWith ("JAVA_PKG_OPT_USE=" )) {
316
+ useFlag = line .substring ("JAVA_PKG_OPT_USE=" .length ()).
317
+ replace ("\" " , "" );
318
+ } else if (line .startsWith ("MAVEN_ID=" )) {
319
+ mavenId = line .substring ("MAVEN_ID=" .length ()).
320
+ replace ("\" " , "" );
321
+ } else if (line .startsWith ("MAVEN_PROVIDES=" )) {
322
+ boolean atMostOneDoubleQuote =
323
+ line .indexOf ("\" " ) == line .lastIndexOf ("\" " );
324
+ line = line .substring ("MAVEN_PROVIDES=" .length ());
325
+ if (!atMostOneDoubleQuote || !line .endsWith ("\" " )) {
326
+ // Line contains an artifact ID
327
+ mavenProvide .addAll (Arrays .asList (
328
+ line .replace ("\" " , "" ).split (" " )));
329
+ }
330
+ if (atMostOneDoubleQuote && line .contains ("\" " )) {
331
+ // Only one double quote -- multi-line declaration
332
+ readingMultiLineMavenProvide = true ;
333
+ }
297
334
}
298
- } else if (line .startsWith ("SLOT=" )) {
299
- slot = line .substring ("SLOT=" .length ()).replace (
300
- "\" " , "" ).replaceAll ("/.*" , "" );
301
- } else if (line .startsWith ("JAVA_PKG_OPT_USE=" )) {
302
- useFlag = line .substring ("JAVA_PKG_OPT_USE=" .length ()).
303
- replace ("\" " , "" );
304
- } else if (line .startsWith ("MAVEN_ID=" )) {
305
- mavenId = line .substring ("MAVEN_ID=" .length ()).
306
- replace ("\" " , "" );
307
- } else if (line .startsWith ("MAVEN_PROVIDES=" )) {
308
- mavenProvide = line .substring ("MAVEN_PROVIDES=" .length ()).
309
- replace ("\" " , "" ).split (" " );
310
335
}
311
336
}
312
337
@@ -368,12 +393,10 @@ private void parseEbuild(final File ebuild) {
368
393
cacheItems .add (new CacheItem (category , pkg , version , slot , useFlag ,
369
394
groupId , artifactId , mavenVersion , eclasses ));
370
395
371
- if (mavenProvide != null ) {
372
- for (String providedId : mavenProvide ) {
373
- final String [] parts = providedId .split (":" );
374
- cacheItems .add (new CacheItem (category , pkg , version , slot , useFlag ,
375
- parts [0 ], parts [1 ], parts [2 ], eclasses ));
376
- }
396
+ for (String providedId : mavenProvide ) {
397
+ final String [] parts = providedId .split (":" );
398
+ cacheItems .add (new CacheItem (category , pkg , version , slot , useFlag ,
399
+ parts [0 ], parts [1 ], parts [2 ], eclasses ));
377
400
}
378
401
countEclasses (eclasses );
379
402
}
0 commit comments