diff options
author | 2020-07-29 14:13:04 +0800 | |
---|---|---|
committer | 2020-07-29 14:19:25 +0800 | |
commit | 970308e5d845b5da6818131c75f84c38691691c6 (patch) | |
tree | 9287ed6d0ce5acd01861f91429e1c3343cf82603 | |
parent | replace "\t" with spaces, enable test if --binjar-uri is set (diff) | |
download | java-ebuilder-970308e5d845b5da6818131c75f84c38691691c6.tar.gz java-ebuilder-970308e5d845b5da6818131c75f84c38691691c6.tar.bz2 java-ebuilder-970308e5d845b5da6818131c75f84c38691691c6.zip |
write src_unpack everytime is not elegant, use java-pkg-maven to handle it
Signed-off-by: zongyu <zzy2529420793@gmail.com>
-rw-r--r-- | maven/eclass/java-pkg-maven.eclass | 60 | ||||
-rw-r--r-- | src/main/java/org/gentoo/java/ebuilder/maven/MavenEbuilder.java | 41 |
2 files changed, 67 insertions, 34 deletions
diff --git a/maven/eclass/java-pkg-maven.eclass b/maven/eclass/java-pkg-maven.eclass new file mode 100644 index 0000000..d926cc3 --- /dev/null +++ b/maven/eclass/java-pkg-maven.eclass @@ -0,0 +1,60 @@ +# Copyright 2004-2020 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id$ + +# @ECLASS: java-pkg-binjar.eclass +# @MAINTAINER: +# zzy2529420793@gmail.com +# @AUTHOR: +# Zhang Zongyu +# @BLURB: Eclass for unpacking Maven aritfacts +# @DESCRIPTION: +# This class is an attempt to unpack Maven artifacts properly. + +EXPORT_FUNCTIONS src_unpack + +# @ECLASS-VARIABLE: JAVA_SOURCE_FILENAME +# @DESCRIPTION: +# The filename of the source code. +: ${JAVA_SOURCE_FILENAME:=${P}-sources.jar} + +# @ECLASS-VARIABLE: JAVA_TEST_SOURCE_FILENAME +# @DESCRIPTION: +# The filename of the source code for launch testing. +: ${JAVA_TEST_SOURCE_FILENAME:=${P}-test-sources.jar} + +# @ECLASS-VARIABLE: JAVA_RESOURCE_DIRS +# @DEFAULT_UNSET +# @DESCRIPTION: +# A directory relative to ${S} which contain the resources of the +# application. Give it a default value to handle src_unpack. +: ${JAVA_RESOURCE_DIRS:=src/main/resources} + +# @FUNCTION: java-pkg-binjar_src_unpack +# @DESCRIPTION: +# Copy the binary jar into the expected place of java-pkg-simple. Do +# not extract files from archive. +java-pkg-maven_src_unpack() { + for file in ${A}; do + case ${file} in + ${JAVA_BINJAR_FILENAME}) ;; + ${JAVA_SOURCE_FILENAME}) + mkdir -p "${S}"/${JAVA_SRC_DIR}\ + || die "Could not create ${JAVA_SRC_DIR}" + unzip -q -o "${DISTDIR}"/${file} -d "${S}"/${JAVA_SRC_DIR}\ + || die "Could not unzip source code" ;; + ${JAVA_TEST_SOURCE_FILENAME}) + mkdir -p "${S}"/${JAVA_TEST_SRC_DIR}\ + || die "Could not create ${JAVA_TEST_SRC_DIR}" + unzip -q -o "${DISTDIR}"/${file} -d "${S}"/${JAVA_TEST_SRC_DIR}\ + || die "Could not unzip source code for testing" ;; + esac + done + + # the resources (maven resources are bundled inside source file) + cp "${S}"/${JAVA_SRC_DIR} "${S}"/${JAVA_RESOURCE_DIRS} -r || die + rm "${S}"/${JAVA_RESOURCE_DIRS}/META-INF -r || die + find "${S}"/${JAVA_RESOURCE_DIRS} -type f ! -name \*.properties \ + -exec rm {} \; || die +} + 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 3f74241..37d45a4 100644 --- a/src/main/java/org/gentoo/java/ebuilder/maven/MavenEbuilder.java +++ b/src/main/java/org/gentoo/java/ebuilder/maven/MavenEbuilder.java @@ -624,7 +624,13 @@ public class MavenEbuilder { writer.println('"'); writer.println(); - writer.println("inherit java-pkg-2 java-pkg-simple"); + writer.print("inherit java-pkg-2 java-pkg-simple"); + + if (config.isFromMavenCentral()) { + writer.print(" java-pkg-maven"); + } + + writer.println(""); } /** @@ -849,11 +855,6 @@ public class MavenEbuilder { writer.println(')'); } } - - if (config.isFromMavenCentral()) { - writeMavenUnpack(mavenProject, writer); - } - } /** @@ -865,32 +866,4 @@ 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}-sources.jar" + - " -d \"${S}\"/${JAVA_SRC_DIR} || die"); - - /** - * unzip ${P}-test-sources.jar, uncomment it after the switch - * --test-source-uri is supported - if (mavenProject.hasTests()) { - writer.println("\tmkdir -p \"${S}\"/${JAVA_TEST_SRC_DIR}"); - writer.println( - "\tunzip \"${DISTDIR}\"/${P}-test-sources.jar" + - " -d \"${S}\"/${JAVA_TEST_SRC_DIR} || die"); - } - */ - - writer.println("}"); - } } |