View Javadoc
1   package org.apache.maven.plugin.descriptor;
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.IOException;
23  import java.io.Reader;
24  
25  import org.codehaus.plexus.component.repository.ComponentDependency;
26  import org.codehaus.plexus.component.repository.ComponentRequirement;
27  import org.codehaus.plexus.configuration.PlexusConfiguration;
28  import org.codehaus.plexus.configuration.PlexusConfigurationException;
29  import org.codehaus.plexus.util.ReaderFactory;
30  
31  import junit.framework.TestCase;
32  
33  /**
34   * Tests {@link PluginDescriptorBuilder}.
35   * 
36   * @author Benjamin Bentmann
37   */
38  public class PluginDescriptorBuilderTest
39      extends TestCase
40  {
41  
42      private PluginDescriptor build( String resource )
43          throws IOException, PlexusConfigurationException
44      {
45          Reader reader = ReaderFactory.newXmlReader( getClass().getResourceAsStream( resource ) );
46  
47          return new PluginDescriptorBuilder().build( reader );
48      }
49  
50      public void testBuildReader()
51          throws Exception
52      {
53          PluginDescriptor pd = build( "/plugin.xml" );
54  
55          assertEquals( "org.apache.maven.plugins", pd.getGroupId() );
56          assertEquals( "maven-jar-plugin", pd.getArtifactId() );
57          assertEquals( "2.3-SNAPSHOT", pd.getVersion() );
58          assertEquals( "jar", pd.getGoalPrefix() );
59          assertEquals( "plugin-description", pd.getDescription() );
60          assertEquals( false, pd.isIsolatedRealm() );
61          assertEquals( true, pd.isInheritedByDefault() );
62          assertEquals( 2, pd.getMojos().size() );
63          assertEquals( 1, pd.getDependencies().size() );
64  
65          MojoDescriptor md = pd.getMojos().get( 0 );
66  
67          assertEquals( "jar", md.getGoal() );
68          assertEquals( "mojo-description", md.getDescription() );
69          assertEquals( "runtime", md.getDependencyResolutionRequired() );
70          assertEquals( "test", md.getDependencyCollectionRequired() );
71          assertEquals( false, md.isAggregator() );
72          assertEquals( false, md.isDirectInvocationOnly() );
73          assertEquals( true, md.isInheritedByDefault() );
74          assertEquals( false, md.isOnlineRequired() );
75          assertEquals( true, md.isProjectRequired() );
76          assertEquals( false, md.isThreadSafe() );
77          assertEquals( "package", md.getPhase() );
78          assertEquals( "org.apache.maven.plugin.jar.JarMojo", md.getImplementation() );
79          assertEquals( "antrun", md.getComponentConfigurator() );
80          assertEquals( "java", md.getLanguage() );
81          assertEquals( "per-lookup", md.getInstantiationStrategy() );
82          assertEquals( "some-goal", md.getExecuteGoal() );
83          assertEquals( "generate-sources", md.getExecutePhase() );
84          assertEquals( "cobertura", md.getExecuteLifecycle() );
85          assertEquals( "2.2", md.getSince() );
86          assertEquals( "deprecated-mojo", md.getDeprecated() );
87          assertEquals( 1, md.getRequirements().size() );
88          assertEquals( 1, md.getParameters().size() );
89  
90          assertNotNull( md.getMojoConfiguration() );
91          assertEquals( 1, md.getMojoConfiguration().getChildCount() );
92  
93          PlexusConfiguration pc = md.getMojoConfiguration().getChild( 0 );
94  
95          assertEquals( "${jar.finalName}", pc.getValue() );
96          assertEquals( "${project.build.finalName}", pc.getAttribute( "default-value" ) );
97          assertEquals( "java.lang.String", pc.getAttribute( "implementation" ) );
98  
99          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 }