Made the StubGenerators not check if they are applicable to a file
This commit is contained in:
@@ -31,6 +31,7 @@ import org.springframework.cloud.contract.spec.Contract;
|
||||
import org.springframework.cloud.contract.verifier.converter.StubGenerator;
|
||||
import org.springframework.cloud.contract.verifier.converter.StubGeneratorProvider;
|
||||
import org.springframework.cloud.contract.verifier.file.ContractMetadata;
|
||||
import org.springframework.cloud.contract.verifier.wiremock.DslToWireMockClientConverter;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
final class MappingGenerator {
|
||||
@@ -45,7 +46,7 @@ final class MappingGenerator {
|
||||
File mappingsFolder) {
|
||||
StubGeneratorProvider provider = new StubGeneratorProvider();
|
||||
Collection<StubGenerator> stubGenerators = provider
|
||||
.converterForName(contractFile);
|
||||
.allOrDefault(new DslToWireMockClientConverter());
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Found following matching stub generators " + stubGenerators);
|
||||
}
|
||||
|
||||
@@ -128,10 +128,8 @@ public class RecursiveFilesConverter {
|
||||
log.debug("Will create a stub for contract [" + contract + "]");
|
||||
}
|
||||
File sourceFile = contract.getPath().toFile();
|
||||
Collection<StubGenerator> stubGenerators = contract
|
||||
.getConvertedContract() != null
|
||||
? holder.allOrDefault(new DslToWireMockClientConverter())
|
||||
: holder.converterForName(sourceFile);
|
||||
Collection<StubGenerator> stubGenerators = holder
|
||||
.allOrDefault(new DslToWireMockClientConverter());
|
||||
try {
|
||||
String path = sourceFile.getPath();
|
||||
if (excludeBuildFolders && (matchesPath(path, "target")
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.contract.verifier.converter;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.cloud.contract.spec.Contract;
|
||||
@@ -30,23 +29,14 @@ import org.springframework.cloud.contract.verifier.file.ContractMetadata;
|
||||
public interface StubGenerator {
|
||||
|
||||
/**
|
||||
* @param fileName - file name
|
||||
* @param contractFileName - file name
|
||||
* @return {@code true} if the converter can handle the file to convert it into a
|
||||
* stub.
|
||||
* @deprecated use {@link StubGenerator#canHandleFileName(File)}
|
||||
* @deprecated all present converters will be picked
|
||||
*/
|
||||
@Deprecated
|
||||
default boolean canHandleFileName(String fileName) {
|
||||
return fileName.endsWith(fileExtension());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param file - file
|
||||
* @return {@code true} if the converter can handle the file to convert it into a
|
||||
* stub.
|
||||
*/
|
||||
default boolean canHandleFileName(File file) {
|
||||
return file.getName().endsWith(fileExtension());
|
||||
default boolean canHandleFileName(String contractFileName) {
|
||||
return contractFileName.endsWith(fileExtension());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,12 +16,10 @@
|
||||
|
||||
package org.springframework.cloud.contract.verifier.converter;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.core.io.support.SpringFactoriesLoader;
|
||||
|
||||
@@ -44,12 +42,6 @@ public class StubGeneratorProvider {
|
||||
this.converters.addAll(converters);
|
||||
}
|
||||
|
||||
public Collection<StubGenerator> converterForName(final File file) {
|
||||
return this.converters.stream()
|
||||
.filter(stubGenerator -> stubGenerator.canHandleFileName(file))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public Collection<StubGenerator> allOrDefault(StubGenerator defaultStubGenerator) {
|
||||
return this.converters.isEmpty() ? Collections.singletonList(defaultStubGenerator)
|
||||
: this.converters;
|
||||
|
||||
@@ -16,19 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.contract.verifier.wiremock;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
|
||||
import com.github.tomakehurst.wiremock.common.JsonException;
|
||||
import com.github.tomakehurst.wiremock.stubbing.StubMapping;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.cloud.contract.verifier.converter.StubGenerator;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
/**
|
||||
* WireMock implementation of the {@link StubGenerator}.
|
||||
@@ -37,8 +25,6 @@ import org.springframework.util.StreamUtils;
|
||||
*/
|
||||
public abstract class DslToWireMockConverter implements StubGenerator {
|
||||
|
||||
private static final Log log = LogFactory.getLog(DslToWireMockConverter.class);
|
||||
|
||||
@Override
|
||||
public String generateOutputFileNameForInput(String inputFileName) {
|
||||
return inputFileName.replaceAll(extension(inputFileName), "json");
|
||||
@@ -52,19 +38,4 @@ public abstract class DslToWireMockConverter implements StubGenerator {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canHandleFileName(File file) {
|
||||
try (InputStream stream = Files.newInputStream(file.toPath())) {
|
||||
StubMapping.buildFrom(
|
||||
StreamUtils.copyToString(stream, Charset.forName("UTF-8")));
|
||||
return true;
|
||||
}
|
||||
catch (IOException | JsonException e) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Cannot read file", e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
# Stub converters
|
||||
org.springframework.cloud.contract.verifier.converter.StubGenerator=\
|
||||
org.springframework.cloud.contract.verifier.wiremock.DslToWireMockClientConverter
|
||||
@@ -194,12 +194,7 @@ org.springframework.cloud.contract.spec.Contract.make {
|
||||
private StubGenerator stubGenerator(String stub) {
|
||||
return new StubGenerator() {
|
||||
@Override
|
||||
boolean canHandleFileName(String fileName) {
|
||||
return true
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean canHandleFileName(File fileName) {
|
||||
boolean canHandleFileName(String contractFileName) {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user