XtendTools 1.0.0 released

Today, the first release of XtendTools has been published!

The Xtend Tools are a library of reusable extensions for Xtend/Xpand called Xtend Lib and a set of utility classes for testing Xpand templates and Xtend extensions using JUnit.

Xtend Tools is a utility project hosted at the Fornax Platform, a development platform for tools related to the Model-Driven-Software-Development – MDSD.

Xtend Tools is open source and released under the Terms of the Apache License 2.0.

Tags » , , «

Autor:
Datum: Mittwoch, 9. Juni 2010 14:22
Trackback: Trackback-URL Themengebiet: MDSD

Feed zum Beitrag: RSS 2.0 Diesen Artikel kommentieren

3 Kommentare

  1. 1

    I did same changes to the XPandUnit that i want to share.
    Mainly the abbility to use JavaBeautifier.

    One additional question: Why do you use StandaloneSetup ?

    /**
    * Provides utility methods for invoking Xpand templates.
    *
    */
    public class XpandHelper {

    private static final String OUTLET_NAME = “test”;

    private MetaModel[] metamodels;

    /**
    * Initializes the XtendHelper.
    * @param epackage the interface name of the EPackage to register
    */
    public static XpandHelper create(MetaModel… metamodels){
    return new XpandHelper(metamodels);
    }

    public static XpandHelper

    private XpandHelper(MetaModel… metamodels){
    this.metamodels = metamodels;
    }

    /**
    * Expands the template template for target. Returns the
    * generator output.
    */
    public String xpandToString(String template, EObject target) {
    return xpandToString(template, new HashMap(), target);
    }

    /**
    * Expands the template template for target, using the given
    * global vars. Returns the generator output.
    */
    public String xpandToString(String template, Map globalvars, EObject target) {
    StringOutput output = new StringOutput();
    xpand(template, globalvars, output, “”,target);
    return output.getOutput();
    }

    /**Xpand to File
    * @param template
    * @param targetFolder
    * @param target
    */
    public void xpandToFile(String template, File targetFolder, EObject target){
    Output output = new OutputImpl();
    xpand(template, new HashMap(), output,targetFolder.toString(), target);
    }

    private void xpand(String template, Map globalvars,
    Output output, String targetFolder, EObject target) {
    Outlet outlet = new Outlet();
    outlet.setName(OUTLET_NAME);
    outlet.setPath(targetFolder);
    JavaBeautifier javaBeautifier = new JavaBeautifier();
    outlet.addPostprocessor(javaBeautifier);
    output.addOutlet(outlet);

    Map gv = new HashMap();
    for (Map.Entry entry : globalvars.entrySet()) {
    gv.put(entry.getKey(), new Variable(entry.getKey(), entry.getValue()));
    }
    XpandExecutionContextImpl xpandCtxt = new XpandExecutionContextImpl(output, null, gv, null, null);
    for (MetaModel mm : metamodels) {
    xpandCtxt.registerMetaModel(mm);
    }
    XpandFacade facade = XpandFacade.create(xpandCtxt);
    facade.evaluate(template, target);
    }

    /**
    * Internal class to capture the generator output.
    */
    private static class StringOutput extends OutputImpl {
    FileHandle current = new DummyFileHandle();
    private String getOutput() {
    return current.getBuffer().toString();
    }
    @Override
    protected FileHandle current() {
    return current;
    }
    @Override
    public void closeFile() {
    this.getOutlet(OUTLET_NAME).beforeWriteAndClose(current);
    }
    @Override
    public void openFile(String path, String outletName) {
    }
    }

    /**
    * Internal class to capture the generator output.
    */
    private static class DummyFileHandle implements FileHandle {
    StringBuffer buffer = new StringBuffer();
    public CharSequence getBuffer() {
    return buffer;
    }
    public void setBuffer(CharSequence b) {
    buffer = new StringBuffer(b);
    }
    public String getFileEncoding() {
    throw new UnsupportedOperationException();
    }
    public Outlet getOutlet() {
    throw new UnsupportedOperationException();
    }
    @SuppressWarnings(“deprecation”)
    public File getTargetFile() {
    throw new UnsupportedOperationException();
    }
    public boolean isAppend() {
    throw new UnsupportedOperationException();
    }
    public boolean isOverwrite() {
    throw new UnsupportedOperationException();
    }
    public void writeAndClose() {
    throw new UnsupportedOperationException();
    }
    @Override
    public String getAbsolutePath() {
    return “.java”;
    }
    }
    }

  2. 2

    Thank you for your contribution! I will add something like that to the next release of XpandUnit. However, I think you should create an MWE workflow and run it from your tests using the WorkflowFacade if you want to test more complex scenarios like named outlets.

    I am using StandaloneSetup to register an EPackage in the global EMF Registry. Depending on what you are doing before calling XpandUnit this might not be necessary. I will make this an optional feature in the next release.

  3. 3

    First thanks for your code is was a great help for me to unit test xpand.

    I think the PostProcessor in your new code is not executed. Therefore i call: getOutlet(OUTLET_NAME).beforeWriteAndClose(current); in the closeFile() method.

    I dont use workflow files because i think its a duplication if i have a worflow file and rebuilt built the same with java for unit tests.

Kommentar abgeben