Omit any file that is not a zip when repackaging
When repackaging an archive, the files in the resulting lib directory must be zip files. If they're not zip files, the resulting archive may fail to run (#324). The previous approach was to consider an artifact's type when deciding whether or not it should be packaged. The type is a string and, while there are a number of well-known values, it can essentially be anything. This caused a problem with an artifact incorrectly being identified as being unsuitable for inclusion (#489). This commit changes the approach. Rather than looking at an artifact's type, it looks at the first four bytes of the archive's file. Only if these header bytes matche that of a zip file is the artifact included. This is a better match for the requirement that all files in lib be zip files. Fixes #489
This commit is contained in:
@@ -17,10 +17,8 @@
|
||||
package org.springframework.boot.maven;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -33,13 +31,10 @@ import org.springframework.boot.loader.tools.LibraryScope;
|
||||
* {@link Libraries} backed by Maven {@link Artifact}s
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class ArtifactsLibraries implements Libraries {
|
||||
|
||||
private static final Set<String> SUPPORTED_TYPES = Collections
|
||||
.unmodifiableSet(new HashSet<String>(Arrays.asList("jar", "ejb",
|
||||
"ejb-client", "test-jar", "bundle")));
|
||||
|
||||
private static final Map<String, LibraryScope> SCOPES;
|
||||
static {
|
||||
Map<String, LibraryScope> scopes = new HashMap<String, LibraryScope>();
|
||||
@@ -58,11 +53,9 @@ public class ArtifactsLibraries implements Libraries {
|
||||
@Override
|
||||
public void doWithLibraries(LibraryCallback callback) throws IOException {
|
||||
for (Artifact artifact : this.artifacts) {
|
||||
if (SUPPORTED_TYPES.contains(artifact.getType())) {
|
||||
LibraryScope scope = SCOPES.get(artifact.getScope());
|
||||
if (scope != null && artifact.getFile() != null) {
|
||||
callback.library(artifact.getFile(), scope);
|
||||
}
|
||||
LibraryScope scope = SCOPES.get(artifact.getScope());
|
||||
if (scope != null && artifact.getFile() != null) {
|
||||
callback.library(artifact.getFile(), scope);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.springframework.boot.loader.tools.LibraryScope;
|
||||
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
|
||||
/**
|
||||
* Tests for {@link ArtifactsLibraries}.
|
||||
@@ -66,13 +65,4 @@ public class ArtifactsLibrariesTest {
|
||||
this.libs.doWithLibraries(this.callback);
|
||||
verify(this.callback).library(this.file, LibraryScope.COMPILE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotIncludePoms() throws Exception {
|
||||
given(this.artifact.getType()).willReturn("pom");
|
||||
given(this.artifact.getScope()).willReturn("compile");
|
||||
this.libs.doWithLibraries(this.callback);
|
||||
verifyZeroInteractions(this.callback);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user