List of usage examples for com.google.gwt.core.ext TreeLogger log
public final void log(TreeLogger.Type type, String msg, Throwable caught)
null helpInfo. From source file:cc.alcina.framework.entity.gen.SimpleCssResourceGenerator.java
License:Apache License
@Override public String createAssignment(TreeLogger logger, ResourceContext context, JMethod method) throws UnableToCompleteException { try {//from www. j av a 2 s . c om ConfigurationProperty cp = context.getGeneratorContext().getPropertyOracle() .getConfigurationProperty(IGNORE_DATA_URLS); logMissingUrlResources = !Boolean.valueOf(cp.getValues().get(0)); } catch (BadPropertyValueException e1) { e1.printStackTrace(); } URL[] resources = ResourceGeneratorUtil.findResources(logger, context, method); if (resources.length != 1) { logger.log(TreeLogger.ERROR, "Exactly one resource must be specified", null); throw new UnableToCompleteException(); } URL resource = resources[0]; SourceWriter sw = new StringSourceWriter(); // Write the expression to create the subtype. sw.println("new " + SimpleCssResource.class.getName() + "() {"); sw.indent(); if (!AbstractResourceGenerator.STRIP_COMMENTS) { // Convenience when examining the generated code. sw.println("// " + resource.toExternalForm()); } sw.println("public String getText() {"); sw.indent(); String toWrite = Util.readURLAsString(resource); if (context.supportsDataUrls()) { try { toWrite = replaceWithDataUrls(context, toWrite); } catch (Exception e) { logger.log(Type.ERROR, "css data url gen", e); throw new UnableToCompleteException(); } } if (toWrite.length() > MAX_STRING_CHUNK) { writeLongString(sw, toWrite); } else { sw.println("return \"" + Generator.escape(toWrite) + "\";"); } sw.outdent(); sw.println("}"); sw.println("public String getName() {"); sw.indent(); sw.println("return \"" + method.getName() + "\";"); sw.outdent(); sw.println("}"); sw.outdent(); sw.println("}"); return sw.toString(); }
From source file:cc.alcina.framework.gwt.appcache.linker.AppCacheManifestLinker.java
License:Apache License
/** * Find all instances of the filter pragma in the manifest template and * return compiled regular expression Pattern objects. *///from w w w . java2 s . c om private Set<Pattern> extractFilters(TreeLogger logger, CharSequence source) throws UnableToCompleteException { logger.branch(TreeLogger.DEBUG, "Finding @filter expressions", null); boolean filterError = false; Matcher filterMatcher = FILTER_PATTERN.matcher(source); Set<Pattern> filters = new HashSet<Pattern>(); while (filterMatcher.find()) { String pattern = filterMatcher.group(1); try { filters.add(Pattern.compile(pattern)); } catch (PatternSyntaxException e) { logger.log(TreeLogger.ERROR, "Could not compile filter pattern at character offset " + filterMatcher.start(), e); filterError = true; } } if (filterError) { throw new UnableToCompleteException(); } return filters; }
From source file:cc.alcina.framework.gwt.appcache.linker.AppCacheManifestLinker.java
License:Apache License
/** * Generate a string containing object literals for each manifest entry. *///from w w w. j av a2s. c om private String generateEntries(TreeLogger logger, LinkerContext context, Set<Pattern> filters, SortedSet<EmittedArtifact> artifacts) throws UnableToCompleteException { logger = logger.branch(TreeLogger.DEBUG, "Generating manifest contents", null); StringBuffer entries = new StringBuffer(); paths: for (EmittedArtifact artifact : artifacts) { if (artifact.getVisibility() != Visibility.Public) { // These artifacts won't be in the module output directory continue; } String path = artifact.getPartialPath(); for (Pattern p : filters) { if (p.matcher(path).matches()) { logger.log(TreeLogger.DEBUG, "Filtering resource " + path, null); continue paths; } } entries.append("/" + context.getModuleName() + "/" + path); entries.append("\n"); // Read the artifact into the digester InputStream in = artifact.getContents(logger); byte[] buffer = new byte[4096]; int read; try { while ((read = in.read(buffer)) != -1) { digester.update(buffer, 0, read); } } catch (IOException e) { logger.log(TreeLogger.ERROR, "Unable to read artifact " + artifact.getPartialPath(), e); throw new UnableToCompleteException(); } } // Add an alias for Module.nocache.js?compiled to support hosted-mode entries.append("/" + context.getModuleName() + "/" + context.getModuleName() + ".nocache.js?compiled\n"); entries.append("/" + context.getModuleName() + "/" + context.getModuleName() + ".nocache.js\n"); return entries.toString(); }
From source file:cc.alcina.framework.gwt.appcache.linker.AppCacheManifestLinker.java
License:Apache License
/** * Load the contents of the manifest template from a file named * {@value #APPCACHE_MANIFEST} in the root of the public path. Failing that, * use the built-in template./*from w w w . jav a2s . c o m*/ */ private StringBuffer readManifestTemplate(TreeLogger logger, EmittedArtifact userManifest) throws UnableToCompleteException { logger = logger.branch(TreeLogger.DEBUG, "Reading manifest template", null); InputStream in; // See if we have a user-provided manifest to work with if (userManifest != null) { logger.log(TreeLogger.DEBUG, "Reading user-provided manifest", null); in = userManifest.getContents(logger); if (in == null) { logger.log(TreeLogger.ERROR, "Unable to read contents of user manifest", null); throw new UnableToCompleteException(); } } else { // Fall back to the built-in manifest String packagePath = getClass().getPackage().getName().replace('.', '/'); String resourceName = packagePath + "/" + APPCACHE_MANIFEST; in = getClass().getClassLoader().getResourceAsStream(resourceName); if (in == null) { logger.log(TreeLogger.ERROR, "Could not load built-in manifest from " + resourceName, null); throw new UnableToCompleteException(); } } StringBuffer out = new StringBuffer(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); try { for (String line = reader.readLine(); line != null; line = reader.readLine()) { out.append(line).append("\n"); } } catch (IOException e) { logger.log(TreeLogger.ERROR, "Unable to read manifest template", e); throw new UnableToCompleteException(); } return out; }
From source file:com.ait.ext4j.rebind.BeanModelGenerator.java
License:Apache License
@Override public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException { oracle = context.getTypeOracle();// w ww .j a v a 2 s.c o m beanModelMarkerType = oracle.findType(BeanModelMarker.class.getName()); beanModelTagType = oracle.findType(BeanModelTag.class.getName()); try { // final all beans and bean markers beans = new ArrayList<JClassType>(); JClassType[] types = oracle.getTypes(); for (JClassType type : types) { if (isBeanMarker(type)) { beans.add(getMarkerBean(type)); } else if (isBean(type)) { beans.add(type); } } final String genPackageName = BeanModelLookup.class.getPackage().getName(); final String genClassName = "BeanModelLookupImpl"; ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(genPackageName, genClassName); composer.setSuperclass(BeanModelLookup.class.getCanonicalName()); composer.addImport(BeanModelFactory.class.getName()); composer.addImport(Map.class.getName()); composer.addImport(FastMap.class.getName()); PrintWriter pw = context.tryCreate(logger, genPackageName, genClassName); if (pw != null) { SourceWriter sw = composer.createSourceWriter(context, pw); sw.println("private Map<String, BeanModelFactory> m;"); sw.println("public BeanModelFactory getFactory(Class b) {"); sw.indent(); sw.println("String n = b.getName();"); sw.println("if (m == null) {"); sw.indentln("m = new FastMap<BeanModelFactory>();"); sw.println("}"); sw.println("if (m.get(n) == null) {"); sw.indent(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < beans.size(); i++) { JClassType bean = beans.get(i); String name = createBean(bean, logger, context); String factory = createFactory(bean, name, logger, context); if (i > 0) { sw.print(" else "); } sw.println("if (" + bean.getQualifiedSourceName() + ".class.getName().equals(n)) {"); sw.indentln("m" + i + "();"); sb.append("private void m" + i + "() {\n"); sb.append(" m.put(" + bean.getQualifiedSourceName() + ".class.getName(), new " + factory + "());\n"); sb.append("}\n"); sw.print("}"); } sw.outdent(); sw.println("}"); sw.println("return m.get(n);"); sw.outdent(); sw.println("}"); sw.println(sb.toString()); sw.commit(logger); } return composer.getCreatedClassName(); } catch (Exception e) { logger.log(TreeLogger.ERROR, "Class " + typeName + " not found.", e); throw new UnableToCompleteException(); } }
From source file:com.ait.toolkit.flash.linker.SwfIFrameLinker.java
License:Open Source License
/** * Generate a selection script. The selection information should previously * have been scanned using/*from w w w. java 2s . c o m*/ * {@link PermutationsUtil#setupPermutationsMap(ArtifactSet)}. */ @Override protected String fillSelectionScriptTemplate(StringBuffer selectionScript, TreeLogger logger, LinkerContext context, ArtifactSet artifacts, CompilationResult result) throws UnableToCompleteException { String computeScriptBase; String processMetas; try { computeScriptBase = Utility.getFileFromClassPath(COMPUTE_SCRIPT_BASE_JS); processMetas = Utility.getFileFromClassPath(PROCESS_METAS_JS); } catch (IOException e) { logger.log(TreeLogger.ERROR, "Unable to read selection script template", e); throw new UnableToCompleteException(); } replaceAll(selectionScript, "__COMPUTE_SCRIPT_BASE__", computeScriptBase); replaceAll(selectionScript, "__PROCESS_METAS__", processMetas); selectionScript = InjectionUtil.injectResources(selectionScript, artifacts); permutationsUtil.addPermutationsJs(selectionScript, logger, context); replaceAll(selectionScript, "__MODULE_FUNC__", context.getModuleFunctionName()); replaceAll(selectionScript, "__MODULE_NAME__", context.getModuleName()); replaceAll(selectionScript, "__HOSTED_FILENAME__", getHostedFilename()); return selectionScript.toString(); }
From source file:com.ait.toolkit.flash.linker.SwfSingleScriptLinker.java
License:Open Source License
/** * Generate a selection script. The selection information should previously * have been scanned using/*from w w w .ja va 2 s. c om*/ * {@link PermutationsUtil#setupPermutationsMap(ArtifactSet)}. */ @Override /** * Generate a selection script. The selection information should previously * have been scanned using * {@link PermutationsUtil#setupPermutationsMap(ArtifactSet)}. */ protected String fillSelectionScriptTemplate(StringBuffer selectionScript, TreeLogger logger, LinkerContext context, ArtifactSet artifacts, CompilationResult result) throws UnableToCompleteException { String computeScriptBase; String processMetas; try { computeScriptBase = Utility.getFileFromClassPath(COMPUTE_SCRIPT_BASE_JS); processMetas = Utility.getFileFromClassPath(PROCESS_METAS_JS); } catch (IOException e) { logger.log(TreeLogger.ERROR, "Unable to read selection script template", e); throw new UnableToCompleteException(); } replaceAll(selectionScript, "__COMPUTE_SCRIPT_BASE__", computeScriptBase); replaceAll(selectionScript, "__PROCESS_METAS__", processMetas); selectionScript = InjectionUtil.injectResources(selectionScript, artifacts); permutationsUtil.addPermutationsJs(selectionScript, logger, context); replaceAll(selectionScript, "__MODULE_FUNC__", context.getModuleFunctionName()); replaceAll(selectionScript, "__MODULE_NAME__", context.getModuleName()); replaceAll(selectionScript, "__HOSTED_FILENAME__", getHostedFilename()); return selectionScript.toString(); }
From source file:com.ait.toolkit.node.dev.linker.NodeJsLinker.java
License:Open Source License
@Override public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts) throws UnableToCompleteException { ArtifactSet toReturn = new ArtifactSet(artifacts); DefaultTextOutput out = new DefaultTextOutput(true); // inject other scripts // for (ScriptReference resource : // artifacts.find(ScriptReference.class)) { // out.print(resource.toString()); // }//from w w w. jav a 2 s.com // closure // out.print("(function () {"); // out.newline(); // grab compilation result Set<CompilationResult> results = artifacts.find(CompilationResult.class); CompilationResult result = null; if (results.size() > 1) { logger.log(TreeLogger.ERROR, "The module must have exactly one distinct" + " permutation when using the " + getDescription() + " Linker.", null); throw new UnableToCompleteException(); } else if (!results.isEmpty()) { result = results.iterator().next(); // dump JS String[] js = result.getJavaScript(); if (js.length != 1) { logger.log(TreeLogger.ERROR, "The module must not have multiple fragments when using the " + getDescription() + " Linker.", null); throw new UnableToCompleteException(); } out.print(js[0]); out.newline(); } out.print("var $stats = function() { };"); out.newline(); out.print("var $sessionId = function() { };"); out.newline(); // global window // TODO: check this against jsdom // out.print("var window = { };"); // out.newline(); // preload code addPreloadCode(logger, context, artifacts, result, out); out.newline(); out.print("gwtOnLoad(null, '" + context.getModuleName() + "', null);"); out.newline(); // out.print("})();"); // out.newline(); // and to string toReturn.add(emitString(logger, out.toString(), context.getModuleName() + ".js")); return toReturn; }
From source file:com.ait.toolkit.node.dev.linker.NodeJsSymbolStoreLinker.java
License:Open Source License
@Override protected void addPreloadCode(TreeLogger logger, LinkerContext context, ArtifactSet artifacts, CompilationResult result, DefaultTextOutput out) throws UnableToCompleteException { super.addPreloadCode(logger, context, artifacts, result, out); //add the symbols out.print("//--- BEGIN SYMBOL MAPPING ---"); out.newline();//from w ww .j a va 2 s .c o m out.print("//create symbol mapping object"); out.newline(); StringBuilder objectJs = new StringBuilder(); BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader( NodeJsSymbolStoreLinker.class.getResourceAsStream("SymbolStoreObject.js"))); String line = reader.readLine(); while (line != null) { line = line.replace("${objectName}", ClientSymbolStore.GLOBAL_JS_OBJECT_NAME); line = line.replace("${classesName}", ClientSymbolStore.CLASSES_MAP_NAME); line = line.replace("${methodsName}", ClientSymbolStore.METHODS_MAP_NAME); line = line.replace("${fieldsName}", ClientSymbolStore.FIELDS_MAP_NAME); objectJs.append(line).append("\n"); line = reader.readLine(); } } catch (IOException e) { logger.log(Type.ERROR, "Can't read local file", e); throw new UnableToCompleteException(); } finally { try { reader.close(); } catch (Exception ignore) { } } out.print(objectJs.toString()); out.newline(); out.print("//add symbols"); for (SymbolData symbol : result.getSymbolMap()) { out.newline(); out.print("global."); out.print(ClientSymbolStore.GLOBAL_JS_OBJECT_NAME); out.print("._add("); out.print(buildSymbolJson(symbol)); out.print(");"); } out.newline(); out.print("//--- END SYMBOL MAPPING ---"); out.newline(); }
From source file:com.ait.toolkit.rebind.BeanModelGenerator.java
License:Open Source License
@Override public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException { oracle = context.getTypeOracle();/*from w w w. j a v a 2s. c om*/ beanModelMarkerType = oracle.findType(BeanMarker.class.getName()); beanModelTagType = oracle.findType(BeanTag.class.getName()); try { // final all beans and bean markers beans = new ArrayList<JClassType>(); JClassType[] types = oracle.getTypes(); for (JClassType type : types) { if (isBeanMarker(type)) { beans.add(getMarkerBean(type)); } else if (isBean(type)) { beans.add(type); } } final String genPackageName = BeanLookup.class.getPackage().getName(); final String genClassName = "BeanLookupImpl"; ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(genPackageName, genClassName); composer.setSuperclass(BeanLookup.class.getCanonicalName()); composer.addImport(BeanFactory.class.getName()); composer.addImport(Map.class.getName()); composer.addImport(FastMap.class.getName()); PrintWriter pw = context.tryCreate(logger, genPackageName, genClassName); if (pw != null) { SourceWriter sw = composer.createSourceWriter(context, pw); sw.println("private Map<String, BeanFactory> m;"); sw.println("public BeanFactory getFactory(Class b) {"); sw.indent(); sw.println("String n = b.getName();"); sw.println("if (m == null) {"); sw.indentln("m = new FastMap<BeanFactory>();"); sw.println("}"); sw.println("if (m.get(n) == null) {"); sw.indent(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < beans.size(); i++) { JClassType bean = beans.get(i); String name = createBean(bean, logger, context); String factory = createFactory(bean, name, logger, context); if (i > 0) { sw.print(" else "); } sw.println("if (" + bean.getQualifiedSourceName() + ".class.getName().equals(n)) {"); sw.indentln("m" + i + "();"); sb.append("private void m" + i + "() {\n"); sb.append(" m.put(" + bean.getQualifiedSourceName() + ".class.getName(), new " + factory + "());\n"); sb.append("}\n"); sw.print("}"); } sw.outdent(); sw.println("}"); sw.println("return m.get(n);"); sw.outdent(); sw.println("}"); sw.println(sb.toString()); sw.commit(logger); } return composer.getCreatedClassName(); } catch (Exception e) { logger.log(TreeLogger.ERROR, "Class " + typeName + " not found.", e); throw new UnableToCompleteException(); } }