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.Iterator;
24  import java.util.List;
25  import java.util.Map;
26  import java.util.ArrayList;
27  
28  import org.codehaus.plexus.util.StringUtils;
29  
30  import org.apache.maven.plugins.annotations.LifecyclePhase;
31  import org.apache.maven.plugins.annotations.Mojo;
32  import org.apache.maven.plugins.annotations.Parameter;
33  
34  /**
35   * Goal which qmakes workspace.
36   *
37   * @author Franck Bonin 
38   */
39  @Mojo( name = "qmake", defaultPhase = LifecyclePhase.GENERATE_SOURCES )
40  public class QMakeMojo extends AbstractLaunchMojo
41  {
42      @Override
43      protected List<String> getArgsList()
44      {
45          return null;
46      }
47      
48      /**
49       * directory were sources are
50       * 
51       * @since 0.0.4
52       */
53      @Parameter()
54      private List<String> sourceDirs = new ArrayList<String>();
55  
56      /**
57       * qmake project file list
58       * Can be empty, then sourceDirs will so be used.
59       * If sourceDirs is empty to, then basedir will be used.
60       * 
61       * @since 0.0.5
62       */
63      @Parameter()
64      private List<String> pros = new ArrayList<String>();
65      
66      protected List<String> getProjectList()
67      {
68          if ( pros.size() == 0 )
69          {
70              Iterator it = sourceDirs.iterator();
71              while ( it.hasNext() )
72              {
73                  pros.add( new File( (String) it.next() ).getAbsolutePath() );
74              }
75          }
76          if ( pros.size() == 0 )
77          {
78              pros.add( new String( basedir.getAbsolutePath() ) );
79          }
80          return pros;
81      }
82      
83      /**
84       * Arguments for qmake program
85       * 
86       * @since 0.0.5
87       */
88      @Parameter( property = "qmake.args", defaultValue = "" )
89      private String commandArgs;
90      
91      @Override
92      protected String getCommandArgs()
93      {
94          String result = new String( "-makefile " );
95          if ( !StringUtils.isEmpty( commandArgs ) )
96          {
97              result += commandArgs + " ";
98          }
99          List<String> proList = getProjectList();
100         Iterator it = proList.iterator();
101         while ( it.hasNext() )
102         {
103             result += "\"" + (String) it.next() + "\" ";
104         }
105         return result;
106     }
107     
108     /**
109      * qmake commands names per OS name
110      * os name match is java.lang.System.getProperty( "os.name" )
111      * 
112      * @since 0.0.5
113      */
114     @Parameter()
115     private Map qmakecommandPerOS = new HashMap();
116     
117     @Override
118     protected String getExecutable()
119     {
120         String sOsName = System.getProperty( "os.name" );
121         sOsName = sOsName.replace( " ", "" );
122         getLog().info( "os.name is \"" + sOsName + "\"" );
123         if ( qmakecommandPerOS == null )
124         {
125             return "qmake";
126         }
127         else
128         {
129             if ( qmakecommandPerOS.containsKey( sOsName ) )
130             {
131                 return (String) qmakecommandPerOS.get( sOsName );
132             }
133             else
134             {
135                 return "qmake";
136             }
137         }
138     }
139     
140     /**
141      * Environment variables passed to qmake program.
142      * 
143      * @since 0.0.5
144      */
145     @Parameter()
146     private Map environmentVariables = new HashMap();
147     
148     @Override
149     protected Map getMoreEnvironmentVariables()
150     {
151         return environmentVariables;
152     }
153 
154     @Override
155     protected List<String> getSuccesCode()
156     {
157         return null;
158     }
159 
160     /**
161      * Out of source directory
162      * 
163      * @since 0.0.5
164      */
165     @Parameter( property = "qmake.outsourcedir" )
166     private File outsourceDir;
167     
168     @Override
169     protected File getWorkingDir()
170     {
171         if ( null == outsourceDir )
172         {
173             outsourceDir = new File( basedir.getPath() );
174         }
175         return outsourceDir;
176     }
177 
178     @Override
179     public boolean isSkip()
180     {
181         return false;
182     }
183 
184 }