fix(maven): resolve Named Locks and proxy auth, add missing dependencies and improve types
This commit is contained in:
1 parent
cd6a4c70e7
commit
9d7e42eda8
52 files changed
+74
-5023
No files matched your search
@@ -19,7 +19,6 @@ hs_err_pid*
|
|||||||
replay_pid*
|
replay_pid*
|
||||||
|
|
||||||
# Maven
|
# Maven
|
||||||
.mvn/
|
|
||||||
mvnw
|
mvnw
|
||||||
mvnw.cmd
|
mvnw.cmd
|
||||||
|
|
||||||
|
|||||||
Generated
+5
@@ -16,5 +16,10 @@
|
|||||||
<option name="name" value="JBoss Community repository" />
|
<option name="name" value="JBoss Community repository" />
|
||||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||||
</remote-repository>
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Central Repository" />
|
||||||
|
<option name="url" value="https://maven.aliyun.com/repository/public" />
|
||||||
|
</remote-repository>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
Generated
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
-Daether.syncContext.named.factory=noop
|
||||||
|
-Daether.connector.basic.threads=1
|
||||||
|
-Daether.connector.http.preemptiveAuth=true
|
||||||
|
-Djdk.http.auth.tunneling.disabledSchemes=""
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
-Daether.syncContext.named.factory=noop
|
||||||
|
-Daether.connector.basic.threads=1
|
||||||
|
-Daether.connector.http.preemptiveAuth=true
|
||||||
@@ -50,6 +50,10 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-websocket</artifactId>
|
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-mail</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||||
@@ -62,6 +66,26 @@
|
|||||||
<artifactId>aws-java-sdk-s3</artifactId>
|
<artifactId>aws-java-sdk-s3</artifactId>
|
||||||
<version>${aws.sdk.version}</version>
|
<version>${aws.sdk.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>software.amazon.awssdk</groupId>
|
||||||
|
<artifactId>kinesisvideo</artifactId>
|
||||||
|
<version>2.25.21</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>software.amazon.awssdk</groupId>
|
||||||
|
<artifactId>kinesisvideosignaling</artifactId>
|
||||||
|
<version>2.25.21</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.xml.bind</groupId>
|
||||||
|
<artifactId>jaxb-api</artifactId>
|
||||||
|
<version>2.3.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fatboyindustrial.gson-jodatime-serialisers</groupId>
|
||||||
|
<artifactId>gson-jodatime-serialisers</artifactId>
|
||||||
|
<version>1.8.0</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.azure</groupId>
|
<groupId>com.azure</groupId>
|
||||||
<artifactId>azure-storage-blob</artifactId>
|
<artifactId>azure-storage-blob</artifactId>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import org.springframework.core.convert.converter.Converter;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class JsonElementConverter implements Converter {
|
public class JsonElementConverter implements Converter<String, JsonElement> {
|
||||||
public JsonElement convert(String source) {
|
public JsonElement convert(String source) {
|
||||||
try {
|
try {
|
||||||
source = URLDecoder.decode(source, Charset.defaultCharset());
|
source = URLDecoder.decode(source, Charset.defaultCharset());
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import org.springframework.core.convert.converter.Converter;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class JsonObjectConverter implements Converter {
|
public class JsonObjectConverter implements Converter<String, JsonObject> {
|
||||||
public JsonObject convert(String source) {
|
public JsonObject convert(String source) {
|
||||||
try {
|
try {
|
||||||
source = URLDecoder.decode(source, Charset.defaultCharset());
|
source = URLDecoder.decode(source, Charset.defaultCharset());
|
||||||
|
|||||||
@@ -116,8 +116,10 @@ public class BaseFile {
|
|||||||
this.extra = new DbObject();
|
this.extra = new DbObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
parameters.forEach((key, value) -> {
|
parameters.forEach((k, v) -> {
|
||||||
if (value.length > 0 && key.startsWith("extra.")) {
|
String key = (String) k;
|
||||||
|
String[] value = (String[]) v;
|
||||||
|
if (value != null && value.length > 0 && key.startsWith("extra.")) {
|
||||||
this.extra.put(key.substring(6), value.length == 1 ? value[0] : Arrays.asList(value));
|
this.extra.put(key.substring(6), value.length == 1 ? value[0] : Arrays.asList(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
|
|||||||
* @author MiDM Core Platform Team
|
* @author MiDM Core Platform Team
|
||||||
*/
|
*/
|
||||||
@Document
|
@Document
|
||||||
public class OtaFile extends BaseFile implements Comparable {
|
public class OtaFile extends BaseFile implements Comparable<OtaFile> {
|
||||||
/** Android Recovery 固件升级脚本入口 */
|
/** Android Recovery 固件升级脚本入口 */
|
||||||
private static final String ENTRY_META_INF = "META-INF/com/";
|
private static final String ENTRY_META_INF = "META-INF/com/";
|
||||||
private static final String ENTRY_UPDATE_SCRIPT = "META-INF/com/google/android/updater-script";
|
private static final String ENTRY_UPDATE_SCRIPT = "META-INF/com/google/android/updater-script";
|
||||||
@@ -643,7 +643,7 @@ public class OtaFile extends BaseFile implements Comparable {
|
|||||||
break;
|
break;
|
||||||
case "display-id":
|
case "display-id":
|
||||||
case "ro.build.display.id":
|
case "ro.build.display.id":
|
||||||
String curDisplayId = this.getDisplayId();
|
curDisplayId = this.getDisplayId();
|
||||||
if (Strings.isNullOrEmpty(curDisplayId) || !curDisplayId.equals(value)) {
|
if (Strings.isNullOrEmpty(curDisplayId) || !curDisplayId.equals(value)) {
|
||||||
this.setDisplayId(value);
|
this.setDisplayId(value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public class SiteInfo {
|
|||||||
return this.isEnabled() && !this.getRoles().isEmpty() && this.getRoles().contains(role);
|
return this.isEnabled() && !this.getRoles().isEmpty() && this.getRoles().contains(role);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasRole(Collection roles) {
|
public boolean hasRole(Collection<String> roles) {
|
||||||
if (this.isEnabled() && !this.getRoles().isEmpty()) {
|
if (this.isEnabled() && !this.getRoles().isEmpty()) {
|
||||||
for(String role : roles) {
|
for(String role : roles) {
|
||||||
if (this.getRoles().contains(role)) {
|
if (this.getRoles().contains(role)) {
|
||||||
@@ -72,7 +72,7 @@ public class SiteInfo {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRoles(Set roles) {
|
public void setRoles(Set<String> roles) {
|
||||||
if (roles != null && !roles.isEmpty()) {
|
if (roles != null && !roles.isEmpty()) {
|
||||||
for(String role : roles) {
|
for(String role : roles) {
|
||||||
role = UserRole.toRole(role);
|
role = UserRole.toRole(role);
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class User extends GeneralProfile {
|
|||||||
serialize = false
|
serialize = false
|
||||||
)
|
)
|
||||||
private String password;
|
private String password;
|
||||||
private List sites;
|
private List<SiteInfo> sites;
|
||||||
@Transient
|
@Transient
|
||||||
private boolean isMultiSiteUser;
|
private boolean isMultiSiteUser;
|
||||||
@Transient
|
@Transient
|
||||||
@@ -172,7 +172,7 @@ public class User extends GeneralProfile {
|
|||||||
this.siteInfo = siteInfo;
|
this.siteInfo = siteInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List getSites() {
|
public List<SiteInfo> getSites() {
|
||||||
if (this.sites == null) {
|
if (this.sites == null) {
|
||||||
this.sites = new ArrayList();
|
this.sites = new ArrayList();
|
||||||
}
|
}
|
||||||
@@ -180,8 +180,8 @@ public class User extends GeneralProfile {
|
|||||||
return this.sites;
|
return this.sites;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List getSiteUuids() {
|
public List<UUID> getSiteUuids() {
|
||||||
return this.sites != null && !this.sites.isEmpty() ? (List)this.sites.stream().map((item) -> item.getSiteUuid()).collect(Collectors.toList()) : null;
|
return this.sites != null && !this.sites.isEmpty() ? (List<UUID>)this.sites.stream().map(SiteInfo::getSiteUuid).collect(Collectors.toList()) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean clearUndefinedSites() {
|
public boolean clearUndefinedSites() {
|
||||||
@@ -201,7 +201,7 @@ public class User extends GeneralProfile {
|
|||||||
return hasChanges;
|
return hasChanges;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSites(List sites) {
|
public void setSites(List<SiteInfo> sites) {
|
||||||
this.sites = sites;
|
this.sites = sites;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ public class NewsMessageService extends BaseService {
|
|||||||
this.messageLogService.deleteByNewsMessage(newsMessage);
|
this.messageLogService.deleteByNewsMessage(newsMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(List newsMessage) {
|
public void delete(List<NewsMessage> newsMessage) {
|
||||||
List<UUID> uuids = (List)newsMessage.stream().map(NewsMessage::getUuid).collect(Collectors.toList());
|
List<UUID> uuids = (List)newsMessage.stream().map(NewsMessage::getUuid).collect(Collectors.toList());
|
||||||
Query query = Query.query(Criteria.where("_id").in(uuids));
|
Query query = Query.query(Criteria.where("_id").in(uuids));
|
||||||
this.mongoTemplate.remove(query, NewsMessage.class);
|
this.mongoTemplate.remove(query, NewsMessage.class);
|
||||||
@@ -204,7 +204,7 @@ public class NewsMessageService extends BaseService {
|
|||||||
this.sendNotification(mails, newsMessage);
|
this.sendNotification(mails, newsMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendNotification(Collection mails, NewsMessage message) {
|
private void sendNotification(Collection<UserMail> mails, NewsMessage message) {
|
||||||
Map<String, InternetAddress> recipients = (Map)mails.stream().collect(Collectors.toMap(UserMail::getEmail, (user) -> user.toAddress()));
|
Map<String, InternetAddress> recipients = (Map)mails.stream().collect(Collectors.toMap(UserMail::getEmail, (user) -> user.toAddress()));
|
||||||
List<InternetAddress> mailsTo = message.getMailsTo();
|
List<InternetAddress> mailsTo = message.getMailsTo();
|
||||||
if (mailsTo != null && !mailsTo.isEmpty()) {
|
if (mailsTo != null && !mailsTo.isEmpty()) {
|
||||||
@@ -229,8 +229,8 @@ public class NewsMessageService extends BaseService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendMail(McMailSender sender, List addresses) {
|
private void sendMail(McMailSender sender, List<InternetAddress> addresses) {
|
||||||
for(List oneList : Lists.partition(addresses, 40)) {
|
for(List<InternetAddress> oneList : Lists.partition(addresses, 40)) {
|
||||||
sender.clearBcc();
|
sender.clearBcc();
|
||||||
sender.addBcc(oneList);
|
sender.addBcc(oneList);
|
||||||
sender.send();
|
sender.send();
|
||||||
@@ -528,7 +528,7 @@ public class NewsMessageService extends BaseService {
|
|||||||
ref.put("errorCode", error.getValue());
|
ref.put("errorCode", error.getValue());
|
||||||
Set<String> ssnSet = null;
|
Set<String> ssnSet = null;
|
||||||
if (REPORT_ERROR.COLLECT_SSN.contains(error)) {
|
if (REPORT_ERROR.COLLECT_SSN.contains(error)) {
|
||||||
Set ssnSet = new HashSet(Arrays.asList(device.getSerialNo()));
|
ssnSet = new HashSet(Arrays.asList(device.getSerialNo()));
|
||||||
ref.put("device", new HashSet(ssnSet));
|
ref.put("device", new HashSet(ssnSet));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ public class UserService extends BaseService {
|
|||||||
this.mongoTemplate.updateMulti(query, update, User.class);
|
this.mongoTemplate.updateMulti(query, update, User.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List saveUsers(List users) {
|
public List<User> saveUsers(List<User> users) {
|
||||||
List<User> savedUsers = new ArrayList();
|
List<User> savedUsers = new ArrayList();
|
||||||
|
|
||||||
for(User user : users) {
|
for(User user : users) {
|
||||||
|
|||||||
@@ -134,17 +134,17 @@ public class DbObject extends Document {
|
|||||||
for(String key : keys) {
|
for(String key : keys) {
|
||||||
Object value = dbObject.get(key);
|
Object value = dbObject.get(key);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
Object var8 = new DbObject();
|
DbObject var8 = new DbObject();
|
||||||
dbObject.put(key, var8);
|
dbObject.put(key, var8);
|
||||||
dbObject = var8;
|
dbObject = var8;
|
||||||
} else if (value instanceof DbObject) {
|
} else if (value instanceof DbObject) {
|
||||||
dbObject = (DbObject)value;
|
dbObject = (DbObject)value;
|
||||||
} else if (value instanceof Map) {
|
} else if (value instanceof Map) {
|
||||||
Object var9 = new DbObject((Map)value);
|
DbObject var9 = new DbObject((Map)value);
|
||||||
dbObject.put(key, var9);
|
dbObject.put(key, var9);
|
||||||
dbObject = var9;
|
dbObject = var9;
|
||||||
} else {
|
} else {
|
||||||
Object var10 = new DbObject();
|
DbObject var10 = new DbObject();
|
||||||
dbObject.put(key, var10);
|
dbObject.put(key, var10);
|
||||||
dbObject = var10;
|
dbObject = var10;
|
||||||
}
|
}
|
||||||
@@ -157,7 +157,7 @@ public class DbObject extends Document {
|
|||||||
if (clazz.equals(DbObject.class)) {
|
if (clazz.equals(DbObject.class)) {
|
||||||
List<Object> list = super.getList(key, Object.class);
|
List<Object> list = super.getList(key, Object.class);
|
||||||
if (list != null) {
|
if (list != null) {
|
||||||
List<T> listDbObject = new ArrayList();
|
List listDbObject = new ArrayList();
|
||||||
list.forEach((item) -> {
|
list.forEach((item) -> {
|
||||||
if (item instanceof Map) {
|
if (item instanceof Map) {
|
||||||
listDbObject.add(new DbObject((Map)item));
|
listDbObject.add(new DbObject((Map)item));
|
||||||
@@ -172,7 +172,7 @@ public class DbObject extends Document {
|
|||||||
} else if (clazz.equals(UUID.class)) {
|
} else if (clazz.equals(UUID.class)) {
|
||||||
List<Object> list = super.getList(key, Object.class);
|
List<Object> list = super.getList(key, Object.class);
|
||||||
if (list != null) {
|
if (list != null) {
|
||||||
List<T> listDbObject = new ArrayList();
|
List listDbObject = new ArrayList();
|
||||||
list.forEach((item) -> {
|
list.forEach((item) -> {
|
||||||
if (item instanceof UUID) {
|
if (item instanceof UUID) {
|
||||||
listDbObject.add(item);
|
listDbObject.add(item);
|
||||||
|
|||||||
@@ -203,20 +203,20 @@ public class Vector2Svg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class Group {
|
private class Group {
|
||||||
private final List paths;
|
private final List<VectorPath> paths;
|
||||||
|
|
||||||
public Group(List paths) {
|
public Group(List<VectorPath> paths) {
|
||||||
this.paths = paths;
|
this.paths = paths;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AndroidVectorDrawable {
|
private class AndroidVectorDrawable {
|
||||||
private final List paths;
|
private final List<VectorPath> paths;
|
||||||
private final List groups;
|
private final List<Group> groups;
|
||||||
private final double height;
|
private final double height;
|
||||||
private final double width;
|
private final double width;
|
||||||
|
|
||||||
private AndroidVectorDrawable(List paths, List groups, double width, double height) {
|
private AndroidVectorDrawable(List<VectorPath> paths, List<Group> groups, double width, double height) {
|
||||||
this.paths = paths;
|
this.paths = paths;
|
||||||
this.groups = groups;
|
this.groups = groups;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ public class HwInfo {
|
|||||||
BufferedReader bufferedReader = new BufferedReader(reader);
|
BufferedReader bufferedReader = new BufferedReader(reader);
|
||||||
|
|
||||||
String line;
|
String line;
|
||||||
for(line = null; (line = bufferedReader.readLine()) != null && (Strings.isNullOrEmpty(line) || line.startsWith("IdentifyingNumber")); var6 = null) {
|
while ((line = bufferedReader.readLine()) != null && (Strings.isNullOrEmpty(line) || line.startsWith("IdentifyingNumber"))) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line != null && line.length() >= 19) {
|
if (line != null && line.length() >= 19) {
|
||||||
|
|||||||
@@ -1,119 +0,0 @@
|
|||||||
package org.springframework.boot.loader;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
final class ClassPathIndexFile {
|
|
||||||
private final File root;
|
|
||||||
private final List lines;
|
|
||||||
|
|
||||||
private ClassPathIndexFile(File root, List lines) {
|
|
||||||
this.root = root;
|
|
||||||
this.lines = (List)lines.stream().map(this::extractName).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
private String extractName(String line) {
|
|
||||||
if (line.startsWith("- \"") && line.endsWith("\"")) {
|
|
||||||
return line.substring(3, line.length() - 1);
|
|
||||||
} else {
|
|
||||||
throw new IllegalStateException("Malformed classpath index line [" + line + "]");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int size() {
|
|
||||||
return this.lines.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean containsEntry(String name) {
|
|
||||||
return name != null && !name.isEmpty() ? this.lines.contains(name) : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
List getUrls() {
|
|
||||||
return Collections.unmodifiableList((List)this.lines.stream().map(this::asUrl).collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private URL asUrl(String line) {
|
|
||||||
try {
|
|
||||||
return (new File(this.root, line)).toURI().toURL();
|
|
||||||
} catch (MalformedURLException ex) {
|
|
||||||
throw new IllegalStateException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static ClassPathIndexFile loadIfPossible(URL root, String location) throws IOException {
|
|
||||||
return loadIfPossible(asFile(root), location);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ClassPathIndexFile loadIfPossible(File root, String location) throws IOException {
|
|
||||||
return loadIfPossible(root, new File(root, location));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ClassPathIndexFile loadIfPossible(File root, File indexFile) throws IOException {
|
|
||||||
if (indexFile.exists() && indexFile.isFile()) {
|
|
||||||
InputStream inputStream = new FileInputStream(indexFile);
|
|
||||||
Throwable var3 = null;
|
|
||||||
|
|
||||||
ClassPathIndexFile var4;
|
|
||||||
try {
|
|
||||||
var4 = new ClassPathIndexFile(root, loadLines(inputStream));
|
|
||||||
} catch (Throwable var13) {
|
|
||||||
var3 = var13;
|
|
||||||
throw var13;
|
|
||||||
} finally {
|
|
||||||
if (inputStream != null) {
|
|
||||||
if (var3 != null) {
|
|
||||||
try {
|
|
||||||
inputStream.close();
|
|
||||||
} catch (Throwable var12) {
|
|
||||||
var3.addSuppressed(var12);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
inputStream.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return var4;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List loadLines(InputStream inputStream) throws IOException {
|
|
||||||
List<String> lines = new ArrayList();
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
|
|
||||||
|
|
||||||
for(String line = reader.readLine(); line != null; line = reader.readLine()) {
|
|
||||||
if (!line.trim().isEmpty()) {
|
|
||||||
lines.add(line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Collections.unmodifiableList(lines);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static File asFile(URL url) {
|
|
||||||
if (!"file".equals(url.getProtocol())) {
|
|
||||||
throw new IllegalArgumentException("URL does not reference a file");
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
return new File(url.toURI());
|
|
||||||
} catch (URISyntaxException var2) {
|
|
||||||
return new File(url.getPath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,135 +0,0 @@
|
|||||||
package org.springframework.boot.loader;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.jar.Attributes;
|
|
||||||
import java.util.jar.Manifest;
|
|
||||||
import org.springframework.boot.loader.archive.Archive;
|
|
||||||
import org.springframework.boot.loader.archive.ExplodedArchive;
|
|
||||||
|
|
||||||
public abstract class ExecutableArchiveLauncher extends Launcher {
|
|
||||||
private static final String START_CLASS_ATTRIBUTE = "Start-Class";
|
|
||||||
protected static final String BOOT_CLASSPATH_INDEX_ATTRIBUTE = "Spring-Boot-Classpath-Index";
|
|
||||||
protected static final String DEFAULT_CLASSPATH_INDEX_FILE_NAME = "classpath.idx";
|
|
||||||
private final Archive archive;
|
|
||||||
private final ClassPathIndexFile classPathIndex;
|
|
||||||
|
|
||||||
public ExecutableArchiveLauncher() {
|
|
||||||
try {
|
|
||||||
this.archive = this.createArchive();
|
|
||||||
this.classPathIndex = this.getClassPathIndex(this.archive);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
throw new IllegalStateException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ExecutableArchiveLauncher(Archive archive) {
|
|
||||||
try {
|
|
||||||
this.archive = archive;
|
|
||||||
this.classPathIndex = this.getClassPathIndex(this.archive);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
throw new IllegalStateException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ClassPathIndexFile getClassPathIndex(Archive archive) throws IOException {
|
|
||||||
if (archive instanceof ExplodedArchive) {
|
|
||||||
String location = this.getClassPathIndexFileLocation(archive);
|
|
||||||
return ClassPathIndexFile.loadIfPossible(archive.getUrl(), location);
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getClassPathIndexFileLocation(Archive archive) throws IOException {
|
|
||||||
Manifest manifest = archive.getManifest();
|
|
||||||
Attributes attributes = manifest != null ? manifest.getMainAttributes() : null;
|
|
||||||
String location = attributes != null ? attributes.getValue("Spring-Boot-Classpath-Index") : null;
|
|
||||||
return location != null ? location : this.getArchiveEntryPathPrefix() + "classpath.idx";
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getMainClass() throws Exception {
|
|
||||||
Manifest manifest = this.archive.getManifest();
|
|
||||||
String mainClass = null;
|
|
||||||
if (manifest != null) {
|
|
||||||
mainClass = manifest.getMainAttributes().getValue("Start-Class");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mainClass == null) {
|
|
||||||
throw new IllegalStateException("No 'Start-Class' manifest entry specified in " + this);
|
|
||||||
} else {
|
|
||||||
return mainClass;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ClassLoader createClassLoader(Iterator archives) throws Exception {
|
|
||||||
List<URL> urls = new ArrayList(this.guessClassPathSize());
|
|
||||||
|
|
||||||
while(archives.hasNext()) {
|
|
||||||
urls.add(((Archive)archives.next()).getUrl());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.classPathIndex != null) {
|
|
||||||
urls.addAll(this.classPathIndex.getUrls());
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.createClassLoader((URL[])urls.toArray(new URL[0]));
|
|
||||||
}
|
|
||||||
|
|
||||||
private int guessClassPathSize() {
|
|
||||||
return this.classPathIndex != null ? this.classPathIndex.size() + 10 : 50;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Iterator getClassPathArchivesIterator() throws Exception {
|
|
||||||
Archive.EntryFilter searchFilter = this::isSearchCandidate;
|
|
||||||
Iterator<Archive> archives = this.archive.getNestedArchives(searchFilter, (entry) -> this.isNestedArchive(entry) && !this.isEntryIndexed(entry));
|
|
||||||
if (this.isPostProcessingClassPathArchives()) {
|
|
||||||
archives = this.applyClassPathArchivePostProcessing(archives);
|
|
||||||
}
|
|
||||||
|
|
||||||
return archives;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isEntryIndexed(Archive.Entry entry) {
|
|
||||||
return this.classPathIndex != null ? this.classPathIndex.containsEntry(entry.getName()) : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Iterator applyClassPathArchivePostProcessing(Iterator archives) throws Exception {
|
|
||||||
List<Archive> list = new ArrayList();
|
|
||||||
|
|
||||||
while(archives.hasNext()) {
|
|
||||||
list.add(archives.next());
|
|
||||||
}
|
|
||||||
|
|
||||||
this.postProcessClassPathArchives(list);
|
|
||||||
return list.iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isSearchCandidate(Archive.Entry entry) {
|
|
||||||
return this.getArchiveEntryPathPrefix() == null ? true : entry.getName().startsWith(this.getArchiveEntryPathPrefix());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract boolean isNestedArchive(Archive.Entry entry);
|
|
||||||
|
|
||||||
protected boolean isPostProcessingClassPathArchives() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void postProcessClassPathArchives(List archives) throws Exception {
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getArchiveEntryPathPrefix() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isExploded() {
|
|
||||||
return this.archive.isExploded();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final Archive getArchive() {
|
|
||||||
return this.archive;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package org.springframework.boot.loader;
|
|
||||||
|
|
||||||
import org.springframework.boot.loader.archive.Archive;
|
|
||||||
|
|
||||||
public class JarLauncher extends ExecutableArchiveLauncher {
|
|
||||||
static final Archive.EntryFilter NESTED_ARCHIVE_ENTRY_FILTER = (entry) -> entry.isDirectory() ? entry.getName().equals("BOOT-INF/classes/") : entry.getName().startsWith("BOOT-INF/lib/");
|
|
||||||
|
|
||||||
public JarLauncher() {
|
|
||||||
}
|
|
||||||
|
|
||||||
protected JarLauncher(Archive archive) {
|
|
||||||
super(archive);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isPostProcessingClassPathArchives() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isNestedArchive(Archive.Entry entry) {
|
|
||||||
return NESTED_ARCHIVE_ENTRY_FILTER.matches(entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getArchiveEntryPathPrefix() {
|
|
||||||
return "BOOT-INF/";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
(new JarLauncher()).launch(args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,303 +0,0 @@
|
|||||||
package org.springframework.boot.loader;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.JarURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLClassLoader;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.security.AccessController;
|
|
||||||
import java.security.PrivilegedActionException;
|
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
import java.util.jar.JarFile;
|
|
||||||
import java.util.jar.Manifest;
|
|
||||||
import org.springframework.boot.loader.archive.Archive;
|
|
||||||
import org.springframework.boot.loader.jar.Handler;
|
|
||||||
|
|
||||||
public class LaunchedURLClassLoader extends URLClassLoader {
|
|
||||||
private static final int BUFFER_SIZE = 4096;
|
|
||||||
private final boolean exploded;
|
|
||||||
private final Archive rootArchive;
|
|
||||||
private final Object packageLock;
|
|
||||||
private volatile DefinePackageCallType definePackageCallType;
|
|
||||||
|
|
||||||
public LaunchedURLClassLoader(URL[] urls, ClassLoader parent) {
|
|
||||||
this(false, urls, parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
public LaunchedURLClassLoader(boolean exploded, URL[] urls, ClassLoader parent) {
|
|
||||||
this(exploded, (Archive)null, urls, parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
public LaunchedURLClassLoader(boolean exploded, Archive rootArchive, URL[] urls, ClassLoader parent) {
|
|
||||||
super(urls, parent);
|
|
||||||
this.packageLock = new Object();
|
|
||||||
this.exploded = exploded;
|
|
||||||
this.rootArchive = rootArchive;
|
|
||||||
}
|
|
||||||
|
|
||||||
public URL findResource(String name) {
|
|
||||||
if (this.exploded) {
|
|
||||||
return super.findResource(name);
|
|
||||||
} else {
|
|
||||||
Handler.setUseFastConnectionExceptions(true);
|
|
||||||
|
|
||||||
URL var2;
|
|
||||||
try {
|
|
||||||
var2 = super.findResource(name);
|
|
||||||
} finally {
|
|
||||||
Handler.setUseFastConnectionExceptions(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return var2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Enumeration findResources(String name) throws IOException {
|
|
||||||
if (this.exploded) {
|
|
||||||
return super.findResources(name);
|
|
||||||
} else {
|
|
||||||
Handler.setUseFastConnectionExceptions(true);
|
|
||||||
|
|
||||||
UseFastConnectionExceptionsEnumeration var2;
|
|
||||||
try {
|
|
||||||
var2 = new UseFastConnectionExceptionsEnumeration(super.findResources(name));
|
|
||||||
} finally {
|
|
||||||
Handler.setUseFastConnectionExceptions(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return var2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
|
|
||||||
if (name.startsWith("org.springframework.boot.loader.jarmode.")) {
|
|
||||||
try {
|
|
||||||
Class<?> result = this.loadClassInLaunchedClassLoader(name);
|
|
||||||
if (resolve) {
|
|
||||||
this.resolveClass(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
} catch (ClassNotFoundException var10) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.exploded) {
|
|
||||||
return super.loadClass(name, resolve);
|
|
||||||
} else {
|
|
||||||
Handler.setUseFastConnectionExceptions(true);
|
|
||||||
|
|
||||||
Class result;
|
|
||||||
try {
|
|
||||||
try {
|
|
||||||
this.definePackageIfNecessary(name);
|
|
||||||
} catch (IllegalArgumentException var8) {
|
|
||||||
if (this.getPackage(name) == null) {
|
|
||||||
throw new AssertionError("Package " + name + " has already been defined but it could not be found");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result = super.loadClass(name, resolve);
|
|
||||||
} finally {
|
|
||||||
Handler.setUseFastConnectionExceptions(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Class loadClassInLaunchedClassLoader(String name) throws ClassNotFoundException {
|
|
||||||
String internalName = name.replace('.', '/') + ".class";
|
|
||||||
InputStream inputStream = this.getParent().getResourceAsStream(internalName);
|
|
||||||
if (inputStream == null) {
|
|
||||||
throw new ClassNotFoundException(name);
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
Class var9;
|
|
||||||
try {
|
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
||||||
byte[] buffer = new byte[4096];
|
|
||||||
int bytesRead = -1;
|
|
||||||
|
|
||||||
while((bytesRead = inputStream.read(buffer)) != -1) {
|
|
||||||
outputStream.write(buffer, 0, bytesRead);
|
|
||||||
}
|
|
||||||
|
|
||||||
inputStream.close();
|
|
||||||
byte[] bytes = outputStream.toByteArray();
|
|
||||||
Class<?> definedClass = this.defineClass(name, bytes, 0, bytes.length);
|
|
||||||
this.definePackageIfNecessary(name);
|
|
||||||
var9 = definedClass;
|
|
||||||
} finally {
|
|
||||||
inputStream.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
return var9;
|
|
||||||
} catch (IOException ex) {
|
|
||||||
throw new ClassNotFoundException("Cannot load resource for class [" + name + "]", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void definePackageIfNecessary(String className) {
|
|
||||||
int lastDot = className.lastIndexOf(46);
|
|
||||||
if (lastDot >= 0) {
|
|
||||||
String packageName = className.substring(0, lastDot);
|
|
||||||
if (this.getPackage(packageName) == null) {
|
|
||||||
try {
|
|
||||||
this.definePackage(className, packageName);
|
|
||||||
} catch (IllegalArgumentException var5) {
|
|
||||||
if (this.getPackage(packageName) == null) {
|
|
||||||
throw new AssertionError("Package " + packageName + " has already been defined but it could not be found");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void definePackage(String className, String packageName) {
|
|
||||||
try {
|
|
||||||
AccessController.doPrivileged(() -> {
|
|
||||||
String packageEntryName = packageName.replace('.', '/') + "/";
|
|
||||||
String classEntryName = className.replace('.', '/') + ".class";
|
|
||||||
|
|
||||||
for(URL url : this.getURLs()) {
|
|
||||||
try {
|
|
||||||
URLConnection connection = url.openConnection();
|
|
||||||
if (connection instanceof JarURLConnection) {
|
|
||||||
JarFile jarFile = ((JarURLConnection)connection).getJarFile();
|
|
||||||
if (jarFile.getEntry(classEntryName) != null && jarFile.getEntry(packageEntryName) != null && jarFile.getManifest() != null) {
|
|
||||||
this.definePackage(packageName, jarFile.getManifest(), url);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (IOException var11) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}, AccessController.getContext());
|
|
||||||
} catch (PrivilegedActionException var4) {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Package definePackage(String name, Manifest man, URL url) throws IllegalArgumentException {
|
|
||||||
if (!this.exploded) {
|
|
||||||
return super.definePackage(name, man, url);
|
|
||||||
} else {
|
|
||||||
synchronized(this.packageLock) {
|
|
||||||
return (Package)this.doDefinePackage(LaunchedURLClassLoader.DefinePackageCallType.MANIFEST, () -> super.definePackage(name, man, url));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Package definePackage(String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase) throws IllegalArgumentException {
|
|
||||||
if (!this.exploded) {
|
|
||||||
return super.definePackage(name, specTitle, specVersion, specVendor, implTitle, implVersion, implVendor, sealBase);
|
|
||||||
} else {
|
|
||||||
synchronized(this.packageLock) {
|
|
||||||
if (this.definePackageCallType == null) {
|
|
||||||
Manifest manifest = this.getManifest(this.rootArchive);
|
|
||||||
if (manifest != null) {
|
|
||||||
return this.definePackage(name, manifest, sealBase);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (Package)this.doDefinePackage(LaunchedURLClassLoader.DefinePackageCallType.ATTRIBUTES, () -> super.definePackage(name, specTitle, specVersion, specVendor, implTitle, implVersion, implVendor, sealBase));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Manifest getManifest(Archive archive) {
|
|
||||||
try {
|
|
||||||
return archive != null ? archive.getManifest() : null;
|
|
||||||
} catch (IOException var3) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object doDefinePackage(DefinePackageCallType type, Supplier call) {
|
|
||||||
DefinePackageCallType existingType = this.definePackageCallType;
|
|
||||||
|
|
||||||
Object var4;
|
|
||||||
try {
|
|
||||||
this.definePackageCallType = type;
|
|
||||||
var4 = call.get();
|
|
||||||
} finally {
|
|
||||||
this.definePackageCallType = existingType;
|
|
||||||
}
|
|
||||||
|
|
||||||
return var4;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clearCache() {
|
|
||||||
if (!this.exploded) {
|
|
||||||
for(URL url : this.getURLs()) {
|
|
||||||
try {
|
|
||||||
URLConnection connection = url.openConnection();
|
|
||||||
if (connection instanceof JarURLConnection) {
|
|
||||||
this.clearCache(connection);
|
|
||||||
}
|
|
||||||
} catch (IOException var6) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void clearCache(URLConnection connection) throws IOException {
|
|
||||||
Object jarFile = ((JarURLConnection)connection).getJarFile();
|
|
||||||
if (jarFile instanceof org.springframework.boot.loader.jar.JarFile) {
|
|
||||||
((org.springframework.boot.loader.jar.JarFile)jarFile).clearCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static {
|
|
||||||
ClassLoader.registerAsParallelCapable();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class UseFastConnectionExceptionsEnumeration implements Enumeration {
|
|
||||||
private final Enumeration delegate;
|
|
||||||
|
|
||||||
UseFastConnectionExceptionsEnumeration(Enumeration delegate) {
|
|
||||||
this.delegate = delegate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasMoreElements() {
|
|
||||||
Handler.setUseFastConnectionExceptions(true);
|
|
||||||
|
|
||||||
boolean var1;
|
|
||||||
try {
|
|
||||||
var1 = this.delegate.hasMoreElements();
|
|
||||||
} finally {
|
|
||||||
Handler.setUseFastConnectionExceptions(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return var1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public URL nextElement() {
|
|
||||||
Handler.setUseFastConnectionExceptions(true);
|
|
||||||
|
|
||||||
URL var1;
|
|
||||||
try {
|
|
||||||
var1 = (URL)this.delegate.nextElement();
|
|
||||||
} finally {
|
|
||||||
Handler.setUseFastConnectionExceptions(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return var1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static enum DefinePackageCallType {
|
|
||||||
MANIFEST,
|
|
||||||
ATTRIBUTES;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
package org.springframework.boot.loader;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.security.CodeSource;
|
|
||||||
import java.security.ProtectionDomain;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import org.springframework.boot.loader.archive.Archive;
|
|
||||||
import org.springframework.boot.loader.archive.ExplodedArchive;
|
|
||||||
import org.springframework.boot.loader.archive.JarFileArchive;
|
|
||||||
import org.springframework.boot.loader.jar.JarFile;
|
|
||||||
|
|
||||||
public abstract class Launcher {
|
|
||||||
private static final String JAR_MODE_LAUNCHER = "org.springframework.boot.loader.jarmode.JarModeLauncher";
|
|
||||||
|
|
||||||
protected void launch(String[] args) throws Exception {
|
|
||||||
if (!this.isExploded()) {
|
|
||||||
JarFile.registerUrlProtocolHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
ClassLoader classLoader = this.createClassLoader(this.getClassPathArchivesIterator());
|
|
||||||
String jarMode = System.getProperty("jarmode");
|
|
||||||
String launchClass = jarMode != null && !jarMode.isEmpty() ? "org.springframework.boot.loader.jarmode.JarModeLauncher" : this.getMainClass();
|
|
||||||
this.launch(args, launchClass, classLoader);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated */
|
|
||||||
@Deprecated
|
|
||||||
protected ClassLoader createClassLoader(List archives) throws Exception {
|
|
||||||
return this.createClassLoader(archives.iterator());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ClassLoader createClassLoader(Iterator archives) throws Exception {
|
|
||||||
List<URL> urls = new ArrayList(50);
|
|
||||||
|
|
||||||
while(archives.hasNext()) {
|
|
||||||
urls.add(((Archive)archives.next()).getUrl());
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.createClassLoader((URL[])urls.toArray(new URL[0]));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ClassLoader createClassLoader(URL[] urls) throws Exception {
|
|
||||||
return new LaunchedURLClassLoader(this.isExploded(), this.getArchive(), urls, this.getClass().getClassLoader());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void launch(String[] args, String launchClass, ClassLoader classLoader) throws Exception {
|
|
||||||
Thread.currentThread().setContextClassLoader(classLoader);
|
|
||||||
this.createMainMethodRunner(launchClass, args, classLoader).run();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected MainMethodRunner createMainMethodRunner(String mainClass, String[] args, ClassLoader classLoader) {
|
|
||||||
return new MainMethodRunner(mainClass, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract String getMainClass() throws Exception;
|
|
||||||
|
|
||||||
protected Iterator getClassPathArchivesIterator() throws Exception {
|
|
||||||
return this.getClassPathArchives().iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated */
|
|
||||||
@Deprecated
|
|
||||||
protected List getClassPathArchives() throws Exception {
|
|
||||||
throw new IllegalStateException("Unexpected call to getClassPathArchives()");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final Archive createArchive() throws Exception {
|
|
||||||
ProtectionDomain protectionDomain = this.getClass().getProtectionDomain();
|
|
||||||
CodeSource codeSource = protectionDomain.getCodeSource();
|
|
||||||
URI location = codeSource != null ? codeSource.getLocation().toURI() : null;
|
|
||||||
String path = location != null ? location.getSchemeSpecificPart() : null;
|
|
||||||
if (path == null) {
|
|
||||||
throw new IllegalStateException("Unable to determine code source archive");
|
|
||||||
} else {
|
|
||||||
File root = new File(path);
|
|
||||||
if (!root.exists()) {
|
|
||||||
throw new IllegalStateException("Unable to determine code source archive from " + root);
|
|
||||||
} else {
|
|
||||||
return (Archive)(root.isDirectory() ? new ExplodedArchive(root) : new JarFileArchive(root));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isExploded() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Archive getArchive() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package org.springframework.boot.loader;
|
|
||||||
|
|
||||||
import [Ljava.lang.String;;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
public class MainMethodRunner {
|
|
||||||
private final String mainClassName;
|
|
||||||
private final String[] args;
|
|
||||||
|
|
||||||
public MainMethodRunner(String mainClass, String[] args) {
|
|
||||||
this.mainClassName = mainClass;
|
|
||||||
this.args = args != null ? (String[])((String;)args).clone() : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run() throws Exception {
|
|
||||||
Class<?> mainClass = Class.forName(this.mainClassName, false, Thread.currentThread().getContextClassLoader());
|
|
||||||
Method mainMethod = mainClass.getDeclaredMethod("main", String[].class);
|
|
||||||
mainMethod.setAccessible(true);
|
|
||||||
mainMethod.invoke((Object)null, this.args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,658 +0,0 @@
|
|||||||
package org.springframework.boot.loader;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.net.URLDecoder;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.jar.Manifest;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
import org.springframework.boot.loader.archive.Archive;
|
|
||||||
import org.springframework.boot.loader.archive.ExplodedArchive;
|
|
||||||
import org.springframework.boot.loader.archive.JarFileArchive;
|
|
||||||
import org.springframework.boot.loader.util.SystemPropertyUtils;
|
|
||||||
|
|
||||||
public class PropertiesLauncher extends Launcher {
|
|
||||||
private static final Class[] PARENT_ONLY_PARAMS = new Class[]{ClassLoader.class};
|
|
||||||
private static final Class[] URLS_AND_PARENT_PARAMS = new Class[]{URL[].class, ClassLoader.class};
|
|
||||||
private static final Class[] NO_PARAMS = new Class[0];
|
|
||||||
private static final URL[] NO_URLS = new URL[0];
|
|
||||||
private static final String DEBUG = "loader.debug";
|
|
||||||
public static final String MAIN = "loader.main";
|
|
||||||
public static final String PATH = "loader.path";
|
|
||||||
public static final String HOME = "loader.home";
|
|
||||||
public static final String ARGS = "loader.args";
|
|
||||||
public static final String CONFIG_NAME = "loader.config.name";
|
|
||||||
public static final String CONFIG_LOCATION = "loader.config.location";
|
|
||||||
public static final String SET_SYSTEM_PROPERTIES = "loader.system";
|
|
||||||
private static final Pattern WORD_SEPARATOR = Pattern.compile("\\W+");
|
|
||||||
private static final String NESTED_ARCHIVE_SEPARATOR;
|
|
||||||
private final File home;
|
|
||||||
private List paths = new ArrayList();
|
|
||||||
private final Properties properties = new Properties();
|
|
||||||
private final Archive parent;
|
|
||||||
private volatile ClassPathArchives classPathArchives;
|
|
||||||
|
|
||||||
public PropertiesLauncher() {
|
|
||||||
try {
|
|
||||||
this.home = this.getHomeDirectory();
|
|
||||||
this.initializeProperties();
|
|
||||||
this.initializePaths();
|
|
||||||
this.parent = this.createArchive();
|
|
||||||
} catch (Exception ex) {
|
|
||||||
throw new IllegalStateException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected File getHomeDirectory() {
|
|
||||||
try {
|
|
||||||
return new File(this.getPropertyWithDefault("loader.home", "${user.dir}"));
|
|
||||||
} catch (Exception ex) {
|
|
||||||
throw new IllegalStateException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initializeProperties() throws Exception {
|
|
||||||
List<String> configs = new ArrayList();
|
|
||||||
if (this.getProperty("loader.config.location") != null) {
|
|
||||||
configs.add(this.getProperty("loader.config.location"));
|
|
||||||
} else {
|
|
||||||
String[] names = this.getPropertyWithDefault("loader.config.name", "loader").split(",");
|
|
||||||
|
|
||||||
for(String name : names) {
|
|
||||||
configs.add("file:" + this.getHomeDirectory() + "/" + name + ".properties");
|
|
||||||
configs.add("classpath:" + name + ".properties");
|
|
||||||
configs.add("classpath:BOOT-INF/classes/" + name + ".properties");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterator var17 = configs.iterator();
|
|
||||||
|
|
||||||
while(true) {
|
|
||||||
if (var17.hasNext()) {
|
|
||||||
String config = (String)var17.next();
|
|
||||||
InputStream resource = this.getResource(config);
|
|
||||||
Throwable var20 = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (resource == null) {
|
|
||||||
this.debug("Not found: " + config);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.debug("Found: " + config);
|
|
||||||
this.loadResource(resource);
|
|
||||||
} catch (Throwable var15) {
|
|
||||||
var20 = var15;
|
|
||||||
throw var15;
|
|
||||||
} finally {
|
|
||||||
if (resource != null) {
|
|
||||||
if (var20 != null) {
|
|
||||||
try {
|
|
||||||
resource.close();
|
|
||||||
} catch (Throwable var14) {
|
|
||||||
var20.addSuppressed(var14);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
resource.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadResource(InputStream resource) throws Exception {
|
|
||||||
this.properties.load(resource);
|
|
||||||
|
|
||||||
for(Object key : Collections.list(this.properties.propertyNames())) {
|
|
||||||
String text = this.properties.getProperty((String)key);
|
|
||||||
String value = SystemPropertyUtils.resolvePlaceholders(this.properties, text);
|
|
||||||
if (value != null) {
|
|
||||||
this.properties.put(key, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ("true".equals(this.getProperty("loader.system"))) {
|
|
||||||
this.debug("Adding resolved properties to System properties");
|
|
||||||
|
|
||||||
for(Object key : Collections.list(this.properties.propertyNames())) {
|
|
||||||
String value = this.properties.getProperty((String)key);
|
|
||||||
System.setProperty((String)key, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private InputStream getResource(String config) throws Exception {
|
|
||||||
if (config.startsWith("classpath:")) {
|
|
||||||
return this.getClasspathResource(config.substring("classpath:".length()));
|
|
||||||
} else {
|
|
||||||
config = this.handleUrl(config);
|
|
||||||
return this.isUrl(config) ? this.getURLResource(config) : this.getFileResource(config);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String handleUrl(String path) throws UnsupportedEncodingException {
|
|
||||||
if (path.startsWith("jar:file:") || path.startsWith("file:")) {
|
|
||||||
path = URLDecoder.decode(path, "UTF-8");
|
|
||||||
if (path.startsWith("file:")) {
|
|
||||||
path = path.substring("file:".length());
|
|
||||||
if (path.startsWith("//")) {
|
|
||||||
path = path.substring(2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isUrl(String config) {
|
|
||||||
return config.contains("://");
|
|
||||||
}
|
|
||||||
|
|
||||||
private InputStream getClasspathResource(String config) {
|
|
||||||
while(config.startsWith("/")) {
|
|
||||||
config = config.substring(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
config = "/" + config;
|
|
||||||
this.debug("Trying classpath: " + config);
|
|
||||||
return this.getClass().getResourceAsStream(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
private InputStream getFileResource(String config) throws Exception {
|
|
||||||
File file = new File(config);
|
|
||||||
this.debug("Trying file: " + config);
|
|
||||||
return file.canRead() ? new FileInputStream(file) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private InputStream getURLResource(String config) throws Exception {
|
|
||||||
URL url = new URL(config);
|
|
||||||
if (this.exists(url)) {
|
|
||||||
URLConnection con = url.openConnection();
|
|
||||||
|
|
||||||
try {
|
|
||||||
return con.getInputStream();
|
|
||||||
} catch (IOException ex) {
|
|
||||||
if (con instanceof HttpURLConnection) {
|
|
||||||
((HttpURLConnection)con).disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean exists(URL url) throws IOException {
|
|
||||||
URLConnection connection = url.openConnection();
|
|
||||||
|
|
||||||
try {
|
|
||||||
connection.setUseCaches(connection.getClass().getSimpleName().startsWith("JNLP"));
|
|
||||||
if (connection instanceof HttpURLConnection) {
|
|
||||||
HttpURLConnection httpConnection = (HttpURLConnection)connection;
|
|
||||||
httpConnection.setRequestMethod("HEAD");
|
|
||||||
int responseCode = httpConnection.getResponseCode();
|
|
||||||
if (responseCode == 200) {
|
|
||||||
boolean var10 = true;
|
|
||||||
return var10;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (responseCode == 404) {
|
|
||||||
boolean var5 = false;
|
|
||||||
return var5;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean var9 = connection.getContentLength() >= 0;
|
|
||||||
return var9;
|
|
||||||
} finally {
|
|
||||||
if (connection instanceof HttpURLConnection) {
|
|
||||||
((HttpURLConnection)connection).disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initializePaths() throws Exception {
|
|
||||||
String path = this.getProperty("loader.path");
|
|
||||||
if (path != null) {
|
|
||||||
this.paths = this.parsePathsProperty(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.debug("Nested archive paths: " + this.paths);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List parsePathsProperty(String commaSeparatedPaths) {
|
|
||||||
List<String> paths = new ArrayList();
|
|
||||||
|
|
||||||
for(String path : commaSeparatedPaths.split(",")) {
|
|
||||||
path = this.cleanupPath(path);
|
|
||||||
path = path != null && !path.isEmpty() ? path : "/";
|
|
||||||
paths.add(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (paths.isEmpty()) {
|
|
||||||
paths.add("lib");
|
|
||||||
}
|
|
||||||
|
|
||||||
return paths;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String[] getArgs(String... args) throws Exception {
|
|
||||||
String loaderArgs = this.getProperty("loader.args");
|
|
||||||
if (loaderArgs != null) {
|
|
||||||
String[] defaultArgs = loaderArgs.split("\\s+");
|
|
||||||
String[] additionalArgs = args;
|
|
||||||
args = new String[defaultArgs.length + args.length];
|
|
||||||
System.arraycopy(defaultArgs, 0, args, 0, defaultArgs.length);
|
|
||||||
System.arraycopy(additionalArgs, 0, args, defaultArgs.length, additionalArgs.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
return args;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getMainClass() throws Exception {
|
|
||||||
String mainClass = this.getProperty("loader.main", "Start-Class");
|
|
||||||
if (mainClass == null) {
|
|
||||||
throw new IllegalStateException("No 'loader.main' or 'Start-Class' specified");
|
|
||||||
} else {
|
|
||||||
return mainClass;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ClassLoader createClassLoader(Iterator archives) throws Exception {
|
|
||||||
String customLoaderClassName = this.getProperty("loader.classLoader");
|
|
||||||
if (customLoaderClassName == null) {
|
|
||||||
return super.createClassLoader(archives);
|
|
||||||
} else {
|
|
||||||
Set<URL> urls = new LinkedHashSet();
|
|
||||||
|
|
||||||
while(archives.hasNext()) {
|
|
||||||
urls.add(((Archive)archives.next()).getUrl());
|
|
||||||
}
|
|
||||||
|
|
||||||
ClassLoader loader = new LaunchedURLClassLoader((URL[])urls.toArray(NO_URLS), this.getClass().getClassLoader());
|
|
||||||
this.debug("Classpath for custom loader: " + urls);
|
|
||||||
ClassLoader var5 = this.wrapWithCustomClassLoader(loader, customLoaderClassName);
|
|
||||||
this.debug("Using custom class loader: " + customLoaderClassName);
|
|
||||||
return var5;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ClassLoader wrapWithCustomClassLoader(ClassLoader parent, String className) throws Exception {
|
|
||||||
Class<ClassLoader> type = Class.forName(className, true, parent);
|
|
||||||
ClassLoader classLoader = this.newClassLoader(type, PARENT_ONLY_PARAMS, parent);
|
|
||||||
if (classLoader == null) {
|
|
||||||
classLoader = this.newClassLoader(type, URLS_AND_PARENT_PARAMS, NO_URLS, parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (classLoader == null) {
|
|
||||||
classLoader = this.newClassLoader(type, NO_PARAMS);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (classLoader == null) {
|
|
||||||
throw new IllegalArgumentException("Unable to create class loader for " + className);
|
|
||||||
} else {
|
|
||||||
return classLoader;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ClassLoader newClassLoader(Class loaderClass, Class[] parameterTypes, Object... initargs) throws Exception {
|
|
||||||
try {
|
|
||||||
Constructor<ClassLoader> constructor = loaderClass.getDeclaredConstructor(parameterTypes);
|
|
||||||
constructor.setAccessible(true);
|
|
||||||
return (ClassLoader)constructor.newInstance(initargs);
|
|
||||||
} catch (NoSuchMethodException var5) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getProperty(String propertyKey) throws Exception {
|
|
||||||
return this.getProperty(propertyKey, (String)null, (String)null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getProperty(String propertyKey, String manifestKey) throws Exception {
|
|
||||||
return this.getProperty(propertyKey, manifestKey, (String)null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getPropertyWithDefault(String propertyKey, String defaultValue) throws Exception {
|
|
||||||
return this.getProperty(propertyKey, (String)null, defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getProperty(String propertyKey, String manifestKey, String defaultValue) throws Exception {
|
|
||||||
if (manifestKey == null) {
|
|
||||||
manifestKey = propertyKey.replace('.', '-');
|
|
||||||
manifestKey = toCamelCase(manifestKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
String property = SystemPropertyUtils.getProperty(propertyKey);
|
|
||||||
if (property != null) {
|
|
||||||
String value = SystemPropertyUtils.resolvePlaceholders(this.properties, property);
|
|
||||||
this.debug("Property '" + propertyKey + "' from environment: " + value);
|
|
||||||
return value;
|
|
||||||
} else if (this.properties.containsKey(propertyKey)) {
|
|
||||||
String value = SystemPropertyUtils.resolvePlaceholders(this.properties, this.properties.getProperty(propertyKey));
|
|
||||||
this.debug("Property '" + propertyKey + "' from properties: " + value);
|
|
||||||
return value;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
if (this.home != null) {
|
|
||||||
label164: {
|
|
||||||
String var9;
|
|
||||||
try (ExplodedArchive archive = new ExplodedArchive(this.home, false)) {
|
|
||||||
Manifest manifest = archive.getManifest();
|
|
||||||
if (manifest == null) {
|
|
||||||
break label164;
|
|
||||||
}
|
|
||||||
|
|
||||||
String value = manifest.getMainAttributes().getValue(manifestKey);
|
|
||||||
if (value == null) {
|
|
||||||
break label164;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.debug("Property '" + manifestKey + "' from home directory manifest: " + value);
|
|
||||||
var9 = SystemPropertyUtils.resolvePlaceholders(this.properties, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return var9;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (IllegalStateException var22) {
|
|
||||||
}
|
|
||||||
|
|
||||||
Manifest manifest = this.createArchive().getManifest();
|
|
||||||
if (manifest != null) {
|
|
||||||
String value = manifest.getMainAttributes().getValue(manifestKey);
|
|
||||||
if (value != null) {
|
|
||||||
this.debug("Property '" + manifestKey + "' from archive manifest: " + value);
|
|
||||||
return SystemPropertyUtils.resolvePlaceholders(this.properties, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return defaultValue != null ? SystemPropertyUtils.resolvePlaceholders(this.properties, defaultValue) : defaultValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Iterator getClassPathArchivesIterator() throws Exception {
|
|
||||||
ClassPathArchives classPathArchives = this.classPathArchives;
|
|
||||||
if (classPathArchives == null) {
|
|
||||||
classPathArchives = new ClassPathArchives();
|
|
||||||
this.classPathArchives = classPathArchives;
|
|
||||||
}
|
|
||||||
|
|
||||||
return classPathArchives.iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
|
||||||
args = launcher.getArgs(args);
|
|
||||||
launcher.launch(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String toCamelCase(CharSequence string) {
|
|
||||||
if (string == null) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
Matcher matcher = WORD_SEPARATOR.matcher(string);
|
|
||||||
|
|
||||||
int pos;
|
|
||||||
for(pos = 0; matcher.find(); pos = matcher.end()) {
|
|
||||||
builder.append(capitalize(string.subSequence(pos, matcher.end()).toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.append(capitalize(string.subSequence(pos, string.length()).toString()));
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String capitalize(String str) {
|
|
||||||
return Character.toUpperCase(str.charAt(0)) + str.substring(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void debug(String message) {
|
|
||||||
if (Boolean.getBoolean("loader.debug")) {
|
|
||||||
System.out.println(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private String cleanupPath(String path) {
|
|
||||||
path = path.trim();
|
|
||||||
if (path.startsWith("./")) {
|
|
||||||
path = path.substring(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
String lowerCasePath = path.toLowerCase(Locale.ENGLISH);
|
|
||||||
if (!lowerCasePath.endsWith(".jar") && !lowerCasePath.endsWith(".zip")) {
|
|
||||||
if (path.endsWith("/*")) {
|
|
||||||
path = path.substring(0, path.length() - 1);
|
|
||||||
} else if (!path.endsWith("/") && !path.equals(".")) {
|
|
||||||
path = path + "/";
|
|
||||||
}
|
|
||||||
|
|
||||||
return path;
|
|
||||||
} else {
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void close() throws Exception {
|
|
||||||
if (this.classPathArchives != null) {
|
|
||||||
this.classPathArchives.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.parent != null) {
|
|
||||||
this.parent.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static {
|
|
||||||
NESTED_ARCHIVE_SEPARATOR = "!" + File.separator;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ClassPathArchives implements Iterable {
|
|
||||||
private final List classPathArchives = new ArrayList();
|
|
||||||
private final List jarFileArchives = new ArrayList();
|
|
||||||
|
|
||||||
ClassPathArchives() throws Exception {
|
|
||||||
for(String path : PropertiesLauncher.this.paths) {
|
|
||||||
for(Archive archive : this.getClassPathArchives(path)) {
|
|
||||||
this.addClassPathArchive(archive);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.addNestedEntries();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addClassPathArchive(Archive archive) throws IOException {
|
|
||||||
if (!(archive instanceof ExplodedArchive)) {
|
|
||||||
this.classPathArchives.add(archive);
|
|
||||||
} else {
|
|
||||||
this.classPathArchives.add(archive);
|
|
||||||
this.classPathArchives.addAll(this.asList(archive.getNestedArchives((Archive.EntryFilter)null, new ArchiveEntryFilter())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private List getClassPathArchives(String path) throws Exception {
|
|
||||||
String root = PropertiesLauncher.this.cleanupPath(PropertiesLauncher.this.handleUrl(path));
|
|
||||||
List<Archive> lib = new ArrayList();
|
|
||||||
File file = new File(root);
|
|
||||||
if (!"/".equals(root)) {
|
|
||||||
if (!this.isAbsolutePath(root)) {
|
|
||||||
file = new File(PropertiesLauncher.this.home, root);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (file.isDirectory()) {
|
|
||||||
PropertiesLauncher.this.debug("Adding classpath entries from " + file);
|
|
||||||
Archive archive = new ExplodedArchive(file, false);
|
|
||||||
lib.add(archive);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Archive archive = this.getArchive(file);
|
|
||||||
if (archive != null) {
|
|
||||||
PropertiesLauncher.this.debug("Adding classpath entries from archive " + archive.getUrl() + root);
|
|
||||||
lib.add(archive);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Archive> nestedArchives = this.getNestedArchives(root);
|
|
||||||
if (nestedArchives != null) {
|
|
||||||
PropertiesLauncher.this.debug("Adding classpath entries from nested " + root);
|
|
||||||
lib.addAll(nestedArchives);
|
|
||||||
}
|
|
||||||
|
|
||||||
return lib;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isAbsolutePath(String root) {
|
|
||||||
return root.contains(":") || root.startsWith("/");
|
|
||||||
}
|
|
||||||
|
|
||||||
private Archive getArchive(File file) throws IOException {
|
|
||||||
if (this.isNestedArchivePath(file)) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
String name = file.getName().toLowerCase(Locale.ENGLISH);
|
|
||||||
return !name.endsWith(".jar") && !name.endsWith(".zip") ? null : this.getJarFileArchive(file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isNestedArchivePath(File file) {
|
|
||||||
return file.getPath().contains(PropertiesLauncher.NESTED_ARCHIVE_SEPARATOR);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List getNestedArchives(String path) throws Exception {
|
|
||||||
Archive parent = PropertiesLauncher.this.parent;
|
|
||||||
String root = path;
|
|
||||||
if ((path.equals("/") || !path.startsWith("/")) && !parent.getUrl().toURI().equals(PropertiesLauncher.this.home.toURI())) {
|
|
||||||
int index = path.indexOf(33);
|
|
||||||
if (index != -1) {
|
|
||||||
File file = new File(PropertiesLauncher.this.home, path.substring(0, index));
|
|
||||||
if (path.startsWith("jar:file:")) {
|
|
||||||
file = new File(path.substring("jar:file:".length(), index));
|
|
||||||
}
|
|
||||||
|
|
||||||
parent = this.getJarFileArchive(file);
|
|
||||||
|
|
||||||
for(root = path.substring(index + 1); root.startsWith("/"); root = root.substring(1)) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (root.endsWith(".jar")) {
|
|
||||||
File file = new File(PropertiesLauncher.this.home, root);
|
|
||||||
if (file.exists()) {
|
|
||||||
parent = this.getJarFileArchive(file);
|
|
||||||
root = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (root.equals("/") || root.equals("./") || root.equals(".")) {
|
|
||||||
root = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
Archive.EntryFilter filter = new PrefixMatchingArchiveFilter(root);
|
|
||||||
List<Archive> archives = this.asList(parent.getNestedArchives((Archive.EntryFilter)null, filter));
|
|
||||||
if ((root == null || root.isEmpty() || ".".equals(root)) && !path.endsWith(".jar") && parent != PropertiesLauncher.this.parent) {
|
|
||||||
archives.add(parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
return archives;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addNestedEntries() {
|
|
||||||
try {
|
|
||||||
Iterator<Archive> archives = PropertiesLauncher.this.parent.getNestedArchives((Archive.EntryFilter)null, JarLauncher.NESTED_ARCHIVE_ENTRY_FILTER);
|
|
||||||
|
|
||||||
while(archives.hasNext()) {
|
|
||||||
this.classPathArchives.add(archives.next());
|
|
||||||
}
|
|
||||||
} catch (IOException var2) {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private List asList(Iterator iterator) {
|
|
||||||
List<Archive> list = new ArrayList();
|
|
||||||
|
|
||||||
while(iterator.hasNext()) {
|
|
||||||
list.add(iterator.next());
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
private JarFileArchive getJarFileArchive(File file) throws IOException {
|
|
||||||
JarFileArchive archive = new JarFileArchive(file);
|
|
||||||
this.jarFileArchives.add(archive);
|
|
||||||
return archive;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Iterator iterator() {
|
|
||||||
return this.classPathArchives.iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
void close() throws IOException {
|
|
||||||
for(JarFileArchive archive : this.jarFileArchives) {
|
|
||||||
archive.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class PrefixMatchingArchiveFilter implements Archive.EntryFilter {
|
|
||||||
private final String prefix;
|
|
||||||
private final ArchiveEntryFilter filter;
|
|
||||||
|
|
||||||
private PrefixMatchingArchiveFilter(String prefix) {
|
|
||||||
this.filter = new ArchiveEntryFilter();
|
|
||||||
this.prefix = prefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean matches(Archive.Entry entry) {
|
|
||||||
if (entry.isDirectory()) {
|
|
||||||
return entry.getName().equals(this.prefix);
|
|
||||||
} else {
|
|
||||||
return entry.getName().startsWith(this.prefix) && this.filter.matches(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class ArchiveEntryFilter implements Archive.EntryFilter {
|
|
||||||
private static final String DOT_JAR = ".jar";
|
|
||||||
private static final String DOT_ZIP = ".zip";
|
|
||||||
|
|
||||||
private ArchiveEntryFilter() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean matches(Archive.Entry entry) {
|
|
||||||
return entry.getName().endsWith(".jar") || entry.getName().endsWith(".zip");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
package org.springframework.boot.loader;
|
|
||||||
|
|
||||||
import org.springframework.boot.loader.archive.Archive;
|
|
||||||
|
|
||||||
public class WarLauncher extends ExecutableArchiveLauncher {
|
|
||||||
public WarLauncher() {
|
|
||||||
}
|
|
||||||
|
|
||||||
protected WarLauncher(Archive archive) {
|
|
||||||
super(archive);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isPostProcessingClassPathArchives() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isNestedArchive(Archive.Entry entry) {
|
|
||||||
if (entry.isDirectory()) {
|
|
||||||
return entry.getName().equals("WEB-INF/classes/");
|
|
||||||
} else {
|
|
||||||
return entry.getName().startsWith("WEB-INF/lib/") || entry.getName().startsWith("WEB-INF/lib-provided/");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getArchiveEntryPathPrefix() {
|
|
||||||
return "WEB-INF/";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
(new WarLauncher()).launch(args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
package org.springframework.boot.loader.archive;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Spliterator;
|
|
||||||
import java.util.Spliterators;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
import java.util.jar.Manifest;
|
|
||||||
|
|
||||||
public interface Archive extends Iterable, AutoCloseable {
|
|
||||||
URL getUrl() throws MalformedURLException;
|
|
||||||
|
|
||||||
Manifest getManifest() throws IOException;
|
|
||||||
|
|
||||||
default Iterator getNestedArchives(EntryFilter searchFilter, EntryFilter includeFilter) throws IOException {
|
|
||||||
EntryFilter combinedFilter = (entry) -> (searchFilter == null || searchFilter.matches(entry)) && (includeFilter == null || includeFilter.matches(entry));
|
|
||||||
List<Archive> nestedArchives = this.getNestedArchives(combinedFilter);
|
|
||||||
return nestedArchives.iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated */
|
|
||||||
@Deprecated
|
|
||||||
default List getNestedArchives(EntryFilter filter) throws IOException {
|
|
||||||
throw new IllegalStateException("Unexpected call to getNestedArchives(filter)");
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated */
|
|
||||||
@Deprecated
|
|
||||||
Iterator iterator();
|
|
||||||
|
|
||||||
/** @deprecated */
|
|
||||||
@Deprecated
|
|
||||||
default void forEach(Consumer action) {
|
|
||||||
Objects.requireNonNull(action);
|
|
||||||
|
|
||||||
for(Entry entry : this) {
|
|
||||||
action.accept(entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated */
|
|
||||||
@Deprecated
|
|
||||||
default Spliterator spliterator() {
|
|
||||||
return Spliterators.spliteratorUnknownSize(this.iterator(), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
default boolean isExploded() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
default void close() throws Exception {
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface Entry {
|
|
||||||
boolean isDirectory();
|
|
||||||
|
|
||||||
String getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@FunctionalInterface
|
|
||||||
public interface EntryFilter {
|
|
||||||
boolean matches(Entry entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,276 +0,0 @@
|
|||||||
package org.springframework.boot.loader.archive;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.Deque;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.jar.Manifest;
|
|
||||||
|
|
||||||
public class ExplodedArchive implements Archive {
|
|
||||||
private static final Set SKIPPED_NAMES = new HashSet(Arrays.asList(".", ".."));
|
|
||||||
private final File root;
|
|
||||||
private final boolean recursive;
|
|
||||||
private File manifestFile;
|
|
||||||
private Manifest manifest;
|
|
||||||
|
|
||||||
public ExplodedArchive(File root) {
|
|
||||||
this(root, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ExplodedArchive(File root, boolean recursive) {
|
|
||||||
if (root.exists() && root.isDirectory()) {
|
|
||||||
this.root = root;
|
|
||||||
this.recursive = recursive;
|
|
||||||
this.manifestFile = this.getManifestFile(root);
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("Invalid source directory " + root);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private File getManifestFile(File root) {
|
|
||||||
File metaInf = new File(root, "META-INF");
|
|
||||||
return new File(metaInf, "MANIFEST.MF");
|
|
||||||
}
|
|
||||||
|
|
||||||
public URL getUrl() throws MalformedURLException {
|
|
||||||
return this.root.toURI().toURL();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Manifest getManifest() throws IOException {
|
|
||||||
if (this.manifest == null && this.manifestFile.exists()) {
|
|
||||||
FileInputStream inputStream = new FileInputStream(this.manifestFile);
|
|
||||||
Throwable var2 = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
this.manifest = new Manifest(inputStream);
|
|
||||||
} catch (Throwable var11) {
|
|
||||||
var2 = var11;
|
|
||||||
throw var11;
|
|
||||||
} finally {
|
|
||||||
if (inputStream != null) {
|
|
||||||
if (var2 != null) {
|
|
||||||
try {
|
|
||||||
inputStream.close();
|
|
||||||
} catch (Throwable var10) {
|
|
||||||
var2.addSuppressed(var10);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
inputStream.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.manifest;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Iterator getNestedArchives(Archive.EntryFilter searchFilter, Archive.EntryFilter includeFilter) throws IOException {
|
|
||||||
return new ArchiveIterator(this.root, this.recursive, searchFilter, includeFilter);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated */
|
|
||||||
@Deprecated
|
|
||||||
public Iterator iterator() {
|
|
||||||
return new EntryIterator(this.root, this.recursive, (Archive.EntryFilter)null, (Archive.EntryFilter)null);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Archive getNestedArchive(Archive.Entry entry) throws IOException {
|
|
||||||
File file = ((FileEntry)entry).getFile();
|
|
||||||
return (Archive)(file.isDirectory() ? new ExplodedArchive(file) : new SimpleJarFileArchive((FileEntry)entry));
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isExploded() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
try {
|
|
||||||
return this.getUrl().toString();
|
|
||||||
} catch (Exception var2) {
|
|
||||||
return "exploded archive";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private abstract static class AbstractIterator implements Iterator {
|
|
||||||
private static final Comparator entryComparator = Comparator.comparing(File::getAbsolutePath);
|
|
||||||
private final File root;
|
|
||||||
private final boolean recursive;
|
|
||||||
private final Archive.EntryFilter searchFilter;
|
|
||||||
private final Archive.EntryFilter includeFilter;
|
|
||||||
private final Deque stack = new LinkedList();
|
|
||||||
private FileEntry current;
|
|
||||||
private String rootUrl;
|
|
||||||
|
|
||||||
AbstractIterator(File root, boolean recursive, Archive.EntryFilter searchFilter, Archive.EntryFilter includeFilter) {
|
|
||||||
this.root = root;
|
|
||||||
this.rootUrl = this.root.toURI().getPath();
|
|
||||||
this.recursive = recursive;
|
|
||||||
this.searchFilter = searchFilter;
|
|
||||||
this.includeFilter = includeFilter;
|
|
||||||
this.stack.add(this.listFiles(root));
|
|
||||||
this.current = this.poll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasNext() {
|
|
||||||
return this.current != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object next() {
|
|
||||||
FileEntry entry = this.current;
|
|
||||||
if (entry == null) {
|
|
||||||
throw new NoSuchElementException();
|
|
||||||
} else {
|
|
||||||
this.current = this.poll();
|
|
||||||
return this.adapt(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private FileEntry poll() {
|
|
||||||
while(!this.stack.isEmpty()) {
|
|
||||||
if (!((Iterator)this.stack.peek()).hasNext()) {
|
|
||||||
this.stack.poll();
|
|
||||||
} else {
|
|
||||||
File file = (File)((Iterator)this.stack.peek()).next();
|
|
||||||
if (!ExplodedArchive.SKIPPED_NAMES.contains(file.getName())) {
|
|
||||||
FileEntry entry = this.getFileEntry(file);
|
|
||||||
if (this.isListable(entry)) {
|
|
||||||
this.stack.addFirst(this.listFiles(file));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.includeFilter == null || this.includeFilter.matches(entry)) {
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private FileEntry getFileEntry(File file) {
|
|
||||||
URI uri = file.toURI();
|
|
||||||
String name = uri.getPath().substring(this.rootUrl.length());
|
|
||||||
|
|
||||||
try {
|
|
||||||
return new FileEntry(name, file, uri.toURL());
|
|
||||||
} catch (MalformedURLException ex) {
|
|
||||||
throw new IllegalStateException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isListable(FileEntry entry) {
|
|
||||||
return entry.isDirectory() && (this.recursive || entry.getFile().getParentFile().equals(this.root)) && (this.searchFilter == null || this.searchFilter.matches(entry)) && (this.includeFilter == null || !this.includeFilter.matches(entry));
|
|
||||||
}
|
|
||||||
|
|
||||||
private Iterator listFiles(File file) {
|
|
||||||
File[] files = file.listFiles();
|
|
||||||
if (files == null) {
|
|
||||||
return Collections.emptyIterator();
|
|
||||||
} else {
|
|
||||||
Arrays.sort(files, entryComparator);
|
|
||||||
return Arrays.asList(files).iterator();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void remove() {
|
|
||||||
throw new UnsupportedOperationException("remove");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract Object adapt(FileEntry entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class EntryIterator extends AbstractIterator {
|
|
||||||
EntryIterator(File root, boolean recursive, Archive.EntryFilter searchFilter, Archive.EntryFilter includeFilter) {
|
|
||||||
super(root, recursive, searchFilter, includeFilter);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Archive.Entry adapt(FileEntry entry) {
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ArchiveIterator extends AbstractIterator {
|
|
||||||
ArchiveIterator(File root, boolean recursive, Archive.EntryFilter searchFilter, Archive.EntryFilter includeFilter) {
|
|
||||||
super(root, recursive, searchFilter, includeFilter);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Archive adapt(FileEntry entry) {
|
|
||||||
File file = entry.getFile();
|
|
||||||
return (Archive)(file.isDirectory() ? new ExplodedArchive(file) : new SimpleJarFileArchive(entry));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class FileEntry implements Archive.Entry {
|
|
||||||
private final String name;
|
|
||||||
private final File file;
|
|
||||||
private final URL url;
|
|
||||||
|
|
||||||
FileEntry(String name, File file, URL url) {
|
|
||||||
this.name = name;
|
|
||||||
this.file = file;
|
|
||||||
this.url = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
File getFile() {
|
|
||||||
return this.file;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDirectory() {
|
|
||||||
return this.file.isDirectory();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
URL getUrl() {
|
|
||||||
return this.url;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class SimpleJarFileArchive implements Archive {
|
|
||||||
private final URL url;
|
|
||||||
|
|
||||||
SimpleJarFileArchive(FileEntry file) {
|
|
||||||
this.url = file.getUrl();
|
|
||||||
}
|
|
||||||
|
|
||||||
public URL getUrl() throws MalformedURLException {
|
|
||||||
return this.url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Manifest getManifest() throws IOException {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Iterator getNestedArchives(Archive.EntryFilter searchFilter, Archive.EntryFilter includeFilter) throws IOException {
|
|
||||||
return Collections.emptyIterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated */
|
|
||||||
@Deprecated
|
|
||||||
public Iterator iterator() {
|
|
||||||
return Collections.emptyIterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
try {
|
|
||||||
return this.getUrl().toString();
|
|
||||||
} catch (Exception var2) {
|
|
||||||
return "jar archive";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,290 +0,0 @@
|
|||||||
package org.springframework.boot.loader.archive;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.nio.file.FileSystem;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.LinkOption;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.nio.file.StandardOpenOption;
|
|
||||||
import java.nio.file.attribute.FileAttribute;
|
|
||||||
import java.nio.file.attribute.PosixFilePermission;
|
|
||||||
import java.nio.file.attribute.PosixFilePermissions;
|
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.jar.JarEntry;
|
|
||||||
import java.util.jar.Manifest;
|
|
||||||
import java.util.zip.ZipEntry;
|
|
||||||
import org.springframework.boot.loader.jar.JarFile;
|
|
||||||
|
|
||||||
public class JarFileArchive implements Archive {
|
|
||||||
private static final String UNPACK_MARKER = "UNPACK:";
|
|
||||||
private static final int BUFFER_SIZE = 32768;
|
|
||||||
private static final FileAttribute[] NO_FILE_ATTRIBUTES = new FileAttribute[0];
|
|
||||||
private static final EnumSet DIRECTORY_PERMISSIONS;
|
|
||||||
private static final EnumSet FILE_PERMISSIONS;
|
|
||||||
private final JarFile jarFile;
|
|
||||||
private URL url;
|
|
||||||
private Path tempUnpackDirectory;
|
|
||||||
|
|
||||||
public JarFileArchive(File file) throws IOException {
|
|
||||||
this(file, file.toURI().toURL());
|
|
||||||
}
|
|
||||||
|
|
||||||
public JarFileArchive(File file, URL url) throws IOException {
|
|
||||||
this(new JarFile(file));
|
|
||||||
this.url = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JarFileArchive(JarFile jarFile) {
|
|
||||||
this.jarFile = jarFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public URL getUrl() throws MalformedURLException {
|
|
||||||
return this.url != null ? this.url : this.jarFile.getUrl();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Manifest getManifest() throws IOException {
|
|
||||||
return this.jarFile.getManifest();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Iterator getNestedArchives(Archive.EntryFilter searchFilter, Archive.EntryFilter includeFilter) throws IOException {
|
|
||||||
return new NestedArchiveIterator(this.jarFile.iterator(), searchFilter, includeFilter);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated */
|
|
||||||
@Deprecated
|
|
||||||
public Iterator iterator() {
|
|
||||||
return new EntryIterator(this.jarFile.iterator(), (Archive.EntryFilter)null, (Archive.EntryFilter)null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void close() throws IOException {
|
|
||||||
this.jarFile.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Archive getNestedArchive(Archive.Entry entry) throws IOException {
|
|
||||||
JarEntry jarEntry = ((JarFileEntry)entry).getJarEntry();
|
|
||||||
if (jarEntry.getComment().startsWith("UNPACK:")) {
|
|
||||||
return this.getUnpackedNestedArchive(jarEntry);
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
JarFile jarFile = this.jarFile.getNestedJarFile((ZipEntry)jarEntry);
|
|
||||||
return new JarFileArchive(jarFile);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
throw new IllegalStateException("Failed to get nested archive for entry " + entry.getName(), ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Archive getUnpackedNestedArchive(JarEntry jarEntry) throws IOException {
|
|
||||||
String name = jarEntry.getName();
|
|
||||||
if (name.lastIndexOf(47) != -1) {
|
|
||||||
name = name.substring(name.lastIndexOf(47) + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
Path path = this.getTempUnpackDirectory().resolve(name);
|
|
||||||
if (!Files.exists(path, new LinkOption[0]) || Files.size(path) != jarEntry.getSize()) {
|
|
||||||
this.unpack(jarEntry, path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new JarFileArchive(path.toFile(), path.toUri().toURL());
|
|
||||||
}
|
|
||||||
|
|
||||||
private Path getTempUnpackDirectory() {
|
|
||||||
if (this.tempUnpackDirectory == null) {
|
|
||||||
Path tempDirectory = Paths.get(System.getProperty("java.io.tmpdir"));
|
|
||||||
this.tempUnpackDirectory = this.createUnpackDirectory(tempDirectory);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.tempUnpackDirectory;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Path createUnpackDirectory(Path parent) {
|
|
||||||
int attempts = 0;
|
|
||||||
|
|
||||||
while(attempts++ < 1000) {
|
|
||||||
String fileName = Paths.get(this.jarFile.getName()).getFileName().toString();
|
|
||||||
Path unpackDirectory = parent.resolve(fileName + "-spring-boot-libs-" + UUID.randomUUID());
|
|
||||||
|
|
||||||
try {
|
|
||||||
this.createDirectory(unpackDirectory);
|
|
||||||
return unpackDirectory;
|
|
||||||
} catch (IOException var6) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new IllegalStateException("Failed to create unpack directory in directory '" + parent + "'");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void unpack(JarEntry entry, Path path) throws IOException {
|
|
||||||
this.createFile(path);
|
|
||||||
path.toFile().deleteOnExit();
|
|
||||||
InputStream inputStream = this.jarFile.getInputStream((ZipEntry)entry);
|
|
||||||
Throwable var4 = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
OutputStream outputStream = Files.newOutputStream(path, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
|
|
||||||
Throwable var6 = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
byte[] buffer = new byte['耀'];
|
|
||||||
|
|
||||||
int bytesRead;
|
|
||||||
while((bytesRead = inputStream.read(buffer)) != -1) {
|
|
||||||
outputStream.write(buffer, 0, bytesRead);
|
|
||||||
}
|
|
||||||
|
|
||||||
outputStream.flush();
|
|
||||||
} catch (Throwable var30) {
|
|
||||||
var6 = var30;
|
|
||||||
throw var30;
|
|
||||||
} finally {
|
|
||||||
if (outputStream != null) {
|
|
||||||
if (var6 != null) {
|
|
||||||
try {
|
|
||||||
outputStream.close();
|
|
||||||
} catch (Throwable var29) {
|
|
||||||
var6.addSuppressed(var29);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
outputStream.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
} catch (Throwable var32) {
|
|
||||||
var4 = var32;
|
|
||||||
throw var32;
|
|
||||||
} finally {
|
|
||||||
if (inputStream != null) {
|
|
||||||
if (var4 != null) {
|
|
||||||
try {
|
|
||||||
inputStream.close();
|
|
||||||
} catch (Throwable var28) {
|
|
||||||
var4.addSuppressed(var28);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
inputStream.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createDirectory(Path path) throws IOException {
|
|
||||||
Files.createDirectory(path, this.getFileAttributes(path.getFileSystem(), DIRECTORY_PERMISSIONS));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createFile(Path path) throws IOException {
|
|
||||||
Files.createFile(path, this.getFileAttributes(path.getFileSystem(), FILE_PERMISSIONS));
|
|
||||||
}
|
|
||||||
|
|
||||||
private FileAttribute[] getFileAttributes(FileSystem fileSystem, EnumSet ownerReadWrite) {
|
|
||||||
return !fileSystem.supportedFileAttributeViews().contains("posix") ? NO_FILE_ATTRIBUTES : new FileAttribute[]{PosixFilePermissions.asFileAttribute(ownerReadWrite)};
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
try {
|
|
||||||
return this.getUrl().toString();
|
|
||||||
} catch (Exception var2) {
|
|
||||||
return "jar archive";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static {
|
|
||||||
DIRECTORY_PERMISSIONS = EnumSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE);
|
|
||||||
FILE_PERMISSIONS = EnumSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE);
|
|
||||||
}
|
|
||||||
|
|
||||||
private abstract static class AbstractIterator implements Iterator {
|
|
||||||
private final Iterator iterator;
|
|
||||||
private final Archive.EntryFilter searchFilter;
|
|
||||||
private final Archive.EntryFilter includeFilter;
|
|
||||||
private Archive.Entry current;
|
|
||||||
|
|
||||||
AbstractIterator(Iterator iterator, Archive.EntryFilter searchFilter, Archive.EntryFilter includeFilter) {
|
|
||||||
this.iterator = iterator;
|
|
||||||
this.searchFilter = searchFilter;
|
|
||||||
this.includeFilter = includeFilter;
|
|
||||||
this.current = this.poll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasNext() {
|
|
||||||
return this.current != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object next() {
|
|
||||||
T result = (T)this.adapt(this.current);
|
|
||||||
this.current = this.poll();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Archive.Entry poll() {
|
|
||||||
while(true) {
|
|
||||||
if (this.iterator.hasNext()) {
|
|
||||||
JarFileEntry candidate = new JarFileEntry((JarEntry)this.iterator.next());
|
|
||||||
if (this.searchFilter != null && !this.searchFilter.matches(candidate) || this.includeFilter != null && !this.includeFilter.matches(candidate)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return candidate;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract Object adapt(Archive.Entry entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class EntryIterator extends AbstractIterator {
|
|
||||||
EntryIterator(Iterator iterator, Archive.EntryFilter searchFilter, Archive.EntryFilter includeFilter) {
|
|
||||||
super(iterator, searchFilter, includeFilter);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Archive.Entry adapt(Archive.Entry entry) {
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class NestedArchiveIterator extends AbstractIterator {
|
|
||||||
NestedArchiveIterator(Iterator iterator, Archive.EntryFilter searchFilter, Archive.EntryFilter includeFilter) {
|
|
||||||
super(iterator, searchFilter, includeFilter);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Archive adapt(Archive.Entry entry) {
|
|
||||||
try {
|
|
||||||
return JarFileArchive.this.getNestedArchive(entry);
|
|
||||||
} catch (IOException ex) {
|
|
||||||
throw new IllegalStateException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class JarFileEntry implements Archive.Entry {
|
|
||||||
private final JarEntry jarEntry;
|
|
||||||
|
|
||||||
JarFileEntry(JarEntry jarEntry) {
|
|
||||||
this.jarEntry = jarEntry;
|
|
||||||
}
|
|
||||||
|
|
||||||
JarEntry getJarEntry() {
|
|
||||||
return this.jarEntry;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDirectory() {
|
|
||||||
return this.jarEntry.isDirectory();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return this.jarEntry.getName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package org.springframework.boot.loader.data;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
public interface RandomAccessData {
|
|
||||||
InputStream getInputStream() throws IOException;
|
|
||||||
|
|
||||||
RandomAccessData getSubsection(long offset, long length);
|
|
||||||
|
|
||||||
byte[] read() throws IOException;
|
|
||||||
|
|
||||||
byte[] read(long offset, long length) throws IOException;
|
|
||||||
|
|
||||||
long getSize();
|
|
||||||
}
|
|
||||||
@@ -1,181 +0,0 @@
|
|||||||
package org.springframework.boot.loader.data;
|
|
||||||
|
|
||||||
import java.io.EOFException;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.RandomAccessFile;
|
|
||||||
|
|
||||||
public class RandomAccessDataFile implements RandomAccessData {
|
|
||||||
private final FileAccess fileAccess;
|
|
||||||
private final long offset;
|
|
||||||
private final long length;
|
|
||||||
|
|
||||||
public RandomAccessDataFile(File file) {
|
|
||||||
if (file == null) {
|
|
||||||
throw new IllegalArgumentException("File must not be null");
|
|
||||||
} else {
|
|
||||||
this.fileAccess = new FileAccess(file);
|
|
||||||
this.offset = 0L;
|
|
||||||
this.length = file.length();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private RandomAccessDataFile(FileAccess fileAccess, long offset, long length) {
|
|
||||||
this.fileAccess = fileAccess;
|
|
||||||
this.offset = offset;
|
|
||||||
this.length = length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public File getFile() {
|
|
||||||
return this.fileAccess.file;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InputStream getInputStream() throws IOException {
|
|
||||||
return new DataInputStream();
|
|
||||||
}
|
|
||||||
|
|
||||||
public RandomAccessData getSubsection(long offset, long length) {
|
|
||||||
if (offset >= 0L && length >= 0L && offset + length <= this.length) {
|
|
||||||
return new RandomAccessDataFile(this.fileAccess, this.offset + offset, length);
|
|
||||||
} else {
|
|
||||||
throw new IndexOutOfBoundsException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] read() throws IOException {
|
|
||||||
return this.read(0L, this.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] read(long offset, long length) throws IOException {
|
|
||||||
if (offset > this.length) {
|
|
||||||
throw new IndexOutOfBoundsException();
|
|
||||||
} else if (offset + length > this.length) {
|
|
||||||
throw new EOFException();
|
|
||||||
} else {
|
|
||||||
byte[] bytes = new byte[(int)length];
|
|
||||||
this.read(bytes, offset, 0, bytes.length);
|
|
||||||
return bytes;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int readByte(long position) throws IOException {
|
|
||||||
return position >= this.length ? -1 : this.fileAccess.readByte(this.offset + position);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int read(byte[] bytes, long position, int offset, int length) throws IOException {
|
|
||||||
return position > this.length ? -1 : this.fileAccess.read(bytes, this.offset + position, offset, length);
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getSize() {
|
|
||||||
return this.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void close() throws IOException {
|
|
||||||
this.fileAccess.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class DataInputStream extends InputStream {
|
|
||||||
private int position;
|
|
||||||
|
|
||||||
private DataInputStream() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public int read() throws IOException {
|
|
||||||
int read = RandomAccessDataFile.this.readByte((long)this.position);
|
|
||||||
if (read > -1) {
|
|
||||||
this.moveOn(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return read;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int read(byte[] b) throws IOException {
|
|
||||||
return this.read(b, 0, b != null ? b.length : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int read(byte[] b, int off, int len) throws IOException {
|
|
||||||
if (b == null) {
|
|
||||||
throw new NullPointerException("Bytes must not be null");
|
|
||||||
} else {
|
|
||||||
return this.doRead(b, off, len);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int doRead(byte[] b, int off, int len) throws IOException {
|
|
||||||
if (len == 0) {
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
int cappedLen = this.cap((long)len);
|
|
||||||
return cappedLen <= 0 ? -1 : (int)this.moveOn(RandomAccessDataFile.this.read(b, (long)this.position, off, cappedLen));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public long skip(long n) throws IOException {
|
|
||||||
return n <= 0L ? 0L : this.moveOn(this.cap(n));
|
|
||||||
}
|
|
||||||
|
|
||||||
public int available() throws IOException {
|
|
||||||
return (int)RandomAccessDataFile.this.length - this.position;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int cap(long n) {
|
|
||||||
return (int)Math.min(RandomAccessDataFile.this.length - (long)this.position, n);
|
|
||||||
}
|
|
||||||
|
|
||||||
private long moveOn(int amount) {
|
|
||||||
this.position += amount;
|
|
||||||
return (long)amount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class FileAccess {
|
|
||||||
private final Object monitor;
|
|
||||||
private final File file;
|
|
||||||
private RandomAccessFile randomAccessFile;
|
|
||||||
|
|
||||||
private FileAccess(File file) {
|
|
||||||
this.monitor = new Object();
|
|
||||||
this.file = file;
|
|
||||||
this.openIfNecessary();
|
|
||||||
}
|
|
||||||
|
|
||||||
private int read(byte[] bytes, long position, int offset, int length) throws IOException {
|
|
||||||
synchronized(this.monitor) {
|
|
||||||
this.openIfNecessary();
|
|
||||||
this.randomAccessFile.seek(position);
|
|
||||||
return this.randomAccessFile.read(bytes, offset, length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void openIfNecessary() {
|
|
||||||
if (this.randomAccessFile == null) {
|
|
||||||
try {
|
|
||||||
this.randomAccessFile = new RandomAccessFile(this.file, "r");
|
|
||||||
} catch (FileNotFoundException var2) {
|
|
||||||
throw new IllegalArgumentException(String.format("File %s must exist", this.file.getAbsolutePath()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void close() throws IOException {
|
|
||||||
synchronized(this.monitor) {
|
|
||||||
if (this.randomAccessFile != null) {
|
|
||||||
this.randomAccessFile.close();
|
|
||||||
this.randomAccessFile = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int readByte(long position) throws IOException {
|
|
||||||
synchronized(this.monitor) {
|
|
||||||
this.openIfNecessary();
|
|
||||||
this.randomAccessFile.seek(position);
|
|
||||||
return this.randomAccessFile.read();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package org.springframework.boot.loader.jar;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.security.Permission;
|
|
||||||
|
|
||||||
abstract class AbstractJarFile extends java.util.jar.JarFile {
|
|
||||||
AbstractJarFile(File file) throws IOException {
|
|
||||||
super(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract URL getUrl() throws MalformedURLException;
|
|
||||||
|
|
||||||
abstract JarFileType getType();
|
|
||||||
|
|
||||||
abstract Permission getPermission();
|
|
||||||
|
|
||||||
abstract InputStream getInputStream() throws IOException;
|
|
||||||
|
|
||||||
static enum JarFileType {
|
|
||||||
DIRECT,
|
|
||||||
NESTED_DIRECTORY,
|
|
||||||
NESTED_JAR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,214 +0,0 @@
|
|||||||
package org.springframework.boot.loader.jar;
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
final class AsciiBytes {
|
|
||||||
private static final String EMPTY_STRING = "";
|
|
||||||
private static final int[] INITIAL_BYTE_BITMASK = new int[]{127, 31, 15, 7};
|
|
||||||
private static final int SUBSEQUENT_BYTE_BITMASK = 63;
|
|
||||||
private final byte[] bytes;
|
|
||||||
private final int offset;
|
|
||||||
private final int length;
|
|
||||||
private String string;
|
|
||||||
private int hash;
|
|
||||||
|
|
||||||
AsciiBytes(String string) {
|
|
||||||
this(string.getBytes(StandardCharsets.UTF_8));
|
|
||||||
this.string = string;
|
|
||||||
}
|
|
||||||
|
|
||||||
AsciiBytes(byte[] bytes) {
|
|
||||||
this(bytes, 0, bytes.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
AsciiBytes(byte[] bytes, int offset, int length) {
|
|
||||||
if (offset >= 0 && length >= 0 && offset + length <= bytes.length) {
|
|
||||||
this.bytes = bytes;
|
|
||||||
this.offset = offset;
|
|
||||||
this.length = length;
|
|
||||||
} else {
|
|
||||||
throw new IndexOutOfBoundsException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int length() {
|
|
||||||
return this.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean startsWith(AsciiBytes prefix) {
|
|
||||||
if (this == prefix) {
|
|
||||||
return true;
|
|
||||||
} else if (prefix.length > this.length) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
for(int i = 0; i < prefix.length; ++i) {
|
|
||||||
if (this.bytes[i + this.offset] != prefix.bytes[i + prefix.offset]) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean endsWith(AsciiBytes postfix) {
|
|
||||||
if (this == postfix) {
|
|
||||||
return true;
|
|
||||||
} else if (postfix.length > this.length) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
for(int i = 0; i < postfix.length; ++i) {
|
|
||||||
if (this.bytes[this.offset + (this.length - 1) - i] != postfix.bytes[postfix.offset + (postfix.length - 1) - i]) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
AsciiBytes substring(int beginIndex) {
|
|
||||||
return this.substring(beginIndex, this.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
AsciiBytes substring(int beginIndex, int endIndex) {
|
|
||||||
int length = endIndex - beginIndex;
|
|
||||||
if (this.offset + length > this.bytes.length) {
|
|
||||||
throw new IndexOutOfBoundsException();
|
|
||||||
} else {
|
|
||||||
return new AsciiBytes(this.bytes, this.offset + beginIndex, length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean matches(CharSequence name, char suffix) {
|
|
||||||
int charIndex = 0;
|
|
||||||
int nameLen = name.length();
|
|
||||||
int totalLen = nameLen + (suffix != 0 ? 1 : 0);
|
|
||||||
|
|
||||||
for(int i = this.offset; i < this.offset + this.length; ++i) {
|
|
||||||
int b = this.bytes[i];
|
|
||||||
int remainingUtfBytes = this.getNumberOfUtfBytes(b) - 1;
|
|
||||||
b &= INITIAL_BYTE_BITMASK[remainingUtfBytes];
|
|
||||||
|
|
||||||
for(int j = 0; j < remainingUtfBytes; ++j) {
|
|
||||||
int var10000 = b << 6;
|
|
||||||
++i;
|
|
||||||
b = var10000 + (this.bytes[i] & 63);
|
|
||||||
}
|
|
||||||
|
|
||||||
char c = this.getChar(name, suffix, charIndex++);
|
|
||||||
if (b <= 65535) {
|
|
||||||
if (c != b) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (c != (b >> 10) + 'ퟀ') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
c = this.getChar(name, suffix, charIndex++);
|
|
||||||
if (c != (b & 1023) + '\udc00') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return charIndex == totalLen;
|
|
||||||
}
|
|
||||||
|
|
||||||
private char getChar(CharSequence name, char suffix, int index) {
|
|
||||||
if (index < name.length()) {
|
|
||||||
return name.charAt(index);
|
|
||||||
} else {
|
|
||||||
return index == name.length() ? suffix : '\u0000';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getNumberOfUtfBytes(int b) {
|
|
||||||
if ((b & 128) == 0) {
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
int numberOfUtfBytes;
|
|
||||||
for(numberOfUtfBytes = 0; (b & 128) != 0; ++numberOfUtfBytes) {
|
|
||||||
b <<= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return numberOfUtfBytes;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (obj == null) {
|
|
||||||
return false;
|
|
||||||
} else if (this == obj) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
if (obj.getClass() == AsciiBytes.class) {
|
|
||||||
AsciiBytes other = (AsciiBytes)obj;
|
|
||||||
if (this.length == other.length) {
|
|
||||||
for(int i = 0; i < this.length; ++i) {
|
|
||||||
if (this.bytes[this.offset + i] != other.bytes[other.offset + i]) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode() {
|
|
||||||
int hash = this.hash;
|
|
||||||
if (hash == 0 && this.bytes.length > 0) {
|
|
||||||
for(int i = this.offset; i < this.offset + this.length; ++i) {
|
|
||||||
int b = this.bytes[i];
|
|
||||||
int remainingUtfBytes = this.getNumberOfUtfBytes(b) - 1;
|
|
||||||
b &= INITIAL_BYTE_BITMASK[remainingUtfBytes];
|
|
||||||
|
|
||||||
for(int j = 0; j < remainingUtfBytes; ++j) {
|
|
||||||
int var10000 = b << 6;
|
|
||||||
++i;
|
|
||||||
b = var10000 + (this.bytes[i] & 63);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (b <= 65535) {
|
|
||||||
hash = 31 * hash + b;
|
|
||||||
} else {
|
|
||||||
hash = 31 * hash + (b >> 10) + 'ퟀ';
|
|
||||||
hash = 31 * hash + (b & 1023) + '\udc00';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.hash = hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
if (this.string == null) {
|
|
||||||
if (this.length == 0) {
|
|
||||||
this.string = "";
|
|
||||||
} else {
|
|
||||||
this.string = new String(this.bytes, this.offset, this.length, StandardCharsets.UTF_8);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.string;
|
|
||||||
}
|
|
||||||
|
|
||||||
static String toString(byte[] bytes) {
|
|
||||||
return new String(bytes, StandardCharsets.UTF_8);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int hashCode(CharSequence charSequence) {
|
|
||||||
return charSequence instanceof StringSequence ? charSequence.hashCode() : charSequence.toString().hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
static int hashCode(int hash, char suffix) {
|
|
||||||
return suffix != 0 ? 31 * hash + suffix : hash;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package org.springframework.boot.loader.jar;
|
|
||||||
|
|
||||||
final class Bytes {
|
|
||||||
private Bytes() {
|
|
||||||
}
|
|
||||||
|
|
||||||
static long littleEndianValue(byte[] bytes, int offset, int length) {
|
|
||||||
long value = 0L;
|
|
||||||
|
|
||||||
for(int i = length - 1; i >= 0; --i) {
|
|
||||||
value = value << 8 | (long)(bytes[offset + i] & 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,152 +0,0 @@
|
|||||||
package org.springframework.boot.loader.jar;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import org.springframework.boot.loader.data.RandomAccessData;
|
|
||||||
|
|
||||||
class CentralDirectoryEndRecord {
|
|
||||||
private static final int MINIMUM_SIZE = 22;
|
|
||||||
private static final int MAXIMUM_COMMENT_LENGTH = 65535;
|
|
||||||
private static final int MAXIMUM_SIZE = 65557;
|
|
||||||
private static final int SIGNATURE = 101010256;
|
|
||||||
private static final int COMMENT_LENGTH_OFFSET = 20;
|
|
||||||
private static final int READ_BLOCK_SIZE = 256;
|
|
||||||
private final Zip64End zip64End;
|
|
||||||
private byte[] block;
|
|
||||||
private int offset;
|
|
||||||
private int size;
|
|
||||||
|
|
||||||
CentralDirectoryEndRecord(RandomAccessData data) throws IOException {
|
|
||||||
this.block = this.createBlockFromEndOfData(data, 256);
|
|
||||||
this.size = 22;
|
|
||||||
|
|
||||||
for(this.offset = this.block.length - this.size; !this.isValid(); this.offset = this.block.length - this.size) {
|
|
||||||
++this.size;
|
|
||||||
if (this.size > this.block.length) {
|
|
||||||
if (this.size >= 65557 || (long)this.size > data.getSize()) {
|
|
||||||
throw new IOException("Unable to find ZIP central directory records after reading " + this.size + " bytes");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.block = this.createBlockFromEndOfData(data, this.size + 256);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
long startOfCentralDirectoryEndRecord = data.getSize() - (long)this.size;
|
|
||||||
Zip64Locator zip64Locator = CentralDirectoryEndRecord.Zip64Locator.find(data, startOfCentralDirectoryEndRecord);
|
|
||||||
this.zip64End = zip64Locator != null ? new Zip64End(data, zip64Locator) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private byte[] createBlockFromEndOfData(RandomAccessData data, int size) throws IOException {
|
|
||||||
int length = (int)Math.min(data.getSize(), (long)size);
|
|
||||||
return data.read(data.getSize() - (long)length, (long)length);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isValid() {
|
|
||||||
if (this.block.length >= 22 && Bytes.littleEndianValue(this.block, this.offset + 0, 4) == 101010256L) {
|
|
||||||
long commentLength = Bytes.littleEndianValue(this.block, this.offset + 20, 2);
|
|
||||||
return (long)this.size == 22L + commentLength;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
long getStartOfArchive(RandomAccessData data) {
|
|
||||||
long length = Bytes.littleEndianValue(this.block, this.offset + 12, 4);
|
|
||||||
long specifiedOffset = this.zip64End != null ? this.zip64End.centralDirectoryOffset : Bytes.littleEndianValue(this.block, this.offset + 16, 4);
|
|
||||||
long zip64EndSize = this.zip64End != null ? this.zip64End.getSize() : 0L;
|
|
||||||
int zip64LocSize = this.zip64End != null ? 20 : 0;
|
|
||||||
long actualOffset = data.getSize() - (long)this.size - length - zip64EndSize - (long)zip64LocSize;
|
|
||||||
return actualOffset - specifiedOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
RandomAccessData getCentralDirectory(RandomAccessData data) {
|
|
||||||
if (this.zip64End != null) {
|
|
||||||
return this.zip64End.getCentralDirectory(data);
|
|
||||||
} else {
|
|
||||||
long offset = Bytes.littleEndianValue(this.block, this.offset + 16, 4);
|
|
||||||
long length = Bytes.littleEndianValue(this.block, this.offset + 12, 4);
|
|
||||||
return data.getSubsection(offset, length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int getNumberOfRecords() {
|
|
||||||
if (this.zip64End != null) {
|
|
||||||
return this.zip64End.getNumberOfRecords();
|
|
||||||
} else {
|
|
||||||
long numberOfRecords = Bytes.littleEndianValue(this.block, this.offset + 10, 2);
|
|
||||||
return (int)numberOfRecords;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String getComment() {
|
|
||||||
int commentLength = (int)Bytes.littleEndianValue(this.block, this.offset + 20, 2);
|
|
||||||
AsciiBytes comment = new AsciiBytes(this.block, this.offset + 20 + 2, commentLength);
|
|
||||||
return comment.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isZip64() {
|
|
||||||
return this.zip64End != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class Zip64End {
|
|
||||||
private static final int ZIP64_ENDTOT = 32;
|
|
||||||
private static final int ZIP64_ENDSIZ = 40;
|
|
||||||
private static final int ZIP64_ENDOFF = 48;
|
|
||||||
private final Zip64Locator locator;
|
|
||||||
private final long centralDirectoryOffset;
|
|
||||||
private final long centralDirectoryLength;
|
|
||||||
private final int numberOfRecords;
|
|
||||||
|
|
||||||
private Zip64End(RandomAccessData data, Zip64Locator locator) throws IOException {
|
|
||||||
this.locator = locator;
|
|
||||||
byte[] block = data.read(locator.getZip64EndOffset(), 56L);
|
|
||||||
this.centralDirectoryOffset = Bytes.littleEndianValue(block, 48, 8);
|
|
||||||
this.centralDirectoryLength = Bytes.littleEndianValue(block, 40, 8);
|
|
||||||
this.numberOfRecords = (int)Bytes.littleEndianValue(block, 32, 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
private long getSize() {
|
|
||||||
return this.locator.getZip64EndSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
private RandomAccessData getCentralDirectory(RandomAccessData data) {
|
|
||||||
return data.getSubsection(this.centralDirectoryOffset, this.centralDirectoryLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getNumberOfRecords() {
|
|
||||||
return this.numberOfRecords;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class Zip64Locator {
|
|
||||||
static final int SIGNATURE = 117853008;
|
|
||||||
static final int ZIP64_LOCSIZE = 20;
|
|
||||||
static final int ZIP64_LOCOFF = 8;
|
|
||||||
private final long zip64EndOffset;
|
|
||||||
private final long offset;
|
|
||||||
|
|
||||||
private Zip64Locator(long offset, byte[] block) {
|
|
||||||
this.offset = offset;
|
|
||||||
this.zip64EndOffset = Bytes.littleEndianValue(block, 8, 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
private long getZip64EndSize() {
|
|
||||||
return this.offset - this.zip64EndOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
private long getZip64EndOffset() {
|
|
||||||
return this.zip64EndOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Zip64Locator find(RandomAccessData data, long centralDirectoryEndOffset) throws IOException {
|
|
||||||
long offset = centralDirectoryEndOffset - 20L;
|
|
||||||
if (offset >= 0L) {
|
|
||||||
byte[] block = data.read(offset, 20L);
|
|
||||||
if (Bytes.littleEndianValue(block, 0, 4) == 117853008L) {
|
|
||||||
return new Zip64Locator(offset, block);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,172 +0,0 @@
|
|||||||
package org.springframework.boot.loader.jar;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.time.temporal.ChronoField;
|
|
||||||
import java.time.temporal.ChronoUnit;
|
|
||||||
import java.time.temporal.ValueRange;
|
|
||||||
import org.springframework.boot.loader.data.RandomAccessData;
|
|
||||||
|
|
||||||
final class CentralDirectoryFileHeader implements FileHeader {
|
|
||||||
private static final AsciiBytes SLASH = new AsciiBytes("/");
|
|
||||||
private static final byte[] NO_EXTRA = new byte[0];
|
|
||||||
private static final AsciiBytes NO_COMMENT = new AsciiBytes("");
|
|
||||||
private byte[] header;
|
|
||||||
private int headerOffset;
|
|
||||||
private AsciiBytes name;
|
|
||||||
private byte[] extra;
|
|
||||||
private AsciiBytes comment;
|
|
||||||
private long localHeaderOffset;
|
|
||||||
|
|
||||||
CentralDirectoryFileHeader() {
|
|
||||||
}
|
|
||||||
|
|
||||||
CentralDirectoryFileHeader(byte[] header, int headerOffset, AsciiBytes name, byte[] extra, AsciiBytes comment, long localHeaderOffset) {
|
|
||||||
this.header = header;
|
|
||||||
this.headerOffset = headerOffset;
|
|
||||||
this.name = name;
|
|
||||||
this.extra = extra;
|
|
||||||
this.comment = comment;
|
|
||||||
this.localHeaderOffset = localHeaderOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
void load(byte[] data, int dataOffset, RandomAccessData variableData, long variableOffset, JarEntryFilter filter) throws IOException {
|
|
||||||
this.header = data;
|
|
||||||
this.headerOffset = dataOffset;
|
|
||||||
long compressedSize = Bytes.littleEndianValue(data, dataOffset + 20, 4);
|
|
||||||
long uncompressedSize = Bytes.littleEndianValue(data, dataOffset + 24, 4);
|
|
||||||
long nameLength = Bytes.littleEndianValue(data, dataOffset + 28, 2);
|
|
||||||
long extraLength = Bytes.littleEndianValue(data, dataOffset + 30, 2);
|
|
||||||
long commentLength = Bytes.littleEndianValue(data, dataOffset + 32, 2);
|
|
||||||
long localHeaderOffset = Bytes.littleEndianValue(data, dataOffset + 42, 4);
|
|
||||||
dataOffset += 46;
|
|
||||||
if (variableData != null) {
|
|
||||||
data = variableData.read(variableOffset + 46L, nameLength + extraLength + commentLength);
|
|
||||||
dataOffset = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.name = new AsciiBytes(data, dataOffset, (int)nameLength);
|
|
||||||
if (filter != null) {
|
|
||||||
this.name = filter.apply(this.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.extra = NO_EXTRA;
|
|
||||||
this.comment = NO_COMMENT;
|
|
||||||
if (extraLength > 0L) {
|
|
||||||
this.extra = new byte[(int)extraLength];
|
|
||||||
System.arraycopy(data, (int)((long)dataOffset + nameLength), this.extra, 0, this.extra.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.localHeaderOffset = this.getLocalHeaderOffset(compressedSize, uncompressedSize, localHeaderOffset, this.extra);
|
|
||||||
if (commentLength > 0L) {
|
|
||||||
this.comment = new AsciiBytes(data, (int)((long)dataOffset + nameLength + extraLength), (int)commentLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private long getLocalHeaderOffset(long compressedSize, long uncompressedSize, long localHeaderOffset, byte[] extra) throws IOException {
|
|
||||||
if (localHeaderOffset != 4294967295L) {
|
|
||||||
return localHeaderOffset;
|
|
||||||
} else {
|
|
||||||
int length;
|
|
||||||
int extraOffset;
|
|
||||||
for(extraOffset = 0; extraOffset < extra.length - 2; extraOffset += length) {
|
|
||||||
int id = (int)Bytes.littleEndianValue(extra, extraOffset, 2);
|
|
||||||
length = (int)Bytes.littleEndianValue(extra, extraOffset, 2);
|
|
||||||
extraOffset += 4;
|
|
||||||
if (id == 1) {
|
|
||||||
int localHeaderExtraOffset = 0;
|
|
||||||
if (compressedSize == 4294967295L) {
|
|
||||||
localHeaderExtraOffset += 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (uncompressedSize == 4294967295L) {
|
|
||||||
localHeaderExtraOffset += 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Bytes.littleEndianValue(extra, extraOffset + localHeaderExtraOffset, 8);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new IOException("Zip64 Extended Information Extra Field not found");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
AsciiBytes getName() {
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasName(CharSequence name, char suffix) {
|
|
||||||
return this.name.matches(name, suffix);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isDirectory() {
|
|
||||||
return this.name.endsWith(SLASH);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMethod() {
|
|
||||||
return (int)Bytes.littleEndianValue(this.header, this.headerOffset + 10, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
long getTime() {
|
|
||||||
long datetime = Bytes.littleEndianValue(this.header, this.headerOffset + 12, 4);
|
|
||||||
return this.decodeMsDosFormatDateTime(datetime);
|
|
||||||
}
|
|
||||||
|
|
||||||
private long decodeMsDosFormatDateTime(long datetime) {
|
|
||||||
int year = getChronoValue((datetime >> 25 & 127L) + 1980L, ChronoField.YEAR);
|
|
||||||
int month = getChronoValue(datetime >> 21 & 15L, ChronoField.MONTH_OF_YEAR);
|
|
||||||
int day = getChronoValue(datetime >> 16 & 31L, ChronoField.DAY_OF_MONTH);
|
|
||||||
int hour = getChronoValue(datetime >> 11 & 31L, ChronoField.HOUR_OF_DAY);
|
|
||||||
int minute = getChronoValue(datetime >> 5 & 63L, ChronoField.MINUTE_OF_HOUR);
|
|
||||||
int second = getChronoValue(datetime << 1 & 62L, ChronoField.SECOND_OF_MINUTE);
|
|
||||||
return ZonedDateTime.of(year, month, day, hour, minute, second, 0, ZoneId.systemDefault()).toInstant().truncatedTo(ChronoUnit.SECONDS).toEpochMilli();
|
|
||||||
}
|
|
||||||
|
|
||||||
long getCrc() {
|
|
||||||
return Bytes.littleEndianValue(this.header, this.headerOffset + 16, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getCompressedSize() {
|
|
||||||
return Bytes.littleEndianValue(this.header, this.headerOffset + 20, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getSize() {
|
|
||||||
return Bytes.littleEndianValue(this.header, this.headerOffset + 24, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] getExtra() {
|
|
||||||
return this.extra;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean hasExtra() {
|
|
||||||
return this.extra.length > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
AsciiBytes getComment() {
|
|
||||||
return this.comment;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getLocalHeaderOffset() {
|
|
||||||
return this.localHeaderOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CentralDirectoryFileHeader clone() {
|
|
||||||
byte[] header = new byte[46];
|
|
||||||
System.arraycopy(this.header, this.headerOffset, header, 0, header.length);
|
|
||||||
return new CentralDirectoryFileHeader(header, 0, this.name, header, this.comment, this.localHeaderOffset);
|
|
||||||
}
|
|
||||||
|
|
||||||
static CentralDirectoryFileHeader fromRandomAccessData(RandomAccessData data, long offset, JarEntryFilter filter) throws IOException {
|
|
||||||
CentralDirectoryFileHeader fileHeader = new CentralDirectoryFileHeader();
|
|
||||||
byte[] bytes = data.read(offset, 46L);
|
|
||||||
fileHeader.load(bytes, 0, data, offset, filter);
|
|
||||||
return fileHeader;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int getChronoValue(long value, ChronoField field) {
|
|
||||||
ValueRange range = field.range();
|
|
||||||
return Math.toIntExact(Math.min(Math.max(value, range.getMinimum()), range.getMaximum()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
package org.springframework.boot.loader.jar;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import org.springframework.boot.loader.data.RandomAccessData;
|
|
||||||
|
|
||||||
class CentralDirectoryParser {
|
|
||||||
private static final int CENTRAL_DIRECTORY_HEADER_BASE_SIZE = 46;
|
|
||||||
private final List visitors = new ArrayList();
|
|
||||||
|
|
||||||
CentralDirectoryVisitor addVisitor(CentralDirectoryVisitor visitor) {
|
|
||||||
this.visitors.add(visitor);
|
|
||||||
return visitor;
|
|
||||||
}
|
|
||||||
|
|
||||||
RandomAccessData parse(RandomAccessData data, boolean skipPrefixBytes) throws IOException {
|
|
||||||
CentralDirectoryEndRecord endRecord = new CentralDirectoryEndRecord(data);
|
|
||||||
if (skipPrefixBytes) {
|
|
||||||
data = this.getArchiveData(endRecord, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
RandomAccessData centralDirectoryData = endRecord.getCentralDirectory(data);
|
|
||||||
this.visitStart(endRecord, centralDirectoryData);
|
|
||||||
this.parseEntries(endRecord, centralDirectoryData);
|
|
||||||
this.visitEnd();
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void parseEntries(CentralDirectoryEndRecord endRecord, RandomAccessData centralDirectoryData) throws IOException {
|
|
||||||
byte[] bytes = centralDirectoryData.read(0L, centralDirectoryData.getSize());
|
|
||||||
CentralDirectoryFileHeader fileHeader = new CentralDirectoryFileHeader();
|
|
||||||
int dataOffset = 0;
|
|
||||||
|
|
||||||
for(int i = 0; i < endRecord.getNumberOfRecords(); ++i) {
|
|
||||||
fileHeader.load(bytes, dataOffset, (RandomAccessData)null, 0L, (JarEntryFilter)null);
|
|
||||||
this.visitFileHeader((long)dataOffset, fileHeader);
|
|
||||||
dataOffset += 46 + fileHeader.getName().length() + fileHeader.getComment().length() + fileHeader.getExtra().length;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private RandomAccessData getArchiveData(CentralDirectoryEndRecord endRecord, RandomAccessData data) {
|
|
||||||
long offset = endRecord.getStartOfArchive(data);
|
|
||||||
return offset == 0L ? data : data.getSubsection(offset, data.getSize() - offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void visitStart(CentralDirectoryEndRecord endRecord, RandomAccessData centralDirectoryData) {
|
|
||||||
for(CentralDirectoryVisitor visitor : this.visitors) {
|
|
||||||
visitor.visitStart(endRecord, centralDirectoryData);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void visitFileHeader(long dataOffset, CentralDirectoryFileHeader fileHeader) {
|
|
||||||
for(CentralDirectoryVisitor visitor : this.visitors) {
|
|
||||||
visitor.visitFileHeader(fileHeader, dataOffset);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void visitEnd() {
|
|
||||||
for(CentralDirectoryVisitor visitor : this.visitors) {
|
|
||||||
visitor.visitEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
package org.springframework.boot.loader.jar;
|
|
||||||
|
|
||||||
import org.springframework.boot.loader.data.RandomAccessData;
|
|
||||||
|
|
||||||
interface CentralDirectoryVisitor {
|
|
||||||
void visitStart(CentralDirectoryEndRecord endRecord, RandomAccessData centralDirectoryData);
|
|
||||||
|
|
||||||
void visitFileHeader(CentralDirectoryFileHeader fileHeader, long dataOffset);
|
|
||||||
|
|
||||||
void visitEnd();
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package org.springframework.boot.loader.jar;
|
|
||||||
|
|
||||||
interface FileHeader {
|
|
||||||
boolean hasName(CharSequence name, char suffix);
|
|
||||||
|
|
||||||
long getLocalHeaderOffset();
|
|
||||||
|
|
||||||
long getCompressedSize();
|
|
||||||
|
|
||||||
long getSize();
|
|
||||||
|
|
||||||
int getMethod();
|
|
||||||
}
|
|
||||||
@@ -1,390 +0,0 @@
|
|||||||
package org.springframework.boot.loader.jar;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.ref.SoftReference;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.net.URLStreamHandler;
|
|
||||||
import java.net.URLStreamHandlerFactory;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class Handler extends URLStreamHandler {
|
|
||||||
private static final String JAR_PROTOCOL = "jar:";
|
|
||||||
private static final String FILE_PROTOCOL = "file:";
|
|
||||||
private static final String TOMCAT_WARFILE_PROTOCOL = "war:file:";
|
|
||||||
private static final String SEPARATOR = "!/";
|
|
||||||
private static final Pattern SEPARATOR_PATTERN = Pattern.compile("!/", 16);
|
|
||||||
private static final String CURRENT_DIR = "/./";
|
|
||||||
private static final Pattern CURRENT_DIR_PATTERN = Pattern.compile("/./", 16);
|
|
||||||
private static final String PARENT_DIR = "/../";
|
|
||||||
private static final String PROTOCOL_HANDLER = "java.protocol.handler.pkgs";
|
|
||||||
private static final String[] FALLBACK_HANDLERS = new String[]{"sun.net.www.protocol.jar.Handler"};
|
|
||||||
private static URL jarContextUrl;
|
|
||||||
private static SoftReference rootFileCache = new SoftReference((Object)null);
|
|
||||||
private final JarFile jarFile;
|
|
||||||
private URLStreamHandler fallbackHandler;
|
|
||||||
|
|
||||||
public Handler() {
|
|
||||||
this((JarFile)null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Handler(JarFile jarFile) {
|
|
||||||
this.jarFile = jarFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected URLConnection openConnection(URL url) throws IOException {
|
|
||||||
if (this.jarFile != null && this.isUrlInJarFile(url, this.jarFile)) {
|
|
||||||
return JarURLConnection.get(url, this.jarFile);
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
return JarURLConnection.get(url, this.getRootJarFileFromUrl(url));
|
|
||||||
} catch (Exception ex) {
|
|
||||||
return this.openFallbackConnection(url, ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isUrlInJarFile(URL url, JarFile jarFile) throws MalformedURLException {
|
|
||||||
return url.getPath().startsWith(jarFile.getUrl().getPath()) && url.toString().startsWith(jarFile.getUrlString());
|
|
||||||
}
|
|
||||||
|
|
||||||
private URLConnection openFallbackConnection(URL url, Exception reason) throws IOException {
|
|
||||||
try {
|
|
||||||
URLConnection connection = this.openFallbackTomcatConnection(url);
|
|
||||||
connection = connection != null ? connection : this.openFallbackContextConnection(url);
|
|
||||||
return connection != null ? connection : this.openFallbackHandlerConnection(url);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
if (reason instanceof IOException) {
|
|
||||||
this.log(false, "Unable to open fallback handler", ex);
|
|
||||||
throw (IOException)reason;
|
|
||||||
} else {
|
|
||||||
this.log(true, "Unable to open fallback handler", ex);
|
|
||||||
if (reason instanceof RuntimeException) {
|
|
||||||
throw (RuntimeException)reason;
|
|
||||||
} else {
|
|
||||||
throw new IllegalStateException(reason);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private URLConnection openFallbackTomcatConnection(URL url) {
|
|
||||||
String file = url.getFile();
|
|
||||||
if (this.isTomcatWarUrl(file)) {
|
|
||||||
file = file.substring("war:file:".length());
|
|
||||||
file = file.replaceFirst("\\*/", "!/");
|
|
||||||
|
|
||||||
try {
|
|
||||||
URLConnection connection = this.openConnection(new URL("jar:file:" + file));
|
|
||||||
connection.getInputStream().close();
|
|
||||||
return connection;
|
|
||||||
} catch (IOException var4) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isTomcatWarUrl(String file) {
|
|
||||||
if (file.startsWith("war:file:") || !file.contains("*/")) {
|
|
||||||
try {
|
|
||||||
URLConnection connection = (new URL(file)).openConnection();
|
|
||||||
if (connection.getClass().getName().startsWith("org.apache.catalina")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} catch (Exception var3) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private URLConnection openFallbackContextConnection(URL url) {
|
|
||||||
try {
|
|
||||||
if (jarContextUrl != null) {
|
|
||||||
return (new URL(jarContextUrl, url.toExternalForm())).openConnection();
|
|
||||||
}
|
|
||||||
} catch (Exception var3) {
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private URLConnection openFallbackHandlerConnection(URL url) throws Exception {
|
|
||||||
URLStreamHandler fallbackHandler = this.getFallbackHandler();
|
|
||||||
return (new URL((URL)null, url.toExternalForm(), fallbackHandler)).openConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
private URLStreamHandler getFallbackHandler() {
|
|
||||||
if (this.fallbackHandler != null) {
|
|
||||||
return this.fallbackHandler;
|
|
||||||
} else {
|
|
||||||
for(String handlerClassName : FALLBACK_HANDLERS) {
|
|
||||||
try {
|
|
||||||
Class<?> handlerClass = Class.forName(handlerClassName);
|
|
||||||
this.fallbackHandler = (URLStreamHandler)handlerClass.getDeclaredConstructor().newInstance();
|
|
||||||
return this.fallbackHandler;
|
|
||||||
} catch (Exception var6) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new IllegalStateException("Unable to find fallback handler");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void log(boolean warning, String message, Exception cause) {
|
|
||||||
try {
|
|
||||||
Level level = warning ? Level.WARNING : Level.FINEST;
|
|
||||||
Logger.getLogger(this.getClass().getName()).log(level, message, cause);
|
|
||||||
} catch (Exception var5) {
|
|
||||||
if (warning) {
|
|
||||||
System.err.println("WARNING: " + message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void parseURL(URL context, String spec, int start, int limit) {
|
|
||||||
if (spec.regionMatches(true, 0, "jar:", 0, "jar:".length())) {
|
|
||||||
this.setFile(context, this.getFileFromSpec(spec.substring(start, limit)));
|
|
||||||
} else {
|
|
||||||
this.setFile(context, this.getFileFromContext(context, spec.substring(start, limit)));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getFileFromSpec(String spec) {
|
|
||||||
int separatorIndex = spec.lastIndexOf("!/");
|
|
||||||
if (separatorIndex == -1) {
|
|
||||||
throw new IllegalArgumentException("No !/ in spec '" + spec + "'");
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
new URL(spec.substring(0, separatorIndex));
|
|
||||||
return spec;
|
|
||||||
} catch (MalformedURLException ex) {
|
|
||||||
throw new IllegalArgumentException("Invalid spec URL '" + spec + "'", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getFileFromContext(URL context, String spec) {
|
|
||||||
String file = context.getFile();
|
|
||||||
if (spec.startsWith("/")) {
|
|
||||||
return this.trimToJarRoot(file) + "!/" + spec.substring(1);
|
|
||||||
} else if (file.endsWith("/")) {
|
|
||||||
return file + spec;
|
|
||||||
} else {
|
|
||||||
int lastSlashIndex = file.lastIndexOf(47);
|
|
||||||
if (lastSlashIndex == -1) {
|
|
||||||
throw new IllegalArgumentException("No / found in context URL's file '" + file + "'");
|
|
||||||
} else {
|
|
||||||
return file.substring(0, lastSlashIndex + 1) + spec;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String trimToJarRoot(String file) {
|
|
||||||
int lastSeparatorIndex = file.lastIndexOf("!/");
|
|
||||||
if (lastSeparatorIndex == -1) {
|
|
||||||
throw new IllegalArgumentException("No !/ found in context URL's file '" + file + "'");
|
|
||||||
} else {
|
|
||||||
return file.substring(0, lastSeparatorIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setFile(URL context, String file) {
|
|
||||||
String path = this.normalize(file);
|
|
||||||
String query = null;
|
|
||||||
int queryIndex = path.lastIndexOf(63);
|
|
||||||
if (queryIndex != -1) {
|
|
||||||
query = path.substring(queryIndex + 1);
|
|
||||||
path = path.substring(0, queryIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setURL(context, "jar:", (String)null, -1, (String)null, (String)null, path, query, context.getRef());
|
|
||||||
}
|
|
||||||
|
|
||||||
private String normalize(String file) {
|
|
||||||
if (!file.contains("/./") && !file.contains("/../")) {
|
|
||||||
return file;
|
|
||||||
} else {
|
|
||||||
int afterLastSeparatorIndex = file.lastIndexOf("!/") + "!/".length();
|
|
||||||
String afterSeparator = file.substring(afterLastSeparatorIndex);
|
|
||||||
afterSeparator = this.replaceParentDir(afterSeparator);
|
|
||||||
afterSeparator = this.replaceCurrentDir(afterSeparator);
|
|
||||||
return file.substring(0, afterLastSeparatorIndex) + afterSeparator;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String replaceParentDir(String file) {
|
|
||||||
int parentDirIndex;
|
|
||||||
while((parentDirIndex = file.indexOf("/../")) >= 0) {
|
|
||||||
int precedingSlashIndex = file.lastIndexOf(47, parentDirIndex - 1);
|
|
||||||
if (precedingSlashIndex >= 0) {
|
|
||||||
file = file.substring(0, precedingSlashIndex) + file.substring(parentDirIndex + 3);
|
|
||||||
} else {
|
|
||||||
file = file.substring(parentDirIndex + 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return file;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String replaceCurrentDir(String file) {
|
|
||||||
return CURRENT_DIR_PATTERN.matcher(file).replaceAll("/");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int hashCode(URL u) {
|
|
||||||
return this.hashCode(u.getProtocol(), u.getFile());
|
|
||||||
}
|
|
||||||
|
|
||||||
private int hashCode(String protocol, String file) {
|
|
||||||
int result = protocol != null ? protocol.hashCode() : 0;
|
|
||||||
int separatorIndex = file.indexOf("!/");
|
|
||||||
if (separatorIndex == -1) {
|
|
||||||
return result + file.hashCode();
|
|
||||||
} else {
|
|
||||||
String source = file.substring(0, separatorIndex);
|
|
||||||
String entry = this.canonicalize(file.substring(separatorIndex + 2));
|
|
||||||
|
|
||||||
try {
|
|
||||||
result += (new URL(source)).hashCode();
|
|
||||||
} catch (MalformedURLException var8) {
|
|
||||||
result += source.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
result += entry.hashCode();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean sameFile(URL u1, URL u2) {
|
|
||||||
if (u1.getProtocol().equals("jar") && u2.getProtocol().equals("jar")) {
|
|
||||||
int separator1 = u1.getFile().indexOf("!/");
|
|
||||||
int separator2 = u2.getFile().indexOf("!/");
|
|
||||||
if (separator1 != -1 && separator2 != -1) {
|
|
||||||
String nested1 = u1.getFile().substring(separator1 + "!/".length());
|
|
||||||
String nested2 = u2.getFile().substring(separator2 + "!/".length());
|
|
||||||
if (!nested1.equals(nested2)) {
|
|
||||||
String canonical1 = this.canonicalize(nested1);
|
|
||||||
String canonical2 = this.canonicalize(nested2);
|
|
||||||
if (!canonical1.equals(canonical2)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String root1 = u1.getFile().substring(0, separator1);
|
|
||||||
String root2 = u2.getFile().substring(0, separator2);
|
|
||||||
|
|
||||||
try {
|
|
||||||
return super.sameFile(new URL(root1), new URL(root2));
|
|
||||||
} catch (MalformedURLException var10) {
|
|
||||||
return super.sameFile(u1, u2);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return super.sameFile(u1, u2);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String canonicalize(String path) {
|
|
||||||
return SEPARATOR_PATTERN.matcher(path).replaceAll("/");
|
|
||||||
}
|
|
||||||
|
|
||||||
public JarFile getRootJarFileFromUrl(URL url) throws IOException {
|
|
||||||
String spec = url.getFile();
|
|
||||||
int separatorIndex = spec.indexOf("!/");
|
|
||||||
if (separatorIndex == -1) {
|
|
||||||
throw new MalformedURLException("Jar URL does not contain !/ separator");
|
|
||||||
} else {
|
|
||||||
String name = spec.substring(0, separatorIndex);
|
|
||||||
return this.getRootJarFile(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private JarFile getRootJarFile(String name) throws IOException {
|
|
||||||
try {
|
|
||||||
if (!name.startsWith("file:")) {
|
|
||||||
throw new IllegalStateException("Not a file URL");
|
|
||||||
} else {
|
|
||||||
File file = new File(URI.create(name));
|
|
||||||
Map<File, JarFile> cache = (Map)rootFileCache.get();
|
|
||||||
JarFile result = cache != null ? (JarFile)cache.get(file) : null;
|
|
||||||
if (result == null) {
|
|
||||||
result = new JarFile(file);
|
|
||||||
addToRootFileCache(file, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
throw new IOException("Unable to open root Jar file '" + name + "'", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void addToRootFileCache(File sourceFile, JarFile jarFile) {
|
|
||||||
Map<File, JarFile> cache = (Map)rootFileCache.get();
|
|
||||||
if (cache == null) {
|
|
||||||
cache = new ConcurrentHashMap();
|
|
||||||
rootFileCache = new SoftReference(cache);
|
|
||||||
}
|
|
||||||
|
|
||||||
cache.put(sourceFile, jarFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void captureJarContextUrl() {
|
|
||||||
if (canResetCachedUrlHandlers()) {
|
|
||||||
String handlers = System.getProperty("java.protocol.handler.pkgs");
|
|
||||||
|
|
||||||
try {
|
|
||||||
System.clearProperty("java.protocol.handler.pkgs");
|
|
||||||
|
|
||||||
try {
|
|
||||||
resetCachedUrlHandlers();
|
|
||||||
jarContextUrl = new URL("jar:file:context.jar!/");
|
|
||||||
URLConnection connection = jarContextUrl.openConnection();
|
|
||||||
if (connection instanceof JarURLConnection) {
|
|
||||||
jarContextUrl = null;
|
|
||||||
}
|
|
||||||
} catch (Exception var5) {
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
if (handlers == null) {
|
|
||||||
System.clearProperty("java.protocol.handler.pkgs");
|
|
||||||
} else {
|
|
||||||
System.setProperty("java.protocol.handler.pkgs", handlers);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
resetCachedUrlHandlers();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean canResetCachedUrlHandlers() {
|
|
||||||
try {
|
|
||||||
resetCachedUrlHandlers();
|
|
||||||
return true;
|
|
||||||
} catch (Error var1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void resetCachedUrlHandlers() {
|
|
||||||
URL.setURLStreamHandlerFactory((URLStreamHandlerFactory)null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setUseFastConnectionExceptions(boolean useFastConnectionExceptions) {
|
|
||||||
JarURLConnection.setUseFastExceptions(useFastConnectionExceptions);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
package org.springframework.boot.loader.jar;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.security.CodeSigner;
|
|
||||||
import java.security.cert.Certificate;
|
|
||||||
import java.util.jar.Attributes;
|
|
||||||
import java.util.jar.Manifest;
|
|
||||||
|
|
||||||
class JarEntry extends java.util.jar.JarEntry implements FileHeader {
|
|
||||||
private final int index;
|
|
||||||
private final AsciiBytes name;
|
|
||||||
private final AsciiBytes headerName;
|
|
||||||
private final JarFile jarFile;
|
|
||||||
private long localHeaderOffset;
|
|
||||||
private volatile JarEntryCertification certification;
|
|
||||||
|
|
||||||
JarEntry(JarFile jarFile, int index, CentralDirectoryFileHeader header, AsciiBytes nameAlias) {
|
|
||||||
super(nameAlias != null ? nameAlias.toString() : header.getName().toString());
|
|
||||||
this.index = index;
|
|
||||||
this.name = nameAlias != null ? nameAlias : header.getName();
|
|
||||||
this.headerName = header.getName();
|
|
||||||
this.jarFile = jarFile;
|
|
||||||
this.localHeaderOffset = header.getLocalHeaderOffset();
|
|
||||||
this.setCompressedSize(header.getCompressedSize());
|
|
||||||
this.setMethod(header.getMethod());
|
|
||||||
this.setCrc(header.getCrc());
|
|
||||||
this.setComment(header.getComment().toString());
|
|
||||||
this.setSize(header.getSize());
|
|
||||||
this.setTime(header.getTime());
|
|
||||||
if (header.hasExtra()) {
|
|
||||||
this.setExtra(header.getExtra());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int getIndex() {
|
|
||||||
return this.index;
|
|
||||||
}
|
|
||||||
|
|
||||||
AsciiBytes getAsciiBytesName() {
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasName(CharSequence name, char suffix) {
|
|
||||||
return this.headerName.matches(name, suffix);
|
|
||||||
}
|
|
||||||
|
|
||||||
URL getUrl() throws MalformedURLException {
|
|
||||||
return new URL(this.jarFile.getUrl(), this.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Attributes getAttributes() throws IOException {
|
|
||||||
Manifest manifest = this.jarFile.getManifest();
|
|
||||||
return manifest != null ? manifest.getAttributes(this.getName()) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Certificate[] getCertificates() {
|
|
||||||
return this.getCertification().getCertificates();
|
|
||||||
}
|
|
||||||
|
|
||||||
public CodeSigner[] getCodeSigners() {
|
|
||||||
return this.getCertification().getCodeSigners();
|
|
||||||
}
|
|
||||||
|
|
||||||
private JarEntryCertification getCertification() {
|
|
||||||
if (!this.jarFile.isSigned()) {
|
|
||||||
return JarEntryCertification.NONE;
|
|
||||||
} else {
|
|
||||||
JarEntryCertification certification = this.certification;
|
|
||||||
if (certification == null) {
|
|
||||||
certification = this.jarFile.getCertification(this);
|
|
||||||
this.certification = certification;
|
|
||||||
}
|
|
||||||
|
|
||||||
return certification;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getLocalHeaderOffset() {
|
|
||||||
return this.localHeaderOffset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package org.springframework.boot.loader.jar;
|
|
||||||
|
|
||||||
import java.security.CodeSigner;
|
|
||||||
import java.security.cert.Certificate;
|
|
||||||
|
|
||||||
class JarEntryCertification {
|
|
||||||
static final JarEntryCertification NONE = new JarEntryCertification((Certificate[])null, (CodeSigner[])null);
|
|
||||||
private final Certificate[] certificates;
|
|
||||||
private final CodeSigner[] codeSigners;
|
|
||||||
|
|
||||||
JarEntryCertification(Certificate[] certificates, CodeSigner[] codeSigners) {
|
|
||||||
this.certificates = certificates;
|
|
||||||
this.codeSigners = codeSigners;
|
|
||||||
}
|
|
||||||
|
|
||||||
Certificate[] getCertificates() {
|
|
||||||
return this.certificates != null ? (Certificate[])this.certificates.clone() : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
CodeSigner[] getCodeSigners() {
|
|
||||||
return this.codeSigners != null ? (CodeSigner[])this.codeSigners.clone() : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
static JarEntryCertification from(java.util.jar.JarEntry certifiedEntry) {
|
|
||||||
Certificate[] certificates = certifiedEntry != null ? certifiedEntry.getCertificates() : null;
|
|
||||||
CodeSigner[] codeSigners = certifiedEntry != null ? certifiedEntry.getCodeSigners() : null;
|
|
||||||
return certificates == null && codeSigners == null ? NONE : new JarEntryCertification(certificates, codeSigners);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package org.springframework.boot.loader.jar;
|
|
||||||
|
|
||||||
interface JarEntryFilter {
|
|
||||||
AsciiBytes apply(AsciiBytes name);
|
|
||||||
}
|
|
||||||
@@ -1,361 +0,0 @@
|
|||||||
package org.springframework.boot.loader.jar;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FilePermission;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.lang.ref.SoftReference;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLStreamHandlerFactory;
|
|
||||||
import java.security.Permission;
|
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Spliterator;
|
|
||||||
import java.util.Spliterators;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
import java.util.jar.Manifest;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
import java.util.stream.StreamSupport;
|
|
||||||
import java.util.zip.ZipEntry;
|
|
||||||
import org.springframework.boot.loader.data.RandomAccessData;
|
|
||||||
import org.springframework.boot.loader.data.RandomAccessDataFile;
|
|
||||||
|
|
||||||
public class JarFile extends AbstractJarFile implements Iterable {
|
|
||||||
private static final String MANIFEST_NAME = "META-INF/MANIFEST.MF";
|
|
||||||
private static final String PROTOCOL_HANDLER = "java.protocol.handler.pkgs";
|
|
||||||
private static final String HANDLERS_PACKAGE = "org.springframework.boot.loader";
|
|
||||||
private static final AsciiBytes META_INF = new AsciiBytes("META-INF/");
|
|
||||||
private static final AsciiBytes SIGNATURE_FILE_EXTENSION = new AsciiBytes(".SF");
|
|
||||||
private static final String READ_ACTION = "read";
|
|
||||||
private final RandomAccessDataFile rootFile;
|
|
||||||
private final String pathFromRoot;
|
|
||||||
private final RandomAccessData data;
|
|
||||||
private final AbstractJarFile.JarFileType type;
|
|
||||||
private URL url;
|
|
||||||
private String urlString;
|
|
||||||
private JarFileEntries entries;
|
|
||||||
private Supplier manifestSupplier;
|
|
||||||
private SoftReference manifest;
|
|
||||||
private boolean signed;
|
|
||||||
private String comment;
|
|
||||||
private volatile boolean closed;
|
|
||||||
private volatile JarFileWrapper wrapper;
|
|
||||||
|
|
||||||
public JarFile(File file) throws IOException {
|
|
||||||
this(new RandomAccessDataFile(file));
|
|
||||||
}
|
|
||||||
|
|
||||||
JarFile(RandomAccessDataFile file) throws IOException {
|
|
||||||
this(file, "", file, AbstractJarFile.JarFileType.DIRECT);
|
|
||||||
}
|
|
||||||
|
|
||||||
private JarFile(RandomAccessDataFile rootFile, String pathFromRoot, RandomAccessData data, AbstractJarFile.JarFileType type) throws IOException {
|
|
||||||
this(rootFile, pathFromRoot, data, (JarEntryFilter)null, type, (Supplier)null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private JarFile(RandomAccessDataFile rootFile, String pathFromRoot, RandomAccessData data, JarEntryFilter filter, AbstractJarFile.JarFileType type, Supplier manifestSupplier) throws IOException {
|
|
||||||
super(rootFile.getFile());
|
|
||||||
if (System.getSecurityManager() == null) {
|
|
||||||
super.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.rootFile = rootFile;
|
|
||||||
this.pathFromRoot = pathFromRoot;
|
|
||||||
CentralDirectoryParser parser = new CentralDirectoryParser();
|
|
||||||
this.entries = (JarFileEntries)parser.addVisitor(new JarFileEntries(this, filter));
|
|
||||||
this.type = type;
|
|
||||||
parser.addVisitor(this.centralDirectoryVisitor());
|
|
||||||
|
|
||||||
try {
|
|
||||||
this.data = parser.parse(data, filter == null);
|
|
||||||
} catch (RuntimeException ex) {
|
|
||||||
try {
|
|
||||||
this.rootFile.close();
|
|
||||||
super.close();
|
|
||||||
} catch (IOException var10) {
|
|
||||||
}
|
|
||||||
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.manifestSupplier = manifestSupplier != null ? manifestSupplier : () -> {
|
|
||||||
try {
|
|
||||||
InputStream inputStream = this.getInputStream("META-INF/MANIFEST.MF");
|
|
||||||
Throwable var2 = null;
|
|
||||||
|
|
||||||
Manifest var3;
|
|
||||||
try {
|
|
||||||
if (inputStream != null) {
|
|
||||||
var3 = new Manifest(inputStream);
|
|
||||||
return var3;
|
|
||||||
}
|
|
||||||
|
|
||||||
var3 = null;
|
|
||||||
} catch (Throwable var14) {
|
|
||||||
var2 = var14;
|
|
||||||
throw var14;
|
|
||||||
} finally {
|
|
||||||
if (inputStream != null) {
|
|
||||||
if (var2 != null) {
|
|
||||||
try {
|
|
||||||
inputStream.close();
|
|
||||||
} catch (Throwable var13) {
|
|
||||||
var2.addSuppressed(var13);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
inputStream.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return var3;
|
|
||||||
} catch (IOException ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private CentralDirectoryVisitor centralDirectoryVisitor() {
|
|
||||||
return new CentralDirectoryVisitor() {
|
|
||||||
public void visitStart(CentralDirectoryEndRecord endRecord, RandomAccessData centralDirectoryData) {
|
|
||||||
JarFile.this.comment = endRecord.getComment();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void visitFileHeader(CentralDirectoryFileHeader fileHeader, long dataOffset) {
|
|
||||||
AsciiBytes name = fileHeader.getName();
|
|
||||||
if (name.startsWith(JarFile.META_INF) && name.endsWith(JarFile.SIGNATURE_FILE_EXTENSION)) {
|
|
||||||
JarFile.this.signed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void visitEnd() {
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
JarFileWrapper getWrapper() throws IOException {
|
|
||||||
JarFileWrapper wrapper = this.wrapper;
|
|
||||||
if (wrapper == null) {
|
|
||||||
wrapper = new JarFileWrapper(this);
|
|
||||||
this.wrapper = wrapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
return wrapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
Permission getPermission() {
|
|
||||||
return new FilePermission(this.rootFile.getFile().getPath(), "read");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final RandomAccessDataFile getRootJarFile() {
|
|
||||||
return this.rootFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
RandomAccessData getData() {
|
|
||||||
return this.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Manifest getManifest() throws IOException {
|
|
||||||
Manifest manifest = this.manifest != null ? (Manifest)this.manifest.get() : null;
|
|
||||||
if (manifest == null) {
|
|
||||||
try {
|
|
||||||
manifest = (Manifest)this.manifestSupplier.get();
|
|
||||||
} catch (RuntimeException ex) {
|
|
||||||
throw new IOException(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.manifest = new SoftReference(manifest);
|
|
||||||
}
|
|
||||||
|
|
||||||
return manifest;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Enumeration entries() {
|
|
||||||
return new JarEntryEnumeration(this.entries.iterator());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Stream stream() {
|
|
||||||
Spliterator<java.util.jar.JarEntry> spliterator = Spliterators.spliterator(this.iterator(), (long)this.size(), 1297);
|
|
||||||
return StreamSupport.stream(spliterator, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Iterator iterator() {
|
|
||||||
return this.entries.iterator(this::ensureOpen);
|
|
||||||
}
|
|
||||||
|
|
||||||
public JarEntry getJarEntry(CharSequence name) {
|
|
||||||
return this.entries.getEntry(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public JarEntry getJarEntry(String name) {
|
|
||||||
return (JarEntry)this.getEntry(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean containsEntry(String name) {
|
|
||||||
return this.entries.containsEntry(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ZipEntry getEntry(String name) {
|
|
||||||
this.ensureOpen();
|
|
||||||
return this.entries.getEntry(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
InputStream getInputStream() throws IOException {
|
|
||||||
return this.data.getInputStream();
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized InputStream getInputStream(ZipEntry entry) throws IOException {
|
|
||||||
this.ensureOpen();
|
|
||||||
return entry instanceof JarEntry ? this.entries.getInputStream((FileHeader)((JarEntry)entry)) : this.getInputStream(entry != null ? entry.getName() : null);
|
|
||||||
}
|
|
||||||
|
|
||||||
InputStream getInputStream(String name) throws IOException {
|
|
||||||
return this.entries.getInputStream(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized JarFile getNestedJarFile(ZipEntry entry) throws IOException {
|
|
||||||
return this.getNestedJarFile((JarEntry)entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized JarFile getNestedJarFile(JarEntry entry) throws IOException {
|
|
||||||
try {
|
|
||||||
return this.createJarFileFromEntry(entry);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
throw new IOException("Unable to open nested jar file '" + entry.getName() + "'", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private JarFile createJarFileFromEntry(JarEntry entry) throws IOException {
|
|
||||||
return entry.isDirectory() ? this.createJarFileFromDirectoryEntry(entry) : this.createJarFileFromFileEntry(entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
private JarFile createJarFileFromDirectoryEntry(JarEntry entry) throws IOException {
|
|
||||||
AsciiBytes name = entry.getAsciiBytesName();
|
|
||||||
JarEntryFilter filter = (candidate) -> candidate.startsWith(name) && !candidate.equals(name) ? candidate.substring(name.length()) : null;
|
|
||||||
return new JarFile(this.rootFile, this.pathFromRoot + "!/" + entry.getName().substring(0, name.length() - 1), this.data, filter, AbstractJarFile.JarFileType.NESTED_DIRECTORY, this.manifestSupplier);
|
|
||||||
}
|
|
||||||
|
|
||||||
private JarFile createJarFileFromFileEntry(JarEntry entry) throws IOException {
|
|
||||||
if (entry.getMethod() != 0) {
|
|
||||||
throw new IllegalStateException("Unable to open nested entry '" + entry.getName() + "'. It has been compressed and nested jar files must be stored without compression. Please check the mechanism used to create your executable jar file");
|
|
||||||
} else {
|
|
||||||
RandomAccessData entryData = this.entries.getEntryData(entry.getName());
|
|
||||||
return new JarFile(this.rootFile, this.pathFromRoot + "!/" + entry.getName(), entryData, AbstractJarFile.JarFileType.NESTED_JAR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getComment() {
|
|
||||||
this.ensureOpen();
|
|
||||||
return this.comment;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int size() {
|
|
||||||
this.ensureOpen();
|
|
||||||
return this.entries.getSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void close() throws IOException {
|
|
||||||
if (!this.closed) {
|
|
||||||
super.close();
|
|
||||||
if (this.type == AbstractJarFile.JarFileType.DIRECT) {
|
|
||||||
this.rootFile.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.closed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ensureOpen() {
|
|
||||||
if (this.closed) {
|
|
||||||
throw new IllegalStateException("zip file closed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isClosed() {
|
|
||||||
return this.closed;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getUrlString() throws MalformedURLException {
|
|
||||||
if (this.urlString == null) {
|
|
||||||
this.urlString = this.getUrl().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.urlString;
|
|
||||||
}
|
|
||||||
|
|
||||||
public URL getUrl() throws MalformedURLException {
|
|
||||||
if (this.url == null) {
|
|
||||||
String file = this.rootFile.getFile().toURI() + this.pathFromRoot + "!/";
|
|
||||||
file = file.replace("file:////", "file://");
|
|
||||||
this.url = new URL("jar", "", -1, file, new Handler(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return this.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return this.rootFile.getFile() + this.pathFromRoot;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isSigned() {
|
|
||||||
return this.signed;
|
|
||||||
}
|
|
||||||
|
|
||||||
JarEntryCertification getCertification(JarEntry entry) {
|
|
||||||
try {
|
|
||||||
return this.entries.getCertification(entry);
|
|
||||||
} catch (IOException ex) {
|
|
||||||
throw new IllegalStateException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clearCache() {
|
|
||||||
this.entries.clearCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getPathFromRoot() {
|
|
||||||
return this.pathFromRoot;
|
|
||||||
}
|
|
||||||
|
|
||||||
AbstractJarFile.JarFileType getType() {
|
|
||||||
return this.type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void registerUrlProtocolHandler() {
|
|
||||||
Handler.captureJarContextUrl();
|
|
||||||
String handlers = System.getProperty("java.protocol.handler.pkgs", "");
|
|
||||||
System.setProperty("java.protocol.handler.pkgs", handlers != null && !handlers.isEmpty() ? handlers + "|" + "org.springframework.boot.loader" : "org.springframework.boot.loader");
|
|
||||||
resetCachedUrlHandlers();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void resetCachedUrlHandlers() {
|
|
||||||
try {
|
|
||||||
URL.setURLStreamHandlerFactory((URLStreamHandlerFactory)null);
|
|
||||||
} catch (Error var1) {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class JarEntryEnumeration implements Enumeration {
|
|
||||||
private final Iterator iterator;
|
|
||||||
|
|
||||||
JarEntryEnumeration(Iterator iterator) {
|
|
||||||
this.iterator = iterator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasMoreElements() {
|
|
||||||
return this.iterator.hasNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
public java.util.jar.JarEntry nextElement() {
|
|
||||||
return (java.util.jar.JarEntry)this.iterator.next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,435 +0,0 @@
|
|||||||
package org.springframework.boot.loader.jar;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
import java.util.jar.Attributes;
|
|
||||||
import java.util.jar.JarInputStream;
|
|
||||||
import java.util.jar.Manifest;
|
|
||||||
import org.springframework.boot.loader.data.RandomAccessData;
|
|
||||||
|
|
||||||
class JarFileEntries implements CentralDirectoryVisitor, Iterable {
|
|
||||||
private static final Runnable NO_VALIDATION = () -> {
|
|
||||||
};
|
|
||||||
private static final String META_INF_PREFIX = "META-INF/";
|
|
||||||
private static final Attributes.Name MULTI_RELEASE = new Attributes.Name("Multi-Release");
|
|
||||||
private static final int BASE_VERSION = 8;
|
|
||||||
private static final int RUNTIME_VERSION;
|
|
||||||
private static final long LOCAL_FILE_HEADER_SIZE = 30L;
|
|
||||||
private static final char SLASH = '/';
|
|
||||||
private static final char NO_SUFFIX = '\u0000';
|
|
||||||
protected static final int ENTRY_CACHE_SIZE = 25;
|
|
||||||
private final JarFile jarFile;
|
|
||||||
private final JarEntryFilter filter;
|
|
||||||
private RandomAccessData centralDirectoryData;
|
|
||||||
private int size;
|
|
||||||
private int[] hashCodes;
|
|
||||||
private Offsets centralDirectoryOffsets;
|
|
||||||
private int[] positions;
|
|
||||||
private Boolean multiReleaseJar;
|
|
||||||
private JarEntryCertification[] certifications;
|
|
||||||
private final Map entriesCache = Collections.synchronizedMap(new LinkedHashMap(16, 0.75F, true) {
|
|
||||||
protected boolean removeEldestEntry(Map.Entry eldest) {
|
|
||||||
return this.size() >= 25;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
JarFileEntries(JarFile jarFile, JarEntryFilter filter) {
|
|
||||||
this.jarFile = jarFile;
|
|
||||||
this.filter = filter;
|
|
||||||
if (RUNTIME_VERSION == 8) {
|
|
||||||
this.multiReleaseJar = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void visitStart(CentralDirectoryEndRecord endRecord, RandomAccessData centralDirectoryData) {
|
|
||||||
int maxSize = endRecord.getNumberOfRecords();
|
|
||||||
this.centralDirectoryData = centralDirectoryData;
|
|
||||||
this.hashCodes = new int[maxSize];
|
|
||||||
this.centralDirectoryOffsets = JarFileEntries.Offsets.from(endRecord);
|
|
||||||
this.positions = new int[maxSize];
|
|
||||||
}
|
|
||||||
|
|
||||||
public void visitFileHeader(CentralDirectoryFileHeader fileHeader, long dataOffset) {
|
|
||||||
AsciiBytes name = this.applyFilter(fileHeader.getName());
|
|
||||||
if (name != null) {
|
|
||||||
this.add(name, dataOffset);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void add(AsciiBytes name, long dataOffset) {
|
|
||||||
this.hashCodes[this.size] = name.hashCode();
|
|
||||||
this.centralDirectoryOffsets.set(this.size, dataOffset);
|
|
||||||
this.positions[this.size] = this.size++;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void visitEnd() {
|
|
||||||
this.sort(0, this.size - 1);
|
|
||||||
int[] positions = this.positions;
|
|
||||||
this.positions = new int[positions.length];
|
|
||||||
|
|
||||||
for(int i = 0; i < this.size; this.positions[positions[i]] = i++) {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int getSize() {
|
|
||||||
return this.size;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sort(int left, int right) {
|
|
||||||
if (left < right) {
|
|
||||||
int pivot = this.hashCodes[left + (right - left) / 2];
|
|
||||||
int i = left;
|
|
||||||
int j = right;
|
|
||||||
|
|
||||||
while(i <= j) {
|
|
||||||
while(this.hashCodes[i] < pivot) {
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
|
|
||||||
while(this.hashCodes[j] > pivot) {
|
|
||||||
--j;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i <= j) {
|
|
||||||
this.swap(i, j);
|
|
||||||
++i;
|
|
||||||
--j;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (left < j) {
|
|
||||||
this.sort(left, j);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (right > i) {
|
|
||||||
this.sort(i, right);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void swap(int i, int j) {
|
|
||||||
swap(this.hashCodes, i, j);
|
|
||||||
this.centralDirectoryOffsets.swap(i, j);
|
|
||||||
swap(this.positions, i, j);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Iterator iterator() {
|
|
||||||
return new EntryIterator(NO_VALIDATION);
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterator iterator(Runnable validator) {
|
|
||||||
return new EntryIterator(validator);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean containsEntry(CharSequence name) {
|
|
||||||
return this.getEntry(name, FileHeader.class, true) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
JarEntry getEntry(CharSequence name) {
|
|
||||||
return (JarEntry)this.getEntry(name, JarEntry.class, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
InputStream getInputStream(String name) throws IOException {
|
|
||||||
FileHeader entry = this.getEntry(name, FileHeader.class, false);
|
|
||||||
return this.getInputStream(entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
InputStream getInputStream(FileHeader entry) throws IOException {
|
|
||||||
if (entry == null) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
InputStream inputStream = this.getEntryData(entry).getInputStream();
|
|
||||||
if (entry.getMethod() == 8) {
|
|
||||||
inputStream = new ZipInflaterInputStream(inputStream, (int)entry.getSize());
|
|
||||||
}
|
|
||||||
|
|
||||||
return inputStream;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RandomAccessData getEntryData(String name) throws IOException {
|
|
||||||
FileHeader entry = this.getEntry(name, FileHeader.class, false);
|
|
||||||
return entry == null ? null : this.getEntryData(entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
private RandomAccessData getEntryData(FileHeader entry) throws IOException {
|
|
||||||
RandomAccessData data = this.jarFile.getData();
|
|
||||||
byte[] localHeader = data.read(entry.getLocalHeaderOffset(), 30L);
|
|
||||||
long nameLength = Bytes.littleEndianValue(localHeader, 26, 2);
|
|
||||||
long extraLength = Bytes.littleEndianValue(localHeader, 28, 2);
|
|
||||||
return data.getSubsection(entry.getLocalHeaderOffset() + 30L + nameLength + extraLength, entry.getCompressedSize());
|
|
||||||
}
|
|
||||||
|
|
||||||
private FileHeader getEntry(CharSequence name, Class type, boolean cacheEntry) {
|
|
||||||
T entry = (T)this.doGetEntry(name, type, cacheEntry, (AsciiBytes)null);
|
|
||||||
if (!this.isMetaInfEntry(name) && this.isMultiReleaseJar()) {
|
|
||||||
int version = RUNTIME_VERSION;
|
|
||||||
|
|
||||||
for(AsciiBytes nameAlias = entry instanceof JarEntry ? ((JarEntry)entry).getAsciiBytesName() : new AsciiBytes(name.toString()); version > 8; --version) {
|
|
||||||
T versionedEntry = (T)this.doGetEntry("META-INF/versions/" + version + "/" + name, type, cacheEntry, nameAlias);
|
|
||||||
if (versionedEntry != null) {
|
|
||||||
return versionedEntry;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isMetaInfEntry(CharSequence name) {
|
|
||||||
return name.toString().startsWith("META-INF/");
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isMultiReleaseJar() {
|
|
||||||
Boolean multiRelease = this.multiReleaseJar;
|
|
||||||
if (multiRelease != null) {
|
|
||||||
return multiRelease;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
Manifest manifest = this.jarFile.getManifest();
|
|
||||||
if (manifest == null) {
|
|
||||||
multiRelease = false;
|
|
||||||
} else {
|
|
||||||
Attributes attributes = manifest.getMainAttributes();
|
|
||||||
multiRelease = attributes.containsKey(MULTI_RELEASE);
|
|
||||||
}
|
|
||||||
} catch (IOException var4) {
|
|
||||||
multiRelease = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.multiReleaseJar = multiRelease;
|
|
||||||
return multiRelease;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private FileHeader doGetEntry(CharSequence name, Class type, boolean cacheEntry, AsciiBytes nameAlias) {
|
|
||||||
int hashCode = AsciiBytes.hashCode(name);
|
|
||||||
T entry = (T)this.getEntry(hashCode, name, '\u0000', type, cacheEntry, nameAlias);
|
|
||||||
if (entry == null) {
|
|
||||||
hashCode = AsciiBytes.hashCode(hashCode, '/');
|
|
||||||
entry = (T)this.getEntry(hashCode, name, '/', type, cacheEntry, nameAlias);
|
|
||||||
}
|
|
||||||
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
private FileHeader getEntry(int hashCode, CharSequence name, char suffix, Class type, boolean cacheEntry, AsciiBytes nameAlias) {
|
|
||||||
for(int index = this.getFirstIndex(hashCode); index >= 0 && index < this.size && this.hashCodes[index] == hashCode; ++index) {
|
|
||||||
T entry = (T)this.getEntry(index, type, cacheEntry, nameAlias);
|
|
||||||
if (entry.hasName(name, suffix)) {
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private FileHeader getEntry(int index, Class type, boolean cacheEntry, AsciiBytes nameAlias) {
|
|
||||||
try {
|
|
||||||
long offset = this.centralDirectoryOffsets.get(index);
|
|
||||||
FileHeader cached = (FileHeader)this.entriesCache.get(index);
|
|
||||||
FileHeader entry = (FileHeader)(cached != null ? cached : CentralDirectoryFileHeader.fromRandomAccessData(this.centralDirectoryData, offset, this.filter));
|
|
||||||
if (CentralDirectoryFileHeader.class.equals(entry.getClass()) && type.equals(JarEntry.class)) {
|
|
||||||
entry = new JarEntry(this.jarFile, index, (CentralDirectoryFileHeader)entry, nameAlias);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cacheEntry && cached != entry) {
|
|
||||||
this.entriesCache.put(index, entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
return entry;
|
|
||||||
} catch (IOException ex) {
|
|
||||||
throw new IllegalStateException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getFirstIndex(int hashCode) {
|
|
||||||
int index = Arrays.binarySearch(this.hashCodes, 0, this.size, hashCode);
|
|
||||||
if (index < 0) {
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
while(index > 0 && this.hashCodes[index - 1] == hashCode) {
|
|
||||||
--index;
|
|
||||||
}
|
|
||||||
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void clearCache() {
|
|
||||||
this.entriesCache.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
private AsciiBytes applyFilter(AsciiBytes name) {
|
|
||||||
return this.filter != null ? this.filter.apply(name) : name;
|
|
||||||
}
|
|
||||||
|
|
||||||
JarEntryCertification getCertification(JarEntry entry) throws IOException {
|
|
||||||
JarEntryCertification[] certifications = this.certifications;
|
|
||||||
if (certifications == null) {
|
|
||||||
certifications = new JarEntryCertification[this.size];
|
|
||||||
JarInputStream certifiedJarStream = new JarInputStream(this.jarFile.getData().getInputStream());
|
|
||||||
Throwable var4 = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
java.util.jar.JarEntry certifiedEntry = null;
|
|
||||||
|
|
||||||
while((certifiedEntry = certifiedJarStream.getNextJarEntry()) != null) {
|
|
||||||
certifiedJarStream.closeEntry();
|
|
||||||
int index = this.getEntryIndex(certifiedEntry.getName());
|
|
||||||
if (index != -1) {
|
|
||||||
certifications[index] = JarEntryCertification.from(certifiedEntry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Throwable var14) {
|
|
||||||
var4 = var14;
|
|
||||||
throw var14;
|
|
||||||
} finally {
|
|
||||||
if (certifiedJarStream != null) {
|
|
||||||
if (var4 != null) {
|
|
||||||
try {
|
|
||||||
certifiedJarStream.close();
|
|
||||||
} catch (Throwable var13) {
|
|
||||||
var4.addSuppressed(var13);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
certifiedJarStream.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
this.certifications = certifications;
|
|
||||||
}
|
|
||||||
|
|
||||||
JarEntryCertification certification = certifications[entry.getIndex()];
|
|
||||||
return certification != null ? certification : JarEntryCertification.NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getEntryIndex(CharSequence name) {
|
|
||||||
int hashCode = AsciiBytes.hashCode(name);
|
|
||||||
|
|
||||||
for(int index = this.getFirstIndex(hashCode); index >= 0 && index < this.size && this.hashCodes[index] == hashCode; ++index) {
|
|
||||||
FileHeader candidate = this.getEntry(index, FileHeader.class, false, (AsciiBytes)null);
|
|
||||||
if (candidate.hasName(name, '\u0000')) {
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void swap(int[] array, int i, int j) {
|
|
||||||
int temp = array[i];
|
|
||||||
array[i] = array[j];
|
|
||||||
array[j] = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void swap(long[] array, int i, int j) {
|
|
||||||
long temp = array[i];
|
|
||||||
array[i] = array[j];
|
|
||||||
array[j] = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
static {
|
|
||||||
int version;
|
|
||||||
try {
|
|
||||||
Object runtimeVersion = Runtime.class.getMethod("version").invoke((Object)null);
|
|
||||||
version = (Integer)runtimeVersion.getClass().getMethod("major").invoke(runtimeVersion);
|
|
||||||
} catch (Throwable var2) {
|
|
||||||
version = 8;
|
|
||||||
}
|
|
||||||
|
|
||||||
RUNTIME_VERSION = version;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final class EntryIterator implements Iterator {
|
|
||||||
private final Runnable validator;
|
|
||||||
private int index;
|
|
||||||
|
|
||||||
private EntryIterator(Runnable validator) {
|
|
||||||
this.index = 0;
|
|
||||||
this.validator = validator;
|
|
||||||
validator.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasNext() {
|
|
||||||
this.validator.run();
|
|
||||||
return this.index < JarFileEntries.this.size;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JarEntry next() {
|
|
||||||
this.validator.run();
|
|
||||||
if (!this.hasNext()) {
|
|
||||||
throw new NoSuchElementException();
|
|
||||||
} else {
|
|
||||||
int entryIndex = JarFileEntries.this.positions[this.index];
|
|
||||||
++this.index;
|
|
||||||
return (JarEntry)JarFileEntries.this.getEntry(entryIndex, JarEntry.class, false, (AsciiBytes)null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private interface Offsets {
|
|
||||||
void set(int index, long value);
|
|
||||||
|
|
||||||
long get(int index);
|
|
||||||
|
|
||||||
void swap(int i, int j);
|
|
||||||
|
|
||||||
static Offsets from(CentralDirectoryEndRecord endRecord) {
|
|
||||||
int size = endRecord.getNumberOfRecords();
|
|
||||||
return (Offsets)(endRecord.isZip64() ? new Zip64Offsets(size) : new ZipOffsets(size));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class ZipOffsets implements Offsets {
|
|
||||||
private final int[] offsets;
|
|
||||||
|
|
||||||
private ZipOffsets(int size) {
|
|
||||||
this.offsets = new int[size];
|
|
||||||
}
|
|
||||||
|
|
||||||
public void swap(int i, int j) {
|
|
||||||
JarFileEntries.swap(this.offsets, i, j);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void set(int index, long value) {
|
|
||||||
this.offsets[index] = (int)value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long get(int index) {
|
|
||||||
return (long)this.offsets[index];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class Zip64Offsets implements Offsets {
|
|
||||||
private final long[] offsets;
|
|
||||||
|
|
||||||
private Zip64Offsets(int size) {
|
|
||||||
this.offsets = new long[size];
|
|
||||||
}
|
|
||||||
|
|
||||||
public void swap(int i, int j) {
|
|
||||||
JarFileEntries.swap(this.offsets, i, j);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void set(int index, long value) {
|
|
||||||
this.offsets[index] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long get(int index) {
|
|
||||||
return this.offsets[index];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
package org.springframework.boot.loader.jar;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.security.Permission;
|
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.jar.Manifest;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
import java.util.zip.ZipEntry;
|
|
||||||
|
|
||||||
class JarFileWrapper extends AbstractJarFile {
|
|
||||||
private final JarFile parent;
|
|
||||||
|
|
||||||
JarFileWrapper(JarFile parent) throws IOException {
|
|
||||||
super(parent.getRootJarFile().getFile());
|
|
||||||
this.parent = parent;
|
|
||||||
if (System.getSecurityManager() == null) {
|
|
||||||
super.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
URL getUrl() throws MalformedURLException {
|
|
||||||
return this.parent.getUrl();
|
|
||||||
}
|
|
||||||
|
|
||||||
AbstractJarFile.JarFileType getType() {
|
|
||||||
return this.parent.getType();
|
|
||||||
}
|
|
||||||
|
|
||||||
Permission getPermission() {
|
|
||||||
return this.parent.getPermission();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Manifest getManifest() throws IOException {
|
|
||||||
return this.parent.getManifest();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Enumeration entries() {
|
|
||||||
return this.parent.entries();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Stream stream() {
|
|
||||||
return this.parent.stream();
|
|
||||||
}
|
|
||||||
|
|
||||||
public java.util.jar.JarEntry getJarEntry(String name) {
|
|
||||||
return this.parent.getJarEntry(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ZipEntry getEntry(String name) {
|
|
||||||
return this.parent.getEntry(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
InputStream getInputStream() throws IOException {
|
|
||||||
return this.parent.getInputStream();
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized InputStream getInputStream(ZipEntry ze) throws IOException {
|
|
||||||
return this.parent.getInputStream(ze);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getComment() {
|
|
||||||
return this.parent.getComment();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int size() {
|
|
||||||
return this.parent.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return this.parent.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return this.parent.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
static JarFile unwrap(java.util.jar.JarFile jarFile) {
|
|
||||||
if (jarFile instanceof JarFile) {
|
|
||||||
return (JarFile)jarFile;
|
|
||||||
} else if (jarFile instanceof JarFileWrapper) {
|
|
||||||
return unwrap(((JarFileWrapper)jarFile).parent);
|
|
||||||
} else {
|
|
||||||
throw new IllegalStateException("Not a JarFile or Wrapper");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,334 +0,0 @@
|
|||||||
package org.springframework.boot.loader.jar;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.net.URLStreamHandler;
|
|
||||||
import java.security.Permission;
|
|
||||||
|
|
||||||
final class JarURLConnection extends java.net.JarURLConnection {
|
|
||||||
private static ThreadLocal useFastExceptions = new ThreadLocal();
|
|
||||||
private static final FileNotFoundException FILE_NOT_FOUND_EXCEPTION = new FileNotFoundException("Jar file or entry not found");
|
|
||||||
private static final IllegalStateException NOT_FOUND_CONNECTION_EXCEPTION;
|
|
||||||
private static final String SEPARATOR = "!/";
|
|
||||||
private static final URL EMPTY_JAR_URL;
|
|
||||||
private static final JarEntryName EMPTY_JAR_ENTRY_NAME;
|
|
||||||
private static final JarURLConnection NOT_FOUND_CONNECTION;
|
|
||||||
private final AbstractJarFile jarFile;
|
|
||||||
private Permission permission;
|
|
||||||
private URL jarFileUrl;
|
|
||||||
private final JarEntryName jarEntryName;
|
|
||||||
private java.util.jar.JarEntry jarEntry;
|
|
||||||
|
|
||||||
private JarURLConnection(URL url, AbstractJarFile jarFile, JarEntryName jarEntryName) throws IOException {
|
|
||||||
super(EMPTY_JAR_URL);
|
|
||||||
this.url = url;
|
|
||||||
this.jarFile = jarFile;
|
|
||||||
this.jarEntryName = jarEntryName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void connect() throws IOException {
|
|
||||||
if (this.jarFile == null) {
|
|
||||||
throw FILE_NOT_FOUND_EXCEPTION;
|
|
||||||
} else {
|
|
||||||
if (!this.jarEntryName.isEmpty() && this.jarEntry == null) {
|
|
||||||
this.jarEntry = this.jarFile.getJarEntry(this.getEntryName());
|
|
||||||
if (this.jarEntry == null) {
|
|
||||||
this.throwFileNotFound(this.jarEntryName, this.jarFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.connected = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public java.util.jar.JarFile getJarFile() throws IOException {
|
|
||||||
this.connect();
|
|
||||||
return this.jarFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public URL getJarFileURL() {
|
|
||||||
if (this.jarFile == null) {
|
|
||||||
throw NOT_FOUND_CONNECTION_EXCEPTION;
|
|
||||||
} else {
|
|
||||||
if (this.jarFileUrl == null) {
|
|
||||||
this.jarFileUrl = this.buildJarFileUrl();
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.jarFileUrl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private URL buildJarFileUrl() {
|
|
||||||
try {
|
|
||||||
String spec = this.jarFile.getUrl().getFile();
|
|
||||||
if (spec.endsWith("!/")) {
|
|
||||||
spec = spec.substring(0, spec.length() - "!/".length());
|
|
||||||
}
|
|
||||||
|
|
||||||
return !spec.contains("!/") ? new URL(spec) : new URL("jar:" + spec);
|
|
||||||
} catch (MalformedURLException ex) {
|
|
||||||
throw new IllegalStateException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public java.util.jar.JarEntry getJarEntry() throws IOException {
|
|
||||||
if (this.jarEntryName != null && !this.jarEntryName.isEmpty()) {
|
|
||||||
this.connect();
|
|
||||||
return this.jarEntry;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEntryName() {
|
|
||||||
if (this.jarFile == null) {
|
|
||||||
throw NOT_FOUND_CONNECTION_EXCEPTION;
|
|
||||||
} else {
|
|
||||||
return this.jarEntryName.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public InputStream getInputStream() throws IOException {
|
|
||||||
if (this.jarFile == null) {
|
|
||||||
throw FILE_NOT_FOUND_EXCEPTION;
|
|
||||||
} else if (this.jarEntryName.isEmpty() && this.jarFile.getType() == AbstractJarFile.JarFileType.DIRECT) {
|
|
||||||
throw new IOException("no entry name specified");
|
|
||||||
} else {
|
|
||||||
this.connect();
|
|
||||||
InputStream inputStream = this.jarEntryName.isEmpty() ? this.jarFile.getInputStream() : this.jarFile.getInputStream(this.jarEntry);
|
|
||||||
if (inputStream == null) {
|
|
||||||
this.throwFileNotFound(this.jarEntryName, this.jarFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
return inputStream;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void throwFileNotFound(Object entry, AbstractJarFile jarFile) throws FileNotFoundException {
|
|
||||||
if (Boolean.TRUE.equals(useFastExceptions.get())) {
|
|
||||||
throw FILE_NOT_FOUND_EXCEPTION;
|
|
||||||
} else {
|
|
||||||
throw new FileNotFoundException("JAR entry " + entry + " not found in " + jarFile.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getContentLength() {
|
|
||||||
long length = this.getContentLengthLong();
|
|
||||||
return length > 2147483647L ? -1 : (int)length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getContentLengthLong() {
|
|
||||||
if (this.jarFile == null) {
|
|
||||||
return -1L;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
if (this.jarEntryName.isEmpty()) {
|
|
||||||
return (long)this.jarFile.size();
|
|
||||||
} else {
|
|
||||||
java.util.jar.JarEntry entry = this.getJarEntry();
|
|
||||||
return entry != null ? (long)((int)entry.getSize()) : -1L;
|
|
||||||
}
|
|
||||||
} catch (IOException var2) {
|
|
||||||
return -1L;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getContent() throws IOException {
|
|
||||||
this.connect();
|
|
||||||
return this.jarEntryName.isEmpty() ? this.jarFile : super.getContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getContentType() {
|
|
||||||
return this.jarEntryName != null ? this.jarEntryName.getContentType() : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Permission getPermission() throws IOException {
|
|
||||||
if (this.jarFile == null) {
|
|
||||||
throw FILE_NOT_FOUND_EXCEPTION;
|
|
||||||
} else {
|
|
||||||
if (this.permission == null) {
|
|
||||||
this.permission = this.jarFile.getPermission();
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.permission;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getLastModified() {
|
|
||||||
if (this.jarFile != null && !this.jarEntryName.isEmpty()) {
|
|
||||||
try {
|
|
||||||
java.util.jar.JarEntry entry = this.getJarEntry();
|
|
||||||
return entry != null ? entry.getTime() : 0L;
|
|
||||||
} catch (IOException var2) {
|
|
||||||
return 0L;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return 0L;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void setUseFastExceptions(boolean useFastExceptions) {
|
|
||||||
JarURLConnection.useFastExceptions.set(useFastExceptions);
|
|
||||||
}
|
|
||||||
|
|
||||||
static JarURLConnection get(URL url, JarFile jarFile) throws IOException {
|
|
||||||
StringSequence spec = new StringSequence(url.getFile());
|
|
||||||
int index = indexOfRootSpec(spec, jarFile.getPathFromRoot());
|
|
||||||
if (index == -1) {
|
|
||||||
return Boolean.TRUE.equals(useFastExceptions.get()) ? NOT_FOUND_CONNECTION : new JarURLConnection(url, (AbstractJarFile)null, EMPTY_JAR_ENTRY_NAME);
|
|
||||||
} else {
|
|
||||||
int separator;
|
|
||||||
while((separator = spec.indexOf("!/", index)) > 0) {
|
|
||||||
JarEntryName entryName = JarURLConnection.JarEntryName.get(spec.subSequence(index, separator));
|
|
||||||
JarEntry jarEntry = jarFile.getJarEntry(entryName.toCharSequence());
|
|
||||||
if (jarEntry == null) {
|
|
||||||
return notFound(jarFile, entryName);
|
|
||||||
}
|
|
||||||
|
|
||||||
jarFile = jarFile.getNestedJarFile(jarEntry);
|
|
||||||
index = separator + "!/".length();
|
|
||||||
}
|
|
||||||
|
|
||||||
JarEntryName jarEntryName = JarURLConnection.JarEntryName.get(spec, index);
|
|
||||||
if (Boolean.TRUE.equals(useFastExceptions.get()) && !jarEntryName.isEmpty() && !jarFile.containsEntry(jarEntryName.toString())) {
|
|
||||||
return NOT_FOUND_CONNECTION;
|
|
||||||
} else {
|
|
||||||
return new JarURLConnection(url, jarFile.getWrapper(), jarEntryName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int indexOfRootSpec(StringSequence file, String pathFromRoot) {
|
|
||||||
int separatorIndex = file.indexOf("!/");
|
|
||||||
return separatorIndex >= 0 && file.startsWith(pathFromRoot, separatorIndex) ? separatorIndex + "!/".length() + pathFromRoot.length() : -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static JarURLConnection notFound() {
|
|
||||||
try {
|
|
||||||
return notFound((JarFile)null, (JarEntryName)null);
|
|
||||||
} catch (IOException ex) {
|
|
||||||
throw new IllegalStateException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static JarURLConnection notFound(JarFile jarFile, JarEntryName jarEntryName) throws IOException {
|
|
||||||
return Boolean.TRUE.equals(useFastExceptions.get()) ? NOT_FOUND_CONNECTION : new JarURLConnection((URL)null, jarFile, jarEntryName);
|
|
||||||
}
|
|
||||||
|
|
||||||
static {
|
|
||||||
NOT_FOUND_CONNECTION_EXCEPTION = new IllegalStateException(FILE_NOT_FOUND_EXCEPTION);
|
|
||||||
|
|
||||||
try {
|
|
||||||
EMPTY_JAR_URL = new URL("jar:", (String)null, 0, "file:!/", new URLStreamHandler() {
|
|
||||||
protected URLConnection openConnection(URL u) throws IOException {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (MalformedURLException ex) {
|
|
||||||
throw new IllegalStateException(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
EMPTY_JAR_ENTRY_NAME = new JarEntryName(new StringSequence(""));
|
|
||||||
NOT_FOUND_CONNECTION = notFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
static class JarEntryName {
|
|
||||||
private final StringSequence name;
|
|
||||||
private String contentType;
|
|
||||||
|
|
||||||
JarEntryName(StringSequence spec) {
|
|
||||||
this.name = this.decode(spec);
|
|
||||||
}
|
|
||||||
|
|
||||||
private StringSequence decode(StringSequence source) {
|
|
||||||
if (!source.isEmpty() && source.indexOf('%') >= 0) {
|
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(source.length());
|
|
||||||
this.write(source.toString(), bos);
|
|
||||||
return new StringSequence(AsciiBytes.toString(bos.toByteArray()));
|
|
||||||
} else {
|
|
||||||
return source;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void write(String source, ByteArrayOutputStream outputStream) {
|
|
||||||
int length = source.length();
|
|
||||||
|
|
||||||
for(int i = 0; i < length; ++i) {
|
|
||||||
int c = source.charAt(i);
|
|
||||||
if (c > 127) {
|
|
||||||
try {
|
|
||||||
String encoded = URLEncoder.encode(String.valueOf((char)c), "UTF-8");
|
|
||||||
this.write(encoded, outputStream);
|
|
||||||
} catch (UnsupportedEncodingException ex) {
|
|
||||||
throw new IllegalStateException(ex);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (c == 37) {
|
|
||||||
if (i + 2 >= length) {
|
|
||||||
throw new IllegalArgumentException("Invalid encoded sequence \"" + source.substring(i) + "\"");
|
|
||||||
}
|
|
||||||
|
|
||||||
c = this.decodeEscapeSequence(source, i);
|
|
||||||
i += 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
outputStream.write(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private char decodeEscapeSequence(String source, int i) {
|
|
||||||
int hi = Character.digit(source.charAt(i + 1), 16);
|
|
||||||
int lo = Character.digit(source.charAt(i + 2), 16);
|
|
||||||
if (hi != -1 && lo != -1) {
|
|
||||||
return (char)((hi << 4) + lo);
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("Invalid encoded sequence \"" + source.substring(i) + "\"");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CharSequence toCharSequence() {
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return this.name.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isEmpty() {
|
|
||||||
return this.name.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
String getContentType() {
|
|
||||||
if (this.contentType == null) {
|
|
||||||
this.contentType = this.deduceContentType();
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.contentType;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String deduceContentType() {
|
|
||||||
String type = this.isEmpty() ? "x-java/jar" : null;
|
|
||||||
type = type != null ? type : URLConnection.guessContentTypeFromName(this.toString());
|
|
||||||
type = type != null ? type : "content/unknown";
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
static JarEntryName get(StringSequence spec) {
|
|
||||||
return get(spec, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static JarEntryName get(StringSequence spec, int beginIndex) {
|
|
||||||
return spec.length() <= beginIndex ? JarURLConnection.EMPTY_JAR_ENTRY_NAME : new JarEntryName(spec.subSequence(beginIndex));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,116 +0,0 @@
|
|||||||
package org.springframework.boot.loader.jar;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
final class StringSequence implements CharSequence {
|
|
||||||
private final String source;
|
|
||||||
private final int start;
|
|
||||||
private final int end;
|
|
||||||
private int hash;
|
|
||||||
|
|
||||||
StringSequence(String source) {
|
|
||||||
this(source, 0, source != null ? source.length() : -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
StringSequence(String source, int start, int end) {
|
|
||||||
Objects.requireNonNull(source, "Source must not be null");
|
|
||||||
if (start < 0) {
|
|
||||||
throw new StringIndexOutOfBoundsException(start);
|
|
||||||
} else if (end > source.length()) {
|
|
||||||
throw new StringIndexOutOfBoundsException(end);
|
|
||||||
} else {
|
|
||||||
this.source = source;
|
|
||||||
this.start = start;
|
|
||||||
this.end = end;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
StringSequence subSequence(int start) {
|
|
||||||
return this.subSequence(start, this.length());
|
|
||||||
}
|
|
||||||
|
|
||||||
public StringSequence subSequence(int start, int end) {
|
|
||||||
int subSequenceStart = this.start + start;
|
|
||||||
int subSequenceEnd = this.start + end;
|
|
||||||
if (subSequenceStart > this.end) {
|
|
||||||
throw new StringIndexOutOfBoundsException(start);
|
|
||||||
} else if (subSequenceEnd > this.end) {
|
|
||||||
throw new StringIndexOutOfBoundsException(end);
|
|
||||||
} else {
|
|
||||||
return start == 0 && subSequenceEnd == this.end ? this : new StringSequence(this.source, subSequenceStart, subSequenceEnd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return this.length() == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int length() {
|
|
||||||
return this.end - this.start;
|
|
||||||
}
|
|
||||||
|
|
||||||
public char charAt(int index) {
|
|
||||||
return this.source.charAt(this.start + index);
|
|
||||||
}
|
|
||||||
|
|
||||||
int indexOf(char ch) {
|
|
||||||
return this.source.indexOf(ch, this.start) - this.start;
|
|
||||||
}
|
|
||||||
|
|
||||||
int indexOf(String str) {
|
|
||||||
return this.source.indexOf(str, this.start) - this.start;
|
|
||||||
}
|
|
||||||
|
|
||||||
int indexOf(String str, int fromIndex) {
|
|
||||||
return this.source.indexOf(str, this.start + fromIndex) - this.start;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean startsWith(String prefix) {
|
|
||||||
return this.startsWith(prefix, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean startsWith(String prefix, int offset) {
|
|
||||||
int prefixLength = prefix.length();
|
|
||||||
int length = this.length();
|
|
||||||
return length - prefixLength - offset < 0 ? false : this.source.startsWith(prefix, this.start + offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj) {
|
|
||||||
return true;
|
|
||||||
} else if (!(obj instanceof CharSequence)) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
CharSequence other = (CharSequence)obj;
|
|
||||||
int n = this.length();
|
|
||||||
if (n != other.length()) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
for(int i = 0; n-- != 0; ++i) {
|
|
||||||
if (this.charAt(i) != other.charAt(i)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode() {
|
|
||||||
int hash = this.hash;
|
|
||||||
if (hash == 0 && this.length() > 0) {
|
|
||||||
for(int i = this.start; i < this.end; ++i) {
|
|
||||||
hash = 31 * hash + this.source.charAt(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.hash = hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return this.source.substring(this.start, this.end);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
package org.springframework.boot.loader.jar;
|
|
||||||
|
|
||||||
import java.io.EOFException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.zip.Inflater;
|
|
||||||
import java.util.zip.InflaterInputStream;
|
|
||||||
|
|
||||||
class ZipInflaterInputStream extends InflaterInputStream {
|
|
||||||
private int available;
|
|
||||||
private boolean extraBytesWritten;
|
|
||||||
|
|
||||||
ZipInflaterInputStream(InputStream inputStream, int size) {
|
|
||||||
super(inputStream, new Inflater(true), getInflaterBufferSize((long)size));
|
|
||||||
this.available = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int available() throws IOException {
|
|
||||||
return this.available < 0 ? super.available() : this.available;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int read(byte[] b, int off, int len) throws IOException {
|
|
||||||
int result = super.read(b, off, len);
|
|
||||||
if (result != -1) {
|
|
||||||
this.available -= result;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void close() throws IOException {
|
|
||||||
super.close();
|
|
||||||
this.inf.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void fill() throws IOException {
|
|
||||||
try {
|
|
||||||
super.fill();
|
|
||||||
} catch (EOFException ex) {
|
|
||||||
if (this.extraBytesWritten) {
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.len = 1;
|
|
||||||
this.buf[0] = 0;
|
|
||||||
this.extraBytesWritten = true;
|
|
||||||
this.inf.setInput(this.buf, 0, this.len);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int getInflaterBufferSize(long size) {
|
|
||||||
size += 2L;
|
|
||||||
size = size > 65536L ? 8192L : size;
|
|
||||||
size = size <= 0L ? 4096L : size;
|
|
||||||
return (int)size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package org.springframework.boot.loader.jarmode;
|
|
||||||
|
|
||||||
public interface JarMode {
|
|
||||||
boolean accepts(String mode);
|
|
||||||
|
|
||||||
void run(String mode, String[] args);
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package org.springframework.boot.loader.jarmode;
|
|
||||||
|
|
||||||
import org.springframework.core.io.support.SpringFactoriesLoader;
|
|
||||||
import org.springframework.util.ClassUtils;
|
|
||||||
|
|
||||||
public final class JarModeLauncher {
|
|
||||||
static final String DISABLE_SYSTEM_EXIT = JarModeLauncher.class.getName() + ".DISABLE_SYSTEM_EXIT";
|
|
||||||
|
|
||||||
private JarModeLauncher() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
String mode = System.getProperty("jarmode");
|
|
||||||
|
|
||||||
for(JarMode candidate : SpringFactoriesLoader.loadFactories(JarMode.class, ClassUtils.getDefaultClassLoader())) {
|
|
||||||
if (candidate.accepts(mode)) {
|
|
||||||
candidate.run(mode, args);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
System.err.println("Unsupported jarmode '" + mode + "'");
|
|
||||||
if (!Boolean.getBoolean(DISABLE_SYSTEM_EXIT)) {
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package org.springframework.boot.loader.jarmode;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
class TestJarMode implements JarMode {
|
|
||||||
public boolean accepts(String mode) {
|
|
||||||
return "test".equals(mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run(String mode, String[] args) {
|
|
||||||
System.out.println("running in " + mode + " jar mode " + Arrays.asList(args));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,143 +0,0 @@
|
|||||||
package org.springframework.boot.loader.util;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public abstract class SystemPropertyUtils {
|
|
||||||
public static final String PLACEHOLDER_PREFIX = "${";
|
|
||||||
public static final String PLACEHOLDER_SUFFIX = "}";
|
|
||||||
public static final String VALUE_SEPARATOR = ":";
|
|
||||||
private static final String SIMPLE_PREFIX = "${".substring(1);
|
|
||||||
|
|
||||||
public static String resolvePlaceholders(String text) {
|
|
||||||
return text == null ? text : parseStringValue((Properties)null, text, text, new HashSet());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String resolvePlaceholders(Properties properties, String text) {
|
|
||||||
return text == null ? text : parseStringValue(properties, text, text, new HashSet());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String parseStringValue(Properties properties, String value, String current, Set visitedPlaceholders) {
|
|
||||||
StringBuilder buf = new StringBuilder(current);
|
|
||||||
int startIndex = current.indexOf("${");
|
|
||||||
|
|
||||||
while(startIndex != -1) {
|
|
||||||
int endIndex = findPlaceholderEndIndex(buf, startIndex);
|
|
||||||
if (endIndex != -1) {
|
|
||||||
String placeholder = buf.substring(startIndex + "${".length(), endIndex);
|
|
||||||
String originalPlaceholder = placeholder;
|
|
||||||
if (!visitedPlaceholders.add(placeholder)) {
|
|
||||||
throw new IllegalArgumentException("Circular placeholder reference '" + placeholder + "' in property definitions");
|
|
||||||
}
|
|
||||||
|
|
||||||
placeholder = parseStringValue(properties, value, placeholder, visitedPlaceholders);
|
|
||||||
String propVal = resolvePlaceholder(properties, value, placeholder);
|
|
||||||
if (propVal == null) {
|
|
||||||
int separatorIndex = placeholder.indexOf(":");
|
|
||||||
if (separatorIndex != -1) {
|
|
||||||
String actualPlaceholder = placeholder.substring(0, separatorIndex);
|
|
||||||
String defaultValue = placeholder.substring(separatorIndex + ":".length());
|
|
||||||
propVal = resolvePlaceholder(properties, value, actualPlaceholder);
|
|
||||||
if (propVal == null) {
|
|
||||||
propVal = defaultValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (propVal != null) {
|
|
||||||
propVal = parseStringValue(properties, value, propVal, visitedPlaceholders);
|
|
||||||
buf.replace(startIndex, endIndex + "}".length(), propVal);
|
|
||||||
startIndex = buf.indexOf("${", startIndex + propVal.length());
|
|
||||||
} else {
|
|
||||||
startIndex = buf.indexOf("${", endIndex + "}".length());
|
|
||||||
}
|
|
||||||
|
|
||||||
visitedPlaceholders.remove(originalPlaceholder);
|
|
||||||
} else {
|
|
||||||
startIndex = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return buf.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String resolvePlaceholder(Properties properties, String text, String placeholderName) {
|
|
||||||
String propVal = getProperty(placeholderName, (String)null, text);
|
|
||||||
if (propVal != null) {
|
|
||||||
return propVal;
|
|
||||||
} else {
|
|
||||||
return properties != null ? properties.getProperty(placeholderName) : null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getProperty(String key) {
|
|
||||||
return getProperty(key, (String)null, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getProperty(String key, String defaultValue) {
|
|
||||||
return getProperty(key, defaultValue, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getProperty(String key, String defaultValue, String text) {
|
|
||||||
try {
|
|
||||||
String propVal = System.getProperty(key);
|
|
||||||
if (propVal == null) {
|
|
||||||
propVal = System.getenv(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (propVal == null) {
|
|
||||||
String name = key.replace('.', '_');
|
|
||||||
propVal = System.getenv(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (propVal == null) {
|
|
||||||
String name = key.toUpperCase(Locale.ENGLISH).replace('.', '_');
|
|
||||||
propVal = System.getenv(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (propVal != null) {
|
|
||||||
return propVal;
|
|
||||||
}
|
|
||||||
} catch (Throwable ex) {
|
|
||||||
System.err.println("Could not resolve key '" + key + "' in '" + text + "' as system property or in environment: " + ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int findPlaceholderEndIndex(CharSequence buf, int startIndex) {
|
|
||||||
int index = startIndex + "${".length();
|
|
||||||
int withinNestedPlaceholder = 0;
|
|
||||||
|
|
||||||
while(index < buf.length()) {
|
|
||||||
if (substringMatch(buf, index, "}")) {
|
|
||||||
if (withinNestedPlaceholder <= 0) {
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
|
|
||||||
--withinNestedPlaceholder;
|
|
||||||
index += "}".length();
|
|
||||||
} else if (substringMatch(buf, index, SIMPLE_PREFIX)) {
|
|
||||||
++withinNestedPlaceholder;
|
|
||||||
index += SIMPLE_PREFIX.length();
|
|
||||||
} else {
|
|
||||||
++index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean substringMatch(CharSequence str, int index, CharSequence substring) {
|
|
||||||
for(int j = 0; j < substring.length(); ++j) {
|
|
||||||
int i = index + j;
|
|
||||||
if (i >= str.length() || str.charAt(i) != substring.charAt(j)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user