Merge branch '2.0.x' into 2.1.x

Closes gh-17078
This commit is contained in:
Andy Wilkinson
2019-06-07 10:50:34 +01:00
2691 changed files with 27746 additions and 46049 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -58,12 +58,11 @@ public final class BuildPropertiesWriter {
}
File parent = file.getParentFile();
if (!parent.isDirectory() && !parent.mkdirs()) {
throw new IllegalStateException("Cannot create parent directory for '"
+ this.outputFile.getAbsolutePath() + "'");
throw new IllegalStateException(
"Cannot create parent directory for '" + this.outputFile.getAbsolutePath() + "'");
}
if (!file.createNewFile()) {
throw new IllegalStateException("Cannot create target file '"
+ this.outputFile.getAbsolutePath() + "'");
throw new IllegalStateException("Cannot create target file '" + this.outputFile.getAbsolutePath() + "'");
}
}
@@ -74,12 +73,10 @@ public final class BuildPropertiesWriter {
properties.put("build.name", project.getName());
properties.put("build.version", project.getVersion());
if (project.getTime() != null) {
properties.put("build.time",
DateTimeFormatter.ISO_INSTANT.format(project.getTime()));
properties.put("build.time", DateTimeFormatter.ISO_INSTANT.format(project.getTime()));
}
if (project.getAdditionalProperties() != null) {
project.getAdditionalProperties()
.forEach((name, value) -> properties.put("build." + name, value));
project.getAdditionalProperties().forEach((name, value) -> properties.put("build." + name, value));
}
return properties;
}
@@ -101,8 +98,8 @@ public final class BuildPropertiesWriter {
private final Map<String, String> additionalProperties;
public ProjectDetails(String group, String artifact, String version, String name,
Instant time, Map<String, String> additionalProperties) {
public ProjectDetails(String group, String artifact, String version, String name, Instant time,
Map<String, String> additionalProperties) {
this.group = group;
this.artifact = artifact;
this.name = name;
@@ -112,8 +109,7 @@ public final class BuildPropertiesWriter {
this.additionalProperties = additionalProperties;
}
private static void validateAdditionalProperties(
Map<String, String> additionalProperties) {
private static void validateAdditionalProperties(Map<String, String> additionalProperties) {
if (additionalProperties != null) {
additionalProperties.forEach((name, value) -> {
if (value == null) {
@@ -152,8 +148,7 @@ public final class BuildPropertiesWriter {
/**
* Exception thrown when an additional property with a null value is encountered.
*/
public static class NullAdditionalPropertyValueException
extends IllegalArgumentException {
public static class NullAdditionalPropertyValueException extends IllegalArgumentException {
public NullAdditionalPropertyValueException(String name) {
super("Additional property '" + name + "' is illegal as its value is null");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,8 +42,7 @@ public class DefaultLaunchScript implements LaunchScript {
private static final int BUFFER_SIZE = 4096;
private static final Pattern PLACEHOLDER_PATTERN = Pattern
.compile("\\{\\{(\\w+)(:.*?)?\\}\\}(?!\\})");
private static final Pattern PLACEHOLDER_PATTERN = Pattern.compile("\\{\\{(\\w+)(:.*?)?\\}\\}(?!\\})");
private static final Set<String> FILE_PATH_KEYS = Collections
.unmodifiableSet(Collections.singleton("inlinedConfScript"));
@@ -79,8 +78,7 @@ public class DefaultLaunchScript implements LaunchScript {
}
}
private void copy(InputStream inputStream, OutputStream outputStream)
throws IOException {
private void copy(InputStream inputStream, OutputStream outputStream) throws IOException {
byte[] buffer = new byte[BUFFER_SIZE];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
@@ -89,8 +87,7 @@ public class DefaultLaunchScript implements LaunchScript {
outputStream.flush();
}
private String expandPlaceholders(String content, Map<?, ?> properties)
throws IOException {
private String expandPlaceholders(String content, Map<?, ?> properties) throws IOException {
StringBuffer expanded = new StringBuffer();
Matcher matcher = PLACEHOLDER_PATTERN.matcher(content);
while (matcher.find()) {
@@ -107,8 +104,7 @@ public class DefaultLaunchScript implements LaunchScript {
}
}
else {
value = (defaultValue != null) ? defaultValue.substring(1)
: matcher.group(0);
value = (defaultValue != null) ? defaultValue.substring(1) : matcher.group(0);
}
matcher.appendReplacement(expanded, value.replace("$", "\\$"));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,8 +38,7 @@ public abstract class FileUtils {
* @param outputDirectory the output directory
* @param originDirectory the origin directory
*/
public static void removeDuplicatesFromOutputDirectory(File outputDirectory,
File originDirectory) {
public static void removeDuplicatesFromOutputDirectory(File outputDirectory, File originDirectory) {
if (originDirectory.isDirectory()) {
for (String name : originDirectory.list()) {
File targetFile = new File(outputDirectory, name);
@@ -48,8 +47,7 @@ public abstract class FileUtils {
targetFile.delete();
}
else {
FileUtils.removeDuplicatesFromOutputDirectory(targetFile,
new File(originDirectory, name));
FileUtils.removeDuplicatesFromOutputDirectory(targetFile, new File(originDirectory, name));
}
}
}
@@ -64,8 +62,8 @@ public abstract class FileUtils {
*/
public static String sha1Hash(File file) throws IOException {
try {
try (DigestInputStream inputStream = new DigestInputStream(
new FileInputStream(file), MessageDigest.getInstance("SHA-1"))) {
try (DigestInputStream inputStream = new DigestInputStream(new FileInputStream(file),
MessageDigest.getInstance("SHA-1"))) {
byte[] buffer = new byte[4098];
while (inputStream.read(buffer) != -1) {
// Read the entire stream

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -82,8 +82,7 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
* @throws IOException if the file cannot be opened
* @throws FileNotFoundException if the file cannot be found
*/
public JarWriter(File file, LaunchScript launchScript)
throws FileNotFoundException, IOException {
public JarWriter(File file, LaunchScript launchScript) throws FileNotFoundException, IOException {
FileOutputStream fileOutputStream = new FileOutputStream(file);
if (launchScript != null) {
fileOutputStream.write(launchScript.toByteArray());
@@ -96,8 +95,7 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
private void setExecutableFilePermission(File file) {
try {
Path path = file.toPath();
Set<PosixFilePermission> permissions = new HashSet<>(
Files.getPosixFilePermissions(path));
Set<PosixFilePermission> permissions = new HashSet<>(Files.getPosixFilePermissions(path));
permissions.add(PosixFilePermission.OWNER_EXECUTE);
Files.setPosixFilePermissions(path, permissions);
}
@@ -129,14 +127,13 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
this.writeEntries(jarFile, new IdentityEntryTransformer(), unpackHandler);
}
void writeEntries(JarFile jarFile, EntryTransformer entryTransformer,
UnpackHandler unpackHandler) throws IOException {
void writeEntries(JarFile jarFile, EntryTransformer entryTransformer, UnpackHandler unpackHandler)
throws IOException {
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarArchiveEntry entry = new JarArchiveEntry(entries.nextElement());
setUpEntry(jarFile, entry);
try (ZipHeaderPeekInputStream inputStream = new ZipHeaderPeekInputStream(
jarFile.getInputStream(entry))) {
try (ZipHeaderPeekInputStream inputStream = new ZipHeaderPeekInputStream(jarFile.getInputStream(entry))) {
EntryWriter entryWriter = new InputStreamEntryWriter(inputStream, true);
JarArchiveEntry transformedEntry = entryTransformer.transform(entry);
if (transformedEntry != null) {
@@ -147,8 +144,7 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
}
private void setUpEntry(JarFile jarFile, JarArchiveEntry entry) throws IOException {
try (ZipHeaderPeekInputStream inputStream = new ZipHeaderPeekInputStream(
jarFile.getInputStream(entry))) {
try (ZipHeaderPeekInputStream inputStream = new ZipHeaderPeekInputStream(jarFile.getInputStream(entry))) {
if (inputStream.hasZipHeader() && entry.getMethod() != ZipEntry.STORED) {
new CrcAndSize(inputStream).setupStoredEntry(entry);
}
@@ -176,8 +172,7 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
* @param library the library
* @throws IOException if the write fails
*/
public void writeNestedLibrary(String destination, Library library)
throws IOException {
public void writeNestedLibrary(String destination, Library library) throws IOException {
File file = library.getFile();
JarArchiveEntry entry = new JarArchiveEntry(destination + library.getName());
entry.setTime(getNestedLibraryTime(file));
@@ -222,13 +217,11 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
@Override
public void writeLoaderClasses(String loaderJarResourceName) throws IOException {
URL loaderJar = getClass().getClassLoader().getResource(loaderJarResourceName);
try (JarInputStream inputStream = new JarInputStream(
new BufferedInputStream(loaderJar.openStream()))) {
try (JarInputStream inputStream = new JarInputStream(new BufferedInputStream(loaderJar.openStream()))) {
JarEntry entry;
while ((entry = inputStream.getNextJarEntry()) != null) {
if (entry.getName().endsWith(".class")) {
writeEntry(new JarArchiveEntry(entry),
new InputStreamEntryWriter(inputStream, false));
writeEntry(new JarArchiveEntry(entry), new InputStreamEntryWriter(inputStream, false));
}
}
}
@@ -243,8 +236,7 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
this.jarOutput.close();
}
private void writeEntry(JarArchiveEntry entry, EntryWriter entryWriter)
throws IOException {
private void writeEntry(JarArchiveEntry entry, EntryWriter entryWriter) throws IOException {
writeEntry(entry, entryWriter, NEVER_UNPACK);
}
@@ -256,8 +248,8 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
* @param unpackHandler handles possible unpacking for the entry
* @throws IOException in case of I/O errors
*/
private void writeEntry(JarArchiveEntry entry, EntryWriter entryWriter,
UnpackHandler unpackHandler) throws IOException {
private void writeEntry(JarArchiveEntry entry, EntryWriter entryWriter, UnpackHandler unpackHandler)
throws IOException {
String parent = entry.getName();
if (parent.endsWith("/")) {
parent = parent.substring(0, parent.length() - 1);
@@ -283,16 +275,15 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
}
}
private EntryWriter addUnpackCommentIfNecessary(JarArchiveEntry entry,
EntryWriter entryWriter, UnpackHandler unpackHandler) throws IOException {
private EntryWriter addUnpackCommentIfNecessary(JarArchiveEntry entry, EntryWriter entryWriter,
UnpackHandler unpackHandler) throws IOException {
if (entryWriter == null || !unpackHandler.requiresUnpack(entry.getName())) {
return entryWriter;
}
ByteArrayOutputStream output = new ByteArrayOutputStream();
entryWriter.write(output);
entry.setComment("UNPACK:" + unpackHandler.sha1Hash(entry.getName()));
return new InputStreamEntryWriter(new ByteArrayInputStream(output.toByteArray()),
true);
return new InputStreamEntryWriter(new ByteArrayInputStream(output.toByteArray()), true);
}
/**
@@ -357,8 +348,7 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
super(in);
this.header = new byte[4];
this.headerLength = in.read(this.header);
this.headerStream = new ByteArrayInputStream(this.header, 0,
this.headerLength);
this.headerStream = new ByteArrayInputStream(this.header, 0, this.headerLength);
}
@Override
@@ -381,8 +371,7 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
@Override
public int read(byte[] b, int off, int len) throws IOException {
int read = (this.headerStream != null) ? this.headerStream.read(b, off, len)
: -1;
int read = (this.headerStream != null) ? this.headerStream.read(b, off, len) : -1;
if (read <= 0) {
return readRemainder(b, off, len);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,8 +35,7 @@ public class JavaExecutable {
public JavaExecutable() {
String javaHome = System.getProperty("java.home");
Assert.state(StringUtils.hasLength(javaHome),
"Unable to find java executable due to missing 'java.home'");
Assert.state(StringUtils.hasLength(javaHome), "Unable to find java executable due to missing 'java.home'");
this.file = findInJavaHome(javaHome);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -57,8 +57,7 @@ public abstract class MainClassFinder {
private static final Type STRING_ARRAY_TYPE = Type.getType(String[].class);
private static final Type MAIN_METHOD_TYPE = Type.getMethodType(Type.VOID_TYPE,
STRING_ARRAY_TYPE);
private static final Type MAIN_METHOD_TYPE = Type.getMethodType(Type.VOID_TYPE, STRING_ARRAY_TYPE);
private static final String MAIN_METHOD_NAME = "main";
@@ -104,8 +103,7 @@ public abstract class MainClassFinder {
* @return the main class or {@code null}
* @throws IOException if the folder cannot be read
*/
public static String findSingleMainClass(File rootFolder, String annotationName)
throws IOException {
public static String findSingleMainClass(File rootFolder, String annotationName) throws IOException {
SingleMainClassCallback callback = new SingleMainClassCallback(annotationName);
MainClassFinder.doWithMainClasses(rootFolder, callback);
return callback.getMainClassName();
@@ -120,14 +118,12 @@ public abstract class MainClassFinder {
* @return the first callback result or {@code null}
* @throws IOException in case of I/O errors
*/
static <T> T doWithMainClasses(File rootFolder, MainClassCallback<T> callback)
throws IOException {
static <T> T doWithMainClasses(File rootFolder, MainClassCallback<T> callback) throws IOException {
if (!rootFolder.exists()) {
return null; // nothing to do
}
if (!rootFolder.isDirectory()) {
throw new IllegalArgumentException(
"Invalid root folder '" + rootFolder + "'");
throw new IllegalArgumentException("Invalid root folder '" + rootFolder + "'");
}
String prefix = rootFolder.getAbsolutePath() + "/";
Deque<File> stack = new ArrayDeque<>();
@@ -138,10 +134,8 @@ public abstract class MainClassFinder {
try (InputStream inputStream = new FileInputStream(file)) {
ClassDescriptor classDescriptor = createClassDescriptor(inputStream);
if (classDescriptor != null && classDescriptor.isMainMethodFound()) {
String className = convertToClassName(file.getAbsolutePath(),
prefix);
T result = callback.doWith(new MainClass(className,
classDescriptor.getAnnotationNames()));
String className = convertToClassName(file.getAbsolutePath(), prefix);
T result = callback.doWith(new MainClass(className, classDescriptor.getAnnotationNames()));
if (result != null) {
return result;
}
@@ -170,8 +164,7 @@ public abstract class MainClassFinder {
* @return the main class or {@code null}
* @throws IOException if the jar file cannot be read
*/
public static String findMainClass(JarFile jarFile, String classesLocation)
throws IOException {
public static String findMainClass(JarFile jarFile, String classesLocation) throws IOException {
return doWithMainClasses(jarFile, classesLocation, MainClass::getName);
}
@@ -182,8 +175,7 @@ public abstract class MainClassFinder {
* @return the main class or {@code null}
* @throws IOException if the jar file cannot be read
*/
public static String findSingleMainClass(JarFile jarFile, String classesLocation)
throws IOException {
public static String findSingleMainClass(JarFile jarFile, String classesLocation) throws IOException {
return findSingleMainClass(jarFile, classesLocation, null);
}
@@ -198,8 +190,8 @@ public abstract class MainClassFinder {
* @return the main class or {@code null}
* @throws IOException if the jar file cannot be read
*/
public static String findSingleMainClass(JarFile jarFile, String classesLocation,
String annotationName) throws IOException {
public static String findSingleMainClass(JarFile jarFile, String classesLocation, String annotationName)
throws IOException {
SingleMainClassCallback callback = new SingleMainClassCallback(annotationName);
MainClassFinder.doWithMainClasses(jarFile, classesLocation, callback);
return callback.getMainClassName();
@@ -214,19 +206,16 @@ public abstract class MainClassFinder {
* @return the first callback result or {@code null}
* @throws IOException in case of I/O errors
*/
static <T> T doWithMainClasses(JarFile jarFile, String classesLocation,
MainClassCallback<T> callback) throws IOException {
static <T> T doWithMainClasses(JarFile jarFile, String classesLocation, MainClassCallback<T> callback)
throws IOException {
List<JarEntry> classEntries = getClassEntries(jarFile, classesLocation);
classEntries.sort(new ClassEntryComparator());
for (JarEntry entry : classEntries) {
try (InputStream inputStream = new BufferedInputStream(
jarFile.getInputStream(entry))) {
try (InputStream inputStream = new BufferedInputStream(jarFile.getInputStream(entry))) {
ClassDescriptor classDescriptor = createClassDescriptor(inputStream);
if (classDescriptor != null && classDescriptor.isMainMethodFound()) {
String className = convertToClassName(entry.getName(),
classesLocation);
T result = callback.doWith(new MainClass(className,
classDescriptor.getAnnotationNames()));
String className = convertToClassName(entry.getName(), classesLocation);
T result = callback.doWith(new MainClass(className, classDescriptor.getAnnotationNames()));
if (result != null) {
return result;
}
@@ -246,15 +235,13 @@ public abstract class MainClassFinder {
return name;
}
private static List<JarEntry> getClassEntries(JarFile source,
String classesLocation) {
private static List<JarEntry> getClassEntries(JarFile source, String classesLocation) {
classesLocation = (classesLocation != null) ? classesLocation : "";
Enumeration<JarEntry> sourceEntries = source.entries();
List<JarEntry> classEntries = new ArrayList<>();
while (sourceEntries.hasMoreElements()) {
JarEntry entry = sourceEntries.nextElement();
if (entry.getName().startsWith(classesLocation)
&& entry.getName().endsWith(DOT_CLASS)) {
if (entry.getName().startsWith(classesLocation) && entry.getName().endsWith(DOT_CLASS)) {
classEntries.add(entry);
}
}
@@ -309,10 +296,8 @@ public abstract class MainClassFinder {
}
@Override
public MethodVisitor visitMethod(int access, String name, String desc,
String signature, String[] exceptions) {
if (isAccess(access, Opcodes.ACC_PUBLIC, Opcodes.ACC_STATIC)
&& MAIN_METHOD_NAME.equals(name)
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
if (isAccess(access, Opcodes.ACC_PUBLIC, Opcodes.ACC_STATIC) && MAIN_METHOD_NAME.equals(name)
&& MAIN_METHOD_TYPE.getDescriptor().equals(desc)) {
this.mainMethodFound = true;
}
@@ -372,8 +357,7 @@ public abstract class MainClassFinder {
*/
MainClass(String name, Set<String> annotationNames) {
this.name = name;
this.annotationNames = Collections
.unmodifiableSet(new HashSet<>(annotationNames));
this.annotationNames = Collections.unmodifiableSet(new HashSet<>(annotationNames));
}
String getName() {
@@ -418,8 +402,7 @@ public abstract class MainClassFinder {
* Find a single main class, throwing an {@link IllegalStateException} if multiple
* candidates exist.
*/
private static final class SingleMainClassCallback
implements MainClassCallback<Object> {
private static final class SingleMainClassCallback implements MainClassCallback<Object> {
private final Set<MainClass> mainClasses = new LinkedHashSet<>();
@@ -449,11 +432,9 @@ public abstract class MainClassFinder {
}
if (matchingMainClasses.size() > 1) {
throw new IllegalStateException(
"Unable to find a single main class from the following candidates "
+ matchingMainClasses);
"Unable to find a single main class from the following candidates " + matchingMainClasses);
}
return (matchingMainClasses.isEmpty() ? null
: matchingMainClasses.iterator().next().getName());
return (matchingMainClasses.isEmpty() ? null : matchingMainClasses.iterator().next().getName());
}
}

View File

@@ -84,8 +84,8 @@ public class Repackager {
throw new IllegalArgumentException("Source file must be provided");
}
if (!source.exists() || !source.isFile()) {
throw new IllegalArgumentException("Source must refer to an existing file, "
+ "got " + source.getAbsolutePath());
throw new IllegalArgumentException(
"Source must refer to an existing file, " + "got " + source.getAbsolutePath());
}
this.source = source.getAbsoluteFile();
this.layoutFactory = layoutFactory;
@@ -96,8 +96,7 @@ public class Repackager {
* main class takes too long.
* @param listener the listener to add
*/
public void addMainClassTimeoutWarningListener(
MainClassTimeoutWarningListener listener) {
public void addMainClassTimeoutWarningListener(MainClassTimeoutWarningListener listener) {
this.mainClassTimeoutListeners.add(listener);
}
@@ -168,8 +167,7 @@ public class Repackager {
* @throws IOException if the file cannot be repackaged
* @since 1.3.0
*/
public void repackage(File destination, Libraries libraries,
LaunchScript launchScript) throws IOException {
public void repackage(File destination, Libraries libraries, LaunchScript launchScript) throws IOException {
if (destination == null || destination.isDirectory()) {
throw new IllegalArgumentException("Invalid destination");
}
@@ -206,8 +204,7 @@ public class Repackager {
if (this.layoutFactory != null) {
return this.layoutFactory;
}
List<LayoutFactory> factories = SpringFactoriesLoader
.loadFactories(LayoutFactory.class, null);
List<LayoutFactory> factories = SpringFactoriesLoader.loadFactories(LayoutFactory.class, null);
if (factories.isEmpty()) {
return new DefaultLayoutFactory();
}
@@ -226,20 +223,19 @@ public class Repackager {
private boolean alreadyRepackaged() throws IOException {
try (JarFile jarFile = new JarFile(this.source)) {
Manifest manifest = jarFile.getManifest();
return (manifest != null && manifest.getMainAttributes()
.getValue(BOOT_VERSION_ATTRIBUTE) != null);
return (manifest != null && manifest.getMainAttributes().getValue(BOOT_VERSION_ATTRIBUTE) != null);
}
}
private void repackage(JarFile sourceJar, File destination, Libraries libraries,
LaunchScript launchScript) throws IOException {
private void repackage(JarFile sourceJar, File destination, Libraries libraries, LaunchScript launchScript)
throws IOException {
WritableLibraries writeableLibraries = new WritableLibraries(libraries);
try (JarWriter writer = new JarWriter(destination, launchScript)) {
writer.writeManifest(buildManifest(sourceJar));
writeLoaderClasses(writer);
if (this.layout instanceof RepackagingLayout) {
writer.writeEntries(sourceJar, new RenamingEntryTransformer(
((RepackagingLayout) this.layout).getRepackagedClassesLocation()),
writer.writeEntries(sourceJar,
new RenamingEntryTransformer(((RepackagingLayout) this.layout).getRepackagedClassesLocation()),
writeableLibraries);
}
else {
@@ -294,8 +290,7 @@ public class Repackager {
}
String launcherClassName = this.layout.getLauncherClassName();
if (launcherClassName != null) {
manifest.getMainAttributes().putValue(MAIN_CLASS_ATTRIBUTE,
launcherClassName);
manifest.getMainAttributes().putValue(MAIN_CLASS_ATTRIBUTE, launcherClassName);
if (startClass == null) {
throw new IllegalStateException("Unable to find main class");
}
@@ -306,10 +301,8 @@ public class Repackager {
}
String bootVersion = getClass().getPackage().getImplementationVersion();
manifest.getMainAttributes().putValue(BOOT_VERSION_ATTRIBUTE, bootVersion);
manifest.getMainAttributes().putValue(BOOT_CLASSES_ATTRIBUTE,
(this.layout instanceof RepackagingLayout)
? ((RepackagingLayout) this.layout).getRepackagedClassesLocation()
: this.layout.getClassesLocation());
manifest.getMainAttributes().putValue(BOOT_CLASSES_ATTRIBUTE, (this.layout instanceof RepackagingLayout)
? ((RepackagingLayout) this.layout).getRepackagedClassesLocation() : this.layout.getClassesLocation());
String lib = this.layout.getLibraryDestination("", LibraryScope.COMPILE);
if (StringUtils.hasLength(lib)) {
manifest.getMainAttributes().putValue(BOOT_LIB_ATTRIBUTE, lib);
@@ -330,14 +323,13 @@ public class Repackager {
}
protected String findMainMethod(JarFile source) throws IOException {
return MainClassFinder.findSingleMainClass(source,
this.layout.getClassesLocation(), SPRING_BOOT_APPLICATION_CLASS_NAME);
return MainClassFinder.findSingleMainClass(source, this.layout.getClassesLocation(),
SPRING_BOOT_APPLICATION_CLASS_NAME);
}
private void renameFile(File file, File dest) {
if (!file.renameTo(dest)) {
throw new IllegalStateException(
"Unable to rename '" + file + "' to '" + dest + "'");
throw new IllegalStateException("Unable to rename '" + file + "' to '" + dest + "'");
}
}
@@ -379,15 +371,12 @@ public class Repackager {
if (entry.getName().equals("META-INF/INDEX.LIST")) {
return null;
}
if ((entry.getName().startsWith("META-INF/")
&& !entry.getName().equals("META-INF/aop.xml")
&& !entry.getName().endsWith(".kotlin_module"))
|| entry.getName().startsWith("BOOT-INF/")
if ((entry.getName().startsWith("META-INF/") && !entry.getName().equals("META-INF/aop.xml")
&& !entry.getName().endsWith(".kotlin_module")) || entry.getName().startsWith("BOOT-INF/")
|| entry.getName().equals("module-info.class")) {
return entry;
}
JarArchiveEntry renamedEntry = new JarArchiveEntry(
this.namePrefix + entry.getName());
JarArchiveEntry renamedEntry = new JarArchiveEntry(this.namePrefix + entry.getName());
renamedEntry.setTime(entry.getTime());
renamedEntry.setSize(entry.getSize());
renamedEntry.setMethod(entry.getMethod());
@@ -424,14 +413,13 @@ public class Repackager {
private WritableLibraries(Libraries libraries) throws IOException {
libraries.doWithLibraries((library) -> {
if (isZip(library.getFile())) {
String libraryDestination = Repackager.this.layout
.getLibraryDestination(library.getName(), library.getScope());
String libraryDestination = Repackager.this.layout.getLibraryDestination(library.getName(),
library.getScope());
if (libraryDestination != null) {
Library existing = this.libraryEntryNames.putIfAbsent(
libraryDestination + library.getName(), library);
Library existing = this.libraryEntryNames.putIfAbsent(libraryDestination + library.getName(),
library);
if (existing != null) {
throw new IllegalStateException(
"Duplicate library " + library.getName());
throw new IllegalStateException("Duplicate library " + library.getName());
}
}
}
@@ -448,16 +436,14 @@ public class Repackager {
public String sha1Hash(String name) throws IOException {
Library library = this.libraryEntryNames.get(name);
if (library == null) {
throw new IllegalArgumentException(
"No library found for entry name '" + name + "'");
throw new IllegalArgumentException("No library found for entry name '" + name + "'");
}
return FileUtils.sha1Hash(library.getFile());
}
private void write(JarWriter writer) throws IOException {
for (Entry<String, Library> entry : this.libraryEntryNames.entrySet()) {
writer.writeNestedLibrary(
entry.getKey().substring(0, entry.getKey().lastIndexOf('/') + 1),
writer.writeNestedLibrary(entry.getKey().substring(0, entry.getKey().lastIndexOf('/') + 1),
entry.getValue());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -69,8 +69,8 @@ public class RunProcess {
return run(waitForProcess, Arrays.asList(args), Collections.emptyMap());
}
public int run(boolean waitForProcess, Collection<String> args,
Map<String, String> environmentVariables) throws IOException {
public int run(boolean waitForProcess, Collection<String> args, Map<String, String> environmentVariables)
throws IOException {
ProcessBuilder builder = new ProcessBuilder(this.command);
builder.directory(this.workingDirectory);
builder.command().addAll(args);