View Javadoc

1   package org.apache.maven.model.converter.plugins;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.model.converter.ProjectConverterException;
23  import org.codehaus.plexus.util.xml.Xpp3Dom;
24  
25  import java.util.Iterator;
26  import java.util.List;
27  import java.util.Properties;
28  import java.util.StringTokenizer;
29  
30  /**
31   * @plexus.component role="org.apache.maven.model.converter.plugins.PluginConfigurationConverter" role-hint="surefire"
32   *
33   * @author Fabrizio Giustina
34   * @author Dennis Lundberg
35   * @version $Id: PCCSurefire.java 661727 2008-05-30 14:21:49Z bentmann $
36   */
37  public class PCCSurefire
38      extends AbstractPluginConfigurationConverter
39  {
40      /**
41       * @see org.apache.maven.model.converter.plugins.AbstractPluginConfigurationConverter#getArtifactId()
42       */
43      public String getArtifactId()
44      {
45          return "maven-surefire-plugin";
46      }
47  
48      public String getType()
49      {
50          return TYPE_BUILD_PLUGIN;
51      }
52  
53      protected void buildConfiguration( Xpp3Dom configuration, org.apache.maven.model.v3_0_0.Model v3Model,
54                                         Properties projectProperties )
55          throws ProjectConverterException
56      {
57          addConfigurationChild( configuration, projectProperties, "maven.junit.jvmargs", "argLine" );
58  
59          String forkMode = projectProperties.getProperty( "maven.junit.forkmode" );
60          if ( forkMode == null )
61          {
62              String fork = projectProperties.getProperty( "maven.junit.fork" );
63              if ( fork != null )
64              {
65                  boolean useFork = Boolean.valueOf( PropertyUtils.convertYesNoToBoolean( fork ) ).booleanValue();
66                  if ( useFork )
67                  {
68                      // Use "once" here as that is the default forkMode
69                      addConfigurationChild( configuration, "forkMode", "once" );
70                  }
71              }
72          }
73          else
74          {
75              addConfigurationChild( configuration, projectProperties, "maven.junit.forkmode", "forkMode" );
76          }
77  
78          addConfigurationChild( configuration, projectProperties, "maven.junit.jvm", "jvm" );
79  
80          addConfigurationChild( configuration, projectProperties, "maven.junit.printSummary", "printSummary" );
81  
82          addConfigurationChild( configuration, projectProperties, "maven.junit.format", "reportFormat" );
83  
84          addConfigurationChild( configuration, projectProperties, "maven.test.skip", "skip" );
85  
86          String sysproperties = projectProperties.getProperty( "maven.junit.sysproperties" );
87          if ( sysproperties != null )
88          {
89              StringTokenizer tokenizer = new StringTokenizer( sysproperties );
90              if ( tokenizer.hasMoreTokens() )
91              {
92                  Xpp3Dom systemProperties = new Xpp3Dom( "systemProperties" );
93                  while ( tokenizer.hasMoreTokens() )
94                  {
95                      String name = tokenizer.nextToken();
96                      String value = projectProperties.getProperty( name );
97                      addConfigurationChild( systemProperties, name, value );
98                  }
99                  if ( systemProperties.getChildCount() > 0 )
100                 {
101                     configuration.addChild( systemProperties );
102                 }
103             }
104         }
105 
106         addConfigurationChild( configuration, projectProperties, "maven.test.failure.ignore", "testFailureIgnore" );
107 
108         addConfigurationChild( configuration, projectProperties, "maven.junit.usefile", "useFile" );
109 
110         if ( v3Model.getBuild() != null && v3Model.getBuild().getUnitTest() != null )
111         {
112             org.apache.maven.model.v3_0_0.UnitTest v3UnitTest = v3Model.getBuild().getUnitTest();
113 
114             List excludes = v3UnitTest.getExcludes();
115             if ( excludes != null && excludes.size() > 0 )
116             {
117                 Xpp3Dom excludesConf = new Xpp3Dom( "excludes" );
118                 for ( Iterator iter = excludes.iterator(); iter.hasNext(); )
119                 {
120                     addConfigurationChild( excludesConf, "exclude", (String) iter.next() );
121                 }
122                 configuration.addChild( excludesConf );
123             }
124 
125             List includes = v3UnitTest.getIncludes();
126             if ( includes != null && includes.size() > 0 )
127             {
128                 Xpp3Dom includesConf = new Xpp3Dom( "includes" );
129                 for ( Iterator iter = includes.iterator(); iter.hasNext(); )
130                 {
131                     addConfigurationChild( includesConf, "include", (String) iter.next() );
132                 }
133                 configuration.addChild( includesConf );
134             }
135         }
136     }
137 }