View Javadoc

1   /*
2    * Copyright (c) 2007 Creative Sphere Limited.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Eclipse Public License v1.0
5    * which accompanies this distribution, and is available at
6    * http://www.eclipse.org/legal/epl-v10.html
7    *
8    * Contributors:
9    *
10   *   Creative Sphere - initial API and implementation
11   *
12   */
13  package org.abstracthorizon.extend.repository.maven.pom;
14  
15  
16  /**
17   * This class represents project
18   * 
19   * @author Daniel Sendula
20   */
21  public class POM extends Artifact {
22  
23      protected Parent parent;
24  
25      protected Dependencies dependencies;
26  
27      protected Properties properties;
28  
29      protected DependencyManagement dependencyManagement;
30      
31      protected POM parentPOM;
32      
33      protected String packaging;
34      
35      public POM() {
36      }
37  
38      public POM getParentPOM() {
39          return parentPOM;
40      }
41      
42      public void setParentPOM(POM parentPOM) {
43          this.parentPOM = parentPOM;
44      }
45      
46      public Parent getParent() {
47          return parent;
48      }
49      
50      public Parent addParent() {
51          if (parent == null) {
52              parent = new Parent();
53              return parent;
54          } else {
55              throw new RuntimeException("There can be only one Parent tag");
56          }
57      }
58      
59      public Dependencies getDependencies() {
60          return dependencies;
61      }
62  
63      public Dependencies addDependencies() {
64          if (dependencies == null) {
65              dependencies = new Dependencies();
66          }
67          return dependencies;
68      }
69      
70      public DependencyManagement getDependencyManagement() {
71          return dependencyManagement;
72      }
73  
74      public DependencyManagement addDependencyManagement() {
75          if (dependencyManagement == null) {
76              dependencyManagement = new DependencyManagement();
77          }
78          return dependencyManagement;
79      }
80      
81      public Properties getProperties() {
82          return properties;
83      }
84  
85      public Properties addProperties() {
86          if (properties == null) {
87              properties = new Properties();
88          }
89          return properties;
90      }
91      
92      public String getPackaging() {
93          return packaging;
94      }
95      
96      public void setPackaging(String packaging) {
97          this.packaging = packaging;
98      }
99  
100     public Dependency findDependency(String groupId, String artifactId) {
101         if (dependencies != null) {
102             return dependencies.findDependency(groupId, artifactId);
103         } else {
104             return null;
105         }
106     }
107     
108     public Dependency findManagedDependency(String groupId, String artifactId) {
109         Dependency dependency = null;
110         if (dependencyManagement != null) {
111             Dependencies dependencies = dependencyManagement.getDependencies();
112             if (dependencies != null) {
113                 dependency = dependencies.findDependency(groupId, artifactId);
114             }
115         }
116         if ((dependency == null) && (parentPOM != null)) {
117             return parentPOM.findManagedDependency(groupId, artifactId);
118         }
119         return dependency;
120     }
121     
122     
123     public String toString() {
124         StringBuffer res = new StringBuffer();
125         ToStringHelper.openTag("project", res, 0);
126         if (parent != null) {
127             res.append(parent.toString(2));
128         }
129         res.append(super.toString(2));
130         if (packaging != null) {
131             ToStringHelper.valueTag("packaging", packaging, res, 2);
132         }
133         
134         if (dependencies != null) {
135             res.append(dependencies.toString(2));
136         }
137         if (dependencyManagement != null) {
138             res.append(dependencyManagement.toString(2));
139         }
140         if (properties != null) {
141             res.append(properties.toString(2));
142         }
143         ToStringHelper.closeTag("project", res, 0);
144         return res.toString();
145     }
146 }