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 z
  49 $BIN/jmod install -L z.lib z.test/modules y
  50 $BIN/jmod install -L z.lib z.test/modules x
  51 $BIN/java -ea -L z.lib -m x
  52 
  53 echo; echo "Module-file install"

  54 $BIN/jpkg -m z.test/modules/z jmod z
  55 $BIN/jpkg -m z.test/modules/y jmod y
  56 $BIN/jpkg -m z.test/modules/x jmod x
  57 rm -rf z.lib
  58 $BIN/jmod create -L z.lib
  59 $BIN/jmod install -L z.lib x@1.jmod y@1.jmod z@1.jmod
  60 $BIN/java -ea -L z.lib -m x
  61 
  62 exit 0
  63 
  64 # -- Setup
  65 
  66 : setup pass compile
  67 


  68 module x @ 1 {
  69   requires y @ 1;

  70   class x.X;
  71 }
  72 
  73 package x;
  74 import java.io.*;
  75 import java.net.*;
  76 import java.util.*;
  77 public class X {
  78     private static void show(URL u, String ev)
  79         throws IOException
  80     {
  81         InputStream in = u.openStream();
  82         byte[] buf = new byte[1024];
  83         int n = in.read(buf);
  84         if (n <= 0 || in.read(buf) != -1)
  85             throw new Error();
  86         System.out.write(buf, 0, n);
  87         String v = new String(buf, 0, n, "US-ASCII");
  88         if (!v.trim().equals(ev))
  89             throw new AssertionError("Wrong value, expected " + ev);
  90     }
  91     private static void load(String rn, String ev)
  92         throws IOException
  93     {
  94         ClassLoader cl = X.class.getClassLoader();
  95         URL u = cl.getResource(rn);
  96         if (u == null)
  97             throw new Error(rn + ": Not found");
  98         System.out.format("%s%n", u);
  99         show(u, ev);
 100     }
 101     private static void loadAll(String rn, String ... evs)
 102         throws IOException
 103     {
 104         ClassLoader cl = X.class.getClassLoader();
 105         List<URL> us = Collections.list(cl.getResources(rn));
 106         Collections.sort(us, new Comparator<URL>() {
 107             public int compare(URL u, URL v) {
 108                 return u.toString().compareTo(v.toString());
 109             }});
 110         if (us.isEmpty())
 111             throw new Error(rn + ": Not found");
 112         System.out.format("%s%n", us);
 113         int i = 0;
 114         for (URL u : us)
 115             show(u, evs[i++]);
 116     }
 117     public static void main(String[] args) throws Exception {
 118         load("foo/x", "Hello!");
 119         load("/bar/y", "Bonjour!");
 120         load("/baz/z", "Hola!");
 121         loadAll("/inf/a",
 122                 "A one,", "and a two,", "and a three!");
 123     }
 124 }
 125 
 126 module y @ 1 {
 127   requires z @ 1;
 128 }
 129 
 130 module z @ 1 { }
--- EOF ---