Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 342759

Summary: [Xtend] support standalone compilation of Xtend files
Product: [Modeling] TMF Reporter: Sven Efftinge <sven.efftinge>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: alex.blewitt, ama, christian.dietrich.opensource, christophkulla, clay, iloncar.ml, jerome.benois, jos.warmer, kowalczyk.krzysztof, mail, refsdal.ivar, schauer, sebastian.zarnekow, stevemash
Version: 2.0.0Flags: sebastian.zarnekow: juno+
Target Milestone: M4   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Sven Efftinge CLA 2011-04-13 16:01:22 EDT
There should be a easy and  documented way to generate Java code out of Xtend files in a standalone scenario (i.e. via MWE2, Maven, or/and ANT).
Comment 1 Jos Warmer CLA 2011-06-13 11:37:00 EDT
I would rate this as High priority, because the lack of this functionality make it impossible to use Xtend2 in a continuous integration environment, and hence very hard to use effectively in a professional software development environment.
Comment 2 Christian Dietrich CLA 2011-07-19 08:24:02 EDT
I would rate this as High priority too
Comment 3 Sven Efftinge CLA 2011-08-09 03:06:04 EDT
It should work in a headless build already. It is unlikely that we are able to solve this without using JDT.
The problem we'll have to solve is, that some Xtend class might depend on a Java class and that Java class again might reference the Xtend class. This chicken-and-egg problem prevents us from first compiling the Java resources and then the Xtend classes (or vice versa). We need to somehow create a symbol table for everything up front and use that symbol table in to compile Xtend and then Java. JDT provides us with all we need.

We'll look into this soon but it would be extremely helpful if someone could dig into running a build using a headless eclipse in the meantime to check whether it would be a viable option.
Comment 4 Sven Efftinge CLA 2011-11-12 06:50:54 EST
We are working on a solution which doesn't require a headless eclipse build or something similar.
It's going to work in any vanilla Java process that includes standard maven or ant builds.
Comment 5 Steve Ash CLA 2011-11-24 11:31:02 EST
Sven when you say "standard maven build" does this mean enhancing xtext generation to support the standard maven source folder layout:

src/main/java compiles to target/classes
src/test/java compiles to target/test-classes

I think I would still want my .xtend files in src/main/java and src/test/java but perhaps the generated java files go in src/main/xtend-gen and src/test/xtend-gen.  This would end up with

src/main/java generating xtend java source to src/main/xtend-gen which compiles to target/classes

and

src/test/java generating xtend java source to src/test/xtend-gen which compiles to target/test-classes

Then I can still put xtend and java code side by side in both production code and test code and still produce the standard maven jar and test-jar artifacts.
Comment 6 Sven Efftinge CLA 2011-11-24 12:24:08 EST
Exactly that's the idea. :-)
Comment 7 Michael Clay CLA 2011-11-26 04:34:07 EST
first shot pushed to master -> 

see http://git.eclipse.org/c/tmf/org.eclipse.xtext.git/commit/?id=cc5cff9c40e5defb5bd5dccd56e92b075ecd2ff2

todo: 

1. fix incorrect dependency version in generated xtext 2.1.1 maven artefact e.g. see  http://maven.eclipse.org/nexus/content/repositories/xtext-proxy/org/eclipse/xtext/org.eclipse.xtext.xtend2/2.1.1.v201111141332/org.eclipse.xtext.xtend2-2.1.1.v201111141332.pom

[WARNING] The POM for org.eclipse.xtext:org.eclipse.xtext.common.types:jar:2.0.0 is missing, no dependency information available
[WARNING] The POM for org.eclipse.xtext:org.eclipse.xtext.xbase:jar:2.0.0 is missing, no dependency information available
.....

2. deploy and CI missing artefacts into maven repo @eclipse

- org.eclipse.xtend2.lib
- org.eclipse.xtext.xtend2.standalone
- org.eclipse.xtext.xtend2.maven
Comment 8 Sven Efftinge CLA 2011-12-01 05:47:43 EST
@Michael: Thanks for the great job! I think we can close the ticket now.
Comment 9 Michael Clay CLA 2011-12-01 15:57:54 EST
what about the missing m2e integration i.e. 'M2E plugin execution not covered ...' 
explained here http://wiki.eclipse.org/M2E_plugin_execution_not_covered

(In reply to comment #8)
> @Michael: Thanks for the great job! I think we can close the ticket now.
Comment 10 Sebastian Zarnekow CLA 2011-12-01 15:59:57 EST
(In reply to comment #9)
> what about the missing m2e integration i.e. 'M2E plugin execution not covered
> ...' 
> explained here http://wiki.eclipse.org/M2E_plugin_execution_not_covered
> 
> (In reply to comment #8)
> > @Michael: Thanks for the great job! I think we can close the ticket now.

A Null-implementation would be sufficient since our builder takes care of the actual work.
Comment 11 Christian Dietrich CLA 2011-12-03 06:26:37 EST
I still stumble over org.eclipse.xtext.xtend2.validation.ClasspathBasedChecks.checkFileNamingConventions(XtendFile) when using the Main in xtend2.standalone. this leads to the error 

The declared package 'test' does not match the expected package

if the xtend files dont reside i a folder that is called bin
Comment 12 Christian Dietrich CLA 2011-12-03 07:00:42 EST
btw this does not happen if i call the stuff from ant
Comment 13 Christian Dietrich CLA 2011-12-03 07:06:46 EST
Just found out that the xtend folder should not be a source folder - at least at the place where you call the Main class, otherwise the .xtend file will be found in the bin folder too which leads to the error - sorry for the noise
Comment 14 Sven Efftinge CLA 2011-12-12 04:28:25 EST
this has been fixed for 2.2
Comment 15 Andy Ma CLA 2012-01-05 02:42:24 EST
Any one know how to use it with ant build? with the xtext project we have src and src-gen source folder, but Xtend2BatchCompiler seems only accept on source folder, I build it with the following target but fail with many errors:

<target name="xtend-gen" description="Generate xtend file to java files">
		<path id="classpath">
			<fileset dir=".">
				<include name="src/**/*.java"/>
				<include name="src-gen/**/*.java"/>
			</fileset>
			<path refid="lib.path.id"></path>
		</path>
		<pathconvert property="classpaths" refid="classpath" pathsep="${path.separator}"/>
		<java classname="org.eclipse.xtext.xtend2.compiler.batch.Main" classpathref="lib.path.id" >
			<arg line="-d xtend-gen"/>
			<arg line="-cp"/>
			<arg line="${classpaths}"/>
			<arg value="src"/>
		</java>
	</target>
Comment 16 Sven Efftinge CLA 2012-01-05 02:57:53 EST
So you generate Xtend code into src-gen? 

I filed a bugzilla for supporting multiple source folders : Bug 367914
Comment 17 Andy Ma CLA 2012-01-05 03:03:41 EST
No, I want to generate the xtend file to java file into folder xtend-gen at the same level with src-gen, it is the same as in eclipse IDE, I mean for a xtext project.
Comment 18 Sven Efftinge CLA 2012-01-05 03:08:21 EST
You only need to configure the source folder containing Xtend sources.
Comment 19 Andy Ma CLA 2012-01-05 03:23:13 EST
Yes, my xtend files are all only in the sub folders of "src" folder, I added both src and src-gen, and all the necessary jars to the class path, still have errors, do you think I make the wrong configuration?
Comment 20 Eclipse Webmaster CLA 2017-10-31 11:06:42 EDT
Requested via bug 522520.

-M.
Comment 21 Eclipse Webmaster CLA 2017-10-31 11:18:06 EDT
Requested via bug 522520.

-M.