Upgrade to spring-javaformat 0.0.11

This commit is contained in:
Andy Wilkinson
2019-06-07 09:44:58 +01:00
parent d548c5ed31
commit 8f1be4cded
1940 changed files with 16814 additions and 28498 deletions

View File

@@ -68,12 +68,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() + "'");
}
}
@@ -85,8 +84,7 @@ public final class BuildPropertiesWriter {
properties.put("build.version", project.getVersion());
properties.put("build.time", formatDate(new Date()));
if (project.getAdditionalProperties() != null) {
for (Map.Entry<String, String> entry : project.getAdditionalProperties()
.entrySet()) {
for (Map.Entry<String, String> entry : project.getAdditionalProperties().entrySet()) {
properties.put("build." + entry.getKey(), entry.getValue());
}
}
@@ -123,8 +121,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) {
for (Entry<String, String> property : additionalProperties.entrySet()) {
if (property.getValue() == null) {
@@ -159,8 +156,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

@@ -41,8 +41,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 final String content;
@@ -75,8 +74,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) {

View File

@@ -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 {
DigestInputStream inputStream = new DigestInputStream(
new FileInputStream(file), MessageDigest.getInstance("SHA-1"));
DigestInputStream inputStream = new DigestInputStream(new FileInputStream(file),
MessageDigest.getInstance("SHA-1"));
try {
byte[] buffer = new byte[4098];
while (inputStream.read(buffer) != -1) {

View File

@@ -78,8 +78,7 @@ public class JarWriter implements LoaderClassesWriter {
* @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());
@@ -126,19 +125,16 @@ public class JarWriter implements LoaderClassesWriter {
this.writeEntries(jarFile, new IdentityEntryTransformer());
}
void writeEntries(JarFile jarFile, EntryTransformer entryTransformer)
throws IOException {
void writeEntries(JarFile jarFile, EntryTransformer entryTransformer) throws IOException {
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
ZipHeaderPeekInputStream inputStream = new ZipHeaderPeekInputStream(
jarFile.getInputStream(entry));
ZipHeaderPeekInputStream inputStream = new ZipHeaderPeekInputStream(jarFile.getInputStream(entry));
try {
if (inputStream.hasZipHeader() && entry.getMethod() != ZipEntry.STORED) {
new CrcAndSize(inputStream).setupStoredEntry(entry);
inputStream.close();
inputStream = new ZipHeaderPeekInputStream(
jarFile.getInputStream(entry));
inputStream = new ZipHeaderPeekInputStream(jarFile.getInputStream(entry));
}
else {
entry.setCompressedSize(-1);
@@ -173,8 +169,7 @@ public class JarWriter implements LoaderClassesWriter {
* @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();
JarEntry entry = new JarEntry(destination + library.getName());
entry.setTime(getNestedLibraryTime(file));
@@ -225,8 +220,7 @@ public class JarWriter implements LoaderClassesWriter {
@Override
public void writeLoaderClasses(String loaderJarResourceName) throws IOException {
URL loaderJar = getClass().getClassLoader().getResource(loaderJarResourceName);
JarInputStream inputStream = new JarInputStream(
new BufferedInputStream(loaderJar.openStream()));
JarInputStream inputStream = new JarInputStream(new BufferedInputStream(loaderJar.openStream()));
JarEntry entry;
while ((entry = inputStream.getNextJarEntry()) != null) {
if (entry.getName().endsWith(".class")) {
@@ -334,8 +328,7 @@ public class JarWriter implements LoaderClassesWriter {
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
@@ -358,8 +351,7 @@ public class JarWriter implements LoaderClassesWriter {
@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

@@ -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

@@ -31,8 +31,7 @@ abstract class JvmUtils {
/**
* Various search locations for tools, including the odd Java 6 OSX jar.
*/
private static final String[] TOOLS_LOCATIONS = { "lib/tools.jar", "../lib/tools.jar",
"../Classes/classes.jar" };
private static final String[] TOOLS_LOCATIONS = { "lib/tools.jar", "../lib/tools.jar", "../Classes/classes.jar" };
public static ClassLoader getToolsClassLoader() {
ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
@@ -57,8 +56,7 @@ abstract class JvmUtils {
private static String getJavaHome() {
try {
return new File(System.getProperty("java.home")).toURI().toURL()
.toExternalForm();
return new File(System.getProperty("java.home")).toURI().toURL().toExternalForm();
}
catch (MalformedURLException ex) {
throw new IllegalStateException("Cannot locate java.home", ex);

View File

@@ -52,8 +52,7 @@ public final class Layouts {
if (file.getName().toLowerCase(Locale.ENGLISH).endsWith(".war")) {
return new War();
}
if (file.isDirectory()
|| file.getName().toLowerCase(Locale.ENGLISH).endsWith(".zip")) {
if (file.isDirectory() || file.getName().toLowerCase(Locale.ENGLISH).endsWith(".zip")) {
return new Expanded();
}
throw new IllegalStateException("Unable to deduce layout for '" + file + "'");
@@ -167,8 +166,7 @@ public final class Layouts {
public static class Module implements Layout {
private static final Set<LibraryScope> LIB_DESTINATION_SCOPES = new HashSet<LibraryScope>(
Arrays.asList(LibraryScope.COMPILE, LibraryScope.RUNTIME,
LibraryScope.CUSTOM));
Arrays.asList(LibraryScope.COMPILE, LibraryScope.RUNTIME, LibraryScope.CUSTOM));
@Override
public String getLauncherClassName() {

View File

@@ -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";
@@ -111,8 +110,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();
@@ -129,8 +127,7 @@ public abstract class MainClassFinder {
* @throws IOException if a root folder cannot be read
* @since 1.5.5
*/
public static String findSingleMainClass(Collection<File> rootFolders,
String annotationName) throws IOException {
public static String findSingleMainClass(Collection<File> rootFolders, String annotationName) throws IOException {
SingleMainClassCallback callback = new SingleMainClassCallback(annotationName);
doWithMainClasses(rootFolders, callback);
return callback.getMainClassName();
@@ -145,8 +142,7 @@ public abstract class MainClassFinder {
* @return the first callback result or {@code null}
* @throws IOException in case of I/O errors
*/
static <T> T doWithMainClasses(Collection<File> rootFolders,
MainClassCallback<T> callback) throws IOException {
static <T> T doWithMainClasses(Collection<File> rootFolders, MainClassCallback<T> callback) throws IOException {
for (File rootFolder : rootFolders) {
T result = doWithMainClasses(rootFolder, callback);
if (result != null) {
@@ -165,14 +161,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<File>();
@@ -184,10 +178,8 @@ public abstract class MainClassFinder {
try {
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;
}
@@ -224,15 +216,13 @@ 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 {
return doWithMainClasses(jarFile, classesLocation,
new MainClassCallback<String>() {
@Override
public String doWith(MainClass mainClass) {
return mainClass.getName();
}
});
public static String findMainClass(JarFile jarFile, String classesLocation) throws IOException {
return doWithMainClasses(jarFile, classesLocation, new MainClassCallback<String>() {
@Override
public String doWith(MainClass mainClass) {
return mainClass.getName();
}
});
}
/**
@@ -242,8 +232,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);
}
@@ -258,8 +247,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();
@@ -274,20 +263,17 @@ 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);
Collections.sort(classEntries, new ClassEntryComparator());
for (JarEntry entry : classEntries) {
InputStream inputStream = new BufferedInputStream(
jarFile.getInputStream(entry));
InputStream inputStream = new BufferedInputStream(jarFile.getInputStream(entry));
try {
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;
}
@@ -310,15 +296,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<JarEntry>();
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);
}
}
@@ -373,10 +357,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;
}
@@ -436,8 +418,7 @@ public abstract class MainClassFinder {
*/
MainClass(String name, Set<String> annotationNames) {
this.name = name;
this.annotationNames = Collections
.unmodifiableSet(new HashSet<String>(annotationNames));
this.annotationNames = Collections.unmodifiableSet(new HashSet<String>(annotationNames));
}
String getName() {
@@ -482,8 +463,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<MainClass>();
@@ -513,11 +493,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

@@ -82,8 +82,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;
@@ -94,8 +94,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);
}
@@ -166,8 +165,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");
}
@@ -208,8 +206,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();
}
@@ -229,16 +226,15 @@ public class Repackager {
JarFile jarFile = new JarFile(this.source);
try {
Manifest manifest = jarFile.getManifest();
return (manifest != null && manifest.getMainAttributes()
.getValue(BOOT_VERSION_ATTRIBUTE) != null);
return (manifest != null && manifest.getMainAttributes().getValue(BOOT_VERSION_ATTRIBUTE) != null);
}
finally {
jarFile.close();
}
}
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 {
JarWriter writer = new JarWriter(destination, launchScript);
try {
final List<Library> unpackLibraries = new ArrayList<Library>();
@@ -271,15 +267,14 @@ public class Repackager {
}
}
private void repackage(JarFile sourceJar, JarWriter writer,
final List<Library> unpackLibraries, final List<Library> standardLibraries)
throws IOException {
private void repackage(JarFile sourceJar, JarWriter writer, final List<Library> unpackLibraries,
final List<Library> standardLibraries) throws IOException {
writer.writeManifest(buildManifest(sourceJar));
Set<String> seen = new HashSet<String>();
writeNestedLibraries(unpackLibraries, seen, writer);
if (this.layout instanceof RepackagingLayout) {
writer.writeEntries(sourceJar, new RenamingEntryTransformer(
((RepackagingLayout) this.layout).getRepackagedClassesLocation()));
writer.writeEntries(sourceJar,
new RenamingEntryTransformer(((RepackagingLayout) this.layout).getRepackagedClassesLocation()));
}
else {
writer.writeEntries(sourceJar);
@@ -288,15 +283,13 @@ public class Repackager {
writeLoaderClasses(writer);
}
private void writeNestedLibraries(List<Library> libraries, Set<String> alreadySeen,
JarWriter writer) throws IOException {
private void writeNestedLibraries(List<Library> libraries, Set<String> alreadySeen, JarWriter writer)
throws IOException {
for (Library library : libraries) {
String destination = Repackager.this.layout
.getLibraryDestination(library.getName(), library.getScope());
String destination = Repackager.this.layout.getLibraryDestination(library.getName(), library.getScope());
if (destination != null) {
if (!alreadySeen.add(destination + library.getName())) {
throw new IllegalStateException(
"Duplicate library " + library.getName());
throw new IllegalStateException("Duplicate library " + library.getName());
}
writer.writeNestedLibrary(destination, library);
}
@@ -352,8 +345,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");
}
@@ -364,10 +356,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);
@@ -388,14 +378,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 + "'");
}
}
@@ -436,8 +425,7 @@ 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"))
if ((entry.getName().startsWith("META-INF/") && !entry.getName().equals("META-INF/aop.xml"))
|| entry.getName().startsWith("BOOT-INF/")) {
return entry;
}

View File

@@ -38,8 +38,7 @@ import org.springframework.util.ReflectionUtils;
*/
public class RunProcess {
private static final Method INHERIT_IO_METHOD = ReflectionUtils
.findMethod(ProcessBuilder.class, "inheritIO");
private static final Method INHERIT_IO_METHOD = ReflectionUtils.findMethod(ProcessBuilder.class, "inheritIO");
private static final long JUST_ENDED_LIMIT = 500;
@@ -75,8 +74,7 @@ public class RunProcess {
return run(waitForProcess, Arrays.asList(args));
}
protected int run(boolean waitForProcess, Collection<String> args)
throws IOException {
protected int run(boolean waitForProcess, Collection<String> args) throws IOException {
ProcessBuilder builder = new ProcessBuilder(this.command);
builder.directory(this.workingDirectory);
builder.command().addAll(args);
@@ -129,8 +127,7 @@ public class RunProcess {
// There's a bug in the Windows VM (https://bugs.openjdk.java.net/browse/JDK-8023130)
// that means we need to avoid inheritIO
private static boolean isInheritIOBroken() {
if (!System.getProperty("os.name", "none").toLowerCase(Locale.ENGLISH)
.contains("windows")) {
if (!System.getProperty("os.name", "none").toLowerCase(Locale.ENGLISH).contains("windows")) {
return false;
}
String runtime = System.getProperty("java.runtime.version");
@@ -154,8 +151,7 @@ public class RunProcess {
}
private void redirectOutput(Process process) {
final BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
final BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
new Thread() {
@Override

View File

@@ -160,8 +160,7 @@ public class DefaultLaunchScriptTests {
public void expandVariables() throws Exception {
File file = this.temporaryFolder.newFile();
FileCopyUtils.copy("h{{a}}ll{{b}}".getBytes(), file);
DefaultLaunchScript script = new DefaultLaunchScript(file,
createProperties("a:e", "b:o"));
DefaultLaunchScript script = new DefaultLaunchScript(file, createProperties("a:e", "b:o"));
String content = new String(script.toByteArray());
assertThat(content).isEqualTo("hello");
}
@@ -170,8 +169,7 @@ public class DefaultLaunchScriptTests {
public void expandVariablesMultiLine() throws Exception {
File file = this.temporaryFolder.newFile();
FileCopyUtils.copy("h{{a}}l\nl{{b}}".getBytes(), file);
DefaultLaunchScript script = new DefaultLaunchScript(file,
createProperties("a:e", "b:o"));
DefaultLaunchScript script = new DefaultLaunchScript(file, createProperties("a:e", "b:o"));
String content = new String(script.toByteArray());
assertThat(content).isEqualTo("hel\nlo");
}
@@ -189,8 +187,7 @@ public class DefaultLaunchScriptTests {
public void expandVariablesWithDefaultsOverride() throws Exception {
File file = this.temporaryFolder.newFile();
FileCopyUtils.copy("h{{a:e}}ll{{b:o}}".getBytes(), file);
DefaultLaunchScript script = new DefaultLaunchScript(file,
createProperties("a:a"));
DefaultLaunchScript script = new DefaultLaunchScript(file, createProperties("a:a"));
String content = new String(script.toByteArray());
assertThat(content).isEqualTo("hallo");
}
@@ -205,8 +202,7 @@ public class DefaultLaunchScriptTests {
}
private void assertThatPlaceholderCanBeReplaced(String placeholder) throws Exception {
DefaultLaunchScript script = new DefaultLaunchScript(null,
createProperties(placeholder + ":__test__"));
DefaultLaunchScript script = new DefaultLaunchScript(null, createProperties(placeholder + ":__test__"));
String content = new String(script.toByteArray());
assertThat(content).contains("__test__");
}

View File

@@ -60,8 +60,7 @@ public class FileUtilsTests {
File file = new File(this.outputDirectory, "logback.xml");
file.createNewFile();
new File(this.originDirectory, "logback.xml").createNewFile();
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory,
this.originDirectory);
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory, this.originDirectory);
assertThat(file.exists()).isFalse();
}
@@ -72,8 +71,7 @@ public class FileUtilsTests {
File file = new File(this.outputDirectory, "sub/logback.xml");
file.createNewFile();
new File(this.originDirectory, "sub/logback.xml").createNewFile();
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory,
this.originDirectory);
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory, this.originDirectory);
assertThat(file.exists()).isFalse();
}
@@ -84,8 +82,7 @@ public class FileUtilsTests {
File file = new File(this.outputDirectory, "sub/logback.xml");
file.createNewFile();
new File(this.originDirectory, "sub/different.xml").createNewFile();
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory,
this.originDirectory);
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory, this.originDirectory);
assertThat(file.exists()).isTrue();
}
@@ -94,8 +91,7 @@ public class FileUtilsTests {
File file = new File(this.outputDirectory, "logback.xml");
file.createNewFile();
new File(this.originDirectory, "different.xml").createNewFile();
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory,
this.originDirectory);
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory, this.originDirectory);
assertThat(file.exists()).isTrue();
}
@@ -109,8 +105,7 @@ public class FileUtilsTests {
finally {
outputStream.close();
}
assertThat(FileUtils.sha1Hash(file))
.isEqualTo("7037807198c22a7d2b0807371d763779a84fdfcf");
assertThat(FileUtils.sha1Hash(file)).isEqualTo("7037807198c22a7d2b0807371d763779a84fdfcf");
}
}

View File

@@ -40,8 +40,7 @@ public class LayoutsTests {
assertThat(Layouts.forFile(new File("test.jar"))).isInstanceOf(Layouts.Jar.class);
assertThat(Layouts.forFile(new File("test.JAR"))).isInstanceOf(Layouts.Jar.class);
assertThat(Layouts.forFile(new File("test.jAr"))).isInstanceOf(Layouts.Jar.class);
assertThat(Layouts.forFile(new File("te.st.jar")))
.isInstanceOf(Layouts.Jar.class);
assertThat(Layouts.forFile(new File("te.st.jar"))).isInstanceOf(Layouts.Jar.class);
}
@Test
@@ -49,8 +48,7 @@ public class LayoutsTests {
assertThat(Layouts.forFile(new File("test.war"))).isInstanceOf(Layouts.War.class);
assertThat(Layouts.forFile(new File("test.WAR"))).isInstanceOf(Layouts.War.class);
assertThat(Layouts.forFile(new File("test.wAr"))).isInstanceOf(Layouts.War.class);
assertThat(Layouts.forFile(new File("te.st.war")))
.isInstanceOf(Layouts.War.class);
assertThat(Layouts.forFile(new File("te.st.war"))).isInstanceOf(Layouts.War.class);
}
@Test
@@ -63,41 +61,29 @@ public class LayoutsTests {
@Test
public void jarLayout() throws Exception {
Layout layout = new Layouts.Jar();
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.COMPILE))
.isEqualTo("BOOT-INF/lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.CUSTOM))
.isEqualTo("BOOT-INF/lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.PROVIDED))
.isEqualTo("BOOT-INF/lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.RUNTIME))
.isEqualTo("BOOT-INF/lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.COMPILE)).isEqualTo("BOOT-INF/lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.CUSTOM)).isEqualTo("BOOT-INF/lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.PROVIDED)).isEqualTo("BOOT-INF/lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.RUNTIME)).isEqualTo("BOOT-INF/lib/");
}
@Test
public void warLayout() throws Exception {
Layout layout = new Layouts.War();
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.COMPILE))
.isEqualTo("WEB-INF/lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.CUSTOM))
.isEqualTo("WEB-INF/lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.PROVIDED))
.isEqualTo("WEB-INF/lib-provided/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.RUNTIME))
.isEqualTo("WEB-INF/lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.COMPILE)).isEqualTo("WEB-INF/lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.CUSTOM)).isEqualTo("WEB-INF/lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.PROVIDED)).isEqualTo("WEB-INF/lib-provided/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.RUNTIME)).isEqualTo("WEB-INF/lib/");
}
@Test
@SuppressWarnings("deprecation")
public void moduleLayout() throws Exception {
Layout layout = new Layouts.Module();
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.COMPILE))
.isEqualTo("lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.PROVIDED))
.isNull();
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.RUNTIME))
.isEqualTo("lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.CUSTOM))
.isEqualTo("lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.COMPILE)).isEqualTo("lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.PROVIDED)).isNull();
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.RUNTIME)).isEqualTo("lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.CUSTOM)).isEqualTo("lib/");
}
}

View File

@@ -84,8 +84,8 @@ public class MainClassFinderTests {
this.testJarFile.addClass("a/B.class", ClassWithMainMethod.class);
this.testJarFile.addClass("a/b/c/E.class", ClassWithMainMethod.class);
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("Unable to find a single main class "
+ "from the following candidates [a.B, a.b.c.E]");
this.thrown
.expectMessage("Unable to find a single main class " + "from the following candidates [a.B, a.b.c.E]");
MainClassFinder.findSingleMainClass(this.testJarFile.getJarFile(), "");
}
@@ -93,8 +93,7 @@ public class MainClassFinderTests {
public void findSingleJarSearchPrefersAnnotatedMainClass() throws Exception {
this.testJarFile.addClass("a/B.class", ClassWithMainMethod.class);
this.testJarFile.addClass("a/b/c/E.class", AnnotatedClassWithMainMethod.class);
String mainClass = MainClassFinder.findSingleMainClass(
this.testJarFile.getJarFile(), "",
String mainClass = MainClassFinder.findSingleMainClass(this.testJarFile.getJarFile(), "",
"org.springframework.boot.loader.tools.sample.SomeApplication");
assertThat(mainClass).isEqualTo("a.b.c.E");
}
@@ -103,8 +102,7 @@ public class MainClassFinderTests {
public void findMainClassInJarSubLocation() throws Exception {
this.testJarFile.addClass("a/B.class", ClassWithMainMethod.class);
this.testJarFile.addClass("a/b/c/E.class", ClassWithMainMethod.class);
String actual = MainClassFinder.findMainClass(this.testJarFile.getJarFile(),
"a/");
String actual = MainClassFinder.findMainClass(this.testJarFile.getJarFile(), "a/");
assertThat(actual).isEqualTo("B");
}
@@ -139,8 +137,8 @@ public class MainClassFinderTests {
this.testJarFile.addClass("a/B.class", ClassWithMainMethod.class);
this.testJarFile.addClass("a/b/c/E.class", ClassWithMainMethod.class);
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("Unable to find a single main class "
+ "from the following candidates [a.B, a.b.c.E]");
this.thrown
.expectMessage("Unable to find a single main class " + "from the following candidates [a.B, a.b.c.E]");
MainClassFinder.findSingleMainClass(this.testJarFile.getJarSource());
}
@@ -148,8 +146,7 @@ public class MainClassFinderTests {
public void findSingleFolderSearchPrefersAnnotatedMainClass() throws Exception {
this.testJarFile.addClass("a/B.class", ClassWithMainMethod.class);
this.testJarFile.addClass("a/b/c/E.class", AnnotatedClassWithMainMethod.class);
String mainClass = MainClassFinder.findSingleMainClass(
this.testJarFile.getJarSource(),
String mainClass = MainClassFinder.findSingleMainClass(this.testJarFile.getJarSource(),
"org.springframework.boot.loader.tools.sample.SomeApplication");
assertThat(mainClass).isEqualTo("a.b.c.E");
}

View File

@@ -117,8 +117,7 @@ public class RepackagerTests {
Manifest actualManifest = getManifest(file);
assertThat(actualManifest.getMainAttributes().getValue("Main-Class"))
.isEqualTo("org.springframework.boot.loader.JarLauncher");
assertThat(actualManifest.getMainAttributes().getValue("Start-Class"))
.isEqualTo("a.b.C");
assertThat(actualManifest.getMainAttributes().getValue("Start-Class")).isEqualTo("a.b.C");
assertThat(hasLauncherClasses(file)).isTrue();
}
@@ -135,8 +134,7 @@ public class RepackagerTests {
Manifest actualManifest = getManifest(file);
assertThat(actualManifest.getMainAttributes().getValue("Main-Class"))
.isEqualTo("org.springframework.boot.loader.JarLauncher");
assertThat(actualManifest.getMainAttributes().getValue("Start-Class"))
.isEqualTo("a.b.C");
assertThat(actualManifest.getMainAttributes().getValue("Start-Class")).isEqualTo("a.b.C");
assertThat(hasLauncherClasses(file)).isTrue();
}
@@ -149,8 +147,7 @@ public class RepackagerTests {
Manifest actualManifest = getManifest(file);
assertThat(actualManifest.getMainAttributes().getValue("Main-Class"))
.isEqualTo("org.springframework.boot.loader.JarLauncher");
assertThat(actualManifest.getMainAttributes().getValue("Start-Class"))
.isEqualTo("a.b.C");
assertThat(actualManifest.getMainAttributes().getValue("Start-Class")).isEqualTo("a.b.C");
assertThat(hasLauncherClasses(file)).isTrue();
}
@@ -164,8 +161,7 @@ public class RepackagerTests {
Manifest actualManifest = getManifest(file);
assertThat(actualManifest.getMainAttributes().getValue("Main-Class"))
.isEqualTo("org.springframework.boot.loader.JarLauncher");
assertThat(actualManifest.getMainAttributes().getValue("Start-Class"))
.isEqualTo("a.b.C");
assertThat(actualManifest.getMainAttributes().getValue("Start-Class")).isEqualTo("a.b.C");
assertThat(hasLauncherClasses(file)).isTrue();
}
@@ -176,8 +172,8 @@ public class RepackagerTests {
File file = this.testJarFile.getFile();
Repackager repackager = new Repackager(file);
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("Unable to find a single main class "
+ "from the following candidates [a.b.C, a.b.D]");
this.thrown
.expectMessage("Unable to find a single main class " + "from the following candidates [a.b.C, a.b.D]");
repackager.repackage(NO_LIBRARIES);
}
@@ -197,8 +193,7 @@ public class RepackagerTests {
repackager.setLayout(new Layouts.None());
repackager.repackage(file, NO_LIBRARIES);
Manifest actualManifest = getManifest(file);
assertThat(actualManifest.getMainAttributes().getValue("Main-Class"))
.isEqualTo("a.b.C");
assertThat(actualManifest.getMainAttributes().getValue("Main-Class")).isEqualTo("a.b.C");
assertThat(hasLauncherClasses(file)).isFalse();
}
@@ -210,8 +205,7 @@ public class RepackagerTests {
repackager.setLayout(new Layouts.None());
repackager.repackage(file, NO_LIBRARIES);
Manifest actualManifest = getManifest(file);
assertThat(actualManifest.getMainAttributes().getValue("Main-Class"))
.isEqualTo(null);
assertThat(actualManifest.getMainAttributes().getValue("Main-Class")).isEqualTo(null);
assertThat(hasLauncherClasses(file)).isFalse();
}
@@ -232,8 +226,7 @@ public class RepackagerTests {
Repackager repackager = new Repackager(file);
repackager.setBackupSource(false);
repackager.repackage(NO_LIBRARIES);
assertThat(new File(file.getParent(), file.getName() + ".original"))
.doesNotExist();
assertThat(new File(file.getParent(), file.getName() + ".original")).doesNotExist();
assertThat(hasLauncherClasses(file)).isTrue();
}
@@ -244,8 +237,7 @@ public class RepackagerTests {
File dest = this.temporaryFolder.newFile("different.jar");
Repackager repackager = new Repackager(source);
repackager.repackage(dest, NO_LIBRARIES);
assertThat(new File(source.getParent(), source.getName() + ".original"))
.doesNotExist();
assertThat(new File(source.getParent(), source.getName() + ".original")).doesNotExist();
assertThat(hasLauncherClasses(source)).isFalse();
assertThat(hasLauncherClasses(dest)).isTrue();
}
@@ -297,8 +289,7 @@ public class RepackagerTests {
final File libNonJarFile = this.temporaryFolder.newFile();
FileCopyUtils.copy(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }, libNonJarFile);
this.testJarFile.addClass("a/b/C.class", ClassWithMainMethod.class);
this.testJarFile.addFile("BOOT-INF/lib/" + libJarFileToUnpack.getName(),
libJarFileToUnpack);
this.testJarFile.addFile("BOOT-INF/lib/" + libJarFileToUnpack.getName(), libJarFileToUnpack);
File file = this.testJarFile.getFile();
libJarFile.setLastModified(JAN_1_1980);
Repackager repackager = new Repackager(file);
@@ -306,14 +297,12 @@ public class RepackagerTests {
@Override
public void doWithLibraries(LibraryCallback callback) throws IOException {
callback.library(new Library(libJarFile, LibraryScope.COMPILE));
callback.library(
new Library(libJarFileToUnpack, LibraryScope.COMPILE, true));
callback.library(new Library(libJarFileToUnpack, LibraryScope.COMPILE, true));
callback.library(new Library(libNonJarFile, LibraryScope.COMPILE));
}
});
assertThat(hasEntry(file, "BOOT-INF/lib/" + libJarFile.getName())).isTrue();
assertThat(hasEntry(file, "BOOT-INF/lib/" + libJarFileToUnpack.getName()))
.isTrue();
assertThat(hasEntry(file, "BOOT-INF/lib/" + libJarFileToUnpack.getName())).isTrue();
assertThat(hasEntry(file, "BOOT-INF/lib/" + libNonJarFile.getName())).isFalse();
JarEntry entry = getEntry(file, "BOOT-INF/lib/" + libJarFile.getName());
assertThat(entry.getTime()).isEqualTo(JAN_1_1985);
@@ -353,8 +342,7 @@ public class RepackagerTests {
final LibraryScope scope = mock(LibraryScope.class);
given(layout.getLauncherClassName()).willReturn("testLauncher");
given(layout.getLibraryDestination(anyString(), eq(scope))).willReturn("test/");
given(layout.getLibraryDestination(anyString(), eq(LibraryScope.COMPILE)))
.willReturn("test-lib/");
given(layout.getLibraryDestination(anyString(), eq(LibraryScope.COMPILE))).willReturn("test-lib/");
repackager.setLayout(layout);
repackager.repackage(new Libraries() {
@@ -365,10 +353,8 @@ public class RepackagerTests {
});
assertThat(hasEntry(file, "test/" + libJarFile.getName())).isTrue();
assertThat(getManifest(file).getMainAttributes().getValue("Spring-Boot-Lib"))
.isEqualTo("test-lib/");
assertThat(getManifest(file).getMainAttributes().getValue("Main-Class"))
.isEqualTo("testLauncher");
assertThat(getManifest(file).getMainAttributes().getValue("Spring-Boot-Lib")).isEqualTo("test-lib/");
assertThat(getManifest(file).getMainAttributes().getValue("Main-Class")).isEqualTo("testLauncher");
}
@Test
@@ -391,10 +377,8 @@ public class RepackagerTests {
}
});
assertThat(getManifest(file).getMainAttributes().getValue("Spring-Boot-Lib"))
.isNull();
assertThat(getManifest(file).getMainAttributes().getValue("Main-Class"))
.isEqualTo("testLauncher");
assertThat(getManifest(file).getMainAttributes().getValue("Spring-Boot-Lib")).isNull();
assertThat(getManifest(file).getMainAttributes().getValue("Main-Class")).isEqualTo("testLauncher");
}
@Test
@@ -404,8 +388,7 @@ public class RepackagerTests {
Repackager repackager = new Repackager(file);
repackager.repackage(NO_LIBRARIES);
Manifest actualManifest = getManifest(file);
assertThat(actualManifest.getMainAttributes())
.containsKey(new Attributes.Name("Spring-Boot-Version"));
assertThat(actualManifest.getMainAttributes()).containsKey(new Attributes.Name("Spring-Boot-Version"));
}
@Test
@@ -415,24 +398,23 @@ public class RepackagerTests {
Repackager repackager = new Repackager(file);
repackager.repackage(NO_LIBRARIES);
Manifest actualManifest = getManifest(file);
assertThat(actualManifest.getMainAttributes())
.containsEntry(new Attributes.Name("Spring-Boot-Lib"), "BOOT-INF/lib/");
assertThat(actualManifest.getMainAttributes()).containsEntry(
new Attributes.Name("Spring-Boot-Classes"), "BOOT-INF/classes/");
assertThat(actualManifest.getMainAttributes()).containsEntry(new Attributes.Name("Spring-Boot-Lib"),
"BOOT-INF/lib/");
assertThat(actualManifest.getMainAttributes()).containsEntry(new Attributes.Name("Spring-Boot-Classes"),
"BOOT-INF/classes/");
}
@Test
public void executableWarLayoutAttributes() throws Exception {
this.testJarFile.addClass("WEB-INF/classes/a/b/C.class",
ClassWithMainMethod.class);
this.testJarFile.addClass("WEB-INF/classes/a/b/C.class", ClassWithMainMethod.class);
File file = this.testJarFile.getFile("war");
Repackager repackager = new Repackager(file);
repackager.repackage(NO_LIBRARIES);
Manifest actualManifest = getManifest(file);
assertThat(actualManifest.getMainAttributes())
.containsEntry(new Attributes.Name("Spring-Boot-Lib"), "WEB-INF/lib/");
assertThat(actualManifest.getMainAttributes()).containsEntry(
new Attributes.Name("Spring-Boot-Classes"), "WEB-INF/classes/");
assertThat(actualManifest.getMainAttributes()).containsEntry(new Attributes.Name("Spring-Boot-Lib"),
"WEB-INF/lib/");
assertThat(actualManifest.getMainAttributes()).containsEntry(new Attributes.Name("Spring-Boot-Classes"),
"WEB-INF/classes/");
}
@Test
@@ -461,11 +443,8 @@ public class RepackagerTests {
});
JarFile jarFile = new JarFile(file);
try {
assertThat(
jarFile.getEntry("BOOT-INF/lib/" + nestedFile.getName()).getMethod())
.isEqualTo(ZipEntry.STORED);
assertThat(jarFile.getEntry("BOOT-INF/classes/test/nested.jar").getMethod())
.isEqualTo(ZipEntry.STORED);
assertThat(jarFile.getEntry("BOOT-INF/lib/" + nestedFile.getName()).getMethod()).isEqualTo(ZipEntry.STORED);
assertThat(jarFile.getEntry("BOOT-INF/classes/test/nested.jar").getMethod()).isEqualTo(ZipEntry.STORED);
}
finally {
jarFile.close();
@@ -485,8 +464,7 @@ public class RepackagerTests {
assertThat(hasLauncherClasses(source)).isFalse();
assertThat(hasLauncherClasses(dest)).isTrue();
try {
assertThat(Files.getPosixFilePermissions(dest.toPath()))
.contains(PosixFilePermission.OWNER_EXECUTE);
assertThat(Files.getPosixFilePermissions(dest.toPath())).contains(PosixFilePermission.OWNER_EXECUTE);
}
catch (UnsupportedOperationException ex) {
// Probably running the test on Windows
@@ -494,13 +472,11 @@ public class RepackagerTests {
}
@Test
public void unpackLibrariesTakePrecedenceOverExistingSourceEntries()
throws Exception {
public void unpackLibrariesTakePrecedenceOverExistingSourceEntries() throws Exception {
TestJarFile nested = new TestJarFile(this.temporaryFolder);
nested.addClass("a/b/C.class", ClassWithoutMainMethod.class);
final File nestedFile = nested.getFile();
this.testJarFile.addFile("BOOT-INF/lib/" + nestedFile.getName(),
nested.getFile());
this.testJarFile.addFile("BOOT-INF/lib/" + nestedFile.getName(), nested.getFile());
this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
File file = this.testJarFile.getFile();
Repackager repackager = new Repackager(file);
@@ -514,9 +490,7 @@ public class RepackagerTests {
});
JarFile jarFile = new JarFile(file);
try {
assertThat(
jarFile.getEntry("BOOT-INF/lib/" + nestedFile.getName()).getComment())
.startsWith("UNPACK:");
assertThat(jarFile.getEntry("BOOT-INF/lib/" + nestedFile.getName()).getComment()).startsWith("UNPACK:");
}
finally {
jarFile.close();
@@ -524,13 +498,11 @@ public class RepackagerTests {
}
@Test
public void existingSourceEntriesTakePrecedenceOverStandardLibraries()
throws Exception {
public void existingSourceEntriesTakePrecedenceOverStandardLibraries() throws Exception {
TestJarFile nested = new TestJarFile(this.temporaryFolder);
nested.addClass("a/b/C.class", ClassWithoutMainMethod.class);
final File nestedFile = nested.getFile();
this.testJarFile.addFile("BOOT-INF/lib/" + nestedFile.getName(),
nested.getFile());
this.testJarFile.addFile("BOOT-INF/lib/" + nestedFile.getName(), nested.getFile());
this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
File file = this.testJarFile.getFile();
Repackager repackager = new Repackager(file);
@@ -548,8 +520,7 @@ public class RepackagerTests {
});
JarFile jarFile = new JarFile(file);
try {
assertThat(jarFile.getEntry("BOOT-INF/lib/" + nestedFile.getName()).getSize())
.isEqualTo(sourceLength);
assertThat(jarFile.getEntry("BOOT-INF/lib/" + nestedFile.getName()).getSize()).isEqualTo(sourceLength);
}
finally {
jarFile.close();
@@ -559,8 +530,7 @@ public class RepackagerTests {
@Test
public void metaInfIndexListIsRemovedFromRepackagedJar() throws Exception {
this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
this.testJarFile.addFile("META-INF/INDEX.LIST",
this.temporaryFolder.newFile("INDEX.LIST"));
this.testJarFile.addFile("META-INF/INDEX.LIST", this.temporaryFolder.newFile("INDEX.LIST"));
File source = this.testJarFile.getFile();
File dest = this.temporaryFolder.newFile("dest.jar");
Repackager repackager = new Repackager(source);
@@ -598,11 +568,9 @@ public class RepackagerTests {
}
@Test
public void metaInfAopXmlIsMovedBeneathBootInfClassesWhenRepackaged()
throws Exception {
public void metaInfAopXmlIsMovedBeneathBootInfClassesWhenRepackaged() throws Exception {
this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
this.testJarFile.addFile("META-INF/aop.xml",
this.temporaryFolder.newFile("aop.xml"));
this.testJarFile.addFile("META-INF/aop.xml", this.temporaryFolder.newFile("aop.xml"));
File source = this.testJarFile.getFile();
File dest = this.temporaryFolder.newFile("dest.jar");
Repackager repackager = new Repackager(source);
@@ -618,8 +586,7 @@ public class RepackagerTests {
}
@Test
public void jarThatUsesCustomCompressionConfigurationCanBeRepackaged()
throws IOException {
public void jarThatUsesCustomCompressionConfigurationCanBeRepackaged() throws IOException {
File source = this.temporaryFolder.newFile("source.jar");
ZipOutputStream output = new ZipOutputStream(new FileOutputStream(source)) {
{

View File

@@ -50,12 +50,11 @@ public class TestJarFile {
addClass(filename, classToCopy, null);
}
public void addClass(String filename, Class<?> classToCopy, Long time)
throws IOException {
public void addClass(String filename, Class<?> classToCopy, Long time) throws IOException {
File file = getFilePath(filename);
file.getParentFile().mkdirs();
InputStream inputStream = getClass().getResourceAsStream(
"/" + classToCopy.getName().replace('.', '/') + ".class");
InputStream inputStream = getClass()
.getResourceAsStream("/" + classToCopy.getName().replace('.', '/') + ".class");
copyToFile(inputStream, file);
if (time != null) {
file.setLastModified(time);
@@ -95,8 +94,7 @@ public class TestJarFile {
return file;
}
private void copyToFile(InputStream inputStream, File file)
throws FileNotFoundException, IOException {
private void copyToFile(InputStream inputStream, File file) throws FileNotFoundException, IOException {
OutputStream outputStream = new FileOutputStream(file);
try {
copy(inputStream, outputStream);

View File

@@ -33,12 +33,10 @@ import static org.assertj.core.api.Assertions.assertThat;
public class ZipHeaderPeekInputStreamTests {
@Test
public void hasZipHeaderReturnsTrueWhenStreamStartsWithZipHeader()
throws IOException {
public void hasZipHeaderReturnsTrueWhenStreamStartsWithZipHeader() throws IOException {
ZipHeaderPeekInputStream in = null;
try {
in = new ZipHeaderPeekInputStream(new ByteArrayInputStream(
new byte[] { 0x50, 0x4b, 0x03, 0x04, 5, 6 }));
in = new ZipHeaderPeekInputStream(new ByteArrayInputStream(new byte[] { 0x50, 0x4b, 0x03, 0x04, 5, 6 }));
assertThat(in.hasZipHeader()).isTrue();
}
finally {
@@ -49,12 +47,10 @@ public class ZipHeaderPeekInputStreamTests {
}
@Test
public void hasZipHeaderReturnsFalseWheStreamDoesNotStartWithZipHeader()
throws IOException {
public void hasZipHeaderReturnsFalseWheStreamDoesNotStartWithZipHeader() throws IOException {
ZipHeaderPeekInputStream in = null;
try {
in = new ZipHeaderPeekInputStream(
new ByteArrayInputStream(new byte[] { 0, 1, 2, 3, 4, 5 }));
in = new ZipHeaderPeekInputStream(new ByteArrayInputStream(new byte[] { 0, 1, 2, 3, 4, 5 }));
assertThat(in.hasZipHeader()).isFalse();
}
finally {
@@ -68,8 +64,7 @@ public class ZipHeaderPeekInputStreamTests {
public void readIndividualBytes() throws IOException {
ZipHeaderPeekInputStream in = null;
try {
in = new ZipHeaderPeekInputStream(
new ByteArrayInputStream(new byte[] { 0, 1, 2, 3, 4, 5 }));
in = new ZipHeaderPeekInputStream(new ByteArrayInputStream(new byte[] { 0, 1, 2, 3, 4, 5 }));
assertThat(in.read()).isEqualTo(0);
assertThat(in.read()).isEqualTo(1);
assertThat(in.read()).isEqualTo(2);
@@ -88,8 +83,7 @@ public class ZipHeaderPeekInputStreamTests {
public void readMultipleBytes() throws IOException {
ZipHeaderPeekInputStream in = null;
try {
in = new ZipHeaderPeekInputStream(
new ByteArrayInputStream(new byte[] { 0, 1, 2, 3, 4, 5 }));
in = new ZipHeaderPeekInputStream(new ByteArrayInputStream(new byte[] { 0, 1, 2, 3, 4, 5 }));
byte[] bytes = new byte[3];
assertThat(in.read(bytes)).isEqualTo(3);
assertThat(bytes).containsExactly(0, 1, 2);
@@ -108,8 +102,7 @@ public class ZipHeaderPeekInputStreamTests {
public void readingMoreThanEntireStreamReadsToEndOfStream() throws IOException {
ZipHeaderPeekInputStream in = null;
try {
in = new ZipHeaderPeekInputStream(
new ByteArrayInputStream(new byte[] { 0, 1, 2, 3, 4, 5 }));
in = new ZipHeaderPeekInputStream(new ByteArrayInputStream(new byte[] { 0, 1, 2, 3, 4, 5 }));
byte[] bytes = new byte[8];
assertThat(in.read(bytes)).isEqualTo(6);
assertThat(bytes).containsExactly(0, 1, 2, 3, 4, 5, 0, 0);
@@ -123,12 +116,10 @@ public class ZipHeaderPeekInputStreamTests {
}
@Test
public void readOfSomeOfTheHeaderThenMoreThanEntireStreamReadsToEndOfStream()
throws IOException {
public void readOfSomeOfTheHeaderThenMoreThanEntireStreamReadsToEndOfStream() throws IOException {
ZipHeaderPeekInputStream in = null;
try {
in = new ZipHeaderPeekInputStream(
new ByteArrayInputStream(new byte[] { 0, 1, 2, 3, 4, 5 }));
in = new ZipHeaderPeekInputStream(new ByteArrayInputStream(new byte[] { 0, 1, 2, 3, 4, 5 }));
byte[] bytes = new byte[8];
assertThat(in.read(bytes, 0, 3)).isEqualTo(3);
assertThat(bytes).containsExactly(0, 1, 2, 0, 0, 0, 0, 0);
@@ -143,12 +134,10 @@ public class ZipHeaderPeekInputStreamTests {
}
@Test
public void readMoreThanEntireStreamWhenStreamLengthIsLessThanZipHeaderLength()
throws IOException {
public void readMoreThanEntireStreamWhenStreamLengthIsLessThanZipHeaderLength() throws IOException {
ZipHeaderPeekInputStream in = null;
try {
in = new ZipHeaderPeekInputStream(
new ByteArrayInputStream(new byte[] { 10 }));
in = new ZipHeaderPeekInputStream(new ByteArrayInputStream(new byte[] { 10 }));
byte[] bytes = new byte[8];
assertThat(in.read(bytes)).isEqualTo(1);
assertThat(bytes).containsExactly(10, 0, 0, 0, 0, 0, 0, 0);
@@ -161,12 +150,10 @@ public class ZipHeaderPeekInputStreamTests {
}
@Test
public void readMoreThanEntireStreamWhenStreamLengthIsSameAsHeaderLength()
throws IOException {
public void readMoreThanEntireStreamWhenStreamLengthIsSameAsHeaderLength() throws IOException {
ZipHeaderPeekInputStream in = null;
try {
in = new ZipHeaderPeekInputStream(
new ByteArrayInputStream(new byte[] { 1, 2, 3, 4 }));
in = new ZipHeaderPeekInputStream(new ByteArrayInputStream(new byte[] { 1, 2, 3, 4 }));
byte[] bytes = new byte[8];
assertThat(in.read(bytes)).isEqualTo(4);
assertThat(bytes).containsExactly(1, 2, 3, 4, 0, 0, 0, 0);