public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Miroslav Šulc" <fordfrog@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/java-ebuilder:master commit in: src/main/java/org/gentoo/java/ebuilder/portage/
Date: Mon,  6 Jul 2020 10:56:08 +0000 (UTC)	[thread overview]
Message-ID: <1594028907.eceb93b00b8a1b4c8841f43bf61347fbb613f249.fordfrog@gentoo> (raw)

commit:     eceb93b00b8a1b4c8841f43bf61347fbb613f249
Author:     zongyu <zzy2529420793 <AT> gmail <DOT> com>
AuthorDate: Mon Jun 29 08:22:46 2020 +0000
Commit:     Miroslav Šulc <fordfrog <AT> gentoo <DOT> org>
CommitDate: Mon Jul  6 09:48:27 2020 +0000
URL:        https://gitweb.gentoo.org/proj/java-ebuilder.git/commit/?id=eceb93b0

enable java-ebuilder to read metadata of a Gentoo package, and get a proper SLOT

Signed-off-by: zongyu <zzy2529420793 <AT> gmail.com>

 .../java/ebuilder/portage/PortageParser.java       | 44 +++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)

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 fd9e2c4..96e0c06 100644
--- a/src/main/java/org/gentoo/java/ebuilder/portage/PortageParser.java
+++ b/src/main/java/org/gentoo/java/ebuilder/portage/PortageParser.java
@@ -8,6 +8,7 @@ import java.io.OutputStreamWriter;
 import java.nio.charset.Charset;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.nio.file.StandardOpenOption;
 import java.text.MessageFormat;
 import java.util.ArrayList;
@@ -251,6 +252,8 @@ public class PortageParser {
         final String pkg = ebuild.getParentFile().getName();
         final String version = filename.substring(pkg.length() + 1);
         final Map<String, String> variables = new HashMap<>(20);
+        final Path ebuildMetadata = Paths.get(ebuild.getParent(), "..", "..",
+                "metadata", "md5-cache", category, filename).normalize();
         List<String> eclasses = null;
         String slot = "0";
         String useFlag = null;
@@ -328,7 +331,12 @@ public class PortageParser {
             pv = version.substring(0, pos);
         }
 
-        slot = processSlot(slot, pv, variables);
+        if (Files.exists(ebuildMetadata)) {
+            slot = processSlot(slot, ebuildMetadata);
+        }
+        else {
+            slot = processSlot(slot, pv, variables);
+        }
 
         if (mavenId != null) {
             mavenId = mavenId.replaceAll("\\$(\\{PN\\}|PN)", pkg).
@@ -388,6 +396,40 @@ public class PortageParser {
         }
     }
 
+    /**
+     * Processes various instructions in SLOT string.
+     *
+     * @param slot           SLOT string
+     * @param ebuildMetadata path to the metadata of the Gentoo package
+     *
+     * @return processed SLOT string
+     */
+    private String processSlot(final String slot,
+            final Path ebuildMetadata) {
+        //final metadata = new File(ebuildMetadata.toString());
+	String result = slot;
+        try (final BufferedReader reader = new BufferedReader(
+                new InputStreamReader(Files.newInputStream(ebuildMetadata,
+                        StandardOpenOption.READ)))) {
+            String line = reader.readLine();
+            while (line != null) {
+                line = line.trim();
+
+                if (!line.isEmpty()) {
+                    if (line.startsWith("SLOT=")) {
+                        result = line.substring("SLOT=".length()).replace(
+                                "\"", "").replaceAll("/.*", "");
+                    }
+
+                line = reader.readLine();
+                }
+            }
+        } catch (final IOException ex) {
+            throw new RuntimeException("Failed to read ebuild", ex);
+        }
+	return result;
+    }
+
     /**
      * Processes various instructions in SLOT string.
      *


             reply	other threads:[~2020-07-06 10:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-06 10:56 Miroslav Šulc [this message]
  -- strict thread matches above, loose matches on Subject: below --
2023-04-15  8:14 [gentoo-commits] proj/java-ebuilder:master commit in: src/main/java/org/gentoo/java/ebuilder/portage/ Miroslav Šulc
2023-04-15  8:14 Miroslav Šulc
2020-07-06 10:56 Miroslav Šulc
2020-07-06 10:56 Miroslav Šulc
2020-07-06 10:56 Miroslav Šulc
2020-07-06 10:56 Miroslav Šulc
2020-07-06 10:56 Miroslav Šulc
2019-11-03 13:54 Miroslav Šulc
2019-10-30 19:26 Miroslav Šulc
2019-10-30 17:35 Michał Górny
2019-10-30 17:35 Michał Górny

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1594028907.eceb93b00b8a1b4c8841f43bf61347fbb613f249.fordfrog@gentoo \
    --to=fordfrog@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox