annotate truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/profiles/SeparateClassloaderTestRunner.java @ 22530:4ba1aa33fda4

Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 06 Jan 2016 13:52:35 +0100
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22530
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
1 /*
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
4 *
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
8 *
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
13 * accompanied this code).
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
14 *
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
18 *
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
21 * questions.
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
22 */
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
23 package com.oracle.truffle.api.profiles;
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
24
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
25 import java.net.URLClassLoader;
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
26 import org.junit.runners.BlockJUnit4ClassRunner;
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
27 import org.junit.runners.model.InitializationError;
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
28
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
29 public final class SeparateClassloaderTestRunner extends BlockJUnit4ClassRunner {
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
30 public SeparateClassloaderTestRunner(Class<?> clazz) throws InitializationError {
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
31 super(getFromTestClassloader(clazz));
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
32 }
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
33
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
34 private static Class<?> getFromTestClassloader(Class<?> clazz) throws InitializationError {
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
35 try {
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
36 ClassLoader testClassLoader = new TestClassLoader();
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
37 return Class.forName(clazz.getName(), true, testClassLoader);
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
38 } catch (ClassNotFoundException e) {
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
39 throw new InitializationError(e);
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
40 }
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
41 }
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
42
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
43 public static final class Theories extends org.junit.experimental.theories.Theories {
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
44 public Theories(Class<?> clazz) throws InitializationError {
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
45 super(getFromTestClassloader(clazz));
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
46 }
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
47 }
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
48
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
49 private static class TestClassLoader extends URLClassLoader {
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
50 public TestClassLoader() {
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
51 super(((URLClassLoader) getSystemClassLoader()).getURLs());
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
52 }
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
53
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
54 @Override
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
55 public Class<?> loadClass(String name) throws ClassNotFoundException {
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
56 if (name.startsWith(Profile.class.getPackage().getName())) {
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
57 return super.findClass(name);
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
58 }
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
59 return super.loadClass(name);
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
60 }
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
61 }
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
62
4ba1aa33fda4 Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
63 }