View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugin.descriptor;
20  
21  import java.io.IOException;
22  import java.io.Reader;
23  
24  import org.codehaus.plexus.component.repository.ComponentDependency;
25  import org.codehaus.plexus.component.repository.ComponentRequirement;
26  import org.codehaus.plexus.configuration.PlexusConfiguration;
27  import org.codehaus.plexus.configuration.PlexusConfigurationException;
28  import org.codehaus.plexus.util.ReaderFactory;
29  import org.junit.jupiter.api.Test;
30  
31  import static org.junit.jupiter.api.Assertions.assertEquals;
32  import static org.junit.jupiter.api.Assertions.assertNotNull;
33  
34  /**
35   * Tests {@link PluginDescriptorBuilder}.
36   *
37   * @author Benjamin Bentmann
38   */
39  public class PluginDescriptorBuilderTest {
40  
41      private PluginDescriptor build(String resource) throws IOException, PlexusConfigurationException {
42          Reader reader = ReaderFactory.newXmlReader(getClass().getResourceAsStream(resource));
43  
44          return new PluginDescriptorBuilder().build(reader);
45      }
46  
47      @Test
48      public void testBuildReader() throws Exception {
49          PluginDescriptor pd = build("/plugin.xml");
50  
51          assertEquals("org.apache.maven.plugins", pd.getGroupId());
52          assertEquals("maven-jar-plugin", pd.getArtifactId());
53          assertEquals("2.3-SNAPSHOT", pd.getVersion());
54          assertEquals("jar", pd.getGoalPrefix());
55          assertEquals("plugin-description", pd.getDescription());
56          assertEquals(false, pd.isIsolatedRealm());
57          assertEquals(true, pd.isInheritedByDefault());
58          assertEquals(2, pd.getMojos().size());
59          assertEquals(1, pd.getDependencies().size());
60  
61          MojoDescriptor md = pd.getMojos().get(0);
62  
63          assertEquals("jar", md.getGoal());
64          assertEquals("mojo-description", md.getDescription());
65          assertEquals("runtime", md.getDependencyResolutionRequired());
66          assertEquals("test", md.getDependencyCollectionRequired());
67          assertEquals(false, md.isAggregator());
68          assertEquals(false, md.isDirectInvocationOnly());
69          assertEquals(true, md.isInheritedByDefault());
70          assertEquals(false, md.isOnlineRequired());
71          assertEquals(true, md.isProjectRequired());
72          assertEquals(false, md.isThreadSafe());
73          assertEquals("package", md.getPhase());
74          assertEquals("org.apache.maven.plugin.jar.JarMojo", md.getImplementation());
75          assertEquals("antrun", md.getComponentConfigurator());
76          assertEquals("java", md.getLanguage());
77          assertEquals("per-lookup", md.getInstantiationStrategy());
78          assertEquals("some-goal", md.getExecuteGoal());
79          assertEquals("generate-sources", md.getExecutePhase());
80          assertEquals("cobertura", md.getExecuteLifecycle());
81          assertEquals("2.2", md.getSince());
82          assertEquals("deprecated-mojo", md.getDeprecated());
83          assertEquals(1, md.getRequirements().size());
84          assertEquals(1, md.getParameters().size());
85  
86          assertNotNull(md.getMojoConfiguration());
87          assertEquals(1, md.getMojoConfiguration().getChildCount());
88  
89          PlexusConfiguration pc = md.getMojoConfiguration().getChild(0);
90  
91          assertEquals("${jar.finalName}", pc.getValue());
92          assertEquals("${project.build.finalName}", pc.getAttribute("default-value"));
93          assertEquals("java.lang.String", pc.getAttribute("implementation"));
94  
95          Parameter mp = md.getParameters().get(0);
96  
97          assertEquals("finalName", mp.getName());
98          assertEquals("jarName", mp.getAlias());
99          assertEquals("java.lang.String", mp.getType());
100         assertEquals("java.lang.String", mp.getImplementation());
101         assertEquals(true, mp.isEditable());
102         assertEquals(false, mp.isRequired());
103         assertEquals("parameter-description", mp.getDescription());
104         assertEquals("deprecated-parameter", mp.getDeprecated());
105         assertEquals("${jar.finalName}", mp.getExpression());
106         assertEquals("${project.build.finalName}", mp.getDefaultValue());
107         assertEquals("3.0.0", mp.getSince());
108 
109         ComponentRequirement cr = md.getRequirements().get(0);
110 
111         assertEquals("org.codehaus.plexus.archiver.Archiver", cr.getRole());
112         assertEquals("jar", cr.getRoleHint());
113         assertEquals("jarArchiver", cr.getFieldName());
114 
115         ComponentDependency cd = pd.getDependencies().get(0);
116 
117         assertEquals("org.apache.maven", cd.getGroupId());
118         assertEquals("maven-plugin-api", cd.getArtifactId());
119         assertEquals("2.0.6", cd.getVersion());
120         assertEquals("jar", cd.getType());
121 
122         md = pd.getMojos().get(1);
123 
124         assertEquals("war", md.getGoal());
125         assertEquals(null, md.getDependencyResolutionRequired());
126         assertEquals(null, md.getDependencyCollectionRequired());
127         assertEquals(true, md.isThreadSafe());
128     }
129 }