Added the deleteStubsAfterTest flag to remove stubs after tests are finished
if `deleteStubsAfterTest` is set to false then stubs will NOT be deleted after tests are executed fixes gh-512
This commit is contained in:
@@ -259,6 +259,8 @@ closure to set it up.
|
||||
JAR is available offline, remotely etc.)
|
||||
* *contractsSnapshotCheckSkip*: If set to `true` will not assert whether the
|
||||
downloaded stubs / contract JAR was downloaded from a remote location or a local one
|
||||
* *deleteStubsAfterTest*: If set to `false` will not remove any downloaded
|
||||
contracts from temporary directories
|
||||
|
||||
[[gradle-single-base-class]]
|
||||
==== Single Base Class for All Tests
|
||||
@@ -584,6 +586,8 @@ Defaults to `groupid/artifactid` where `gropuid` is slash separated.
|
||||
* *contractsMode*: Picks the mode in which stubs will be found and registered
|
||||
* *contractsSnapshotCheckSkip*: If `true` then will not assert whether a stub / contract
|
||||
JAR was downloaded from local or remote location
|
||||
* *deleteStubsAfterTest*: If set to `false` will not remove any downloaded
|
||||
contracts from temporary directories
|
||||
* *contractsRepositoryUrl*: URL to a repo with the artifacts that have contracts. If it is not provided,
|
||||
use the current Maven ones.
|
||||
* *contractsRepositoryUsername*: The user name to be used to connect to the repo with contracts.
|
||||
|
||||
@@ -81,8 +81,10 @@ public class AetherStubDownloader implements StubDownloader {
|
||||
private final RepositorySystemSession session;
|
||||
private final boolean workOffline;
|
||||
private final boolean snapshotCheckSkip;
|
||||
private final boolean deleteStubsAfterTest;
|
||||
|
||||
public AetherStubDownloader(StubRunnerOptions stubRunnerOptions) {
|
||||
this.deleteStubsAfterTest = stubRunnerOptions.isDeleteStubsAfterTest();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Will be resolving versions for the following options: [" + stubRunnerOptions + "]");
|
||||
}
|
||||
@@ -122,6 +124,7 @@ public class AetherStubDownloader implements StubDownloader {
|
||||
*/
|
||||
public AetherStubDownloader(RepositorySystem repositorySystem,
|
||||
List<RemoteRepository> remoteRepositories, RepositorySystemSession session) {
|
||||
this.deleteStubsAfterTest = true;
|
||||
this.remoteRepos = remoteRepositories;
|
||||
this.repositorySystem = repositorySystem;
|
||||
this.session = session;
|
||||
@@ -303,6 +306,9 @@ public class AetherStubDownloader implements StubDownloader {
|
||||
}
|
||||
|
||||
private void cleanup() {
|
||||
if (!this.deleteStubsAfterTest) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
for (File file : TEMP_FILES_LOG) {
|
||||
if (file.isDirectory()) {
|
||||
|
||||
@@ -75,7 +75,9 @@ public class ClasspathStubProvider implements StubDownloaderBuilder {
|
||||
throw new IllegalStateException("No stubs were found on classpath for [" + config.getGroupId() + ":" + config.getArtifactId() + "]");
|
||||
}
|
||||
final File tmp = createTempDir();
|
||||
tmp.deleteOnExit();
|
||||
if (stubRunnerOptions.isDeleteStubsAfterTest()) {
|
||||
tmp.deleteOnExit();
|
||||
}
|
||||
Pattern groupAndArtifactPattern = Pattern.compile(
|
||||
"^(.*)(" + config.getGroupId() + "." + config.getArtifactId() + ")(.*)$");
|
||||
String version = config.getVersion();
|
||||
|
||||
@@ -97,12 +97,19 @@ public class StubRunnerOptions {
|
||||
*/
|
||||
private boolean snapshotCheckSkip;
|
||||
|
||||
/**
|
||||
* If set to {@code false} will NOT delete stubs from a temporary
|
||||
* folder after running tests
|
||||
*/
|
||||
private boolean deleteStubsAfterTest;
|
||||
|
||||
StubRunnerOptions(Integer minPortValue, Integer maxPortValue,
|
||||
String stubRepositoryRoot, StubRunnerProperties.StubsMode stubsMode, String stubsClassifier,
|
||||
Collection<StubConfiguration> dependencies,
|
||||
Map<StubConfiguration, Integer> stubIdsToPortMapping,
|
||||
String username, String password, final StubRunnerProxyOptions stubRunnerProxyOptions,
|
||||
boolean stubsPerConsumer, String consumerName, String mappingsOutputFolder, boolean snapshotCheckSkip) {
|
||||
boolean stubsPerConsumer, String consumerName, String mappingsOutputFolder, boolean snapshotCheckSkip,
|
||||
boolean deleteStubsAfterTest) {
|
||||
this.minPortValue = minPortValue;
|
||||
this.maxPortValue = maxPortValue;
|
||||
this.stubRepositoryRoot = stubRepositoryRoot;
|
||||
@@ -117,6 +124,7 @@ public class StubRunnerOptions {
|
||||
this.consumerName = consumerName;
|
||||
this.mappingsOutputFolder = mappingsOutputFolder;
|
||||
this.snapshotCheckSkip = snapshotCheckSkip;
|
||||
this.deleteStubsAfterTest = deleteStubsAfterTest;
|
||||
}
|
||||
|
||||
public Integer port(StubConfiguration stubConfiguration) {
|
||||
@@ -141,7 +149,8 @@ public class StubRunnerOptions {
|
||||
.withStubPerConsumer(Boolean.parseBoolean(System.getProperty("stubrunner.stubs-per-consumer", "false")))
|
||||
.withConsumerName(System.getProperty("stubrunner.consumer-name"))
|
||||
.withMappingsOutputFolder(System.getProperty("stubrunner.mappings-output-folder"))
|
||||
.withSnapshotCheckSkip(Boolean.parseBoolean(System.getProperty("stubrunner.snapshot-check-skip", "false")));
|
||||
.withSnapshotCheckSkip(Boolean.parseBoolean(System.getProperty("stubrunner.snapshot-check-skip", "false")))
|
||||
.withDeleteStubsAfterTest(Boolean.parseBoolean(System.getProperty("stubrunner.delete-stubs-after-test", "true")));
|
||||
String proxyHost = System.getProperty("stubrunner.proxy.host");
|
||||
if (proxyHost != null) {
|
||||
builder.withProxy(proxyHost, Integer.parseInt(System.getProperty("stubrunner.proxy.port")));
|
||||
@@ -229,6 +238,14 @@ public class StubRunnerOptions {
|
||||
this.snapshotCheckSkip = snapshotCheckSkip;
|
||||
}
|
||||
|
||||
public boolean isDeleteStubsAfterTest() {
|
||||
return this.deleteStubsAfterTest;
|
||||
}
|
||||
|
||||
public void setDeleteStubsAfterTest(boolean deleteStubsAfterTest) {
|
||||
this.deleteStubsAfterTest = deleteStubsAfterTest;
|
||||
}
|
||||
|
||||
public static class StubRunnerProxyOptions {
|
||||
|
||||
private final String proxyHost;
|
||||
|
||||
@@ -48,6 +48,7 @@ public class StubRunnerOptionsBuilder {
|
||||
private String mappingsOutputFolder;
|
||||
private StubRunnerProperties.StubsMode stubsMode;
|
||||
private boolean snapshotCheckSkip = false;
|
||||
private boolean deleteStubsAfterTest = true;
|
||||
|
||||
public StubRunnerOptionsBuilder() {
|
||||
}
|
||||
@@ -127,6 +128,7 @@ public class StubRunnerOptionsBuilder {
|
||||
this.stubIdsToPortMapping = options.stubIdsToPortMapping != null ?
|
||||
options.stubIdsToPortMapping : new LinkedHashMap<StubConfiguration, Integer>();
|
||||
this.snapshotCheckSkip = options.isSnapshotCheckSkip();
|
||||
this.deleteStubsAfterTest = options.isDeleteStubsAfterTest();
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -140,11 +142,16 @@ public class StubRunnerOptionsBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public StubRunnerOptionsBuilder withDeleteStubsAfterTest(boolean deleteStubsAfterTest) {
|
||||
this.deleteStubsAfterTest = deleteStubsAfterTest;
|
||||
return this;
|
||||
}
|
||||
|
||||
public StubRunnerOptions build() {
|
||||
return new StubRunnerOptions(this.minPortValue, this.maxPortValue, this.stubRepositoryRoot,
|
||||
this.stubsMode, this.stubsClassifier, buildDependencies(), this.stubIdsToPortMapping,
|
||||
this.username, this.password, this.stubRunnerProxyOptions, this.stubsPerConsumer, this.consumerName,
|
||||
this.mappingsOutputFolder, this.snapshotCheckSkip);
|
||||
this.mappingsOutputFolder, this.snapshotCheckSkip, this.deleteStubsAfterTest);
|
||||
}
|
||||
|
||||
private Collection<StubConfiguration> buildDependencies() {
|
||||
|
||||
@@ -159,6 +159,12 @@ public class StubRunnerRule implements TestRule, StubFinder, StubRunnerRuleOptio
|
||||
return this.delegate;
|
||||
}
|
||||
|
||||
@Override public StubRunnerRule withDeleteStubsAfterTest(
|
||||
boolean deleteStubsAfterTest) {
|
||||
builder().withDeleteStubsAfterTest(deleteStubsAfterTest);
|
||||
return this.delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL findStubUrl(String groupId, String artifactId) {
|
||||
return this.stubFinder().findStubUrl(groupId, artifactId);
|
||||
|
||||
@@ -99,4 +99,10 @@ interface StubRunnerRuleOptions {
|
||||
* JAR was downloaded from a remote location or a local one
|
||||
*/
|
||||
StubRunnerRule withSnapshotCheckSkip(boolean snapshotCheckSkip);
|
||||
|
||||
/**
|
||||
* If set to {@code false} will NOT delete stubs from a temporary
|
||||
* folder after running tests
|
||||
*/
|
||||
StubRunnerRule withDeleteStubsAfterTest(boolean deleteStubsAfterTest);
|
||||
}
|
||||
|
||||
@@ -94,7 +94,8 @@ public class StubRunnerConfiguration {
|
||||
.withStubPerConsumer(this.props.isStubsPerConsumer())
|
||||
.withConsumerName(consumerName())
|
||||
.withMappingsOutputFolder(this.props.getMappingsOutputFolder())
|
||||
.withSnapshotCheckSkip(this.props.isSnapshotCheckSkip());
|
||||
.withSnapshotCheckSkip(this.props.isSnapshotCheckSkip())
|
||||
.withDeleteStubsAfterTest(this.props.isDeleteStubsAfterTest());
|
||||
}
|
||||
|
||||
private String consumerName() {
|
||||
|
||||
@@ -101,6 +101,12 @@ public class StubRunnerProperties {
|
||||
*/
|
||||
private boolean snapshotCheckSkip;
|
||||
|
||||
/**
|
||||
* If set to {@code false} will NOT delete stubs from a temporary
|
||||
* folder after running tests
|
||||
*/
|
||||
private boolean deleteStubsAfterTest = true;
|
||||
|
||||
/**
|
||||
* An enumeration stub modes.
|
||||
*/
|
||||
@@ -238,6 +244,14 @@ public class StubRunnerProperties {
|
||||
this.snapshotCheckSkip = snapshotCheckSkip;
|
||||
}
|
||||
|
||||
public boolean isDeleteStubsAfterTest() {
|
||||
return this.deleteStubsAfterTest;
|
||||
}
|
||||
|
||||
public void setDeleteStubsAfterTest(boolean deleteStubsAfterTest) {
|
||||
this.deleteStubsAfterTest = deleteStubsAfterTest;
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
return "StubRunnerProperties{" + "minPort=" + this.minPort + ", maxPort=" + this.maxPort
|
||||
+ ", repositoryRoot=" + this.repositoryRoot
|
||||
|
||||
@@ -162,6 +162,12 @@ class ContractVerifierExtension {
|
||||
*/
|
||||
boolean contractsSnapshotCheckSkip = false
|
||||
|
||||
/**
|
||||
* If set to {@code false} will NOT delete stubs from a temporary
|
||||
* folder after running tests
|
||||
*/
|
||||
boolean deleteStubsAfterTest = true
|
||||
|
||||
void contractDependency(@DelegatesTo(Dependency) Closure closure) {
|
||||
closure.delegate = contractDependency
|
||||
closure.call()
|
||||
|
||||
@@ -83,6 +83,7 @@ class GradleContractsDownloader {
|
||||
.withUsername(extension.contractRepository.username)
|
||||
.withPassword(extension.contractRepository.password)
|
||||
.withSnapshotCheckSkip(extension.contractsSnapshotCheckSkip)
|
||||
.withDeleteStubsAfterTest(extension.deleteStubsAfterTests)
|
||||
if (extension.contractRepository.proxyPort) {
|
||||
options = options.withProxy(extension.contractRepository.proxyHost, extension.contractRepository.proxyPort)
|
||||
}
|
||||
|
||||
@@ -148,6 +148,13 @@ public class ConvertMojo extends AbstractMojo {
|
||||
@Parameter(property = "contractsSnapshotCheckSkip", defaultValue = "false")
|
||||
private boolean contractsSnapshotCheckSkip;
|
||||
|
||||
/**
|
||||
* If set to {@code false} will NOT delete stubs from a temporary
|
||||
* folder after running tests
|
||||
*/
|
||||
@Parameter(property = "deleteStubsAfterTest", defaultValue = "true")
|
||||
private boolean deleteStubsAfterTest;
|
||||
|
||||
@Component(role = MavenResourcesFiltering.class, hint = "default")
|
||||
private MavenResourcesFiltering mavenResourcesFiltering;
|
||||
|
||||
@@ -176,7 +183,7 @@ public class ConvertMojo extends AbstractMojo {
|
||||
this.contractsPath, this.contractsRepositoryUrl, this.contractsMode, getLog(),
|
||||
this.aetherStubDownloaderFactory, this.repoSession, this.contractsRepositoryUsername,
|
||||
this.contractsRepositoryPassword, this.contractsRepositoryProxyHost, this.contractsRepositoryProxyPort,
|
||||
this.contractsSnapshotCheckSkip)
|
||||
this.contractsSnapshotCheckSkip, this.deleteStubsAfterTest)
|
||||
.downloadAndUnpackContractsIfRequired(config, this.contractsDirectory);
|
||||
getLog().info("Directory with contract is present at [" + contractsDirectory + "]");
|
||||
|
||||
|
||||
@@ -203,6 +203,13 @@ public class GenerateTestsMojo extends AbstractMojo {
|
||||
@Parameter(property = "contractsSnapshotCheckSkip", defaultValue = "false")
|
||||
private boolean contractsSnapshotCheckSkip;
|
||||
|
||||
/**
|
||||
* If set to {@code false} will NOT delete stubs from a temporary
|
||||
* folder after running tests
|
||||
*/
|
||||
@Parameter(property = "deleteStubsAfterTest", defaultValue = "true")
|
||||
private boolean deleteStubsAfterTest;
|
||||
|
||||
private final AetherStubDownloaderFactory aetherStubDownloaderFactory;
|
||||
|
||||
@Inject
|
||||
@@ -226,7 +233,7 @@ public class GenerateTestsMojo extends AbstractMojo {
|
||||
this.aetherStubDownloaderFactory, this.repoSession,
|
||||
this.contractsRepositoryUsername, this.contractsRepositoryPassword,
|
||||
this.contractsRepositoryProxyHost, this.contractsRepositoryProxyPort,
|
||||
this.contractsSnapshotCheckSkip).downloadAndUnpackContractsIfRequired(config, this.contractsDirectory);
|
||||
this.contractsSnapshotCheckSkip, this.deleteStubsAfterTest).downloadAndUnpackContractsIfRequired(config, this.contractsDirectory);
|
||||
getLog().info("Directory with contract is present at [" + contractsDirectory + "]");
|
||||
setupConfig(config, contractsDirectory);
|
||||
this.project.addTestCompileSourceRoot(this.generatedTestSourcesDir.getAbsolutePath());
|
||||
|
||||
@@ -45,6 +45,7 @@ class MavenContractsDownloader {
|
||||
private final String repositoryProxyHost;
|
||||
private final Integer repositoryProxyPort;
|
||||
private final boolean contractsSnapshotCheckSkip;
|
||||
private final boolean deleteStubsAfterTest;
|
||||
|
||||
MavenContractsDownloader(MavenProject project, Dependency contractDependency,
|
||||
String contractsPath, String contractsRepositoryUrl,
|
||||
@@ -52,7 +53,8 @@ class MavenContractsDownloader {
|
||||
AetherStubDownloaderFactory aetherStubDownloaderFactory,
|
||||
RepositorySystemSession repoSession, String repositoryUsername,
|
||||
String repositoryPassword, String repositoryProxyHost,
|
||||
Integer repositoryProxyPort, boolean contractsSnapshotCheckSkip) {
|
||||
Integer repositoryProxyPort, boolean contractsSnapshotCheckSkip,
|
||||
boolean deleteStubsAfterTest) {
|
||||
this.project = project;
|
||||
this.contractDependency = contractDependency;
|
||||
this.contractsPath = contractsPath;
|
||||
@@ -67,6 +69,7 @@ class MavenContractsDownloader {
|
||||
this.repositoryProxyPort = repositoryProxyPort;
|
||||
this.stubDownloaderBuilderProvider = new StubDownloaderBuilderProvider();
|
||||
this.contractsSnapshotCheckSkip = contractsSnapshotCheckSkip;
|
||||
this.deleteStubsAfterTest = deleteStubsAfterTest;
|
||||
}
|
||||
|
||||
File downloadAndUnpackContractsIfRequired(ContractVerifierConfigProperties config, File defaultContractsDir) {
|
||||
@@ -142,7 +145,8 @@ class MavenContractsDownloader {
|
||||
.withStubsMode(this.stubsMode)
|
||||
.withUsername(this.repositoryUsername)
|
||||
.withPassword(this.repositoryPassword)
|
||||
.withSnapshotCheckSkip(this.contractsSnapshotCheckSkip);
|
||||
.withSnapshotCheckSkip(this.contractsSnapshotCheckSkip)
|
||||
.withDeleteStubsAfterTest(this.deleteStubsAfterTest);
|
||||
if (this.repositoryProxyPort != null) {
|
||||
builder.withProxy(this.repositoryProxyHost, this.repositoryProxyPort);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user