]>
Commit | Line | Data |
---|---|---|
4b134847 | 1 | /** @file\r |
2 | This file is to define the FileTimeStamp class for speeding up the dependency check.\r | |
3 | \r | |
4 | Copyright (c) 2006, Intel Corporation\r | |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | package org.tianocore.common.cache;\r | |
15 | \r | |
16 | import java.io.File;\r | |
17 | import java.util.Map;\r | |
18 | import java.util.TreeMap;\r | |
19 | import java.util.HashMap;\r | |
20 | \r | |
21 | /**\r | |
22 | FileTimeStamp class is used to cache the time stamp of accessing file, which\r | |
23 | will speed up the dependency check for build\r | |
24 | **/\r | |
25 | public class FileTimeStamp {\r | |
26 | //\r | |
27 | // cache the modified timestamp of files accessed, to speed up the depencey check\r | |
28 | // \r | |
29 | private static Map<String, Long> timeStampCache = new HashMap<String, Long>();\r | |
30 | \r | |
31 | /**\r | |
32 | Get the time stamp of given file. It will try the cache first and then\r | |
33 | get from file system if no time stamp of the file is cached.\r | |
34 | \r | |
35 | @param file File name\r | |
36 | \r | |
37 | @return long The time stamp of the file\r | |
38 | **/\r | |
39 | synchronized public static long get(String file) {\r | |
40 | long timeStamp = 0;\r | |
41 | \r | |
42 | Long value = timeStampCache.get(file);\r | |
43 | if (value != null) {\r | |
44 | timeStamp = value.longValue();\r | |
45 | } else {\r | |
46 | timeStamp = new File(file).lastModified();\r | |
47 | timeStampCache.put(file, new Long(timeStamp));\r | |
48 | }\r | |
49 | \r | |
50 | return timeStamp;\r | |
51 | }\r | |
52 | \r | |
53 | /**\r | |
54 | Force update the time stamp for the given file\r | |
55 | \r | |
56 | @param file File name\r | |
57 | @param timeStamp The time stamp of the file\r | |
58 | **/\r | |
59 | synchronized public static void update(String file, long timeStamp) {\r | |
60 | timeStampCache.put(file, new Long(timeStamp));\r | |
61 | }\r | |
62 | \r | |
63 | /**\r | |
64 | Force update the time stamp for the given file\r | |
65 | \r | |
66 | @param file File name\r | |
67 | **/\r | |
68 | synchronized public static void update(String file) {\r | |
69 | long timeStamp = new File(file).lastModified();\r | |
70 | timeStampCache.put(file, new Long(timeStamp));\r | |
71 | }\r | |
72 | \r | |
73 | /**\r | |
74 | Check if the time stamp of given file has been cached for not\r | |
75 | \r | |
76 | @param file The file name\r | |
77 | \r | |
78 | @return boolean\r | |
79 | **/\r | |
80 | synchronized public static boolean containsKey(String file) {\r | |
81 | return timeStampCache.containsKey(file);\r | |
82 | }\r | |
83 | }\r |