changeset 13527:4c0f482dceb1

Replace/move container test
author alanb
date Mon, 27 Jul 2015 15:25:53 +0100
parents 8c17c2fe566b
children 2d756bf68301
files test/jdk/jigsaw/container/run.sh test/jdk/jigsaw/container/src/app1/app1/Main.java test/jdk/jigsaw/container/src/app1/module-info.java test/jdk/jigsaw/container/src/app2/app2/Main.java test/jdk/jigsaw/container/src/app2/module-info.java test/jdk/jigsaw/container/src/container/container/Main.java test/jdk/jigsaw/container/src/container/module-info.java test/jdk/jigsaw/container/src/java.ws.rs/javax/ws/rs/Client.java test/jdk/jigsaw/container/src/java.ws.rs/module-info.java test/jdk/jigsaw/container/src/java.xml.ws/javax/xml/ws/WebService.java test/jdk/jigsaw/container/src/java.xml.ws/module-info.java test/jdk/jigsaw/container/test.policy test/jdk/jigsaw/functional/container/ContainerTest.java test/jdk/jigsaw/functional/container/src/app1/app1/Main.java test/jdk/jigsaw/functional/container/src/app1/module-info.java test/jdk/jigsaw/functional/container/src/app2/app2/Main.java test/jdk/jigsaw/functional/container/src/app2/module-info.java test/jdk/jigsaw/functional/container/src/container/container/Main.java test/jdk/jigsaw/functional/container/src/container/module-info.java test/jdk/jigsaw/functional/container/src/java.ws.rs/javax/ws/rs/Client.java test/jdk/jigsaw/functional/container/src/java.ws.rs/module-info.java test/jdk/jigsaw/functional/container/src/java.xml.ws/javax/xml/ws/WebService.java test/jdk/jigsaw/functional/container/src/java.xml.ws/module-info.java
diffstat 23 files changed, 514 insertions(+), 464 deletions(-) [+]
line wrap: on
line diff
--- a/test/jdk/jigsaw/container/run.sh	Mon Jul 27 12:58:31 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,81 +0,0 @@
-#
-# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-# @test
-# @summary Exercise dynamic configuration by launching a container that in
-#   turn starts a number of applications
-
-set -e
-
-if [ -z "$TESTJAVA" ]; then
-  if [ $# -lt 1 ]; then exit 1; fi
-  TESTJAVA="$1"; shift
-  COMPILEJAVA="${TESTJAVA}"
-  TESTSRC="`pwd`"
-  TESTCLASSES="`pwd`"
-fi
-
-JAVAC="$COMPILEJAVA/bin/javac"
-JAVA="$TESTJAVA/bin/java ${TESTVMOPTS}"
-JAR="$TESTJAVA/bin/jar"
-JMOD="$TESTJAVA/bin/jmod ${TESTTOOLVMOPTS}"
-
-rm -rf mlib
-mkdir -p mlib
-
-mkdir -p mods/container
-$JAVAC -d mods/container `find $TESTSRC/src/container -name "*.java"`
-$JMOD create --class-path mods/container \
-   --module-version 1.0 --main-class container.Main mlib/wls@1.0.jmod
-
-rm -rf applib
-mkdir -p applib
-
-# app1 uses a "newer" version of JAX-WS
-mkdir -p mods/java.xml.ws
-$JAVAC -d mods/java.xml.ws `find $TESTSRC/src/java.xml.ws -name "*.java"`
-$JAR cf applib/jaxws.jar -C mods/java.xml.ws .
-
-# app1 uses JAX-WS
-mkdir -p mods/app1
-$JAVAC -upgrademodulepath applib -d mods/app1 `find $TESTSRC/src/app1 -name "*.java"`
-$JAR cf applib/app1.jar -C mods/app1 .
-
-# app2 ships with its own copy of JAX-RS
-mkdir -p mods/java.ws.rs
-$JAVAC -d mods/java.ws.rs `find $TESTSRC/src/java.ws.rs -name "*.java"`
-$JAR cf applib/jaxrs.jar -C mods/java.ws.rs .
-
-mkdir -p mods/app2
-$JAVAC -upgrademodulepath applib -d mods/app2 `find $TESTSRC/src/app2 -name "*.java"`
-$JAR cf applib/app2.jar -C mods/app2 .
-
-# launch the container
-$JAVA -mp mlib -m container
-
-# launch the container with a security manager
-MLIB=`pwd -P`/mlib
-$JAVA -Dmlib=$MLIB -Djava.security.manager \
-    -Djava.security.policy=${TESTSRC}/test.policy \
-    -mp mlib -m container
-
--- a/test/jdk/jigsaw/container/src/app1/app1/Main.java	Mon Jul 27 12:58:31 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-/*
- * Copyright (c)  2014, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package app1;
-
-import javax.xml.ws.WebService;
-
-public class Main {
-
-    static void trace(Class<?> c) {
-        System.out.format("%s loaded by %s\n", c, c.getClassLoader());
-    }
-
-    public static void main(String[] args) throws Exception {
-        trace(Main.class);
-
-        WebService ws = new WebService();
-        trace(ws.getClass());
-    }
-}
--- a/test/jdk/jigsaw/container/src/app1/module-info.java	Mon Jul 27 12:58:31 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-/*
- * Copyright (c)  2014, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-module app1 {
-    requires java.base;
-    requires java.xml.ws;
-}
--- a/test/jdk/jigsaw/container/src/app2/app2/Main.java	Mon Jul 27 12:58:31 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-/*
- * Copyright (c)  2014, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package app2;
-
-import javax.ws.rs.Client;
-
-public class Main {
-
-    static void trace(Class<?> c) {
-        System.out.format("%s loaded by %s\n", c, c.getClassLoader());
-    }
-
-    public static void main(String[] args) throws Exception {
-        trace(Main.class);
-
-        Client c = new Client();
-        trace(c.getClass());
-    }
-}
--- a/test/jdk/jigsaw/container/src/app2/module-info.java	Mon Jul 27 12:58:31 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-/*
- * Copyright (c)  2014, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-module app2 {
-    requires java.base;
-    requires java.ws.rs;
-}
--- a/test/jdk/jigsaw/container/src/container/container/Main.java	Mon Jul 27 12:58:31 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,105 +0,0 @@
-/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package container;
-
-import java.io.File;
-import java.lang.module.Configuration;
-import java.lang.module.Layer;
-import java.lang.module.ModuleFinder;
-import java.lang.module.ModuleDescriptor;
-import java.lang.reflect.Method;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-
-/**
- * Exercises dynamic configuration.
- */
-
-public class Main {
-
-    public static void main(String[] args) throws Exception {
-
-        System.out.println("Boot layer");
-        Layer.boot()
-             .configuration().get()
-             .descriptors()
-             .stream()
-             .map(ModuleDescriptor::name)
-             .forEach(System.out::println);
-
-        // "start" two applications in their own layers
-        start("applib", "app1", "app1.Main");
-        start("applib", "app2", "app2.Main");
-    }
-
-    static void start(String appModulePath,
-                      String appModuleName,
-                      String appMainClass) throws Exception {
-
-        System.out.format("Starting %s/%s ...%n", appModuleName, appMainClass);
-
-        String[] dirs = appModulePath.split(File.pathSeparator);
-        Path[] paths = new Path[dirs.length];
-        int i = 0;
-        for (String dir: dirs) {
-            paths[i++] = Paths.get(dir);
-        }
-
-        Layer bootLayer = Layer.boot();
-
-        ModuleFinder finder = ModuleFinder.of(paths);
-
-        Configuration cf = Configuration.resolve(finder,
-                bootLayer,
-                ModuleFinder.empty(),
-                appModuleName);
-        cf = cf.bind();
-
-        System.out.println("Resolved");
-        cf.descriptors()
-          .forEach(md -> System.out.format("  %s%n", md.name()));
-
-        // choose a class loader
-        ModuleClassLoader loader = new ModuleClassLoader();
-
-        // reify the configuration as a Layer
-        Layer layer = Layer.create(cf, m -> loader);
-
-        // invoke application main method
-        Class<?> c = layer.findLoader(appModuleName).loadClass(appMainClass);
-        Method mainMethod = c.getMethod("main", String[].class);
-        mainMethod.setAccessible(true);
-
-        // set TCCL as that is the EE thing to do
-        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
-        try {
-            Thread.currentThread().setContextClassLoader(loader);
-            mainMethod.invoke(null, (Object)new String[0]);
-        } finally {
-            Thread.currentThread().setContextClassLoader(tccl);
-        }
-
-        System.out.println();
-    }
-}
--- a/test/jdk/jigsaw/container/src/container/module-info.java	Mon Jul 27 12:58:31 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-/*
- * Copyright (c)  2014, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-module container {
-    requires java.se;
-}
--- a/test/jdk/jigsaw/container/src/java.ws.rs/javax/ws/rs/Client.java	Mon Jul 27 12:58:31 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-/*
- * Copyright (c)  2014, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package javax.ws.rs;
-
-public class Client {
-    public Client() { }
-}
-
--- a/test/jdk/jigsaw/container/src/java.ws.rs/module-info.java	Mon Jul 27 12:58:31 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-/*
- * Copyright (c)  2014, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-module java.ws.rs {
-    requires java.base;
-
-    exports javax.ws.rs;
-}
--- a/test/jdk/jigsaw/container/src/java.xml.ws/javax/xml/ws/WebService.java	Mon Jul 27 12:58:31 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-/*
- * Copyright (c)  2014, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package javax.xml.ws;
-
-public class WebService {
-    public WebService() { }
-}
--- a/test/jdk/jigsaw/container/src/java.xml.ws/module-info.java	Mon Jul 27 12:58:31 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-/*
- * Copyright (c)  2014, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-module java.xml.ws {
-    requires java.base;
-
-    exports javax.xml.ws;
-}
--- a/test/jdk/jigsaw/container/test.policy	Mon Jul 27 12:58:31 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,12 +0,0 @@
-// grant permission to specific code base
-grant codeBase "jmod:file://${mlib}/wls@1.0.jmod!/" {
-    permission java.lang.RuntimePermission "createClassLoader";
-    permission java.lang.RuntimePermission "getBootLayer";
-    permission java.lang.RuntimePermission "getClassLoader";
-    permission java.lang.RuntimePermission "registerSystemModule";
-    permission java.lang.RuntimePermission "setContextClassLoader";
-    permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
-    permission java.io.FilePermission "applib", "read";
-    permission java.io.FilePermission "applib/*", "read";
-    permission java.util.PropertyPermission "user.dir", "read";
-};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/jigsaw/functional/container/ContainerTest.java	Mon Jul 27 15:25:53 2015 +0100
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @library ../../lib /lib/testlibrary
+ * @modules jdk.jlink/jdk.tools.jmod
+ * @build ContainerTest CompilerUtils jdk.testlibrary.ProcessTools
+ * @run testng ContainerTest
+ * @summary Starts a simple container that uses dynamic configurations
+ *          and launches two applications in the same VM
+ */
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import static jdk.testlibrary.ProcessTools.*;
+
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+import static org.testng.Assert.*;
+
+@Test
+public class ContainerTest {
+
+    private static final String TEST_SRC = System.getProperty("test.src");
+
+    private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
+    private static final Path MODS_DIR = Paths.get("mods");
+
+    private static final Path MLIB_DIR = Paths.get("mlib");
+    private static final Path APPLIB_DIR = Paths.get("applib");
+
+    private static final String CONTAINER_MODULE = "container";
+    private static final String CONTAINER_MAIN_CLASS = "container.Main";
+
+
+    /**
+     * Creates the container module in mlib/container@1.0.jmod
+     */
+    void buildContainer() throws Exception {
+
+        Path src = SRC_DIR.resolve(CONTAINER_MODULE);
+        Path output = MODS_DIR.resolve(CONTAINER_MODULE);
+
+        boolean compiled = CompilerUtils.compile(src, output);
+        assertTrue(compiled);
+
+        // jmod create ...
+        Path mlib = Files.createDirectories(MLIB_DIR);
+        String cp = output.toString();
+        String jmod = mlib.resolve(CONTAINER_MODULE + "@1.0.jmod").toString();
+        String[] args = {
+            "create",
+            "--class-path", cp,
+            "--main-class", CONTAINER_MAIN_CLASS,
+            jmod
+        };
+        jdk.tools.jmod.JmodTask task = new jdk.tools.jmod.JmodTask();
+        assertEquals(task.run(args), 0);
+    }
+
+    /**
+     * Creates app1 and its bundled libraries in applib.
+     */
+    void buildApp1() throws Exception {
+        Path dir = Files.createDirectories(APPLIB_DIR);
+
+        // app1 uses its own copy of JAX-WS
+        boolean compiled
+            = CompilerUtils.compile(SRC_DIR.resolve("java.xml.ws"),
+                                    dir.resolve("java.xml.ws"));
+        assertTrue(compiled);
+
+        compiled = CompilerUtils.compile(SRC_DIR.resolve("app1"),
+                                         dir.resolve("app1"),
+                                         "-upgrademodulepath", dir.toString());
+        assertTrue(compiled);
+    }
+
+    /**
+     * Creates app2 and its bundled libraries in applib.
+     */
+    void buildApp2() throws Exception {
+        Path dir = Files.createDirectories(APPLIB_DIR);
+
+        // app2 uses JAX-RS
+        boolean compiled
+            = CompilerUtils.compile(SRC_DIR.resolve("java.ws.rs"),
+                                    dir.resolve("java.ws.rs"));
+        assertTrue(compiled);
+
+        compiled = CompilerUtils.compile(SRC_DIR.resolve("app2"),
+                                         dir.resolve("app2"),
+                                         "-mp", dir.toString());
+        assertTrue(compiled);
+    }
+
+
+    @BeforeTest
+    public void setup() throws Exception {
+        buildContainer();
+        buildApp1();
+        buildApp2();
+    }
+
+    /**
+     * Launches the container
+     */
+    public void testContainer() throws Exception {
+
+        int exitValue
+            = executeTestJava("-mp", MLIB_DIR.toString(),
+                              "-m", CONTAINER_MODULE)
+                .outputTo(System.out)
+                .errorTo(System.err)
+                .getExitValue();
+
+        assertTrue(exitValue == 0);
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/jigsaw/functional/container/src/app1/app1/Main.java	Mon Jul 27 15:25:53 2015 +0100
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c)  2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package app1;
+
+import javax.xml.ws.WebService;
+
+public class Main {
+
+    static void trace(Class<?> c) {
+        System.out.format("%s loaded by %s\n", c, c.getClassLoader());
+    }
+
+    public static void main(String[] args) throws Exception {
+        trace(Main.class);
+
+        WebService ws = new WebService();
+        trace(ws.getClass());
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/jigsaw/functional/container/src/app1/module-info.java	Mon Jul 27 15:25:53 2015 +0100
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c)  2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+module app1 {
+    requires java.base;
+    requires java.xml.ws;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/jigsaw/functional/container/src/app2/app2/Main.java	Mon Jul 27 15:25:53 2015 +0100
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c)  2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package app2;
+
+import javax.ws.rs.Client;
+
+public class Main {
+
+    static void trace(Class<?> c) {
+        System.out.format("%s loaded by %s\n", c, c.getClassLoader());
+    }
+
+    public static void main(String[] args) throws Exception {
+        trace(Main.class);
+
+        Client c = new Client();
+        trace(c.getClass());
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/jigsaw/functional/container/src/app2/module-info.java	Mon Jul 27 15:25:53 2015 +0100
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c)  2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+module app2 {
+    requires java.base;
+    requires java.ws.rs;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/jigsaw/functional/container/src/container/container/Main.java	Mon Jul 27 15:25:53 2015 +0100
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package container;
+
+import java.io.File;
+import java.lang.module.Configuration;
+import java.lang.module.Layer;
+import java.lang.module.ModuleFinder;
+import java.lang.module.ModuleDescriptor;
+import java.lang.reflect.Method;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+/**
+ * Exercises dynamic configuration.
+ */
+
+public class Main {
+
+    public static void main(String[] args) throws Exception {
+
+        System.out.println("Boot layer");
+        Layer.boot()
+             .configuration().get()
+             .descriptors()
+             .stream()
+             .map(ModuleDescriptor::name)
+             .forEach(System.out::println);
+
+        // "start" two applications in their own layers
+        start("applib", "app1", "app1.Main");
+        start("applib", "app2", "app2.Main");
+    }
+
+    static void start(String appModulePath,
+                      String appModuleName,
+                      String appMainClass) throws Exception {
+
+        System.out.format("Starting %s/%s ...%n", appModuleName, appMainClass);
+
+        String[] dirs = appModulePath.split(File.pathSeparator);
+        Path[] paths = new Path[dirs.length];
+        int i = 0;
+        for (String dir: dirs) {
+            paths[i++] = Paths.get(dir);
+        }
+
+        Layer bootLayer = Layer.boot();
+
+        ModuleFinder finder = ModuleFinder.of(paths);
+
+        Configuration cf = Configuration.resolve(finder,
+                bootLayer,
+                ModuleFinder.empty(),
+                appModuleName);
+        cf = cf.bind();
+
+        System.out.println("Resolved");
+        cf.descriptors()
+          .forEach(md -> System.out.format("  %s%n", md.name()));
+
+        // choose a class loader
+        ModuleClassLoader loader = new ModuleClassLoader();
+
+        // reify the configuration as a Layer
+        Layer layer = Layer.create(cf, m -> loader);
+
+        // invoke application main method
+        Class<?> c = layer.findLoader(appModuleName).loadClass(appMainClass);
+        Method mainMethod = c.getMethod("main", String[].class);
+        mainMethod.setAccessible(true);
+
+        // set TCCL as that is the EE thing to do
+        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+        try {
+            Thread.currentThread().setContextClassLoader(loader);
+            mainMethod.invoke(null, (Object)new String[0]);
+        } finally {
+            Thread.currentThread().setContextClassLoader(tccl);
+        }
+
+        System.out.println();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/jigsaw/functional/container/src/container/module-info.java	Mon Jul 27 15:25:53 2015 +0100
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c)  2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+module container {
+    requires java.se;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/jigsaw/functional/container/src/java.ws.rs/javax/ws/rs/Client.java	Mon Jul 27 15:25:53 2015 +0100
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c)  2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package javax.ws.rs;
+
+public class Client {
+    public Client() { }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/jigsaw/functional/container/src/java.ws.rs/module-info.java	Mon Jul 27 15:25:53 2015 +0100
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c)  2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+module java.ws.rs {
+    requires java.base;
+
+    exports javax.ws.rs;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/jigsaw/functional/container/src/java.xml.ws/javax/xml/ws/WebService.java	Mon Jul 27 15:25:53 2015 +0100
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c)  2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package javax.xml.ws;
+
+public class WebService {
+    public WebService() { }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/jigsaw/functional/container/src/java.xml.ws/module-info.java	Mon Jul 27 15:25:53 2015 +0100
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c)  2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+module java.xml.ws {
+    requires java.base;
+
+    exports javax.xml.ws;
+}