Search in sources :

Example 1 with LoggerErrorManager

use of com.google.javascript.jscomp.LoggerErrorManager in project closure-compiler by google.

the class DependencyFile method loadGraph.

/**
 * Loads the dependency graph.
 */
private void loadGraph() throws ServiceException {
    dependencies.clear();
    logger.info("Loading dependency graph");
    // Parse the deps.js file.
    ErrorManager errorManager = new LoggerErrorManager(logger);
    DepsFileRegexParser parser = new DepsFileRegexParser(errorManager);
    List<DependencyInfo> depInfos = parser.parseFile(getName(), getContent());
    // Ensure the parse succeeded.
    if (!parser.didParseSucceed()) {
        throw new ServiceException("Problem parsing " + getName() + ". See logs for details.");
    }
    // Incorporate the dependencies into our maps.
    for (DependencyInfo depInfo : depInfos) {
        for (String provide : depInfo.getProvides()) {
            DependencyInfo existing = dependencies.get(provide);
            if (existing != null && !existing.equals(depInfo)) {
                throw new ServiceException("Duplicate provide of " + provide + ". Was provided by " + existing.getPathRelativeToClosureBase() + " and " + depInfo.getPathRelativeToClosureBase());
            }
            dependencies.put(provide, depInfo);
        }
    }
    List<String> provides = new ArrayList<>();
    provides.add(CLOSURE_BASE_PROVIDE);
    // Add implicit base.js entry.
    dependencies.put(CLOSURE_BASE_PROVIDE, SimpleDependencyInfo.builder(CLOSURE_BASE, CLOSURE_BASE).setProvides(provides).build());
    errorManager.generateReport();
    logger.info("Dependencies loaded");
}
Also used : LoggerErrorManager(com.google.javascript.jscomp.LoggerErrorManager) ErrorManager(com.google.javascript.jscomp.ErrorManager) ArrayList(java.util.ArrayList) LoggerErrorManager(com.google.javascript.jscomp.LoggerErrorManager)

Example 2 with LoggerErrorManager

use of com.google.javascript.jscomp.LoggerErrorManager in project closure-compiler by google.

the class DefaultDependencyResolver method parseRequires.

/**
 * Parses a block of code for goog.require statements and extracts the required symbols.
 */
private static Collection<String> parseRequires(String code, boolean addClosureBase) {
    ErrorManager errorManager = new LoggerErrorManager(logger);
    JsFileRegexParser parser = new JsFileRegexParser(errorManager);
    DependencyInfo deps = parser.parseFile("<unknown path>", "<unknown path>", code);
    List<String> requires = new ArrayList<>();
    if (addClosureBase) {
        requires.add(CLOSURE_BASE_PROVIDE);
    }
    requires.addAll(deps.getRequiredSymbols());
    errorManager.generateReport();
    return requires;
}
Also used : LoggerErrorManager(com.google.javascript.jscomp.LoggerErrorManager) ErrorManager(com.google.javascript.jscomp.ErrorManager) ArrayList(java.util.ArrayList) LoggerErrorManager(com.google.javascript.jscomp.LoggerErrorManager)

Aggregations

ErrorManager (com.google.javascript.jscomp.ErrorManager)2 LoggerErrorManager (com.google.javascript.jscomp.LoggerErrorManager)2 ArrayList (java.util.ArrayList)2