1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
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 package org.apache.maven.shared.release.transform.jdom2;
20
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
24
25 import org.apache.maven.model.Build;
26 import org.apache.maven.model.Dependency;
27 import org.apache.maven.model.DependencyManagement;
28 import org.jdom2.Element;
29
30 /**
31 * <p>JDomModelBase class.</p>
32 *
33 * @author Robert Scholte
34 * @since 3.0
35 */
36 public class JDomModelBase {
37 private final Element modelBase;
38
39 /**
40 * <p>Constructor for JDomModelBase.</p>
41 *
42 * @param modelBase a {@link org.jdom2.Element} object
43 */
44 public JDomModelBase(Element modelBase) {
45 this.modelBase = modelBase;
46 }
47
48 /**
49 * <p>getBuild.</p>
50 *
51 * @return a {@link org.apache.maven.model.Build} object
52 */
53 public Build getBuild() {
54 Element elm = modelBase.getChild("build", modelBase.getNamespace());
55 if (elm == null) {
56 return null;
57 } else {
58 // this way build setters change DOM tree immediately
59 return new JDomBuild(elm);
60 }
61 }
62
63 /**
64 * <p>getDependencies.</p>
65 *
66 * @return a {@link java.util.List} object
67 */
68 public List<Dependency> getDependencies() {
69 Element dependenciesElm = modelBase.getChild("dependencies", modelBase.getNamespace());
70 if (dependenciesElm == null) {
71 return Collections.emptyList();
72 } else {
73 List<Element> dependencyElms = dependenciesElm.getChildren("dependency", modelBase.getNamespace());
74
75 List<Dependency> dependencies = new ArrayList<>(dependencyElms.size());
76
77 for (Element dependencyElm : dependencyElms) {
78 dependencies.add(new JDomDependency(dependencyElm));
79 }
80
81 return dependencies;
82 }
83 }
84
85 /**
86 * <p>getDependencyManagement.</p>
87 *
88 * @return a {@link org.apache.maven.model.DependencyManagement} object
89 */
90 public DependencyManagement getDependencyManagement() {
91 Element elm = modelBase.getChild("dependencyManagement", modelBase.getNamespace());
92 if (elm == null) {
93 return null;
94 } else {
95 // this way build setters change DOM tree immediately
96 return new JDomDependencyManagement(elm);
97 }
98 }
99 }