diff options
author | 2021-06-11 13:52:25 -0700 | |
---|---|---|
committer | 2023-04-15 10:13:52 +0200 | |
commit | 3dc12a1cf977e05cd3ff4ef0c61267c5e4abf395 (patch) | |
tree | 5584c8da21bef6d24c8dab64b7a4b5b5566f6c03 | |
parent | changed eapi to 8 (diff) | |
download | java-ebuilder-3dc12a1cf977e05cd3ff4ef0c61267c5e4abf395.tar.gz java-ebuilder-3dc12a1cf977e05cd3ff4ef0c61267c5e4abf395.tar.bz2 java-ebuilder-3dc12a1cf977e05cd3ff4ef0c61267c5e4abf395.zip |
Add support for multi-line MAVEN_PROVIDES definition
Closes: https://bugs.gentoo.org/903666
Signed-off-by: Yuan Liao <liaoyuan@gmail.com>
Signed-off-by: Miroslav Šulc <fordfrog@gentoo.org>
-rw-r--r-- | src/main/java/org/gentoo/java/ebuilder/portage/PortageParser.java | 81 |
1 files changed, 52 insertions, 29 deletions
diff --git a/src/main/java/org/gentoo/java/ebuilder/portage/PortageParser.java b/src/main/java/org/gentoo/java/ebuilder/portage/PortageParser.java index a1a7075..ff4acf3 100644 --- a/src/main/java/org/gentoo/java/ebuilder/portage/PortageParser.java +++ b/src/main/java/org/gentoo/java/ebuilder/portage/PortageParser.java @@ -263,8 +263,9 @@ public class PortageParser { String groupId = null; String artifactId = null; String mavenVersion = null; - String[] mavenProvide = null; + List<String> mavenProvide = new ArrayList<>(); + boolean readingMultiLineMavenProvide = false; try (final BufferedReader reader = new BufferedReader( new InputStreamReader(Files.newInputStream(ebuild.toPath(), StandardOpenOption.READ)))) { @@ -282,31 +283,55 @@ public class PortageParser { } if (!line.isEmpty()) { - final Matcher matcher = PATTERN_VARIABLE.matcher(line); - - if (matcher.matches()) { - variables.put(matcher.group(1), - matcher.group(2).replaceAll("(^\"|\"$)", "")); - } + // Check if a multi-line MAVEN_PROVIDES declaration is + // being read + if (readingMultiLineMavenProvide) { + if (!line.startsWith("\"")) { + // Line contains an artifact ID + mavenProvide.add(line.replace("\"", "")); + } + if (line.contains("\"")) { + // Closing double quote + readingMultiLineMavenProvide = false; + } + } else { + // Check if the line contains variable declaration + final Matcher matcher = PATTERN_VARIABLE.matcher(line); - if (line.startsWith("inherit ")) { - eclasses = getJavaInheritEclasses(line); + if (matcher.matches()) { + variables.put(matcher.group(1), + matcher.group(2).replaceAll("(^\"|\"$)", "")); + } - if (eclasses == null || eclasses.isEmpty()) { - return; + if (line.startsWith("inherit ")) { + eclasses = getJavaInheritEclasses(line); + + if (eclasses == null || eclasses.isEmpty()) { + return; + } + } else if (line.startsWith("SLOT=")) { + slot = line.substring("SLOT=".length()).replace( + "\"", "").replaceAll("/.*", ""); + } else if (line.startsWith("JAVA_PKG_OPT_USE=")) { + useFlag = line.substring("JAVA_PKG_OPT_USE=".length()). + replace("\"", ""); + } else if (line.startsWith("MAVEN_ID=")) { + mavenId = line.substring("MAVEN_ID=".length()). + replace("\"", ""); + } else if (line.startsWith("MAVEN_PROVIDES=")) { + boolean atMostOneDoubleQuote = + line.indexOf("\"") == line.lastIndexOf("\""); + line = line.substring("MAVEN_PROVIDES=".length()); + if (!atMostOneDoubleQuote || !line.endsWith("\"")) { + // Line contains an artifact ID + mavenProvide.addAll(Arrays.asList( + line.replace("\"", "").split(" "))); + } + if (atMostOneDoubleQuote && line.contains("\"")) { + // Only one double quote -- multi-line declaration + readingMultiLineMavenProvide = true; + } } - } else if (line.startsWith("SLOT=")) { - slot = line.substring("SLOT=".length()).replace( - "\"", "").replaceAll("/.*", ""); - } else if (line.startsWith("JAVA_PKG_OPT_USE=")) { - useFlag = line.substring("JAVA_PKG_OPT_USE=".length()). - replace("\"", ""); - } else if (line.startsWith("MAVEN_ID=")) { - mavenId = line.substring("MAVEN_ID=".length()). - replace("\"", ""); - } else if (line.startsWith("MAVEN_PROVIDES=")) { - mavenProvide = line.substring("MAVEN_PROVIDES=".length()). - replace("\"", "").split(" "); } } @@ -368,12 +393,10 @@ public class PortageParser { cacheItems.add(new CacheItem(category, pkg, version, slot, useFlag, groupId, artifactId, mavenVersion, eclasses)); - if (mavenProvide != null) { - for (String providedId: mavenProvide) { - final String[] parts = providedId.split(":"); - cacheItems.add(new CacheItem(category, pkg, version, slot, useFlag, - parts[0], parts[1], parts[2], eclasses)); - } + for (String providedId: mavenProvide) { + final String[] parts = providedId.split(":"); + cacheItems.add(new CacheItem(category, pkg, version, slot, useFlag, + parts[0], parts[1], parts[2], eclasses)); } countEclasses(eclasses); } |