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.InputStream;
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.junit.jupiter.api.Test;
29  
30  import static org.junit.jupiter.api.Assertions.assertEquals;
31  import static org.junit.jupiter.api.Assertions.assertFalse;
32  import static org.junit.jupiter.api.Assertions.assertNotNull;
33  import static org.junit.jupiter.api.Assertions.assertNull;
34  import static org.junit.jupiter.api.Assertions.assertTrue;
35  
36  /**
37   * Tests {@link PluginDescriptorBuilder}.
38   *
39   */
40  class PluginDescriptorBuilderTest {
41  
42      private PluginDescriptor build(String resource) throws IOException, PlexusConfigurationException {
43          try (InputStream is = getClass().getResourceAsStream(resource)) {
44              return new PluginDescriptorBuilder().build(is, null);
45          }
46      }
47  
48      @Test
49      void testBuildReader() throws Exception {
50          PluginDescriptor pd = build("/plugin.xml");
51  
52          assertEquals("org.apache.maven.plugins", pd.getGroupId());
53          assertEquals("maven-jar-plugin", pd.getArtifactId());
54          assertEquals("2.3-SNAPSHOT", pd.getVersion());
55          assertEquals("jar", pd.getGoalPrefix());
56          assertEquals("plugin-description", pd.getDescription());
57          assertFalse(pd.isIsolatedRealm());
58          assertTrue(pd.isInheritedByDefault());
59          assertEquals(2, pd.getMojos().size());
60          assertEquals(1, pd.getDependencies().size());
61  
62          MojoDescriptor md = pd.getMojos().get(0);
63  
64          assertEquals("jar", md.getGoal());
65          assertEquals("mojo-description", md.getDescription());
66          assertEquals("runtime", md.getDependencyResolutionRequired());
67          assertEquals("test", md.getDependencyCollectionRequired());
68          assertFalse(md.isAggregator());
69          assertFalse(md.isDirectInvocationOnly());
70          assertTrue(md.isInheritedByDefault());
71          assertFalse(md.isOnlineRequired());
72          assertTrue(md.isProjectRequired());
73          assertFalse(md.isThreadSafe());
74          assertEquals("package", md.getPhase());
75          assertEquals("org.apache.maven.plugin.jar.JarMojo", md.getImplementation());
76          assertEquals("antrun", md.getComponentConfigurator());
77          assertEquals("java", md.getLanguage());
78          assertEquals("per-lookup", md.getInstantiationStrategy());
79          assertEquals("some-goal", md.getExecuteGoal());
80          assertEquals("generate-sources", md.getExecutePhase());
81          assertEquals("cobertura", md.getExecuteLifecycle());
82          assertEquals("2.2", md.getSince());
83          assertEquals("deprecated-mojo", md.getDeprecated());
84          assertEquals(1, md.getRequirements().size());
85          assertEquals(1, md.getParameters().size());
86  
87          assertNotNull(md.getMojoConfiguration());
88          assertEquals(1, md.getMojoConfiguration().getChildCount());
89  
90          PlexusConfiguration pc = md.getMojoConfiguration().getChild(0);
91  
92          assertEquals("${jar.finalName}", pc.getValue());
93          assertEquals("${project.build.finalName}", pc.getAttribute("default-value"));
94          assertEquals("java.lang.String", pc.getAttribute("implementation"));
95  
96          Parameter mp = md.getParameters().get(0);
97  
98          assertEquals("finalName", mp.getName());
99          assertEquals("jarName", mp.getAlias());
100         assertEquals("java.lang.String", mp.getType());
101         assertEquals("java.lang.String", mp.getImplementation());
102         assertTrue(mp.isEditable());
103         assertFalse(mp.isRequired());
104         assertEquals("parameter-description", mp.getDescription());
105         assertEquals("deprecated-parameter", mp.getDeprecated());
106         assertEquals("${jar.finalName}", mp.getExpression());
107         assertEquals("${project.build.finalName}", mp.getDefaultValue());
108         assertEquals("3.0.0", mp.getSince());
109 
110         ComponentRequirement cr = md.getRequirements().get(0);
111 
112         assertEquals("org.codehaus.plexus.archiver.Archiver", cr.getRole());
113         assertEquals("jar", cr.getRoleHint());
114         assertEquals("jarArchiver", cr.getFieldName());
115 
116         ComponentDependency cd = pd.getDependencies().get(0);
117 
118         assertEquals("org.apache.maven", cd.getGroupId());
119         assertEquals("maven-plugin-api", cd.getArtifactId());
120         assertEquals("2.0.6", cd.getVersion());
121         assertEquals("jar", cd.getType());
122 
123         md = pd.getMojos().get(1);
124 
125         assertEquals("war", md.getGoal());
126         assertNull(md.getDependencyResolutionRequired());
127         assertNull(md.getDependencyCollectionRequired());
128         assertTrue(md.isThreadSafe());
129     }
130 }