001package org.apache.maven.plugin.descriptor;
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.IOException;
023import java.io.Reader;
024
025import org.codehaus.plexus.component.repository.ComponentDependency;
026import org.codehaus.plexus.component.repository.ComponentRequirement;
027import org.codehaus.plexus.configuration.PlexusConfiguration;
028import org.codehaus.plexus.configuration.PlexusConfigurationException;
029import org.codehaus.plexus.util.ReaderFactory;
030
031import junit.framework.TestCase;
032
033/**
034 * Tests {@link PluginDescriptorBuilder}.
035 *
036 * @author Benjamin Bentmann
037 */
038public class PluginDescriptorBuilderTest
039    extends TestCase
040{
041
042    private PluginDescriptor build( String resource )
043        throws IOException, PlexusConfigurationException
044    {
045        Reader reader = ReaderFactory.newXmlReader( getClass().getResourceAsStream( resource ) );
046
047        return new PluginDescriptorBuilder().build( reader );
048    }
049
050    public void testBuildReader()
051        throws Exception
052    {
053        PluginDescriptor pd = build( "/plugin.xml" );
054
055        assertEquals( "org.apache.maven.plugins", pd.getGroupId() );
056        assertEquals( "maven-jar-plugin", pd.getArtifactId() );
057        assertEquals( "2.3-SNAPSHOT", pd.getVersion() );
058        assertEquals( "jar", pd.getGoalPrefix() );
059        assertEquals( "plugin-description", pd.getDescription() );
060        assertEquals( false, pd.isIsolatedRealm() );
061        assertEquals( true, pd.isInheritedByDefault() );
062        assertEquals( 2, pd.getMojos().size() );
063        assertEquals( 1, pd.getDependencies().size() );
064
065        MojoDescriptor md = pd.getMojos().get( 0 );
066
067        assertEquals( "jar", md.getGoal() );
068        assertEquals( "mojo-description", md.getDescription() );
069        assertEquals( "runtime", md.getDependencyResolutionRequired() );
070        assertEquals( "test", md.getDependencyCollectionRequired() );
071        assertEquals( false, md.isAggregator() );
072        assertEquals( false, md.isDirectInvocationOnly() );
073        assertEquals( true, md.isInheritedByDefault() );
074        assertEquals( false, md.isOnlineRequired() );
075        assertEquals( true, md.isProjectRequired() );
076        assertEquals( false, md.isThreadSafe() );
077        assertEquals( "package", md.getPhase() );
078        assertEquals( "org.apache.maven.plugin.jar.JarMojo", md.getImplementation() );
079        assertEquals( "antrun", md.getComponentConfigurator() );
080        assertEquals( "java", md.getLanguage() );
081        assertEquals( "per-lookup", md.getInstantiationStrategy() );
082        assertEquals( "some-goal", md.getExecuteGoal() );
083        assertEquals( "generate-sources", md.getExecutePhase() );
084        assertEquals( "cobertura", md.getExecuteLifecycle() );
085        assertEquals( "2.2", md.getSince() );
086        assertEquals( "deprecated-mojo", md.getDeprecated() );
087        assertEquals( 1, md.getRequirements().size() );
088        assertEquals( 1, md.getParameters().size() );
089
090        assertNotNull( md.getMojoConfiguration() );
091        assertEquals( 1, md.getMojoConfiguration().getChildCount() );
092
093        PlexusConfiguration pc = md.getMojoConfiguration().getChild( 0 );
094
095        assertEquals( "${jar.finalName}", pc.getValue() );
096        assertEquals( "${project.build.finalName}", pc.getAttribute( "default-value" ) );
097        assertEquals( "java.lang.String", pc.getAttribute( "implementation" ) );
098
099        Parameter mp = md.getParameters().get( 0 );
100
101        assertEquals( "finalName", mp.getName() );
102        assertEquals( "jarName", mp.getAlias() );
103        assertEquals( "java.lang.String", mp.getType() );
104        assertEquals( "java.lang.String", mp.getImplementation() );
105        assertEquals( true, mp.isEditable() );
106        assertEquals( false, mp.isRequired() );
107        assertEquals( "parameter-description", mp.getDescription() );
108        assertEquals( "deprecated-parameter", mp.getDeprecated() );
109        assertEquals( "${jar.finalName}", mp.getExpression() );
110        assertEquals( "${project.build.finalName}", mp.getDefaultValue() );
111
112        ComponentRequirement cr = md.getRequirements().get( 0 );
113
114        assertEquals( "org.codehaus.plexus.archiver.Archiver", cr.getRole() );
115        assertEquals( "jar", cr.getRoleHint() );
116        assertEquals( "jarArchiver", cr.getFieldName() );
117
118        ComponentDependency cd = pd.getDependencies().get( 0 );
119
120        assertEquals( "org.apache.maven", cd.getGroupId() );
121        assertEquals( "maven-plugin-api", cd.getArtifactId() );
122        assertEquals( "2.0.6", cd.getVersion() );
123        assertEquals( "jar", cd.getType() );
124
125        md = pd.getMojos().get( 1 );
126
127        assertEquals( "war", md.getGoal() );
128        assertEquals( null, md.getDependencyResolutionRequired() );
129        assertEquals( null, md.getDependencyCollectionRequired() );
130        assertEquals( true, md.isThreadSafe() );
131    }
132
133}