langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JDK9Wrappers.java
author alanb
Fri, 10 Feb 2017 09:06:10 +0000
changeset 43767 9cff98a149cb
parent 42822 a84956e7ee4d
child 44573 245bb4e6f983
permissions -rw-r--r--
8173393: Module system implementation refresh (2/2017) Reviewed-by: mcimadamore, mchung, alanb Contributed-by: alan.bateman@oracle.com, mandy.chung@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * accompanied this code).
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    23
 * questions.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    24
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    25
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    26
package com.sun.tools.javac.util;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    27
41440
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
    28
import java.io.IOException;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    29
import java.lang.reflect.InvocationTargetException;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    30
import java.lang.reflect.Method;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import java.nio.file.Path;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    32
import java.util.Collection;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import java.util.ServiceLoader;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    34
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    35
/**
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    36
 *  This class provides wrappers for classes and methods that are new in JDK 9, and which are not
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    37
 *  available on older versions of the platform on which javac may be compiled and run.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    38
 *  In future releases, when javac is always compiled on JDK 9 or later, the use of these wrappers
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    39
 *  can be replaced by use of the real underlying classes.
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    40
 *
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    41
 *  <p>Wrapper classes provide a subset of the API of the wrapped classes, as needed for use
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    42
 *  in javac. Wrapper objects contain an {@code Object} reference to the underlying runtime object,
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    43
 *  and {@code Class} and {@code Method} objects for obtaining or using such instances via
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    44
 *  runtime reflection.  The {@code Class} and {@code Method} objects are set up on a per-class
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    45
 *  basis, by an {@code init} method, which is called from static methods on the wrapper class,
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    46
 *  or in the constructor, when instances are created.
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    47
 *  <p>
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    48
 *
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    49
 *  <p><b>This is NOT part of any supported API.
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    50
 *  If you write code that depends on this, you do so at your own risk.
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    51
 *  This code and its internal interfaces are subject to change or
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    52
 *  deletion without notice.</b>
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    53
 */
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    54
public class JDK9Wrappers {
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    55
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    56
    /**
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    57
     * Helper class for new method in java.util.ServiceLoader.
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    58
     */
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
    public static final class ServiceLoaderHelper {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
        @SuppressWarnings("unchecked")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
        public static <S> ServiceLoader<S> load(Layer layer, Class<S> service) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
            try {
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    63
                init();
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    64
                Object result = loadMethod.invoke(null, layer.theRealLayer, service);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
                return (ServiceLoader<S>)result;
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    66
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    67
                    | SecurityException ex) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
                throw new Abort(ex);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    72
        // -----------------------------------------------------------------------------------------
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    73
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    74
        private static Method loadMethod = null;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    76
        private static void init() {
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    77
            if (loadMethod == null) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
                try {
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    79
                    Class<?> layerClass = Layer.layerClass;
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    80
                    loadMethod = ServiceLoader.class.getDeclaredMethod("load", layerClass, Class.class);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
                } catch (NoSuchMethodException | SecurityException ex) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
                    throw new Abort(ex);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    83
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    84
            }
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    85
        }
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    86
    }
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    87
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
    88
    /**
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
    89
     * Wrapper class for java.lang.module.ModuleDescriptor and ModuleDescriptor.Version.
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
    90
     */
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
    91
    public static class ModuleDescriptor {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
    92
        public static class Version {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
    93
            public static final String CLASSNAME = "java.lang.module.ModuleDescriptor$Version";
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
    94
            private final Object theRealVersion;
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
    95
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
    96
            private Version(Object version) {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
    97
                this.theRealVersion = version;
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
    98
            }
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
    99
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   100
            public static Version parse(String v) {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   101
                try {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   102
                    init();
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   103
                    Object result = parseMethod.invoke(null, v);
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   104
                    Version version = new Version(result);
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   105
                    return version;
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   106
                } catch (InvocationTargetException ex) {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   107
                    if (ex.getCause() instanceof IllegalArgumentException) {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   108
                        throw (IllegalArgumentException) ex.getCause();
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   109
                    } else {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   110
                        throw new Abort(ex);
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   111
                    }
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   112
                } catch (IllegalAccessException | IllegalArgumentException | SecurityException ex) {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   113
                    throw new Abort(ex);
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   114
                }
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   115
            }
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   116
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   117
            @Override
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   118
            public String toString() {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   119
                return theRealVersion.toString();
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   120
            }
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   121
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   122
            // -----------------------------------------------------------------------------------------
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   123
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   124
            private static Class<?> versionClass = null;
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   125
            private static Method parseMethod = null;
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   126
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   127
            private static void init() {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   128
                if (versionClass == null) {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   129
                    try {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   130
                        versionClass = Class.forName(CLASSNAME, false, null);
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   131
                        parseMethod = versionClass.getDeclaredMethod("parse", String.class);
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   132
                    } catch (ClassNotFoundException | NoSuchMethodException | SecurityException ex) {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   133
                        throw new Abort(ex);
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   134
                    }
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   135
                }
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   136
            }
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   137
        }
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   138
    }
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   139
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   140
    /**
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   141
     * Wrapper class for java.lang.module.ModuleFinder.
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   142
     */
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   143
    public static class ModuleFinder {
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   144
        private final Object theRealModuleFinder;
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   145
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   146
        private ModuleFinder(Object moduleFinder) {
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   147
            this.theRealModuleFinder = moduleFinder;
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   148
            init();
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   151
        public static ModuleFinder of(Path... dirs) {
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   152
            try {
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   153
                init();
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   154
                Object result = ofMethod.invoke(null, (Object)dirs);
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   155
                ModuleFinder mFinder = new ModuleFinder(result);
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   156
                return mFinder;
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   157
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   158
                    | SecurityException ex) {
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   159
                throw new Abort(ex);
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   160
            }
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   161
        }
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   162
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   163
        // -----------------------------------------------------------------------------------------
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   164
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   165
        private static Class<?> moduleFinderClass = null;
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   166
        private static Method ofMethod;
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   167
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   168
        static final Class<?> getModuleFinderClass() {
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   169
            init();
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   170
            return moduleFinderClass;
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   171
        }
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   172
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   173
        private static void init() {
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   174
            if (moduleFinderClass == null) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   175
                try {
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   176
                    moduleFinderClass = Class.forName("java.lang.module.ModuleFinder", false, null);
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   177
                    ofMethod = moduleFinderClass.getDeclaredMethod("of", Path[].class);
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   178
                } catch (ClassNotFoundException | NoSuchMethodException | SecurityException ex) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
                    throw new Abort(ex);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   181
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   185
    /**
41033
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   186
     * Wrapper class for java.lang.reflect.Module. To materialize a handle use the static factory
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   187
     * methods Module#getModule(Class<?>) or Module#getUnnamedModule(ClassLoader).
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   188
     */
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   189
    public static class Module {
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   190
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   191
        private final Object theRealModule;
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   192
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   193
        private Module(Object module) {
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   194
            this.theRealModule = module;
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   195
            init();
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   196
        }
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   197
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   198
        public static Module getModule(Class<?> clazz) {
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   199
            try {
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   200
                init();
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   201
                Object result = getModuleMethod.invoke(clazz, new Object[0]);
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   202
                return new Module(result);
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   203
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   204
                    | SecurityException ex) {
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   205
                throw new Abort(ex);
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   206
            }
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   207
        }
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   208
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   209
        public static Module getUnnamedModule(ClassLoader classLoader) {
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   210
            try {
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   211
                init();
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   212
                Object result = getUnnamedModuleMethod.invoke(classLoader, new Object[0]);
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   213
                return new Module(result);
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   214
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   215
                    | SecurityException ex) {
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   216
                throw new Abort(ex);
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   217
            }
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   218
        }
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   219
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   220
        public Module addExports(String pn, Module other) {
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   221
            try {
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   222
                addExportsMethod.invoke(theRealModule, new Object[] { pn, other.theRealModule});
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   223
            } catch (IllegalAccessException | InvocationTargetException ex) {
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   224
                throw new Abort(ex);
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   225
            }
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   226
            return this;
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   227
        }
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   228
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   229
        public Module addUses(Class<?> st) {
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   230
            try {
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   231
                addUsesMethod.invoke(theRealModule, new Object[] { st });
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   232
            } catch (IllegalAccessException | InvocationTargetException ex) {
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   233
                throw new Abort(ex);
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   234
            }
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   235
            return this;
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   236
        }
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   237
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   238
        // -----------------------------------------------------------------------------------------
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   239
        // on java.lang.reflect.Module
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   240
        private static Method addExportsMethod = null;
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   241
        // on java.lang.reflect.Module
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   242
        private static Method addUsesMethod = null;
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   243
        // on java.lang.Class
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   244
        private static Method getModuleMethod;
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   245
        // on java.lang.ClassLoader
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   246
        private static Method getUnnamedModuleMethod;
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   247
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   248
        private static void init() {
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   249
            if (addExportsMethod == null) {
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   250
                try {
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   251
                    Class<?> moduleClass = Class.forName("java.lang.reflect.Module", false, null);
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   252
                    addUsesMethod = moduleClass.getDeclaredMethod("addUses", new Class<?>[] { Class.class });
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   253
                    addExportsMethod = moduleClass.getDeclaredMethod("addExports",
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   254
                                                        new Class<?>[] { String.class, moduleClass });
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   255
                    getModuleMethod = Class.class.getDeclaredMethod("getModule", new Class<?>[0]);
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   256
                    getUnnamedModuleMethod = ClassLoader.class.getDeclaredMethod("getUnnamedModule", new Class<?>[0]);
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   257
                } catch (ClassNotFoundException | NoSuchMethodException | SecurityException ex) {
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   258
                    throw new Abort(ex);
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   259
                }
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   260
            }
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   261
        }
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   262
    }
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   263
49af2ecba616 8164742: ServiceConfigurationError on invoke of getServiceLoader method of StandardJavaFileManager
sadayapalam
parents: 40308
diff changeset
   264
    /**
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   265
     * Wrapper class for java.lang.module.Configuration.
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   266
     */
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   267
    public static final class Configuration {
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   268
        private final Object theRealConfiguration;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   269
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   270
        private Configuration(Object configuration) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   271
            this.theRealConfiguration = configuration;
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   272
            init();
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   273
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   274
43767
9cff98a149cb 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42822
diff changeset
   275
        public Configuration resolveAndBind(
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   276
                ModuleFinder beforeFinder,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   277
                ModuleFinder afterFinder,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   278
                Collection<String> roots) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   279
            try {
43767
9cff98a149cb 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42822
diff changeset
   280
                Object result = resolveAndBindMethod.invoke(theRealConfiguration,
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   281
                                    beforeFinder.theRealModuleFinder,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   282
                                    afterFinder.theRealModuleFinder,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   283
                                    roots
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   284
                                );
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   285
                Configuration configuration = new Configuration(result);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   286
                return configuration;
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   287
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   288
                    | SecurityException ex) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   289
                throw new Abort(ex);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   290
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   291
        }
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   292
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   293
        // -----------------------------------------------------------------------------------------
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   294
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   295
        private static Class<?> configurationClass = null;
43767
9cff98a149cb 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42822
diff changeset
   296
        private static Method resolveAndBindMethod;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   297
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   298
        static final Class<?> getConfigurationClass() {
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   299
            init();
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   300
            return configurationClass;
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   301
        }
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   302
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   303
        private static void init() {
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   304
            if (configurationClass == null) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   305
                try {
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   306
                    configurationClass = Class.forName("java.lang.module.Configuration", false, null);
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   307
                    Class<?> moduleFinderInterface = ModuleFinder.getModuleFinderClass();
43767
9cff98a149cb 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42822
diff changeset
   308
                    resolveAndBindMethod = configurationClass.getDeclaredMethod("resolveAndBind",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   309
                                moduleFinderInterface,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   310
                                moduleFinderInterface,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   311
                                Collection.class
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   312
                    );
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   313
                } catch (ClassNotFoundException | NoSuchMethodException | SecurityException ex) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   314
                    throw new Abort(ex);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   315
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   316
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   317
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   318
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   319
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   320
    /**
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   321
     * Wrapper class for java.lang.module.Layer.
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   322
     */
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   323
    public static final class Layer {
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   324
        private final Object theRealLayer;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   325
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   326
        private Layer(Object layer) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   327
            this.theRealLayer = layer;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   328
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   329
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   330
        public static Layer boot() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   331
            try {
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   332
                init();
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   333
                Object result = bootMethod.invoke(null);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   334
                Layer layer = new Layer(result);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   335
                return layer;
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   336
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   337
                    | SecurityException ex) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   338
                throw new Abort(ex);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   339
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   340
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   341
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   342
        public Configuration configuration() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   343
            try {
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   344
                Object result = configurationMethod.invoke(theRealLayer);
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   345
                Configuration configuration = new Configuration(result);
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   346
                return configuration;
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   347
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   348
                    | SecurityException ex) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   349
                throw new Abort(ex);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   350
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   351
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   352
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   353
        public Layer defineModulesWithOneLoader(Configuration configuration, ClassLoader parentClassLoader) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   354
            try {
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   355
                Object result = defineModulesWithOneLoaderMethod.invoke(
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   356
                        theRealLayer, configuration.theRealConfiguration, parentClassLoader);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   357
                Layer layer = new Layer(result);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   358
                return layer;
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   359
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   360
                    | SecurityException ex) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   361
                throw new Abort(ex);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   362
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   363
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   364
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   365
        // -----------------------------------------------------------------------------------------
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   366
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   367
        private static Class<?> layerClass = null;
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   368
        private static Method bootMethod;
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   369
        private static Method defineModulesWithOneLoaderMethod;
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   370
        private static Method configurationMethod;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   371
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   372
        private static void init() {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   373
            if (layerClass == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   374
                try {
38533
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   375
                    layerClass = Class.forName("java.lang.reflect.Layer", false, null);
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   376
                    bootMethod = layerClass.getDeclaredMethod("boot");
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   377
                    defineModulesWithOneLoaderMethod = layerClass.getDeclaredMethod("defineModulesWithOneLoader",
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   378
                                Configuration.getConfigurationClass(),
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   379
                                ClassLoader.class);
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   380
                    configurationMethod = layerClass.getDeclaredMethod("configuration");
2bd347dde526 8157474: clean up/simplify/rename ModuleWrappers class
jjg
parents: 37848
diff changeset
   381
                } catch (ClassNotFoundException | NoSuchMethodException | SecurityException ex) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   382
                    throw new Abort(ex);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   383
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   384
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   385
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   386
    }
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   387
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   388
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   389
    /**
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   390
     * Helper class for new method in jdk.internal.misc.VM.
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   391
     */
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   392
    public static final class VMHelper {
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   393
        public static final String CLASSNAME = "jdk.internal.misc.VM";
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   394
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   395
        @SuppressWarnings("unchecked")
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   396
        public static String[] getRuntimeArguments() {
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   397
            try {
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   398
                init();
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   399
                Object result = getRuntimeArgumentsMethod.invoke(null);
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   400
                return (String[])result;
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   401
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   402
                    | SecurityException ex) {
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   403
                throw new Abort(ex);
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   404
            }
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   405
        }
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   406
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   407
        // -----------------------------------------------------------------------------------------
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   408
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   409
        private static Class<?> vmClass = null;
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   410
        private static Method getRuntimeArgumentsMethod = null;
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   411
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   412
        private static void init() {
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   413
            if (vmClass == null) {
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   414
                try {
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41440
diff changeset
   415
                    vmClass = Class.forName(CLASSNAME, false, null);
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   416
                    getRuntimeArgumentsMethod = vmClass.getDeclaredMethod("getRuntimeArguments");
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   417
                } catch (ClassNotFoundException | NoSuchMethodException | SecurityException ex) {
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   418
                    throw new Abort(ex);
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   419
                }
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   420
            }
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   421
        }
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38533
diff changeset
   422
    }
41440
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   423
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   424
    /**
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   425
     * Helper class for new method in jdk.internal.jmod.JmodFile
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   426
     */
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   427
    public static final class JmodFile {
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   428
        public static final String JMOD_FILE_CLASSNAME = "jdk.internal.jmod.JmodFile";
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   429
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   430
        public static void checkMagic(Path file) throws IOException {
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   431
            try {
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   432
                init();
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   433
                checkMagicMethod.invoke(null, file);
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   434
            } catch (InvocationTargetException ex) {
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   435
                if (ex.getCause() instanceof IOException) {
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   436
                    throw IOException.class.cast(ex.getCause());
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   437
                }
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   438
                throw new Abort(ex);
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   439
            } catch (IllegalAccessException | IllegalArgumentException | SecurityException ex) {
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   440
                throw new Abort(ex);
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   441
            }
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   442
        }
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   443
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   444
        // -----------------------------------------------------------------------------------------
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   445
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   446
        private static Class<?> jmodFileClass = null;
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   447
        private static Method checkMagicMethod = null;
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   448
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   449
        private static void init() {
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   450
            if (jmodFileClass == null) {
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   451
                try {
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   452
                    jmodFileClass = Class.forName(JMOD_FILE_CLASSNAME, false, null);
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   453
                    checkMagicMethod = jmodFileClass.getDeclaredMethod("checkMagic", Path.class);
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   454
                } catch (ClassNotFoundException | NoSuchMethodException | SecurityException ex) {
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   455
                    throw new Abort(ex);
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   456
                }
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   457
            }
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   458
        }
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41033
diff changeset
   459
    }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   460
}