1   package org.apache.maven.model.converter.plugins;
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
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  
32  
33  
34  
35  
36  
37  public class PCCSurefire
38      extends AbstractPluginConfigurationConverter
39  {
40      
41  
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                      
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 }