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 = (lastModifiedAtTimeOfDeployment > target.lastModified() ? 1 :
33                      lastModifiedAtTimeOfDeployment < target.lastModified() ? -1 : 0);
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      public boolean equals(DeploymentUnit deploymentUnit) {
45          if (!path.equals(deploymentUnit.path)) return false;
46          if (lastModifiedAtTimeOfDeployment != deploymentUnit.lastModifiedAtTimeOfDeployment) return false;
47  
48          return true;
49      }
50  
51      public int hashCode() {
52          int result;
53          result = path.hashCode();
54          result = 31 * result + (int) (lastModifiedAtTimeOfDeployment ^ (lastModifiedAtTimeOfDeployment >>> 32));
55          return result;
56      }
57  
58      public String toString() {
59          return "Unit: " + path.toString() + " (" + lastModifiedAtTimeOfDeployment + ")";
60      }
61  }