001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019
020
021 package org.apache.geronimo.mavenplugins.car;
022
023 import java.util.List;
024 import java.util.Collections;
025
026 /**
027 * Check that all dependencies mentioned explicitly in the car-maven-plugin configuration are present as maven dependencies.
028 *
029 * @goal validate-configuration
030 *
031 * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
032 */
033 public class ValidateConfigurationMojo extends AbstractCarMojo {
034
035 /**
036 * Dependencies explicitly listed in the car-maven-plugin configuration
037 *
038 * @parameter
039 */
040 private List<Dependency> dependencies = Collections.emptyList();
041
042 public void doExecute() {
043 for (Dependency dependency: dependencies) {
044 checkForMatch(dependency);
045 }
046 }
047
048 private void checkForMatch(Dependency dependency) {
049 for (Object o: getProject().getDependencies()) {
050 org.apache.maven.model.Dependency test = (org.apache.maven.model.Dependency) o;
051 if (matches(test, dependency)) {
052 return;
053 }
054 }
055 throw new IllegalStateException("No match for dependency: " + dependency);
056 }
057
058 private boolean matches(org.apache.maven.model.Dependency test, Dependency dependency) {
059 if (dependency.getGroupId() != null && !dependency.getGroupId().equals(test.getGroupId())) {
060 return false;
061 }
062 if (dependency.getArtifactId() != null && !dependency.getArtifactId().equals(test.getArtifactId())) {
063 return false;
064 }
065 if (dependency.getVersion() != null && !dependency.getVersion().equals(test.getVersion())) {
066 return false;
067 }
068 if (dependency.getType() != null && !dependency.getType().equals(test.getType())) {
069 return false;
070 }
071 return true;
072 }
073 }