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-- |
36511 | 1 |
/* |
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
package jdk.tools.jlink.plugin; |
|
26 |
||
27 |
import java.nio.ByteOrder; |
|
28 |
import java.util.Map; |
|
38320 | 29 |
import java.util.Optional; |
30 |
import java.util.function.Function; |
|
31 |
import java.util.stream.Stream; |
|
36511 | 32 |
|
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 | 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 | 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 | 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 | 43 |
|
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 | 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 | 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 | 50 |
|
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 | 53 |
* |
54 |
* @return the entry count. |
|
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 | 57 |
|
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 | 60 |
* |
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 | 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 | 74 |
|
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 | 77 |
* |
78 |
* @param data The module data to check existence for. |
|
79 |
* @return The module data or null if not found. |
|
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 | 82 |
|
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 | 85 |
* |
86 |
* @return True, no content, false otherwise. |
|
87 |
*/ |
|
38320 | 88 |
public boolean isEmpty(); |
36511 | 89 |
|
90 |
/** |
|
91 |
* The ByteOrder currently in use when generating the jimage file. |
|
92 |
* |
|
93 |
* @return The ByteOrder. |
|
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 | 96 |
|
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 | 119 |
} |