1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sourceforge.javadpkg.control.impl;
20
21 import java.util.List;
22
23 import net.sourceforge.javadpkg.BuildException;
24 import net.sourceforge.javadpkg.Context;
25 import net.sourceforge.javadpkg.control.PackageDependency;
26 import net.sourceforge.javadpkg.control.PackageDependencyBuilder;
27 import net.sourceforge.javadpkg.control.PackageNameBuilder;
28 import net.sourceforge.javadpkg.control.PackageVersionBuilder;
29 import net.sourceforge.javadpkg.control.PackageVersionRelationOperatorBuilder;
30
31
32
33
34
35
36
37
38
39
40 public class PackageDependencyBuilderImpl implements PackageDependencyBuilder {
41
42
43
44 private PackageNameBuilder packageNameBuilder;
45
46 private PackageVersionRelationOperatorBuilder packageVersionRelationOperatorBuilder;
47
48 private PackageVersionBuilder packageVersionBuilder;
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 public PackageDependencyBuilderImpl(PackageNameBuilder packageNameBuilder,
66 PackageVersionRelationOperatorBuilder packageVersionRelationOperatorBuilder,
67 PackageVersionBuilder packageVersionBuilder) {
68
69 super();
70
71 if (packageNameBuilder == null)
72 throw new IllegalArgumentException("Argument packageNameBuilder is null.");
73 if (packageVersionRelationOperatorBuilder == null)
74 throw new IllegalArgumentException("Argument packageVersionRelationOperatorBuilder is null.");
75 if (packageVersionBuilder == null)
76 throw new IllegalArgumentException("Argument packageVersionBuilder is null.");
77
78 this.packageNameBuilder = packageNameBuilder;
79 this.packageVersionRelationOperatorBuilder = packageVersionRelationOperatorBuilder;
80 this.packageVersionBuilder = packageVersionBuilder;
81 }
82
83
84 @Override
85 public String buildPackageDependency(PackageDependency dependency, Context context) throws BuildException {
86 String value;
87 StringBuilder sb;
88
89
90 if (dependency == null)
91 throw new IllegalArgumentException("Argument dependency is null.");
92 if (context == null)
93 throw new IllegalArgumentException("Argument context is null.");
94
95
96 if (dependency.isCondition()) {
97 sb = new StringBuilder();
98
99 for (PackageDependency dep : dependency.getConditionPackageDependencies()) {
100 if (sb.length() > 0) {
101 switch (dependency.getCondition()) {
102 case OR:
103 sb.append(" | ");
104 break;
105
106 default:
107 throw new BuildException("Unsupported dependency condition |" + dependency.getCondition() + "|.");
108 }
109
110 }
111 value = this.buildPackageDependency(dep, context);
112 sb.append(value);
113 }
114 value = sb.toString();
115 }
116
117 else {
118 sb = new StringBuilder();
119
120
121 try {
122 value = this.packageNameBuilder.buildPackageName(dependency.getPackage(), context);
123 } catch (BuildException e) {
124 throw new BuildException("Couldn't build dependency: " + e.getMessage(), e);
125 }
126 sb.append(value);
127
128 if (dependency.getVersion() != null) {
129 sb.append(" (");
130
131 if (dependency.getRelationOperator() != null) {
132 try {
133 value = this.packageVersionRelationOperatorBuilder
134 .buildPackageVersionRelationOperator(dependency.getRelationOperator(), context);
135 } catch (BuildException e) {
136 throw new BuildException("Couldn't build dependency: " + e.getMessage(), e);
137 }
138 sb.append(value);
139 sb.append(' ');
140 }
141
142
143 try {
144 value = this.packageVersionBuilder.buildPackageVersion(dependency.getVersion(), context);
145 } catch (BuildException e) {
146 throw new BuildException("Couldn't build dependency: " + e.getMessage(), e);
147 }
148 sb.append(value);
149 sb.append(')');
150 }
151 value = sb.toString();
152 }
153 return value;
154 }
155
156
157 @Override
158 public String buildPackageDependencies(List<PackageDependency> dependencies, Context context) throws BuildException {
159 StringBuilder result;
160 String value;
161
162
163 if (dependencies == null)
164 throw new IllegalArgumentException("Argument dependencies is null.");
165 if (context == null)
166 throw new IllegalArgumentException("Argument context is null.");
167
168 result = new StringBuilder();
169 for (PackageDependency dependency : dependencies) {
170 if (result.length() > 0) {
171 result.append(", ");
172 }
173
174 try {
175 value = this.buildPackageDependency(dependency, context);
176 } catch (BuildException e) {
177 throw new BuildException("Couldn't build dependencies: " + e.getMessage(), e);
178 }
179 result.append(value);
180 }
181 return result.toString();
182 }
183
184
185 }