8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Chris Hegarty <chris.hegarty@oracle.com>
Co-authored-by: Alexandr Scherbatiy <alexandr.scherbatiy@oracle.com>
Co-authored-by: Amy Lu <amy.lu@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Daniel Fuchs <daniel.fuchs@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Jaroslav Bachorik <jaroslav.bachorik@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jan Lahoda <jan.lahoda@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Miroslav Kos <miroslav.kos@oracle.com>
Co-authored-by: Huaming Li <huaming.li@oracle.com>
Co-authored-by: Sean Mullan <sean.mullan@oracle.com>
Co-authored-by: Naoto Sato <naoto.sato@oracle.com>
Co-authored-by: Masayoshi Okutsu <masayoshi.okutsu@oracle.com>
Co-authored-by: Peter Levart <peter.levart@gmail.com>
Co-authored-by: Philip Race <philip.race@oracle.com>
Co-authored-by: Claes Redestad <claes.redestad@oracle.com>
Co-authored-by: Sergey Bylokhov <sergey.bylokhov@oracle.com>
Co-authored-by: Alexandre Iline <alexandre.iline@oracle.com>
Co-authored-by: Volker Simonis <volker.simonis@gmail.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Stuart Marks <stuart.marks@oracle.com>
Co-authored-by: Semyon Sadetsky <semyon.sadetsky@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Co-authored-by: Valerie Peng <valerie.peng@oracle.com>
Co-authored-by: Vincent Ryan <vincent.x.ryan@oracle.com>
Co-authored-by: Weijun Wang <weijun.wang@oracle.com>
Co-authored-by: Yuri Nesterenko <yuri.nesterenko@oracle.com>
Co-authored-by: Yekaterina Kantserova <yekaterina.kantserova@oracle.com>
Co-authored-by: Alexander Kulyakthin <alexander.kulyakhtin@oracle.com>
Co-authored-by: Felix Yang <felix.yang@oracle.com>
Co-authored-by: Andrei Eremeev <andrei.eremeev@oracle.com>
Co-authored-by: Frank Yuan <frank.yuan@oracle.com>
Co-authored-by: Sergei Pikalev <sergei.pikalev@oracle.com>
Co-authored-by: Sibabrata Sahoo <sibabrata.sahoo@oracle.com>
Co-authored-by: Tiantian Du <tiantian.du@oracle.com>
Co-authored-by: Sha Jiang <sha.jiang@oracle.com>
Reviewed-by: alanb, mchung, naoto, rriggs, psandoz, plevart, mullan, ascarpino, vinnie, prr, sherman, dfuchs, mhaupt
2016-03-17 19:04:16 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015, 2016, 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import java.lang.module.Configuration;
|
|
|
|
import java.lang.module.ResolvedModule;
|
|
|
|
import java.lang.reflect.Layer;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Path;
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
|
|
|
/**
|
2016-12-01 08:57:53 +00:00
|
|
|
* Basic test of Class getResource and getResourceAsStream to locate/read
|
|
|
|
* resources in named modules.
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Chris Hegarty <chris.hegarty@oracle.com>
Co-authored-by: Alexandr Scherbatiy <alexandr.scherbatiy@oracle.com>
Co-authored-by: Amy Lu <amy.lu@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Daniel Fuchs <daniel.fuchs@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Jaroslav Bachorik <jaroslav.bachorik@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jan Lahoda <jan.lahoda@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Miroslav Kos <miroslav.kos@oracle.com>
Co-authored-by: Huaming Li <huaming.li@oracle.com>
Co-authored-by: Sean Mullan <sean.mullan@oracle.com>
Co-authored-by: Naoto Sato <naoto.sato@oracle.com>
Co-authored-by: Masayoshi Okutsu <masayoshi.okutsu@oracle.com>
Co-authored-by: Peter Levart <peter.levart@gmail.com>
Co-authored-by: Philip Race <philip.race@oracle.com>
Co-authored-by: Claes Redestad <claes.redestad@oracle.com>
Co-authored-by: Sergey Bylokhov <sergey.bylokhov@oracle.com>
Co-authored-by: Alexandre Iline <alexandre.iline@oracle.com>
Co-authored-by: Volker Simonis <volker.simonis@gmail.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Stuart Marks <stuart.marks@oracle.com>
Co-authored-by: Semyon Sadetsky <semyon.sadetsky@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Co-authored-by: Valerie Peng <valerie.peng@oracle.com>
Co-authored-by: Vincent Ryan <vincent.x.ryan@oracle.com>
Co-authored-by: Weijun Wang <weijun.wang@oracle.com>
Co-authored-by: Yuri Nesterenko <yuri.nesterenko@oracle.com>
Co-authored-by: Yekaterina Kantserova <yekaterina.kantserova@oracle.com>
Co-authored-by: Alexander Kulyakthin <alexander.kulyakhtin@oracle.com>
Co-authored-by: Felix Yang <felix.yang@oracle.com>
Co-authored-by: Andrei Eremeev <andrei.eremeev@oracle.com>
Co-authored-by: Frank Yuan <frank.yuan@oracle.com>
Co-authored-by: Sergei Pikalev <sergei.pikalev@oracle.com>
Co-authored-by: Sibabrata Sahoo <sibabrata.sahoo@oracle.com>
Co-authored-by: Tiantian Du <tiantian.du@oracle.com>
Co-authored-by: Sha Jiang <sha.jiang@oracle.com>
Reviewed-by: alanb, mchung, naoto, rriggs, psandoz, plevart, mullan, ascarpino, vinnie, prr, sherman, dfuchs, mhaupt
2016-03-17 19:04:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
public class Main {
|
|
|
|
|
|
|
|
static final String NAME = "myresource";
|
|
|
|
|
|
|
|
public static void main(String[] args) throws IOException {
|
|
|
|
|
2016-12-01 08:57:53 +00:00
|
|
|
// create resources in m1
|
|
|
|
createResource("m1", Paths.get("."), "m1");
|
|
|
|
createResource("m1", Paths.get("p1"), "m1/p1");
|
|
|
|
createResource("m1", Paths.get("p1", "impl"), "m1/p1.impl");
|
|
|
|
createResource("m1", Paths.get("p1", "resources"), "m1/p1.resources");
|
|
|
|
|
|
|
|
// create resources in m2
|
|
|
|
createResource("m2", Paths.get("."), "m2");
|
|
|
|
createResource("m2", Paths.get("p2"), "m2/p2");
|
|
|
|
createResource("m2", Paths.get("p2", "impl"), "m2/p2.impl");
|
|
|
|
createResource("m2", Paths.get("p2", "resources"), "m2/p2.resources");
|
|
|
|
|
|
|
|
|
|
|
|
// invoke Class getResource from an unnamed module.
|
|
|
|
URL url = Main.class.getResource("/" + NAME);
|
|
|
|
assertNotNull(url);
|
|
|
|
|
|
|
|
url = Main.class.getResource("/p1/" + NAME);
|
|
|
|
assertNull(url);
|
|
|
|
|
|
|
|
url = Main.class.getResource("/p1/impl/" + NAME);
|
|
|
|
assertNull(url);
|
|
|
|
|
|
|
|
url = Main.class.getResource("/p1/resources/" + NAME);
|
|
|
|
assertEquals(readAllAsString(url), "m1/p1.resources");
|
|
|
|
|
|
|
|
url = Main.class.getResource("/p2/" + NAME);
|
|
|
|
assertNull(url);
|
|
|
|
|
|
|
|
url = Main.class.getResource("/p2/impl/" + NAME);
|
|
|
|
assertNull(url);
|
|
|
|
|
|
|
|
// m1: exports private p1.resources
|
|
|
|
url = Main.class.getResource("/p2/resources/" + NAME);
|
|
|
|
assertNull(url);
|
|
|
|
|
|
|
|
|
|
|
|
// invoke Class getResource from module m1
|
|
|
|
url = p1.Main.getResource("/" + NAME);
|
|
|
|
assertEquals(readAllAsString(url), "m1");
|
|
|
|
|
|
|
|
url = p1.Main.getResource("/p1/" + NAME);
|
|
|
|
assertEquals(readAllAsString(url), "m1/p1");
|
|
|
|
|
|
|
|
url = p1.Main.getResource("/p1/impl/" + NAME);
|
|
|
|
assertEquals(readAllAsString(url), "m1/p1.impl");
|
|
|
|
|
|
|
|
url = p1.Main.getResource("/p1/resources/" + NAME);
|
|
|
|
assertEquals(readAllAsString(url), "m1/p1.resources");
|
|
|
|
|
|
|
|
// m2: not a named package
|
|
|
|
url = p1.Main.getResource(p2.Main.class, "/" + NAME);
|
|
|
|
assertEquals(readAllAsString(url), "m2");
|
|
|
|
|
|
|
|
url = p1.Main.getResource(p2.Main.class, "/p2/" + NAME);
|
|
|
|
assertNull(url);
|
|
|
|
|
|
|
|
// m2: exports p2.impl to m1
|
|
|
|
url = p1.Main.getResource(p2.Main.class, "/p2/impl/" + NAME);
|
|
|
|
assertNull(url);
|
|
|
|
|
|
|
|
// m2: exports private p2.resources to m1;
|
|
|
|
url = p1.Main.getResource(p2.Main.class, "/p2/resources/" + NAME);
|
|
|
|
assertEquals(readAllAsString(url), "m2/p2.resources");
|
|
|
|
|
|
|
|
|
|
|
|
// invoke Class getResource from module m2
|
|
|
|
url = p2.Main.getResource("/" + NAME);
|
|
|
|
assertEquals(readAllAsString(url), "m2");
|
|
|
|
|
|
|
|
url = p2.Main.getResource("/p2/" + NAME);
|
|
|
|
assertEquals(readAllAsString(url), "m2/p2");
|
|
|
|
|
|
|
|
url = p2.Main.getResource("/p2/impl/" + NAME);
|
|
|
|
assertEquals(readAllAsString(url), "m2/p2.impl");
|
|
|
|
|
|
|
|
url = p2.Main.getResource("/p2/resources/" + NAME);
|
|
|
|
assertEquals(readAllAsString(url), "m2/p2.resources");
|
|
|
|
|
|
|
|
// m1: not a named package
|
|
|
|
url = p2.Main.getResource(p1.Main.class, "/" + NAME);
|
|
|
|
assertEquals(readAllAsString(url), "m1");
|
|
|
|
|
|
|
|
url = p2.Main.getResource(p1.Main.class, "/p1/" + NAME);
|
|
|
|
assertNull(url);
|
|
|
|
|
|
|
|
url = p2.Main.getResource(p1.Main.class, "/p1/impl/" + NAME);
|
|
|
|
assertNull(url);
|
|
|
|
|
|
|
|
// m1: exports private p1.resources;
|
|
|
|
url = p2.Main.getResource(p1.Main.class, "/p1/resources/" + NAME);
|
|
|
|
assertEquals(readAllAsString(url), "m1/p1.resources");
|
|
|
|
|
|
|
|
|
|
|
|
// invoke Class getResourceAsStream from an unnamed module.
|
|
|
|
InputStream in = Main.class.getResourceAsStream("/" + NAME);
|
|
|
|
assertNotNull(in);
|
|
|
|
|
|
|
|
in = Main.class.getResourceAsStream("/p1/" + NAME);
|
|
|
|
assertNull(in);
|
|
|
|
|
|
|
|
in = Main.class.getResourceAsStream("/p1/impl/" + NAME);
|
|
|
|
assertNull(in);
|
|
|
|
|
|
|
|
in = Main.class.getResourceAsStream("/p1/resources/" + NAME);
|
|
|
|
assertEquals(readAllAsString(in), "m1/p1.resources");
|
|
|
|
|
|
|
|
in = Main.class.getResourceAsStream("/p2/" + NAME);
|
|
|
|
assertNull(in);
|
|
|
|
|
|
|
|
in = Main.class.getResourceAsStream("/p2/impl/" + NAME);
|
|
|
|
assertNull(in);
|
|
|
|
|
|
|
|
in = Main.class.getResourceAsStream("/p2/resources/" + NAME);
|
|
|
|
assertNull(in);
|
|
|
|
|
|
|
|
|
|
|
|
// invoke Class getResourceAsStream from module m1
|
|
|
|
in = p1.Main.getResourceAsStream("/" + NAME);
|
|
|
|
assertEquals(readAllAsString(in), "m1");
|
|
|
|
|
|
|
|
in = p1.Main.getResourceAsStream("/p1/" + NAME);
|
|
|
|
assertEquals(readAllAsString(in), "m1/p1");
|
|
|
|
|
|
|
|
in = p1.Main.getResourceAsStream("/p1/impl/" + NAME);
|
|
|
|
assertEquals(readAllAsString(in), "m1/p1.impl");
|
|
|
|
|
|
|
|
in = p1.Main.getResourceAsStream("/p1/resources/" + NAME);
|
|
|
|
assertEquals(readAllAsString(in), "m1/p1.resources");
|
|
|
|
|
|
|
|
in = p1.Main.getResourceAsStream(p2.Main.class, "/" + NAME);
|
|
|
|
assertEquals(readAllAsString(in), "m2");
|
|
|
|
|
|
|
|
in = p1.Main.getResourceAsStream(p2.Main.class, "/p2/" + NAME);
|
|
|
|
assertNull(in);
|
|
|
|
|
|
|
|
in = p1.Main.getResourceAsStream(p2.Main.class, "/p2/impl/" + NAME);
|
|
|
|
assertNull(in);
|
|
|
|
|
|
|
|
in = p1.Main.getResourceAsStream(p2.Main.class, "/p2/resources/" + NAME);
|
|
|
|
assertEquals(readAllAsString(in), "m2/p2.resources");
|
|
|
|
|
|
|
|
|
|
|
|
// invoke Class getResourceAsStream from module m2
|
|
|
|
in = p2.Main.getResourceAsStream("/" + NAME);
|
|
|
|
assertEquals(readAllAsString(in), "m2");
|
|
|
|
|
|
|
|
in = p2.Main.getResourceAsStream("/p2/" + NAME);
|
|
|
|
assertEquals(readAllAsString(in), "m2/p2");
|
|
|
|
|
|
|
|
in = p2.Main.getResourceAsStream("/p2/impl/" + NAME);
|
|
|
|
assertEquals(readAllAsString(in), "m2/p2.impl");
|
|
|
|
|
|
|
|
in = p2.Main.getResourceAsStream("/p2/resources/" + NAME);
|
|
|
|
assertEquals(readAllAsString(in), "m2/p2.resources");
|
|
|
|
|
|
|
|
in = p2.Main.getResourceAsStream(p1.Main.class, "/" + NAME);
|
|
|
|
assertEquals(readAllAsString(in), "m1");
|
|
|
|
|
|
|
|
in = p2.Main.getResourceAsStream(p1.Main.class, "/p1/" + NAME);
|
|
|
|
assertNull(in);
|
|
|
|
|
|
|
|
in = p2.Main.getResourceAsStream(p1.Main.class, "/p1/impl/" + NAME);
|
|
|
|
assertNull(in);
|
|
|
|
|
|
|
|
in = p2.Main.getResourceAsStream(p1.Main.class, "/p1/resources/" + NAME);
|
|
|
|
assertEquals(readAllAsString(in), "m1/p1.resources");
|
|
|
|
|
|
|
|
|
|
|
|
// Nulls
|
|
|
|
try {
|
|
|
|
Main.class.getResource(null);
|
|
|
|
assertTrue(false);
|
|
|
|
} catch (NullPointerException expected) { }
|
|
|
|
try {
|
|
|
|
Main.class.getResourceAsStream(null);
|
|
|
|
assertTrue(false);
|
|
|
|
} catch (NullPointerException expected) { }
|
|
|
|
try {
|
|
|
|
p1.Main.class.getResource(null);
|
|
|
|
assertTrue(false);
|
|
|
|
} catch (NullPointerException expected) { }
|
|
|
|
try {
|
|
|
|
p1.Main.class.getResourceAsStream(null);
|
|
|
|
assertTrue(false);
|
|
|
|
} catch (NullPointerException expected) { }
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Chris Hegarty <chris.hegarty@oracle.com>
Co-authored-by: Alexandr Scherbatiy <alexandr.scherbatiy@oracle.com>
Co-authored-by: Amy Lu <amy.lu@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Daniel Fuchs <daniel.fuchs@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Jaroslav Bachorik <jaroslav.bachorik@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jan Lahoda <jan.lahoda@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Miroslav Kos <miroslav.kos@oracle.com>
Co-authored-by: Huaming Li <huaming.li@oracle.com>
Co-authored-by: Sean Mullan <sean.mullan@oracle.com>
Co-authored-by: Naoto Sato <naoto.sato@oracle.com>
Co-authored-by: Masayoshi Okutsu <masayoshi.okutsu@oracle.com>
Co-authored-by: Peter Levart <peter.levart@gmail.com>
Co-authored-by: Philip Race <philip.race@oracle.com>
Co-authored-by: Claes Redestad <claes.redestad@oracle.com>
Co-authored-by: Sergey Bylokhov <sergey.bylokhov@oracle.com>
Co-authored-by: Alexandre Iline <alexandre.iline@oracle.com>
Co-authored-by: Volker Simonis <volker.simonis@gmail.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Stuart Marks <stuart.marks@oracle.com>
Co-authored-by: Semyon Sadetsky <semyon.sadetsky@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Co-authored-by: Valerie Peng <valerie.peng@oracle.com>
Co-authored-by: Vincent Ryan <vincent.x.ryan@oracle.com>
Co-authored-by: Weijun Wang <weijun.wang@oracle.com>
Co-authored-by: Yuri Nesterenko <yuri.nesterenko@oracle.com>
Co-authored-by: Yekaterina Kantserova <yekaterina.kantserova@oracle.com>
Co-authored-by: Alexander Kulyakthin <alexander.kulyakhtin@oracle.com>
Co-authored-by: Felix Yang <felix.yang@oracle.com>
Co-authored-by: Andrei Eremeev <andrei.eremeev@oracle.com>
Co-authored-by: Frank Yuan <frank.yuan@oracle.com>
Co-authored-by: Sergei Pikalev <sergei.pikalev@oracle.com>
Co-authored-by: Sibabrata Sahoo <sibabrata.sahoo@oracle.com>
Co-authored-by: Tiantian Du <tiantian.du@oracle.com>
Co-authored-by: Sha Jiang <sha.jiang@oracle.com>
Reviewed-by: alanb, mchung, naoto, rriggs, psandoz, plevart, mullan, ascarpino, vinnie, prr, sherman, dfuchs, mhaupt
2016-03-17 19:04:16 +00:00
|
|
|
|
|
|
|
// SecurityManager case
|
|
|
|
System.setSecurityManager(new SecurityManager());
|
|
|
|
|
|
|
|
assertNull(Main.class.getResource("/" + NAME));
|
|
|
|
assertNull(p1.Main.getResource("/" + NAME));
|
|
|
|
assertNull(p2.Main.getResource("/" + NAME));
|
|
|
|
|
|
|
|
assertNull(Main.class.getResourceAsStream("/" + NAME));
|
|
|
|
assertNull(p1.Main.getResourceAsStream("/" + NAME));
|
|
|
|
assertNull(p2.Main.getResourceAsStream("/" + NAME));
|
|
|
|
|
|
|
|
System.out.println("Success!");
|
|
|
|
}
|
|
|
|
|
2016-12-01 08:57:53 +00:00
|
|
|
/**
|
|
|
|
* Create a resource in the sub-directory of the given exploded module
|
|
|
|
*/
|
|
|
|
static void createResource(String mn, Path subdir, String msg) throws IOException {
|
|
|
|
Path dir = directoryFor(mn).resolve(subdir);
|
|
|
|
Path file = dir.resolve(NAME);
|
|
|
|
Files.write(file, msg.getBytes("UTF-8"));
|
|
|
|
}
|
|
|
|
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Chris Hegarty <chris.hegarty@oracle.com>
Co-authored-by: Alexandr Scherbatiy <alexandr.scherbatiy@oracle.com>
Co-authored-by: Amy Lu <amy.lu@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Daniel Fuchs <daniel.fuchs@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Jaroslav Bachorik <jaroslav.bachorik@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jan Lahoda <jan.lahoda@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Miroslav Kos <miroslav.kos@oracle.com>
Co-authored-by: Huaming Li <huaming.li@oracle.com>
Co-authored-by: Sean Mullan <sean.mullan@oracle.com>
Co-authored-by: Naoto Sato <naoto.sato@oracle.com>
Co-authored-by: Masayoshi Okutsu <masayoshi.okutsu@oracle.com>
Co-authored-by: Peter Levart <peter.levart@gmail.com>
Co-authored-by: Philip Race <philip.race@oracle.com>
Co-authored-by: Claes Redestad <claes.redestad@oracle.com>
Co-authored-by: Sergey Bylokhov <sergey.bylokhov@oracle.com>
Co-authored-by: Alexandre Iline <alexandre.iline@oracle.com>
Co-authored-by: Volker Simonis <volker.simonis@gmail.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Stuart Marks <stuart.marks@oracle.com>
Co-authored-by: Semyon Sadetsky <semyon.sadetsky@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Co-authored-by: Valerie Peng <valerie.peng@oracle.com>
Co-authored-by: Vincent Ryan <vincent.x.ryan@oracle.com>
Co-authored-by: Weijun Wang <weijun.wang@oracle.com>
Co-authored-by: Yuri Nesterenko <yuri.nesterenko@oracle.com>
Co-authored-by: Yekaterina Kantserova <yekaterina.kantserova@oracle.com>
Co-authored-by: Alexander Kulyakthin <alexander.kulyakhtin@oracle.com>
Co-authored-by: Felix Yang <felix.yang@oracle.com>
Co-authored-by: Andrei Eremeev <andrei.eremeev@oracle.com>
Co-authored-by: Frank Yuan <frank.yuan@oracle.com>
Co-authored-by: Sergei Pikalev <sergei.pikalev@oracle.com>
Co-authored-by: Sibabrata Sahoo <sibabrata.sahoo@oracle.com>
Co-authored-by: Tiantian Du <tiantian.du@oracle.com>
Co-authored-by: Sha Jiang <sha.jiang@oracle.com>
Reviewed-by: alanb, mchung, naoto, rriggs, psandoz, plevart, mullan, ascarpino, vinnie, prr, sherman, dfuchs, mhaupt
2016-03-17 19:04:16 +00:00
|
|
|
/**
|
|
|
|
* Returns the directory for the given module (by name).
|
|
|
|
*/
|
|
|
|
static Path directoryFor(String name) {
|
|
|
|
Configuration cf = Layer.boot().configuration();
|
|
|
|
ResolvedModule resolvedModule = cf.findModule(name).orElse(null);
|
|
|
|
if (resolvedModule == null)
|
|
|
|
throw new RuntimeException("not found: " + name);
|
|
|
|
Path dir = Paths.get(resolvedModule.reference().location().get());
|
|
|
|
if (!Files.isDirectory(dir))
|
|
|
|
throw new RuntimeException("not a directory: " + dir);
|
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
2016-12-01 08:57:53 +00:00
|
|
|
static String readAllAsString(InputStream in) throws IOException {
|
|
|
|
if (in == null)
|
|
|
|
return null;
|
|
|
|
try (in) {
|
|
|
|
return new String(in.readAllBytes(), "UTF-8");
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Chris Hegarty <chris.hegarty@oracle.com>
Co-authored-by: Alexandr Scherbatiy <alexandr.scherbatiy@oracle.com>
Co-authored-by: Amy Lu <amy.lu@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Daniel Fuchs <daniel.fuchs@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Jaroslav Bachorik <jaroslav.bachorik@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jan Lahoda <jan.lahoda@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Miroslav Kos <miroslav.kos@oracle.com>
Co-authored-by: Huaming Li <huaming.li@oracle.com>
Co-authored-by: Sean Mullan <sean.mullan@oracle.com>
Co-authored-by: Naoto Sato <naoto.sato@oracle.com>
Co-authored-by: Masayoshi Okutsu <masayoshi.okutsu@oracle.com>
Co-authored-by: Peter Levart <peter.levart@gmail.com>
Co-authored-by: Philip Race <philip.race@oracle.com>
Co-authored-by: Claes Redestad <claes.redestad@oracle.com>
Co-authored-by: Sergey Bylokhov <sergey.bylokhov@oracle.com>
Co-authored-by: Alexandre Iline <alexandre.iline@oracle.com>
Co-authored-by: Volker Simonis <volker.simonis@gmail.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Stuart Marks <stuart.marks@oracle.com>
Co-authored-by: Semyon Sadetsky <semyon.sadetsky@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Co-authored-by: Valerie Peng <valerie.peng@oracle.com>
Co-authored-by: Vincent Ryan <vincent.x.ryan@oracle.com>
Co-authored-by: Weijun Wang <weijun.wang@oracle.com>
Co-authored-by: Yuri Nesterenko <yuri.nesterenko@oracle.com>
Co-authored-by: Yekaterina Kantserova <yekaterina.kantserova@oracle.com>
Co-authored-by: Alexander Kulyakthin <alexander.kulyakhtin@oracle.com>
Co-authored-by: Felix Yang <felix.yang@oracle.com>
Co-authored-by: Andrei Eremeev <andrei.eremeev@oracle.com>
Co-authored-by: Frank Yuan <frank.yuan@oracle.com>
Co-authored-by: Sergei Pikalev <sergei.pikalev@oracle.com>
Co-authored-by: Sibabrata Sahoo <sibabrata.sahoo@oracle.com>
Co-authored-by: Tiantian Du <tiantian.du@oracle.com>
Co-authored-by: Sha Jiang <sha.jiang@oracle.com>
Reviewed-by: alanb, mchung, naoto, rriggs, psandoz, plevart, mullan, ascarpino, vinnie, prr, sherman, dfuchs, mhaupt
2016-03-17 19:04:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-01 08:57:53 +00:00
|
|
|
static String readAllAsString(URL url) throws IOException {
|
|
|
|
if (url == null)
|
|
|
|
return null;
|
|
|
|
InputStream in = url.openStream();
|
|
|
|
return readAllAsString(url.openStream());
|
|
|
|
}
|
|
|
|
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Chris Hegarty <chris.hegarty@oracle.com>
Co-authored-by: Alexandr Scherbatiy <alexandr.scherbatiy@oracle.com>
Co-authored-by: Amy Lu <amy.lu@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Daniel Fuchs <daniel.fuchs@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Jaroslav Bachorik <jaroslav.bachorik@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jan Lahoda <jan.lahoda@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Miroslav Kos <miroslav.kos@oracle.com>
Co-authored-by: Huaming Li <huaming.li@oracle.com>
Co-authored-by: Sean Mullan <sean.mullan@oracle.com>
Co-authored-by: Naoto Sato <naoto.sato@oracle.com>
Co-authored-by: Masayoshi Okutsu <masayoshi.okutsu@oracle.com>
Co-authored-by: Peter Levart <peter.levart@gmail.com>
Co-authored-by: Philip Race <philip.race@oracle.com>
Co-authored-by: Claes Redestad <claes.redestad@oracle.com>
Co-authored-by: Sergey Bylokhov <sergey.bylokhov@oracle.com>
Co-authored-by: Alexandre Iline <alexandre.iline@oracle.com>
Co-authored-by: Volker Simonis <volker.simonis@gmail.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Stuart Marks <stuart.marks@oracle.com>
Co-authored-by: Semyon Sadetsky <semyon.sadetsky@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Co-authored-by: Valerie Peng <valerie.peng@oracle.com>
Co-authored-by: Vincent Ryan <vincent.x.ryan@oracle.com>
Co-authored-by: Weijun Wang <weijun.wang@oracle.com>
Co-authored-by: Yuri Nesterenko <yuri.nesterenko@oracle.com>
Co-authored-by: Yekaterina Kantserova <yekaterina.kantserova@oracle.com>
Co-authored-by: Alexander Kulyakthin <alexander.kulyakhtin@oracle.com>
Co-authored-by: Felix Yang <felix.yang@oracle.com>
Co-authored-by: Andrei Eremeev <andrei.eremeev@oracle.com>
Co-authored-by: Frank Yuan <frank.yuan@oracle.com>
Co-authored-by: Sergei Pikalev <sergei.pikalev@oracle.com>
Co-authored-by: Sibabrata Sahoo <sibabrata.sahoo@oracle.com>
Co-authored-by: Tiantian Du <tiantian.du@oracle.com>
Co-authored-by: Sha Jiang <sha.jiang@oracle.com>
Reviewed-by: alanb, mchung, naoto, rriggs, psandoz, plevart, mullan, ascarpino, vinnie, prr, sherman, dfuchs, mhaupt
2016-03-17 19:04:16 +00:00
|
|
|
static void assertTrue(boolean condition) {
|
|
|
|
if (!condition) throw new RuntimeException();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void assertNull(Object o) {
|
|
|
|
assertTrue(o == null);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void assertNotNull(Object o) {
|
|
|
|
assertTrue(o != null);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void assertEquals(Object actual, Object expected) {
|
|
|
|
if (expected == null) {
|
|
|
|
assertNull(actual);
|
|
|
|
} else {
|
|
|
|
assertTrue(expected.equals(actual));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void assertNotEquals(Object actual, Object expected) {
|
|
|
|
if (expected == null) {
|
|
|
|
assertNotNull(actual);
|
|
|
|
} else {
|
|
|
|
assertTrue(!expected.equals(actual));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|