View Javadoc
1   /**
2    * @author mchyzer
3    * $Id$
4    */
5   package edu.internet2.middleware.grouperInstaller;
6   
7   import java.io.File;
8   
9   import edu.internet2.middleware.grouperInstaller.util.GrouperInstallerUtils;
10  
11  
12  /**
13   * when indexing a file, keep track of the name, file, type, etc
14   */
15  public class GrouperInstallerIndexFile {
16  
17    /**
18     * errors to print when there is an error
19     */
20    private StringBuilder errors = new StringBuilder();
21    
22    
23    /**
24     * errors to print when there is an error
25     * @return the errors
26     */
27    public StringBuilder getErrors() {
28      return this.errors;
29    }
30  
31    
32    /**
33     * errors to print when there is an error
34     * @param errors1 the errors to set
35     */
36    public void setErrors(StringBuilder errors1) {
37      this.errors = errors1;
38    }
39  
40    /**
41     * type of patch file
42     */
43    public static enum PatchFileType {
44      
45      /**
46       * normal file
47       */
48      file("files"),
49      
50      /**
51       * goes on classpath
52       */
53      clazz("classes"),
54      
55      /**
56       * library
57       */
58      lib("lib"),
59  
60      /**
61       * bin directory
62       */
63      bin("bin");
64  
65      /**
66       * dirname in patch
67       */
68      private String dirName;
69      
70      /**
71       * dirname in patch
72       * @return the dirName
73       */
74      public String getDirName() {
75        return this.dirName;
76      }
77      
78      /**
79       * dirname in patch
80       * @param dirName1 the dirName to set
81       */
82      public void setDirName(String dirName1) {
83        this.dirName = dirName1;
84      }
85  
86      /**
87       * construct with dir name
88       * @param theDirName
89       */
90      private PatchFileType(String theDirName) {
91        this.dirName = theDirName;
92      }
93      
94    }
95    
96    /**
97     * 
98     */
99    public GrouperInstallerIndexFile() {
100   }
101   
102   /**
103    * if there are multiple files by this simplename
104    */
105   private boolean hasMultipleFilesBySimpleName;
106   
107   /**
108    * if there are multiple files by path from start of project
109    */
110   private boolean hasMultipleFilesByPath;
111   
112   /**
113    * if there are multiple files by relative path (in the patch)
114    */
115   private boolean hasMultipleFilesByRelativePath;
116   
117   /**
118    * if there are multiple files by relative path (in the patch)
119    * @return the hasMultipleFilesByRelativePath
120    */
121   public boolean isHasMultipleFilesByRelativePath() {
122     return this.hasMultipleFilesByRelativePath;
123   }
124   
125   /**
126    * if there are multiple files by relative path (in the patch)
127    * @param hasMultipleFilesByRelativePath1 the hasMultipleFilesByRelativePath to set
128    */
129   public void setHasMultipleFilesByRelativePath(boolean hasMultipleFilesByRelativePath1) {
130     this.hasMultipleFilesByRelativePath = hasMultipleFilesByRelativePath1;
131   }
132 
133   /**
134    * if there are multiple files by this simplename
135    * @return the hasMultipleFilesBysimpleName
136    */
137   public boolean isHasMultipleFilesBySimpleName() {
138     return this.hasMultipleFilesBySimpleName;
139   }
140 
141 
142   
143   /**
144    * if there are multiple files by this simplename
145    * @param hasMultipleFilesBysimpleName1 the hasMultipleFilesBysimpleName to set
146    */
147   public void setHasMultipleFilesBySimpleName(boolean hasMultipleFilesBysimpleName1) {
148     this.hasMultipleFilesBySimpleName = hasMultipleFilesBysimpleName1;
149   }
150 
151   /**
152    * relative path is path from patch dir (e.g. inside files or classes)
153    */
154   private String relativePath;
155   
156   /**
157    * relative path is path from patch dir (e.g. inside files or classes)
158    * @return the relativePath
159    */
160   public String getRelativePath() {
161     return this.relativePath;
162   }
163 
164   
165   /**
166    * @see java.lang.Object#toString()
167    */
168   @Override
169   public String toString() {
170     return this.simpleName + ", relPath: " + this.relativePath + ", type: " + this.patchFileType
171         + ", hasMult: " + this.hasMultipleFilesBySimpleName + ", " + this.hasMultipleFilesByRelativePath + ", "
172         + this.hasMultipleFilesByPath;
173         
174   }
175 
176   /**
177    * relative path is path from patch dir (e.g. inside files or classes)
178    * @param relativePath1 the relativePath to set
179    */
180   public void setRelativePath(String relativePath1) {
181     this.relativePath = relativePath1;
182   }
183 
184   /**
185    * if there are multiple files by path from start of project
186    * @return the hasMultipleFilesByPath
187    */
188   public boolean isHasMultipleFilesByPath() {
189     return this.hasMultipleFilesByPath;
190   }
191 
192 
193   
194   /**
195    * if there are multiple files by path from start of project
196    * @param hasMultipleFilesByPath1 the hasMultipleFilesByPath to set
197    */
198   public void setHasMultipleFilesByPath(boolean hasMultipleFilesByPath1) {
199     this.hasMultipleFilesByPath = hasMultipleFilesByPath1;
200   }
201 
202   /**
203    * name and extension of file
204    */
205   private String simpleName;
206   
207   
208   /**
209    * name and extension of file
210    * @return the simpleName
211    */
212   public String getSimpleName() {
213     return this.simpleName;
214   }
215 
216   
217   /**
218    * name and extension of file
219    * @param simpleName1 the simpleName to set
220    */
221   public void setSimpleName(String simpleName1) {
222     this.simpleName = simpleName1;
223   }
224 
225   
226   /**
227    * type of file
228    * @return the patchFileType
229    */
230   public PatchFileType getPatchFileType() {
231     return this.patchFileType;
232   }
233 
234   
235   /**
236    * type of file
237    * @param patchFileType1 the patchFileType to set
238    */
239   public void setPatchFileType(PatchFileType patchFileType1) {
240     this.patchFileType = patchFileType1;
241   }
242 
243   
244   /**
245    * path from the project directory for the file
246    * @return the path
247    */
248   public String getPath() {
249     return this.path;
250   }
251 
252   
253   /**
254    * path from the project directory for the file
255    * @param path1 the path to set
256    */
257   public void setPath(String path1) {
258     this.path = path1;
259   }
260 
261   
262   /**
263    * reference to the file object itself
264    * @return the file
265    */
266   public File getFile() {
267     return this.file;
268   }
269 
270   
271   /**
272    * reference to the file object itself
273    * @param file1 the file to set
274    */
275   public void setFile(File file1) {
276     this.file = file1;
277     this.sha1 = null;
278   }
279 
280   /**
281    * null if not computed yet, or the sha1 on file
282    */
283   private String sha1;
284 
285   /**
286    * compute sha1
287    * @return the hex sha1
288    */
289   public String computeSha1() {
290     if (this.sha1 == null) {
291       if (this.file == null){
292         throw new RuntimeException("Need a file");
293       }
294       if (this.file.isDirectory()) {
295         throw new RuntimeException("Cant do sha1 on directory: " + this.file.getAbsolutePath());
296       }
297       this.sha1 = GrouperInstallerUtils.fileSha1(this.file);
298     }
299     return this.sha1;
300   }
301   
302   /**
303    * type of file
304    */
305   private PatchFileType patchFileType;
306 
307   /**
308    * path from the project directory for the file
309    */
310   private String path;
311   
312   /**
313    * reference to the file object itself
314    */
315   private File file;
316   
317 }