Merge branch '1.2.x'
This commit is contained in:
@@ -95,11 +95,13 @@ public class MetadataCollector {
|
||||
|
||||
private boolean shouldBeMerged(ItemMetadata itemMetadata) {
|
||||
String sourceType = itemMetadata.getSourceType();
|
||||
return (sourceType != null && !deletedInCurrentBuild(sourceType) && !processedInCurrentBuild(sourceType));
|
||||
return (sourceType != null && !deletedInCurrentBuild(sourceType)
|
||||
&& !processedInCurrentBuild(sourceType));
|
||||
}
|
||||
|
||||
private boolean deletedInCurrentBuild(String sourceType) {
|
||||
return this.processingEnvironment.getElementUtils().getTypeElement(sourceType) == null;
|
||||
return this.processingEnvironment.getElementUtils()
|
||||
.getTypeElement(sourceType) == null;
|
||||
}
|
||||
|
||||
private boolean processedInCurrentBuild(String sourceType) {
|
||||
|
||||
@@ -97,21 +97,21 @@ public class MetadataStore {
|
||||
}
|
||||
|
||||
private FileObject getMetadataResource() throws IOException {
|
||||
FileObject resource = this.environment.getFiler().getResource(
|
||||
StandardLocation.CLASS_OUTPUT, "", METADATA_PATH);
|
||||
FileObject resource = this.environment.getFiler()
|
||||
.getResource(StandardLocation.CLASS_OUTPUT, "", METADATA_PATH);
|
||||
return resource;
|
||||
}
|
||||
|
||||
private FileObject createMetadataResource() throws IOException {
|
||||
FileObject resource = this.environment.getFiler().createResource(
|
||||
StandardLocation.CLASS_OUTPUT, "", METADATA_PATH);
|
||||
FileObject resource = this.environment.getFiler()
|
||||
.createResource(StandardLocation.CLASS_OUTPUT, "", METADATA_PATH);
|
||||
return resource;
|
||||
}
|
||||
|
||||
private InputStream getAdditionalMetadataStream() throws IOException {
|
||||
// Most build systems will have copied the file to the class output location
|
||||
FileObject fileObject = this.environment.getFiler().getResource(
|
||||
StandardLocation.CLASS_OUTPUT, "", ADDITIONAL_METADATA_PATH);
|
||||
FileObject fileObject = this.environment.getFiler()
|
||||
.getResource(StandardLocation.CLASS_OUTPUT, "", ADDITIONAL_METADATA_PATH);
|
||||
File file = new File(fileObject.toUri());
|
||||
if (!file.exists()) {
|
||||
// Gradle keeps things separate
|
||||
@@ -123,8 +123,8 @@ public class MetadataStore {
|
||||
file = new File(path);
|
||||
}
|
||||
}
|
||||
return (file.exists() ? new FileInputStream(file) : fileObject.toUri().toURL()
|
||||
.openStream());
|
||||
return (file.exists() ? new FileInputStream(file)
|
||||
: fileObject.toUri().toURL().openStream());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -54,8 +54,8 @@ class TypeElementMembers {
|
||||
}
|
||||
|
||||
private void process(TypeElement element) {
|
||||
for (ExecutableElement method : ElementFilter.methodsIn(element
|
||||
.getEnclosedElements())) {
|
||||
for (ExecutableElement method : ElementFilter
|
||||
.methodsIn(element.getEnclosedElements())) {
|
||||
processMethod(method);
|
||||
}
|
||||
for (VariableElement field : ElementFilter
|
||||
@@ -95,14 +95,14 @@ class TypeElementMembers {
|
||||
}
|
||||
|
||||
private boolean isSetterReturnType(ExecutableElement method) {
|
||||
return (TypeKind.VOID == method.getReturnType().getKind() || this.env
|
||||
.getTypeUtils().isSameType(method.getEnclosingElement().asType(),
|
||||
method.getReturnType()));
|
||||
return (TypeKind.VOID == method.getReturnType().getKind()
|
||||
|| this.env.getTypeUtils().isSameType(
|
||||
method.getEnclosingElement().asType(), method.getReturnType()));
|
||||
}
|
||||
|
||||
private String getAccessorName(String methodName) {
|
||||
String name = methodName.startsWith("is") ? methodName.substring(2) : methodName
|
||||
.substring(3);
|
||||
String name = methodName.startsWith("is") ? methodName.substring(2)
|
||||
: methodName.substring(3);
|
||||
name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ import javax.lang.model.util.Types;
|
||||
class TypeUtils {
|
||||
|
||||
private static final Map<TypeKind, Class<?>> PRIMITIVE_WRAPPERS;
|
||||
|
||||
static {
|
||||
Map<TypeKind, Class<?>> wrappers = new HashMap<TypeKind, Class<?>>();
|
||||
wrappers.put(TypeKind.BOOLEAN, Boolean.class);
|
||||
@@ -63,8 +64,9 @@ class TypeUtils {
|
||||
this.env = env;
|
||||
Types types = env.getTypeUtils();
|
||||
WildcardType wc = types.getWildcardType(null, null);
|
||||
this.collectionType = types.getDeclaredType(this.env.getElementUtils()
|
||||
.getTypeElement(Collection.class.getName()), wc);
|
||||
this.collectionType = types.getDeclaredType(
|
||||
this.env.getElementUtils().getTypeElement(Collection.class.getName()),
|
||||
wc);
|
||||
this.mapType = types.getDeclaredType(
|
||||
this.env.getElementUtils().getTypeElement(Map.class.getName()), wc, wc);
|
||||
}
|
||||
@@ -108,8 +110,8 @@ class TypeUtils {
|
||||
}
|
||||
|
||||
public String getJavaDoc(Element element) {
|
||||
String javadoc = (element == null ? null : this.env.getElementUtils()
|
||||
.getDocComment(element));
|
||||
String javadoc = (element == null ? null
|
||||
: this.env.getElementUtils().getDocComment(element));
|
||||
if (javadoc != null) {
|
||||
javadoc = javadoc.trim();
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ public class JavaCompilerFieldValuesParser implements FieldValuesParser {
|
||||
private static class FieldCollector implements TreeVisitor {
|
||||
|
||||
private static final Map<String, Class<?>> WRAPPER_TYPES;
|
||||
|
||||
static {
|
||||
Map<String, Class<?>> types = new HashMap<String, Class<?>>();
|
||||
types.put("boolean", Boolean.class);
|
||||
@@ -76,6 +77,7 @@ public class JavaCompilerFieldValuesParser implements FieldValuesParser {
|
||||
}
|
||||
|
||||
private static final Map<Class<?>, Object> DEFAULT_TYPE_VALUES;
|
||||
|
||||
static {
|
||||
Map<Class<?>, Object> values = new HashMap<Class<?>, Object>();
|
||||
values.put(Boolean.class, false);
|
||||
@@ -87,6 +89,7 @@ public class JavaCompilerFieldValuesParser implements FieldValuesParser {
|
||||
}
|
||||
|
||||
private static final Map<String, Object> WELL_KNOWN_STATIC_FINALS;
|
||||
|
||||
static {
|
||||
Map<String, Object> values = new HashMap<String, Object>();
|
||||
values.put("Boolean.TRUE", true);
|
||||
|
||||
@@ -41,9 +41,11 @@ class Tree extends ReflectionWrapper {
|
||||
}
|
||||
|
||||
public void accept(TreeVisitor visitor) throws Exception {
|
||||
this.acceptMethod.invoke(getInstance(), Proxy.newProxyInstance(getInstance()
|
||||
.getClass().getClassLoader(), new Class<?>[] { this.treeVisitorType },
|
||||
new TreeVisitorInvocationHandler(visitor)), 0);
|
||||
this.acceptMethod.invoke(getInstance(),
|
||||
Proxy.newProxyInstance(getInstance().getClass().getClassLoader(),
|
||||
new Class<?>[] { this.treeVisitorType },
|
||||
new TreeVisitorInvocationHandler(visitor)),
|
||||
0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,7 +61,8 @@ class Tree extends ReflectionWrapper {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
public Object invoke(Object proxy, Method method, Object[] args)
|
||||
throws Throwable {
|
||||
if (method.getName().equals("visitClass")) {
|
||||
if ((Integer) args[1] == 0) {
|
||||
Iterable members = (Iterable) Tree.this.GET_CLASS_TREE_MEMBERS
|
||||
|
||||
@@ -73,9 +73,10 @@ public class TestCompiler {
|
||||
return getTask(javaFileObjects);
|
||||
}
|
||||
|
||||
private TestCompilationTask getTask(Iterable<? extends JavaFileObject> javaFileObjects) {
|
||||
return new TestCompilationTask(this.compiler.getTask(null, this.fileManager,
|
||||
null, null, null, javaFileObjects));
|
||||
private TestCompilationTask getTask(
|
||||
Iterable<? extends JavaFileObject> javaFileObjects) {
|
||||
return new TestCompilationTask(this.compiler.getTask(null, this.fileManager, null,
|
||||
null, null, javaFileObjects));
|
||||
}
|
||||
|
||||
public File getOutputLocation() {
|
||||
|
||||
@@ -35,8 +35,8 @@ import org.springframework.boot.configurationprocessor.metadata.JsonMarshaller;
|
||||
*/
|
||||
@SupportedAnnotationTypes({ "*" })
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_6)
|
||||
public class TestConfigurationMetadataAnnotationProcessor extends
|
||||
ConfigurationMetadataAnnotationProcessor {
|
||||
public class TestConfigurationMetadataAnnotationProcessor
|
||||
extends ConfigurationMetadataAnnotationProcessor {
|
||||
|
||||
static final String CONFIGURATION_PROPERTIES_ANNOTATION = "org.springframework.boot.configurationsample.ConfigurationProperties";
|
||||
|
||||
@@ -74,8 +74,8 @@ public class TestConfigurationMetadataAnnotationProcessor extends
|
||||
File metadataFile = new File(this.outputLocation,
|
||||
"META-INF/spring-configuration-metadata.json");
|
||||
if (metadataFile.isFile()) {
|
||||
this.metadata = new JsonMarshaller().read(new FileInputStream(
|
||||
metadataFile));
|
||||
this.metadata = new JsonMarshaller()
|
||||
.read(new FileInputStream(metadataFile));
|
||||
}
|
||||
else {
|
||||
this.metadata = new ConfigurationMetadata();
|
||||
|
||||
@@ -140,8 +140,8 @@ public class TestProject {
|
||||
File targetFile = getSourceFile(target);
|
||||
String contents = getContents(targetFile);
|
||||
int insertAt = contents.lastIndexOf('}');
|
||||
String additionalSource = FileCopyUtils.copyToString(new InputStreamReader(
|
||||
snippetStream));
|
||||
String additionalSource = FileCopyUtils
|
||||
.copyToString(new InputStreamReader(snippetStream));
|
||||
contents = contents.substring(0, insertAt) + additionalSource
|
||||
+ contents.substring(insertAt);
|
||||
putContents(targetFile, contents);
|
||||
|
||||
@@ -86,8 +86,8 @@ public abstract class AbstractFieldValuesProcessorTests {
|
||||
equalToObject(new Object[] { "FOO", "BAR" }));
|
||||
assertThat(values.get("stringArrayNone"), nullValue());
|
||||
assertThat(values.get("stringEmptyArray"), equalToObject(new Object[0]));
|
||||
assertThat(values.get("stringArrayConst"), equalToObject(new Object[] { "OK",
|
||||
"KO" }));
|
||||
assertThat(values.get("stringArrayConst"),
|
||||
equalToObject(new Object[] { "OK", "KO" }));
|
||||
assertThat(values.get("stringArrayConstElements"),
|
||||
equalToObject(new Object[] { "c" }));
|
||||
assertThat(values.get("integerArray"), equalToObject(new Object[] { 42, 24 }));
|
||||
@@ -98,7 +98,8 @@ public abstract class AbstractFieldValuesProcessorTests {
|
||||
return equalTo(object);
|
||||
}
|
||||
|
||||
@SupportedAnnotationTypes({ "org.springframework.boot.configurationsample.ConfigurationProperties" })
|
||||
@SupportedAnnotationTypes({
|
||||
"org.springframework.boot.configurationsample.ConfigurationProperties" })
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_6)
|
||||
private class TestProcessor extends AbstractProcessor {
|
||||
|
||||
@@ -118,8 +119,8 @@ public abstract class AbstractFieldValuesProcessorTests {
|
||||
for (Element element : roundEnv.getElementsAnnotatedWith(annotation)) {
|
||||
if (element instanceof TypeElement) {
|
||||
try {
|
||||
this.values.putAll(this.processor
|
||||
.getFieldValues((TypeElement) element));
|
||||
this.values.putAll(
|
||||
this.processor.getFieldValues((TypeElement) element));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
|
||||
@@ -28,8 +28,8 @@ import static org.junit.Assume.assumeNoException;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class JavaCompilerFieldValuesProcessorTests extends
|
||||
AbstractFieldValuesProcessorTests {
|
||||
public class JavaCompilerFieldValuesProcessorTests
|
||||
extends AbstractFieldValuesProcessorTests {
|
||||
|
||||
@Override
|
||||
protected FieldValuesParser createProcessor(ProcessingEnvironment env) {
|
||||
|
||||
@@ -40,7 +40,8 @@ public class ConfigurationMetadataTests {
|
||||
|
||||
@Test
|
||||
public void toDashedCaseWordsSeveralUnderScores() {
|
||||
assertThat(toDashedCase("Word___With__underscore"), is("word___with__underscore"));
|
||||
assertThat(toDashedCase("Word___With__underscore"),
|
||||
is("word___with__underscore"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -21,8 +21,8 @@ package org.springframework.boot.configurationsample.simple;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public abstract class HierarchicalPropertiesParent extends
|
||||
HierarchicalPropertiesGrandparent {
|
||||
public abstract class HierarchicalPropertiesParent
|
||||
extends HierarchicalPropertiesGrandparent {
|
||||
|
||||
private String second;
|
||||
|
||||
|
||||
@@ -105,8 +105,8 @@ public abstract class ManagedDependencies implements Dependencies {
|
||||
*/
|
||||
public static ManagedDependencies get(
|
||||
Collection<Dependencies> versionManagedDependencies) {
|
||||
return new ManagedDependencies(new ManagedDependenciesDelegate(
|
||||
versionManagedDependencies)) {
|
||||
return new ManagedDependencies(
|
||||
new ManagedDependenciesDelegate(versionManagedDependencies)) {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -30,10 +30,10 @@ public class ManagedDependenciesDelegateTests {
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
PropertiesFileDependencies root = new PropertiesFileDependencies(getClass()
|
||||
.getResourceAsStream("external.properties"));
|
||||
PropertiesFileDependencies extra = new PropertiesFileDependencies(getClass()
|
||||
.getResourceAsStream("additional-external.properties"));
|
||||
PropertiesFileDependencies root = new PropertiesFileDependencies(
|
||||
getClass().getResourceAsStream("external.properties"));
|
||||
PropertiesFileDependencies extra = new PropertiesFileDependencies(
|
||||
getClass().getResourceAsStream("additional-external.properties"));
|
||||
this.dependencies = new ManagedDependenciesDelegate(root,
|
||||
Collections.<Dependencies> singleton(extra));
|
||||
}
|
||||
|
||||
@@ -64,8 +64,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) {
|
||||
|
||||
@@ -198,8 +198,8 @@ public class JarWriter {
|
||||
*/
|
||||
public void writeLoaderClasses() throws IOException {
|
||||
URL loaderJar = getClass().getClassLoader().getResource(NESTED_LOADER_JAR);
|
||||
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")) {
|
||||
@@ -323,8 +323,8 @@ public class JarWriter {
|
||||
|
||||
@Override
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
int read = (this.headerStream == null ? -1 : this.headerStream.read(b, off,
|
||||
len));
|
||||
int read = (this.headerStream == null ? -1
|
||||
: this.headerStream.read(b, off, len));
|
||||
if (read != -1) {
|
||||
this.headerStream = null;
|
||||
return read;
|
||||
|
||||
@@ -31,8 +31,8 @@ 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();
|
||||
|
||||
@@ -119,6 +119,7 @@ public final class Layouts {
|
||||
public static class War implements Layout {
|
||||
|
||||
private static final Map<LibraryScope, String> SCOPE_DESTINATIONS;
|
||||
|
||||
static {
|
||||
Map<LibraryScope, String> map = new HashMap<LibraryScope, String>();
|
||||
map.put(LibraryScope.COMPILE, "WEB-INF/lib/");
|
||||
|
||||
@@ -114,7 +114,8 @@ public abstract class MainClassFinder {
|
||||
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>();
|
||||
@@ -232,7 +233,8 @@ 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>();
|
||||
|
||||
@@ -132,8 +132,8 @@ public class Repackager {
|
||||
destination = destination.getAbsoluteFile();
|
||||
File workingSource = this.source;
|
||||
if (this.source.equals(destination)) {
|
||||
workingSource = new File(this.source.getParentFile(), this.source.getName()
|
||||
+ ".original");
|
||||
workingSource = new File(this.source.getParentFile(),
|
||||
this.source.getName() + ".original");
|
||||
workingSource.delete();
|
||||
renameFile(this.source, workingSource);
|
||||
}
|
||||
@@ -158,8 +158,8 @@ 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();
|
||||
@@ -208,12 +208,12 @@ public class Repackager {
|
||||
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);
|
||||
}
|
||||
@@ -260,8 +260,8 @@ 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");
|
||||
}
|
||||
@@ -282,8 +282,8 @@ public class Repackager {
|
||||
|
||||
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 + "'");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,8 +36,8 @@ 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;
|
||||
|
||||
@@ -131,8 +131,8 @@ 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
|
||||
|
||||
@@ -91,8 +91,8 @@ 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, equalTo("B"));
|
||||
|
||||
}
|
||||
|
||||
@@ -190,7 +190,8 @@ public class LaunchedURLClassLoader extends URLClassLoader {
|
||||
// manifest
|
||||
if (jarFile.getJarEntryData(path) != null
|
||||
&& jarFile.getManifest() != null) {
|
||||
definePackage(packageName, jarFile.getManifest(), url);
|
||||
definePackage(packageName, jarFile.getManifest(),
|
||||
url);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -149,7 +149,8 @@ public abstract class Launcher {
|
||||
throw new IllegalStateException(
|
||||
"Unable to determine code source archive from " + root);
|
||||
}
|
||||
return (root.isDirectory() ? new ExplodedArchive(root) : new JarFileArchive(root));
|
||||
return (root.isDirectory() ? new ExplodedArchive(root)
|
||||
: new JarFileArchive(root));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -47,8 +47,8 @@ public class MainMethodRunner implements Runnable {
|
||||
.loadClass(this.mainClassName);
|
||||
Method mainMethod = mainClass.getDeclaredMethod("main", String[].class);
|
||||
if (mainMethod == null) {
|
||||
throw new IllegalStateException(this.mainClassName
|
||||
+ " does not have a main method");
|
||||
throw new IllegalStateException(
|
||||
this.mainClassName + " does not have a main method");
|
||||
}
|
||||
mainMethod.invoke(null, new Object[] { this.args });
|
||||
}
|
||||
|
||||
@@ -169,16 +169,17 @@ public class PropertiesLauncher extends Launcher {
|
||||
}
|
||||
|
||||
protected File getHomeDirectory() {
|
||||
return new File(SystemPropertyUtils.resolvePlaceholders(System.getProperty(HOME,
|
||||
"${user.dir}")));
|
||||
return new File(SystemPropertyUtils
|
||||
.resolvePlaceholders(System.getProperty(HOME, "${user.dir}")));
|
||||
}
|
||||
|
||||
private void initializeProperties(File home) throws Exception, IOException {
|
||||
String config = "classpath:"
|
||||
+ SystemPropertyUtils.resolvePlaceholders(SystemPropertyUtils
|
||||
.getProperty(CONFIG_NAME, "application")) + ".properties";
|
||||
config = SystemPropertyUtils.resolvePlaceholders(SystemPropertyUtils.getProperty(
|
||||
CONFIG_LOCATION, config));
|
||||
+ SystemPropertyUtils.resolvePlaceholders(
|
||||
SystemPropertyUtils.getProperty(CONFIG_NAME, "application"))
|
||||
+ ".properties";
|
||||
config = SystemPropertyUtils.resolvePlaceholders(
|
||||
SystemPropertyUtils.getProperty(CONFIG_LOCATION, config));
|
||||
InputStream resource = getResource(config);
|
||||
|
||||
if (resource != null) {
|
||||
@@ -197,8 +198,9 @@ public class PropertiesLauncher extends Launcher {
|
||||
this.properties.put(key, value);
|
||||
}
|
||||
}
|
||||
if (SystemPropertyUtils.resolvePlaceholders(
|
||||
"${" + SET_SYSTEM_PROPERTIES + ":false}").equals("true")) {
|
||||
if (SystemPropertyUtils
|
||||
.resolvePlaceholders("${" + SET_SYSTEM_PROPERTIES + ":false}")
|
||||
.equals("true")) {
|
||||
this.logger.info("Adding resolved properties to System properties");
|
||||
for (Object key : Collections.list(this.properties.propertyNames())) {
|
||||
String value = this.properties.getProperty((String) key);
|
||||
@@ -277,8 +279,8 @@ public class PropertiesLauncher extends Launcher {
|
||||
// Try a URL connection content-length header...
|
||||
URLConnection connection = url.openConnection();
|
||||
try {
|
||||
connection.setUseCaches(connection.getClass().getSimpleName()
|
||||
.startsWith("JNLP"));
|
||||
connection.setUseCaches(
|
||||
connection.getClass().getSimpleName().startsWith("JNLP"));
|
||||
if (connection instanceof HttpURLConnection) {
|
||||
HttpURLConnection httpConnection = (HttpURLConnection) connection;
|
||||
httpConnection.setRequestMethod("HEAD");
|
||||
@@ -305,7 +307,8 @@ public class PropertiesLauncher extends Launcher {
|
||||
path = this.properties.getProperty(PATH);
|
||||
}
|
||||
if (path != null) {
|
||||
this.paths = parsePathsProperty(SystemPropertyUtils.resolvePlaceholders(path));
|
||||
this.paths = parsePathsProperty(
|
||||
SystemPropertyUtils.resolvePlaceholders(path));
|
||||
}
|
||||
this.logger.info("Nested archive paths: " + this.paths);
|
||||
}
|
||||
@@ -343,8 +346,8 @@ public class PropertiesLauncher extends Launcher {
|
||||
protected String getMainClass() throws Exception {
|
||||
String mainClass = getProperty(MAIN, "Start-Class");
|
||||
if (mainClass == null) {
|
||||
throw new IllegalStateException("No '" + MAIN
|
||||
+ "' or 'Start-Class' specified");
|
||||
throw new IllegalStateException(
|
||||
"No '" + MAIN + "' or 'Start-Class' specified");
|
||||
}
|
||||
return mainClass;
|
||||
}
|
||||
@@ -364,8 +367,8 @@ public class PropertiesLauncher extends Launcher {
|
||||
private ClassLoader wrapWithCustomClassLoader(ClassLoader parent,
|
||||
String loaderClassName) throws Exception {
|
||||
|
||||
Class<ClassLoader> loaderClass = (Class<ClassLoader>) Class.forName(
|
||||
loaderClassName, true, parent);
|
||||
Class<ClassLoader> loaderClass = (Class<ClassLoader>) Class
|
||||
.forName(loaderClassName, true, parent);
|
||||
|
||||
try {
|
||||
return loaderClass.getConstructor(ClassLoader.class).newInstance(parent);
|
||||
@@ -403,8 +406,8 @@ public class PropertiesLauncher extends Launcher {
|
||||
}
|
||||
|
||||
if (this.properties.containsKey(propertyKey)) {
|
||||
String value = SystemPropertyUtils.resolvePlaceholders(this.properties
|
||||
.getProperty(propertyKey));
|
||||
String value = SystemPropertyUtils
|
||||
.resolvePlaceholders(this.properties.getProperty(propertyKey));
|
||||
this.logger.fine("Property '" + propertyKey + "' from properties: " + value);
|
||||
return value;
|
||||
}
|
||||
@@ -428,8 +431,8 @@ public class PropertiesLauncher extends Launcher {
|
||||
if (manifest != null) {
|
||||
String value = manifest.getMainAttributes().getValue(manifestKey);
|
||||
if (value != null) {
|
||||
this.logger.fine("Property '" + manifestKey + "' from archive manifest: "
|
||||
+ value);
|
||||
this.logger.fine(
|
||||
"Property '" + manifestKey + "' from archive manifest: " + value);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -465,14 +468,14 @@ public class PropertiesLauncher extends Launcher {
|
||||
}
|
||||
Archive archive = getArchive(file);
|
||||
if (archive != null) {
|
||||
this.logger.info("Adding classpath entries from archive " + archive.getUrl()
|
||||
+ root);
|
||||
this.logger.info(
|
||||
"Adding classpath entries from archive " + archive.getUrl() + root);
|
||||
lib.add(archive);
|
||||
}
|
||||
Archive nested = getNestedArchive(root);
|
||||
if (nested != null) {
|
||||
this.logger.info("Adding classpath entries from nested " + nested.getUrl()
|
||||
+ root);
|
||||
this.logger.info(
|
||||
"Adding classpath entries from nested " + nested.getUrl() + root);
|
||||
lib.add(nested);
|
||||
}
|
||||
return lib;
|
||||
@@ -506,8 +509,8 @@ public class PropertiesLauncher extends Launcher {
|
||||
return new FilteredArchive(this.parent, filter);
|
||||
}
|
||||
|
||||
private void addParentClassLoaderEntries(List<Archive> lib) throws IOException,
|
||||
URISyntaxException {
|
||||
private void addParentClassLoaderEntries(List<Archive> lib)
|
||||
throws IOException, URISyntaxException {
|
||||
ClassLoader parentClassLoader = getClass().getClassLoader();
|
||||
List<Archive> urls = new ArrayList<Archive>();
|
||||
for (URL url : getURLs(parentClassLoader)) {
|
||||
@@ -518,8 +521,8 @@ public class PropertiesLauncher extends Launcher {
|
||||
String name = url.getFile();
|
||||
File dir = new File(name.substring(0, name.length() - 1));
|
||||
if (dir.exists()) {
|
||||
urls.add(new ExplodedArchive(new File(name.substring(0,
|
||||
name.length() - 1)), false));
|
||||
urls.add(new ExplodedArchive(
|
||||
new File(name.substring(0, name.length() - 1)), false));
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -44,8 +44,8 @@ import org.springframework.boot.loader.util.AsciiBytes;
|
||||
*/
|
||||
public class ExplodedArchive extends Archive {
|
||||
|
||||
private static final Set<String> SKIPPED_NAMES = new HashSet<String>(Arrays.asList(
|
||||
".", ".."));
|
||||
private static final Set<String> SKIPPED_NAMES = new HashSet<String>(
|
||||
Arrays.asList(".", ".."));
|
||||
|
||||
private static final AsciiBytes MANIFEST_ENTRY_NAME = new AsciiBytes(
|
||||
"META-INF/MANIFEST.MF");
|
||||
@@ -152,7 +152,8 @@ public class ExplodedArchive extends Archive {
|
||||
|
||||
protected Archive getNestedArchive(Entry entry) throws IOException {
|
||||
File file = ((FileEntry) entry).getFile();
|
||||
return (file.isDirectory() ? new ExplodedArchive(file) : new JarFileArchive(file));
|
||||
return (file.isDirectory() ? new ExplodedArchive(file)
|
||||
: new JarFileArchive(file));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -201,8 +202,8 @@ public class ExplodedArchive extends Archive {
|
||||
|
||||
@Override
|
||||
protected URLConnection openConnection(URL url) throws IOException {
|
||||
String name = url.getPath().substring(
|
||||
ExplodedArchive.this.root.toURI().getPath().length());
|
||||
String name = url.getPath()
|
||||
.substring(ExplodedArchive.this.root.toURI().getPath().length());
|
||||
if (ExplodedArchive.this.entries.containsKey(new AsciiBytes(name))) {
|
||||
return new URL(url.toString()).openConnection();
|
||||
}
|
||||
|
||||
@@ -85,8 +85,8 @@ public class FilteredArchive extends Archive {
|
||||
return this.parent.getFilteredArchive(new EntryRenameFilter() {
|
||||
@Override
|
||||
public AsciiBytes apply(AsciiBytes entryName, Entry entry) {
|
||||
return FilteredArchive.this.filter.matches(entry) ? filter.apply(
|
||||
entryName, entry) : null;
|
||||
return FilteredArchive.this.filter.matches(entry)
|
||||
? filter.apply(entryName, entry) : null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -248,8 +248,9 @@ public class RandomAccessDataFile implements RandomAccessData {
|
||||
try {
|
||||
this.available.acquire();
|
||||
RandomAccessFile file = this.files.poll();
|
||||
return (file == null ? new RandomAccessFile(
|
||||
RandomAccessDataFile.this.file, "r") : file);
|
||||
return (file == null
|
||||
? new RandomAccessFile(RandomAccessDataFile.this.file, "r")
|
||||
: file);
|
||||
}
|
||||
catch (InterruptedException ex) {
|
||||
throw new IOException(ex);
|
||||
|
||||
@@ -82,8 +82,8 @@ class CentralDirectoryEndRecord {
|
||||
return false;
|
||||
}
|
||||
// Total size must be the structure size + comment
|
||||
long commentLength = Bytes.littleEndianValue(this.block, this.offset
|
||||
+ COMMENT_LENGTH_OFFSET, 2);
|
||||
long commentLength = Bytes.littleEndianValue(this.block,
|
||||
this.offset + COMMENT_LENGTH_OFFSET, 2);
|
||||
return this.size == MINIMUM_SIZE + commentLength;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,14 +45,16 @@ public class Handler extends URLStreamHandler {
|
||||
|
||||
private static final String SEPARATOR = "!/";
|
||||
|
||||
private static final String[] FALLBACK_HANDLERS = { "sun.net.www.protocol.jar.Handler" };
|
||||
private static final String[] FALLBACK_HANDLERS = {
|
||||
"sun.net.www.protocol.jar.Handler" };
|
||||
|
||||
private static final Method OPEN_CONNECTION_METHOD;
|
||||
|
||||
static {
|
||||
Method method = null;
|
||||
try {
|
||||
method = URLStreamHandler.class
|
||||
.getDeclaredMethod("openConnection", URL.class);
|
||||
method = URLStreamHandler.class.getDeclaredMethod("openConnection",
|
||||
URL.class);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
// Swallow and ignore
|
||||
@@ -61,6 +63,7 @@ public class Handler extends URLStreamHandler {
|
||||
}
|
||||
|
||||
private static SoftReference<Map<File, JarFile>> rootFileCache;
|
||||
|
||||
static {
|
||||
rootFileCache = new SoftReference<Map<File, JarFile>>(null);
|
||||
}
|
||||
@@ -187,7 +190,8 @@ public class Handler extends URLStreamHandler {
|
||||
* which are then swallowed.
|
||||
* @param useFastConnectionExceptions if fast connection exceptions can be used.
|
||||
*/
|
||||
public static void setUseFastConnectionExceptions(boolean useFastConnectionExceptions) {
|
||||
public static void setUseFastConnectionExceptions(
|
||||
boolean useFastConnectionExceptions) {
|
||||
JarURLConnection.setUseFastExceptions(useFastConnectionExceptions);
|
||||
}
|
||||
|
||||
|
||||
@@ -108,13 +108,13 @@ public final class JarEntryData {
|
||||
// aspectjrt-1.7.4.jar has a different ext bytes length in the
|
||||
// local directory to the central directory. We need to re-read
|
||||
// here to skip them
|
||||
byte[] localHeader = Bytes.get(this.source.getData().getSubsection(
|
||||
this.localHeaderOffset, LOCAL_FILE_HEADER_SIZE));
|
||||
byte[] localHeader = Bytes.get(this.source.getData()
|
||||
.getSubsection(this.localHeaderOffset, LOCAL_FILE_HEADER_SIZE));
|
||||
long nameLength = Bytes.littleEndianValue(localHeader, 26, 2);
|
||||
long extraLength = Bytes.littleEndianValue(localHeader, 28, 2);
|
||||
this.data = this.source.getData().getSubsection(
|
||||
this.localHeaderOffset + LOCAL_FILE_HEADER_SIZE + nameLength
|
||||
+ extraLength, getCompressedSize());
|
||||
this.data = this.source.getData().getSubsection(this.localHeaderOffset
|
||||
+ LOCAL_FILE_HEADER_SIZE + nameLength + extraLength,
|
||||
getCompressedSize());
|
||||
}
|
||||
return this.data;
|
||||
}
|
||||
@@ -155,8 +155,8 @@ public final class JarEntryData {
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode MSDOS Date Time details. See <a
|
||||
* href="http://mindprod.com/jgloss/zip.html">mindprod.com/jgloss/zip.html</a> for
|
||||
* Decode MSDOS Date Time details. See
|
||||
* <a href="http://mindprod.com/jgloss/zip.html">mindprod.com/jgloss/zip.html</a> for
|
||||
* more details of the format.
|
||||
* @param date the date part
|
||||
* @param time the time part
|
||||
|
||||
@@ -124,7 +124,7 @@ public class JarFile extends java.util.jar.JarFile implements Iterable<JarEntryD
|
||||
|
||||
private JarFile(RandomAccessDataFile rootFile, String pathFromRoot,
|
||||
RandomAccessData data, List<JarEntryData> entries, JarEntryFilter... filters)
|
||||
throws IOException {
|
||||
throws IOException {
|
||||
super(rootFile.getFile());
|
||||
this.rootFile = rootFile;
|
||||
this.pathFromRoot = pathFromRoot;
|
||||
@@ -167,7 +167,8 @@ public class JarFile extends java.util.jar.JarFile implements Iterable<JarEntryD
|
||||
for (JarEntryData entry : entries) {
|
||||
AsciiBytes name = entry.getName();
|
||||
for (JarEntryFilter filter : filters) {
|
||||
name = (filter == null || name == null ? name : filter.apply(name, entry));
|
||||
name = (filter == null || name == null ? name
|
||||
: filter.apply(name, entry));
|
||||
}
|
||||
if (name != null) {
|
||||
JarEntryData filteredCopy = entry.createFilteredCopy(this, name);
|
||||
@@ -291,8 +292,8 @@ public class JarFile extends java.util.jar.JarFile implements Iterable<JarEntryD
|
||||
// Fallback to JarInputStream to obtain certificates, not fast but hopefully not
|
||||
// happening that often.
|
||||
try {
|
||||
JarInputStream inputStream = new JarInputStream(getData().getInputStream(
|
||||
ResourceAccess.ONCE));
|
||||
JarInputStream inputStream = new JarInputStream(
|
||||
getData().getInputStream(ResourceAccess.ONCE));
|
||||
try {
|
||||
java.util.jar.JarEntry entry = inputStream.getNextJarEntry();
|
||||
while (entry != null) {
|
||||
@@ -343,8 +344,8 @@ public class JarFile extends java.util.jar.JarFile implements Iterable<JarEntryD
|
||||
return sourceEntry.nestedJar;
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new IOException("Unable to open nested jar file '"
|
||||
+ sourceEntry.getName() + "'", ex);
|
||||
throw new IOException(
|
||||
"Unable to open nested jar file '" + sourceEntry.getName() + "'", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,9 +368,10 @@ public class JarFile extends java.util.jar.JarFile implements Iterable<JarEntryD
|
||||
return null;
|
||||
}
|
||||
};
|
||||
return new JarFile(this.rootFile, this.pathFromRoot + "!/"
|
||||
+ sourceEntry.getName().substring(0, sourceName.length() - 1), this.data,
|
||||
this.entries, filter);
|
||||
return new JarFile(this.rootFile,
|
||||
this.pathFromRoot + "!/"
|
||||
+ sourceEntry.getName().substring(0, sourceName.length() - 1),
|
||||
this.data, this.entries, filter);
|
||||
}
|
||||
|
||||
private JarFile createJarFileFromFileEntry(JarEntryData sourceEntry)
|
||||
@@ -380,8 +382,8 @@ public class JarFile extends java.util.jar.JarFile implements Iterable<JarEntryD
|
||||
+ "jar files must be stored without compression. Please check the "
|
||||
+ "mechanism used to create your executable jar file");
|
||||
}
|
||||
return new JarFile(this.rootFile, this.pathFromRoot + "!/"
|
||||
+ sourceEntry.getName(), sourceEntry.getData());
|
||||
return new JarFile(this.rootFile,
|
||||
this.pathFromRoot + "!/" + sourceEntry.getName(), sourceEntry.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -101,8 +101,8 @@ class JarURLConnection extends java.net.JarURLConnection {
|
||||
@Override
|
||||
public void connect() throws IOException {
|
||||
if (!this.jarEntryName.isEmpty()) {
|
||||
this.jarEntryData = this.jarFile.getJarEntryData(this.jarEntryName
|
||||
.asAsciiBytes());
|
||||
this.jarEntryData = this.jarFile
|
||||
.getJarEntryData(this.jarEntryName.asAsciiBytes());
|
||||
if (this.jarEntryData == null) {
|
||||
throwFileNotFound(this.jarEntryName, this.jarFile);
|
||||
}
|
||||
@@ -115,8 +115,8 @@ class JarURLConnection extends java.net.JarURLConnection {
|
||||
if (Boolean.TRUE.equals(useFastExceptions.get())) {
|
||||
throw FILE_NOT_FOUND_EXCEPTION;
|
||||
}
|
||||
throw new FileNotFoundException("JAR entry " + entry + " not found in "
|
||||
+ jarFile.getName());
|
||||
throw new FileNotFoundException(
|
||||
"JAR entry " + entry + " not found in " + jarFile.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -247,8 +247,8 @@ class JarURLConnection extends java.net.JarURLConnection {
|
||||
int hi = Character.digit(source.charAt(i + 1), 16);
|
||||
int lo = Character.digit(source.charAt(i + 2), 16);
|
||||
if (hi == -1 || lo == -1) {
|
||||
throw new IllegalArgumentException("Invalid encoded sequence \""
|
||||
+ source.substring(i) + "\"");
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid encoded sequence \"" + source.substring(i) + "\"");
|
||||
}
|
||||
return ((char) ((hi << 4) + lo));
|
||||
}
|
||||
|
||||
@@ -101,8 +101,8 @@ public final class AsciiBytes {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < postfix.length; i++) {
|
||||
if (this.bytes[this.offset + (this.length - 1) - i] != postfix.bytes[postfix.offset
|
||||
+ (postfix.length - 1) - i]) {
|
||||
if (this.bytes[this.offset + (this.length - 1)
|
||||
- i] != postfix.bytes[postfix.offset + (postfix.length - 1) - i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,8 +96,8 @@ public abstract class SystemPropertyUtils {
|
||||
while (startIndex != -1) {
|
||||
int endIndex = findPlaceholderEndIndex(buf, startIndex);
|
||||
if (endIndex != -1) {
|
||||
String placeholder = buf.substring(
|
||||
startIndex + PLACEHOLDER_PREFIX.length(), endIndex);
|
||||
String placeholder = buf
|
||||
.substring(startIndex + PLACEHOLDER_PREFIX.length(), endIndex);
|
||||
String originalPlaceholder = placeholder;
|
||||
if (!visitedPlaceholders.add(originalPlaceholder)) {
|
||||
throw new IllegalArgumentException("Circular placeholder reference '"
|
||||
@@ -115,9 +115,10 @@ public abstract class SystemPropertyUtils {
|
||||
if (separatorIndex != -1) {
|
||||
String actualPlaceholder = placeholder.substring(0,
|
||||
separatorIndex);
|
||||
String defaultValue = placeholder.substring(separatorIndex
|
||||
+ VALUE_SEPARATOR.length());
|
||||
propVal = resolvePlaceholder(properties, value, actualPlaceholder);
|
||||
String defaultValue = placeholder
|
||||
.substring(separatorIndex + VALUE_SEPARATOR.length());
|
||||
propVal = resolvePlaceholder(properties, value,
|
||||
actualPlaceholder);
|
||||
if (propVal == null) {
|
||||
propVal = defaultValue;
|
||||
}
|
||||
@@ -135,8 +136,8 @@ public abstract class SystemPropertyUtils {
|
||||
}
|
||||
else {
|
||||
// Proceed with unprocessed value.
|
||||
startIndex = buf.indexOf(PLACEHOLDER_PREFIX, endIndex
|
||||
+ PLACEHOLDER_SUFFIX.length());
|
||||
startIndex = buf.indexOf(PLACEHOLDER_PREFIX,
|
||||
endIndex + PLACEHOLDER_SUFFIX.length());
|
||||
}
|
||||
visitedPlaceholders.remove(originalPlaceholder);
|
||||
}
|
||||
|
||||
@@ -34,38 +34,39 @@ import static org.junit.Assert.assertTrue;
|
||||
public class InputArgumentsJavaAgentDetectorTests {
|
||||
|
||||
@Test
|
||||
public void nonAgentJarsDoNotProduceFalsePositives() throws MalformedURLException,
|
||||
IOException {
|
||||
public void nonAgentJarsDoNotProduceFalsePositives()
|
||||
throws MalformedURLException, IOException {
|
||||
InputArgumentsJavaAgentDetector detector = new InputArgumentsJavaAgentDetector(
|
||||
Arrays.asList("-javaagent:my-agent.jar"));
|
||||
assertFalse(detector.isJavaAgentJar(new File("something-else.jar")
|
||||
.getCanonicalFile().toURI().toURL()));
|
||||
assertFalse(detector.isJavaAgentJar(
|
||||
new File("something-else.jar").getCanonicalFile().toURI().toURL()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleJavaAgent() throws MalformedURLException, IOException {
|
||||
InputArgumentsJavaAgentDetector detector = new InputArgumentsJavaAgentDetector(
|
||||
Arrays.asList("-javaagent:my-agent.jar"));
|
||||
assertTrue(detector.isJavaAgentJar(new File("my-agent.jar").getCanonicalFile()
|
||||
.toURI().toURL()));
|
||||
assertTrue(detector.isJavaAgentJar(
|
||||
new File("my-agent.jar").getCanonicalFile().toURI().toURL()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleJavaAgentWithOptions() throws MalformedURLException, IOException {
|
||||
InputArgumentsJavaAgentDetector detector = new InputArgumentsJavaAgentDetector(
|
||||
Arrays.asList("-javaagent:my-agent.jar=a=alpha,b=bravo"));
|
||||
assertTrue(detector.isJavaAgentJar(new File("my-agent.jar").getCanonicalFile()
|
||||
.toURI().toURL()));
|
||||
assertTrue(detector.isJavaAgentJar(
|
||||
new File("my-agent.jar").getCanonicalFile().toURI().toURL()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleJavaAgents() throws MalformedURLException, IOException {
|
||||
InputArgumentsJavaAgentDetector detector = new InputArgumentsJavaAgentDetector(
|
||||
Arrays.asList("-javaagent:my-agent.jar", "-javaagent:my-other-agent.jar"));
|
||||
assertTrue(detector.isJavaAgentJar(new File("my-agent.jar").getCanonicalFile()
|
||||
.toURI().toURL()));
|
||||
assertTrue(detector.isJavaAgentJar(new File("my-other-agent.jar")
|
||||
.getCanonicalFile().toURI().toURL()));
|
||||
Arrays.asList("-javaagent:my-agent.jar",
|
||||
"-javaagent:my-other-agent.jar"));
|
||||
assertTrue(detector.isJavaAgentJar(
|
||||
new File("my-agent.jar").getCanonicalFile().toURI().toURL()));
|
||||
assertTrue(detector.isJavaAgentJar(
|
||||
new File("my-other-agent.jar").getCanonicalFile().toURI().toURL()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,44 +46,44 @@ public class LaunchedURLClassLoaderTests {
|
||||
public void resolveResourceFromWindowsFilesystem() throws Exception {
|
||||
// This path is invalid - it should return null even on Windows.
|
||||
// A regular URLClassLoader will deal with it gracefully.
|
||||
assertNull(getClass().getClassLoader().getResource(
|
||||
"c:\\Users\\user\\bar.properties"));
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { new URL(
|
||||
"jar:file:src/test/resources/jars/app.jar!/") }, getClass()
|
||||
.getClassLoader());
|
||||
assertNull(getClass().getClassLoader()
|
||||
.getResource("c:\\Users\\user\\bar.properties"));
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") },
|
||||
getClass().getClassLoader());
|
||||
// So we should too...
|
||||
assertNull(loader.getResource("c:\\Users\\user\\bar.properties"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveResourceFromArchive() throws Exception {
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { new URL(
|
||||
"jar:file:src/test/resources/jars/app.jar!/") }, getClass()
|
||||
.getClassLoader());
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") },
|
||||
getClass().getClassLoader());
|
||||
assertNotNull(loader.getResource("demo/Application.java"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveResourcesFromArchive() throws Exception {
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { new URL(
|
||||
"jar:file:src/test/resources/jars/app.jar!/") }, getClass()
|
||||
.getClassLoader());
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") },
|
||||
getClass().getClassLoader());
|
||||
assertTrue(loader.getResources("demo/Application.java").hasMoreElements());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveRootPathFromArchive() throws Exception {
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { new URL(
|
||||
"jar:file:src/test/resources/jars/app.jar!/") }, getClass()
|
||||
.getClassLoader());
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") },
|
||||
getClass().getClassLoader());
|
||||
assertNotNull(loader.getResource(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveRootResourcesFromArchive() throws Exception {
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { new URL(
|
||||
"jar:file:src/test/resources/jars/app.jar!/") }, getClass()
|
||||
.getClassLoader());
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") },
|
||||
getClass().getClassLoader());
|
||||
assertTrue(loader.getResources("").hasMoreElements());
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,8 @@ public class PropertiesLauncherTests {
|
||||
System.setProperty("loader.config.name", "foo");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertEquals("my.Application", launcher.getMainClass());
|
||||
assertEquals("[etc/]", ReflectionTestUtils.getField(launcher, "paths").toString());
|
||||
assertEquals("[etc/]",
|
||||
ReflectionTestUtils.getField(launcher, "paths").toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,8 +96,8 @@ public class PropertiesLauncherTests {
|
||||
System.setProperty("loader.path", "jars/*");
|
||||
System.setProperty("loader.main", "demo.Application");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertEquals("[jars/]", ReflectionTestUtils.getField(launcher, "paths")
|
||||
.toString());
|
||||
assertEquals("[jars/]",
|
||||
ReflectionTestUtils.getField(launcher, "paths").toString());
|
||||
launcher.launch(new String[0]);
|
||||
waitFor("Hello World");
|
||||
}
|
||||
@@ -106,8 +107,8 @@ public class PropertiesLauncherTests {
|
||||
System.setProperty("loader.path", "jars/app.jar");
|
||||
System.setProperty("loader.main", "demo.Application");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertEquals("[jars/app.jar]", ReflectionTestUtils.getField(launcher, "paths")
|
||||
.toString());
|
||||
assertEquals("[jars/app.jar]",
|
||||
ReflectionTestUtils.getField(launcher, "paths").toString());
|
||||
launcher.launch(new String[0]);
|
||||
waitFor("Hello World");
|
||||
}
|
||||
@@ -117,8 +118,8 @@ public class PropertiesLauncherTests {
|
||||
System.setProperty("loader.path", "./jars/app.jar");
|
||||
System.setProperty("loader.main", "demo.Application");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertEquals("[jars/app.jar]", ReflectionTestUtils.getField(launcher, "paths")
|
||||
.toString());
|
||||
assertEquals("[jars/app.jar]",
|
||||
ReflectionTestUtils.getField(launcher, "paths").toString());
|
||||
launcher.launch(new String[0]);
|
||||
waitFor("Hello World");
|
||||
}
|
||||
@@ -128,8 +129,8 @@ public class PropertiesLauncherTests {
|
||||
System.setProperty("loader.path", "jars/app.jar");
|
||||
System.setProperty("loader.classLoader", URLClassLoader.class.getName());
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertEquals("[jars/app.jar]", ReflectionTestUtils.getField(launcher, "paths")
|
||||
.toString());
|
||||
assertEquals("[jars/app.jar]",
|
||||
ReflectionTestUtils.getField(launcher, "paths").toString());
|
||||
launcher.launch(new String[0]);
|
||||
waitFor("Hello World");
|
||||
}
|
||||
|
||||
@@ -65,10 +65,8 @@ public class WarLauncherTests {
|
||||
List<Archive> archives = launcher.getClassPathArchives();
|
||||
assertEquals(2, archives.size());
|
||||
|
||||
assertThat(
|
||||
getUrls(archives),
|
||||
hasItems(webInfClasses.toURI().toURL(), new URL("jar:"
|
||||
+ webInfLibFoo.toURI().toURL() + "!/")));
|
||||
assertThat(getUrls(archives), hasItems(webInfClasses.toURI().toURL(),
|
||||
new URL("jar:" + webInfLibFoo.toURI().toURL() + "!/")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -80,12 +78,10 @@ public class WarLauncherTests {
|
||||
List<Archive> archives = launcher.getClassPathArchives();
|
||||
assertEquals(2, archives.size());
|
||||
|
||||
assertThat(
|
||||
getUrls(archives),
|
||||
hasItems(
|
||||
new URL("jar:" + warRoot.toURI().toURL() + "!/WEB-INF/classes!/"),
|
||||
new URL("jar:" + warRoot.toURI().toURL()
|
||||
+ "!/WEB-INF/lib/foo.jar!/")));
|
||||
assertThat(getUrls(archives),
|
||||
hasItems(new URL("jar:" + warRoot.toURI().toURL()
|
||||
+ "!/WEB-INF/classes!/"),
|
||||
new URL("jar:" + warRoot.toURI().toURL() + "!/WEB-INF/lib/foo.jar!/")));
|
||||
}
|
||||
|
||||
private Set<URL> getUrls(List<Archive> archives) throws MalformedURLException {
|
||||
@@ -100,8 +96,8 @@ public class WarLauncherTests {
|
||||
File warRoot = new File("target/archive.war");
|
||||
warRoot.delete();
|
||||
|
||||
JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(
|
||||
warRoot));
|
||||
JarOutputStream jarOutputStream = new JarOutputStream(
|
||||
new FileOutputStream(warRoot));
|
||||
|
||||
jarOutputStream.putNextEntry(new JarEntry("WEB-INF/"));
|
||||
jarOutputStream.putNextEntry(new JarEntry("WEB-INF/classes/"));
|
||||
|
||||
@@ -69,8 +69,8 @@ public class ExplodedArchiveTests {
|
||||
Enumeration<JarEntry> entries = jarFile.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
JarEntry entry = entries.nextElement();
|
||||
File destination = new File(this.rootFolder.getAbsolutePath()
|
||||
+ File.separator + entry.getName());
|
||||
File destination = new File(
|
||||
this.rootFolder.getAbsolutePath() + File.separator + entry.getName());
|
||||
destination.getParentFile().mkdirs();
|
||||
if (entry.isDirectory()) {
|
||||
destination.mkdir();
|
||||
@@ -115,8 +115,8 @@ public class ExplodedArchiveTests {
|
||||
public void getNestedArchive() throws Exception {
|
||||
Entry entry = getEntriesMap(this.archive).get("nested.jar");
|
||||
Archive nested = this.archive.getNestedArchive(entry);
|
||||
assertThat(nested.getUrl().toString(), equalTo("jar:" + this.rootFolder.toURI()
|
||||
+ "nested.jar!/"));
|
||||
assertThat(nested.getUrl().toString(),
|
||||
equalTo("jar:" + this.rootFolder.toURI() + "nested.jar!/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -125,8 +125,8 @@ public class ExplodedArchiveTests {
|
||||
Archive nested = this.archive.getNestedArchive(entry);
|
||||
Map<String, Entry> nestedEntries = getEntriesMap(nested);
|
||||
assertThat(nestedEntries.size(), equalTo(1));
|
||||
assertThat(nested.getUrl().toString(), equalTo("file:"
|
||||
+ this.rootFolder.toURI().getPath() + "d/"));
|
||||
assertThat(nested.getUrl().toString(),
|
||||
equalTo("file:" + this.rootFolder.toURI().getPath() + "d/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -159,7 +159,8 @@ public class ExplodedArchiveTests {
|
||||
|
||||
@Test
|
||||
public void getNonRecursiveManifest() throws Exception {
|
||||
ExplodedArchive archive = new ExplodedArchive(new File("src/test/resources/root"));
|
||||
ExplodedArchive archive = new ExplodedArchive(
|
||||
new File("src/test/resources/root"));
|
||||
assertNotNull(archive.getManifest());
|
||||
Map<String, Archive.Entry> entries = getEntriesMap(archive);
|
||||
assertThat(entries.size(), equalTo(4));
|
||||
@@ -167,8 +168,8 @@ public class ExplodedArchiveTests {
|
||||
|
||||
@Test
|
||||
public void getNonRecursiveManifestEvenIfNonRecursive() throws Exception {
|
||||
ExplodedArchive archive = new ExplodedArchive(
|
||||
new File("src/test/resources/root"), false);
|
||||
ExplodedArchive archive = new ExplodedArchive(new File("src/test/resources/root"),
|
||||
false);
|
||||
assertNotNull(archive.getManifest());
|
||||
Map<String, Archive.Entry> entries = getEntriesMap(archive);
|
||||
assertThat(entries.size(), equalTo(3));
|
||||
@@ -176,7 +177,8 @@ public class ExplodedArchiveTests {
|
||||
|
||||
@Test
|
||||
public void getResourceAsStream() throws Exception {
|
||||
ExplodedArchive archive = new ExplodedArchive(new File("src/test/resources/root"));
|
||||
ExplodedArchive archive = new ExplodedArchive(
|
||||
new File("src/test/resources/root"));
|
||||
assertNotNull(archive.getManifest());
|
||||
URLClassLoader loader = new URLClassLoader(new URL[] { archive.getUrl() });
|
||||
assertNotNull(loader.getResourceAsStream("META-INF/spring/application.xml"));
|
||||
@@ -185,8 +187,8 @@ public class ExplodedArchiveTests {
|
||||
|
||||
@Test
|
||||
public void getResourceAsStreamNonRecursive() throws Exception {
|
||||
ExplodedArchive archive = new ExplodedArchive(
|
||||
new File("src/test/resources/root"), false);
|
||||
ExplodedArchive archive = new ExplodedArchive(new File("src/test/resources/root"),
|
||||
false);
|
||||
assertNotNull(archive.getManifest());
|
||||
URLClassLoader loader = new URLClassLoader(new URL[] { archive.getUrl() });
|
||||
assertNotNull(loader.getResourceAsStream("META-INF/spring/application.xml"));
|
||||
|
||||
@@ -85,8 +85,8 @@ public class JarFileArchiveTests {
|
||||
public void getNestedArchive() throws Exception {
|
||||
Entry entry = getEntriesMap(this.archive).get("nested.jar");
|
||||
Archive nested = this.archive.getNestedArchive(entry);
|
||||
assertThat(nested.getUrl().toString(), equalTo("jar:" + this.rootJarFileUrl
|
||||
+ "!/nested.jar!/"));
|
||||
assertThat(nested.getUrl().toString(),
|
||||
equalTo("jar:" + this.rootJarFileUrl + "!/nested.jar!/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -34,8 +34,8 @@ public class ByteArrayRandomAccessDataTests {
|
||||
public void testGetInputStream() throws Exception {
|
||||
byte[] bytes = new byte[] { 0, 1, 2, 3, 4, 5 };
|
||||
RandomAccessData data = new ByteArrayRandomAccessData(bytes);
|
||||
assertThat(FileCopyUtils.copyToByteArray(data
|
||||
.getInputStream(ResourceAccess.PER_READ)), equalTo(bytes));
|
||||
assertThat(FileCopyUtils.copyToByteArray(
|
||||
data.getInputStream(ResourceAccess.PER_READ)), equalTo(bytes));
|
||||
assertThat(data.getSize(), equalTo((long) bytes.length));
|
||||
}
|
||||
|
||||
@@ -44,8 +44,10 @@ public class ByteArrayRandomAccessDataTests {
|
||||
byte[] bytes = new byte[] { 0, 1, 2, 3, 4, 5 };
|
||||
RandomAccessData data = new ByteArrayRandomAccessData(bytes);
|
||||
data = data.getSubsection(1, 4).getSubsection(1, 2);
|
||||
assertThat(FileCopyUtils.copyToByteArray(data
|
||||
.getInputStream(ResourceAccess.PER_READ)), equalTo(new byte[] { 2, 3 }));
|
||||
assertThat(
|
||||
FileCopyUtils
|
||||
.copyToByteArray(data.getInputStream(ResourceAccess.PER_READ)),
|
||||
equalTo(new byte[] { 2, 3 }));
|
||||
assertThat(data.getSize(), equalTo(2L));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ import static org.junit.Assert.assertThat;
|
||||
public class RandomAccessDataFileTests {
|
||||
|
||||
private static final byte[] BYTES;
|
||||
|
||||
static {
|
||||
BYTES = new byte[256];
|
||||
for (int i = 0; i < BYTES.length; i++) {
|
||||
@@ -212,7 +213,8 @@ public class RandomAccessDataFileTests {
|
||||
@Test
|
||||
public void subsectionZeroLength() throws Exception {
|
||||
RandomAccessData subsection = this.file.getSubsection(0, 0);
|
||||
assertThat(subsection.getInputStream(ResourceAccess.PER_READ).read(), equalTo(-1));
|
||||
assertThat(subsection.getInputStream(ResourceAccess.PER_READ).read(),
|
||||
equalTo(-1));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -152,8 +152,8 @@ public class JarFileTests {
|
||||
|
||||
@Test
|
||||
public void getInputStream() throws Exception {
|
||||
InputStream inputStream = this.jarFile.getInputStream(this.jarFile
|
||||
.getEntry("1.dat"));
|
||||
InputStream inputStream = this.jarFile
|
||||
.getInputStream(this.jarFile.getEntry("1.dat"));
|
||||
assertThat(inputStream.available(), equalTo(1));
|
||||
assertThat(inputStream.read(), equalTo(1));
|
||||
assertThat(inputStream.available(), equalTo(0));
|
||||
@@ -180,8 +180,8 @@ public class JarFileTests {
|
||||
|
||||
@Test
|
||||
public void close() throws Exception {
|
||||
RandomAccessDataFile randomAccessDataFile = spy(new RandomAccessDataFile(
|
||||
this.rootJarFile, 1));
|
||||
RandomAccessDataFile randomAccessDataFile = spy(
|
||||
new RandomAccessDataFile(this.rootJarFile, 1));
|
||||
JarFile jarFile = new JarFile(randomAccessDataFile);
|
||||
jarFile.close();
|
||||
verify(randomAccessDataFile).close();
|
||||
@@ -204,7 +204,8 @@ public class JarFileTests {
|
||||
@Test
|
||||
public void createEntryUrl() throws Exception {
|
||||
URL url = new URL(this.jarFile.getUrl(), "1.dat");
|
||||
assertThat(url.toString(), equalTo("jar:" + this.rootJarFile.toURI() + "!/1.dat"));
|
||||
assertThat(url.toString(),
|
||||
equalTo("jar:" + this.rootJarFile.toURI() + "!/1.dat"));
|
||||
JarURLConnection jarURLConnection = (JarURLConnection) url.openConnection();
|
||||
assertThat(jarURLConnection.getJarFile(), sameInstance(this.jarFile));
|
||||
assertThat(jarURLConnection.getJarEntry(),
|
||||
@@ -217,8 +218,8 @@ public class JarFileTests {
|
||||
@Test
|
||||
public void getMissingEntryUrl() throws Exception {
|
||||
URL url = new URL(this.jarFile.getUrl(), "missing.dat");
|
||||
assertThat(url.toString(), equalTo("jar:" + this.rootJarFile.toURI()
|
||||
+ "!/missing.dat"));
|
||||
assertThat(url.toString(),
|
||||
equalTo("jar:" + this.rootJarFile.toURI() + "!/missing.dat"));
|
||||
this.thrown.expect(FileNotFoundException.class);
|
||||
((JarURLConnection) url.openConnection()).getJarEntry();
|
||||
}
|
||||
@@ -242,8 +243,8 @@ public class JarFileTests {
|
||||
|
||||
@Test
|
||||
public void getNestedJarFile() throws Exception {
|
||||
JarFile nestedJarFile = this.jarFile.getNestedJarFile(this.jarFile
|
||||
.getEntry("nested.jar"));
|
||||
JarFile nestedJarFile = this.jarFile
|
||||
.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
|
||||
Enumeration<java.util.jar.JarEntry> entries = nestedJarFile.entries();
|
||||
assertThat(entries.nextElement().getName(), equalTo("META-INF/"));
|
||||
@@ -253,14 +254,14 @@ public class JarFileTests {
|
||||
assertThat(entries.nextElement().getName(), equalTo("\u00E4.dat"));
|
||||
assertThat(entries.hasMoreElements(), equalTo(false));
|
||||
|
||||
InputStream inputStream = nestedJarFile.getInputStream(nestedJarFile
|
||||
.getEntry("3.dat"));
|
||||
InputStream inputStream = nestedJarFile
|
||||
.getInputStream(nestedJarFile.getEntry("3.dat"));
|
||||
assertThat(inputStream.read(), equalTo(3));
|
||||
assertThat(inputStream.read(), equalTo(-1));
|
||||
|
||||
URL url = nestedJarFile.getUrl();
|
||||
assertThat(url.toString(), equalTo("jar:" + this.rootJarFile.toURI()
|
||||
+ "!/nested.jar!/"));
|
||||
assertThat(url.toString(),
|
||||
equalTo("jar:" + this.rootJarFile.toURI() + "!/nested.jar!/"));
|
||||
JarURLConnection conn = (JarURLConnection) url.openConnection();
|
||||
assertThat(conn.getJarFile(), sameInstance(nestedJarFile));
|
||||
assertThat(conn.getJarFileURL().toString(),
|
||||
@@ -276,8 +277,8 @@ public class JarFileTests {
|
||||
assertThat(entries.nextElement().getName(), equalTo("9.dat"));
|
||||
assertThat(entries.hasMoreElements(), equalTo(false));
|
||||
|
||||
InputStream inputStream = nestedJarFile.getInputStream(nestedJarFile
|
||||
.getEntry("9.dat"));
|
||||
InputStream inputStream = nestedJarFile
|
||||
.getInputStream(nestedJarFile.getEntry("9.dat"));
|
||||
assertThat(inputStream.read(), equalTo(9));
|
||||
assertThat(inputStream.read(), equalTo(-1));
|
||||
|
||||
@@ -289,11 +290,11 @@ public class JarFileTests {
|
||||
|
||||
@Test
|
||||
public void getNestJarEntryUrl() throws Exception {
|
||||
JarFile nestedJarFile = this.jarFile.getNestedJarFile(this.jarFile
|
||||
.getEntry("nested.jar"));
|
||||
JarFile nestedJarFile = this.jarFile
|
||||
.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
URL url = nestedJarFile.getJarEntry("3.dat").getUrl();
|
||||
assertThat(url.toString(), equalTo("jar:" + this.rootJarFile.toURI()
|
||||
+ "!/nested.jar!/3.dat"));
|
||||
assertThat(url.toString(),
|
||||
equalTo("jar:" + this.rootJarFile.toURI() + "!/nested.jar!/3.dat"));
|
||||
InputStream inputStream = url.openStream();
|
||||
assertThat(inputStream, notNullValue());
|
||||
assertThat(inputStream.read(), equalTo(3));
|
||||
@@ -310,8 +311,8 @@ public class JarFileTests {
|
||||
assertThat(inputStream.read(), equalTo(3));
|
||||
JarURLConnection connection = (JarURLConnection) url.openConnection();
|
||||
assertThat(connection.getURL().toString(), equalTo(spec));
|
||||
assertThat(connection.getJarFileURL().toString(), equalTo("jar:"
|
||||
+ this.rootJarFile.toURI() + "!/nested.jar"));
|
||||
assertThat(connection.getJarFileURL().toString(),
|
||||
equalTo("jar:" + this.rootJarFile.toURI() + "!/nested.jar"));
|
||||
assertThat(connection.getEntryName(), equalTo("3.dat"));
|
||||
}
|
||||
|
||||
@@ -360,8 +361,8 @@ public class JarFileTests {
|
||||
assertThat(entries.nextElement().getName(), equalTo("x.dat"));
|
||||
assertThat(entries.hasMoreElements(), equalTo(false));
|
||||
|
||||
InputStream inputStream = filteredJarFile.getInputStream(filteredJarFile
|
||||
.getEntry("x.dat"));
|
||||
InputStream inputStream = filteredJarFile
|
||||
.getInputStream(filteredJarFile.getEntry("x.dat"));
|
||||
assertThat(inputStream.read(), equalTo(1));
|
||||
assertThat(inputStream.read(), equalTo(-1));
|
||||
}
|
||||
@@ -369,8 +370,10 @@ public class JarFileTests {
|
||||
@Test
|
||||
public void sensibleToString() throws Exception {
|
||||
assertThat(this.jarFile.toString(), equalTo(this.rootJarFile.getPath()));
|
||||
assertThat(this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"))
|
||||
.toString(), equalTo(this.rootJarFile.getPath() + "!/nested.jar"));
|
||||
assertThat(
|
||||
this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"))
|
||||
.toString(),
|
||||
equalTo(this.rootJarFile.getPath() + "!/nested.jar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -418,8 +421,8 @@ public class JarFileTests {
|
||||
@Test
|
||||
public void cannotLoadMissingJar() throws Exception {
|
||||
// relates to gh-1070
|
||||
JarFile nestedJarFile = this.jarFile.getNestedJarFile(this.jarFile
|
||||
.getEntry("nested.jar"));
|
||||
JarFile nestedJarFile = this.jarFile
|
||||
.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
URL nestedUrl = nestedJarFile.getUrl();
|
||||
URL url = new URL(nestedUrl, nestedJarFile.getUrl() + "missing.jar!/3.dat");
|
||||
this.thrown.expect(FileNotFoundException.class);
|
||||
|
||||
@@ -49,7 +49,8 @@ public class SystemPropertyUtilsTests {
|
||||
|
||||
@Test
|
||||
public void testNestedPlaceholder() {
|
||||
assertEquals("foo", SystemPropertyUtils.resolvePlaceholders("${bar:${spam:foo}}"));
|
||||
assertEquals("foo",
|
||||
SystemPropertyUtils.resolvePlaceholders("${bar:${spam:foo}}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -107,10 +107,10 @@ public abstract class AbstractDependencyFilterMojo extends AbstractMojo {
|
||||
for (ArtifactsFilter additionalFilter : additionalFilters) {
|
||||
filters.addFilter(additionalFilter);
|
||||
}
|
||||
filters.addFilter(new ArtifactIdFilter("",
|
||||
cleanFilterConfig(this.excludeArtifactIds)));
|
||||
filters.addFilter(new MatchingGroupIdFilter(
|
||||
cleanFilterConfig(this.excludeGroupIds)));
|
||||
filters.addFilter(
|
||||
new ArtifactIdFilter("", cleanFilterConfig(this.excludeArtifactIds)));
|
||||
filters.addFilter(
|
||||
new MatchingGroupIdFilter(cleanFilterConfig(this.excludeGroupIds)));
|
||||
if (this.includes != null && !this.includes.isEmpty()) {
|
||||
filters.addFilter(new IncludeFilter(this.includes));
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ import org.springframework.boot.loader.tools.LibraryScope;
|
||||
public class ArtifactsLibraries implements Libraries {
|
||||
|
||||
private static final Map<String, LibraryScope> SCOPES;
|
||||
|
||||
static {
|
||||
Map<String, LibraryScope> scopes = new HashMap<String, LibraryScope>();
|
||||
scopes.put(Artifact.SCOPE_COMPILE, LibraryScope.COMPILE);
|
||||
|
||||
@@ -66,8 +66,8 @@ public class PropertiesMergingResourceTransformer implements ResourceTransformer
|
||||
String name = (String) key;
|
||||
String value = properties.getProperty(name);
|
||||
String existing = this.data.getProperty(name);
|
||||
this.data
|
||||
.setProperty(name, existing == null ? value : existing + "," + value);
|
||||
this.data.setProperty(name,
|
||||
existing == null ? value : existing + "," + value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,8 +58,8 @@ class RunArguments {
|
||||
return CommandLineUtils.translateCommandline(arguments);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalArgumentException("Failed to parse arguments [" + arguments
|
||||
+ "]", ex);
|
||||
throw new IllegalArgumentException(
|
||||
"Failed to parse arguments [" + arguments + "]", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,17 +41,17 @@ public class ExcludeFilterTests {
|
||||
|
||||
@Test
|
||||
public void excludeSimple() throws ArtifactFilterException {
|
||||
ExcludeFilter filter = new ExcludeFilter(Arrays.asList(createExclude("com.foo",
|
||||
"bar")));
|
||||
Set result = filter.filter(Collections
|
||||
.singleton(createArtifact("com.foo", "bar")));
|
||||
ExcludeFilter filter = new ExcludeFilter(
|
||||
Arrays.asList(createExclude("com.foo", "bar")));
|
||||
Set result = filter
|
||||
.filter(Collections.singleton(createArtifact("com.foo", "bar")));
|
||||
assertEquals("Should have been filtered", 0, result.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void excludeGroupIdNoMatch() throws ArtifactFilterException {
|
||||
ExcludeFilter filter = new ExcludeFilter(Arrays.asList(createExclude("com.foo",
|
||||
"bar")));
|
||||
ExcludeFilter filter = new ExcludeFilter(
|
||||
Arrays.asList(createExclude("com.foo", "bar")));
|
||||
Artifact artifact = createArtifact("com.baz", "bar");
|
||||
Set result = filter.filter(Collections.singleton(artifact));
|
||||
assertEquals("Should not have been filtered", 1, result.size());
|
||||
@@ -60,8 +60,8 @@ public class ExcludeFilterTests {
|
||||
|
||||
@Test
|
||||
public void excludeArtifactIdNoMatch() throws ArtifactFilterException {
|
||||
ExcludeFilter filter = new ExcludeFilter(Arrays.asList(createExclude("com.foo",
|
||||
"bar")));
|
||||
ExcludeFilter filter = new ExcludeFilter(
|
||||
Arrays.asList(createExclude("com.foo", "bar")));
|
||||
Artifact artifact = createArtifact("com.foo", "biz");
|
||||
Set result = filter.filter(Collections.singleton(artifact));
|
||||
assertEquals("Should not have been filtered", 1, result.size());
|
||||
@@ -70,17 +70,17 @@ public class ExcludeFilterTests {
|
||||
|
||||
@Test
|
||||
public void excludeClassifier() throws ArtifactFilterException {
|
||||
ExcludeFilter filter = new ExcludeFilter(Arrays.asList(createExclude("com.foo",
|
||||
"bar", "jdk5")));
|
||||
Set result = filter.filter(Collections.singleton(createArtifact("com.foo", "bar",
|
||||
"jdk5")));
|
||||
ExcludeFilter filter = new ExcludeFilter(
|
||||
Arrays.asList(createExclude("com.foo", "bar", "jdk5")));
|
||||
Set result = filter
|
||||
.filter(Collections.singleton(createArtifact("com.foo", "bar", "jdk5")));
|
||||
assertEquals("Should have been filtered", 0, result.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void excludeClassifierNoTargetClassifier() throws ArtifactFilterException {
|
||||
ExcludeFilter filter = new ExcludeFilter(Arrays.asList(createExclude("com.foo",
|
||||
"bar", "jdk5")));
|
||||
ExcludeFilter filter = new ExcludeFilter(
|
||||
Arrays.asList(createExclude("com.foo", "bar", "jdk5")));
|
||||
Artifact artifact = createArtifact("com.foo", "bar");
|
||||
Set result = filter.filter(Collections.singleton(artifact));
|
||||
assertEquals("Should not have been filtered", 1, result.size());
|
||||
@@ -89,8 +89,8 @@ public class ExcludeFilterTests {
|
||||
|
||||
@Test
|
||||
public void excludeClassifierNoMatch() throws ArtifactFilterException {
|
||||
ExcludeFilter filter = new ExcludeFilter(Arrays.asList(createExclude("com.foo",
|
||||
"bar", "jdk5")));
|
||||
ExcludeFilter filter = new ExcludeFilter(
|
||||
Arrays.asList(createExclude("com.foo", "bar", "jdk5")));
|
||||
Artifact artifact = createArtifact("com.foo", "bar", "jdk6");
|
||||
Set result = filter.filter(Collections.singleton(artifact));
|
||||
assertEquals("Should not have been filtered", 1, result.size());
|
||||
@@ -126,7 +126,8 @@ public class ExcludeFilterTests {
|
||||
return exclude;
|
||||
}
|
||||
|
||||
private Artifact createArtifact(String groupId, String artifactId, String classifier) {
|
||||
private Artifact createArtifact(String groupId, String artifactId,
|
||||
String classifier) {
|
||||
Artifact a = mock(Artifact.class);
|
||||
given(a.getGroupId()).willReturn(groupId);
|
||||
given(a.getArtifactId()).willReturn(artifactId);
|
||||
|
||||
@@ -40,8 +40,8 @@ public class IncludeFilterTests {
|
||||
|
||||
@Test
|
||||
public void includeSimple() throws ArtifactFilterException {
|
||||
IncludeFilter filter = new IncludeFilter(Arrays.asList(createInclude("com.foo",
|
||||
"bar")));
|
||||
IncludeFilter filter = new IncludeFilter(
|
||||
Arrays.asList(createInclude("com.foo", "bar")));
|
||||
Artifact artifact = createArtifact("com.foo", "bar");
|
||||
Set result = filter.filter(Collections.singleton(artifact));
|
||||
assertEquals("Should not have been filtered", 1, result.size());
|
||||
@@ -50,8 +50,8 @@ public class IncludeFilterTests {
|
||||
|
||||
@Test
|
||||
public void includeGroupIdNoMatch() throws ArtifactFilterException {
|
||||
IncludeFilter filter = new IncludeFilter(Arrays.asList(createInclude("com.foo",
|
||||
"bar")));
|
||||
IncludeFilter filter = new IncludeFilter(
|
||||
Arrays.asList(createInclude("com.foo", "bar")));
|
||||
Artifact artifact = createArtifact("com.baz", "bar");
|
||||
Set result = filter.filter(Collections.singleton(artifact));
|
||||
assertEquals("Should have been filtered", 0, result.size());
|
||||
@@ -59,8 +59,8 @@ public class IncludeFilterTests {
|
||||
|
||||
@Test
|
||||
public void includeArtifactIdNoMatch() throws ArtifactFilterException {
|
||||
IncludeFilter filter = new IncludeFilter(Arrays.asList(createInclude("com.foo",
|
||||
"bar")));
|
||||
IncludeFilter filter = new IncludeFilter(
|
||||
Arrays.asList(createInclude("com.foo", "bar")));
|
||||
Artifact artifact = createArtifact("com.foo", "biz");
|
||||
Set result = filter.filter(Collections.singleton(artifact));
|
||||
assertEquals("Should have been filtered", 0, result.size());
|
||||
@@ -68,8 +68,8 @@ public class IncludeFilterTests {
|
||||
|
||||
@Test
|
||||
public void includeClassifier() throws ArtifactFilterException {
|
||||
IncludeFilter filter = new IncludeFilter(Arrays.asList(createInclude("com.foo",
|
||||
"bar", "jdk5")));
|
||||
IncludeFilter filter = new IncludeFilter(
|
||||
Arrays.asList(createInclude("com.foo", "bar", "jdk5")));
|
||||
Artifact artifact = createArtifact("com.foo", "bar", "jdk5");
|
||||
Set result = filter.filter(Collections.singleton(artifact));
|
||||
assertEquals("Should not have been filtered", 1, result.size());
|
||||
@@ -78,8 +78,8 @@ public class IncludeFilterTests {
|
||||
|
||||
@Test
|
||||
public void includeClassifierNoTargetClassifier() throws ArtifactFilterException {
|
||||
IncludeFilter filter = new IncludeFilter(Arrays.asList(createInclude("com.foo",
|
||||
"bar", "jdk5")));
|
||||
IncludeFilter filter = new IncludeFilter(
|
||||
Arrays.asList(createInclude("com.foo", "bar", "jdk5")));
|
||||
Artifact artifact = createArtifact("com.foo", "bar");
|
||||
Set result = filter.filter(Collections.singleton(artifact));
|
||||
assertEquals("Should have been filtered", 0, result.size());
|
||||
@@ -87,8 +87,8 @@ public class IncludeFilterTests {
|
||||
|
||||
@Test
|
||||
public void includeClassifierNoMatch() throws ArtifactFilterException {
|
||||
IncludeFilter filter = new IncludeFilter(Arrays.asList(createInclude("com.foo",
|
||||
"bar", "jdk5")));
|
||||
IncludeFilter filter = new IncludeFilter(
|
||||
Arrays.asList(createInclude("com.foo", "bar", "jdk5")));
|
||||
Artifact artifact = createArtifact("com.foo", "bar", "jdk6");
|
||||
Set result = filter.filter(Collections.singleton(artifact));
|
||||
assertEquals("Should have been filtered", 0, result.size());
|
||||
@@ -122,7 +122,8 @@ public class IncludeFilterTests {
|
||||
return include;
|
||||
}
|
||||
|
||||
private Artifact createArtifact(String groupId, String artifactId, String classifier) {
|
||||
private Artifact createArtifact(String groupId, String artifactId,
|
||||
String classifier) {
|
||||
Artifact a = mock(Artifact.class);
|
||||
given(a.getGroupId()).willReturn(groupId);
|
||||
given(a.getArtifactId()).willReturn(artifactId);
|
||||
|
||||
@@ -44,7 +44,8 @@ public class RunArgumentsTests {
|
||||
|
||||
@Test
|
||||
public void parseDebugFlags() {
|
||||
String[] args = parseArgs("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005");
|
||||
String[] args = parseArgs(
|
||||
"-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005");
|
||||
assertEquals(2, args.length);
|
||||
assertEquals("-Xdebug", args[0]);
|
||||
assertEquals("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005",
|
||||
|
||||
@@ -131,8 +131,8 @@ public final class Verify {
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("Unable to find entry starting with "
|
||||
+ entryName);
|
||||
throw new IllegalStateException(
|
||||
"Unable to find entry starting with " + entryName);
|
||||
}
|
||||
|
||||
public boolean hasEntry(String entry) {
|
||||
@@ -225,16 +225,16 @@ public final class Verify {
|
||||
verifier.assertHasEntryNameStartingWith("lib/spring-context");
|
||||
verifier.assertHasEntryNameStartingWith("lib/spring-core");
|
||||
verifier.assertHasEntryNameStartingWith("lib/javax.servlet-api-3");
|
||||
assertTrue("Unpacked launcher classes", verifier.hasEntry("org/"
|
||||
+ "springframework/boot/loader/JarLauncher.class"));
|
||||
assertTrue("Own classes", verifier.hasEntry("org/"
|
||||
+ "test/SampleApplication.class"));
|
||||
assertTrue("Unpacked launcher classes", verifier
|
||||
.hasEntry("org/" + "springframework/boot/loader/JarLauncher.class"));
|
||||
assertTrue("Own classes",
|
||||
verifier.hasEntry("org/" + "test/SampleApplication.class"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void verifyManifest(Manifest manifest) throws Exception {
|
||||
assertEquals("org.springframework.boot.loader.JarLauncher", manifest
|
||||
.getMainAttributes().getValue("Main-Class"));
|
||||
assertEquals("org.springframework.boot.loader.JarLauncher",
|
||||
manifest.getMainAttributes().getValue("Main-Class"));
|
||||
assertEquals(this.main, manifest.getMainAttributes().getValue("Start-Class"));
|
||||
assertEquals("Foo", manifest.getMainAttributes().getValue("Not-Used"));
|
||||
}
|
||||
@@ -251,20 +251,21 @@ public final class Verify {
|
||||
super.verifyZipEntries(verifier);
|
||||
verifier.assertHasEntryNameStartingWith("WEB-INF/lib/spring-context");
|
||||
verifier.assertHasEntryNameStartingWith("WEB-INF/lib/spring-core");
|
||||
verifier.assertHasEntryNameStartingWith("WEB-INF/lib-provided/javax.servlet-api-3");
|
||||
assertTrue("Unpacked launcher classes", verifier.hasEntry("org/"
|
||||
+ "springframework/boot/loader/JarLauncher.class"));
|
||||
assertTrue("Own classes", verifier.hasEntry("WEB-INF/classes/org/"
|
||||
+ "test/SampleApplication.class"));
|
||||
verifier.assertHasEntryNameStartingWith(
|
||||
"WEB-INF/lib-provided/javax.servlet-api-3");
|
||||
assertTrue("Unpacked launcher classes", verifier
|
||||
.hasEntry("org/" + "springframework/boot/loader/JarLauncher.class"));
|
||||
assertTrue("Own classes", verifier
|
||||
.hasEntry("WEB-INF/classes/org/" + "test/SampleApplication.class"));
|
||||
assertTrue("Web content", verifier.hasEntry("index.html"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void verifyManifest(Manifest manifest) throws Exception {
|
||||
assertEquals("org.springframework.boot.loader.WarLauncher", manifest
|
||||
.getMainAttributes().getValue("Main-Class"));
|
||||
assertEquals("org.test.SampleApplication", manifest.getMainAttributes()
|
||||
.getValue("Start-Class"));
|
||||
assertEquals("org.springframework.boot.loader.WarLauncher",
|
||||
manifest.getMainAttributes().getValue("Main-Class"));
|
||||
assertEquals("org.test.SampleApplication",
|
||||
manifest.getMainAttributes().getValue("Start-Class"));
|
||||
assertEquals("Foo", manifest.getMainAttributes().getValue("Not-Used"));
|
||||
}
|
||||
}
|
||||
@@ -277,10 +278,10 @@ public final class Verify {
|
||||
|
||||
@Override
|
||||
protected void verifyManifest(Manifest manifest) throws Exception {
|
||||
assertEquals("org.springframework.boot.loader.PropertiesLauncher", manifest
|
||||
.getMainAttributes().getValue("Main-Class"));
|
||||
assertEquals("org.test.SampleApplication", manifest.getMainAttributes()
|
||||
.getValue("Start-Class"));
|
||||
assertEquals("org.springframework.boot.loader.PropertiesLauncher",
|
||||
manifest.getMainAttributes().getValue("Main-Class"));
|
||||
assertEquals("org.test.SampleApplication",
|
||||
manifest.getMainAttributes().getValue("Start-Class"));
|
||||
assertEquals("Foo", manifest.getMainAttributes().getValue("Not-Used"));
|
||||
}
|
||||
}
|
||||
@@ -297,10 +298,10 @@ public final class Verify {
|
||||
verifier.assertHasEntryNameStartingWith("lib/spring-context");
|
||||
verifier.assertHasEntryNameStartingWith("lib/spring-core");
|
||||
verifier.assertHasNoEntryNameStartingWith("lib/javax.servlet-api-3");
|
||||
assertFalse("Unpacked launcher classes", verifier.hasEntry("org/"
|
||||
+ "springframework/boot/loader/JarLauncher.class"));
|
||||
assertTrue("Own classes", verifier.hasEntry("org/"
|
||||
+ "test/SampleModule.class"));
|
||||
assertFalse("Unpacked launcher classes", verifier
|
||||
.hasEntry("org/" + "springframework/boot/loader/JarLauncher.class"));
|
||||
assertTrue("Own classes",
|
||||
verifier.hasEntry("org/" + "test/SampleModule.class"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user