001package org.apache.maven.plugin;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *  http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.util.ArrayList;
023import java.util.List;
024
025import org.apache.maven.artifact.Artifact;
026import org.apache.maven.plugin.descriptor.PluginDescriptor;
027
028public class MavenPluginValidator
029{
030    private final Artifact pluginArtifact;
031
032    private List<String> errors = new ArrayList<String>();
033
034    private boolean firstDescriptor = true;
035
036    public MavenPluginValidator( Artifact pluginArtifact )
037    {
038        this.pluginArtifact = pluginArtifact;
039    }
040
041    public void validate( PluginDescriptor pluginDescriptor )
042    {
043        /*
044         * NOTE: For plugins that depend on other plugin artifacts the plugin realm contains more than one plugin
045         * descriptor. However, only the first descriptor is of interest.
046         */
047        if ( !firstDescriptor )
048        {
049            return;
050        }
051        firstDescriptor = false;
052
053        if ( !pluginArtifact.getGroupId().equals( pluginDescriptor.getGroupId() ) )
054        {
055            errors.add( "Plugin's descriptor contains the wrong group ID: " + pluginDescriptor.getGroupId() );
056        }
057
058        if ( !pluginArtifact.getArtifactId().equals( pluginDescriptor.getArtifactId() ) )
059        {
060            errors.add( "Plugin's descriptor contains the wrong artifact ID: " + pluginDescriptor.getArtifactId() );
061        }
062
063        if ( !pluginArtifact.getBaseVersion().equals( pluginDescriptor.getVersion() ) )
064        {
065            errors.add( "Plugin's descriptor contains the wrong version: " + pluginDescriptor.getVersion() );
066        }
067    }
068
069    public boolean hasErrors()
070    {
071        return !errors.isEmpty();
072    }
073
074    public List<String> getErrors()
075    {
076        return errors;
077    }
078}