diff options
author | 2020-08-04 15:10:01 +0800 | |
---|---|---|
committer | 2020-08-05 12:05:24 +0800 | |
commit | 11678b72a491963a8bad6d65c84d6228a0e3ac5a (patch) | |
tree | 6243a9ce5d6e6dc6892db643083ff3fff117a7c3 | |
parent | sort licenses (diff) | |
download | java-ebuilder-11678b72a491963a8bad6d65c84d6228a0e3ac5a.tar.gz java-ebuilder-11678b72a491963a8bad6d65c84d6228a0e3ac5a.tar.bz2 java-ebuilder-11678b72a491963a8bad6d65c84d6228a0e3ac5a.zip |
sort KEYWORDS
Signed-off-by: zongyu <zzy2529420793@gmail.com>
5 files changed, 64 insertions, 9 deletions
diff --git a/src/main/java/org/gentoo/java/ebuilder/Config.java b/src/main/java/org/gentoo/java/ebuilder/Config.java index dbfa30b..4502ab3 100644 --- a/src/main/java/org/gentoo/java/ebuilder/Config.java +++ b/src/main/java/org/gentoo/java/ebuilder/Config.java @@ -7,7 +7,10 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; import org.gentoo.java.ebuilder.maven.JavaVersion; +import org.gentoo.java.ebuilder.portage.KeywordComparator; /** * Container for command line configuration. @@ -73,7 +76,7 @@ public class Config { /** * Arch keywords. */ - private String keywords; + private SortedSet<String> keywords = new TreeSet<>(new KeywordComparator()); /** * License name. */ @@ -301,16 +304,33 @@ public class Config { * @return {@link #keywords} */ public String getKeywords() { - return keywords; + return String.join(" ", keywords); } /** - * Setter for {@link #keywords}. + * add keyword to {@link #keywords}. * - * @param keywords {@link #keywords} + * @param keyword String that contains one or more keywords */ - public void setKeywords(final String keywords) { - this.keywords = keywords; + public void addKeywords(final String keywords) { + String[] parts = keywords.split(" "); + + /** + * Make "-amd64" replace "amd64 ~amd64" + * Make "amd64" replace "~amd64" + */ + for (String part : parts) { + if (part.startsWith("-")) { + this.keywords.remove(part.substring(1)); + this.keywords.remove("~" + part.substring(1)); + this.keywords.add(part); + } else if (part.startsWith("~")) { + this.keywords.add(part); + } else { + this.keywords.remove("~" + part); + this.keywords.add(part); + } + } } /** diff --git a/src/main/java/org/gentoo/java/ebuilder/Main.java b/src/main/java/org/gentoo/java/ebuilder/Main.java index 49f6a49..999f741 100644 --- a/src/main/java/org/gentoo/java/ebuilder/Main.java +++ b/src/main/java/org/gentoo/java/ebuilder/Main.java @@ -262,7 +262,7 @@ public class Main { case "--keywords": case "-k": i++; - config.setKeywords(args[i]); + config.addKeywords(args[i]); break; case "--license": case "-l": diff --git a/src/main/java/org/gentoo/java/ebuilder/maven/MavenProject.java b/src/main/java/org/gentoo/java/ebuilder/maven/MavenProject.java index e1016a8..51ec844 100644 --- a/src/main/java/org/gentoo/java/ebuilder/maven/MavenProject.java +++ b/src/main/java/org/gentoo/java/ebuilder/maven/MavenProject.java @@ -46,7 +46,7 @@ public class MavenProject { /** * Lisences. */ - private SortedSet<String> licenses = new TreeSet<>(10); + private SortedSet<String> licenses = new TreeSet<>(); /** * Homepage URL. */ diff --git a/src/main/java/org/gentoo/java/ebuilder/portage/KeywordComparator.java b/src/main/java/org/gentoo/java/ebuilder/portage/KeywordComparator.java new file mode 100644 index 0000000..4382cf4 --- /dev/null +++ b/src/main/java/org/gentoo/java/ebuilder/portage/KeywordComparator.java @@ -0,0 +1,35 @@ +package org.gentoo.java.ebuilder.portage; + +import java.util.Comparator; + +/** + * a comparator to sort keywords + * + * @author Zhang Zongyu + */ +public class KeywordComparator implements Comparator<String> { + + /** + * it is designed to compare KEYWORDS as what repoman will do: + * 1) "-amd64", "amd64" and "~amd64" are the same -- they will + * not appear at the same time in a TreeSet; + * 2) After splitting the strings into two parts by "-", it will + * compare the suffixes before it compares the prefixes. + */ + @Override + public int compare(String o1, String o2) { + // prepend "-0-" to make sure the length of the array is 2 + final String[] trimmedO1 = (o1 + "-0-"). + replaceAll("^[-~]", ""). + split("-", 2); + final String[] trimmedO2 = (o2 + "-0-"). + replaceAll("^[-~]", ""). + split("-", 2); + + if (trimmedO1[1].compareTo(trimmedO2[1]) == 0) { + return trimmedO1[0].compareTo(trimmedO2[0]); + } else { + return trimmedO1[1].compareTo(trimmedO2[1]); + } + } +} diff --git a/src/main/resources/usage.txt b/src/main/resources/usage.txt index 1ceceeb..e48e3f9 100644 --- a/src/main/resources/usage.txt +++ b/src/main/resources/usage.txt @@ -10,7 +10,7 @@ Generating ebuild: --force-min-java-version <version> force minimum JDK/JRE version in dependencies --from-maven-central make java-ebuilder inherit java-pkg-maven.eclass --generate-ebuild|-g generates ebuild from pom.xml ---keywords|-k <keywords> arch keywords +--keywords|-k <keywords> arch keywords (can be specified multiple times) --license|-l <license> license name, if it is not specified, java-ebuilder will determine LICENSE from pom.xml --pom|-p <file> path to pom.xml that should be parsed, |