Author: dennisl Date: Sat Jun 24 10:56:35 2006 New Revision: 416941 URL: http://svn.apache.org/viewvc?rev=416941&view=rev Log: Move utility methods to their own class
Added: maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/ModelUtils.java (with props) Modified: maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/plugins/AbstractPluginConfigurationConverter.java Added: maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/ModelUtils.java URL: http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/ModelUtils.java?rev=416941&view=auto ============================================================================== --- maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/ModelUtils.java (added) +++ maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/ModelUtils.java Sat Jun 24 10:56:35 2006 @@ -0,0 +1,86 @@ +package org.apache.maven.maven1converter; + +import org.apache.maven.model.Model; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.ReportPlugin; + +import java.util.Iterator; + +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Utility class which features various methods associated with Maven model. + * + * @author Dennis Lundberg + * @version $Id: PropertyUtils.java 410688 2006-05-31 22:21:07 +0000 (on, 31 maj 2006) carlos $ + */ +public class ModelUtils +{ + /** + * Try to find a build plugin in a model. + * + * @param model Look for the build plugin in this model + * @param groupId The groupId for the build plugin to look for + * @param artifactId The artifactId for the build plugin to look for + * @return The requested build plugin if it exists, otherwise null + */ + public static Plugin findBuildPlugin( Model model, String groupId, String artifactId ) + { + if ( model.getBuild() == null || model.getBuild().getPlugins() == null ) + { + return null; + } + + Iterator iterator = model.getBuild().getPlugins().iterator(); + while ( iterator.hasNext() ) + { + Plugin plugin = (Plugin) iterator.next(); + if ( plugin.getGroupId().equals( groupId ) && plugin.getArtifactId().equals( artifactId ) ) + { + return plugin; + } + } + return null; + } + + /** + * Try to find a report plugin in a model. + * + * @param model Look for the report plugin in this model + * @param groupId The groupId for the report plugin to look for + * @param artifactId The artifactId for the report plugin to look for + * @return The requested report plugin if it exists, otherwise null + */ + public static ReportPlugin findReportPlugin( Model model, String groupId, String artifactId ) + { + if ( model.getReporting() == null || model.getReporting().getPlugins() == null ) + { + return null; + } + + Iterator iterator = model.getReporting().getPlugins().iterator(); + while ( iterator.hasNext() ) + { + ReportPlugin plugin = (ReportPlugin) iterator.next(); + if ( plugin.getGroupId().equals( groupId ) && plugin.getArtifactId().equals( artifactId ) ) + { + return plugin; + } + } + return null; + } +} Propchange: maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/ModelUtils.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/plugins/AbstractPluginConfigurationConverter.java URL: http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/plugins/AbstractPluginConfigurationConverter.java?rev=416941&r1=416940&r2=416941&view=diff ============================================================================== --- maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/plugins/AbstractPluginConfigurationConverter.java (original) +++ maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/plugins/AbstractPluginConfigurationConverter.java Sat Jun 24 10:56:35 2006 @@ -22,9 +22,9 @@ import org.apache.maven.model.ReportPlugin; import org.apache.maven.model.Reporting; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.maven1converter.ModelUtils; import org.codehaus.plexus.util.xml.Xpp3Dom; -import java.util.Iterator; import java.util.Properties; /** @@ -96,7 +96,7 @@ { if ( TYPE_BUILD_PLUGIN.equals( getType() ) ) { - Plugin plugin = findBuildPlugin( v4Model, getGroupId(), getArtifactId() ); + Plugin plugin = ModelUtils.findBuildPlugin( v4Model, getGroupId(), getArtifactId() ); if ( plugin == null ) { addPlugin = true; @@ -118,7 +118,7 @@ } else if ( TYPE_REPORT_PLUGIN.equals( getType() ) ) { - ReportPlugin plugin = findReportPlugin( v4Model, getGroupId(), getArtifactId() ); + ReportPlugin plugin = ModelUtils.findReportPlugin( v4Model, getGroupId(), getArtifactId() ); if ( plugin == null ) { addPlugin = true; @@ -139,58 +139,6 @@ } } } - } - - /** - * Try to find a plugin in a model. - * - * @param model Look for the build plugin in this model - * @param groupId The groupId for the build plugin to look for - * @param artifactId The artifactId for the build plugin to look for - * @return The requested build plugin if it exists, otherwise null - */ - private Plugin findBuildPlugin( Model model, String groupId, String artifactId ) - { - if ( model.getBuild() == null || model.getBuild().getPlugins() == null ) - { - return null; - } - Iterator iterator = model.getBuild().getPlugins().iterator(); - while ( iterator.hasNext() ) - { - Plugin plugin = (Plugin) iterator.next(); - if ( plugin.getGroupId().equals( groupId ) && plugin.getArtifactId().equals( artifactId ) ) - { - return plugin; - } - } - return null; - } - - /** - * Try to find a report plugin in a model. - * - * @param model Look for the report plugin in this model - * @param groupId The groupId for the report plugin to look for - * @param artifactId The artifactId for the report plugin to look for - * @return The requested report plugin if it exists, otherwise null - */ - private ReportPlugin findReportPlugin( Model model, String groupId, String artifactId ) - { - if ( model.getReporting() == null || model.getReporting().getPlugins() == null ) - { - return null; - } - Iterator iterator = model.getReporting().getPlugins().iterator(); - while ( iterator.hasNext() ) - { - ReportPlugin plugin = (ReportPlugin) iterator.next(); - if ( plugin.getGroupId().equals( groupId ) && plugin.getArtifactId().equals( artifactId ) ) - { - return plugin; - } - } - return null; } protected abstract void buildConfiguration( Xpp3Dom configuration, org.apache.maven.model.v3_0_0.Model v3Model,