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.File;
22  import java.util.HashMap;
23  import java.util.List;
24  import java.util.Map;
25  
26  import org.apache.maven.plugins.annotations.LifecyclePhase;
27  import org.apache.maven.plugins.annotations.Mojo;
28  import org.apache.maven.plugins.annotations.Parameter;
29  
30  /**
31   * Goal which valgrind executables.
32   *
33   * @author Franck Bonin 
34   */
35  @Mojo( name = "valgrind", defaultPhase = LifecyclePhase.TEST )
36  public class ValgrindMojo extends AbstractLaunchMojo
37  {
38      @Override
39      protected List<String> getArgsList()
40      {
41          return null;
42      }
43  
44      /**
45       * The Report OutputFile Location.
46       * 
47       * @since 0.0.4
48       */
49      @Parameter( property = "valgrind.reportsfilePath", defaultValue = "${project.build.directory}/valgrind-reports" )
50      private File reportsfileDir;
51  
52      /**
53       * The Report OutputFile name identifier.
54       * 
55       * @since 0.0.4
56       */
57      @Parameter( property = "valgrind.reportIdentifier", defaultValue = "" )
58      private String reportIdentifier;
59      
60      private String getReportFileName()
61      {
62          return "valgrind-result-" + reportIdentifier + ".xml";
63      }
64      /**
65       * Arguments for valgrind program. Shall be --leak-check=yes --demangle=yes --xml=yes
66       * 
67       */
68      @Parameter( property = "valgrind.args", defaultValue = "--leak-check=yes --demangle=yes --xml=yes" )
69      private String commandArgs;
70      
71      @Override
72      protected String getCommandArgs()
73      {
74          String params = commandArgs + " ";
75          String outputReportName = new String();
76          if ( reportsfileDir.isAbsolute() )
77          {
78              outputReportName = reportsfileDir.getAbsolutePath() + "/" + getReportFileName();
79          }
80          else
81          {
82              outputReportName = basedir.getAbsolutePath() + "/" + reportsfileDir.getPath() + "/" + getReportFileName();
83          }
84          File file = new File( outputReportName );
85          new File( file.getParent() ).mkdirs();
86          
87          params += "--xml-file=\"" + outputReportName + "\" ";
88          
89          params += "\"" + instrumentedExecutablePath + "\" " + instrumentedExecutableArgs;
90                  
91          return params;
92      }
93      
94      /**
95       * Path to executed (tested) program 
96       * 
97       */
98      @Parameter( property = "valgrind.instrumented", required = true )
99      private String instrumentedExecutablePath;
100     
101     /**
102      * Arguments of executed program 
103      * 
104      */
105     @Parameter( property = "valgrind.instrumentedArgs", defaultValue = " " )
106     private String instrumentedExecutableArgs;
107     
108     @Override
109     protected String getExecutable()
110     {
111         return "valgrind";
112     }
113 
114     /**
115      * Environment variables passed to valgrind program.
116      * 
117      * @since 0.0.4
118      */
119     @Parameter()
120     private Map environmentVariables = new HashMap();
121     
122     @Override
123     protected Map getMoreEnvironmentVariables()
124     {
125         return environmentVariables;
126     }
127 
128     @Override
129     protected List<String> getSuccesCode()
130     {
131         return null;
132     }
133 
134     /**
135      * The current working directory. Optional. If not specified, basedir will be used.
136      * 
137      * @since 0.0.4
138      */
139     @Parameter( property = "valgrind.workingdir" )
140     private File workingDir;
141     
142     @Override
143     protected File getWorkingDir()
144     {
145         if ( null == workingDir )
146         {
147             workingDir = new File( basedir.getPath() );
148         }
149         return workingDir;
150     }
151     
152     
153     /**
154     * Set this to "true" to skip running tests, but still compile them. Its use is NOT RECOMMENDED, but quite
155     * convenient on occasion.
156     *
157     * @since 0.0.5
158     */
159     @Parameter( property = "skipTests", defaultValue = "false" )
160     protected boolean skipTests;
161     
162     /**
163     * Set this to "true" to bypass unit tests entirely. Its use is NOT RECOMMENDED, especially if you enable it
164     * using the "maven.test.skip" property, because maven.test.skip shall disables both running the tests and
165     * compiling the tests. Consider using the <code>skipTests</code> parameter instead.
166     *
167     * @since 0.0.5
168     */
169     @Parameter( property = "maven.test.skip", defaultValue = "false" )
170     protected boolean skip;
171     
172     @Override
173     protected boolean isSkip()
174     {
175         return localIsSkip() || skipTests || skip;
176     }
177 
178     protected boolean localIsSkip()
179     {
180         String sOsName = System.getProperty( "os.name" );
181         // vilgrind will work on linux, macos, everything but windows
182         return sOsName.contains( "windows" );
183     }
184 
185 }