commit:     3dc12a1cf977e05cd3ff4ef0c61267c5e4abf395
Author:     Yuan Liao <liaoyuan <AT> gmail <DOT> com>
AuthorDate: Fri Jun 11 20:52:25 2021 +0000
Commit:     Miroslav Šulc <fordfrog <AT> gentoo <DOT> org>
CommitDate: Sat Apr 15 08:13:52 2023 +0000
URL:        https://gitweb.gentoo.org/proj/java-ebuilder.git/commit/?id=3dc12a1c

Add support for multi-line MAVEN_PROVIDES definition

Closes: https://bugs.gentoo.org/903666
Signed-off-by: Yuan Liao <liaoyuan <AT> gmail.com>
Signed-off-by: Miroslav Šulc <fordfrog <AT> gentoo.org>

 .../java/ebuilder/portage/PortageParser.java       | 81 ++++++++++++++--------
 1 file 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);
     }

Reply via email to