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