View Javadoc

1   package org.apache.maven.project.canonical;
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 java.io.File;
23  import java.util.Iterator;
24  import java.util.List;
25  
26  import org.apache.maven.model.Plugin;
27  import org.apache.maven.model.PluginExecution;
28  import org.apache.maven.project.AbstractMavenProjectTestCase;
29  import org.apache.maven.project.MavenProject;
30  import org.codehaus.plexus.util.xml.Xpp3Dom;
31  
32  /**
33   * @author Jason van Zyl
34   */
35  public class CanonicalProjectBuilderTest
36      extends AbstractMavenProjectTestCase
37  {
38      public void testProjectBuilder()
39          throws Exception
40      {
41          File f = getFileForClasspathResource( "canonical-pom.xml" );
42  
43          MavenProject project = getProject( f );
44  
45          // ----------------------------------------------------------------------
46          // Top-level elements
47          // ----------------------------------------------------------------------
48  
49          assertEquals( "4.0.0", project.getModelVersion() );
50  
51          // ----------------------------------------------------------------------
52          // Plugins
53          // ----------------------------------------------------------------------
54  
55          List plugins = project.getBuildPlugins();
56  
57          // Plugin0 [plexus]
58  
59          String key = "org.apache.maven.plugins:maven-plexus-plugin";
60  
61          Plugin plugin = null;
62          for ( Iterator it = plugins.iterator(); it.hasNext(); )
63          {
64              Plugin check = (Plugin) it.next();
65  
66              if ( key.equals( check.getKey() ) )
67              {
68                  plugin = check;
69                  break;
70              }
71          }
72  
73          assertNotNull( plugin );
74  
75          assertEquals( "1.0", plugin.getVersion() );
76  
77          Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
78  
79          assertEquals( "src/conf/plexus.conf", configuration.getChild( "plexusConfiguration" ).getValue() );
80  
81          assertEquals( "src/conf/plexus.properties",
82                        configuration.getChild( "plexusConfigurationPropertiesFile" ).getValue() );
83  
84          assertEquals( "Continuum", configuration.getChild( "plexusApplicationName" ).getValue() );
85  
86          // ----------------------------------------------------------------------
87          // Goal specific configuration
88          // ----------------------------------------------------------------------
89  
90          List executions = plugin.getExecutions();
91  
92          PluginExecution execution = (PluginExecution) executions.get( 0 );
93  
94          String g0 = (String) execution.getGoals().get( 0 );
95  
96          assertEquals( "plexus:runtime", g0 );
97  
98          configuration = (Xpp3Dom) execution.getConfiguration();
99  
100         assertEquals( "ContinuumPro", configuration.getChild( "plexusApplicationName" ).getValue() );
101 
102         // Plugin1 [antlr]
103     }
104 }