Package org.sugarj.common.path

Examples of org.sugarj.common.path.RelativePath


   * @param driverResult
   * @return path to new Stratego module or null of no str file existed
   * @throws IOException
   */
  public static RelativePath importStratego(String modulePath, Environment environment, Result driverResult) {
    RelativePath str = searchFile(modulePath, "str", environment, driverResult);
   
    if (str == null)
      return null;

    log.log("Found desugaring for " + modulePath, Log.IMPORT);
View Full Code Here


   * @param driverResult
   * @return true iff a serv file existed.
   * @throws IOException
   */
  public static boolean importEditorServices(String modulePath, Environment environment, Result driverResult) throws IOException {
    RelativePath serv = searchFile(modulePath, "serv", environment, driverResult);
   
    if (serv == null)
      return false;
   
    BufferedReader reader = null;
   
    log.beginTask("Incorporation", "Found editor services for " + modulePath, Log.IMPORT);
    try {
      reader = new BufferedReader(new FileReader(serv.getFile()));
      String line;
     
      while ((line = reader.readLine()) != null)
        driverResult.addEditorService(ATermCommands.atermFromString(line));
     
View Full Code Here

      log.endTask();
    }
  }
 
  public static RelativePath importModel(String modulePath, Environment environment, Result driverResult) {
    RelativePath model = searchFile(modulePath, "model", environment, driverResult);
   
    if (model == null)
      return null;

    log.log("Found model for " + modulePath, Log.IMPORT);
View Full Code Here

  public static RelativePath locateSourceFile(String path, List<Path> sourcePath) {
    return locateSourceFile (FileCommands.dropExtension(path), FileCommands.getExtension(path), sourcePath);
  }

  public static RelativePath locateSourceFileOrModel(String modulePath, List<Path> sourcePath, AbstractBaseProcessor baseProcessor, Environment environment) {
    RelativePath result = locateSourceFile(modulePath, baseProcessor.getLanguage().getSugarFileExtension(), sourcePath);
    if (result == null)
      result = searchFile(modulePath, "model", environment, null);
    if (result == null && baseProcessor.getLanguage().getBaseFileExtension() != null)
      result = locateSourceFile(modulePath, baseProcessor.getLanguage().getBaseFileExtension(), sourcePath);
    return result;
View Full Code Here

   * @param fileExtension without leading "."
   * @return RelativePath or null.
   * @throws IOException
   */
  public static RelativePath searchFile(String relativePath, String fileExtension, Environment environment, Result driverResult) {
    RelativePath p;
   
    p = searchFile(environment.createOutPath(relativePath + "." + fileExtension), driverResult);
    if (p == null) {
      p = searchFile(environment.createOutPath(relativePath + "." + fileExtension), driverResult);
      if (p == null)
View Full Code Here

    return null;
  }
   
  private static RelativePath searchFileInSearchPath(String relativePath, String extension, List<Path> searchPath, Result driverResult) {
    for (Path base : searchPath) {
      RelativePath p = searchFile(base, relativePath, extension, driverResult);
      if (p != null)
        return p;
    }
   
    return null;
View Full Code Here

    return null;
  }

  private static RelativePath searchFileInSourceLocationPath(String relativePath, String extension, List<Path> searchPath, Result driverResult) {
    for (Path loc : searchPath) {
      RelativePath p = searchFile(loc, relativePath, extension, driverResult);
      if (p != null)
        return p;
    }
   
    return null;
View Full Code Here

    if (relativePath.startsWith(base.getAbsolutePath())) {
      int sepOffset = relativePath.endsWith(Environment.sep) ? 0 : 1;
      relativePath = relativePath.substring(base.getAbsolutePath().length() + sepOffset);
    }
   
    RelativePath p = new RelativePath(base, relativePath + "." + extension);
    if (driverResult != null)
      driverResult.addFileDependency(p);
    if (p.getFile().exists())
      return p;
   
    URLClassLoader cl = null;
    try {
      cl = new URLClassLoader(new URL[] {base.getFile().toURI().toURL()}, null);
      if (cl.getResource(relativePath + "." + extension) != null)
        return new RelativePath(base, relativePath + "." + extension);
    } catch (MalformedURLException e) {
      e.printStackTrace();
    } finally {
      /* URLClassLoader.close() is only available in Java 1.7.
      if (cl != null)
View Full Code Here

   * @param environment
   * @param driver
   * @return a pair consisting of the path to the transformed model and a flag indicating a circular import (if true).
   */
  public Pair<String, Boolean> transformModel(IStrategoTerm model, IStrategoTerm transformation, IStrategoTerm toplevelDecl) throws TokenExpectedException, IOException, ParseException, InvalidParseTableException, SGLRException, InterruptedException {
    RelativePath modelPath = resolveModule(model, toplevelDecl, true);
    RelativePath transformationPath = resolveModule(transformation, toplevelDecl, false);
   
    if (modelPath == null) {
      // something's wrong
      String name;
      try {
        name = baseProcessor.getModulePath(model);
      } catch (Exception e) {
        name = model.toString();
      }
      driver.setErrorMessage(toplevelDecl, "model not found " + name);
      return null;
    }
    if (transformationPath == null) {
      // something's wrong
      String name;
      try {
        name = baseProcessor.getModulePath(transformation);
      } catch (Exception e) {
        name = transformation.toString();
      }
      driver.setErrorMessage(toplevelDecl, "transformation not found " + name);
      return null;
    }

    Log.log.beginTask("Transform model " + FileCommands.fileName(modelPath) + " with transformation " + FileCommands.fileName(transformationPath), Log.TRANSFORM);
    try {
      RelativePath transformedModelSourceFile = getTransformedModelSourceFilePath(modelPath, transformationPath, environment);
      String transformedModelPath = FileCommands.dropExtension(transformedModelSourceFile.getRelativePath());
      Result transformedModelResult = ModuleSystemCommands.locateResult(transformedModelPath, environment);
 
      if (transformedModelResult != null && transformedModelResult.isUpToDate(environment)) {
        // result of transformation is already up-to-date, nothing to do here.
        driverResult.addDependency(transformedModelResult);
View Full Code Here

  public void setIncludePath(List<Path> includePath) {
    this.includePath = includePath;
  }

  public RelativePath createCachePath(String relativePath) {
    return new RelativePath(cacheDir, relativePath);
  }
View Full Code Here

TOP

Related Classes of org.sugarj.common.path.RelativePath

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.