2
# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
3
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
# This code is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License version 2 only, as
7
# published by the Free Software Foundation.
9
# This code is distributed in the hope that it will be useful, but WITHOUT
10
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
# version 2 for more details (a copy is included in the LICENSE file that
13
# accompanied this code).
15
# You should have received a copy of the GNU General Public License version
16
# 2 along with this work; if not, write to the Free Software Foundation,
17
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
# or visit www.oracle.com if you need additional information or have any
29
include JavaCompilation.gmk
30
include UtilsForTests.gmk
32
THIS_FILE := $(TOPDIR)/test/make/TestJavaCompilation.gmk
34
$(TOPDIR)/make/common/MakeBase.gmk \
35
$(TOPDIR)/make/common/JavaCompilation.gmk \
38
OUTPUT_DIR := $(TESTMAKE_OUTPUTDIR)/java-compilation
40
################################################################################
42
# Creates a simple jar file and unzips it to verify that the files have not
45
JAR1_SRC_ROOT := $(OUTPUT_DIR)/jar1src
46
JAR1_UNZIP := $(OUTPUT_DIR)/jar1unzip
47
JAR1_FILE := $(OUTPUT_DIR)/jar1.jar
48
JAR1_MANIFEST := $(OUTPUT_DIR)/jar1_manifest
51
$(RM) -r $(OUTPUT_DIR)/_jar1* $(OUTPUT_DIR)/jar1*
53
$(JAR1_MANIFEST): | $(OUTPUT_DIR)/_jar1_created
54
$(ECHO) "Test-Attribute: value" > $(JAR1_MANIFEST)
56
$(OUTPUT_DIR)/_jar1_created: $(DEPS)
57
$(RM) -r $(JAR1_SRC_ROOT)
59
$(RM) -r $(JAR1_UNZIP)
60
$(MKDIR) -p $(JAR1_SRC_ROOT)
61
$(MKDIR) -p $(JAR1_SRC_ROOT)/dir1
62
$(MKDIR) -p $(JAR1_SRC_ROOT)/dir2
63
$(MKDIR) -p $(JAR1_SRC_ROOT)/META-INF
64
$(TOUCH) $(JAR1_SRC_ROOT)/dir1/file1.class
65
$(TOUCH) $(JAR1_SRC_ROOT)/dir2/file2.class
66
$(TOUCH) $(JAR1_SRC_ROOT)/META-INF/metafile
69
$(eval $(call SetupJarArchive, BUILD_JAR1, \
70
DEPENDENCIES := $(OUTPUT_DIR)/_jar1_created, \
71
SRCS := $(JAR1_SRC_ROOT), \
72
MANIFEST := $(JAR1_MANIFEST), \
73
JAR := $(JAR1_FILE), \
76
$(OUTPUT_DIR)/_jar1_verified: $(BUILD_JAR1)
77
$(RM) -r $(JAR1_UNZIP)
78
$(MKDIR) -p $(JAR1_UNZIP)
79
$(CD) $(JAR1_UNZIP) && $(UNZIP) $(JAR1_FILE) $(LOG_DEBUG)
80
$(DIFF) -r $(JAR1_SRC_ROOT)/dir1 $(JAR1_UNZIP)/dir1
81
$(DIFF) -r $(JAR1_SRC_ROOT)/dir2 $(JAR1_UNZIP)/dir2
82
$(DIFF) -r $(JAR1_SRC_ROOT)/META-INF/metafile $(JAR1_UNZIP)/META-INF/metafile
83
if [ "`$(GREP) 'Test-Attribute: value' $(JAR1_UNZIP)/META-INF/MANIFEST.MF`" = "" ]; then \
84
$(ECHO) "Could not find Test-Attribute in manifest of $(JAR1_FILE)"; \
89
create-jar2: $(OUTPUT_DIR)/_jar1_verified
90
TEST_TARGETS += $(OUTPUT_DIR)/_jar1_verified
92
# Change a source file and call this makefile again to force the jar to be
94
$(OUTPUT_DIR)/_jar1_updated: $(OUTPUT_DIR)/_jar1_verified
95
$(ECHO) updated > $(JAR1_SRC_ROOT)/dir1/file1.class
96
$(ECHO) updated > $(JAR1_SRC_ROOT)/META-INF/metafile
97
$(TOUCH) $(OUTPUT_DIR)/_jar1_created
98
+$(MAKE) -f $(THIS_FILE) $(OUTPUT_DIR)/_jar1_verified
101
update-jar1: $(OUTPUT_DIR)_jar1_updated
103
# Change the manifest file and call this makefile again to force the jar
105
$(OUTPUT_DIR)/_jar1_updated_manifest: $(OUTPUT_DIR)/_jar1_updated
107
$(ECHO) "Test-Attribute: foobar" > $(JAR1_MANIFEST)
108
+$(MAKE) -f $(THIS_FILE) $(BUILD_JAR1)
109
$(RM) -r $(JAR1_UNZIP)
110
$(MKDIR) -p $(JAR1_UNZIP)
111
$(CD) $(JAR1_UNZIP) && $(UNZIP) $(JAR1_FILE) $(LOG_DEBUG)
112
if [ "`$(GREP) 'Test-Attribute: foobar' $(JAR1_UNZIP)/META-INF/MANIFEST.MF`" = "" ]; then \
113
$(ECHO) "Could not find Test-Attribute in manifest of $(JAR1_FILE)"; \
118
update-jar1-manifest: $(OUTPUT_DIR)/_jar1_updated_manifest
120
TEST_TARGETS += $(OUTPUT_DIR)/_jar1_updated $(OUTPUT_DIR)/_jar1_updated_manifest
122
.PHONY: clean-jar1 create-jar1 update-jar1 update-jar1-manifest
124
################################################################################
126
# Creates a jar file based on 2 source roots
128
JAR2_SRC_ROOT1 := $(OUTPUT_DIR)/jar2src1
129
JAR2_SRC_ROOT2 := $(OUTPUT_DIR)/jar2src2
130
JAR2_UNZIP := $(OUTPUT_DIR)/jar2unzip
131
JAR2_FILE := $(OUTPUT_DIR)/jar2.jar
134
$(RM) -r $(OUTPUT_DIR)/_jar2* $(OUTPUT_DIR)/jar2*
136
$(OUTPUT_DIR)/_jar2_created: $(DEPS)
137
$(RM) -r $(JAR2_SRC_ROOT1)
138
$(RM) -r $(JAR2_SRC_ROOT2)
140
$(RM) -r $(JAR2_UNZIP)
141
$(MKDIR) -p $(JAR2_SRC_ROOT1)/dir1
142
$(MKDIR) -p $(JAR2_SRC_ROOT2)/dir2
143
$(TOUCH) $(JAR2_SRC_ROOT1)/dir1/file1.class
144
$(TOUCH) $(JAR2_SRC_ROOT2)/dir2/file2.class
147
$(eval $(call SetupJarArchive, BUILD_JAR2, \
148
DEPENDENCIES := $(OUTPUT_DIR)/_jar2_created, \
149
SRCS := $(JAR2_SRC_ROOT1) $(JAR2_SRC_ROOT2), \
150
JAR := $(JAR2_FILE), \
153
$(OUTPUT_DIR)/_jar2_verified: $(BUILD_JAR2)
154
$(RM) -r $(JAR2_UNZIP)
155
$(MKDIR) -p $(JAR2_UNZIP)
156
$(CD) $(JAR2_UNZIP) && $(UNZIP) $(JAR2_FILE) $(LOG_DEBUG)
157
$(DIFF) -r $(JAR2_SRC_ROOT1)/dir1 $(JAR2_UNZIP)/dir1
158
$(DIFF) -r $(JAR2_SRC_ROOT2)/dir2 $(JAR2_UNZIP)/dir2
161
create-jar2: $(OUTPUT_DIR)/_jar2_verified
162
TEST_TARGETS += $(OUTPUT_DIR)/_jar2_verified
164
$(OUTPUT_DIR)/_jar2_updated: $(OUTPUT_DIR)/_jar2_verified
165
$(ECHO) updated > $(JAR2_SRC_ROOT1)/dir1/file1.class
166
$(TOUCH) $(OUTPUT_DIR)/_jar2_created
167
+$(MAKE) -f $(THIS_FILE) $(OUTPUT_DIR)/_jar2_verified
170
update-jar2: $(OUTPUT_DIR)/_jar2_updated
171
TEST_TARGETS += $(OUTPUT_DIR)/_jar2_updated
173
.PHONY: clean-jar2 create-jar2 update-jar2
175
################################################################################
177
# Creates a jar file based on 2 source roots with an extra file
179
JAR3_SRC_ROOT1 := $(OUTPUT_DIR)/jar3src1
180
JAR3_SRC_ROOT2 := $(OUTPUT_DIR)/jar3src2
181
JAR3_UNZIP := $(OUTPUT_DIR)/jar3unzip
182
JAR3_FILE := $(OUTPUT_DIR)/jar3.jar
185
$(RM) -r $(OUTPUT_DIR)/_jar3* $(OUTPUT_DIR)/jar3*
187
$(OUTPUT_DIR)/_jar3_created: $(DEPS)
188
$(RM) -r $(JAR3_SRC_ROOT1)
189
$(RM) -r $(JAR3_SRC_ROOT2)
191
$(RM) -r $(JAR3_UNZIP)
192
$(MKDIR) -p $(JAR3_SRC_ROOT1)/dir1
193
$(MKDIR) -p $(JAR3_SRC_ROOT2)/dir2
194
$(TOUCH) $(JAR3_SRC_ROOT1)/dir1/file1\$$foo.class
195
$(TOUCH) $(JAR3_SRC_ROOT2)/dir2/file2.class
196
$(TOUCH) $(JAR3_SRC_ROOT2)/extra-file
197
$(TOUCH) $(JAR3_SRC_ROOT2)/extra-file-abs
198
$(TOUCH) $(JAR3_SRC_ROOT2)/dir2/file\$$foo.dollar
201
$(eval $(call SetupJarArchive, BUILD_JAR3, \
202
DEPENDENCIES := $(OUTPUT_DIR)/_jar3_created, \
203
SRCS := $(JAR3_SRC_ROOT1) $(JAR3_SRC_ROOT2), \
204
EXTRA_FILES := extra-file \
205
dir2/file$$foo.dollar \
206
$(JAR3_SRC_ROOT2)/extra-file-abs, \
207
EXCLUDE_FILES := dir1/file1$$foo.class, \
208
JAR := $(JAR3_FILE), \
211
$(OUTPUT_DIR)/_jar3_verified: $(BUILD_JAR3)
212
$(RM) -r $(JAR3_UNZIP)
213
$(MKDIR) -p $(JAR3_UNZIP)
214
$(CD) $(JAR3_UNZIP) && $(UNZIP) $(JAR3_FILE) $(LOG_DEBUG)
215
if [ -d "$(JAR3_UNZIP)/dir1" ]; then \
216
echo Should not be included $(JAR3_UNZIP)/dir1; \
219
$(DIFF) -r $(JAR3_SRC_ROOT2)/dir2 $(JAR3_UNZIP)/dir2
220
$(DIFF) -r $(JAR3_SRC_ROOT2)/extra-file $(JAR3_UNZIP)/extra-file
223
create-jar3: $(OUTPUT_DIR)/_jar3_verified
224
TEST_TARGETS += $(OUTPUT_DIR)/_jar3_verified
226
$(OUTPUT_DIR)/_jar3_updated: $(OUTPUT_DIR)/_jar3_verified
227
$(ECHO) updated > $(JAR3_SRC_ROOT2)/extra-file
228
$(TOUCH) $(OUTPUT_DIR)/_jar3_created
229
+$(MAKE) -f $(THIS_FILE) $(OUTPUT_DIR)/_jar3_verified
232
update-jar3: $(OUTPUT_DIR)/_jar3_updated
233
TEST_TARGETS += $(OUTPUT_DIR)/_jar3_updated
235
.PHONY: clean-jar3 create-jar3 update-jar3
237
################################################################################
238
# Test SetupJavaCompilation overrides of java files
240
JAVA_SRC_ROOT1 := $(OUTPUT_DIR)/javaroot1
241
JAVA_SRC_ROOT2 := $(OUTPUT_DIR)/javaroot2
243
# Since this makefile calls itself a number of times, protect this macro from
244
# being executed more than once.
246
# Param 2 - Package name
247
# Param 3 - Class name
250
$(if $(wildcard $1),,$(shell \
251
$(MKDIR) -p $(dir $1); \
252
$(ECHO) "package $2;" > $1; \
253
$(ECHO) "public class $3 {" >> $1; \
254
$(ECHO) " public static void main(String[] args) {" >> $1; \
255
$(ECHO) " System.out.print(\"$4\");" >> $1; \
256
$(ECHO) " }" >> $1; \
260
# Since this makefile calls itself a number of times, protect this macro from
261
# being executed more than once.
265
$(if $(wildcard $1),,$(shell \
266
$(MKDIR) -p $(dir $1); \
267
$(PRINTF) '$2' > $1; \
270
$(call CreateJavaSrc,$(JAVA_SRC_ROOT1)/a/A.java,a,A,javaroot1)
271
$(call CreateJavaSrc,$(JAVA_SRC_ROOT2)/a/A.java,a,A,javaroot2)
272
$(call CreateTextFile,$(JAVA_SRC_ROOT1)/a/b.txt,javaroot1\n)
273
$(call CreateTextFile,$(JAVA_SRC_ROOT2)/a/b.txt,javaroot2\n)
274
$(call CreateTextFile,$(JAVA_SRC_ROOT1)/a/c.properties,#javaroot1\nname=value1\n)
275
$(call CreateTextFile,$(JAVA_SRC_ROOT2)/a/c.properties,#javaroot2\nname=value2\n)
277
# Due to a bug in gnu make 3.81, need to add the src roots with trailing slash,
278
# otherwise $(wildcard ) will not find the directories and the sanity check in
279
# SetupJavaCompilation will fail.
280
$(eval $(call SetupJavaCompilation, BUILD_ROOT1_FIRST, \
281
TARGET_RELEASE := $(TARGET_RELEASE_BOOTJDK), \
282
SRC := $(JAVA_SRC_ROOT1)/ $(JAVA_SRC_ROOT2)/, \
283
COPY := .txt .java, \
284
CLEAN := .properties, \
285
BIN := $(OUTPUT_DIR)/root1first/, \
290
verify-root1-first: $(BUILD_ROOT1_FIRST)
291
$(JAVA_SMALL) -cp $(OUTPUT_DIR)/root1first a.A > $(OUTPUT_DIR)/root1first.output
292
if [ "`$(CAT) $(OUTPUT_DIR)/root1first.output`" != "javaroot1" ]; then \
293
$(ECHO) "The wrong class was compiled. Expected >javaroot1<"; \
294
$(ECHO) "Got >`$(CAT) $(OUTPUT_DIR)/root1first.output`<"; \
297
if [ "`$(CAT) $(OUTPUT_DIR)/root1first/a/b.txt`" != "javaroot1" ]; then \
298
$(ECHO) "The wrong file was copied. Expected >javaroot1<"; \
299
$(ECHO) "Got >`$(CAT) $(OUTPUT_DIR)/root1first/a/b.txt`<"; \
302
if [ ! -e "$(OUTPUT_DIR)/root1first/a/A.java" ]; then \
303
$(ECHO) "Missed copying $(OUTPUT_DIR)/root1first/a/A.java"; \
306
if [ "`$(CAT) $(OUTPUT_DIR)/root1first/a/c.properties`" != "name=value1" ]; then \
307
$(ECHO) "The wrong file was cleaned. Expected >name=value1<"; \
308
$(ECHO) "Got >`$(CAT) $(OUTPUT_DIR)/root1first/a/c.properties`<"; \
312
$(eval $(call SetupJavaCompilation, BUILD_ROOT2_FIRST, \
313
TARGET_RELEASE := $(TARGET_RELEASE_BOOTJDK), \
314
SRC := $(JAVA_SRC_ROOT2)/ $(JAVA_SRC_ROOT1)/, \
316
CLEAN := .properties, \
317
BIN := $(OUTPUT_DIR)/root2first/, \
322
verify-root2-first: $(BUILD_ROOT2_FIRST)
323
$(JAVA_SMALL) -cp $(OUTPUT_DIR)/root2first a.A > $(OUTPUT_DIR)/root2first.output
324
if [ "`$(CAT) $(OUTPUT_DIR)/root2first.output`" != "javaroot2" ]; then \
325
$(ECHO) "The wrong class was compiled. Expected >javaroot2<"; \
326
$(ECHO) "Got >`$(CAT) $(OUTPUT_DIR)/root2first.output`<"; \
329
if [ "`$(CAT) $(OUTPUT_DIR)/root2first/a/b.txt`" != "javaroot2" ]; then \
330
$(ECHO) "The wrong file was cleaned. Expected >javaroot2<"; \
331
$(ECHO) "Got >`$(CAT) $(OUTPUT_DIR)/root2first/a/b.txt`<"; \
334
if [ "`$(CAT) $(OUTPUT_DIR)/root2first/a/c.properties`" != "name=value2" ]; then \
335
$(ECHO) "The wrong file was cleaned. Expected >name=value2<"; \
336
$(ECHO) "Got >`$(CAT) $(OUTPUT_DIR)/root2first/a/c.properties`<"; \
340
TEST_TARGETS += verify-root1-first verify-root2-first
342
.PHONY: verify-root1-first verify-root2-first
344
################################################################################