/[gentoo-x86]/eclass/java-pkg-simple.eclass
Gentoo

Contents of /eclass/java-pkg-simple.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (show annotations) (download)
Sun May 24 20:40:40 2015 UTC (3 years, 10 months ago) by chewi
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +1 -5 lines
Remove annoying java-pkg-simple build script check. Most people only
use java-pkg-simple as a last resort and a usable Maven eclass is
still some way off.

1 # Eclass for simple bare-source Java packages
2 #
3 # Copyright (c) 2004-2015, 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.5 2015/04/04 21:04:49 chewi 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 # @variable-external JAVA_JAR_FILENAME
91 # @variable-default ${PN}.jar
92 #
93 # The name of the jar file to create and install
94 # -----------------------------------------------------------------------------
95 : ${JAVA_JAR_FILENAME:=${PN}.jar}
96
97 # ------------------------------------------------------------------------------
98 # @eclass-src_compile
99 #
100 # src_compile for simple bare source java packages. Finds all *.java
101 # sources in ${JAVA_SRC_DIR}, compiles them with the classpath
102 # calculated from ${JAVA_GENTOO_CLASSPATH}, and packages the resulting
103 # classes to ${JAVA_JAR_FILENAME}.
104 #
105 # variables:
106 # JAVA_GENTOO_CLASSPATH - list java packages to put on the classpath.
107 # JAVA_ENCODING - encoding of source files, used by javac and javadoc
108 # JAVA_SRC_DIR - directories containing source files, relative to ${S}
109 # JAVAC_ARGS - additional arguments to be passed to javac
110 # JAVADOC_ARGS - additional arguments to be passed to javadoc
111 # ------------------------------------------------------------------------------
112 java-pkg-simple_src_compile() {
113 local sources=sources.lst classes=target/classes apidoc=target/api
114
115 # gather sources
116 find ${JAVA_SRC_DIR:-*} -name \*.java > ${sources}
117 mkdir -p ${classes} || die "Could not create target directory"
118
119 # compile
120 local classpath="${JAVA_CLASSPATH_EXTRA}" dependency
121 for dependency in ${JAVA_GENTOO_CLASSPATH}; do
122 classpath="${classpath}:$(java-pkg_getjars ${dependency})" \
123 || die "getjars failed for ${dependency}"
124 done
125 while [[ $classpath = *::* ]]; do classpath="${classpath//::/:}"; done
126 classpath=${classpath%:}
127 classpath=${classpath#:}
128 debug-print "CLASSPATH=${classpath}"
129 java-pkg-simple_verbose-cmd \
130 ejavac -d ${classes} -encoding ${JAVA_ENCODING} \
131 ${classpath:+-classpath ${classpath}} ${JAVAC_ARGS} \
132 @${sources}
133
134 # javadoc
135 if has doc ${JAVA_PKG_IUSE} && use doc; then
136 mkdir -p ${apidoc}
137 java-pkg-simple_verbose-cmd \
138 ejavadoc -d ${apidoc} \
139 -encoding ${JAVA_ENCODING} -docencoding UTF-8 -charset UTF-8 \
140 ${classpath:+-classpath ${classpath}} ${JAVADOC_ARGS:- -quiet} \
141 @${sources} || die "javadoc failed"
142 fi
143
144 # package
145 local jar_args="cf ${JAVA_JAR_FILENAME}"
146 if [[ -e ${classes}/META-INF/MANIFEST.MF ]]; then
147 jar_args="cfm ${JAVA_JAR_FILENAME} ${classes}/META-INF/MANIFEST.MF"
148 fi
149 java-pkg-simple_verbose-cmd \
150 jar ${jar_args} -C ${classes} . || die "jar failed"
151 }
152
153 # ------------------------------------------------------------------------------
154 # @eclass-src_install
155 #
156 # src_install for simple single jar java packages. Simply packages the
157 # contents from the target directory and installs it as
158 # ${JAVA_JAR_FILENAME}. If the file target/META-INF/MANIFEST.MF exists,
159 # it is used as the manifest of the created jar.
160 # ------------------------------------------------------------------------------
161 java-pkg-simple_src_install() {
162 local sources=sources.lst classes=target/classes apidoc=target/api
163
164 # main jar
165 java-pkg-simple_verbose-cmd \
166 java-pkg_dojar ${JAVA_JAR_FILENAME}
167
168 # javadoc
169 if has doc ${JAVA_PKG_IUSE} && use doc; then
170 java-pkg-simple_verbose-cmd \
171 java-pkg_dojavadoc ${apidoc}
172 fi
173
174 # dosrc
175 if has source ${JAVA_PKG_IUSE} && use source; then
176 local srcdirs=""
177 if [[ ${JAVA_SRC_DIR} ]]; then
178 local parent child
179 for parent in ${JAVA_SRC_DIR}; do
180 for child in ${parent}/*; do
181 srcdirs="${srcdirs} ${child}"
182 done
183 done
184 else
185 # take all directories actually containing any sources
186 srcdirs="$(cut -d/ -f1 ${sources} | sort -u)"
187 fi
188 java-pkg-simple_verbose-cmd \
189 java-pkg_dosrc ${srcdirs}
190 fi
191 }
192
193 # ------------------------------------------------------------------------------
194 # @internal-function java-pkg-simple_verbose-cmd
195 #
196 # Print a command before executing it. To give user some feedback
197 # about what is going on, where the time is being spent, and also to
198 # help debugging ebuilds.
199 #
200 # @param $@ - command to be called and its arguments
201 # ------------------------------------------------------------------------------
202 java-pkg-simple_verbose-cmd() {
203 echo "$*"
204 "$@"
205 }
206
207 # ------------------------------------------------------------------------------
208 # @eclass-end
209 # ------------------------------------------------------------------------------

  ViewVC Help
Powered by ViewVC 1.1.20