aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzongyu <zzy2529420793@gmail.com>2020-07-01 22:07:24 +0800
committerzongyu <zzy2529420793@gmail.com>2020-07-06 17:48:27 +0800
commit3c816ce40c84791ac55f4bbe037e2da366e3e1e5 (patch)
tree50fb1bcf58dffb528ed6129b48349056998bd7f0
parentenable java-ebuilder to read metadata of a Gentoo package, and get a proper SLOT (diff)
downloadjava-ebuilder-3c816ce40c84791ac55f4bbe037e2da366e3e1e5.tar.gz
java-ebuilder-3c816ce40c84791ac55f4bbe037e2da366e3e1e5.tar.bz2
java-ebuilder-3c816ce40c84791ac55f4bbe037e2da366e3e1e5.zip
initial support for Maven Central Distributed Source jars
new CLI switch: --from-maven-central Signed-off-by: zongyu <zzy2529420793@gmail.com>
-rw-r--r--src/main/java/org/gentoo/java/ebuilder/Config.java22
-rw-r--r--src/main/java/org/gentoo/java/ebuilder/Main.java3
-rw-r--r--src/main/java/org/gentoo/java/ebuilder/maven/MavenEbuilder.java64
3 files changed, 85 insertions, 4 deletions
diff --git a/src/main/java/org/gentoo/java/ebuilder/Config.java b/src/main/java/org/gentoo/java/ebuilder/Config.java
index c53e7a9..53af30f 100644
--- a/src/main/java/org/gentoo/java/ebuilder/Config.java
+++ b/src/main/java/org/gentoo/java/ebuilder/Config.java
@@ -55,6 +55,10 @@ public class Config {
*/
private JavaVersion forceMinJavaVersion;
/**
+ * Whethe the source code is distributed by Maven Central
+ */
+ private boolean fromMavenCentral;
+ /**
* Whether ebuild should be generated.
*/
private boolean generateEbuild;
@@ -374,6 +378,24 @@ public class Config {
}
/**
+ * Getter for {@link #fromMavenCentral}.
+ *
+ * @return {@link #fromMavenCentral}
+ */
+ public boolean isFromMavenCentral() {
+ return fromMavenCentral;
+ }
+
+ /**
+ * Setter for {@link #fromMavenCentral}.
+ *
+ * @param fromMavenCentral {@link #fromMavenCentral}
+ */
+ public void setFromMavenCentral(final boolean fromMavenCentral) {
+ this.fromMavenCentral = fromMavenCentral;
+ }
+
+ /**
* Getter for {@link #generateEbuild}.
*
* @return {@link #generateEbuild}
diff --git a/src/main/java/org/gentoo/java/ebuilder/Main.java b/src/main/java/org/gentoo/java/ebuilder/Main.java
index fa4a85e..0b4eff6 100644
--- a/src/main/java/org/gentoo/java/ebuilder/Main.java
+++ b/src/main/java/org/gentoo/java/ebuilder/Main.java
@@ -239,6 +239,9 @@ public class Main {
i++;
config.setForceMinJavaVersion(new JavaVersion(args[i]));
break;
+ case "--from-maven-central":
+ config.setFromMavenCentral(true);
+ break;
case "--generate-ebuild":
case "-g":
config.setGenerateEbuild(true);
diff --git a/src/main/java/org/gentoo/java/ebuilder/maven/MavenEbuilder.java b/src/main/java/org/gentoo/java/ebuilder/maven/MavenEbuilder.java
index f17f860..0387120 100644
--- a/src/main/java/org/gentoo/java/ebuilder/maven/MavenEbuilder.java
+++ b/src/main/java/org/gentoo/java/ebuilder/maven/MavenEbuilder.java
@@ -26,12 +26,12 @@ public class MavenEbuilder {
* Pattern for retrieval of tarball extension.
*/
private static final Pattern PATTERN_TARBALL_EXTENSION = Pattern.compile(
- "^.*((?:\\.tar)\\.\\S+)$");
+ "^.*((?:\\.tar)\\.\\S+|(?:\\.jar))$");
/**
* Pattern for checking whether download tarball name matches expected name.
*/
private static final Pattern PATTERN_TARBALL_NAME
- = Pattern.compile("^.*/\\$\\{P\\}(?:\\.tar)\\.\\S+$");
+ = Pattern.compile("^.*/\\$\\{P\\}((?:\\.tar)\\.\\S+|(?:\\.jar))$");
/**
* Generates ebuild from the collected information at the specified path.
@@ -236,6 +236,41 @@ public class MavenEbuilder {
}
/**
+ * If the tarball name does not match pattern ${P}-test.ext then we will update
+ * it to store the tarball as ${P}-test.ext.
+ *
+ * @param TestSrcUri source test URI
+ *
+ * @return either original source test URI or updated source test URI
+ private String improveTestSrcUri(final String TestSrcUri) {
+ if (PATTERN_TEST_TARBALL_NAME.matcher(TestSrcUri).matches()) {
+ return TestSrcUri;
+ }
+
+ final Matcher matcher = PATTERN_TARBALL_EXTENSION.matcher(TestSrcUri);
+
+ /**
+ * We do not know how to get the extension so we will leave the tarball
+ * name as it is.
+ /
+ if (!matcher.matches()) {
+ return TestSrcUri;
+ }
+
+ return TestSrcUri + " -> " + "${P}-test" + matcher.group(1);
+ }
+ */
+
+ /**
+ * Merges maven project system dependencies of specified type and removed
+ * duplicates.
+ *
+ * @param mavenProjects list of maven projects
+ * @param type type of dependencies ("common", "compile", "runtime"
+ * and "test")
+ *
+ * @return list of merged dependencies
+ /**
* Merges maven project system dependencies of specified type and removed
* duplicates.
*
@@ -702,12 +737,10 @@ public class MavenEbuilder {
writer.println('"');
}
- /*
writer.print("JAVA_SRC_DIR=\"");
writer.print(replaceWithVars(config.getWorkdir().relativize(
mavenProject.getSourceDirectory()).toString(), config));
writer.println('"');
- */
if (mavenProject.getMainClass() != null) {
writer.print("JAVA_MAIN_CLASS=\"");
@@ -778,6 +811,11 @@ public class MavenEbuilder {
writer.println(')');
}
}
+
+ if (config.isFromMavenCentral()) {
+ writeMavenUnpack(mavenProject, writer);
+ }
+
}
/**
@@ -789,4 +827,22 @@ public class MavenEbuilder {
writer.println();
writer.println("S=\"${WORKDIR}\"");
}
+
+ /**
+ * modify src_unpack() if we use Maven distributed source codes.
+ *
+ * @param writer ebuild writer
+ */
+ private void writeMavenUnpack(final MavenProject mavenProject,
+ final PrintWriter writer) {
+ writer.println();
+ writer.println("src_unpack() {");
+ writer.println("\tmkdir -p ${S}/${JAVA_SRC_DIR}");
+ writer.println("\tunzip ${DISTDIR}/${P}.jar -d ${S}/${JAVA_SRC_DIR}");
+ if (mavenProject.hasTests()) {
+ writer.println("\tmkdir -p ${JAVA_TEST_SRC_DIR}");
+ writer.println("\tunzip ${DISTDIR}/${P}-test.jar -d ${S}/${JAVA_TEST_SRC_DIR}");
+ }
+ writer.println("}");
+ }
}