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.internal;
26
27 import java.io.IOException;
28 import java.io.InputStream;
29 import java.nio.file.Path;
30 import java.util.Objects;
31 import java.util.stream.Stream;
32
33 /**
34 * An Archive of all content, classes, resources, configuration files, and
35 * other, for a module.
36 */
37 public interface Archive {
38
39 /**
40 * Entry is contained in an Archive
41 */
42 public abstract class Entry {
43
44 public static enum EntryType {
45 MODULE_NAME,
46 CLASS_OR_RESOURCE,
47 CONFIG,
48 NATIVE_LIB,
49 NATIVE_CMD,
50 HEADER_FILE,
51 LEGAL_NOTICE,
52 MAN_PAGE,
53 SERVICE;
54 }
55
56 private final String name;
57 private final EntryType type;
58 private final Archive archive;
59 private final String path;
60
61 /**
62 * Constructs an entry of the given archive
63 * @param archive archive
64 * @param path
65 * @param name an entry name that does not contain the module name
66 * @param type
67 */
68 public Entry(Archive archive, String path, String name, EntryType type) {
69 this.archive = Objects.requireNonNull(archive);
70 this.path = Objects.requireNonNull(path);
71 this.name = Objects.requireNonNull(name);
72 this.type = Objects.requireNonNull(type);
73 }
74
75 public final Archive archive() {
76 return archive;
77 }
78
79 public final EntryType type() {
80 return type;
81 }
82
83 /**
84 * Returns the name of this entry.
85 */
86 public final String name() {
87 return name;
88 }
89
90 /**
91 * Returns the name representing a ResourcePoolEntry in the form of:
92 * /$MODULE/$ENTRY_NAME
93 */
94 public final String getResourcePoolEntryName() {
95 return "/" + archive.moduleName() + "/" + name;
96 }
97
98 @Override
117 * Returns the path to this module's content
118 */
119 Path getPath();
120
121 /*
122 * Stream of Entry.
123 * The stream of entries needs to be closed after use
124 * since it might cover lazy I/O based resources.
125 * So callers need to use a try-with-resources block.
126 */
127 Stream<Entry> entries();
128
129 /*
130 * Open the archive
131 */
132 void open() throws IOException;
133
134 /*
135 * Close the archive
136 */
137 void close() throws IOException;
138 }
|
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.internal;
26
27 import java.io.Closeable;
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.nio.file.Path;
31 import java.util.Objects;
32 import java.util.stream.Stream;
33
34 /**
35 * An Archive of all content, classes, resources, configuration files, and
36 * other, for a module.
37 */
38 public interface Archive extends Closeable {
39
40 /**
41 * Entry is contained in an Archive
42 */
43 public abstract class Entry {
44
45 public static enum EntryType {
46 MODULE_NAME,
47 CLASS_OR_RESOURCE,
48 CONFIG,
49 NATIVE_LIB,
50 NATIVE_CMD,
51 HEADER_FILE,
52 LEGAL_NOTICE,
53 MAN_PAGE,
54 SERVICE;
55 }
56
57 private final String name;
58 private final EntryType type;
59 private final Archive archive;
60 private final String path;
61
62 /**
63 * Constructs an entry of the given archive.
64 *
65 * @param archive the archive in which this entry exists.
66 * @param path the complete path of the entry, including the module.
67 * @param name an entry name relative to its containing module.
68 * @param type the entry type.
69 */
70 public Entry(Archive archive, String path, String name, EntryType type) {
71 this.archive = Objects.requireNonNull(archive);
72 this.path = Objects.requireNonNull(path);
73 this.name = Objects.requireNonNull(name);
74 this.type = Objects.requireNonNull(type);
75 }
76
77 public final EntryType type() {
78 return type;
79 }
80
81 /**
82 * Returns the name of this entry.
83 */
84 public final String name() {
85 return name;
86 }
87
88 /**
89 * Returns the name representing a ResourcePoolEntry in the form of:
90 * /$MODULE/$ENTRY_NAME
91 */
92 public final String getResourcePoolEntryName() {
93 return "/" + archive.moduleName() + "/" + name;
94 }
95
96 @Override
115 * Returns the path to this module's content
116 */
117 Path getPath();
118
119 /*
120 * Stream of Entry.
121 * The stream of entries needs to be closed after use
122 * since it might cover lazy I/O based resources.
123 * So callers need to use a try-with-resources block.
124 */
125 Stream<Entry> entries();
126
127 /*
128 * Open the archive
129 */
130 void open() throws IOException;
131
132 /*
133 * Close the archive
134 */
135 @Override
136 void close() throws IOException;
137 }
|