01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
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:
20: package org.apache.geronimo.mavenplugins.car;
21:
22: import java.util.List;
23: import java.util.Collections;
24:
25: /**
26: * Check that all dependencies mentioned explicitly in the car-maven-plugin configuration are present as maven dependencies.
27: *
28: * @goal validate-configuration
29: *
30: * @version $Rev: 613667 $ $Date: 2008-01-20 12:18:37 -0800 (Sun, 20 Jan 2008) $
31: */
32: public class ValidateConfigurationMojo extends AbstractCarMojo {
33:
34: /**
35: * Dependencies explicitly listed in the car-maven-plugin configuration
36: *
37: * @parameter
38: */
39: private List<Dependency> dependencies = Collections.emptyList();
40:
41: public void doExecute() {
42: for (Dependency dependency : dependencies) {
43: checkForMatch(dependency);
44: }
45: }
46:
47: private void checkForMatch(Dependency dependency) {
48: for (Object o : getProject().getDependencies()) {
49: org.apache.maven.model.Dependency test = (org.apache.maven.model.Dependency) o;
50: if (matches(test, dependency)) {
51: return;
52: }
53: }
54: throw new IllegalStateException("No match for dependency: "
55: + dependency);
56: }
57:
58: private boolean matches(org.apache.maven.model.Dependency test,
59: Dependency dependency) {
60: if (dependency.getGroupId() != null
61: && !dependency.getGroupId().equals(test.getGroupId())) {
62: return false;
63: }
64: if (dependency.getArtifactId() != null
65: && !dependency.getArtifactId().equals(
66: test.getArtifactId())) {
67: return false;
68: }
69: if (dependency.getVersion() != null
70: && !dependency.getVersion().equals(test.getVersion())) {
71: return false;
72: }
73: if (dependency.getType() != null
74: && !dependency.getType().equals(test.getType())) {
75: return false;
76: }
77: return true;
78: }
79: }
|