Building a xText projects temporal with Ant [message #836275] |
Wed, 04 April 2012 09:55 |
Paul Deuster Messages: 15 Registered: April 2012 |
Junior Member |
|
|
Hello all,
i am developing a plug-in xText project, which should be build (Generate Xtext Artifacts) temporary at runtime.
I dont want all the *.ui *.test projects in my Version Control.
I have already looked up many different explainations to build xText with ant, but i still get errors i don't know how to fix.
I did the following:
(Using Eclipse 3.7)
I created a plug-in project with xText nature, then added the grammatic for my language (Language.xtext) and the mwe2 file (GenerateLanguage.mwe2). The build.xml i added to the META-INF Folder.
After that i wrote an Activator class which copies the project to a temporary Folder("C:/Language-test") i created before and executes the build.xml file which is localed directly in the project folder.
The build.xml and a snapshot of the mwe2 file are appended.
when i execute the ant-file via the Activator class in eclipse as well as via console i get the Exception in 'log.txt', i hope somebody can help me:
(console-command: C:\Language-test>C:\Users\myUser\Downloads\apache-ant-1.8.3-bin\apache-ant-1.8.3\bin\ant -f build.xml -Declipse.home=C:\Users\myUser\private_indigo > log.txt)
-
Attachment: log.txt
(Size: 84.88KB, Downloaded 182 times) -
Attachment: mwe2file.txt
(Size: 0.56KB, Downloaded 172 times) -
Attachment: build.xml
(Size: 2.63KB, Downloaded 134 times)
[Updated on: Wed, 04 April 2012 10:04] Report message to a moderator
|
|
|
|
|
|
|
Re: Building a xText projects temporal with Ant [message #836301 is a reply to message #836296] |
Wed, 04 April 2012 10:21 |
Paul Deuster Messages: 15 Registered: April 2012 |
Junior Member |
|
|
what i mean with Activator is this java class.
It is an Activator of the plug-in project
package de.cs3d.test.dsl;
import java.io.File;
import java.io.FileOutputStream;
import java.net.URL;
import java.util.Enumeration;
import org.apache.commons.io.IOUtils;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectHelper;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "de.cs3d.test.dsl.language"; //$NON-NLS-1$
// The shared instance
private static Activator plugin;
/**
* The constructor
*/
public Activator() {
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
Bundle b = context.getBundle();
Enumeration<URL> initFiles = b.findEntries(
"/src/de/cs3d/test/dsl/", "*", true);
File tempDir = new File("C:\\Language-test");
//System.out.println("foo");
//create common project
File commonProject = new File(tempDir, "de.cs3d.test.dsl.language");
commonProject.mkdir();
//copy build file
File antFile = new File(commonProject, "build.xml");
IOUtils.copy(b.getEntry("META-INF/build.xml").openStream(),
new FileOutputStream(antFile));
//copy .project file
/*File projectFile = new File(commonProject,".project");
IOUtils.copy(b.getEntry(".project").openStream(),
new FileOutputStream(projectFile));*/
//create META-INF folder for project
File metaInfFolder = new File(commonProject,"META-INF");
metaInfFolder.mkdir();
//copy manifest
File manifestFile = new File(metaInfFolder, "MANIFEST.MF");
IOUtils.copy(b.getEntry("META-INF/MANIFEST.MF").openStream(),
new FileOutputStream(manifestFile));
//create src folder for project
File srcFolder =new File(commonProject,"src");
@SuppressWarnings("unused")
boolean succes= srcFolder.mkdir();
//create packagehierachy in src folder
File deFolder = new File(srcFolder, "de");
deFolder.mkdir();
File cs3dFolder = new File (deFolder,"cs3d");
cs3dFolder.mkdir();
File testFolder = new File(cs3dFolder, "test");
testFolder.mkdir();
File dslFolder= new File(testFolder, "dsl");
dslFolder.mkdir();
//create src-gen folder for project
File srcGenFolder =new File(commonProject,"src-gen");
srcGenFolder.mkdir();
//create xtend-gen folder for project
File xtendGenFolder =new File(commonProject,"xtend-gen");
xtendGenFolder.mkdir();
//create packagehierachy in src-gen folder
/*File srcGendeFolder = new File(srcGenFolder, "de");
srcGendeFolder.mkdir();
File srcGencs3dFolder = new File (srcGendeFolder,"cs3d");
srcGencs3dFolder.mkdir();
File srcGentestFolder = new File(srcGencs3dFolder, "test");
srcGentestFolder.mkdir();
File srcGendslFolder = new File(srcGentestFolder,"dsl");
srcGendslFolder.mkdir();
new File(srcGendslFolder,"language").mkdir();*/
// Copy File of from package to package
while (initFiles.hasMoreElements()) {
URL u = initFiles.nextElement();
IOUtils.copy(u.openStream(), new FileOutputStream(
new File(commonProject, u.getFile())));
}
//run ant script
Project p = new Project();
p.setUserProperty("ant.file", antFile.getAbsolutePath());
p.setUserProperty("eclipse.home",
"C:\\Users\\myUser\\private_indigo");
/*p.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
p.addReference("ant.projectHelper", helper);
helper.parse(p, antFile);
p.executeTarget(p.getDefaultTarget());*/
DefaultLogger consoleLogger = new DefaultLogger();
consoleLogger.setErrorPrintStream(System.err);
consoleLogger.setOutputPrintStream(System.out);
consoleLogger.setMessageOutputLevel(Project.MSG_INFO);
p.addBuildListener(consoleLogger);
try {
p.fireBuildStarted();
p.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
p.addReference("ant.projectHelper", helper);
helper.parse(p, antFile);
p.executeTarget(p.getDefaultTarget());
p.fireBuildFinished(null);
} catch (BuildException e) {
p.fireBuildFinished(e);
}
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}
}
|
|
|
|
|
|
|
Re: Building a xText projects temporal with Ant [message #836339 is a reply to message #836324] |
Wed, 04 April 2012 11:15 |
|
very strange.
here is what i do.
(1) create a new Xtext project with wizard
(2) copy the stuff to c:/temp
(3) execute this ant file (from a location within my eclipse)
<project basedir="C:\temp\org.xtext.example.mydsl" default="gen" name="Generate Language">
<property name="eclipse.home" value="C:\Users\dietrich\Downloads\eclipse-java-indigo-SR1-win32\eclipse"></property>
<path id="gen.classpath">
<fileset dir="${eclipse.home}/">
<!-- antlr-2.7.7.jar
antlr-3.0.1.jar-->
<include name="plugins/org.antlr.generator*.jar"/>
<include name="plugins/com.google.guava*.jar"/>
<include name="plugins/com.google.inject*.jar"/>
<include name="plugins/com.ibm.icu*.jar"/>
<include name="plugins/de.itemis.xtext.antlr*.jar"/>
<include name="plugins/org.antlr.runtime*.jar"/>
<include name="plugins/org.apache.commons.cli*.jar"/>
<include name="plugins/org.apache.commons.logging*.jar"/>
<include name="plugins/org.apache.log4j*.jar"/>
<include name="plugins/org.eclipse.emf.codegen.ecore*.jar"/>
<include name="plugins/org.eclipse.emf.codegen*.jar"/>
<include name="plugins/org.eclipse.emf.common*.jar"/>
<include name="plugins/org.eclipse.emf.ecore.xmi*.jar"/>
<include name="plugins/org.eclipse.emf.ecore*.jar"/>
<include name="plugins/org.eclipse.emf.mwe.core*.jar"/>
<include name="plugins/org.eclipse.emf.mwe.utils*.jar"/>
<include name="plugins/org.eclipse.emf.mwe2.lib*.jar"/>
<include name="plugins/org.eclipse.emf.mwe2.language*.jar"/>
<include name="plugins/org.eclipse.emf.mwe2.launch*.jar"/>
<include name="plugins/org.eclipse.emf.mwe2.runtime*.jar"/>
<include name="plugins/org.eclipse.xpand*.jar"/>
<include name="plugins/org.eclipse.xtend.typesystem.emf*.jar"/>
<include name="plugins/org.eclipse.xtend.util.stdlib*.jar"/>
<include name="plugins/org.eclipse.xtend*.jar"/>
<include name="plugins/org.eclipse.xtext.common.types_*.jar"/>
<include name="plugins/org.eclipse.xtext.generator*.jar"/>
<include name="plugins/org.eclipse.xtext.util*.jar"/>
<include name="plugins/org.eclipse.xtext.xtend*.jar"/>
<include name="plugins/org.eclipse.xtext*.jar"/>
<include name="plugins/javax.inject*.jar"/>
<include name="plugins/stringtemplate*.jar"/>
</fileset>
<pathelement location="src"/>
<pathelement location="src-gen"/>
</path>
<target name="gen">
<java classname="org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher"
classpathref="gen.classpath" fork="true" failonerror="true">
<arg value="org.xtext.example.mydsl.GenerateMyDsl"/>
</java>
</target>
</project>
and hey: it works like a charm.
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Building a xText projects temporal with Ant [message #836559 is a reply to message #836486] |
Wed, 04 April 2012 16:17 |
|
Here is the code, but it doubt this is the problem
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
Bundle b = context.getBundle();
Enumeration<URL> initFiles = b.findEntries(
"/src/de/cs3d/test/dsl/", "*", true);
//run ant script
Project p = new Project();
p.setUserProperty("ant.file", "C:\\Users\\dietrich\\Downloads\\mcp56\\eclipse2\\org.xtext.example.mydsl2.ui\\META-INF\\build.xml");
p.setUserProperty("eclipse.home",
"C:\\Users\\dietrich\\Downloads\\eclipse-java-indigo-SR1-win32\\eclipse");
/*p.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
p.addReference("ant.projectHelper", helper);
helper.parse(p, antFile);
p.executeTarget(p.getDefaultTarget());*/
DefaultLogger consoleLogger = new DefaultLogger();
consoleLogger.setErrorPrintStream(System.err);
consoleLogger.setOutputPrintStream(System.out);
consoleLogger.setMessageOutputLevel(Project.MSG_INFO);
p.addBuildListener(consoleLogger);
try {
p.fireBuildStarted();
p.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
p.addReference("ant.projectHelper", helper);
helper.parse(p, new File("C:\\Users\\dietrich\\Downloads\\mcp56\\eclipse2\\org.xtext.example.mydsl2.ui\\META-INF\\build.xml"));
p.executeTarget(p.getDefaultTarget());
p.fireBuildFinished(null);
} catch (BuildException e) {
p.fireBuildFinished(e);
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
Re: Building a xText projects temporal with Ant [message #837097 is a reply to message #837055] |
Thu, 05 April 2012 09:09 |
Paul Deuster Messages: 15 Registered: April 2012 |
Junior Member |
|
|
The problem appears just for the generated .java file which represent my grammar. I think at this point
gen:
[java] 0 INFO StandaloneSetup - Registering platform uri 'C:\Foo-test'
[java] 1252 INFO DirectoryCleaner - Cleaning C:\Foo-test\org.xtext.example.foobar\..\org.xtext.example.foobar\src-gen
[java] 1273 INFO DirectoryCleaner - Cleaning C:\Foo-test\org.xtext.example.foobar\..\org.xtext.example.foobar.ui\src-gen
[java] 1590 INFO LanguageConfig - generating infrastructure for org.xtext.example.foobar.Foo with fragments : ImplicitRuntimeFragment, ImplicitUiFragment, GrammarAccessFragment, EcoreGeneratorFragment, ParseTreeConstructorFragment, ResourceFactoryFragment, XtextAntlrGeneratorFragment, JavaValidatorFragment, ImportNamespacesScopingFragment, QualifiedNamesFragment, BuilderIntegrationFragment, GeneratorFragment, FormatterFragment, LabelProviderFragment, OutlineTreeProviderFragment, QuickOutlineFragment, QuickfixProviderFragment, JavaBasedContentAssistFragment, XtextAntlrUiGeneratorFragment, Junit4Fragment, TypesGeneratorFragment, XbaseGeneratorFragment, CodetemplatesGeneratorFragment
the .java should exist already, maybe at dies point before the error in
[java] 4682 INFO GenModelHelper - Registered GenModel 'ht tp:// ww w.xtext.org/example/foobar/Foo' from 'file:/C:/Foo-test/org.xtext.example.foobar/src-gen/org/xtext/example/foobar/Foo.genmodel'
[java] org.eclipse.emf.common.util.WrappedException: java.io.IOException: The path '/org.xtext.example.foobar/src-gen/org/xtext/example/foobar/foo/FooPackage.java' is unmapped
appear, There is a problem, what is not mentioned.
Does this fact bring up an idea to somebody, where the error could be nested?
|
|
|
|
Powered by
FUDForum. Page generated in 0.05415 seconds