View Javadoc

1   package de.matthias_burbach.deputy.core.repository;
2   
3   import java.io.File;
4   import java.util.ArrayList;
5   import java.util.Collections;
6   import java.util.Iterator;
7   import java.util.List;
8   
9   import javax.swing.tree.DefaultMutableTreeNode;
10  
11  import de.matthias_burbach.deputy.core.project.VersionComparator;
12  
13  /***
14   * Is an artifact node in the repositories tree.
15   *
16   * @author Matthias Burbach
17   */
18  public class RepositoryArtifact extends DefaultMutableTreeNode {
19      /***
20       * The directory to scan for versions of this artifact.
21       */
22      private File dir;
23  
24      /***
25       * The group id of this node's artifact.
26       */
27      private String groupId;
28  
29      /***
30       * The artifact id of this node's artifact.
31       */
32      private String artifactId;
33  
34      /***
35       * This node's available artifact versions of type {@link java.lang.String}.
36       */
37      private List artifactVersions = new ArrayList();
38  
39      /***
40       * Constructs a repository artifact node.
41       *
42       * @param groupId The group id of this node's artifact.
43       * @param dir The directory to scan for versions of this artifact.
44       * @param artifactId The artifact id of this node's artifact.
45       */
46      public RepositoryArtifact(
47              final String groupId,
48              final File dir,
49              final String artifactId) {
50          this.dir = dir;
51          this.artifactId = artifactId;
52          this.groupId = groupId;
53          initialize();
54      }
55  
56      /***
57       * Initializes this node by creating and adding the child nodes.
58       */
59      private void initialize() {
60          VersionScanner scanner = new VersionScanner();
61          if (dir.exists()) {
62              List versions =
63                  scanner.getAllVersions(
64                      dir.getAbsolutePath(),
65                      artifactId);
66              Collections.sort(versions, new VersionComparator());
67              for (Iterator iter = versions.iterator(); iter.hasNext();) {
68                  String version = (String) iter.next();
69                  RepositoryArtifactVersion artifactVersion =
70                      new RepositoryArtifactVersion(groupId, artifactId, version);
71                  artifactVersions.add(artifactVersion);
72                  add(artifactVersion);
73              }
74          }
75      }
76  
77      /***
78       * @return The group id of this node.
79       */
80      public String getGroupId() {
81          return groupId;
82      }
83  
84      /***
85       * @return The artifact id of this node.
86       */
87      public String getArtifactId() {
88          return artifactId;
89      }
90  
91      /*(non-Javadoc)
92       * @see java.lang.Object#toString()
93       */
94      /***
95       * {@inheritDoc}
96       */
97      public String toString() {
98          return artifactId;
99      }
100 }