Beispiel #1
0
  public static Path compile(
      Path str,
      String main,
      Map<Path, Integer> dependentFiles,
      SGLR strParser,
      ModuleKeyCache<Path> strCache,
      Environment environment,
      AbstractBaseProcessor baseProcessor)
      throws IOException, InvalidParseTableException, TokenExpectedException, BadTokenException,
          SGLRException {
    ModuleKey key = getModuleKeyForAssimilation(str, main, dependentFiles, strParser);
    Path prog = lookupAssimilationInCache(strCache, key);
    StrategoException error = null;

    if (prog == null) {
      try {
        prog = generateAssimilator(key, str, main, environment.getIncludePath(), baseProcessor);
      } catch (StrategoException e) {
        prog = FAILED_COMPILATION_PATH;
        error = e;
      } finally {
        if (prog != null && FileCommands.exists(prog) && !FileCommands.isEmptyFile(prog))
          prog = cacheAssimilator(strCache, key, prog, environment);
      }

      if (error != null) throw error;
    }

    return prog;
  }
 private void writePersistentPath(long timeStamp) {
   try {
     if (!persistentPath.exists()) {
       FileCommands.createFile(persistentPath);
     }
     FileCommands.writeToFile(persistentPath, String.valueOf(timeStamp));
   } catch (IOException e) {
     Log.log.logErr(
         "There occured an error when creating or writing"
             + " the persistentPath of a RemoteRequirement",
         Log.CORE);
   }
 }
Beispiel #3
0
 private static Path generateAssimilator(
     ModuleKey key, Path str, String main, List<Path> paths, AbstractBaseProcessor baseProcessor)
     throws IOException {
   boolean success = false;
   log.beginTask("Generating", "Generate the assimilator", Log.TRANSFORM);
   try {
     Path prog = FileCommands.newTempFile("ctree");
     log.log("calling STRJ", Log.TRANSFORM);
     strj(true, str, prog, main, paths, baseProcessor);
     success = FileCommands.exists(prog);
     return prog;
   } finally {
     log.endTask(success);
   }
 }
Beispiel #4
0
 static {
   try {
     FAILED_COMPILATION_PATH = FileCommands.newTempFile("ctree");
   } catch (IOException e) {
     throw new IllegalStateException(e);
   }
 }
Beispiel #5
0
  private static Path cacheAssimilator(
      ModuleKeyCache<Path> strCache, ModuleKey key, Path prog, Environment environment)
      throws IOException {
    if (strCache == null) return prog;

    log.beginTask("Caching", "Cache assimilator", Log.CACHING);
    try {
      Path cacheProg = environment.createCachePath(prog.getFile().getName());
      if (FileCommands.exists(prog)) FileCommands.copyFile(prog, cacheProg);
      else cacheProg = prog;

      Path oldProg = strCache.putGet(key, cacheProg);
      //      FileCommands.delete(oldProg);

      log.log("Cache Location: " + cacheProg, Log.CACHING);
      return cacheProg;
    } finally {
      log.endTask();
    }
  }
 /**
  * Checks if a consistencycheck needs to be made.
  *
  * @param currentTime the time to check if the consistency needs to be checked.
  * @return true if a consistencycheck needs to be made.
  */
 private boolean needsConsistencyCheck(long currentTime) {
   if (!FileCommands.exists(persistentPath)) {
     writePersistentPath(currentTime);
     return true;
   }
   if (consistencyCheckInterval == NEVER_CHECK) {
     return false;
   }
   long lastConsistencyCheck = readPersistentPath();
   if (lastConsistencyCheck + consistencyCheckInterval < currentTime) {
     return true;
   }
   return false;
 }
Beispiel #7
0
 protected void clean(IProgressMonitor monitor) throws CoreException {
   File f =
       getProject()
           .getLocation()
           .append(
               JavaCore.create(getProject())
                   .getOutputLocation()
                   .makeRelativeTo(getProject().getFullPath()))
           .toFile();
   try {
     FileCommands.delete(new AbsolutePath(f.getPath()));
   } catch (IOException e) {
   }
 }
 private long readPersistentPath() {
   try {
     String persistentPathContent = FileCommands.readFileAsString(persistentPath);
     return Long.parseLong(persistentPathContent.replace("\n", ""));
   } catch (IOException e) {
     Log.log.logErr(
         "There occured an error reading the persistentPath " + "of a RemoteRequirement",
         Log.CORE);
   } catch (NumberFormatException e) {
     Log.log.logErr(
         "The content of the persistentPath of a "
             + "RemoteRequirement was not correctly written previously",
         Log.CORE);
   }
   // timestamp file was not found or was not correctly written.
   // Therefore we need to force a consistencycheck.
   return 0L;
 }
Beispiel #9
0
  private static ModuleKey getModuleKeyForAssimilation(
      Path str, String main, Map<Path, Integer> dependentFiles, SGLR strParser)
      throws IOException, InvalidParseTableException, TokenExpectedException, BadTokenException,
          SGLRException {
    log.beginTask("Generating", "Generate module key for current assimilation", Log.CACHING);
    try {
      IStrategoTerm aterm =
          (IStrategoTerm)
              strParser.parse(
                  FileCommands.readFileAsString(str), str.getAbsolutePath(), "StrategoModule");

      aterm = ATermCommands.getApplicationSubterm(aterm, "Module", 1);

      return new ModuleKey(dependentFiles, STR_FILE_PATTERN, aterm);
    } catch (Exception e) {
      throw new SGLRException(strParser, "could not parse STR file " + str, e);
    } finally {
      log.endTask();
    }
  }