001    package org.apache.maven.project.canonical;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *  http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import java.io.File;
023    import java.util.Iterator;
024    import java.util.List;
025    
026    import org.apache.maven.model.Plugin;
027    import org.apache.maven.model.PluginExecution;
028    import org.apache.maven.project.AbstractMavenProjectTestCase;
029    import org.apache.maven.project.MavenProject;
030    import org.codehaus.plexus.util.xml.Xpp3Dom;
031    
032    /**
033     * @author Jason van Zyl
034     */
035    public class CanonicalProjectBuilderTest
036        extends AbstractMavenProjectTestCase
037    {
038        public void testProjectBuilder()
039            throws Exception
040        {
041            File f = getFileForClasspathResource( "canonical-pom.xml" );
042    
043            MavenProject project = getProject( f );
044    
045            // ----------------------------------------------------------------------
046            // Top-level elements
047            // ----------------------------------------------------------------------
048    
049            assertEquals( "4.0.0", project.getModelVersion() );
050    
051            // ----------------------------------------------------------------------
052            // Plugins
053            // ----------------------------------------------------------------------
054    
055            List plugins = project.getBuildPlugins();
056    
057            // Plugin0 [plexus]
058    
059            String key = "org.apache.maven.plugins:maven-plexus-plugin";
060    
061            Plugin plugin = null;
062            for ( Iterator it = plugins.iterator(); it.hasNext(); )
063            {
064                Plugin check = (Plugin) it.next();
065    
066                if ( key.equals( check.getKey() ) )
067                {
068                    plugin = check;
069                    break;
070                }
071            }
072    
073            assertNotNull( plugin );
074    
075            assertEquals( "1.0", plugin.getVersion() );
076    
077            Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
078    
079            assertEquals( "src/conf/plexus.conf", configuration.getChild( "plexusConfiguration" ).getValue() );
080    
081            assertEquals( "src/conf/plexus.properties",
082                          configuration.getChild( "plexusConfigurationPropertiesFile" ).getValue() );
083    
084            assertEquals( "Continuum", configuration.getChild( "plexusApplicationName" ).getValue() );
085    
086            // ----------------------------------------------------------------------
087            // Goal specific configuration
088            // ----------------------------------------------------------------------
089    
090            List executions = plugin.getExecutions();
091    
092            PluginExecution execution = (PluginExecution) executions.get( 0 );
093    
094            String g0 = (String) execution.getGoals().get( 0 );
095    
096            assertEquals( "plexus:runtime", g0 );
097    
098            configuration = (Xpp3Dom) execution.getConfiguration();
099    
100            assertEquals( "ContinuumPro", configuration.getChild( "plexusApplicationName" ).getValue() );
101    
102            // Plugin1 [antlr]
103        }
104    }