xref: /trunk/main/solenv/inc/javaunittest.mk (revision efc1756a)
1#**************************************************************
2#
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing,
14#  software distributed under the License is distributed on an
15#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16#  KIND, either express or implied.  See the License for the
17#  specific language governing permissions and limitations
18#  under the License.
19#
20#**************************************************************
21
22
23
24# Makefile template for directories that contain Java unit tests.
25#
26# Before including this makefile, the following variables should be set:
27# - PRJ, PRJNAME, TARGET
28# - PACKAGE
29# - JAVATESTFILES: the unit test classes;
30#     each one of the form <basename>.java;
31#     these java files must only define classes within the package corresponding
32#     to PACKAGE, the name of each defined (outer) class should end with "_Test"
33# - JAVAFILES: optional java files, corresponding class files are generated
34#     that can be used when compiling or running the tests;
35#     each one of the form <basename>.java;
36#     these java files must only define classes within the package corresponding
37#     to PACKAGE, the name of each defined (outer) class should start with
38#     "Test"
39# - IDLTESTFILES: optional idl files, corresponding class files are generated
40#     that can be used when compiling or running the tests;
41#     each one of the form <basename>.idl;
42#     these idl files must only define entities within the module corresponding
43#     to PACKAGE, the name of each defined entity should start with "Test"
44# - JARFILES: optional jar files that can be used when compiling or running the
45#     tests;
46#     each one of the form <basename>.jar
47# All generated class files are placed into <platform>/class/test/ instead of
48# <platform>/class/, so that they are not accidentally included in jar files
49# packed from <platform>/class/ subdirectories.
50
51JAVAFILES +:= $(JAVATESTFILES)
52EXTRAJARFILES += $(OOO_JUNIT_JAR)
53.IF "$(HAMCREST_CORE_JAR)" != ""
54EXTRAJARFILES += $(HAMCREST_CORE_JAR)
55.END
56
57.INCLUDE: settings.mk
58
59.IF "$(XCLASSPATH)" == ""
60XCLASSPATH := $(CLASSDIR)
61.ELSE
62XCLASSPATH !:= $(XCLASSPATH)$(PATH_SEPERATOR)$(CLASSDIR)
63.ENDIF
64CLASSDIR !:= $(CLASSDIR)/test
65
66.INCLUDE: target.mk
67
68$(JAVATARGET) : $(MISC)/$(TARGET).classdir.flag
69
70$(MISC)/$(TARGET).classdir.flag:
71    - $(MKDIR) $(CLASSDIR)
72    $(TOUCH) $@
73
74.IF "$(JAVATESTFILES)" != ""
75ALLTAR : test
76.END
77
78.IF "$(SOLAR_JAVA)" == "TRUE" && "$(OOO_JUNIT_JAR)" != ""
79.IF "$(HAMCREST_CORE_JAR)" != ""
80test .PHONY : $(JAVATARGET)
81    $(JAVAI) $(JAVAIFLAGS) $(JAVACPS) \
82        '$(OOO_JUNIT_JAR)$(PATH_SEPERATOR)$(HAMCREST_CORE_JAR)$(PATH_SEPERATOR)$(CLASSPATH)' \
83        org.junit.runner.JUnitCore \
84        $(foreach,i,$(JAVATESTFILES) $(subst,/,. $(PACKAGE)).$(i:s/.java//))
85.ELSE
86test .PHONY : $(JAVATARGET)
87    $(JAVAI) $(JAVAIFLAGS) $(JAVACPS) \
88        '$(OOO_JUNIT_JAR)$(PATH_SEPERATOR)$(CLASSPATH)' \
89        org.junit.runner.JUnitCore \
90        $(foreach,i,$(JAVATESTFILES) $(subst,/,. $(PACKAGE)).$(i:s/.java//))
91.END
92.ELSE
93test .PHONY :
94    echo 'test needs SOLAR_JAVA=TRUE and OOO_JUNIT_JAR'
95.END
96
97.IF "$(IDLTESTFILES)" != ""
98
99# The following dependency (to execute javac whenever javamaker has run) does
100# not work reliably, see #i28827#:
101$(JAVAFILES) $(JAVACLASSFILES): $(MISC)/$(TARGET).javamaker.flag
102
103$(MISC)/$(TARGET).javamaker.flag: $(MISC)/$(TARGET).rdb
104    $(JAVAMAKER) -O$(CLASSDIR) -BUCR -nD $< -X$(SOLARBINDIR)/types.rdb
105    $(TOUCH) $@
106
107$(MISC)/$(TARGET).rdb .ERRREMOVE: \
108        $(foreach,i,$(IDLTESTFILES) $(subst,.idl,.urd $(MISC)/$(TARGET)/$i))
109    - rm $@
110    $(REGMERGE) $@ /UCR $<
111
112$(foreach,i,$(IDLTESTFILES) $(subst,.idl,.urd $(MISC)/$(TARGET)/$i)): \
113        $(IDLTESTFILES)
114    - $(MKDIR) $(MISC)/$(TARGET)
115    $(IDLC) -O$(MISC)/$(TARGET) -I$(SOLARIDLDIR) -cid -we $<
116
117.ENDIF
118