예제 #1
0
  public ParsedResult parseCode(String uri, String gsp) throws IOException {
    // Simulate what the parser does so we get it in the encoding expected
    Object enc = GrailsWebUtil.currentConfiguration().get("grails.views.gsp.encoding");
    if ((enc == null) || (enc.toString().trim().length() == 0)) {
      enc = System.getProperty("file.encoding", "us-ascii");
    }

    InputStream gspIn = new ByteArrayInputStream(gsp.getBytes(enc.toString()));
    GroovyPageParser parse = new GroovyPageParser(uri, uri, uri, gspIn, enc.toString(), "HTML");

    InputStream in = parse.parse();
    ParsedResult result = new ParsedResult();
    result.parser = parse;
    result.generatedGsp = IOGroovyMethods.getText(in, enc.toString());
    result.htmlParts = parse.getHtmlPartsArray();
    return result;
  }
예제 #2
0
  public void run(
      Level logLevel,
      ExecutorService executor,
      FileReadUtil fileReader,
      PerformanceTrackers perfTracking)
      throws IOException, FileFormatException {
    HashSet<List<String>> missingNamespaces = new HashSet<>();
    Logging log =
        this.logFile != null
            ? new LoggingImpl(
                logLevel,
                new PrintStream(this.logFile.toFile()),
                LoggingPrefixFormat.DATETIME_LEVEL_AND_CLASS)
            : null;

    val loadRes = SourceFiles.load(this.sources);
    if (log != null) {
      loadRes.log(log, logLevel, true);
    }

    // TODO debugging
    long start = System.nanoTime();

    val parseRes = ParsedResult.parse(loadRes.getSources(), executor, fileReader, perfTracking);

    // TODO debugging
    System.out.println(
        "load() time: "
            + TimeUnitUtil.convert(
                TimeUnit.NANOSECONDS, (System.nanoTime() - start), TimeUnit.MILLISECONDS)
            + " "
            + TimeUnitUtil.abbreviation(TimeUnit.MILLISECONDS, true, false));

    if (log != null) {
      parseRes.log(log, logLevel, true);
    }

    val resolvedRes = ResolvedResult.resolve(parseRes.compilationUnits, missingNamespaces);
    if (log != null) {
      resolvedRes.log(log, logLevel, true);
    }

    val filterRes = FilterResult.filter(resolvedRes.compilationUnits, this.destinations);
    if (log != null) {
      filterRes.log(log, logLevel, true);
    }

    WriteResult.write(filterRes.filterSets, missingNamespaces);
  }