Example #1
0
 /**
  * Returns a cached copy of the given file. The cached copy is guaranteed to not be modified or
  * removed.
  *
  * @param original The source file.
  * @param baseDirFactory A factory that can provide a base directory for the file cache.
  * @return The cached file.
  */
 public File getCachedJar(File original, Factory<File> baseDirFactory) {
   File source = FileUtils.canonicalize(original);
   FileInfo fileInfo;
   // TODO - do some of this work concurrently
   lock.lock();
   try {
     fileInfo = cachedFiles.getIfPresent(source);
     if (fileInfo == null || !fileInfo.cachedFile.exists()) {
       // TODO - use the hashing service for this
       long lastModified = source.lastModified();
       long length = source.length();
       HashValue hashValue = HashUtil.createHash(source, "sha1");
       fileInfo = copyIntoCache(baseDirFactory, source, lastModified, length, hashValue);
     } else {
       // TODO - use the change detection service for this
       long lastModified = source.lastModified();
       long length = source.length();
       if (lastModified != fileInfo.lastModified || length != fileInfo.length) {
         HashValue hashValue = HashUtil.createHash(source, "sha1");
         if (!hashValue.equals(fileInfo.hashValue)) {
           fileInfo = copyIntoCache(baseDirFactory, source, lastModified, length, hashValue);
         }
       }
     }
   } finally {
     lock.unlock();
   }
   return fileInfo.cachedFile;
 }
Example #2
0
 private File getOutputFile(WindowsResourceCompileSpec spec) {
   String outputFileName = FilenameUtils.getBaseName(inputFile.getName()) + ".res";
   String compactMD5 = HashUtil.createCompactMD5(inputFile.getAbsolutePath());
   File outputDirectory = new File(spec.getObjectFileDir(), compactMD5);
   if (!outputDirectory.exists()) {
     outputDirectory.mkdir();
   }
   File outputFile = new File(outputDirectory, outputFileName);
   return windowsPathLengthLimitation
       ? FileUtils.assertInWindowsPathLengthLimitation(outputFile)
       : outputFile;
 }