List of usage examples for com.google.gwt.core.ext UnableToCompleteException UnableToCompleteException
public UnableToCompleteException()
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 {//w w w.j a va 2s . c o m 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 www . j av a 2s.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 ww. jav a 2 s . co m 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./*w w w . ja v a2s .co 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();/*from www . j a va 2s . c om*/ 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.ext4j.rebind.TemplateGenerator.java
License:Apache License
/** * Given a TemplateResource interface, return the path to its .html file, * suitable for any classloader to find it as a resource. If the .html does * not exist or is empty see if the template was declared inline. If no * content is found we throw an exception. */// w ww .ja v a 2 s .co m private String getTemplateContent(GeneratorContext context, TreeLogger logger, JClassType interfaceType) throws UnableToCompleteException { String templateHtmlFile = null; TemplateResource annotation = interfaceType.getAnnotation(TemplateResource.class); if (annotation == null) { // if the interface is defined as a nested class, use the name of // the // enclosing type if (interfaceType.getEnclosingType() != null) { interfaceType = interfaceType.getEnclosingType(); } templateHtmlFile = slashify(interfaceType.getQualifiedBinaryName()) + TEMPLATE_SUFFIX; logger.log(TreeLogger.INFO, "Template : " + templateHtmlFile); InputStream stream = getTemplateResource(context, logger, templateHtmlFile); if (stream == null) { logger.log(Type.ERROR, "No data could be loaded - no data at path " + interfaceType.getQualifiedBinaryName() + TEMPLATE_SUFFIX); throw new UnableToCompleteException(); } return sanitize(Util.readStreamAsString(stream)); } else { // first we look at the HTML File templateHtmlFile = annotation.source(); if (templateHtmlFile.length() > 0) { if (!templateHtmlFile.endsWith(TEMPLATE_SUFFIX)) { logger.log(TreeLogger.ERROR, "Template file name must end with " + TEMPLATE_SUFFIX); throw new UnableToCompleteException(); } if (annotation.value().length() != 0) { logger.log(Type.WARN, "Found both source file and inline template, using source file"); } templateHtmlFile = slashify(interfaceType.getPackage().getName()) + "/" + templateHtmlFile; InputStream stream = getTemplateResource(context, logger, templateHtmlFile); return sanitize(Util.readStreamAsString(stream)); } else if (annotation.value().length() > 0) { return annotation.value(); } else { logger.log(Type.ERROR, "Template annotation found with no contents, cannot generate method , this may cause other failures."); } } return null; }
From source file:com.ait.ext4j.rebind.TemplateGenerator.java
License:Apache License
@Override public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException { TypeOracle oracle = context.getTypeOracle(); this.templatesInterface = oracle.findType(Name.getSourceNameForClass(Template.class)); JClassType interfaceType;/*from w w w . ja v a 2 s .com*/ try { interfaceType = oracle.getType(typeName); } catch (NotFoundException e) { throw new RuntimeException(e); } if (interfaceType.isInterface() == null) { logger.log(TreeLogger.ERROR, typeName + " is not an interface type"); throw new UnableToCompleteException(); } if (!interfaceType.isAssignableTo(templatesInterface)) { logger.log(Type.ERROR, "This isn't a Template subtype..."); throw new UnableToCompleteException(); } String content = getTemplateContent(context, logger, interfaceType); String packageName = interfaceType.getPackage().getName(); String className = "Template_For_" + interfaceType.getQualifiedSourceName().replace(".", "_"); ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, className); composer.addImport(SafeHtml.class.getName()); composer.addImport(SafeHtmlUtils.class.getName()); composer.addImplementedInterface(Template.class.getName()); PrintWriter pw = context.tryCreate(logger, packageName, className); SourceWriter sw = composer.createSourceWriter(context, pw); sw.println(" public SafeHtml getContent(){"); sw.println(" return SafeHtmlUtils.fromSafeConstant(\"" + content + "\");"); sw.println(" }"); sw.println(""); sw.println(""); sw.println(" public SafeHtml getSafeContent(){"); sw.println(" return SafeHtmlUtils.fromString(\"" + content + "\");"); sw.println(" }"); sw.commit(logger); return composer.getCreatedClassName(); }
From source file:com.ait.ext4j.rebind.TemplateGenerator.java
License:Apache License
protected InputStream getTemplateResource(GeneratorContext context, TreeLogger l, String markerPath) throws UnableToCompleteException { // look for a local file first String path = slashify(markerPath); l.log(Type.INFO, "Current resource path : " + markerPath); Resource res = context.getResourcesOracle().getResourceMap().get(path); // if not a local path, try an absolute one if (res == null) { l.log(Type.INFO, "Resource is Null trying with URL "); URL url = Thread.currentThread().getContextClassLoader().getResource(markerPath); if (url == null) { l.log(Type.INFO, "URL seems to be null here ... hmmmmss"); return null; }/* w ww . j a v a 2 s .c o m*/ try { return url.openStream(); } catch (IOException e) { l.log(Type.ERROR, "IO Exception occured", e); throw new UnableToCompleteException(); } } try { return res.openContents(); } catch (Exception e) { l.log(Type.ERROR, "Exception occured reading " + path, 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// w w w . j av a 2 s.co 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 ww.j a va 2s. co m*/ * {@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(); }