-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibrary.java
More file actions
194 lines (169 loc) · 6.07 KB
/
Library.java
File metadata and controls
194 lines (169 loc) · 6.07 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
* Copyright (c) 2026.
* # 太霄玉府五雷使院镇煞符
* # 敕令:诸 BUG 急退,急急如律令!
* #
* # 雷 火 雷
* # 部 令
* # 雷 火 雷
* #
* # 净天地神咒(节选)
* # 天地自然,秽气分散,洞中玄虚,晃朗太元;
* # 八方威神,使我自然,灵宝符命,普告九天。
* #
* # 本代码受太上老君、九天应元雷声普化天尊庇佑,
* # 如生 BUG,则坎离交泰,雷火丹成,BUG 自化虚无。
*
*/
package cn.nukkitmot.exampleplugin.loader;
import java.util.Collection;
import java.util.LinkedList;
import java.util.UUID;
public class Library {
private final Collection<String> urls;
private final Collection<String> repositories;
private final String id;
private final String groupId;
private final String artifactId;
private final String version;
private final String classifier;
private final byte[] checksum;
private final Collection<Relocation> relocations;
private final boolean isolatedLoad;
private Library(Collection<String> urls, Collection<String> repositories, String id,
String groupId, String artifactId, String version, String classifier,
byte[] checksum, Collection<Relocation> relocations, boolean isolatedLoad) {
this.urls = urls;
this.repositories = repositories;
this.id = id;
this.groupId = groupId;
this.artifactId = artifactId;
this.version = version;
this.classifier = classifier;
this.checksum = checksum;
this.relocations = relocations;
this.isolatedLoad = isolatedLoad;
}
public static Library create(String groupId, String artifactId, String version) {
return builder()
.groupId(groupId)
.artifactId(artifactId)
.version(version)
.build();
}
public static Builder builder() {
return new Builder();
}
public Collection<String> getUrls() { return urls; }
public Collection<String> getRepositories() { return repositories; }
public String getId() { return id; }
public String getGroupId() { return groupId; }
public String getArtifactId() { return artifactId; }
public String getVersion() { return version; }
public String getClassifier() { return classifier; }
public byte[] getChecksum() { return checksum; }
public Collection<Relocation> getRelocations() { return relocations; }
public boolean isIsolatedLoad() { return isolatedLoad; }
public String getPath() {
StringBuilder path = new StringBuilder();
path.append(groupId.replace(".", "/"));
path.append("/");
path.append(artifactId);
path.append("/");
path.append(version);
path.append("/");
path.append(artifactId);
path.append("-");
path.append(version);
if (classifier != null && !classifier.isEmpty()) {
path.append("-").append(classifier);
}
path.append(".jar");
return path.toString();
}
public String getRelocatedPath() {
StringBuilder path = new StringBuilder();
path.append(groupId.replace(".", "/"));
path.append("/");
path.append(artifactId);
path.append("/");
path.append(version);
path.append("/");
path.append(artifactId);
path.append("-");
path.append(version);
if (classifier != null && !classifier.isEmpty()) {
path.append("-").append(classifier);
}
path.append("-relocated.jar");
return path.toString();
}
public boolean hasChecksum() {
return checksum != null && checksum.length > 0;
}
public boolean hasRelocations() {
return relocations != null && !relocations.isEmpty();
}
public static class Builder {
private final Collection<String> urls = new LinkedList<>();
private final Collection<String> repositories = new LinkedList<>();
private String id;
private String groupId;
private String artifactId;
private String version;
private String classifier;
private byte[] checksum;
private boolean isolatedLoad;
private final Collection<Relocation> relocations = new LinkedList<>();
public Builder url(String url) {
this.urls.add(url);
return this;
}
public Builder repository(String url) {
this.repositories.add(url.endsWith("/") ? url : url + "/");
return this;
}
public Builder id(String id) {
this.id = id != null ? id : UUID.randomUUID().toString();
return this;
}
public Builder groupId(String groupId) {
this.groupId = groupId;
return this;
}
public Builder artifactId(String artifactId) {
this.artifactId = artifactId;
return this;
}
public Builder version(String version) {
this.version = version;
return this;
}
public Builder classifier(String classifier) {
this.classifier = classifier;
return this;
}
public Builder checksum(byte[] checksum) {
this.checksum = checksum;
return this;
}
public Builder checksum(String checksum) {
return this.checksum(java.util.Base64.getDecoder().decode(checksum));
}
public Builder isolatedLoad(boolean isolatedLoad) {
this.isolatedLoad = isolatedLoad;
return this;
}
public Builder relocate(Relocation relocation) {
this.relocations.add(relocation);
return this;
}
public Builder relocate(String pattern, String relocatedPattern) {
return this.relocate(new Relocation(pattern, relocatedPattern));
}
public Library build() {
return new Library(urls, repositories, id, groupId, artifactId, version,
classifier, checksum, relocations, isolatedLoad);
}
}
}