pull/812/head
Phillip Webb 11 years ago
parent 1fc6bbda4f
commit 32d2fc25c7

@ -26,6 +26,7 @@ import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException; import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
import org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter; import org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter;
import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter;
import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts; import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts;
import org.apache.maven.shared.artifact.filter.collection.GroupIdFilter; import org.apache.maven.shared.artifact.filter.collection.GroupIdFilter;
@ -38,9 +39,9 @@ import org.apache.maven.shared.artifact.filter.collection.GroupIdFilter;
public abstract class AbstractDependencyFilterMojo extends AbstractMojo { public abstract class AbstractDependencyFilterMojo extends AbstractMojo {
/** /**
* Collection of artifact definitions to exclude. The {@link Exclude} * Collection of artifact definitions to exclude. The {@link Exclude} element defines
* element defines a {@code groupId} and {@code artifactId} mandatory * a {@code groupId} and {@code artifactId} mandatory properties and an optional
* properties and an optional {@code classifier} property. * {@code classifier} property.
* @since 1.1 * @since 1.1
*/ */
@Parameter @Parameter
@ -51,15 +52,14 @@ public abstract class AbstractDependencyFilterMojo extends AbstractMojo {
* @since 1.1 * @since 1.1
*/ */
@Parameter(property = "excludeGroupIds", defaultValue = "") @Parameter(property = "excludeGroupIds", defaultValue = "")
protected String excludeGroupIds; private String excludeGroupIds;
/** /**
* Comma separated list of artifact names to exclude. * Comma separated list of artifact names to exclude.
* @since 1.1 * @since 1.1
*/ */
@Parameter(property = "excludeArtifactIds", defaultValue = "") @Parameter(property = "excludeArtifactIds", defaultValue = "")
protected String excludeArtifactIds; private String excludeArtifactIds;
protected void setExcludes(List<Exclude> excludes) { protected void setExcludes(List<Exclude> excludes) {
this.excludes = excludes; this.excludes = excludes;
@ -74,8 +74,8 @@ public abstract class AbstractDependencyFilterMojo extends AbstractMojo {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected Set<Artifact> filterDependencies(Set<Artifact> dependencies, FilterArtifacts filters) protected Set<Artifact> filterDependencies(Set<Artifact> dependencies,
throws MojoExecutionException { FilterArtifacts filters) throws MojoExecutionException {
try { try {
return filters.filter(dependencies); return filters.filter(dependencies);
} }
@ -84,28 +84,37 @@ public abstract class AbstractDependencyFilterMojo extends AbstractMojo {
} }
} }
protected void initializeFilterArtifacts(FilterArtifacts filters) { /**
filters.addFilter(new ArtifactIdFilter("", cleanConfigItem(this.excludeArtifactIds))); * Return artifact filters configured for this MOJO.
filters.addFilter(new GroupIdFilter("", cleanConfigItem(this.excludeGroupIds))); * @param additionalFilters optional additional filters to apply
* @return the filters
*/
protected final FilterArtifacts getFilters(ArtifactsFilter... additionalFilters) {
FilterArtifacts filters = new FilterArtifacts();
for (ArtifactsFilter additionalFilter : additionalFilters) {
filters.addFilter(additionalFilter);
}
filters.addFilter(new ArtifactIdFilter("",
cleanFilterConfig(this.excludeArtifactIds)));
filters.addFilter(new GroupIdFilter("", cleanFilterConfig(this.excludeGroupIds)));
if (this.excludes != null) { if (this.excludes != null) {
filters.addFilter(new ExcludeFilter(this.excludes)); filters.addFilter(new ExcludeFilter(this.excludes));
} }
return filters;
} }
private String cleanFilterConfig(String content) {
static String cleanConfigItem(String content) {
if (content == null || content.trim().isEmpty()) { if (content == null || content.trim().isEmpty()) {
return ""; return "";
} }
StringBuilder sb = new StringBuilder(); StringBuilder cleaned = new StringBuilder();
StringTokenizer st = new StringTokenizer(content, ","); StringTokenizer tokenizer = new StringTokenizer(content, ",");
while (st.hasMoreElements()) { while (tokenizer.hasMoreElements()) {
String t = st.nextToken(); cleaned.append(tokenizer.nextToken().trim());
sb.append(t.trim()); if (tokenizer.hasMoreElements()) {
if (st.hasMoreElements()) { cleaned.append(",");
sb.append(",");
} }
} }
return sb.toString(); return cleaned.toString();
} }
} }

@ -45,7 +45,7 @@ public class Exclude {
private String classifier; private String classifier;
public String getGroupId() { public String getGroupId() {
return groupId; return this.groupId;
} }
public void setGroupId(String groupId) { public void setGroupId(String groupId) {
@ -53,7 +53,7 @@ public class Exclude {
} }
public String getArtifactId() { public String getArtifactId() {
return artifactId; return this.artifactId;
} }
public void setArtifactId(String artifactId) { public void setArtifactId(String artifactId) {
@ -61,7 +61,7 @@ public class Exclude {
} }
public String getClassifier() { public String getClassifier() {
return classifier; return this.classifier;
} }
public void setClassifier(String classifier) { public void setClassifier(String classifier) {

@ -26,8 +26,8 @@ import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterExceptio
/** /**
* An {@link org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter * An {@link org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter
* ArtifactsFilter} that filters out any artifact matching a configurable list * ArtifactsFilter} that filters out any artifact matching a configurable list of
* of {@link Exclude} instances. * {@link Exclude} instances.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
* @since 1.1 * @since 1.1
@ -37,14 +37,14 @@ public class ExcludeFilter extends AbstractArtifactsFilter{
private final List<Exclude> excludes; private final List<Exclude> excludes;
/** /**
* Create a new instance with the list of {@link Exclude} * Create a new instance with the list of {@link Exclude} instance(s) to use.
* instance(s) to use.
*/ */
public ExcludeFilter(List<Exclude> excludes) { public ExcludeFilter(List<Exclude> excludes) {
this.excludes = excludes; this.excludes = excludes;
} }
@Override @Override
@SuppressWarnings("rawtypes")
public Set filter(Set artifacts) throws ArtifactFilterException { public Set filter(Set artifacts) throws ArtifactFilterException {
Set<Artifact> result = new HashSet<Artifact>(); Set<Artifact> result = new HashSet<Artifact>();
for (Object a : artifacts) { for (Object a : artifacts) {
@ -57,11 +57,11 @@ public class ExcludeFilter extends AbstractArtifactsFilter{
} }
/** /**
* Check if the specified {@link Artifact} matches one of the * Check if the specified {@link Artifact} matches one of the known excludes. Returns
* known excludes. Returns {@code true} if it should be excluded * {@code true} if it should be excluded
*/ */
private boolean matchExclude(Artifact artifact) { private boolean matchExclude(Artifact artifact) {
for (Exclude exclude : excludes) { for (Exclude exclude : this.excludes) {
if (match(artifact, exclude)) { if (match(artifact, exclude)) {
return true; return true;
} }
@ -70,8 +70,8 @@ public class ExcludeFilter extends AbstractArtifactsFilter{
} }
/** /**
* Check if the specified {@link Artifact} matches the specified * Check if the specified {@link Artifact} matches the specified {@link Exclude}.
* {@link Exclude}. Returns {@code true} if it should be excluded * Returns {@code true} if it should be excluded
*/ */
private boolean match(Artifact artifact, Exclude exclude) { private boolean match(Artifact artifact, Exclude exclude) {
if (!exclude.getGroupId().equals(artifact.getGroupId())) { if (!exclude.getGroupId().equals(artifact.getGroupId())) {
@ -80,8 +80,8 @@ public class ExcludeFilter extends AbstractArtifactsFilter{
if (!exclude.getArtifactId().equals(artifact.getArtifactId())) { if (!exclude.getArtifactId().equals(artifact.getArtifactId())) {
return false; return false;
} }
return exclude.getClassifier() == null || return (exclude.getClassifier() == null || artifact.getClassifier() != null
artifact.getClassifier() != null && exclude.getClassifier().equals(artifact.getClassifier()); && exclude.getClassifier().equals(artifact.getClassifier()));
} }

@ -23,7 +23,6 @@ import java.util.concurrent.TimeUnit;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Component;
@ -33,8 +32,6 @@ import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper; import org.apache.maven.project.MavenProjectHelper;
import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts;
import org.springframework.boot.loader.tools.Layout; import org.springframework.boot.loader.tools.Layout;
import org.springframework.boot.loader.tools.Layouts; import org.springframework.boot.loader.tools.Layouts;
import org.springframework.boot.loader.tools.Libraries; import org.springframework.boot.loader.tools.Libraries;
@ -139,9 +136,8 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
repackager.setLayout(this.layout.layout()); repackager.setLayout(this.layout.layout());
} }
FilterArtifacts filters = new FilterArtifacts(); Set<Artifact> artifacts = filterDependencies(this.project.getArtifacts(),
initializeFilterArtifacts(filters); getFilters());
Set<Artifact> artifacts = filterDependencies(this.project.getArtifacts(), filters);
Libraries libraries = new ArtifactsLibraries(artifacts); Libraries libraries = new ArtifactsLibraries(artifacts);
try { try {

@ -38,7 +38,6 @@ import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.artifact.filter.collection.AbstractArtifactFeatureFilter; import org.apache.maven.shared.artifact.filter.collection.AbstractArtifactFeatureFilter;
import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts; import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts;
import org.springframework.boot.loader.tools.FileUtils; import org.springframework.boot.loader.tools.FileUtils;
import org.springframework.boot.loader.tools.JavaExecutable; import org.springframework.boot.loader.tools.JavaExecutable;
import org.springframework.boot.loader.tools.MainClassFinder; import org.springframework.boot.loader.tools.MainClassFinder;
@ -256,11 +255,9 @@ public class RunMojo extends AbstractDependencyFilterMojo {
urls.add(this.classesDirectory.toURI().toURL()); urls.add(this.classesDirectory.toURI().toURL());
} }
private void addDependencies(List<URL> urls) throws MalformedURLException, MojoExecutionException { private void addDependencies(List<URL> urls) throws MalformedURLException,
FilterArtifacts filters = new FilterArtifacts(); MojoExecutionException {
filters.addFilter(new TestArtifactFilter()); FilterArtifacts filters = getFilters(new TestArtifactFilter());
initializeFilterArtifacts(filters);
Set<Artifact> artifacts = filterDependencies(this.project.getArtifacts(), filters); Set<Artifact> artifacts = filterDependencies(this.project.getArtifacts(), filters);
for (Artifact artifact : artifacts) { for (Artifact artifact : artifacts) {
if (artifact.getFile() != null) { if (artifact.getFile() != null) {
@ -274,6 +271,7 @@ public class RunMojo extends AbstractDependencyFilterMojo {
super("", Artifact.SCOPE_TEST); super("", Artifact.SCOPE_TEST);
} }
@Override
protected String getArtifactFeature(Artifact artifact) { protected String getArtifactFeature(Artifact artifact) {
return artifact.getScope(); return artifact.getScope();
} }

@ -16,10 +16,6 @@
package org.springframework.boot.maven; package org.springframework.boot.maven;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
@ -29,9 +25,13 @@ import java.util.Set;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
/** /**
* *
* @author Stephane Nicoll * @author Stephane Nicoll
@ -44,16 +44,13 @@ public class DependencyFilterMojoTests {
Collections.<Exclude> emptyList(), "com.foo", "exclude-id"); Collections.<Exclude> emptyList(), "com.foo", "exclude-id");
Artifact artifact = createArtifact("com.bar", "one"); Artifact artifact = createArtifact("com.bar", "one");
Set<Artifact> artifacts = mojo.filterDependencies(createArtifact("com.foo", "one"), Set<Artifact> artifacts = mojo.filterDependencies(
createArtifact("com.foo", "two"), createArtifact("com.foo", "one"), createArtifact("com.foo", "two"),
createArtifact("com.bar", "exclude-id"), createArtifact("com.bar", "exclude-id"), artifact);
artifact);
assertEquals("wrong filtering of artifacts", 1, artifacts.size()); assertEquals("wrong filtering of artifacts", 1, artifacts.size());
assertSame("Wrong filtered artifact", artifact, artifacts.iterator().next()); assertSame("Wrong filtered artifact", artifact, artifacts.iterator().next());
} }
private Artifact createArtifact(String groupId, String artifactId) { private Artifact createArtifact(String groupId, String artifactId) {
Artifact a = mock(Artifact.class); Artifact a = mock(Artifact.class);
given(a.getGroupId()).willReturn(groupId); given(a.getGroupId()).willReturn(groupId);
@ -61,20 +58,20 @@ public class DependencyFilterMojoTests {
return a; return a;
} }
private static class TestableDependencyFilterMojo extends
AbstractDependencyFilterMojo {
private static class TestableDependencyFilterMojo extends AbstractDependencyFilterMojo { private TestableDependencyFilterMojo(List<Exclude> excludes,
String excludeGroupIds, String excludeArtifactIds) {
private TestableDependencyFilterMojo(List<Exclude> excludes, String excludeGroupIds, String excludeArtifactIds) {
setExcludes(excludes); setExcludes(excludes);
setExcludeGroupIds(excludeGroupIds); setExcludeGroupIds(excludeGroupIds);
setExcludeArtifactIds(excludeArtifactIds); setExcludeArtifactIds(excludeArtifactIds);
} }
public Set<Artifact> filterDependencies(Artifact... artifacts) throws MojoExecutionException { public Set<Artifact> filterDependencies(Artifact... artifacts)
throws MojoExecutionException {
Set<Artifact> input = new HashSet<Artifact>(Arrays.asList(artifacts)); Set<Artifact> input = new HashSet<Artifact>(Arrays.asList(artifacts));
FilterArtifacts filters = new FilterArtifacts(); return filterDependencies(input, getFilters());
initializeFilterArtifacts(filters);
return filterDependencies(input, filters);
} }
@Override @Override

@ -16,10 +16,6 @@
package org.springframework.boot.maven; package org.springframework.boot.maven;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
import static org.mockito.Mockito.mock;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
@ -29,23 +25,32 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException; import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
/** /**
* Tests for {@link ExcludeFilter}.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
@SuppressWarnings("rawtypes")
public class ExcludeFilterTests { public class ExcludeFilterTests {
@Test @Test
public void excludeSimple() throws ArtifactFilterException { public void excludeSimple() throws ArtifactFilterException {
ExcludeFilter filter = new ExcludeFilter(Arrays.asList(createExclude("com.foo", "bar"))); ExcludeFilter filter = new ExcludeFilter(Arrays.asList(createExclude("com.foo",
Set result = filter.filter(Collections.singleton(createArtifact("com.foo", "bar"))); "bar")));
Set result = filter.filter(Collections
.singleton(createArtifact("com.foo", "bar")));
assertEquals("Should have been filtered", 0, result.size()); assertEquals("Should have been filtered", 0, result.size());
} }
@Test @Test
public void excludeGroupIdNoMatch() throws ArtifactFilterException { 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"); Artifact artifact = createArtifact("com.baz", "bar");
Set result = filter.filter(Collections.singleton(artifact)); Set result = filter.filter(Collections.singleton(artifact));
assertEquals("Should not have been filtered", 1, result.size()); assertEquals("Should not have been filtered", 1, result.size());
@ -54,7 +59,8 @@ public class ExcludeFilterTests {
@Test @Test
public void excludeArtifactIdNoMatch() throws ArtifactFilterException { 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"); Artifact artifact = createArtifact("com.foo", "biz");
Set result = filter.filter(Collections.singleton(artifact)); Set result = filter.filter(Collections.singleton(artifact));
assertEquals("Should not have been filtered", 1, result.size()); assertEquals("Should not have been filtered", 1, result.size());
@ -63,14 +69,17 @@ public class ExcludeFilterTests {
@Test @Test
public void excludeClassifier() throws ArtifactFilterException { public void excludeClassifier() throws ArtifactFilterException {
ExcludeFilter filter = new ExcludeFilter(Arrays.asList(createExclude("com.foo", "bar", "jdk5"))); ExcludeFilter filter = new ExcludeFilter(Arrays.asList(createExclude("com.foo",
Set result = filter.filter(Collections.singleton(createArtifact("com.foo", "bar", "jdk5"))); "bar", "jdk5")));
Set result = filter.filter(Collections.singleton(createArtifact("com.foo", "bar",
"jdk5")));
assertEquals("Should have been filtered", 0, result.size()); assertEquals("Should have been filtered", 0, result.size());
} }
@Test @Test
public void excludeClassifierNoTargetClassifier() throws ArtifactFilterException { 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"); Artifact artifact = createArtifact("com.foo", "bar");
Set result = filter.filter(Collections.singleton(artifact)); Set result = filter.filter(Collections.singleton(artifact));
assertEquals("Should not have been filtered", 1, result.size()); assertEquals("Should not have been filtered", 1, result.size());
@ -79,7 +88,8 @@ public class ExcludeFilterTests {
@Test @Test
public void excludeClassifierNoMatch() throws ArtifactFilterException { 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"); Artifact artifact = createArtifact("com.foo", "bar", "jdk6");
Set result = filter.filter(Collections.singleton(artifact)); Set result = filter.filter(Collections.singleton(artifact));
assertEquals("Should not have been filtered", 1, result.size()); assertEquals("Should not have been filtered", 1, result.size());
@ -89,8 +99,7 @@ public class ExcludeFilterTests {
@Test @Test
public void excludeMulti() throws ArtifactFilterException { public void excludeMulti() throws ArtifactFilterException {
ExcludeFilter filter = new ExcludeFilter(Arrays.asList( ExcludeFilter filter = new ExcludeFilter(Arrays.asList(
createExclude("com.foo", "bar"), createExclude("com.foo", "bar"), createExclude("com.foo", "bar2"),
createExclude("com.foo", "bar2"),
createExclude("org.acme", "app"))); createExclude("org.acme", "app")));
Set<Artifact> artifacts = new HashSet<Artifact>(); Set<Artifact> artifacts = new HashSet<Artifact>();
artifacts.add(createArtifact("com.foo", "bar")); artifacts.add(createArtifact("com.foo", "bar"));
@ -102,7 +111,6 @@ public class ExcludeFilterTests {
assertSame(anotherAcme, result.iterator().next()); assertSame(anotherAcme, result.iterator().next());
} }
private Exclude createExclude(String groupId, String artifactId, String classifier) { private Exclude createExclude(String groupId, String artifactId, String classifier) {
Exclude e = new Exclude(); Exclude e = new Exclude();
e.setGroupId(groupId); e.setGroupId(groupId);

@ -1,44 +0,0 @@
/*
* Copyright 2012-2014 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.maven;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
/**
*
* @author Stephane Nicoll
*/
public class RepackageMojoTests {
@Test
public void cleanConfigItemWithSpaces() {
assertEquals("foo,bar,biz", RepackageMojo.cleanConfigItem("foo, bar , biz"));
}
@Test
public void cleanNullConfigItemWith() {
assertEquals("", RepackageMojo.cleanConfigItem(null));
}
@Test
public void cleanEmptyConfigItemWith() {
assertEquals("", RepackageMojo.cleanConfigItem(""));
}
}

@ -81,8 +81,8 @@ public class Verify {
public void assertHasNoEntryNameStartingWith(String entry) { public void assertHasNoEntryNameStartingWith(String entry) {
for (String name : this.content.keySet()) { for (String name : this.content.keySet()) {
if (name.startsWith(entry)) { if (name.startsWith(entry)) {
throw new IllegalStateException("Entry starting with " throw new IllegalStateException("Entry starting with " + entry
+ entry + " should not have been found"); + " should not have been found");
} }
} }
} }
@ -127,13 +127,13 @@ public class Verify {
} }
} }
protected void verifyZipEntries(ArchiveVerifier verifier) protected void verifyZipEntries(ArchiveVerifier verifier) throws Exception {
throws Exception {
verifyManifest(verifier); verifyManifest(verifier);
} }
private void verifyManifest(ArchiveVerifier verifier) throws Exception { private void verifyManifest(ArchiveVerifier verifier) throws Exception {
Manifest manifest = new Manifest(verifier.getEntryContent("META-INF/MANIFEST.MF")); Manifest manifest = new Manifest(
verifier.getEntryContent("META-INF/MANIFEST.MF"));
verifyManifest(manifest); verifyManifest(manifest);
} }
@ -151,8 +151,7 @@ public class Verify {
} }
@Override @Override
protected void verifyZipEntries(ArchiveVerifier verifier) protected void verifyZipEntries(ArchiveVerifier verifier) throws Exception {
throws Exception {
super.verifyZipEntries(verifier); super.verifyZipEntries(verifier);
verifier.assertHasEntryNameStartingWith("lib/spring-context"); verifier.assertHasEntryNameStartingWith("lib/spring-context");
verifier.assertHasEntryNameStartingWith("lib/spring-core"); verifier.assertHasEntryNameStartingWith("lib/spring-core");
@ -179,13 +178,11 @@ public class Verify {
} }
@Override @Override
protected void verifyZipEntries(ArchiveVerifier verifier) protected void verifyZipEntries(ArchiveVerifier verifier) throws Exception {
throws Exception {
super.verifyZipEntries(verifier); super.verifyZipEntries(verifier);
verifier.assertHasEntryNameStartingWith("WEB-INF/lib/spring-context"); verifier.assertHasEntryNameStartingWith("WEB-INF/lib/spring-context");
verifier.assertHasEntryNameStartingWith("WEB-INF/lib/spring-core"); verifier.assertHasEntryNameStartingWith("WEB-INF/lib/spring-core");
verifier.assertHasEntryNameStartingWith( verifier.assertHasEntryNameStartingWith("WEB-INF/lib-provided/javax.servlet-api-3.0.1.jar");
"WEB-INF/lib-provided/javax.servlet-api-3.0.1.jar");
assertTrue("Unpacked launcher classes", verifier.hasEntry("org/" assertTrue("Unpacked launcher classes", verifier.hasEntry("org/"
+ "springframework/boot/loader/JarLauncher.class")); + "springframework/boot/loader/JarLauncher.class"));
assertTrue("Own classes", verifier.hasEntry("WEB-INF/classes/org/" assertTrue("Own classes", verifier.hasEntry("WEB-INF/classes/org/"

Loading…
Cancel
Save