159 lines
8.5 KiB
HTML
159 lines
8.5 KiB
HTML
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../.resources/report.css" type="text/css"/><link rel="shortcut icon" href="../.resources/report.gif" type="image/gif"/><title>GenerateTestsMojo.java</title><link rel="stylesheet" href="../.resources/prettify.css" type="text/css"/><script type="text/javascript" src="../.resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../.sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">Spring Cloud Contract Maven Plugin</a> > <a href="index.source.html" class="el_package">org.springframework.cloud.contract.maven.verifier</a> > <span class="el_source">GenerateTestsMojo.java</span></div><h1>GenerateTestsMojo.java</h1><pre class="source lang-java linenums">/*
|
|
* Copyright 2013-2016 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.cloud.contract.maven.verifier;
|
|
|
|
import java.io.File;
|
|
import java.util.List;
|
|
|
|
import org.apache.maven.plugin.AbstractMojo;
|
|
import org.apache.maven.plugin.MojoExecutionException;
|
|
import org.apache.maven.plugin.MojoFailureException;
|
|
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
|
import org.apache.maven.plugins.annotations.Mojo;
|
|
import org.apache.maven.plugins.annotations.Parameter;
|
|
import org.apache.maven.plugins.annotations.ResolutionScope;
|
|
import org.apache.maven.project.MavenProject;
|
|
import org.springframework.cloud.contract.spec.ContractVerifierException;
|
|
import org.springframework.cloud.contract.verifier.TestGenerator;
|
|
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties;
|
|
import org.springframework.cloud.contract.verifier.config.TestFramework;
|
|
import org.springframework.cloud.contract.verifier.config.TestMode;
|
|
|
|
@Mojo(name = "generateTests", defaultPhase = LifecyclePhase.GENERATE_TEST_SOURCES,
|
|
requiresDependencyResolution = ResolutionScope.TEST)
|
|
<span class="fc" id="L37">public class GenerateTestsMojo extends AbstractMojo {</span>
|
|
|
|
@Parameter(property = "spring.cloud.contract.verifier.contractsDirectory",
|
|
defaultValue = "${project.basedir}/src/test/resources/contracts")
|
|
private File contractsDirectory;
|
|
|
|
@Parameter(
|
|
defaultValue = "${project.build.directory}/generated-test-sources/contracts")
|
|
private File generatedTestSourcesDir;
|
|
|
|
@Parameter(defaultValue = "org.springframework.cloud.contract.verifier.tests")
|
|
private String basePackageForTests;
|
|
|
|
@Parameter
|
|
private String baseClassForTests;
|
|
|
|
@Parameter(defaultValue = "MOCKMVC")
|
|
private TestMode testMode;
|
|
|
|
@Parameter(defaultValue = "JUNIT")
|
|
private TestFramework testFramework;
|
|
|
|
@Parameter
|
|
private String ruleClassForTests;
|
|
|
|
@Parameter
|
|
private String nameSuffixForTests;
|
|
|
|
/**
|
|
* Imports that should be added to generated tests
|
|
*/
|
|
@Parameter
|
|
private String[] imports;
|
|
|
|
/**
|
|
* Static imports that should be added to generated tests
|
|
*/
|
|
@Parameter
|
|
private String[] staticImports;
|
|
|
|
/**
|
|
* Patterns that should not be taken into account for processing
|
|
*/
|
|
@Parameter
|
|
private List<String> excludedFiles;
|
|
|
|
/**
|
|
* Patterns for which Spring Cloud Contract Verifier should generate @Ignored tests
|
|
*/
|
|
@Parameter
|
|
private List<String> ignoredFiles;
|
|
|
|
@Parameter(defaultValue = "${project}", readonly = true)
|
|
private MavenProject project;
|
|
|
|
@Parameter(property = "spring.cloud.contract.verifier.skip", defaultValue = "false")
|
|
private boolean skip;
|
|
|
|
@Parameter(property = "maven.test.skip", defaultValue = "false")
|
|
private boolean mavenTestSkip;
|
|
|
|
@Parameter(property = "skipTests", defaultValue = "false") private boolean skipTests;
|
|
|
|
public void execute() throws MojoExecutionException, MojoFailureException {
|
|
<span class="pc bpc" id="L101" title="3 of 6 branches missed."> if (skip || mavenTestSkip || skipTests) {</span>
|
|
<span class="nc bnc" id="L102" title="All 2 branches missed."> if (skip) getLog().info("Skipping Spring Cloud Contract Verifier execution: spring.cloud.contract.verifier.skip=" + skip);</span>
|
|
<span class="nc bnc" id="L103" title="All 2 branches missed."> if (mavenTestSkip) getLog().info("Skipping Spring Cloud Contract Verifier execution: maven.test.skip=" + mavenTestSkip);</span>
|
|
<span class="nc bnc" id="L104" title="All 2 branches missed."> if (skipTests) getLog().info("Skipping Spring Cloud Contract Verifier execution: skipTests" + skipTests);</span>
|
|
<span class="nc" id="L105"> return;</span>
|
|
}
|
|
<span class="fc" id="L107"> getLog().info(</span>
|
|
"Generating server tests source code for Spring Cloud Contract Verifier contract verification");
|
|
<span class="fc" id="L109"> final ContractVerifierConfigProperties config = new ContractVerifierConfigProperties();</span>
|
|
<span class="fc" id="L110"> config.setContractsDslDir(contractsDirectory);</span>
|
|
<span class="fc" id="L111"> config.setGeneratedTestSourcesDir(generatedTestSourcesDir);</span>
|
|
<span class="fc" id="L112"> config.setTargetFramework(testFramework);</span>
|
|
<span class="fc" id="L113"> config.setTestMode(testMode);</span>
|
|
<span class="fc" id="L114"> config.setBasePackageForTests(basePackageForTests);</span>
|
|
<span class="fc" id="L115"> config.setBaseClassForTests(baseClassForTests);</span>
|
|
<span class="fc" id="L116"> config.setRuleClassForTests(ruleClassForTests);</span>
|
|
<span class="fc" id="L117"> config.setNameSuffixForTests(nameSuffixForTests);</span>
|
|
<span class="fc" id="L118"> config.setImports(imports);</span>
|
|
<span class="fc" id="L119"> config.setStaticImports(staticImports);</span>
|
|
<span class="fc" id="L120"> config.setIgnoredFiles(ignoredFiles);</span>
|
|
<span class="fc" id="L121"> config.setExcludedFiles(excludedFiles);</span>
|
|
<span class="fc" id="L122"> project.addTestCompileSourceRoot(generatedTestSourcesDir.getAbsolutePath());</span>
|
|
<span class="pc bpc" id="L123" title="1 of 2 branches missed."> if (getLog().isInfoEnabled()) {</span>
|
|
<span class="fc" id="L124"> getLog().info(</span>
|
|
<span class="fc" id="L125"> "Test Source directory: " + generatedTestSourcesDir.getAbsolutePath()</span>
|
|
+ " added.");
|
|
<span class="fc" id="L127"> getLog().info("Using " + config.getBaseClassForTests()</span>
|
|
+ " as base class for test classes");
|
|
}
|
|
try {
|
|
<span class="fc" id="L131"> TestGenerator generator = new TestGenerator(config);</span>
|
|
<span class="fc" id="L132"> int generatedClasses = generator.generate();</span>
|
|
<span class="fc" id="L133"> getLog().info("Generated " + generatedClasses + " test classes.");</span>
|
|
}
|
|
<span class="nc" id="L135"> catch (ContractVerifierException e) {</span>
|
|
<span class="nc" id="L136"> throw new MojoExecutionException(</span>
|
|
<span class="nc" id="L137"> String.format("Spring Cloud Contract Verifier Plugin exception: %s",</span>
|
|
<span class="nc" id="L138"> e.getMessage()), e);</span>
|
|
<span class="fc" id="L139"> }</span>
|
|
<span class="fc" id="L140"> }</span>
|
|
|
|
public List<String> getExcludedFiles() {
|
|
<span class="nc" id="L143"> return excludedFiles;</span>
|
|
}
|
|
|
|
public void setExcludedFiles(List<String> excludedFiles) {
|
|
<span class="nc" id="L147"> this.excludedFiles = excludedFiles;</span>
|
|
<span class="nc" id="L148"> }</span>
|
|
|
|
public List<String> getIgnoredFiles() {
|
|
<span class="nc" id="L151"> return ignoredFiles;</span>
|
|
}
|
|
|
|
public void setIgnoredFiles(List<String> ignoredFiles) {
|
|
<span class="nc" id="L155"> this.ignoredFiles = ignoredFiles;</span>
|
|
<span class="nc" id="L156"> }</span>
|
|
|
|
}
|
|
</pre><div class="footer"><span class="right">Created with <a href="http://www.eclemma.org/jacoco">JaCoCo</a> 0.7.4.201502262128</span></div></body></html> |