예제 #1
0
  public HelpManager(PathConfig pcfg, PrintWriter stdout, PrintWriter stderr) {
    this.pcfg = pcfg;
    this.stdout = stdout;
    this.stderr = stderr;

    ISourceLocation binDir = pcfg.getBoot();
    coursesDir =
        URIUtil.correctLocation(
            binDir.getScheme(), binDir.getAuthority(), binDir.getPath() + "/courses");

    try {
      helpServer = new HelpServer(getPort(), this, coursesDir);
      indexSearcher = makeIndexSearcher();
    } catch (IOException e) {
      System.err.println("HelpManager: " + e.getMessage());
    }
  }
예제 #2
0
 Path copyToTmp(ISourceLocation fromDir) throws IOException {
   Path targetDir = Files.createTempDirectory(URIUtil.getLocationName(fromDir));
   targetDir.toFile().deleteOnExit();
   URIResolverRegistry reg = URIResolverRegistry.getInstance();
   for (ISourceLocation file : reg.list(fromDir)) {
     if (!reg.isDirectory(file)) {
       String p = file.getPath();
       int n = p.lastIndexOf("/");
       String fileName = n >= 0 ? p.substring(n + 1) : p;
       // Only copy _* (index files) and segments* (defines number of segments)
       if (fileName.startsWith("_") || fileName.startsWith("segments")) {
         Path targetFile = targetDir.resolve(fileName);
         // System.out.println("copy " + file + " to " + toDir.resolve(fileName));
         Files.copy(reg.getInputStream(file), targetFile);
         targetFile.toFile().deleteOnExit();
       }
     }
   }
   return targetDir;
 }
예제 #3
0
 private CompletionResult completeLocation(String line, int locationStart) {
   int locationEnd = StringUtils.findRascalLocationEnd(line, locationStart);
   try {
     String locCandidate = line.substring(locationStart + 1, locationEnd + 1);
     if (!locCandidate.contains("://")) {
       return null;
     }
     ISourceLocation directory = VF.sourceLocation(new URI(locCandidate));
     String fileName = "";
     URIResolverRegistry reg = URIResolverRegistry.getInstance();
     if (!reg.isDirectory(directory)) {
       // split filename and directory
       String fullPath = directory.getPath();
       int lastSeparator = fullPath.lastIndexOf('/');
       fileName = fullPath.substring(lastSeparator + 1);
       fullPath = fullPath.substring(0, lastSeparator);
       directory = VF.sourceLocation(directory.getScheme(), directory.getAuthority(), fullPath);
       if (!reg.isDirectory(directory)) {
         return null;
       }
     }
     String[] filesInPath = reg.listEntries(directory);
     URI directoryURI = directory.getURI();
     Set<String> result = new TreeSet<>(); // sort it up
     for (String currentFile : filesInPath) {
       if (currentFile.startsWith(fileName)) {
         URI currentDir = URIUtil.getChildURI(directoryURI, currentFile);
         boolean isDirectory = reg.isDirectory(VF.sourceLocation(currentDir));
         result.add(currentDir.toString() + (isDirectory ? "/" : "|"));
       }
     }
     if (result.size() > 0) {
       return new CompletionResult(locationStart + 1, result);
     }
     return null;
   } catch (URISyntaxException | IOException e) {
     return null;
   }
 }
예제 #4
0
 private String extractClassName(ISourceLocation jarLoc) {
   return jarLoc.getPath().substring(jarLoc.getPath().indexOf("!") + 1);
 }
예제 #5
0
 private String extractJarName(ISourceLocation jarLoc) {
   String tmp = jarLoc.getPath().substring(0, jarLoc.getPath().indexOf("!"));
   return tmp.substring(tmp.lastIndexOf("/") + 1);
 }