x11-terms/mlterm: Fix typo in metadata.xml
[gentoo.git] / eclass / java-pkg-simple.eclass
1 # Copyright 2004-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: java-pkg-simple.eclass
5 # @MAINTAINER:
6 # java@gentoo.org
7 # @AUTHOR:
8 # Java maintainers (java@gentoo.org)
9 # @BLURB: Eclass for packaging Java software with ease.
10 # @DESCRIPTION:
11 # This class is intended to build pure Java packages from Java sources
12 # without the use of any build instructions shipped with the sources.
13 # There is no support for resources besides the generated class files,
14 # or for generating source files, or for controlling the META-INF of
15 # the resulting jar, although these issues may be addressed by an
16 # ebuild by putting corresponding files into the target directory
17 # before calling the src_compile function of this eclass.
18
19 inherit java-utils-2
20
21 if ! has java-pkg-2 ${INHERITED}; then
22         eerror "java-pkg-simple eclass can only be inherited AFTER java-pkg-2"
23 fi
24
25 EXPORT_FUNCTIONS src_compile src_install
26
27 # We are only interested in finding all java source files, wherever they may be.
28 S="${WORKDIR}"
29
30 # @ECLASS-VARIABLE: JAVA_GENTOO_CLASSPATH
31 # @DEFAULT_UNSET
32 # @DESCRIPTION:
33 # Comma or space separated list of java packages to include in the
34 # class path. The packages will also be registered as runtime
35 # dependencies of this new package. Dependencies will be calculated
36 # transitively. See "java-config -l" for appropriate package names.
37 #
38 # @CODE
39 #       JAVA_GENTOO_CLASSPATH="foo,bar-2"
40 # @CODE
41
42 # @ECLASS-VARIABLE: JAVA_GENTOO_CLASSPATH_EXTRA
43 # @DEFAULT_UNSET
44 # @DESCRIPTION:
45 # Extra list of colon separated path elements to be put on the
46 # classpath when compiling sources.
47
48 # @ECLASS-VARIABLE: JAVA_SRC_DIR
49 # @DEFAULT_UNSET
50 # @DESCRIPTION:
51 # Directories relative to ${S} which contain the sources of the
52 # application. The default of "" will be treated mostly as ${S}
53 # itself. For the generated source package (if source is listed in
54 # ${JAVA_PKG_IUSE}), it is important that these directories are
55 # actually the roots of the corresponding source trees.
56 #
57 # @CODE
58 #       JAVA_SRC_DIR="src/java/org/gentoo"
59 # @CODE
60
61 # @ECLASS-VARIABLE: JAVA_ENCODING
62 # @DESCRIPTION:
63 # The character encoding used in the source files.
64 : ${JAVA_ENCODING:=UTF-8}
65
66 # @ECLASS-VARIABLE: JAVAC_ARGS
67 # @DEFAULT_UNSET
68 # @DESCRIPTION:
69 # Additional arguments to be passed to javac.
70
71 # @ECLASS-VARIABLE: JAVADOC_ARGS
72 # @DEFAULT_UNSET
73 # @DESCRIPTION:
74 # Additional arguments to be passed to javadoc.
75
76 # @ECLASS-VARIABLE: JAVA_JAR_FILENAME
77 # @DESCRIPTION:
78 # The name of the jar file to create and install.
79 : ${JAVA_JAR_FILENAME:=${PN}.jar}
80
81 # @FUNCTION: java-pkg-simple_src_compile
82 # @DESCRIPTION:
83 # src_compile for simple bare source java packages. Finds all *.java
84 # sources in ${JAVA_SRC_DIR}, compiles them with the classpath
85 # calculated from ${JAVA_GENTOO_CLASSPATH}, and packages the resulting
86 # classes to ${JAVA_JAR_FILENAME}.
87 java-pkg-simple_src_compile() {
88         local sources=sources.lst classes=target/classes apidoc=target/api
89
90         # auto generate classpath
91         java-pkg_gen-cp JAVA_GENTOO_CLASSPATH
92
93         # gather sources
94         find ${JAVA_SRC_DIR:-*} -name \*.java > ${sources}
95         mkdir -p ${classes} || die "Could not create target directory"
96
97         # compile
98         local classpath="${JAVA_GENTOO_CLASSPATH_EXTRA}" dependency
99         for dependency in ${JAVA_GENTOO_CLASSPATH}; do
100                 classpath="${classpath}:$(java-pkg_getjars ${dependency})" \
101                         || die "getjars failed for ${dependency}"
102         done
103         while [[ $classpath = *::* ]]; do classpath="${classpath//::/:}"; done
104         classpath=${classpath%:}
105         classpath=${classpath#:}
106         debug-print "CLASSPATH=${classpath}"
107         ejavac -d ${classes} -encoding ${JAVA_ENCODING} \
108                 ${classpath:+-classpath ${classpath}} ${JAVAC_ARGS} \
109                 @${sources}
110
111         # javadoc
112         if has doc ${JAVA_PKG_IUSE} && use doc; then
113                 mkdir -p ${apidoc}
114                 ejavadoc -d ${apidoc} \
115                         -encoding ${JAVA_ENCODING} -docencoding UTF-8 -charset UTF-8 \
116                         ${classpath:+-classpath ${classpath}} ${JAVADOC_ARGS:- -quiet} \
117                         @${sources} || die "javadoc failed"
118         fi
119
120         # package
121         local jar_args="cf ${JAVA_JAR_FILENAME}"
122         if [[ -e ${classes}/META-INF/MANIFEST.MF ]]; then
123                 jar_args="cfm ${JAVA_JAR_FILENAME} ${classes}/META-INF/MANIFEST.MF"
124         fi
125         jar ${jar_args} -C ${classes} . || die "jar failed"
126 }
127
128 # @FUNCTION: java-pkg-simple_src_install
129 # @DESCRIPTION:
130 # src_install for simple single jar java packages. Simply packages the
131 # contents from the target directory and installs it as
132 # ${JAVA_JAR_FILENAME}. If the file target/META-INF/MANIFEST.MF exists,
133 # it is used as the manifest of the created jar.
134 java-pkg-simple_src_install() {
135         local sources=sources.lst classes=target/classes apidoc=target/api
136
137         # main jar
138         java-pkg_dojar ${JAVA_JAR_FILENAME}
139
140         # javadoc
141         if has doc ${JAVA_PKG_IUSE} && use doc; then
142                 java-pkg_dojavadoc ${apidoc}
143         fi
144
145         # dosrc
146         if has source ${JAVA_PKG_IUSE} && use source; then
147                 local srcdirs=""
148                 if [[ ${JAVA_SRC_DIR} ]]; then
149                         local parent child
150                         for parent in ${JAVA_SRC_DIR}; do
151                                 for child in ${parent}/*; do
152                                         srcdirs="${srcdirs} ${child}"
153                                 done
154                         done
155                 else
156                         # take all directories actually containing any sources
157                         srcdirs="$(cut -d/ -f1 ${sources} | sort -u)"
158                 fi
159                 java-pkg_dosrc ${srcdirs}
160         fi
161 }