Package org.sugarj.common.path

Examples of org.sugarj.common.path.Path


   
    return libDir;
  }

  public Path ensureFile(String resource) {
    Path f = new RelativePath(getPluginDirectory(), resource);
 
    if (FileCommands.exists(f))
      return f;
 
    if (libTmpDir == null) {
      try {
        libTmpDir = FileCommands.newTempDir();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
 
    f = new RelativePath(libTmpDir, resource);
    f.getFile().getParentFile().mkdirs();
 
    try {
      InputStream in = this.getClass().getClassLoader().getResourceAsStream(resource);
      if (in == null) {
        Log.log.logErr("Could not load resource " + resource, Log.ALWAYS);
        return new RelativePath(getPluginDirectory(), resource);
      }
 
      FileOutputStream fos = new FileOutputStream(f.getFile());
      int len = -1;
      byte[] bs = new byte[256];
      while ((len = in.read(bs)) >= 0)
        fos.write(bs, 0, len);
      fos.close();
View Full Code Here


  @Override
  public List<Path> compile(List<Path> outFiles, Path bin, List<Path> includePaths) throws IOException {
    List<Path> generatedFiles = new LinkedList<Path>();
    for (Path out : outFiles) {
      RelativePath relOut = (RelativePath) out;
      Path compilePath = new RelativePath(bin, FileCommands.dropExtension(relOut.getRelativePath()) + ".pts");
      FileCommands.copyFile(out, compilePath);
      generatedFiles.add(compilePath);
    }
    return generatedFiles;
  }
View Full Code Here

      getProject().accept(new IResourceVisitor() {
        Environment environment = SugarJParseController.makeProjectEnvironment(getProject());
       
        @Override
        public boolean visit(IResource resource) throws CoreException {
          Path root = new AbsolutePath(getProject().getLocation().makeAbsolute().toString());
          IPath relPath = resource.getFullPath().makeRelativeTo(getProject().getFullPath());
          if (!relPath.isEmpty() &&
              (environment.getParseBin().equals(new RelativePath(root, relPath.toString())) ||
               environment.getIncludePath().contains(new RelativePath(root, relPath.toString()))))
            return false;
View Full Code Here

   
    return null;
  }
 
  public static Result locateResult(String modulePath, Environment environment) {
    Path dep = ModuleSystemCommands.searchFile(modulePath, "dep", environment, null);
    Result res = null;
   
    if (dep != null)
      try {
        res = Result.readDependencyFile(dep);
View Full Code Here

  @Override
  public boolean call(IContext context, Strategy[] svars, IStrategoTerm[] tvars) throws InterpreterException {
    String modelPath = ATermCommands.getString(context.current());
    try {
      Path p = ModuleSystemCommands.importModel(modelPath, env, driverResult);
      if (p == null)
        return false;
      IStrategoTerm model = ATermCommands.atermFromFile(p.getAbsolutePath());
      if (model == null)
        return false;
      context.setCurrent(model);
      return true;
    } catch (IOException e) {
View Full Code Here

//          inputTreeBuilder.retract(restTerm);
//      } catch (Throwable t) {
//        t.printStackTrace();
//      }
     
      Path tmpFile = FileCommands.newTempFile("aterm");
      FileCommands.writeToFile(tmpFile, toplevelDecl.toString());
      log.log("next toplevel declaration parsed: " + tmpFile, Log.PARSE);

      return new IncrementalParseResult(toplevelDecl, rest);
    } catch (Exception e) {
View Full Code Here

  private static IStrategoTerm executeTransformation(RelativePath model, RelativePath transformationPath, IStrategoTerm toplevelDecl, Environment environment, STRCommands str, Driver driver) throws IOException, TokenExpectedException, BadTokenException, InvalidParseTableException, SGLRException {
    IStrategoTerm modelTerm = ATermCommands.atermFromFile(model.getAbsolutePath());
    String strat = "main-" + FileCommands.dropExtension(transformationPath.getRelativePath()).replace('/', '_');
    Result transformationResult = ModuleSystemCommands.locateResult(FileCommands.dropExtension(transformationPath.getRelativePath()), environment);
   
    Path trans = str.compile(transformationPath, strat, transformationResult.getTransitiveFileDependencies());
   
    IStrategoTerm transformationInput =
        ATermCommands.makeTuple(
            modelTerm,
            ATermCommands.makeString(FileCommands.dropExtension(model.getRelativePath()), null),
View Full Code Here

  public static IStrategoTerm atermFromString(String s) throws IOException {
    return new TAFTermReader(factory).parseFromString(s);
  }

  public static Path atermToFile(IStrategoTerm aterm) throws IOException {
    Path file = FileCommands.newTempFile("ast");
    atermToFile(aterm, file);
    return file;
  }
View Full Code Here

 
  private static Environment makeProjectEnvironment(IJavaProject project) throws JavaModelException {
    Environment env = new Environment(false, StdLib.stdLibDir);
   
    IPath fullPath = project.getProject().getFullPath();
    Path root = new AbsolutePath(project.getProject().getLocation().makeAbsolute().toString());
    Path bin = new RelativePath(root, project.getOutputLocation().makeRelativeTo(fullPath).toString());
    env.setRoot(root);
    env.setBin(bin);
   
    for (IPackageFragmentRoot fragment : project.getAllPackageFragmentRoots()) {
      IPath path = fragment.getPath();
      boolean externalPath = fragment.getResource() == null;
      String p = externalPath ? path.toString() : path.makeRelativeTo(fullPath).toString();

      Path includePath;
      if (fullPath.isPrefixOf(path))
        includePath = p.isEmpty() ? root : new RelativePath(root, p);
      else if (externalPath)
        includePath = new AbsolutePath(p);
      else
View Full Code Here

      e.printStackTrace();
    }
  }

  public static Path ensureFile(String resource) {
    Path f = new RelativePath(stdLibDir, resource);
    if (FileCommands.exists(f))
      return f;
   
    f = new RelativePath(stdLibTmpDir, resource);
    f.getFile().getParentFile().mkdirs();
   
    try {
      InputStream in = StdLib.class.getClassLoader().getResourceAsStream(resource);
      if (in == null)
        return new RelativePath(stdLibDir, resource);
     
      FileOutputStream fos = new FileOutputStream(f.getFile());
      int len = -1;
      byte[] bs = new byte[256];
      while ((len = in.read(bs)) >= 0)
        fos.write(bs, 0, len);
      fos.close();
View Full Code Here

TOP

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

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.