1 #! /bin/sh 2 3 # Copyright (c) 2012, 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 25 # @summary jmod remove tests 26 27 set -e 28 29 BIN=${TESTJAVA:-../../../../../build}/bin 30 SRC=${TESTSRC:-.} 31 VMOPTS="${TESTVMOPTS} -esa -ea" 32 test=000jmod-rm 33 34 mk() { 35 d=`dirname $1` 36 if [ ! -d $d ]; then mkdir -p $d; fi 37 cat - >$1 38 } 39 40 compare() { 41 if [ "$1" != "$2" ]; then 42 echo "FAIL: expected [$1], got [$2]" 43 exit 1 44 fi 45 } 46 47 rm -rf $test/z.* 48 49 mk $test/z.src/foo/module-info.java <<EOF 50 module foo@1.0 { 51 exports com.foo; 52 class com.foo.Main; 53 view foo.internal { 54 exports com.foo.internal; 55 permits qux; 56 } 57 } 58 EOF 59 60 mk $test/z.src/foo/com/foo/Main.java <<EOF 61 package com.foo; 62 public class Main { 63 public static void main(String[] args) { 64 System.out.println("Hello from " + name()); 65 } 66 67 public static String name() { 68 return "foo"; 69 } 70 } 71 EOF 72 73 mk $test/z.src/foo/com/foo/internal/Hello.java <<EOF 74 package com.foo.internal; 75 public class Hello { 76 public static String name() { 77 return "foo.internal"; 78 } 79 } 80 EOF 81 82 mk $test/z.src/foo/natlib/libfoo.so <<EOF 83 just some random lib data 84 EOF 85 86 mk $test/z.src/foo/natcmd/foo <<EOF 87 just some random cmd data 88 EOF 89 90 mk $test/z.src/foo/config/fooProps.txt <<EOF 91 just some random config data 92 EOF 93 94 mk $test/z.src/bar/module-info.java <<EOF 95 module bar@1.0 { 96 class com.bar.Main; 97 } 98 EOF 99 100 mk $test/z.src/bar/com/bar/Main.java <<EOF 101 package com.bar; 102 public class Main { 103 public static void main(String[] args) { 104 System.out.println("Hello from bar"); 105 } 106 } 107 EOF 108 109 mk $test/z.src/baz/module-info.java <<EOF 110 module baz@1.0 { 111 requires foo @ 1.0; 112 class com.baz.Main; 113 } 114 EOF 115 116 mk $test/z.src/baz/com/baz/Main.java <<EOF 117 package com.baz; 118 public class Main { 119 public static void main(String[] args) { 120 System.out.println("Hello from baz, and hello from " + com.foo.Main.name()); 121 } 122 } 123 EOF 124 125 mk $test/z.src/qux/module-info.java <<EOF 126 module qux@1.0 { 127 requires foo.internal @ 1.0; 128 class com.qux.Main; 129 } 130 EOF 131 132 mk $test/z.src/qux/com/qux/Main.java <<EOF 133 package com.qux; 134 import com.foo.internal.Hello; 135 public class Main { 136 public static void main(String[] args) { 137 System.out.println("Hello from qux, and hello from " + Hello.name()); 138 } 139 } 140 EOF 141 142 mkdir $test/z.modules $test/z.classes 143 144 $BIN/javac -source 8 -d $test/z.modules -modulepath $test/z.modules \ 145 `find $test/z.src -name '*.java'` 146 $BIN/jmod ${TESTTOOLVMOPTS} -L $test/z.lib create 147 $BIN/jmod ${TESTTOOLVMOPTS} -L $test/z.lib install $test/z.modules foo 148 ## Check foo@1.0 is installed 149 compare foo@1.0 `$BIN/jmod ${TESTTOOLVMOPTS} -L $test/z.lib list | tr -d ' \n\r'` 150 ## Check jmod remove -d (--dry) 151 $BIN/jmod ${TESTTOOLVMOPTS} -L $test/z.lib remove -d foo@1.0 152 compare foo@1.0 `$BIN/jmod ${TESTTOOLVMOPTS} -L $test/z.lib list | tr -d ' \n\r'` 153 ## Check jmod remove (not a dry run!) 154 $BIN/jmod ${TESTTOOLVMOPTS} -L $test/z.lib remove foo@1.0 155 compare "" `$BIN/jmod ${TESTTOOLVMOPTS} -L $test/z.lib list | tr -d ' \n\r'` 156 rm -rf $test/z.lib 157 158 ## Check jmod remove with additional non dependent root modules 159 $BIN/jmod ${TESTTOOLVMOPTS} -L $test/z.lib create 160 $BIN/jmod ${TESTTOOLVMOPTS} -L $test/z.lib install $test/z.modules foo bar 161 $BIN/jmod ${TESTTOOLVMOPTS} -L $test/z.lib rm foo@1.0 162 compare bar@1.0 `$BIN/jmod ${TESTTOOLVMOPTS} -L $test/z.lib list | tr -d ' \n\r'` 163 rm -rf $test/z.lib 164 165 ## Check with foo and dependent baz, should fail to remove foo 166 $BIN/jmod ${TESTTOOLVMOPTS} -L $test/z.lib create 167 $BIN/jmod ${TESTTOOLVMOPTS} -L $test/z.lib install $test/z.modules foo baz 168 ## We expect the remove to fail. Temporarily disable '-e' ( script exits 169 ## immediately if a command exits with a non-zero exit status ). 170 set +e 171 if `$BIN/jmod ${TESTTOOLVMOPTS} -L $test/z.lib rm foo@1.0 > /dev/null 2>&1`; then 172 echo "FAIL: foo@1.0 should not be removed as baz@1.0 depends on it" 173 exit 1 174 fi 175 set -e 176 $BIN/jmod ${TESTTOOLVMOPTS} -L $test/z.lib rm foo@1.0 baz@1.0 177 compare "" `$BIN/jmod ${TESTTOOLVMOPTS} -L $test/z.lib list | tr -d ' \n\r'` 178 rm -rf $test/z.lib 179 180 ## Check views, foo.internal and dependent qux, should fail to remove foo 181 $BIN/jmod ${TESTTOOLVMOPTS} -L $test/z.lib create 182 $BIN/jmod ${TESTTOOLVMOPTS} -L $test/z.lib install $test/z.modules foo qux 183 ## Expect next command to fail 184 set +e 185 if `$BIN/jmod ${TESTTOOLVMOPTS} -L $test/z.lib rm foo@1.0 > /dev/null 2>&1`; then 186 echo "FAIL: foo@1.0 should not be removed as qux@1.0 depends on it" 187 exit 1 188 fi 189 set -e 190 $BIN/jmod ${TESTTOOLVMOPTS} -L $test/z.lib rm qux@1.0 foo@1.0 191 compare "" `$BIN/jmod ${TESTTOOLVMOPTS} -L $test/z.lib list | tr -d ' \n\r'` 192 rm -rf $test/z.lib 193 194 ## Check -f (--force), foo and dependent baz, should remove foo 195 $BIN/jmod ${TESTTOOLVMOPTS} -L $test/z.lib create 196 $BIN/jmod ${TESTTOOLVMOPTS} -L $test/z.lib install $test/z.modules foo baz 197 $BIN/jmod ${TESTTOOLVMOPTS} -L $test/z.lib rm -f foo@1.0 198 compare baz@1.0 `$BIN/jmod ${TESTTOOLVMOPTS} -L $test/z.lib list | tr -d ' \n\r'` 199 rm -rf $test/z.lib 200 201 202 ## Check out of module content 203 assertExists() { 204 if [ ! -f $1 ]; then 205 echo "ERROR: $1 does not exist" 206 exit 1 207 fi 208 } 209 assertDoesNotExist() { 210 if [ -f $1 ]; then 211 echo "FAILED: $1 should have been removed" 212 exit 1 213 fi 214 } 215 216 mkdir $test/z.image $test/z.jmods 217 $BIN/jpkg ${TESTTOOLVMOPTS} -m $test/z.modules/foo -d $test/z.jmods \ 218 --natcmd $test/z.src/foo/natcmd \ 219 --natlib $test/z.src/foo/natlib \ 220 --config $test/z.src/foo/config \ 221 jmod foo 222 $BIN/jmod ${TESTTOOLVMOPTS} -L $test/z.image/lib/z.lib create \ 223 --natcmd $test/z.image/bin \ 224 --natlib $test/z.image/lib \ 225 --config $test/z.image/config 226 $BIN/jmod ${TESTTOOLVMOPTS} -L $test/z.image/lib/z.lib install \ 227 $test/z.jmods/foo@1.0.jmod 228 compare foo@1.0 `$BIN/jmod ${TESTTOOLVMOPTS} -L $test/z.image/lib/z.lib list | tr -d ' \n\r'` 229 assertExists $test/z.image/bin/foo 230 assertExists $test/z.image/lib/libfoo.so 231 assertExists $test/z.image/config/fooProps.txt ] 232 $BIN/jmod ${TESTTOOLVMOPTS} -L $test/z.image/lib/z.lib rm foo@1.0 233 assertDoesNotExist $test/z.image/bin/foo 234 assertDoesNotExist $test/z.image/lib/libfoo.so 235 assertDoesNotExist $test/z.image/config/fooProps.txt