diff options
author | zongyu <zzy2529420793@gmail.com> | 2020-06-29 16:22:46 +0800 |
---|---|---|
committer | zongyu <zzy2529420793@gmail.com> | 2020-07-06 17:48:27 +0800 |
commit | eceb93b00b8a1b4c8841f43bf61347fbb613f249 (patch) | |
tree | e299386faa9768cf8bb9489832e51315e5e1c8ab /src | |
parent | jdk-8 -> jdk-1.8 (diff) | |
download | java-ebuilder-eceb93b00b8a1b4c8841f43bf61347fbb613f249.tar.gz java-ebuilder-eceb93b00b8a1b4c8841f43bf61347fbb613f249.tar.bz2 java-ebuilder-eceb93b00b8a1b4c8841f43bf61347fbb613f249.zip |
enable java-ebuilder to read metadata of a Gentoo package, and get a proper SLOT
Signed-off-by: zongyu <zzy2529420793@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/gentoo/java/ebuilder/portage/PortageParser.java | 44 |
1 files changed, 43 insertions, 1 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 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). @@ -391,6 +399,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. + * * @param slot SLOT string * @param pv PV variable * @param variables map of collected variables and their values |