aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiroslav Šulc <fordfrog@gentoo.org>2019-11-01 20:41:43 +0100
committerMiroslav Šulc <fordfrog@gentoo.org>2019-11-01 20:41:43 +0100
commit889bcaf2504570a64c9b0a8e1f22b092a83e0c0c (patch)
tree57abd7a6cfcdae6ca809d69af48321de7e7dc49e
parentversion updated (diff)
downloadjava-ebuilder-889bcaf2.tar.gz
java-ebuilder-889bcaf2.tar.bz2
java-ebuilder-889bcaf2.zip
added parsing of ebuild file name components
Signed-off-by: Miroslav Šulc <fordfrog@gentoo.org>
-rw-r--r--src/main/java/org/gentoo/java/ebuilder/Config.java66
-rw-r--r--src/main/java/org/gentoo/java/ebuilder/Main.java30
-rw-r--r--src/main/java/org/gentoo/java/ebuilder/portage/PortageParser.java45
3 files changed, 141 insertions, 0 deletions
diff --git a/src/main/java/org/gentoo/java/ebuilder/Config.java b/src/main/java/org/gentoo/java/ebuilder/Config.java
index 4127266..9bc98f8 100644
--- a/src/main/java/org/gentoo/java/ebuilder/Config.java
+++ b/src/main/java/org/gentoo/java/ebuilder/Config.java
@@ -29,6 +29,18 @@ public class Config {
*/
private Path ebuild;
/**
+ * Ebuild name.
+ */
+ private String ebuildName;
+ /**
+ * Ebuild version excluding suffix.
+ */
+ private String ebuildVersion;
+ /**
+ * Ebuild version suffix (-r).
+ */
+ private String ebuildVersionSuffix;
+ /**
* Writer for errors.
*/
private final PrintWriter errorWriter;
@@ -145,6 +157,60 @@ public class Config {
}
/**
+ * Getter for {@link #ebuildName}.
+ *
+ * @return {@link #ebuildName}
+ */
+ public String getEbuildName() {
+ return ebuildName;
+ }
+
+ /**
+ * Setter for {@link #ebuildName}.
+ *
+ * @param ebuildName {@link #ebuildName}
+ */
+ public void setEbuildName(final String ebuildName) {
+ this.ebuildName = ebuildName;
+ }
+
+ /**
+ * Getter for {@link #ebuildVersion}.
+ *
+ * @return {@link #ebuildVersion}
+ */
+ public String getEbuildVersion() {
+ return ebuildVersion;
+ }
+
+ /**
+ * Setter for {@link #ebuildVersion}.
+ *
+ * @param ebuildVersion {@link #ebuildVersion}
+ */
+ public void setEbuildVersion(final String ebuildVersion) {
+ this.ebuildVersion = ebuildVersion;
+ }
+
+ /**
+ * Getter for {@link #ebuildVersionSuffix}.
+ *
+ * @return {@link #ebuildVersionSuffix}
+ */
+ public String getEbuildVersionSuffix() {
+ return ebuildVersionSuffix;
+ }
+
+ /**
+ * Setter for {@link #ebuildVersionSuffix}.
+ *
+ * @param ebuildVersionSuffix {@link #ebuildVersionSuffix}
+ */
+ public void setEbuildVersionSuffix(final String ebuildVersionSuffix) {
+ this.ebuildVersionSuffix = ebuildVersionSuffix;
+ }
+
+ /**
* Getter for {@link #errorWriter}.
*
* @return {@link #errorWriter}
diff --git a/src/main/java/org/gentoo/java/ebuilder/Main.java b/src/main/java/org/gentoo/java/ebuilder/Main.java
index 5921ea1..6c5cd13 100644
--- a/src/main/java/org/gentoo/java/ebuilder/Main.java
+++ b/src/main/java/org/gentoo/java/ebuilder/Main.java
@@ -9,6 +9,7 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Paths;
import java.util.List;
+import java.util.Map;
import org.gentoo.java.ebuilder.maven.MavenCache;
import org.gentoo.java.ebuilder.maven.MavenEbuilder;
import org.gentoo.java.ebuilder.maven.MavenParser;
@@ -159,6 +160,8 @@ public class Main {
* @param config application configuration
*/
private static void generateEbuild(final Config config) {
+ parseEbuildName(config);
+
final MavenCache mavenCache = new MavenCache();
mavenCache.loadCache(config);
@@ -254,6 +257,33 @@ public class Main {
}
/**
+ * Parses ebuild file name into its components.
+ *
+ * @param config app configuration containing ebuild information
+ */
+ private static void parseEbuildName(final Config config) {
+ final Map<String, String> result;
+
+ try {
+ result = PortageParser.parseEbuildName(
+ config.getEbuild().getFileName().toString());
+
+ config.setEbuildName(result.get("name"));
+ config.setEbuildVersion(result.get("version"));
+ config.setEbuildVersionSuffix(result.get("suffix"));
+
+ config.getStdoutWriter().println("Parsed ebuild file name - name: "
+ + config.getEbuildName() + " version: "
+ + config.getEbuildVersion() + " suffix: "
+ + config.getEbuildVersionSuffix());
+ } catch (final IllegalArgumentException ex) {
+ config.getStdoutWriter().println("Cannot parse ebuild file name");
+
+ Runtime.getRuntime().exit(1);
+ }
+ }
+
+ /**
* Prints application usage information.
*/
private static void printUsage(final Config config) {
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 d504b2c..a85fe6c 100644
--- a/src/main/java/org/gentoo/java/ebuilder/portage/PortageParser.java
+++ b/src/main/java/org/gentoo/java/ebuilder/portage/PortageParser.java
@@ -50,6 +50,11 @@ public class PortageParser {
*/
private static final String ECLASS_JAVA_UTILS = "java-utils-2";
/**
+ * Pattern for parsing ebuild file name.
+ */
+ private static final Pattern PATTERN_EBUILD_NAME = Pattern.compile(
+ "^(\\S+?)-([^-]+)(?:-(r\\d+))?\\.ebuild$");
+ /**
* Pattern for parsing SLOT with bash substring.
*/
private static final Pattern PATTERN_SLOT_SUBSTRING = Pattern.compile(
@@ -67,6 +72,46 @@ public class PortageParser {
*/
private static final Pattern PATTERN_VARIABLE = Pattern.compile(
"^(\\S+?)=(.*)$");
+
+ /**
+ * Parses ebuild name into map. Keys are:
+ * <dl>
+ * <dt>name</dt>
+ * <dd>ebuild name</dd>
+ * <dt>version</dt>
+ * <dd>ebuild version</dd>
+ * <dt>suffix</dt>
+ * <dd>ebuild version suffix (-r)</dd>
+ * </dl>
+ * If suffix is not present in ebuild name, it is not put into the map
+ * aswell.
+ *
+ * @param name ebuild file name
+ *
+ * @return map of parsed values
+ *
+ * @throws IllegalArgumentException Thrown if the ebuild file name is not
+ * valid or it cannot be parsed.
+ */
+ public static Map<String, String> parseEbuildName(final String name) {
+ final Matcher matcher = PATTERN_EBUILD_NAME.matcher(name);
+
+ if (!matcher.matches()) {
+ throw new IllegalArgumentException("Ebuild file name is not valid "
+ + "or parser does not support this ebuild name format");
+ }
+
+ final Map<String, String> result = new HashMap<>(3);
+ result.put("name", matcher.group(1));
+ result.put("version", matcher.group(2));
+
+ if (matcher.groupCount() > 2) {
+ result.put("suffix", matcher.group(3));
+ }
+
+ return result;
+ }
+
/**
* List of cache items. This list is populated during parsing the tree.
*/