Second approach to generating Xtend files in the build

This commit is contained in:
Miro Spönemann 2016-11-22 16:35:07 +01:00
parent 55b7531d74
commit 648f51911b
7 changed files with 64 additions and 36 deletions

View file

@ -2,6 +2,12 @@
* Root project for xtext-core.
*/
import java.time.format.DateTimeFormatter
import java.time.LocalDateTime
apply from: "${rootDir}/gradle/versions.gradle"
apply from: "${rootDir}/gradle/bootstrap-setup.gradle"
buildscript {
repositories {
jcenter()
@ -10,6 +16,7 @@ buildscript {
}
}
dependencies {
classpath 'org.xtext:xtext-gradle-plugin:1.0.12'
classpath 'io.typefox.gradle:io.typefox.gradle.p2gen:0.1.0'
}
}
@ -17,18 +24,20 @@ buildscript {
apply from: "${rootDir}/gradle/versions.gradle"
apply from: "${rootDir}/gradle/p2-deployment.gradle"
ext.buildTime = new java.text.SimpleDateFormat('yyyyMMdd-HHmm').format(new Date())
ext.buildTime = DateTimeFormatter.ofPattern('yyyyMMdd-HHmm').format(LocalDateTime.now())
subprojects {
group = 'org.eclipse.xtext'
version = rootProject.version
apply plugin: 'java'
apply plugin: 'org.xtext.xtend'
apply plugin: 'eclipse'
apply plugin: 'maven'
apply from: "${rootDir}/gradle/upstream-repositories.gradle"
apply from: "${rootDir}/gradle/java-compiler-settings.gradle"
apply from: "${rootDir}/gradle/xtend-compiler-settings.gradle"
apply from: "${rootDir}/gradle/maven-deployment.gradle"
apply from: "${rootDir}/gradle/eclipse-project-layout.gradle"
apply from: "${rootDir}/gradle/manifest-gen.gradle"

View file

@ -0,0 +1,25 @@
/*
* Root project configuration that is reused by subprojects to apply the Xtend compiler.
*/
repositories.jcenter()
configurations {
xtendCompiler {
description 'Bootstrap dependencies for the Xtend compiler'
resolutionStrategy {
eachDependency {
if (requested.group == 'org.eclipse.xtext' || requested.group == 'org.eclipse.xtend')
useVersion(versions.xtext_bootstrap)
if (requested.group == 'com.google.inject' && requested.name == 'guice')
useVersion(versions.guice)
}
}
exclude group: 'asm'
}
}
dependencies {
xtendCompiler "org.eclipse.xtend:org.eclipse.xtend.core:$versions.xtext_bootstrap"
xtendCompiler "org.xtext:xtext-gradle-builder:$versions.xtend_plugin"
}

View file

@ -4,17 +4,18 @@
*/
def isTestProject = name.endsWith('tests')
def sourceDirs = ['src', 'xtend-gen', 'src-gen', 'emf-gen']
def sourceDirs = ['src', 'src-gen', 'emf-gen']
sourceSets {
configure(isTestProject? test : main) {
java {
srcDirs = sourceDirs
include '**/*.java', '**/*.xtend'
xtendOutputDir = 'xtend-gen'
}
resources {
srcDirs = sourceDirs
exclude '**/*.java', '**/*.xtend', '**/*.xtendbin', '**/*._trace'
exclude '**/*.java', '**/*.xtend'
}
}
configure(isTestProject? main : test) {
@ -47,18 +48,10 @@ if (isTestProject || name.contains('testlanguage')) {
artifacts.archives javadocJar
}
eclipse {
classpath {
file {
whenMerged {
entries.each {
source ->
if (source.kind == 'src' && source.path.endsWith('-gen') && !source.path.equals('xtend-gen') ) {
source.entryAttributes['ignore_optional_problems'] = 'true'
}
}
}
eclipse.classpath.file.whenMerged {
entries.each { source ->
if (source.kind == 'src' && source.path.endsWith('-gen') && !source.path.equals('xtend-gen') ) {
source.entryAttributes['ignore_optional_problems'] = 'true'
}
}
}

View file

@ -53,7 +53,7 @@ afterEvaluate {
description = 'Create or update the local Maven repository'
configuration = configurations.archives
repositories.mavenDeployer {
repository(url: "file:" + file("../build/maven-repository"))
repository(url: "file:" + file("${rootDir}/build/maven-repository"))
configurePom(pom)
}
}

View file

@ -6,7 +6,8 @@ version = '2.11.0-SNAPSHOT'
ext.versions = [
'xtext': version,
'xtext_bootstrap': '2.10.0',
'xtext_bootstrap': '2.11.0.beta2',
'xtend_plugin': '1.0.12',
'lsp4j': '0.1.0-SNAPSHOT',
'log4j': '1.2.16',
'equinoxCommon' : '3.6.0',

View file

@ -0,0 +1,7 @@
/*
* Configuration of Xtend compiler.
*/
xtext.version = versions.xtext_bootstrap
generateXtext.xtextClasspath = rootProject.configurations.getByName('xtendCompiler')

View file

@ -1,41 +1,34 @@
// re-configure the 'main' and 'mwe2' sourceSets as the content of this project's
// source folders need to be compiled before the generator execution
// 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' ]
mwe2.java.srcDirs = [ 'src' ]
}
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)
// 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
// 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.
*/
// 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)
// 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)