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