Skip to content

Commit f135f23

Browse files
committed
Add support for multi-line MAVEN_PROVIDES definition
Signed-off-by: Yuan Liao <liaoyuan@gmail.com>
1 parent c7b3d7e commit f135f23

File tree

1 file changed

+52
-29
lines changed

1 file changed

+52
-29
lines changed

src/main/java/org/gentoo/java/ebuilder/portage/PortageParser.java

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,9 @@ private void parseEbuild(final File ebuild) {
263263
String groupId = null;
264264
String artifactId = null;
265265
String mavenVersion = null;
266-
String[] mavenProvide = null;
266+
List<String> mavenProvide = new ArrayList<>();
267267

268+
boolean readingMultiLineMavenProvide = false;
268269
try (final BufferedReader reader = new BufferedReader(
269270
new InputStreamReader(Files.newInputStream(ebuild.toPath(),
270271
StandardOpenOption.READ)))) {
@@ -282,31 +283,55 @@ private void parseEbuild(final File ebuild) {
282283
}
283284

284285
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);
291300

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+
}
294305

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+
}
297334
}
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(" ");
310335
}
311336
}
312337

@@ -368,12 +393,10 @@ private void parseEbuild(final File ebuild) {
368393
cacheItems.add(new CacheItem(category, pkg, version, slot, useFlag,
369394
groupId, artifactId, mavenVersion, eclasses));
370395

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));
377400
}
378401
countEclasses(eclasses);
379402
}

0 commit comments

Comments
 (0)