src/jdk.jlink/share/classes/jdk/tools/jlink/plugin/ResourcePool.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 39894 jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/plugin/ResourcePool.java@cd4f403f9618
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * accompanied this code).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    23
 * questions.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    24
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
package jdk.tools.jlink.plugin;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
import java.nio.ByteOrder;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
import java.util.Map;
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37600
diff changeset
    29
import java.util.Optional;
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37600
diff changeset
    30
import java.util.function.Function;
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37600
diff changeset
    31
import java.util.stream.Stream;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
/**
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
    34
 * A Pool of Java resources.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
 */
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
    36
public interface ResourcePool {
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
    37
    /**
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
    38
     * Return the module view of this resource pool.
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37600
diff changeset
    39
     *
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
    40
     * @return a module based view of this resource pool.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
     */
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
    42
    public ResourcePoolModuleView moduleView();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
    /**
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
    45
     * Get all ResourcePoolEntry contained in this ResourcePool instance.
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37600
diff changeset
    46
     *
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
    47
     * @return The stream of ResourcePoolEntries.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
     */
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
    49
    public Stream<ResourcePoolEntry> entries();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
    /**
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
    52
     * Return the number of ResourcePoolEntry count in this ResourcePool.
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37600
diff changeset
    53
     *
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37600
diff changeset
    54
     * @return the entry count.
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37600
diff changeset
    55
     */
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
    56
    public int entryCount();
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37600
diff changeset
    57
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37600
diff changeset
    58
    /**
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
    59
     * Get the ResourcePoolEntry for the passed path.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
     * @param path A data path
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
    62
     * @return A ResourcePoolEntry instance or null if the data is not found
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
     */
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
    64
    public Optional<ResourcePoolEntry> findEntry(String path);
39635
07c4b195280d 8161067: jlink: Enable plugins to use the module pool for class lookup
jlaskey
parents: 38320
diff changeset
    65
07c4b195280d 8161067: jlink: Enable plugins to use the module pool for class lookup
jlaskey
parents: 38320
diff changeset
    66
    /**
07c4b195280d 8161067: jlink: Enable plugins to use the module pool for class lookup
jlaskey
parents: 38320
diff changeset
    67
     * Get the ModuleEntry for the passed path restricted to supplied context.
07c4b195280d 8161067: jlink: Enable plugins to use the module pool for class lookup
jlaskey
parents: 38320
diff changeset
    68
     *
07c4b195280d 8161067: jlink: Enable plugins to use the module pool for class lookup
jlaskey
parents: 38320
diff changeset
    69
     * @param path A data path
07c4b195280d 8161067: jlink: Enable plugins to use the module pool for class lookup
jlaskey
parents: 38320
diff changeset
    70
     * @param context A context of the search
07c4b195280d 8161067: jlink: Enable plugins to use the module pool for class lookup
jlaskey
parents: 38320
diff changeset
    71
     * @return A ModuleEntry instance or null if the data is not found
07c4b195280d 8161067: jlink: Enable plugins to use the module pool for class lookup
jlaskey
parents: 38320
diff changeset
    72
     */
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
    73
    public Optional<ResourcePoolEntry> findEntryInContext(String path, ResourcePoolEntry context);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    75
    /**
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
    76
     * Check if the ResourcePool contains the given ResourcePoolEntry.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
     * @param data The module data to check existence for.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
     * @return The module data or null if not found.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
     */
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
    81
    public boolean contains(ResourcePoolEntry data);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
    /**
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
    84
     * Check if the ResourcePool contains some content at all.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    85
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    86
     * @return True, no content, false otherwise.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
     */
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37600
diff changeset
    88
    public boolean isEmpty();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    91
     * The ByteOrder currently in use when generating the jimage file.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
     * @return The ByteOrder.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
     */
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
    95
    public ByteOrder byteOrder();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    96
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    97
    /**
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
    98
     * Visit each ResourcePoolEntry in this ResourcePool to transform it and copy
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
    99
     * the transformed ResourcePoolEntry to the output ResourcePoolBuilder.
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   100
     *
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   101
     * @param transform The function called for each ResourcePoolEntry found in the
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   102
     * ResourcePool. The transform function should return a ResourcePoolEntry
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   103
     * instance which will be added to the output or it should return null if
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   104
     * the passed ResourcePoolEntry is to be ignored for the output.
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   105
     *
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   106
     * @param outBuilder The ResourcePoolBuilder to be filled with Visitor returned
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   107
     * ResourcePoolEntries.
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   108
     */
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   109
    public default void transformAndCopy(
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   110
            Function<ResourcePoolEntry, ResourcePoolEntry> transform,
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   111
            ResourcePoolBuilder outBuilder) {
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   112
        entries().forEach(resource -> {
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   113
            ResourcePoolEntry res = transform.apply(resource);
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   114
            if (res != null) {
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   115
                outBuilder.add(res);
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   116
            }
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   117
        });
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   118
    }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   119
}