| 1 |
# Eclass for simple bare-source Java packages
|
| 2 |
#
|
| 3 |
# Copyright (c) 2004-2011, Gentoo Foundation
|
| 4 |
#
|
| 5 |
# Licensed under the GNU General Public License, v2
|
| 6 |
#
|
| 7 |
# $Header: /var/cvsroot/gentoo-x86/eclass/java-pkg-simple.eclass,v 1.2 2011/07/08 11:35:01 ssuominen Exp $
|
| 8 |
|
| 9 |
inherit java-utils-2
|
| 10 |
|
| 11 |
if ! has java-pkg-2 ${INHERITED}; then
|
| 12 |
eerror "java-pkg-simple eclass can only be inherited AFTER java-pkg-2"
|
| 13 |
fi
|
| 14 |
|
| 15 |
# -----------------------------------------------------------------------------
|
| 16 |
# @eclass-begin
|
| 17 |
# @eclass-summary Eclass for Java sources without build instructions
|
| 18 |
#
|
| 19 |
# This class is intended to build pure Java packages from Java sources
|
| 20 |
# without the use of any build instructions shipped with the sources.
|
| 21 |
# There is no support for resources besides the generated class files,
|
| 22 |
# or for generating source files, or for controlling the META-INF of
|
| 23 |
# the resulting jar, although these issues may be addressed by an
|
| 24 |
# ebuild by putting corresponding files into the target directory
|
| 25 |
# before calling the src_compile function of this eclass.
|
| 26 |
# -----------------------------------------------------------------------------
|
| 27 |
|
| 28 |
EXPORT_FUNCTIONS src_compile src_install
|
| 29 |
|
| 30 |
# We are only interested in finding all java source files, wherever they may be.
|
| 31 |
S="${WORKDIR}"
|
| 32 |
|
| 33 |
# -----------------------------------------------------------------------------
|
| 34 |
# @variable-external JAVA_GENTOO_CLASSPATH
|
| 35 |
# @variable-default ""
|
| 36 |
#
|
| 37 |
# Comma or space separated list of java packages to include in the
|
| 38 |
# class path. The packages will also be registered as runtime
|
| 39 |
# dependencies of this new package. Dependencies will be calculated
|
| 40 |
# transitively. See "java-config -l" for appropriate package names.
|
| 41 |
# -----------------------------------------------------------------------------
|
| 42 |
# JAVA_GENTOO_CLASSPATH
|
| 43 |
|
| 44 |
# -----------------------------------------------------------------------------
|
| 45 |
# @variable-external JAVA_CLASSPATH_EXTRA
|
| 46 |
# @variable-default ""
|
| 47 |
#
|
| 48 |
# Extra list of colon separated path elements to be put on the
|
| 49 |
# classpath when compiling sources.
|
| 50 |
# -----------------------------------------------------------------------------
|
| 51 |
# JAVA_CLASSPATH_EXTRA
|
| 52 |
|
| 53 |
# -----------------------------------------------------------------------------
|
| 54 |
# @variable-external JAVA_SRC_DIR
|
| 55 |
# @variable-default ""
|
| 56 |
#
|
| 57 |
# Directories relative to ${S} which contain the sources of the
|
| 58 |
# application. The default of "" will be treated mostly as ${S}
|
| 59 |
# itself. For the generated source package (if source is listed in
|
| 60 |
# ${JAVA_PKG_IUSE}), it is important that these directories are
|
| 61 |
# actually the roots of the corresponding source trees.
|
| 62 |
# -----------------------------------------------------------------------------
|
| 63 |
# JAVA_SRC_DIR
|
| 64 |
|
| 65 |
# -----------------------------------------------------------------------------
|
| 66 |
# @variable-external JAVA_ENCODING
|
| 67 |
# @variable-default UTF-8
|
| 68 |
#
|
| 69 |
# The character encoding used in the source files
|
| 70 |
# -----------------------------------------------------------------------------
|
| 71 |
: ${JAVA_ENCODING:=UTF-8}
|
| 72 |
|
| 73 |
# -----------------------------------------------------------------------------
|
| 74 |
# @variable-external JAVAC_ARGS
|
| 75 |
# @variable-default ""
|
| 76 |
#
|
| 77 |
# Additional arguments to be passed to javac
|
| 78 |
# -----------------------------------------------------------------------------
|
| 79 |
# JAVAC_ARGS
|
| 80 |
|
| 81 |
# -----------------------------------------------------------------------------
|
| 82 |
# @variable-external JAVADOC_ARGS
|
| 83 |
# @variable-default ""
|
| 84 |
#
|
| 85 |
# Additional arguments to be passed to javadoc
|
| 86 |
# -----------------------------------------------------------------------------
|
| 87 |
# JAVADOC_ARGS
|
| 88 |
|
| 89 |
# ------------------------------------------------------------------------------
|
| 90 |
# @eclass-src_compile
|
| 91 |
#
|
| 92 |
# src_compile for simple bare source java packages. Finds all *.java
|
| 93 |
# sources in ${JAVA_SRC_DIR}, compiles them with the classpath
|
| 94 |
# calculated from ${JAVA_GENTOO_CLASSPATH}, and packages the resulting
|
| 95 |
# classes to ${PN}.jar.
|
| 96 |
#
|
| 97 |
# variables:
|
| 98 |
# JAVA_GENTOO_CLASSPATH - list java packages to put on the classpath.
|
| 99 |
# JAVA_ENCODING - encoding of source files, used by javac and javadoc
|
| 100 |
# JAVA_SRC_DIR - directories containing source files, relative to ${S}
|
| 101 |
# JAVAC_ARGS - additional arguments to be passed to javac
|
| 102 |
# JAVADOC_ARGS - additional arguments to be passed to javadoc
|
| 103 |
# ------------------------------------------------------------------------------
|
| 104 |
java-pkg-simple_src_compile() {
|
| 105 |
local sources=sources.lst classes=target/classes apidoc=target/api
|
| 106 |
|
| 107 |
# QA checks
|
| 108 |
[[ "$(find . -name build.xml -o -name pom.xml)" ]] &&
|
| 109 |
java-pkg_announce-qa-violation "Package ships with a build file, use that instead of java-pkg-simple!"
|
| 110 |
|
| 111 |
# gather sources
|
| 112 |
find ${JAVA_SRC_DIR:-*} -name \*.java > ${sources}
|
| 113 |
mkdir -p ${classes} || die "Could not create target directory"
|
| 114 |
|
| 115 |
# compile
|
| 116 |
local classpath="${JAVA_CLASSPATH_EXTRA}" dependency
|
| 117 |
for dependency in ${JAVA_GENTOO_CLASSPATH}; do
|
| 118 |
classpath="${classpath}:$(java-pkg_getjars ${dependency})" \
|
| 119 |
|| die "getjars failed for ${dependency}"
|
| 120 |
done
|
| 121 |
while [[ $classpath = *::* ]]; do classpath="${classpath//::/:}"; done
|
| 122 |
classpath=${classpath%:}
|
| 123 |
classpath=${classpath#:}
|
| 124 |
debug-print "CLASSPATH=${classpath}"
|
| 125 |
java-pkg-simple_verbose-cmd \
|
| 126 |
ejavac -d ${classes} -encoding ${JAVA_ENCODING} \
|
| 127 |
${classpath:+-classpath ${classpath}} ${JAVAC_ARGS} \
|
| 128 |
@${sources}
|
| 129 |
|
| 130 |
# javadoc
|
| 131 |
if has doc ${JAVA_PKG_IUSE} && use doc; then
|
| 132 |
mkdir -p ${apidoc}
|
| 133 |
java-pkg-simple_verbose-cmd \
|
| 134 |
javadoc -d ${apidoc} \
|
| 135 |
-encoding ${JAVA_ENCODING} -docencoding UTF-8 -charset UTF-8 \
|
| 136 |
${classpath:+-classpath ${classpath}} ${JAVADOC_ARGS:- -quiet} \
|
| 137 |
@${sources} || die "javadoc failed"
|
| 138 |
fi
|
| 139 |
|
| 140 |
# package
|
| 141 |
local jar_args="cf ${PN}.jar"
|
| 142 |
if [[ -e ${classes}/META-INF/MANIFEST.MF ]]; then
|
| 143 |
jar_args="cfm ${PN}.jar ${classes}/META-INF/MANIFEST.MF"
|
| 144 |
fi
|
| 145 |
java-pkg-simple_verbose-cmd \
|
| 146 |
jar ${jar_args} -C ${classes} . || die "jar failed"
|
| 147 |
}
|
| 148 |
|
| 149 |
# ------------------------------------------------------------------------------
|
| 150 |
# @eclass-src_install
|
| 151 |
#
|
| 152 |
# src_install for simple single jar java packages. Simply packages the
|
| 153 |
# contents from the target directory and installs it as ${PN}.jar. If
|
| 154 |
# the file target/META-INF/MANIFEST.MF exists, it is used as the
|
| 155 |
# manifest of the created jar.
|
| 156 |
# ------------------------------------------------------------------------------
|
| 157 |
java-pkg-simple_src_install() {
|
| 158 |
local sources=sources.lst classes=target/classes apidoc=target/api
|
| 159 |
|
| 160 |
# main jar
|
| 161 |
java-pkg-simple_verbose-cmd \
|
| 162 |
java-pkg_dojar ${PN}.jar
|
| 163 |
|
| 164 |
# javadoc
|
| 165 |
if has doc ${JAVA_PKG_IUSE} && use doc; then
|
| 166 |
java-pkg-simple_verbose-cmd \
|
| 167 |
java-pkg_dojavadoc ${apidoc}
|
| 168 |
fi
|
| 169 |
|
| 170 |
# dosrc
|
| 171 |
if has source ${JAVA_PKG_IUSE} && use source; then
|
| 172 |
local srcdirs=""
|
| 173 |
if [[ ${JAVA_SRC_DIR} ]]; then
|
| 174 |
local parent child
|
| 175 |
for parent in ${JAVA_SRC_DIR}; do
|
| 176 |
for child in ${parent}/*; do
|
| 177 |
srcdirs="${srcdirs} ${child}"
|
| 178 |
done
|
| 179 |
done
|
| 180 |
else
|
| 181 |
# take all directories actually containing any sources
|
| 182 |
srcdirs="$(cut -d/ -f1 ${sources} | sort -u)"
|
| 183 |
fi
|
| 184 |
java-pkg-simple_verbose-cmd \
|
| 185 |
java-pkg_dosrc ${srcdirs}
|
| 186 |
fi
|
| 187 |
}
|
| 188 |
|
| 189 |
# ------------------------------------------------------------------------------
|
| 190 |
# @internal-function java-pkg-simple_verbose-cmd
|
| 191 |
#
|
| 192 |
# Print a command before executing it. To give user some feedback
|
| 193 |
# about what is going on, where the time is being spent, and also to
|
| 194 |
# help debugging ebuilds.
|
| 195 |
#
|
| 196 |
# @param $@ - command to be called and its arguments
|
| 197 |
# ------------------------------------------------------------------------------
|
| 198 |
java-pkg-simple_verbose-cmd() {
|
| 199 |
echo "$*"
|
| 200 |
"$@"
|
| 201 |
}
|
| 202 |
|
| 203 |
# ------------------------------------------------------------------------------
|
| 204 |
# @eclass-end
|
| 205 |
# ------------------------------------------------------------------------------
|