1 21 package proguard; 22 23 import java.io.File ; 24 25 30 public class UpToDateChecker 31 { 32 private Configuration configuration; 33 34 35 38 public UpToDateChecker(Configuration configuration) 39 { 40 this.configuration = configuration; 41 } 42 43 44 48 public boolean check() 49 { 50 long inputLastModified = configuration.lastModified; 51 long outputLastModified = Long.MAX_VALUE; 52 53 ClassPath programJars = configuration.programJars; 54 ClassPath libraryJars = configuration.libraryJars; 55 56 if (programJars != null) 58 { 59 for (int index = 0; index < programJars.size(); index++) 60 { 61 if (inputLastModified >= outputLastModified) 63 { 64 break; 65 } 66 67 ClassPathEntry classPathEntry = programJars.get(index); 69 if (classPathEntry.isOutput()) 70 { 71 long lastModified = lastModified(classPathEntry.getFile(), true); 72 if (outputLastModified > lastModified) 73 { 74 outputLastModified = lastModified; 75 } 76 } 77 else 78 { 79 long lastModified = lastModified(classPathEntry.getFile(), false); 80 if (inputLastModified < lastModified) 81 { 82 inputLastModified = lastModified; 83 } 84 } 85 } 86 } 87 88 if (libraryJars != null) 90 { 91 for (int index = 0; index < libraryJars.size(); index++) 92 { 93 if (inputLastModified >= outputLastModified) 95 { 96 break; 97 } 98 99 ClassPathEntry classPathEntry = libraryJars.get(index); 101 long lastModified = lastModified(classPathEntry.getFile(), false); 102 if (inputLastModified < lastModified) 103 { 104 inputLastModified = lastModified; 105 } 106 } 107 } 108 109 boolean outputUpToDate = inputLastModified < outputLastModified; 110 if (outputUpToDate) 111 { 112 System.out.println("The output is up to date"); 113 } 114 115 return outputUpToDate; 116 } 117 118 119 123 private long lastModified(File file, boolean minimum) 124 { 125 if (file.isDirectory()) 127 { 128 long lastModified = minimum ? Long.MAX_VALUE : 0; 130 131 File [] files = file.listFiles(); 132 for (int index = 0; index < files.length; index++) 133 { 134 long fileLastModified = lastModified(files[index], minimum); 135 if ((lastModified < fileLastModified) ^ minimum) 136 { 137 lastModified = fileLastModified; 138 } 139 } 140 141 return lastModified; 142 } 143 else 144 { 145 return file.lastModified(); 147 } 148 } 149 } 150 | Popular Tags |