1 #! /bin/sh 2 3 # Copyright (c) 2009, 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 # @test Resources 25 26 set -e 27 SRC=${TESTSRC:-.} 28 BIN=${TESTJAVA:-../../../../build}/bin 29 30 sh ${TESTSRC:-.}/tester.sh $0 31 32 mk() { 33 mkdir -p `dirname $1` 34 echo "$2" >$1 35 } 36 37 mk z.test/modules/x/foo/x 'Hello!' 38 mk z.test/modules/x/inf/a 'A one,' 39 40 mk z.test/modules/y/bar/y 'Bonjour!' 41 mk z.test/modules/y/inf/a 'and a two,' 42 43 mk z.test/modules/z/baz/z 'Hola!' 44 mk z.test/modules/z/inf/a 'and a three!' 45 46 echo; echo "Direct install" 47 $BIN/jmod create -L z.lib 48 $BIN/jmod install -L z.lib z.test/modules empty 49 $BIN/jmod install -L z.lib z.test/modules z 50 $BIN/jmod install -L z.lib z.test/modules y 51 $BIN/jmod install -L z.lib z.test/modules x 52 $BIN/java -ea -esa -L z.lib -m x 53 54 echo; echo "Module-file install" 55 $BIN/jpkg -m z.test/modules/empty jmod empty 56 $BIN/jpkg -m z.test/modules/z jmod z 57 $BIN/jpkg -m z.test/modules/y jmod y 58 $BIN/jpkg -m z.test/modules/x jmod x 59 rm -rf z.lib 60 $BIN/jmod create -L z.lib 61 $BIN/jmod install -L z.lib x@1.jmod y@1.jmod z@1.jmod empty@1.jmod 62 $BIN/java -ea -esa -L z.lib -m x 63 64 exit 0 65 66 # -- Setup 67 68 : setup pass compile 69 70 module empty @ 1 { } 71 72 module x @ 1 { 73 requires y @ 1; 74 requires empty @ 1; 75 class x.X; 76 } 77 78 package x; 79 import java.io.*; 80 import java.net.*; 81 import java.util.*; 82 public class X { 83 private static void show(URL u, String ev) 84 throws IOException 85 { 86 InputStream in = u.openStream(); 87 byte[] buf = new byte[1024]; 88 int n = in.read(buf); 89 if (n <= 0 || in.read(buf) != -1) 90 throw new Error(); 91 System.out.write(buf, 0, n); 92 String v = new String(buf, 0, n, "US-ASCII"); 93 if (!v.trim().equals(ev)) 94 throw new AssertionError("Wrong value, expected " + ev); 95 } 96 private static void load(String rn, String ev) 97 throws IOException 98 { 99 ClassLoader cl = X.class.getClassLoader(); 100 URL u = cl.getResource(rn); 101 if (u == null) 102 throw new Error(rn + ": Not found"); 103 System.out.format("%s%n", u); 104 show(u, ev); 105 } 106 private static void loadAll(String rn, String ... evs) 107 throws IOException 108 { 109 ClassLoader cl = X.class.getClassLoader(); 110 List<URL> us = Collections.list(cl.getResources(rn)); 111 Collections.sort(us, new Comparator<URL>() { 112 public int compare(URL u, URL v) { 113 return u.toString().compareTo(v.toString()); 114 }}); 115 if (us.isEmpty()) 116 throw new Error(rn + ": Not found"); 117 System.out.format("%s%n", us); 118 int i = 0; 119 for (URL u : us) 120 show(u, evs[i++]); 121 } 122 public static void main(String[] args) throws Exception { 123 load("foo/x", "Hello!"); 124 load("/bar/y", "Bonjour!"); 125 load("/baz/z", "Hola!"); 126 loadAll("/inf/a", 127 "A one,", "and a two,", "and a three!"); 128 } 129 } 130 131 module y @ 1 { 132 requires z @ 1; 133 } 134 135 module z @ 1 { }