View Javadoc
1   package com.atlassian.plugin.loaders.classloading;
2   
3   import java.io.File;
4   
5   /**
6    * A file that is to, or has been, deployed as a plugin. Differs to the {@link com.atlassian.plugin.PluginArtifact},
7    * which identifies an artifact to be deployed but may not be a physical file.
8    */
9   public final class DeploymentUnit implements Comparable<DeploymentUnit> {
10      private final File path;
11      private final long lastModifiedAtTimeOfDeployment;
12  
13      public DeploymentUnit(File path) {
14          if (path == null) {
15              throw new IllegalArgumentException("File should not be null!");
16          }
17          this.path = path;
18          this.lastModifiedAtTimeOfDeployment = path.lastModified();
19      }
20  
21      public long lastModified() {
22          return lastModifiedAtTimeOfDeployment;
23      }
24  
25      public File getPath() {
26          return path;
27      }
28  
29      public int compareTo(DeploymentUnit target) {
30          int result = path.compareTo(target.getPath());
31          if (result == 0) {
32              result = Long.compare(lastModifiedAtTimeOfDeployment, target.lastModified());
33          }
34          return result;
35      }
36  
37      public boolean equals(Object deploymentUnit) {
38          if (deploymentUnit instanceof DeploymentUnit) {
39              return equals((DeploymentUnit) deploymentUnit);
40          } else {
41              return false;
42          }
43      }
44  
45      public boolean equals(DeploymentUnit deploymentUnit) {
46          if (!path.equals(deploymentUnit.path)) {
47              return false;
48          }
49          if (lastModifiedAtTimeOfDeployment != deploymentUnit.lastModifiedAtTimeOfDeployment) {
50              return false;
51          }
52  
53          return true;
54      }
55  
56      public int hashCode() {
57          int result;
58          result = path.hashCode();
59          result = 31 * result + (int) (lastModifiedAtTimeOfDeployment ^ (lastModifiedAtTimeOfDeployment >>> 32));
60          return result;
61      }
62  
63      public String toString() {
64          return "Unit: " + path.toString() + " (" + lastModifiedAtTimeOfDeployment + ")";
65      }
66  }