List of usage examples for com.google.gwt.util.tools Utility getFileFromClassPath
public static String getFileFromClassPath(String partialPath) throws IOException
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 ww w. j a va 2s . c om * {@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// w w w . j a v a 2 s . com * {@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.bedatadriven.rebar.appcache.linker.AppCacheIFrameLinker.java
License:Apache License
/** * The bootstrap script is an analog of the IFrameLinker's selection script, * execpt that permutation selection has already been done so it's mostly * straight-line code to load the body of the app. *//*from ww w .ja v a 2s.c o m*/ private String generateBootstrapScript(TreeLogger logger, PermutationContext context, ArtifactSet artifacts) throws UnableToCompleteException { // ICK, copy-and-pasted from SelectionScriptLinker. Ideally work with // the GWT folks to make this more easily overridable. // from SelectionScriptLinker.fillSelectionScriptTemplate StringBuffer selectionScript; try { selectionScript = new StringBuffer( Utility.getFileFromClassPath(getSelectionScriptTemplate(logger, context.getLinkerContext()))); } catch (IOException e) { logger.log(TreeLogger.ERROR, "Unable to read selection script template", e); throw new UnableToCompleteException(); } selectionScript = fillSelectionScriptTemplate(logger, context, artifacts, selectionScript); return selectionScript.toString(); }
From source file:com.bedatadriven.rebar.appcache.linker.AppCacheIFrameLinker.java
License:Apache License
private StringBuffer fillSelectionScriptTemplate(TreeLogger logger, PermutationContext context, ArtifactSet artifacts, StringBuffer selectionScript) throws UnableToCompleteException { String computeScriptBase;/*from w w w . ja v a 2 s. co m*/ 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); addPermutationJs(context, selectionScript); selectionScript = ResourceInjectionUtil.injectResources(selectionScript, artifacts); replaceAll(selectionScript, "__MODULE_FUNC__", context.getModuleFunctionName()); replaceAll(selectionScript, "__MODULE_NAME__", context.getModuleName()); replaceAll(selectionScript, "__HOSTED_FILENAME__", getHostedFilename()); return selectionScript; }
From source file:com.jawspeak.gwt.verysimpletemplate.rebind.VerySimpleGwtTemplateGenerator.java
License:Apache License
private void generateMethodsForEachHtmlTemplate(TreeLogger logger, SourceWriter sourceWriter) throws SecurityException, ClassNotFoundException, IOException, CouldNotParseTemplateException { String folderPrefix = packageName.replace(".", "/"); for (Method method : Class.forName(typeName).getMethods()) { String methodName = method.getName(); if (!methodName.startsWith("get")) { break; }/*from w w w . jav a2 s . c o m*/ String path = folderPrefix + "/" + methodName.substring(3) + ".html"; String template = Utility.getFileFromClassPath(path); String parameters = getParameters(method); sourceWriter.println("public VerySimpleGwtTemplate " + methodName + "(" + parameters + ") {"); sourceWriter.indent(); sourceWriter.println("VerySimpleGwtTemplate template = new VerySimpleGwtTemplate(\"" + Generator.escape(template) + "\");"); for (Map.Entry<String, String> entry : getTemplateReplaceables(template).entrySet()) { // TODO(jwolter): look for the getter method, and throw an exception if it doesn't exist // TODO(jwolter): look at the getter's return type, and do nice null checking then "" + or call toString() // TODO(jwolter): allow an arbitrary way to "pipe" subsequent options to the setter, so that you can for a date i.e. call a date formatter on it. // TODO(jwolter): basically look at the features of FreeMarker, and see how to integrate the best ones in here. Or adopt to FreemarkerGWT. // as for now, we simply turn each value into a String by prepending a "" + to the value. // also for the time being, remember you can have a $${token} that will not get replaced, so you can set it manually. So, // you should only have ${token}'s that you are comfortable getting them set literally as Strings. sourceWriter .println("template.set(\"" + entry.getKey() + "\", " + "\"\" + " + entry.getValue() + ");"); } sourceWriter.println("return template;"); sourceWriter.outdent(); sourceWriter.println("}"); } sourceWriter.outdent(); }
From source file:com.msco.mil.server.com.sencha.gxt.explorer.rebind.SampleGenerator.java
License:sencha.com license
@Override public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException { // Get access to metadata about the type to be generated TypeOracle oracle = context.getTypeOracle(); JClassType toGenerate = oracle.findType(typeName).isClass(); // Get the name of the new type String packageName = toGenerate.getPackage().getName(); String simpleSourceName = toGenerate.getName().replace('.', '_') + "Impl"; PrintWriter pw = context.tryCreate(logger, packageName, simpleSourceName); if (pw == null) { return packageName + "." + simpleSourceName; }/*from www. j a v a 2 s. c om*/ // Generate an HTML file resource for every example and write the source JClassType[] types = oracle.getTypes(); // Build a ResourceOracle capable of reading java files sourceOracle = new ResourceOracleImpl(logger.branch(Type.DEBUG, "Gathering sources")); // Clean up these prefixes to not have filters PathPrefixSet prefixes = ((ResourceOracleImpl) context.getResourcesOracle()).getPathPrefixes(); sourceOracle.setPathPrefixes(new PathPrefixSet()); for (PathPrefix p : prefixes.values()) { sourceOracle.getPathPrefixes().add(new PathPrefix(p.getPrefix(), null)); } ResourceOracleImpl.refresh(logger, sourceOracle); // Load the header and footer HTML content try { String slashyPackageName = getClass().getPackage().getName().replace('.', '/'); javaHeader = Utility.getFileFromClassPath(slashyPackageName + "/header.html"); footer = Utility.getFileFromClassPath(slashyPackageName + "/footer.html"); } catch (IOException e) { logger.log(Type.ERROR, "Header or Footer failed to be read", e); throw new UnableToCompleteException(); } // Find all examples, annotated with @Detail Set<ExampleDetailModel> examples = new HashSet<ExampleDetailModel>(); Map<String, List<ExampleDetailModel>> hierarchy = new HashMap<String, List<ExampleDetailModel>>(); Set<SourceModel> exampleSources = new HashSet<SourceModel>(); for (JClassType type : types) { Example.Detail detail = type.getAnnotation(Example.Detail.class); if (detail != null) { ExampleDetailModel example = new ExampleDetailModel(logger, context, type, detail); // Collect sources to be built into html exampleSources.addAll(example.getAllSources()); List<ExampleDetailModel> exampleList = hierarchy.get(detail.category()); if (exampleList == null) { exampleList = new ArrayList<ExampleDetailModel>(); hierarchy.put(detail.category(), exampleList); } examples.add(example); exampleList.add(example); } } // Sort folders, sort within those folders List<String> folders = new ArrayList<String>(hierarchy.keySet()); Collections.sort(folders); for (List<ExampleDetailModel> contents : hierarchy.values()) { Collections.sort(contents); } // Actually build source for each type for (SourceModel type : exampleSources) { TreeLogger l = logger.branch(Type.DEBUG, "Writing HTML file for " + type.getName()); // attempt to create the output file if (type.getType() == FileType.JAVA) { writeTypeToHtml(l, context, type.getJClassType()); } else { writeFileToHtml(l, context, type.getPath()); } } // Start making the class, with basic imports ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(packageName, simpleSourceName); factory.setSuperclass(typeName); factory.addImport(Name.getSourceNameForClass(Category.class)); factory.addImport(Name.getSourceNameForClass(ImageResource.class)); factory.addImport(Name.getSourceNameForClass(GWT.class)); factory.addImport(Name.getSourceNameForClass(Example.class)); factory.addImport(Name.getSourceNameForClass(Source.class)); factory.addImport(Name.getSourceNameForClass(Source.FileType.class)); SourceWriter sw = factory.createSourceWriter(context, pw); // Write the ctor sw.println("public %1$s() {", simpleSourceName); sw.indent(); // Declare variables that will be used sw.println("Category c;"); sw.println("ImageResource icon;"); sw.println("Example e;"); sw.println("Source dir;"); Set<String> names = new HashSet<String>(); Map<JClassType, String> bundles = new HashMap<JClassType, String>(); for (String folder : folders) { // TODO escape name sw.println("c = new Category(\"%1$s\");", folder); for (ExampleDetailModel example : hierarchy.get(folder)) { // make sure the bundle to be used exists if (!bundles.containsKey(example.getClientBundleType())) { String bundleName = getNextName("bundle", names); sw.println("%1$s %2$s = GWT.create(%1$s.class);", example.getClientBundleType().getQualifiedSourceName(), bundleName); bundles.put(example.getClientBundleType(), bundleName); } // write out the example, adding it to the current category writeExample(sw, bundles.get(example.getClientBundleType()), example); } sw.println("categories.add(c);"); } sw.outdent(); sw.println("}");// end ctor sw.commit(logger); return factory.getCreatedClassName(); }
From source file:com.smartgwt.linker.SmartGwtDomainSyncLinker.java
License:Open Source License
private String appendDomainScyncScript(String defaultModulePrefix, TreeLogger logger) throws UnableToCompleteException { String domainSycnScript;/*from w ww . j a v a 2s . co m*/ try { domainSycnScript = Utility.getFileFromClassPath(SCRIPT_FILE); } catch (IOException e) { logger.log(TreeLogger.ERROR, "Unable to read file: " + SCRIPT_FILE, e); throw new UnableToCompleteException(); } //append the domain sync code at the very beginning of the script return defaultModulePrefix.replaceFirst("<script>", "<script>\n" + domainSycnScript + "\n"); }
From source file:org.cruxframework.crux.core.rebind.offline.AppCacheLinker.java
License:Apache License
protected StringBuffer readFileToStringBuffer(String filename, TreeLogger logger) throws UnableToCompleteException { StringBuffer buffer;//w w w . java 2 s. c o m try { buffer = new StringBuffer(Utility.getFileFromClassPath(filename)); } catch (IOException e) { logger.log(TreeLogger.ERROR, "Unable to read file: " + filename, e); throw new UnableToCompleteException(); } return buffer; }