Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » 2.5.0: Problems using Standalone Xtend with Xpand code(Noob question)
2.5.0: Problems using Standalone Xtend with Xpand code [message #1219554] Wed, 04 December 2013 15:43 Go to next message
Adam Crowther is currently offline Adam Crowther
Messages: 5
Registered: November 2013
Junior Member
Hi all,

I am having problems with the standalone xtend compiler, using Release 2.5.0 Milestone 3. (2.5.0.v201311121244)

Using the simple MyDsl example project, I extended the file MyDslGenerator.xtend to look like this:
package org.xtext.example.mydsl.generator

import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.IFileSystemAccess
import org.eclipse.xtext.generator.IGenerator
import org.xtext.example.mydsl.myDsl.Greeting

class MyDslGenerator implements IGenerator {
    
    override void doGenerate(Resource resource, IFileSystemAccess fsa) {
        fsa.generateFile('greetings.txt', 'People to greet: ' + 
            resource.allContents
                .filter(typeof(Greeting))
                .map[name]
                .join(', '))
                
        for(g: resource.allContents.toIterable.filter(typeof(Greeting))) {
            fsa.generateFile('org/xtext/example/mydsl/' + g.name.toFirstUpper + '.java', g.generateFile)  
        }
                
    }
    
    def String generateFile(Greeting g) '''
        package org.xtext.example.mydsl;
    
        public class «g.name.toFirstUpper» {
            
            public static void main(String[] args) {
                «g.name.toFirstUpper» «g.name.toFirstLower» = new «g.name.toFirstUpper»();
                
                «g.name.toFirstLower».greet();
            }
            
            public void greet() {
                System.out.println("Hello «g.name»!");
            }
        }

    '''
    
}


That all works fine as an eclipse plugin; it generates the desired code as expected.

My ant script is based on Boris Brodski's example on xtextcasts.org, and looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<!-- 
     NB: This ant script is designed to be run in an eclipse environment, where the required JAR files are 
     available in the plugins directory.  Before running, make sure the ant script runs in the same JRE as 
     eclipse by selecting the following setting:
      - External Tool Configurations....
      - JRE tab
      - Run in the same JRE as the workspace
     This will ensure that the system property "eclipse.home" is set.
 --> 

<project name="MyDSL" default="all">
    <property name="workflow" value="src/org/xtext/example/mydsl/GenerateMyDsl.mwe2"/>
    
    <path id="classpath">
        <fileset dir="${eclipse.home}/plugins">
            <include name="org.eclipse.xtext_2.5.0.v201311121244.jar"/>
            <include name="org.eclipse.emf.ecore.xmi_2.9.1.v20130827-0309.jar"/>
            <include name="org.eclipse.emf.ecore_2.9.1.v20130827-0309.jar"/>
            <include name="org.eclipse.emf.common_2.9.1.v20130827-0309.jar"/>
            <include name="org.antlr.runtime_3.2.0.v201101311130.jar"/>
            <include name="com.google.inject_3.0.0.v201203062045.jar"/>
            <include name="com.google.inject.assistedinject_3.0.0.201207101151.jar"/>
            <include name="com.google.inject.multibindings_3.0.0.201207101151.jar"/>
            <include name="org.eclipse.emf.mwe.core_1.2.1.v201311120431.jar"/>
            <include name="org.apache.commons.cli_1.2.0.v201105210650.jar"/>
            <include name="org.eclipse.emf.mwe2.runtime_2.5.0.v201311120431.jar"/>
            <include name="org.eclipse.emf.mwe.utils_1.3.1.v201311120431.jar"/>
            <include name="org.eclipse.xtext.util_2.5.0.v201311121244.jar"/>
            <include name="com.google.guava_10.0.1.v201203051515.jar"/>
            <include name="javax.inject_1.0.0.v20091030.jar"/>
            <include name="org.eclipse.xtext.xbase_2.5.0.v201311121244.jar"/>
            <include name="org.eclipse.xtext.common.types_2.5.0.v201311121244.jar"/>
            <include name="org.eclipse.jdt.annotation_1.0.1.v20130111-135246.jar"/>
            <include name="org.eclipse.xtend.lib_2.5.0.v201311121244.jar"/>
            <include name="org.eclipse.xtext.xbase.lib_2.5.0.v201311121244.jar"/>
            <include name="org.eclipse.xtext.generator_2.5.0.v201311121244.jar"/>
            <include name="org.eclipse.xtend_2.0.0.v201311120517.jar"/>
            <include name="com.ibm.icu_4.4.2.v20110823.jar"/>
            <include name="org.eclipse.xpand_2.0.0.v201311120517.jar"/>
            <include name="org.eclipse.xtend.typesystem.emf_2.0.0.v201311120517.jar"/>
            <include name="org.eclipse.emf.codegen.ecore_2.9.1.v20130902-0605.jar"/>
            <include name="org.eclipse.emf.codegen_2.9.0.v20130902-0605.jar"/>
            <include name="de.itemis.xtext.antlr_2.1.0.v201308291703.jar"/>
            <include name="org.antlr.generator_3.2.0.v201308291703.jar"/>
            <include name="org.eclipse.emf.mwe2.lib_2.5.0.v201311120431.jar"/>
            <include name="org.apache.commons.logging_1.0.4.v201101211617.jar"/>
            <include name="org.eclipse.emf.mwe2.launch_2.5.0.v201311120717.jar"/>
            <include name="org.eclipse.emf.mwe2.language_2.5.0.v201311120717.jar"/>
            <include name="org.slf4j.api_1.6.4.v20120130-2120.jar"/>
            <include name="ch.qos.logback.classic_1.0.0.v20111214-2030.jar"/>
            <include name="ch.qos.logback.core_1.0.0.v20111214-2030.jar"/>
            <include name="org.eclipse.m2e.logback.configuration_1.3.0.20130129-0926.jar"/>
            <include name="org.eclipse.core.resources_3.8.1.v20121114-124432.jar"/>
            <include name="org.apache.log4j_1.2.15.v201012070815.jar"/>
                
            <!-- The following jars are not in the Referenced Libraries, but are required by the compile process -->
            <include name="org.eclipse.xtend.core_2.5.0.v201311121244.jar" />
            <include name="org.eclipse.jdt.core_3.8.3.v20130121-145325.jar" />
            <include name="org.eclipse.equinox.common_3.6.100.v20120522-1841.jar" />
            
        </fileset>
        <fileset dir="." includes=".antlr-generator-3.2.0.jar"/>
        <pathelement location="src"/>
    </path>
    
    <target name="clean">
        <delete dir="ant/src" quiet="true"/>
        <delete dir="ant/src-gen" quiet="true"/>
        <delete dir="ant/bin" quiet="true"/>
        <delete dir="ant/xtend-gen" quiet="true"/>
        <delete dir="ant/dist" quiet="true"/>
    </target>
    
    <target name="generate-xtext-artifacts">
        <java classpathref="classpath" 
              classname="org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher" 
              fork="true">
            <arg value="${workflow}"/>
        </java>
    </target>
            
    <target name="convert-crlf-to-unix">
        <mkdir dir="ant/src"/>
        <mkdir dir="ant/src-gen"/>
        <fixcrlf srcdir="src"
                 destdir="ant/src"
                 eol="lf"
                 eof="remove"
        />
            
        <fixcrlf srcdir="src-gen"
                 destdir="ant/src-gen"
                 eol="lf"
                 eof="remove"
        />            
    </target>
    
    <target name="compile-xtend">
        <pathconvert pathsep="${path.separator}" 
                     property="classpath-string" 
                     refid="classpath">
        </pathconvert>
        <echo>Classpath: ${classpath-string}</echo>
        <echo>Basedir: ${basedir}</echo>
        <echo>Workflow: ${workflow}</echo>
        <mkdir dir="ant/xtend-gen"/>
        <java classpathref="classpath"
              classname="org.eclipse.xtend.core.compiler.batch.Main"
              fork="true"
              failonerror="yes">
            <arg value="-cp" />
            <arg value="${classpath-string}" />
            <arg value="-d" />
            <arg value="ant/xtend-gen" />
            <arg value="ant/src${path.separator}ant/src-gen" />
        </java>
    </target>   
    
    <target name="compile-java">
        <mkdir dir="ant/bin"/>
        <javac classpathref="classpath"
               destdir="ant/bin"
               source="1.6"
               target="1.6"
               includeantruntime="true">
            <src path="src" />
            <src path="src-gen" />
            <src path="ant/xtend-gen" />
        </javac>
        <copy todir="ant/bin">
            <fileset dir="ant/src" excludes="**/*.java,**/*.xtend" />
            <fileset dir="ant/src-gen" excludes="**/*.java,**/*.xtend" />
            <fileset dir="ant/xtend-gen" excludes="**/*.java,**/*.xtend" />
        </copy>
    </target>
    
    <target name="package">
        <mkdir dir="ant/dist"/>
        <manifestclasspath property="jar.classpath" jarfile="ant/dist/ulvtdsl_bo_generator.jar">
              <classpath refid="classpath"/>
        </manifestclasspath>
        <jar destfile="ant/dist/ulvtdsl_bo_generator.jar">
            <fileset dir="ant/bin"/>         
            <manifest>
                <attribute name="Main-Class" value="com.vxxxxxxl.ullink.xtext.dsl.Main"/>
                <attribute name="Class-Path" value="${jar.classpath}"/>
            </manifest>         
        </jar>
    </target>

    <target name="all" depends="clean,generate-xtext-artifacts,convert-crlf-to-unix,compile-xtend,compile-java,package"
            description="build all">
    </target>
</project>


The task "compile-xtend" (org.eclipse.xtend.core.compiler.batch.Main) fails with the following error messages:
compile-xtend:
        [echo] Classpath: C:\Program Files\Eclipse\plugins\ch.qos.logback.classic_1.0.0.v20111214-2030.jar;C:\Program Files\Eclipse\plugins\ch.qos.logback.core_1.0.0.v20111214-2030.jar;C:\Program Files\Eclipse\plugins\com.google.guava_10.0.1.v201203051515.jar;C:\Program Files\Eclipse\plugins\com.google.inject.assistedinject_3.0.0.201207101151.jar;C:\Program Files\Eclipse\plugins\com.google.inject.multibindings_3.0.0.201207101151.jar;C:\Program Files\Eclipse\plugins\com.google.inject_3.0.0.v201203062045.jar;C:\Program Files\Eclipse\plugins\com.ibm.icu_4.4.2.v20110823.jar;C:\Program Files\Eclipse\plugins\de.itemis.xtext.antlr_2.1.0.v201308291703.jar;C:\Program Files\Eclipse\plugins\javax.inject_1.0.0.v20091030.jar;C:\Program Files\Eclipse\plugins\org.antlr.generator_3.2.0.v201308291703.jar;C:\Program Files\Eclipse\plugins\org.antlr.runtime_3.2.0.v201101311130.jar;C:\Program Files\Eclipse\plugins\org.apache.commons.cli_1.2.0.v201105210650.jar;C:\Program Files\Eclipse\plugins\org.apache.commons.logging_1.0.4.v201101211617.jar;C:\Program Files\Eclipse\plugins\org.apache.log4j_1.2.15.v201012070815.jar;C:\Program Files\Eclipse\plugins\org.eclipse.core.resources_3.8.1.v20121114-124432.jar;C:\Program Files\Eclipse\plugins\org.eclipse.emf.codegen.ecore_2.9.1.v20130902-0605.jar;C:\Program Files\Eclipse\plugins\org.eclipse.emf.codegen_2.9.0.v20130902-0605.jar;C:\Program Files\Eclipse\plugins\org.eclipse.emf.common_2.9.1.v20130827-0309.jar;C:\Program Files\Eclipse\plugins\org.eclipse.emf.ecore.xmi_2.9.1.v20130827-0309.jar;C:\Program Files\Eclipse\plugins\org.eclipse.emf.ecore_2.9.1.v20130827-0309.jar;C:\Program Files\Eclipse\plugins\org.eclipse.emf.mwe.core_1.2.1.v201311120431.jar;C:\Program Files\Eclipse\plugins\org.eclipse.emf.mwe.utils_1.3.1.v201311120431.jar;C:\Program Files\Eclipse\plugins\org.eclipse.emf.mwe2.language_2.5.0.v201311120717.jar;C:\Program Files\Eclipse\plugins\org.eclipse.emf.mwe2.launch_2.5.0.v201311120717.jar;C:\Program Files\Eclipse\plugins\org.eclipse.emf.mwe2.lib_2.5.0.v201311120431.jar;C:\Program Files\Eclipse\plugins\org.eclipse.emf.mwe2.runtime_2.5.0.v201311120431.jar;C:\Program Files\Eclipse\plugins\org.eclipse.equinox.common_3.6.100.v20120522-1841.jar;C:\Program Files\Eclipse\plugins\org.eclipse.jdt.annotation_1.0.1.v20130111-135246.jar;C:\Program Files\Eclipse\plugins\org.eclipse.jdt.core_3.8.3.v20130121-145325.jar;C:\Program Files\Eclipse\plugins\org.eclipse.m2e.logback.configuration_1.3.0.20130129-0926.jar;C:\Program Files\Eclipse\plugins\org.eclipse.xpand_2.0.0.v201311120517.jar;C:\Program Files\Eclipse\plugins\org.eclipse.xtend.core_2.5.0.v201311121244.jar;C:\Program Files\Eclipse\plugins\org.eclipse.xtend.lib_2.5.0.v201311121244.jar;C:\Program Files\Eclipse\plugins\org.eclipse.xtend.typesystem.emf_2.0.0.v201311120517.jar;C:\Program Files\Eclipse\plugins\org.eclipse.xtend_2.0.0.v201311120517.jar;C:\Program Files\Eclipse\plugins\org.eclipse.xtext.common.types_2.5.0.v201311121244.jar;C:\Program Files\Eclipse\plugins\org.eclipse.xtext.generator_2.5.0.v201311121244.jar;C:\Program Files\Eclipse\plugins\org.eclipse.xtext.util_2.5.0.v201311121244.jar;C:\Program Files\Eclipse\plugins\org.eclipse.xtext.xbase.lib_2.5.0.v201311121244.jar;C:\Program Files\Eclipse\plugins\org.eclipse.xtext.xbase_2.5.0.v201311121244.jar;C:\Program Files\Eclipse\plugins\org.eclipse.xtext_2.5.0.v201311121244.jar;C:\Program Files\Eclipse\plugins\org.slf4j.api_1.6.4.v20120130-2120.jar;C:\Users\vb4sd\workspace\branch_Monitoring\org.xtext.example.mydsl\src
        [echo] Basedir: C:\Users\vb4sd\workspace\branch_Monitoring\org.xtext.example.mydsl
        [echo] Workflow: src/org/xtext/example/mydsl/GenerateMyDsl.mwe2
       [mkdir] Created dir: C:\Users\vb4sd\workspace\branch_Monitoring\org.xtext.example.mydsl\ant\xtend-gen
        [java] 0    ERROR XtendBatchCompiler - 
        [java] ERROR: 	MyDslGenerator.xtend - C:\Users\vb4sd\workspace\branch_Monitoring\org.xtext.example.mydsl\ant\src\org\xtext\example\mydsl\generator\MyDslGenerator.xtend
        [java] 31: The method toFirstUpper is undefined for the type MyDslGenerator
        [java] 0 [main] ERROR org.eclipse.xtend.core.compiler.batch.XtendBatchCompiler  - 
        [java] ERROR: 	MyDslGenerator.xtend - C:\Users\vb4sd\workspace\branch_Monitoring\org.xtext.example.mydsl\ant\src\org\xtext\example\mydsl\generator\MyDslGenerator.xtend
        [java] 31: The method toFirstUpper is undefined for the type MyDslGenerator
        [java] 13   ERROR XtendBatchCompiler - 
        [java] ERROR: 	MyDslGenerator.xtend - C:\Users\vb4sd\workspace\branch_Monitoring\org.xtext.example.mydsl\ant\src\org\xtext\example\mydsl\generator\MyDslGenerator.xtend
        [java] 34: The method toFirstUpper is undefined for the type MyDslGenerator
        [java] 13 [main] ERROR org.eclipse.xtend.core.compiler.batch.XtendBatchCompiler  - 
        [java] ERROR: 	MyDslGenerator.xtend - C:\Users\vb4sd\workspace\branch_Monitoring\org.xtext.example.mydsl\ant\src\org\xtext\example\mydsl\generator\MyDslGenerator.xtend
        [java] 34: The method toFirstUpper is undefined for the type MyDslGenerator
        [java] 13   ERROR XtendBatchCompiler - 
        [java] ERROR: 	MyDslGenerator.xtend - C:\Users\vb4sd\workspace\branch_Monitoring\org.xtext.example.mydsl\ant\src\org\xtext\example\mydsl\generator\MyDslGenerator.xtend
        [java] 34: The method toFirstLower is undefined for the type MyDslGenerator
        [java] 13 [main] ERROR org.eclipse.xtend.core.compiler.batch.XtendBatchCompiler  - 
        [java] ERROR: 	MyDslGenerator.xtend - C:\Users\vb4sd\workspace\branch_Monitoring\org.xtext.example.mydsl\ant\src\org\xtext\example\mydsl\generator\MyDslGenerator.xtend
        [java] 34: The method toFirstLower is undefined for the type MyDslGenerator
        [java] 13   ERROR XtendBatchCompiler - 
        [java] ERROR: 	MyDslGenerator.xtend - C:\Users\vb4sd\workspace\branch_Monitoring\org.xtext.example.mydsl\ant\src\org\xtext\example\mydsl\generator\MyDslGenerator.xtend
        [java] 34: The method toFirstUpper is undefined for the type MyDslGenerator
        [java] 13 [main] ERROR org.eclipse.xtend.core.compiler.batch.XtendBatchCompiler  - 
        [java] ERROR: 	MyDslGenerator.xtend - C:\Users\vb4sd\workspace\branch_Monitoring\org.xtext.example.mydsl\ant\src\org\xtext\example\mydsl\generator\MyDslGenerator.xtend
        [java] 34: The method toFirstUpper is undefined for the type MyDslGenerator
        [java] 13   ERROR XtendBatchCompiler - 
        [java] ERROR: 	MyDslGenerator.xtend - C:\Users\vb4sd\workspace\branch_Monitoring\org.xtext.example.mydsl\ant\src\org\xtext\example\mydsl\generator\MyDslGenerator.xtend
        [java] 36: The method toFirstLower is undefined for the type MyDslGenerator
        [java] 13 [main] ERROR org.eclipse.xtend.core.compiler.batch.XtendBatchCompiler  - 
        [java] ERROR: 	MyDslGenerator.xtend - C:\Users\vb4sd\workspace\branch_Monitoring\org.xtext.example.mydsl\ant\src\org\xtext\example\mydsl\generator\MyDslGenerator.xtend
        [java] 36: The method toFirstLower is undefined for the type MyDslGenerator
        [java] 14   ERROR XtendBatchCompiler - 
        [java] ERROR: 	MyDslGenerator.xtend - C:\Users\vb4sd\workspace\branch_Monitoring\org.xtext.example.mydsl\ant\src\org\xtext\example\mydsl\generator\MyDslGenerator.xtend
        [java] 40: The method name is undefined for the type MyDslGenerator
        [java] 14 [main] ERROR org.eclipse.xtend.core.compiler.batch.XtendBatchCompiler  - 
        [java] ERROR: 	MyDslGenerator.xtend - C:\Users\vb4sd\workspace\branch_Monitoring\org.xtext.example.mydsl\ant\src\org\xtext\example\mydsl\generator\MyDslGenerator.xtend
        [java] 40: The method name is undefined for the type MyDslGenerator


If I comment the xpand code out of the file MyDslGenerator.xtend it seems to work fine.

I didn't see this problem with 2.4.x - am I doing something wrong or is this a bug?

Thanks for any help or hints.

Yours,

Adam Crowther
Re: 2.5.0: Problems using Standalone Xtend with Xpand code [message #1219584 is a reply to message #1219554] Wed, 04 December 2013 18:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6305
Registered: July 2009
Senior Member
Hi,

did you check the encoding of the file?
Re: 2.5.0: Problems using Standalone Xtend with Xpand code [message #1219592 is a reply to message #1219584] Wed, 04 December 2013 19:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6305
Registered: July 2009
Senior Member
P:S: on my mac i had to add

<arg value="-encoding" />
<arg value="UTF-8" />
Re: 2.5.0: Problems using Standalone Xtend with Xpand code [message #1219658 is a reply to message #1219592] Thu, 05 December 2013 10:02 Go to previous message
Adam Crowther is currently offline Adam Crowther
Messages: 5
Registered: November 2013
Junior Member
Yep, that was it.

Thanks very much Smile
Previous Topic:Class cast exception while running workflow
Next Topic:Call xtend function in java
Goto Forum:
  


Current Time: Fri Sep 19 17:54:58 GMT 2014

Powered by FUDForum. Page generated in 0.01830 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software