View Javadoc

1   package org.apache.maven.model.converter;
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 org.apache.maven.model.Model;
23  import org.apache.maven.model.Plugin;
24  import org.apache.maven.model.ReportPlugin;
25  
26  import java.util.Iterator;
27  
28  /**
29   * Utility class which features various methods associated with Maven model.
30   *
31   * @author Dennis Lundberg
32   * @version $Id: ModelUtils.java 661727 2008-05-30 14:21:49Z bentmann $
33   */
34  public class ModelUtils
35  {
36      /**
37       * Try to find a build plugin in a model.
38       *
39       * @param model      Look for the build plugin in this model
40       * @param groupId    The groupId for the build plugin to look for
41       * @param artifactId The artifactId for the build plugin to look for
42       * @return The requested build plugin if it exists, otherwise null
43       */
44      public static Plugin findBuildPlugin( Model model, String groupId, String artifactId )
45      {
46          if ( model.getBuild() == null || model.getBuild().getPlugins() == null )
47          {
48              return null;
49          }
50  
51          Iterator iterator = model.getBuild().getPlugins().iterator();
52          while ( iterator.hasNext() )
53          {
54              Plugin plugin = (Plugin) iterator.next();
55              if ( plugin.getGroupId().equals( groupId ) && plugin.getArtifactId().equals( artifactId ) )
56              {
57                  return plugin;
58              }
59          }
60          return null;
61      }
62  
63      /**
64       * Try to find a report plugin in a model.
65       *
66       * @param model      Look for the report plugin in this model
67       * @param groupId    The groupId for the report plugin to look for
68       * @param artifactId The artifactId for the report plugin to look for
69       * @return The requested report plugin if it exists, otherwise null
70       */
71      public static ReportPlugin findReportPlugin( Model model, String groupId, String artifactId )
72      {
73          if ( model.getReporting() == null || model.getReporting().getPlugins() == null )
74          {
75              return null;
76          }
77          
78          Iterator iterator = model.getReporting().getPlugins().iterator();
79          while ( iterator.hasNext() )
80          {
81              ReportPlugin plugin = (ReportPlugin) iterator.next();
82              if ( plugin.getGroupId().equals( groupId ) && plugin.getArtifactId().equals( artifactId ) )
83              {
84                  return plugin;
85              }
86          }
87          return null;
88      }
89  }