Files
spring-cloud-contract/spring-cloud-contract-maven-plugin/jacoco/org.springframework.cloud.contract.maven.verifier/GenerateTestsMojo.java.html
2016-07-20 15:03:20 +02:00

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> &gt; <a href="index.source.html" class="el_package">org.springframework.cloud.contract.maven.verifier</a> &gt; <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 &quot;License&quot;);
* 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 &quot;AS IS&quot; 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 = &quot;generateTests&quot;, defaultPhase = LifecyclePhase.GENERATE_TEST_SOURCES,
requiresDependencyResolution = ResolutionScope.TEST)
<span class="fc" id="L37">public class GenerateTestsMojo extends AbstractMojo {</span>
@Parameter(property = &quot;spring.cloud.contract.verifier.contractsDirectory&quot;,
defaultValue = &quot;${project.basedir}/src/test/resources/contracts&quot;)
private File contractsDirectory;
@Parameter(
defaultValue = &quot;${project.build.directory}/generated-test-sources/contracts&quot;)
private File generatedTestSourcesDir;
@Parameter(defaultValue = &quot;org.springframework.cloud.contract.verifier.tests&quot;)
private String basePackageForTests;
@Parameter
private String baseClassForTests;
@Parameter(defaultValue = &quot;MOCKMVC&quot;)
private TestMode testMode;
@Parameter(defaultValue = &quot;JUNIT&quot;)
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&lt;String&gt; excludedFiles;
/**
* Patterns for which Spring Cloud Contract Verifier should generate @Ignored tests
*/
@Parameter
private List&lt;String&gt; ignoredFiles;
@Parameter(defaultValue = &quot;${project}&quot;, readonly = true)
private MavenProject project;
@Parameter(property = &quot;spring.cloud.contract.verifier.skip&quot;, defaultValue = &quot;false&quot;)
private boolean skip;
@Parameter(property = &quot;maven.test.skip&quot;, defaultValue = &quot;false&quot;)
private boolean mavenTestSkip;
@Parameter(property = &quot;skipTests&quot;, defaultValue = &quot;false&quot;) 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(&quot;Skipping Spring Cloud Contract Verifier execution: spring.cloud.contract.verifier.skip=&quot; + skip);</span>
<span class="nc bnc" id="L103" title="All 2 branches missed."> if (mavenTestSkip) getLog().info(&quot;Skipping Spring Cloud Contract Verifier execution: maven.test.skip=&quot; + mavenTestSkip);</span>
<span class="nc bnc" id="L104" title="All 2 branches missed."> if (skipTests) getLog().info(&quot;Skipping Spring Cloud Contract Verifier execution: skipTests&quot; + skipTests);</span>
<span class="nc" id="L105"> return;</span>
}
<span class="fc" id="L107"> getLog().info(</span>
&quot;Generating server tests source code for Spring Cloud Contract Verifier contract verification&quot;);
<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"> &quot;Test Source directory: &quot; + generatedTestSourcesDir.getAbsolutePath()</span>
+ &quot; added.&quot;);
<span class="fc" id="L127"> getLog().info(&quot;Using &quot; + config.getBaseClassForTests()</span>
+ &quot; as base class for test classes&quot;);
}
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(&quot;Generated &quot; + generatedClasses + &quot; test classes.&quot;);</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(&quot;Spring Cloud Contract Verifier Plugin exception: %s&quot;,</span>
<span class="nc" id="L138"> e.getMessage()), e);</span>
<span class="fc" id="L139"> }</span>
<span class="fc" id="L140"> }</span>
public List&lt;String&gt; getExcludedFiles() {
<span class="nc" id="L143"> return excludedFiles;</span>
}
public void setExcludedFiles(List&lt;String&gt; excludedFiles) {
<span class="nc" id="L147"> this.excludedFiles = excludedFiles;</span>
<span class="nc" id="L148"> }</span>
public List&lt;String&gt; getIgnoredFiles() {
<span class="nc" id="L151"> return ignoredFiles;</span>
}
public void setIgnoredFiles(List&lt;String&gt; 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>