-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
ClassPathElement.java
149 lines (125 loc) · 4.04 KB
/
ClassPathElement.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package io.quarkus.bootstrap.classloading;
import java.io.Closeable;
import java.nio.file.Path;
import java.security.ProtectionDomain;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.function.Function;
import java.util.jar.Manifest;
import io.quarkus.maven.dependency.ArtifactKey;
import io.quarkus.maven.dependency.ResolvedDependency;
import io.quarkus.paths.EmptyPathTree;
import io.quarkus.paths.OpenPathTree;
import io.quarkus.paths.PathTree;
/**
* Represents an element on the virtual classpath, such as a jar file or classes
* directory.
*/
public interface ClassPathElement extends Closeable {
/**
* If this classpath element represents a Maven artifact, the method will return its key,
* otherwise - null.
*
* @return the key of the Maven artifact this classpath element represents or null, in case
* this element does not represent any Maven artifact
*/
default ArtifactKey getDependencyKey() {
ResolvedDependency resolvedDependency = getResolvedDependency();
return resolvedDependency != null ? resolvedDependency.getKey() : null;
}
/**
* If this classpath element represents a Maven artifact, the method will return it,
* otherwise - null.
*
* @return the Maven artifact this classpath element represents or null, in case
* this element does not represent any Maven artifact
*/
default ResolvedDependency getResolvedDependency() {
return null;
}
/**
*
* @return The element root, or null if not applicable
*/
Path getRoot();
/**
* Processes the content of this classpath element and returns a result.
*
* @param <T> result type
* @param func content processing function
* @return processing result
*/
<T> T apply(Function<OpenPathTree, T> func);
/**
* Loads a resource from the class path element, or null if it does not exist.
*
* @param name The resource to load
* @return An representation of the class path resource if it exists
*/
ClassPathResource getResource(String name);
/**
* Returns a set of all known resources.
*
* @return A set representing all known resources
*/
Set<String> getProvidedResources();
/**
*
* @return The protection domain that should be used to define classes from this element
*/
ProtectionDomain getProtectionDomain();
Manifest getManifest();
/**
* Checks whether this is a runtime classpath element
*
* @return true in case this is a runtime classpath element, otherwise - false
*/
boolean isRuntime();
/**
* Creates an element from a file system path
*/
static ClassPathElement fromPath(Path path, boolean runtime) {
return new PathTreeClassPathElement(PathTree.ofDirectoryOrArchive(path),
runtime);
}
static ClassPathElement fromDependency(ResolvedDependency dep) {
return new PathTreeClassPathElement(dep.getContentTree(), dep.isRuntimeCp(), dep);
}
static ClassPathElement EMPTY = new ClassPathElement() {
@Override
public Path getRoot() {
return null;
}
@Override
public boolean isRuntime() {
return false;
}
@Override
public <T> T apply(Function<OpenPathTree, T> func) {
return func.apply(EmptyPathTree.getInstance());
}
@Override
public ClassPathResource getResource(String name) {
return null;
}
@Override
public Set<String> getProvidedResources() {
return Collections.emptySet();
}
@Override
public ProtectionDomain getProtectionDomain() {
return null;
}
@Override
public Manifest getManifest() {
return null;
}
@Override
public void close() {
}
};
default List<ClassPathResource> getResources(String name) {
return List.of(getResource(name));
}
}