diff options
author | 2020-07-11 23:02:22 +0800 | |
---|---|---|
committer | 2020-07-11 23:02:22 +0800 | |
commit | 40ff29ff64cb6cf411682bfeca58817a24bc1e05 (patch) | |
tree | f2dd30f51e5c1f5e5d469832bc6756456ac42ca7 | |
parent | fix some typos (diff) | |
download | java-ebuilder-40ff29ff64cb6cf411682bfeca58817a24bc1e05.tar.gz java-ebuilder-40ff29ff64cb6cf411682bfeca58817a24bc1e05.tar.bz2 java-ebuilder-40ff29ff64cb6cf411682bfeca58817a24bc1e05.zip |
add more command-line switches
--binjar-uri, which specifies uri of the pre-compiled jar
support installing binary maven packge
support future src_test(), which will
compare Gentoo-compiled jars and Maven
Central distributed jars
Signed-off-by: zongyu <zzy2529420793@gmail.com>
4 files changed, 97 insertions, 6 deletions
diff --git a/src/main/java/org/gentoo/java/ebuilder/Config.java b/src/main/java/org/gentoo/java/ebuilder/Config.java index 53af30f..27dbc7c 100644 --- a/src/main/java/org/gentoo/java/ebuilder/Config.java +++ b/src/main/java/org/gentoo/java/ebuilder/Config.java @@ -22,6 +22,14 @@ public class Config { private Path cacheFile = Paths.get(System.getProperty("user.home"), ".java-ebuilder/cache"); /** + * URI that goes to pre-compiled Maven Jar. + */ + private URI binjarUri; + /** + * whether binjarUri is set. + */ + private boolean binjarUriExists; + /** * URI that goes to SRC_URI. */ private URI downloadUri; @@ -135,6 +143,34 @@ public class Config { } /** + * Getter for {@link #binjarUri}. + * + * @return {@link #binjarUri} + */ + public URI getBinjarUri() { + return binjarUri; + } + + /** + * Getter for {@link #binjarUriExists}. + * + * @return {@link #binjarUriExists} + */ + public boolean hasBinjarUri() { + return binjarUriExists; + } + + /** + * Setter for {@link #binjarUri}. + * + * @param binjarUri {@link #binjarUri} + */ + public void setBinjarUri(final URI binjarUri) { + this.binjarUri = binjarUri; + this.binjarUriExists = true; + } + + /** * Getter for {@link #downloadUri}. * * @return {@link #downloadUri} diff --git a/src/main/java/org/gentoo/java/ebuilder/Main.java b/src/main/java/org/gentoo/java/ebuilder/Main.java index 0b4eff6..6843af7 100644 --- a/src/main/java/org/gentoo/java/ebuilder/Main.java +++ b/src/main/java/org/gentoo/java/ebuilder/Main.java @@ -213,6 +213,17 @@ public class Main { final String arg = args[i]; switch (arg) { + case "--binjar-uri": + i++; + + try { + config.setBinjarUri(new URI(args[i])); + } catch (final URISyntaxException ex) { + config.getErrorWriter().println("ERROR: BINJAR_URI " + args[i] + + " is not valid."); + } + + break; case "--download-uri": case "-u": i++; @@ -220,7 +231,7 @@ public class Main { try { config.setDownloadUri(new URI(args[i])); } catch (final URISyntaxException ex) { - config.getErrorWriter().println("ERROR: URI " + args[i] + config.getErrorWriter().println("ERROR: SRC_URI " + args[i] + " is not valid."); } 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 48920e5..08a5f99 100644 --- a/src/main/java/org/gentoo/java/ebuilder/maven/MavenEbuilder.java +++ b/src/main/java/org/gentoo/java/ebuilder/maven/MavenEbuilder.java @@ -236,6 +236,27 @@ public class MavenEbuilder { } /** + * Rename binjar file to ${P}-bin.ext + * + * @param binjarUri binjar URI + * + * @return updated binjar URI + */ + private String improveBinjarUri(final String binjarUri) { + + final Matcher matcher = PATTERN_TARBALL_EXTENSION.matcher(binjarUri); + + /** + * We do not know how to get the extension so assume it will be jar + */ + if (!matcher.matches()) { + return binjarUri + " -> " + "${P}-bin.jar"; + } + + return binjarUri + " -> " + "${P}-bin" + matcher.group(1); + } + + /** * If the tarball name does not match pattern ${P}-test.ext then we will update * it to store the tarball as ${P}-test.ext. * @@ -507,6 +528,10 @@ public class MavenEbuilder { mavenProjects, config.getForceMinJavaVersion())); writer.println(":*"); + if (config.hasBinjarUri()) { + writer.println("\t!binary? ("); + } + if (hasCDepend) { writer.print("${CDEPEND}"); } @@ -519,6 +544,11 @@ public class MavenEbuilder { }); } + if (config.hasBinjarUri()) { + writer.println("\t)"); + } + + writer.println('"'); } @@ -592,6 +622,10 @@ public class MavenEbuilder { writer.print(" test"); } + if (mavenProject.hasBinjarUri()) { + writer.print(" binary"); + } + writer.println('"'); writer.println(); writer.println("inherit java-pkg-2 java-pkg-simple"); @@ -656,6 +690,10 @@ public class MavenEbuilder { writer.print("SRC_URI=\""); writer.print(improveSrcUri( replaceWithVars(config.getDownloadUri().toString(), config))); + if (config.hasBinjarUri()) { + writer.print("\n\t" + improveBinjarUri( + replaceWithVars(config.getBinjarUri().toString(), config))); + } writer.println('"'); writer.print("LICENSE=\""); @@ -813,7 +851,7 @@ public class MavenEbuilder { } if (config.isFromMavenCentral()) { - writeMavenUnpack(mavenProject, writer); + writeMavenUnpack(config, mavenProject, writer); } } @@ -833,16 +871,22 @@ public class MavenEbuilder { * * @param writer ebuild writer */ - private void writeMavenUnpack(final MavenProject mavenProject, - final PrintWriter writer) { + private void writeMavenUnpack(final Config config, + 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} || die"); + if (mavenProject.hasTests()) { writer.println("\tmkdir -p ${JAVA_TEST_SRC_DIR}"); writer.println("\tunzip ${DISTDIR}/${P}-test.jar -d ${S}/${JAVA_TEST_SRC_DIR} || die"); } + + if (config.hasBinjarUri()) { + writer.println("use binary && cp ${DISTDIR}/${P}-bin.jar ${S}/${PN}.jar || die \"failed to copy binary jar\""); + } + writer.println("}"); } } 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 96e0c06..b918f51 100644 --- a/src/main/java/org/gentoo/java/ebuilder/portage/PortageParser.java +++ b/src/main/java/org/gentoo/java/ebuilder/portage/PortageParser.java @@ -302,8 +302,8 @@ public class PortageParser { } else if (line.startsWith("MAVEN_ID=")) { mavenId = line.substring("MAVEN_ID=".length()). replace("\"", ""); - } else if (line.startsWith("MAVEN_PROVIDE=")) { - mavenProvide = line.substring("MAVEN_PROVIDE=".length()). + } else if (line.startsWith("MAVEN_PROVIDES=")) { + mavenProvide = line.substring("MAVEN_PROVIDES=".length()). replace("\"", "").split(" "); } } |