1#!/bin/sh
2#
3# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
4# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5#
6# This code is free software; you can redistribute it and/or modify it
7# under the terms of the GNU General Public License version 2 only, as
8# published by the Free Software Foundation.
9#
10# This code is distributed in the hope that it will be useful, but WITHOUT
11# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13# version 2 for more details (a copy is included in the LICENSE file that
14# accompanied this code).
15#
16# You should have received a copy of the GNU General Public License version
17# 2 along with this work; if not, write to the Free Software Foundation,
18# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19#
20# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21# or visit www.oracle.com if you need additional information or have any
22# questions.
23#
24
25# @test 
26# @bug 4212732 6485027
27# @summary Test handling of the Class-Path attribute in jar file manifests
28# @author Martin Buchholz
29#
30# @run shell Class-Path2.sh
31
32# To run this test manually, simply do ./Class-Path2.sh
33
34. ${TESTSRC-.}/Util.sh
35
36set -u
37
38Cleanup() {
39    Sys rm -rf pkg Main.java Main.class Main.jar jars
40    Sys rm -rf MANIFEST.MF A.jar B.zip
41}
42
43Cleanup
44Sys mkdir pkg
45
46#----------------------------------------------------------------
47# Create mutually referential jar files
48#----------------------------------------------------------------
49cat >pkg/A.java <<EOF
50package pkg;
51import pkg.B;
52public class A {
53    public static int f() { return B.g(); }
54    public static int g() { return 0; }
55}
56EOF
57
58cat >pkg/B.java <<EOF
59package pkg;
60import pkg.A;
61public class B {
62    public static int f() { return A.g(); }
63    public static int g() { return 0; }
64}
65EOF
66
67Sys "$javac" pkg/A.java pkg/B.java
68
69MkManifestWithClassPath "./sub/B.zip"
70Sys "$jar" cmf MANIFEST.MF A.jar pkg/A.class
71
72MkManifestWithClassPath "../A.jar"
73Sys "$jar" cmf MANIFEST.MF B.zip pkg/B.class
74
75cat >Main.java <<EOF
76import pkg.*;
77public class Main {
78    public static void main(String []a) { System.exit(A.f() + B.f()); }
79}
80EOF
81
82Sys rm -rf pkg
83
84Sys mkdir jars
85Sys mkdir jars/sub/
86Sys mv A.jar jars/.
87Sys mv B.zip jars/sub/.
88
89#
90# Test 1: Compiling 
91#
92
93Success "$javac" ${TESTTOOLVMOPTS} -cp "jars/A.jar" Main.java
94Success "$java"  ${TESTVMOPTS}     -cp "jars/A.jar${PS}." Main
95
96Success "$javac" ${TESTTOOLVMOPTS} -cp "jars/sub/B.zip"       Main.java
97Success "$java"  ${TESTVMOPTS}     -cp "jars/sub/B.zip${PS}." Main
98
99#
100# Test 2: Use of extension directories is incorrect
101#
102
103# Success "$javac" ${TESTTOOLVMOPTS} -extdirs jars          -cp None Main.java
104# Success "$java"  ${TESTVMOPTS}     -Djava.ext.dirs="jars" -cp .    Main
105
106# Success "$javac" ${TESTTOOLVMOPTS} -extdirs jars/sub          -cp None Main.java
107# Success "$java"  ${TESTVMOPTS}     -Djava.ext.dirs="jars/sub" -cp .    Main
108
109Cleanup
110
111Bottom Line
112