[xtext lang] contributed new bundle 'org.eclipse.xtext.xtext.bootstrap' containing the 'GenerateXtext.mwe2' workflow and a customizing guice module

* added task 'generateXtextLanguage' in 'build.gradle' for executing the workflow via gradle
* fixed definition of 'mwe2' sourceSet in '/gradle/java-compiler-settings.gradle'

Signed-off-by: Christian Schneider <christian.schneider@typefox.io>
This commit is contained in:
Christian Schneider 2016-12-13 16:18:42 +01:00
parent 7fae8432f9
commit 9083f8b48b
10 changed files with 329 additions and 6 deletions

View file

@ -17,12 +17,7 @@ tasks.withType(Javadoc) {
}
sourceSets {
mwe2 {
java {
compileClasspath += main.output
runtimeClasspath += main.output
}
}
mwe2 {}
}
configurations {

View file

@ -8,6 +8,8 @@ apply plugin: 'io.typefox.gradle.p2gen'
group = 'org.eclipse.xtext'
p2gen {
exclude 'org.eclipse.xtext.xtext.bootstrap'
dependencies {
repositoryUrl "http://download.eclipse.org/modeling/tmf/xtext/updates/releases/${versions.xtext_bootstrap}/"
feature 'org.eclipse.xtext.sdk'

View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src">
<attributes>
<attribute name="FROM_GRADLE_MODEL" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="xtend-gen">
<attributes>
<attribute name="FROM_GRADLE_MODEL" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.xtext.xtext.bootstrap</name>
<comment>Project org.eclipse.xtext.bootstrap created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.emf.mwe2.launch.Mwe2LaunchConfigurationType">
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${working_set:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;resources&gt;&#10;&lt;item path=&quot;/org.eclipse.xtext&quot; type=&quot;4&quot;/&gt;&#10;&lt;item path=&quot;/org.eclipse.xtext.ui&quot; type=&quot;4&quot;/&gt;&#10;&lt;item path=&quot;/org.eclipse.xtext.xtext.ui&quot; type=&quot;4&quot;/&gt;&#10;&lt;/resources&gt;}"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/org.eclipse.xtext.xtext.bootstrap"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="src/org/eclipse/xtext/xtext/bootstrap/GenerateXtext.mwe2"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.xtext.xtext.bootstrap"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xmx512m"/>
</launchConfiguration>

View file

@ -0,0 +1,41 @@
// re-configure the 'main' and 'mwe2' sourceSets as the content of this project's
// source folders need to be compiled before the generator execution
sourceSets {
main.java.srcDirs = []
main.resources.srcDirs = []
// the 'mwe2' sourceSet is declared in '../gradle/java-compiler-settings.gradle'
mwe2.java.srcDirs = [ 'src', 'xtend-gen' ]
}
dependencies {
// we cannot use the projects within the workspace, as we would have
// to compile them before generating the code, so we need to stick to the bootstrapping version
// buildship, however, links the workspace projects anyway (as yet)
mwe2Compile "org.eclipse.xtext:org.eclipse.xtext:$versions.xtext_bootstrap"
mwe2Compile "org.eclipse.xtext:org.eclipse.xtext.xtext.generator:$versions.xtext_bootstrap"
// dependencies required for successfully executing the Xtext generation workflow
mwe2Runtime "org.eclipse.emf:org.eclipse.emf.mwe2.launch:$versions.emfMwe2"
mwe2Runtime "org.eclipse.xtext:org.eclipse.xtext.common.types:$versions.xtext_bootstrap"
mwe2Runtime "org.eclipse.xtext:org.eclipse.xtext.ecore:$versions.xtext_bootstrap"
}
/**
* Call this task for generating the 'Xtext' language implementation.
* The employed version of the Xtext generator is determined by '$versions.xtext_bootstrap', see above.
*/
task generateXtextLanguage(type: JavaExec) {
main = 'org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher'
classpath = sourceSets.mwe2.runtimeClasspath
// includes mwe2Runtime+mwe2Compile dependencies + the classes obtained from sourceSets.mwe2.java.srcDirs
args += "src/org/eclipse/xtext/xtext/bootstrap/GenerateXtext.mwe2"
args += "-p"
args += "rootPath=/${projectDir}/.."
}
// the following setting would cause 'generateXtextLanguage' to be executed as part of 'build',
// namely before compiling the classes of the 'main' sourceSet, which however is empty here
// classes.dependsOn(generateXtextLanguage)

View file

@ -0,0 +1,139 @@
/*******************************************************************************
* Copyright (c) 2010 itemis AG (http://www.itemis.eu) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
module org.eclipse.xtext.xtext.bootstrap.GenerateXtext
import org.eclipse.emf.mwe.utils.*
import org.eclipse.xtext.xtext.generator.*
import org.eclipse.xtext.xtext.generator.model.project.*
import org.eclipse.xtext.generator.*
import org.eclipse.xtext.ui.generator.*
import org.eclipse.xtext.generator.parser.antlr.*
import org.eclipse.xtext.resource.XtextResourceSet
var rootPath = ".."
var baseName = "org.eclipse.xtext"
var runtimeProjectName = baseName
var ideProjectName = "${baseName}.xtext.ide"
var eclipseProjectName = "${baseName}.xtext.ui"
var ideaProjectName = "${baseName}.xtext.idea"
var fileHeader = "/*\n * generated by Xtext 2.11\n */" //\${version}\n */"
var file.extensions = "xtext,xtext2"
Workflow {
component = XtextGenerator {
configuration = DefaultGeneratorModule {
project = StandardProjectConfig {
baseName = baseName
rootPath = rootPath
runtime = {
name = runtimeProjectName
}
}
code = {
encoding = "ISO-8859-1"
lineDelimiter = "\n"
fileHeader = fileHeader
preferXtendStubs = false
}
}
language = {
name = "org.eclipse.xtext.common.Terminals"
fragment = grammarAccess.GrammarAccessFragment2 {}
fragment = serializer.SerializerFragment2 {
generateStub = false
}
}
}
component = XtextGenerator {
configuration = XtextLangGeneratorModule {
project = StandardProjectConfig {
baseName = baseName
rootPath = rootPath
runtime = {
name = runtimeProjectName
}
genericIde = {
enabled = true
name = ideProjectName
}
eclipsePlugin = {
enabled = true
name = eclipseProjectName
root = "${rootPath}/../xtext-eclipse/${eclipseProjectName}"
}
ideaPlugin = {
enabled = true
name = ideaProjectName
root = "${rootPath}/../xtext-idea/${ideaProjectName}"
}
// createEclipseMetaData = true
}
code = {
encoding = "ISO-8859-1"
lineDelimiter = "\n"
fileHeader = fileHeader
preferXtendStubs = false
}
}
cleaner = {
// for the sake of keeping the artifacts generated above exclude everything in
// 'org.eclipse.xtext.common'; unfortunately the cleaner expects simple names so...
exclude = "common"
}
language = {
name = "org.eclipse.xtext.Xtext"
fileExtensions = file.extensions
referencedResource = "platform:/resource/org.eclipse.xtext/org/eclipse/xtext/Xtext.genmodel"
referencedResource = "platform:/resource/org.eclipse.xtext/org/eclipse/xtext/Xtext.ecore"
fragment = grammarAccess.GrammarAccessFragment2 {}
fragment = parser.antlr.XtextAntlrGeneratorFragment2 {
options = {
classSplitting = true
}
}
fragment = ui.contentAssist.ContentAssistFragment2 {}
fragment = ui.labeling.LabelProviderFragment2 {}
fragment = resourceFactory.ResourceFactoryFragment2 {}
fragment = serializer.SerializerFragment2 {
generateStub = false
}
fragment = ui.compare.CompareFragment2 {}
fragment = ui.refactoring.RefactorElementNameFragment2 {}
fragment = ui.templates.CodetemplatesGeneratorFragment2 {}
fragment = org.eclipse.xtext.xtext.generator.idea.IdeaPluginGenerator {
generateXtendStub = true
}
fragment = org.eclipse.xtext.xtext.generator.idea.parser.antlr.XtextAntlrIDEAGeneratorFragment {
options = {
classSplitting = true
}
}
}
}
}

View file

@ -0,0 +1,40 @@
package org.eclipse.xtext.xtext.bootstrap
import org.eclipse.xtext.Grammar
import org.eclipse.xtext.xtext.generator.DefaultGeneratorModule
import org.eclipse.xtext.xtext.generator.XtextGeneratorNaming
import org.eclipse.xtext.xtext.generator.model.TypeReference
class XtextLangGeneratorModule extends DefaultGeneratorModule {
def Class<? extends XtextGeneratorNaming> bindNaming() {
return XtextLangGeneratorNaming
}
public static class XtextLangGeneratorNaming extends XtextGeneratorNaming {
override getGenericIdeBasePackage(Grammar grammar) {
if (isXtext(grammar)) {
return "org.eclipse.xtext.xtext.ide";
} else {
return super.getGenericIdeBasePackage(grammar);
}
}
override getEclipsePluginBasePackage(Grammar grammar) {
if (isXtext(grammar)) {
return "org.eclipse.xtext.xtext.ui";
} else {
return super.getEclipsePluginBasePackage(grammar);
}
}
override getEclipsePluginActivator() {
return new TypeReference("org.eclipse.xtext.xtext.ui.internal", "Activator");
}
def boolean isXtext(Grammar grammar) {
return grammar.getName().equals("org.eclipse.xtext.Xtext");
}
}
}

View file

@ -0,0 +1,45 @@
package org.eclipse.xtext.xtext.bootstrap;
import org.eclipse.xtext.Grammar;
import org.eclipse.xtext.xtext.generator.DefaultGeneratorModule;
import org.eclipse.xtext.xtext.generator.XtextGeneratorNaming;
import org.eclipse.xtext.xtext.generator.model.TypeReference;
@SuppressWarnings("all")
public class XtextLangGeneratorModule extends DefaultGeneratorModule {
public static class XtextLangGeneratorNaming extends XtextGeneratorNaming {
@Override
public String getGenericIdeBasePackage(final Grammar grammar) {
boolean _isXtext = this.isXtext(grammar);
if (_isXtext) {
return "org.eclipse.xtext.xtext.ide";
} else {
return super.getGenericIdeBasePackage(grammar);
}
}
@Override
public String getEclipsePluginBasePackage(final Grammar grammar) {
boolean _isXtext = this.isXtext(grammar);
if (_isXtext) {
return "org.eclipse.xtext.xtext.ui";
} else {
return super.getEclipsePluginBasePackage(grammar);
}
}
@Override
public TypeReference getEclipsePluginActivator() {
return new TypeReference("org.eclipse.xtext.xtext.ui.internal", "Activator");
}
public boolean isXtext(final Grammar grammar) {
String _name = grammar.getName();
return _name.equals("org.eclipse.xtext.Xtext");
}
}
public Class<? extends XtextGeneratorNaming> bindNaming() {
return XtextLangGeneratorModule.XtextLangGeneratorNaming.class;
}
}

View file

@ -1,5 +1,6 @@
rootProject.name = 'xtext-core'
include 'org.eclipse.xtext.xtext.bootstrap'
include 'org.eclipse.xtext'
include 'org.eclipse.xtext.ide'
include 'org.eclipse.xtext.util'