Merge branch 'master' into 2.0.x
This commit is contained in:
30
pom.xml
30
pom.xml
@@ -257,30 +257,6 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<version>${checkstyle.version}</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-build-tools</artifactId>
|
||||
<version>${spring-cloud-build.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>validate</id>
|
||||
<phase>validate</phase>
|
||||
<configuration>
|
||||
<configLocation>checkstyle.xml</configLocation>
|
||||
<headerLocation>LICENSE.txt</headerLocation>
|
||||
<consoleOutput>true</consoleOutput>
|
||||
<failsOnError>true</failsOnError>
|
||||
<excludes>${project.build.directory}/**</excludes>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>check</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
@@ -290,12 +266,6 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<version>${checkstyle.version}</version>
|
||||
<configuration>
|
||||
<configLocation>checkstyle.xml</configLocation>
|
||||
<headerLocation>LICENSE.txt</headerLocation>
|
||||
<excludes>${project.build.directory}/**</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
|
||||
@@ -113,20 +113,22 @@ public class WireMockConfiguration implements SmartLifecycle {
|
||||
}
|
||||
|
||||
private void registerFiles(com.github.tomakehurst.wiremock.core.WireMockConfiguration factory) throws IOException {
|
||||
List<Resource> resources = new ArrayList<>();
|
||||
for (String files : this.wireMock.getFiles()) {
|
||||
if (StringUtils.hasText(files)) {
|
||||
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(
|
||||
this.resourceLoader);
|
||||
List<Resource> resources = new ArrayList<>();
|
||||
for (Resource resource : resolver.getResources(files)) {
|
||||
if (resource.exists()) {
|
||||
resources.add(resource);
|
||||
}
|
||||
}
|
||||
ResourcesFileSource fileSource = new ResourcesFileSource(resources.toArray(new Resource[0]));
|
||||
factory.fileSource(fileSource);
|
||||
}
|
||||
}
|
||||
if (!resources.isEmpty()) {
|
||||
ResourcesFileSource fileSource = new ResourcesFileSource(resources.toArray(new Resource[0]));
|
||||
factory.fileSource(fileSource);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -34,28 +34,37 @@ import com.github.tomakehurst.wiremock.common.TextFile;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
* @author Pei-Tang Huang
|
||||
*/
|
||||
public class ResourcesFileSource implements FileSource {
|
||||
|
||||
private final FileSource[] sources;
|
||||
|
||||
public ResourcesFileSource(Resource[] resources) {
|
||||
this.sources = new FileSource[resources.length];
|
||||
public ResourcesFileSource(Resource... resources) {
|
||||
this(toSources(resources));
|
||||
}
|
||||
|
||||
private ResourcesFileSource(FileSource... sources) {
|
||||
this.sources = sources;
|
||||
}
|
||||
|
||||
private static FileSource[] toSources(Resource[] resources) {
|
||||
FileSource[] sources = new FileSource[resources.length];
|
||||
for (int i = 0; i < resources.length; i++) {
|
||||
Resource resource = resources[i];
|
||||
if (resource instanceof ClassPathResource) {
|
||||
ClassPathResource classes = (ClassPathResource) resource;
|
||||
this.sources[i] = new ClasspathFileSource(classes.getPath());
|
||||
sources[i] = new ClasspathFileSource(classes.getPath());
|
||||
}
|
||||
else if (resource instanceof FileSystemResource) {
|
||||
FileSystemResource files = (FileSystemResource) resource;
|
||||
this.sources[i] = new SingleRootFileSource(files.getFile());
|
||||
sources[i] = new SingleRootFileSource(files.getFile());
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Unsupported resource type for file source: " + resource.getClass());
|
||||
}
|
||||
}
|
||||
return sources;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,17 +103,21 @@ public class ResourcesFileSource implements FileSource {
|
||||
|
||||
@Override
|
||||
public FileSource child(String subDirectoryName) {
|
||||
List<FileSource> childSources = new ArrayList<>();
|
||||
for (FileSource resource : this.sources) {
|
||||
try {
|
||||
UrlResource uri = new UrlResource(resource.child(subDirectoryName).getUri());
|
||||
if (uri.createRelative(subDirectoryName).exists()) {
|
||||
return resource.child(subDirectoryName);
|
||||
childSources.add(resource.child(subDirectoryName));
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
if (!childSources.isEmpty()) {
|
||||
return new ResourcesFileSource(childSources.toArray(new FileSource[0]));
|
||||
}
|
||||
return this.sources[0].child(subDirectoryName);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes=WiremockTestsApplication.class, properties="app.baseUrl=http://localhost:${wiremock.server.port}", webEnvironment=WebEnvironment.NONE)
|
||||
@DirtiesContext
|
||||
@AutoConfigureWireMock(port=0, files={"classpath:/nonexistent/", "classpath:/root/"}, stubs="file:src/test/resources/io.stubs/mappings")
|
||||
@AutoConfigureWireMock(port=0, files={"classpath:/", "classpath:/root/", "classpath:/nonexistent/"}, stubs="file:src/test/resources/io.stubs/mappings")
|
||||
public class AutoConfigureWireMockStubsAndMultipleFilesApplicationTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
Reference in New Issue
Block a user