Revert Layout changes
This reverts commits: -974ec92ad6. -537e0c12c2. -500a3df6e9.
This commit is contained in:
@@ -53,6 +53,8 @@ import org.springframework.lang.UsesJava7;
|
||||
*/
|
||||
public class JarWriter {
|
||||
|
||||
private static final String NESTED_LOADER_JAR = "META-INF/loader/spring-boot-loader.jar";
|
||||
|
||||
private static final int BUFFER_SIZE = 32 * 1024;
|
||||
|
||||
private final JarOutputStream jarOutput;
|
||||
@@ -204,20 +206,9 @@ public class JarWriter {
|
||||
/**
|
||||
* Write the required spring-boot-loader classes to the JAR.
|
||||
* @throws IOException if the classes cannot be written
|
||||
* @deprecated us {@link #writeLoaderClasses(String)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public void writeLoaderClasses() throws IOException {
|
||||
writeLoaderClasses(Layouts.DEFAULT_LOADER_JAR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the required spring-boot-loader classes to the JAR.
|
||||
* @param loaderJarPath the path to the loader jar (in the classpath)
|
||||
* @throws IOException if the classes cannot be written
|
||||
*/
|
||||
public void writeLoaderClasses(String loaderJarPath) throws IOException {
|
||||
URL loaderJar = getClass().getClassLoader().getResource(loaderJarPath);
|
||||
URL loaderJar = getClass().getClassLoader().getResource(NESTED_LOADER_JAR);
|
||||
JarInputStream inputStream = new JarInputStream(
|
||||
new BufferedInputStream(loaderJar.openStream()));
|
||||
JarEntry entry;
|
||||
|
||||
@@ -40,25 +40,15 @@ public interface Layout {
|
||||
String getLibraryDestination(String libraryName, LibraryScope scope);
|
||||
|
||||
/**
|
||||
* Returns the location of classes within the archive. Empty if the location is the
|
||||
* root path, otherwise ends with a slash ('/').
|
||||
* Returns the location of classes within the archive.
|
||||
* @return the classes location
|
||||
*/
|
||||
String getClassesLocation();
|
||||
|
||||
/**
|
||||
* Returns if loader classes should be included to make the archive executable. If
|
||||
* true, then {@link #getLoaderJarPath()} should point to a valid jar file that
|
||||
* contains the loader classes.
|
||||
* Returns if loader classes should be included to make the archive executable.
|
||||
* @return if the layout is executable
|
||||
*/
|
||||
boolean isExecutable();
|
||||
|
||||
/**
|
||||
* Returns the path to a nested jar that contains the loader, and which will be
|
||||
* unpacked into the root of the repackaged jar.
|
||||
* @return the path to a nested jar that contains the loader
|
||||
*/
|
||||
String getLoaderJarPath();
|
||||
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2015 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.loader.tools;
|
||||
|
||||
/**
|
||||
* Strategy for creating instances of {@link Layout}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public interface LayoutFactory {
|
||||
|
||||
Layout getLayout();
|
||||
|
||||
String getName();
|
||||
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2015 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.loader.tools;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.core.io.support.SpringFactoriesLoader;
|
||||
|
||||
/**
|
||||
* Archive layout types.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public enum LayoutType {
|
||||
|
||||
/**
|
||||
* Jar Layout.
|
||||
*/
|
||||
JAR(new Layouts.Jar()),
|
||||
|
||||
/**
|
||||
* War Layout.
|
||||
*/
|
||||
WAR(new Layouts.War()),
|
||||
|
||||
/**
|
||||
* Zip Layout.
|
||||
*/
|
||||
ZIP(new Layouts.Expanded()),
|
||||
|
||||
/**
|
||||
* Dir Layout.
|
||||
*/
|
||||
DIR(new Layouts.Expanded()),
|
||||
|
||||
/**
|
||||
* Module Layout.
|
||||
*/
|
||||
MODULE(new Layouts.Module()),
|
||||
|
||||
/**
|
||||
* No Layout.
|
||||
*/
|
||||
NONE(new Layouts.None());
|
||||
|
||||
private static Map<String, Layout> customTypes;
|
||||
|
||||
private final Layout layout;
|
||||
|
||||
public Layout layout() {
|
||||
return this.layout;
|
||||
}
|
||||
|
||||
LayoutType(Layout layout) {
|
||||
this.layout = layout;
|
||||
}
|
||||
|
||||
public static Layout layout(String value) {
|
||||
try {
|
||||
return valueOf(value).layout();
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
if (customTypes == null) {
|
||||
customTypes = new HashMap<String, Layout>();
|
||||
lookupCustomTypes();
|
||||
}
|
||||
Layout layout = customTypes.get(value);
|
||||
if (layout == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Cannot resolve custom layout type: " + value);
|
||||
}
|
||||
return layout;
|
||||
}
|
||||
}
|
||||
|
||||
private static void lookupCustomTypes() {
|
||||
ClassLoader classLoader = LayoutType.class.getClassLoader();
|
||||
List<LayoutFactory> factories = SpringFactoriesLoader
|
||||
.loadFactories(LayoutFactory.class, classLoader);
|
||||
for (LayoutFactory factory : factories) {
|
||||
customTypes.put(factory.getName(), factory.getLayout());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,11 +33,6 @@ import java.util.Set;
|
||||
*/
|
||||
public final class Layouts {
|
||||
|
||||
/**
|
||||
* Default value for {@link Layout#getLoaderJarPath()}.
|
||||
*/
|
||||
public static final String DEFAULT_LOADER_JAR = "META-INF/loader/spring-boot-loader.jar";
|
||||
|
||||
private Layouts() {
|
||||
}
|
||||
|
||||
@@ -92,11 +87,6 @@ public final class Layouts {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLoaderJarPath() {
|
||||
return DEFAULT_LOADER_JAR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,11 +116,6 @@ public final class Layouts {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLoaderJarPath() {
|
||||
return DEFAULT_LOADER_JAR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -169,11 +154,6 @@ public final class Layouts {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLoaderJarPath() {
|
||||
return DEFAULT_LOADER_JAR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -208,11 +188,6 @@ public final class Layouts {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLoaderJarPath() {
|
||||
return DEFAULT_LOADER_JAR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ public class Repackager {
|
||||
}
|
||||
writeNestedLibraries(standardLibraries, seen, writer);
|
||||
if (this.layout.isExecutable()) {
|
||||
writer.writeLoaderClasses(this.layout.getLoaderJarPath());
|
||||
writer.writeLoaderClasses();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2015 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.loader.tools;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class LayoutTypeTests {
|
||||
|
||||
@Test
|
||||
public void standardType() {
|
||||
assertThat(LayoutType.layout("DIR"))
|
||||
.isEqualTo(LayoutType.valueOf("DIR").layout());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customType() {
|
||||
assertThat(LayoutType.layout("CUSTOM")).isNotNull();
|
||||
}
|
||||
|
||||
public static class TestLayoutFactory implements LayoutFactory {
|
||||
|
||||
@Override
|
||||
public Layout getLayout() {
|
||||
return new Layouts.Jar();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "CUSTOM";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
org.springframework.boot.loader.tools.LayoutFactory=\
|
||||
org.springframework.boot.loader.tools.LayoutTypeTests.TestLayoutFactory
|
||||
Reference in New Issue
Block a user