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.project.canonical;
20  
21  import java.io.File;
22  import java.util.List;
23  
24  import org.apache.maven.api.xml.XmlNode;
25  import org.apache.maven.model.Plugin;
26  import org.apache.maven.model.PluginExecution;
27  import org.apache.maven.project.AbstractMavenProjectTestCase;
28  import org.apache.maven.project.MavenProject;
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   */
36  class CanonicalProjectBuilderTest extends AbstractMavenProjectTestCase {
37      @Test
38      void testProjectBuilder() throws Exception {
39          File f = getFileForClasspathResource("canonical-pom.xml");
40  
41          MavenProject project = getProject(f);
42  
43          // ----------------------------------------------------------------------
44          // Top-level elements
45          // ----------------------------------------------------------------------
46  
47          assertEquals("4.0.0", project.getModelVersion());
48  
49          // ----------------------------------------------------------------------
50          // Plugins
51          // ----------------------------------------------------------------------
52  
53          List<Plugin> plugins = project.getBuildPlugins();
54  
55          // Plugin0 [plexus]
56  
57          String key = "org.apache.maven.plugins:maven-plexus-plugin";
58  
59          Plugin plugin = null;
60          for (Plugin check : plugins) {
61              if (key.equals(check.getKey())) {
62                  plugin = check;
63                  break;
64              }
65          }
66  
67          assertNotNull(plugin);
68  
69          assertEquals("1.0", plugin.getVersion());
70  
71          XmlNode configuration = plugin.getDelegate().getConfiguration();
72  
73          assertEquals(
74                  "src/conf/plexus.conf",
75                  configuration.getChild("plexusConfiguration").getValue());
76  
77          assertEquals(
78                  "src/conf/plexus.properties",
79                  configuration.getChild("plexusConfigurationPropertiesFile").getValue());
80  
81          assertEquals(
82                  "Continuum", configuration.getChild("plexusApplicationName").getValue());
83  
84          // ----------------------------------------------------------------------
85          // Goal specific configuration
86          // ----------------------------------------------------------------------
87  
88          List<PluginExecution> executions = plugin.getExecutions();
89  
90          PluginExecution execution = executions.get(0);
91  
92          String g0 = execution.getGoals().get(0);
93  
94          assertEquals("plexus:runtime", g0);
95  
96          configuration = execution.getDelegate().getConfiguration();
97  
98          assertEquals(
99                  "ContinuumPro", configuration.getChild("plexusApplicationName").getValue());
100 
101         // Plugin1 [antlr]
102     }
103 }