}
}
private int runOnce(boolean writeFiles) {
boolean success = false;
MessageContext mc = null;
CajoledModule compiledJsOutput = null;
Node compiledDomOutput = null;
String compiledHtmlOutput = null;
File fileLimitAncestor = config.getFetcherBase();
File jsOutputDest = config.getOutputJsFile();
File htmlOutputDest = config.getOutputHtmlFile();
try {
UriFetcher fetcher;
UriPolicy policy;
try {
if (fileLimitAncestor != null) {
UriToFile u2f = new UriToFile(fileLimitAncestor);
fetcher = ChainingUriFetcher.make(
new DataUriFetcher(),
new CachingUriFetcher(u2f));
policy = new FileSystemUriPolicy(u2f);
} else {
fetcher = new DataUriFetcher();
policy = UriPolicy.DENY_ALL;
}
} catch (IOException e) { // Could not resolve file name
fetcher = new DataUriFetcher();
policy = UriPolicy.DENY_ALL;
}
final Set<String> lUrls = config.getLinkableUris();
if (!lUrls.isEmpty()) {
final UriPolicy prePolicy = policy;
policy = new UriPolicy() {
public String rewriteUri(
ExternalReference u, UriEffect effect,
LoaderType loader, Map<String, ?> hints) {
String uri = u.getUri().toString();
if (lUrls.contains(uri)) { return uri; }
return prePolicy.rewriteUri(u, effect, loader, hints);
}
};
}
final Set<String> fUris = config.getFetchableUris();
final boolean fUriAll = config.hasFetchableUriAll();
if (fUriAll || !fUris.isEmpty()) {
fetcher = ChainingUriFetcher.make(
fetcher,
new UriFetcher() {
public FetchedData fetch(ExternalReference ref, String mimeType)
throws UriFetchException {
String uri = ref.getUri().toString();
if (!fUriAll && !fUris.contains(uri)) {
throw new UriFetchException(ref, mimeType);
}
try {
return FetchedData.fromConnection(
new URL(uri).openConnection());
} catch (IOException ex) {
throw new UriFetchException(ref, mimeType, ex);
}
}
});
}
if (config.hasLinkableUriAll()) {
policy = UriPolicy.IDENTITY;
} else if (config.hasLinkableUriRuntime()) {
policy = null;
}
PluginMeta meta = new PluginMeta(fetcher, policy);
meta.setIdClass(config.getIdClass());
meta.setPrecajoleMinify(
config.renderer() == Config.SourceRenderMode.MINIFY);
if (config.hasNoPrecajoled()) {
meta.setPrecajoleMap(null);
}
PluginCompiler compiler = new PluginCompiler(
BuildInfo.getInstance(), meta, mq);
compiler.setPreconditions(
config.preconditions(compiler.getPreconditions()));
compiler.setGoals(config.goals(compiler.getGoals()));
mc = compiler.getMessageContext();
compiler.setCssSchema(config.getCssSchema(mq));
compiler.setHtmlSchema(config.getHtmlSchema(mq));
success = parseInputs(meta, config.getInputUris(), compiler)
&& compiler.run();
if (success) {
compiledJsOutput = compiler.getJavascript();
compiledDomOutput = compiler.getStaticHtml();
compiledHtmlOutput = compiledDomOutput != null ?
Nodes.render(compiledDomOutput) : "";
}
} finally {
if (mc == null) { mc = new MessageContext(); }
MessageLevel maxMessageLevel = dumpMessages(mq, mc, System.err);
success &= MessageLevel.ERROR.compareTo(maxMessageLevel) > 0;
}
if (!writeFiles) {