Applied checkstyle rules

This commit is contained in:
Marcin Grzejszczak
2016-08-29 12:04:21 +02:00
parent c7a44b92ae
commit bfc2172d66
86 changed files with 509 additions and 482 deletions

View File

@@ -77,20 +77,20 @@ public class ConvertMojo extends AbstractMojo {
public void execute() throws MojoExecutionException, MojoFailureException {
if (skip) {
if (this.skip) {
getLog().info(String.format(
"Skipping Spring Cloud Contract Verifier execution: spring.cloud.contract.verifier.skip=%s",
skip));
this.skip));
return;
}
new CopyContracts(project, mavenSession, mavenResourcesFiltering)
.copy(contractsDirectory, outputDirectory);
new CopyContracts(this.project, this.mavenSession, this.mavenResourcesFiltering)
.copy(this.contractsDirectory, this.outputDirectory);
final ContractVerifierConfigProperties config = new ContractVerifierConfigProperties();
config.setContractsDslDir(isInsideProject() ? contractsDirectory : source);
config.setContractsDslDir(isInsideProject() ? this.contractsDirectory : this.source);
config.setStubsOutputDir(
isInsideProject() ? new File(outputDirectory, "mappings") : destination);
isInsideProject() ? new File(this.outputDirectory, "mappings") : this.destination);
getLog().info(
"Converting from Spring Cloud Contract Verifier contracts to WireMock stubs mappings");
@@ -106,7 +106,7 @@ public class ConvertMojo extends AbstractMojo {
}
private boolean isInsideProject() {
return mavenSession.getRequest().isProjectPresent();
return this.mavenSession.getRequest().isProjectPresent();
}
}

View File

