1 package de.matthias_burbach.deputy.core.repository;
2
3 import java.io.File;
4 import java.util.Arrays;
5
6 import javax.swing.tree.DefaultMutableTreeNode;
7
8
9 /***
10 * Is a repository node in the repositories tree.
11 *
12 * @author Matthias Burbach
13 */
14 public class Repository extends DefaultMutableTreeNode {
15 /***
16 * The config info for this repository.
17 */
18 private RepositoryConfig repositoryConfig;
19
20 /***
21 * @param repositoryConfig The config info for the repository to construct.
22 */
23 public Repository(final RepositoryConfig repositoryConfig) {
24 this.repositoryConfig = repositoryConfig;
25 initialize();
26 }
27
28 /***
29 * Initializes this repository tree node by creating and
30 * adding a node for each child.
31 */
32 private void initialize() {
33 String repositoryPath = repositoryConfig.getPath();
34 File dir = new File(repositoryPath);
35 if (dir.exists() && dir.isDirectory()) {
36 File[] groups = dir.listFiles();
37 Arrays.sort(groups);
38 for (int i = 0; i < groups.length; i++) {
39 if (groups[i].isDirectory()) {
40 if (groups[i].getName().equals("vrp")) {
41 String[] specials = new String[] {
42 "vrp-assembly",
43 "vrp-adapter",
44 "vrp-brand",
45 "vrp-business",
46 "vrp-framework",
47 "vrp-legacy",
48 "vrp-legacy-adapter",
49 "vrp-presentation",
50 "vrp-serialization",
51 "vrp-transformation",
52 "vrp-webservice",
53 "vrp-xpres"
54 };
55 String[][] excludes = new String[][] {
56 {},
57 {},
58 {},
59 {},
60 {},
61 {"vrp-legacy-adapter"},
62 {},
63 {},
64 {},
65 {},
66 {},
67 {}
68 };
69 for (int j = 0; j < specials.length; j++) {
70 RepositoryGroup repositoryGroup =
71 new RepositoryGroup(
72 groups[i],
73 specials[j],
74 excludes[j]);
75
76
77 insert(repositoryGroup, j);
78 }
79 } else {
80 RepositoryGroup repositoryGroup =
81 new RepositoryGroup(groups[i], null, null);
82 add(repositoryGroup);
83 }
84 }
85 }
86 }
87 }
88
89
90
91
92 /***
93 * {@inheritDoc}
94 */
95 public String toString() {
96 return repositoryConfig.getDisplayName();
97 }
98
99 /***
100 * @param groupId The group id of the artifact to find the node for.
101 * @param artifactId The artifact id to find the node for.
102 * @param version The version of the artifact to find the node for.
103 * @return The node in this repository tree representing the versioned
104 * artifact passed in.
105 */
106 public RepositoryArtifactVersion findVersionNode(
107 final String groupId,
108 final String artifactId,
109 final String version) {
110 RepositoryArtifactVersion result = null;
111 RepositoryGroup repositoryGroup = null;
112
113
114
115
116 for (int i = getChildCount() - 1; i >= 0; i--) {
117 RepositoryGroup groupNode = (RepositoryGroup) getChildAt(i);
118 if (groupId.equals("vrp")) {
119 if (artifactId.startsWith(groupNode.toString())) {
120 repositoryGroup = groupNode;
121 break;
122 }
123 } else {
124 if (groupId.equals(groupNode.toString())) {
125 repositoryGroup = groupNode;
126 break;
127 }
128 }
129 }
130 if (repositoryGroup != null) {
131 RepositoryArtifact repositoryArtifact = null;
132 for (int i = 0; i < repositoryGroup.getChildCount(); i++) {
133 RepositoryArtifact artifactNode =
134 (RepositoryArtifact) repositoryGroup.getChildAt(i);
135 if (artifactId.equals(artifactNode.toString())) {
136 repositoryArtifact = artifactNode;
137 break;
138 }
139 }
140 if (repositoryArtifact != null) {
141 for (int i = 0; i < repositoryArtifact.getChildCount(); i++) {
142 RepositoryArtifactVersion versionNode =
143 (RepositoryArtifactVersion) repositoryArtifact
144 .getChildAt(i);
145 if (version.equals(versionNode.toString())) {
146 result = versionNode;
147 break;
148 }
149 }
150 }
151 }
152 return result;
153 }
154 }