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 class DeploymentUnit implements Comparable<DeploymentUnit>
10  {
11  	private final File path;
12      private long lastModifiedAtTimeOfDeployment;
13  
14      public DeploymentUnit(File path)
15  	{
16          if (path == null)
17          {
18              throw new IllegalArgumentException("File should not be null!");
19          }
20          this.path = path;
21          this.lastModifiedAtTimeOfDeployment = path.lastModified();
22      }
23  
24  	public long lastModified()
25  	{
26  		return lastModifiedAtTimeOfDeployment;
27  	}
28  
29  	public File getPath()
30  	{
31  		return path;
32  	}
33  
34      public int compareTo(DeploymentUnit target)
35      {
36          int result = path.compareTo(target.getPath());
37          if (result == 0)
38              result = (lastModifiedAtTimeOfDeployment > target.lastModified() ? 1 :
39                      lastModifiedAtTimeOfDeployment < target.lastModified() ? -1 : 0);
40          return result;
41      }
42  
43      public boolean equals(Object deploymentUnit)
44      {
45          if (deploymentUnit instanceof DeploymentUnit)
46              return equals((DeploymentUnit) deploymentUnit);
47          else
48              return false;
49      }
50  
51      public boolean equals(DeploymentUnit deploymentUnit)
52      {
53          if (!path.equals(deploymentUnit.path)) return false;
54          if (lastModifiedAtTimeOfDeployment != deploymentUnit.lastModifiedAtTimeOfDeployment) return false;
55  
56          return true;
57      }
58  
59      public int hashCode()
60      {
61          int result;
62          result = path.hashCode();
63          result = 31 * result + (int) (lastModifiedAtTimeOfDeployment ^ (lastModifiedAtTimeOfDeployment >>> 32));
64          return result;
65      }
66  
67      public String toString()
68      {
69          return "Unit: " + path.toString() + " (" + lastModifiedAtTimeOfDeployment + ")";
70      }
71  }