@@ -51,15 +51,15 @@ class CopyContracts {
MavenResourcesExecution execution = new MavenResourcesExecution();
execution.setResources(Collections.singletonList(resource));
execution.setOutputDirectory(new File(outputDirectory, "contracts"));
execution.setMavenProject(project);
execution.setMavenProject(this.project);
execution.setEncoding("UTF-8");
execution.setMavenSession(mavenSession);
execution.setMavenSession(this.mavenSession);
execution.setInjectProjectBuildFilters(false);
execution.setOverwrite(true);
execution.setIncludeEmptyDirs(false);
execution.setFilterFilenames(false);
try {
mavenResourcesFiltering.filterResources(execution);
this.mavenResourcesFiltering.filterResources(execution);
}
catch (MavenFilteringException e) {
throw new MojoExecutionException(e.getMessage(), e);

View File

@@ -66,14 +66,14 @@ public class GenerateStubsMojo extends AbstractMojo {
private String classifier;
public void execute() throws MojoExecutionException, MojoFailureException {
if (skip) {
if (this.skip) {
getLog().info(
"Skipping Spring Cloud Contract Verifier execution: spring.cloud.contract.verifier.skip="
+ skip);
+ this.skip);
return;
}
File stubsJarFile = createStubJar(outputDirectory);
projectHelper.attachArtifact(project, "jar", classifier, stubsJarFile);
File stubsJarFile = createStubJar(this.outputDirectory);
this.projectHelper.attachArtifact(this.project, "jar", this.classifier, stubsJarFile);
}
private File createStubJar(File stubsOutputDir)
@@ -84,29 +84,29 @@ public class GenerateStubsMojo extends AbstractMojo {
+ "] .\nPlease make sure that spring-cloud-contract:convert was invoked");
}
String stubArchiveName =
project.getBuild().getFinalName() + "-" + classifier + ".jar";
File stubsJarFile = new File(projectBuildDirectory, stubArchiveName);
this.project.getBuild().getFinalName() + "-" + this.classifier + ".jar";
File stubsJarFile = new File(this.projectBuildDirectory, stubArchiveName);
try {
if (attachContracts) {
archiver.addDirectory(stubsOutputDir,
if (this.attachContracts) {
this.archiver.addDirectory(stubsOutputDir,
new String[] { STUB_MAPPING_FILE_PATTERN, CONTRACT_FILE_PATTERN },
new String[0]);
}
else {
getLog().info(
"Skipping attaching Spring Cloud Contract Verifier contracts");
archiver.addDirectory(stubsOutputDir,
this.archiver.addDirectory(stubsOutputDir,
new String[] { STUB_MAPPING_FILE_PATTERN },
new String[] { CONTRACT_FILE_PATTERN });
}
archiver.setCompress(true);
archiver.setDestFile(stubsJarFile);
archiver.addConfiguredManifest(ManifestCreator.createManifest(project));
archiver.createArchive();
this.archiver.setCompress(true);
this.archiver.setDestFile(stubsJarFile);
this.archiver.addConfiguredManifest(ManifestCreator.createManifest(this.project));
this.archiver.createArchive();
}
catch (Exception e) {
throw new MojoFailureException(
"Exception while packaging " + classifier + " jar.", e);
"Exception while packaging " + this.classifier + " jar.", e);
}
return stubsJarFile;
}

View File

@@ -106,32 +106,32 @@ public class GenerateTestsMojo extends AbstractMojo {
@Parameter(property = "skipTests", defaultValue = "false") private boolean skipTests;
public void execute() throws MojoExecutionException, MojoFailureException {
if (skip || mavenTestSkip || skipTests) {
if (skip) getLog().info("Skipping Spring Cloud Contract Verifier execution: spring.cloud.contract.verifier.skip=" + skip);
if (mavenTestSkip) getLog().info("Skipping Spring Cloud Contract Verifier execution: maven.test.skip=" + mavenTestSkip);
if (skipTests) getLog().info("Skipping Spring Cloud Contract Verifier execution: skipTests" + skipTests);
if (this.skip || this.mavenTestSkip || this.skipTests) {
if (this.skip) getLog().info("Skipping Spring Cloud Contract Verifier execution: spring.cloud.contract.verifier.skip=" + this.skip);
if (this.mavenTestSkip) getLog().info("Skipping Spring Cloud Contract Verifier execution: maven.test.skip=" + this.mavenTestSkip);
if (this.skipTests) getLog().info("Skipping Spring Cloud Contract Verifier execution: skipTests" + this.skipTests);
return;
}
getLog().info(
"Generating server tests source code for Spring Cloud Contract Verifier contract verification");
final ContractVerifierConfigProperties config = new ContractVerifierConfigProperties();
config.setContractsDslDir(contractsDirectory);
config.setGeneratedTestSourcesDir(generatedTestSourcesDir);
config.setTargetFramework(testFramework);
config.setTestMode(testMode);
config.setBasePackageForTests(basePackageForTests);
config.setBaseClassForTests(baseClassForTests);
config.setRuleClassForTests(ruleClassForTests);
config.setNameSuffixForTests(nameSuffixForTests);
config.setImports(imports);
config.setStaticImports(staticImports);
config.setIgnoredFiles(ignoredFiles);
config.setExcludedFiles(excludedFiles);
config.setAssertJsonSize(assertJsonSize);
project.addTestCompileSourceRoot(generatedTestSourcesDir.getAbsolutePath());
config.setContractsDslDir(this.contractsDirectory);
config.setGeneratedTestSourcesDir(this.generatedTestSourcesDir);
config.setTargetFramework(this.testFramework);
config.setTestMode(this.testMode);
config.setBasePackageForTests(this.basePackageForTests);
config.setBaseClassForTests(this.baseClassForTests);
config.setRuleClassForTests(this.ruleClassForTests);
config.setNameSuffixForTests(this.nameSuffixForTests);
config.setImports(this.imports);
config.setStaticImports(this.staticImports);
config.setIgnoredFiles(this.ignoredFiles);
config.setExcludedFiles(this.excludedFiles);
config.setAssertJsonSize(this.assertJsonSize);
this.project.addTestCompileSourceRoot(this.generatedTestSourcesDir.getAbsolutePath());
if (getLog().isInfoEnabled()) {
getLog().info(
"Test Source directory: " + generatedTestSourcesDir.getAbsolutePath()
"Test Source directory: " + this.generatedTestSourcesDir.getAbsolutePath()
+ " added.");
getLog().info("Using " + config.getBaseClassForTests()
+ " as base class for test classes");
@@ -149,7 +149,7 @@ public class GenerateTestsMojo extends AbstractMojo {
}
public List<String> getExcludedFiles() {
return excludedFiles;
return this.excludedFiles;
}
public void setExcludedFiles(List<String> excludedFiles) {
@@ -157,7 +157,7 @@ public class GenerateTestsMojo extends AbstractMojo {
}
public List<String> getIgnoredFiles() {
return ignoredFiles;
return this.ignoredFiles;
}
public void setIgnoredFiles(List<String> ignoredFiles) {
@@ -165,7 +165,7 @@ public class GenerateTestsMojo extends AbstractMojo {
}
public boolean isAssertJsonSize() {
return assertJsonSize;
return this.assertJsonSize;
}
public void setAssertJsonSize(boolean assertJsonSize) {

View File

@@ -97,25 +97,25 @@ public class RunMojo extends AbstractMojo {
}
public void execute() throws MojoExecutionException, MojoFailureException {
if (skip || skipTestOnly) {
getLog().info("Skipping verifier execution: spring.cloud.contract.verifier.skip=" + skip);
if (this.skip || this.skipTestOnly) {
getLog().info("Skipping verifier execution: spring.cloud.contract.verifier.skip=" + this.skip);
return;
}
BatchStubRunner batchStubRunner = null;
StubRunnerOptionsBuilder optionsBuilder = new StubRunnerOptionsBuilder()
.withStubsClassifier(stubsClassifier);
if (isNullOrEmpty(stubs)) {
.withStubsClassifier(this.stubsClassifier);
if (isNullOrEmpty(this.stubs)) {
StubRunnerOptions options = optionsBuilder
.withPort(httpPort)
.withPort(this.httpPort)
.build();
StubRunner stubRunner = localStubRunner.run(resolveStubsDirectory().getAbsolutePath(), options);
StubRunner stubRunner = this.localStubRunner.run(resolveStubsDirectory().getAbsolutePath(), options);
batchStubRunner = new BatchStubRunner(Collections.singleton(stubRunner));
} else {
StubRunnerOptions options = optionsBuilder
.withStubs(stubs)
.withMinMaxPort(minPort, maxPort)
.withStubs(this.stubs)
.withMinMaxPort(this.minPort, this.maxPort)
.build();
batchStubRunner = remoteStubRunner.run(options, repoSession);
batchStubRunner = this.remoteStubRunner.run(options, this.repoSession);
}
pressAnyKeyToContinue();
if (batchStubRunner != null) {
@@ -129,9 +129,9 @@ public class RunMojo extends AbstractMojo {
private File resolveStubsDirectory() {
if (isInsideProject()) {
return stubsDirectory;
return this.stubsDirectory;
} else {
return destination;
return this.destination;
}
}
@@ -144,7 +144,7 @@ public class RunMojo extends AbstractMojo {
}
private boolean isInsideProject() {
return mavenSession.getRequest().isProjectPresent();
return this.mavenSession.getRequest().isProjectPresent();
}
}

View File

@@ -38,7 +38,7 @@ public class AetherStubDownloaderFactory {
}
public AetherStubDownloader build(RepositorySystemSession repoSession) {
return new AetherStubDownloader(repoSystem,
project.getRemoteProjectRepositories(), repoSession);
return new AetherStubDownloader(this.repoSystem,
this.project.getRemoteProjectRepositories(), repoSession);
}
}

View File

@@ -39,7 +39,7 @@ public class RemoteStubRunner {
}
public BatchStubRunner run(StubRunnerOptions options, RepositorySystemSession repositorySystemSession) {
AetherStubDownloader stubDownloader = aetherStubDownloaderFactory.build(repositorySystemSession);
AetherStubDownloader stubDownloader = this.aetherStubDownloaderFactory.build(repositorySystemSession);
try {
if (log.isDebugEnabled()) {
log.debug("Launching StubRunner with args: " + options);

View File

@@ -46,8 +46,8 @@ public class PluginIT {
@Test
public void should_build_project_Spring_Boot_Groovy_with_Accurest() throws Exception {
File basedir = resources.getBasedir("spring-boot-groovy");
maven.forProject(basedir)
File basedir = this.resources.getBasedir("spring-boot-groovy");
this.maven.forProject(basedir)
.execute("package")
.assertErrorFreeLog()
.assertLogText("Generating server tests source code for Spring Cloud Contract Verifier contract verification")
@@ -60,8 +60,8 @@ public class PluginIT {
@Test
public void should_build_project_Spring_Boot_Java_with_Accurest() throws Exception {
File basedir = resources.getBasedir("spring-boot-java");
maven.forProject(basedir)
File basedir = this.resources.getBasedir("spring-boot-java");
this.maven.forProject(basedir)
.execute("package")
.assertErrorFreeLog()
.assertLogText("Generating server tests source code for Spring Cloud Contract Verifier contract verification")
@@ -74,8 +74,8 @@ public class PluginIT {
@Test
public void should_build_project_with_plugin_extension() throws Exception {
File basedir = resources.getBasedir("plugin-extension");
maven.forProject(basedir)
File basedir = this.resources.getBasedir("plugin-extension");
this.maven.forProject(basedir)
.execute("package")
.assertErrorFreeLog()
.assertLogText("Generating server tests source code for Spring Cloud Contract Verifier contract verification")
@@ -89,8 +89,8 @@ public class PluginIT {
@Test
@Ignore("Ignored, because of bug accurest#245")
public void should_build_project_project_with_complex_configuration() throws Exception {
File basedir = resources.getBasedir("complex-configuration");
maven.forProject(basedir)
File basedir = this.resources.getBasedir("complex-configuration");
this.maven.forProject(basedir)
.execute("package")
.assertErrorFreeLog()
.assertLogText("Tests run: 2, Failures: 0, Errors: 0, Skipped: 1")
@@ -100,12 +100,12 @@ public class PluginIT {
@Test
public void should_convert_Accurest_Contracts_to_WireMock_Stubs_mappings() throws Exception {
File basedir = resources.getBasedir("pomless");
properties.getPluginVersion();
maven.forProject(basedir)
File basedir = this.resources.getBasedir("pomless");
this.properties.getPluginVersion();
this.maven.forProject(basedir)
.withCliOption("-X")
.execute(String.format("org.springframework.cloud:spring-cloud-contract-maven-plugin:%s:convert",
properties.getPluginVersion()))
this.properties.getPluginVersion()))
.assertLogText("Converting from Spring Cloud Contract Verifier contracts to WireMock stubs mappings")
.assertLogText("Creating new json")
.assertErrorFreeLog();

View File

@@ -40,62 +40,62 @@ public class PluginUnitTest {
@Test
public void shouldGenerateWireMockStubsInDefaultLocation() throws Exception {
File basedir = resources.getBasedir("basic");
maven.executeMojo(basedir, "convert");
File basedir = this.resources.getBasedir("basic");
this.maven.executeMojo(basedir, "convert");
assertFilesPresent(basedir, "target/stubs/mappings/Sample.json");
assertFilesNotPresent(basedir, "target/stubs/mappings/Messaging.json");
}
@Test
public void shouldGenerateWireMockFromStubsDirectory() throws Exception {
File basedir = resources.getBasedir("withStubs");
maven.executeMojo(basedir, "convert", newParameter("contractsDirectory", "src/test/resources/stubs"));
File basedir = this.resources.getBasedir("withStubs");
this.maven.executeMojo(basedir, "convert", newParameter("contractsDirectory", "src/test/resources/stubs"));
assertFilesPresent(basedir, "target/stubs/mappings/Sample.json");
}
@Test
public void shouldCopyContracts() throws Exception {
File basedir = resources.getBasedir("basic");
maven.executeMojo(basedir, "convert");
File basedir = this.resources.getBasedir("basic");
this.maven.executeMojo(basedir, "convert");
assertFilesPresent(basedir, "target/stubs/contracts/Sample.groovy");
assertFilesPresent(basedir, "target/stubs/contracts/Messaging.groovy");
}
@Test
public void shouldGenerateWireMockStubsInSelectedLocation() throws Exception {
File basedir = resources.getBasedir("basic");
maven.executeMojo(basedir, "convert", newParameter("outputDirectory", "target/foo"));
File basedir = this.resources.getBasedir("basic");
this.maven.executeMojo(basedir, "convert", newParameter("outputDirectory", "target/foo"));
assertFilesPresent(basedir, "target/foo/mappings/Sample.json");
}
@Test
public void shouldGenerateContractSpecificationInDefaultLocation() throws Exception {
File basedir = resources.getBasedir("basic");
maven.executeMojo(basedir, "generateTests", newParameter("testFramework", "SPOCK"));
File basedir = this.resources.getBasedir("basic");
this.maven.executeMojo(basedir, "generateTests", newParameter("testFramework", "SPOCK"));
assertFilesPresent(basedir,
"target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/ContractVerifierSpec.groovy");
}
@Test
public void shouldGenerateContractTestsInDefaultLocation() throws Exception {
File basedir = resources.getBasedir("basic");
maven.executeMojo(basedir, "generateTests");
File basedir = this.resources.getBasedir("basic");
this.maven.executeMojo(basedir, "generateTests");
assertFilesPresent(basedir,
"target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/ContractVerifierTest.java");
}
@Test
public void shouldGenerateContractTestsWithCustomImports() throws Exception {
File basedir = resources.getBasedir("basic");
maven.executeMojo(basedir, "generateTests", newParameter("imports", ""));
File basedir = this.resources.getBasedir("basic");
this.maven.executeMojo(basedir, "generateTests", newParameter("imports", ""));
assertFilesPresent(basedir,
"target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/ContractVerifierTest.java");
}
@Test
public void shouldGenerateContractTestsWithoutArraySize() throws Exception {
File basedir = resources.getBasedir("basic");
maven.executeMojo(basedir, "generateTests");
File basedir = this.resources.getBasedir("basic");
this.maven.executeMojo(basedir, "generateTests");
assertFilesPresent(basedir,
"target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/ContractVerifierTest.java");
File test = new File(basedir, "target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/ContractVerifierTest.java");
@@ -104,8 +104,8 @@ public class PluginUnitTest {
@Test
public void shouldGenerateContractTestsWithArraySize() throws Exception {
File basedir = resources.getBasedir("basic");
maven.executeMojo(basedir, "generateTests", newParameter("assertJsonSize", "true"));
File basedir = this.resources.getBasedir("basic");
this.maven.executeMojo(basedir, "generateTests", newParameter("assertJsonSize", "true"));
assertFilesPresent(basedir,
"target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/ContractVerifierTest.java");
File test = new File(basedir, "target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/ContractVerifierTest.java");
@@ -114,23 +114,23 @@ public class PluginUnitTest {
@Test
public void shouldGenerateStubs() throws Exception {
File basedir = resources.getBasedir("generatedStubs");
maven.executeMojo(basedir, "generateStubs");
File basedir = this.resources.getBasedir("generatedStubs");
this.maven.executeMojo(basedir, "generateStubs");
assertFilesPresent(basedir, "target/sample-project-0.1-stubs.jar");
}
@Test
public void shouldGenerateStubsWithMappingsOnly() throws Exception {
File basedir = resources.getBasedir("generatedStubs");
maven.executeMojo(basedir, "generateStubs", newParameter("attachContracts", "false"));
File basedir = this.resources.getBasedir("generatedStubs");
this.maven.executeMojo(basedir, "generateStubs", newParameter("attachContracts", "false"));
assertFilesPresent(basedir, "target/sample-project-0.1-stubs.jar");
// FIXME: add assertion for jar content
}
@Test
public void shouldGenerateStubsWithCustomClassifier() throws Exception {
File basedir = resources.getBasedir("generatedStubs");
maven.executeMojo(basedir, "generateStubs", newParameter("classifier", "foo"));
File basedir = this.resources.getBasedir("generatedStubs");
this.maven.executeMojo(basedir, "generateStubs", newParameter("classifier", "foo"));
assertFilesPresent(basedir, "target/sample-project-0.1-foo.jar");
}