001package 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
022import java.io.File;
023import java.util.List;
024
025import org.apache.maven.model.Plugin;
026import org.apache.maven.model.PluginExecution;
027import org.apache.maven.project.AbstractMavenProjectTestCase;
028import org.apache.maven.project.MavenProject;
029import org.codehaus.plexus.util.xml.Xpp3Dom;
030
031/**
032 * @author Jason van Zyl
033 */
034public class CanonicalProjectBuilderTest
035    extends AbstractMavenProjectTestCase
036{
037    public void testProjectBuilder()
038        throws Exception
039    {
040        File f = getFileForClasspathResource( "canonical-pom.xml" );
041
042        MavenProject project = getProject( f );
043
044        // ----------------------------------------------------------------------
045        // Top-level elements
046        // ----------------------------------------------------------------------
047
048        assertEquals( "4.0.0", project.getModelVersion() );
049
050        // ----------------------------------------------------------------------
051        // Plugins
052        // ----------------------------------------------------------------------
053
054        List<Plugin> plugins = project.getBuildPlugins();
055
056        // Plugin0 [plexus]
057
058        String key = "org.apache.maven.plugins:maven-plexus-plugin";
059
060        Plugin plugin = null;
061        for ( Plugin check : plugins )
062        {
063            if ( key.equals( check.getKey() ) )
064            {
065                plugin = check;
066                break;
067            }
068        }
069
070        assertNotNull( plugin );
071
072        assertEquals( "1.0", plugin.getVersion() );
073
074        Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
075
076        assertEquals( "src/conf/plexus.conf", configuration.getChild( "plexusConfiguration" ).getValue() );
077
078        assertEquals( "src/conf/plexus.properties",
079                      configuration.getChild( "plexusConfigurationPropertiesFile" ).getValue() );
080
081        assertEquals( "Continuum", configuration.getChild( "plexusApplicationName" ).getValue() );
082
083        // ----------------------------------------------------------------------
084        // Goal specific configuration
085        // ----------------------------------------------------------------------
086
087        List<PluginExecution> executions = plugin.getExecutions();
088
089        PluginExecution execution = executions.get( 0 );
090
091        String g0 = execution.getGoals().get( 0 );
092
093        assertEquals( "plexus:runtime", g0 );
094
095        configuration = (Xpp3Dom) execution.getConfiguration();
096
097        assertEquals( "ContinuumPro", configuration.getChild( "plexusApplicationName" ).getValue() );
098
099        // Plugin1 [antlr]
100    }
101}