View Javadoc
1   package org.apache.maven.plugin.cxx;
2   
3   /*
4    * Copyright (C) 2011-2016, Neticoa SAS France - Tous droits réservés.
5    * Author(s) : Franck Bonin, Neticoa SAS France
6    *
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   *
19   */
20  
21  import java.io.DataOutputStream;
22  import java.io.File;
23  import java.io.FileOutputStream;
24  import java.io.IOException;
25  import java.util.Properties;
26  
27  import org.apache.commons.exec.CommandLine;
28  import org.apache.commons.exec.Executor;
29  import org.apache.maven.plugin.MojoExecutionException;
30  
31  import org.apache.maven.plugins.annotations.LifecyclePhase;
32  import org.apache.maven.plugins.annotations.Mojo;
33  import org.apache.maven.plugins.annotations.Parameter;
34  
35  /**
36   * Goal which launch unit test using a custom command.
37   * This mojo just tell programmer where to produce xUnit reports
38   *
39   * @author Franck Bonin 
40   */
41  @Mojo( name = "xunit", defaultPhase = LifecyclePhase.TEST )
42  public class XUnitMojo extends LaunchMojo
43  {
44      /**
45       * The Report OutputFile Location.
46       * 
47       * @since 0.0.4
48       */
49      @Parameter( property = "xunit.reportsfilePath", defaultValue = "${project.build.directory}/xunit-reports" )
50      private File reportsfileDir;
51      
52      @Override
53      protected void preExecute( Executor exec, CommandLine commandLine, Properties enviro ) throws MojoExecutionException
54      {
55          // this
56          String outputReportDir = new String();
57          if ( reportsfileDir.isAbsolute() )
58          {
59              outputReportDir = reportsfileDir.getAbsolutePath();
60          }
61          else
62          {
63              outputReportDir = basedir.getAbsolutePath() + "/" + reportsfileDir.getPath();
64          }
65          new File( outputReportDir ).mkdirs();
66          getLog().info( "You shall produce a xUnit report called \"" + outputReportDir + File.separator
67              + "xunit-result-*.xml\" within this xunit goal" );
68          File file = new File( outputReportDir + "/Readme.txt" );
69          try
70          {
71              DataOutputStream out = new DataOutputStream( new FileOutputStream( file ) );
72              out.writeBytes( "You shall produce xUnit reports called \"xunit-result-*.xml\" within this directory.\n" );
73          }
74          catch ( IOException e )
75          {
76               getLog().info( "Could not write to " + outputReportDir + File.separator + "Readme.txt" );
77          }
78      }
79      
80      /**
81       * The Xunit Legacy Skip feature.
82       * 
83       * @since 0.0.5
84       */
85      @Parameter( property = "xunit.skiptests", defaultValue = "false" )
86      private boolean skiptests;
87      
88      /**
89       * Set this to "true" to skip running tests, but still compile them. Its use is NOT RECOMMENDED, but quite
90       * convenient on occasion.
91       *
92       * @since 0.0.5
93       */
94      @Parameter( property = "skipTests", defaultValue = "false" )
95      protected boolean skipTests;
96      
97      /**
98       * Set this to "true" to bypass unit tests entirely. Its use is NOT RECOMMENDED, especially if you enable
99       * it using the "maven.test.skip" property, because maven.test.skip shall disables both running the tests
100      * and compiling the tests. Consider using the <code>skipTests</code> parameter instead.
101      *
102      * @since 0.0.5
103      */
104     @Parameter( property = "maven.test.skip", defaultValue = "false" )
105     protected boolean skip;
106     
107     protected boolean isSkip()
108     {
109         return super.isSkip() || skiptests || skipTests || skip;
110     }
111 }