Skip to content

Commit

Permalink
Merge pull request #36 from xtext/incremental_build
Browse files Browse the repository at this point in the history
Incremental build
  • Loading branch information
oehme committed Dec 16, 2015
2 parents b377b76 + 9d31b2c commit fb169ee
Show file tree
Hide file tree
Showing 84 changed files with 3,578 additions and 846 deletions.
22 changes: 16 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
.classpath
.project
.settings/
.gradle/
# Eclipse
.classpath
.project
.settings/
.metadata/
bin/

# IntelliJ
*.iml
*.ipr
*.iws
.idea/
out/

# Gradle
.gradle/
build/

bin/
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
language: java
sudo: false
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
cache:
directories:
- $HOME/.gradle
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
install: true
script: ./gradlew check && ./.travis/releaseOnTag.sh
73 changes: 3 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,75 +1,8 @@
xtext-gradle-plugin
Xtext Gradle Plugins
===================

[![Build Status](https://travis-ci.org/xtext/xtext-gradle-plugin.svg?branch=master)](https://travis-ci.org/xtext/xtext-gradle-plugin)

A plugin for using Xtext languages from a Gradle build
A set of [Gradle](gradle.org) plugins to build and use [Xtext](xtext.org) languages and the [Xtend](xtend-lang.org) programming language.

Features
--------

- Use Xtext based code generators in your Gradle build
- automatically integrates with the Java plugin
- all your languages are built in one go, so they can have cross-references
- configures the Eclipse plugin to generate .settings files for each language

Usage
-----

Get the latest version of the plugin from the [Gradle Plugin Portal](http://plugins.gradle.org/plugin/org.xtext.xtext)

Add your languages to the xtextTooling configuration

```groovy
dependencies {
xtextTooling 'org.example:org.example.hero.core:3.3.3'
xtextTooling 'org.example:org.example.villain.core:6.6.6'
}
```

Add code that your models compile against to the xtext configuration. If you use the Java plugin, this configuration will automatically contain everything from compile and testCompile. So in many cases this can be omitted.

```groovy
dependencies {
xtext 'com.google.guava:guava:15.0'
}
```

Configure your languages

```groovy
xtext {
version = '2.8.0' // the current default, can be omitted
encoding = 'UTF-8' //the default, can be omitted
/* Java sourceDirs are added automatically,
* so you only need this element if you have
* additional source directories to add
*/
sources {
srcDir 'src/main/heroes'
srcDir 'src/main/villains'
}
languages{
heroes {
setup = 'org.example.hero.core.HeroStandaloneSetup'
consumesJava = true
outputs {
DEFAULT_OUTPUT.dir = 'build/heroes'
SIDEKICKS {
dir = 'build/sidekicks'
//automatically adds the above folder as a Java source folder for the main sourceSet
producesJavaFor sourceSets.main
}
}
}
villains {
setup = 'org.example.villain.core.VillainStandaloneSetup'
//equivalent to DEFAULT_OUTPUT.dir
output.dir = 'build/villains'
}
}
}
```
The documentation is hosted on the [project's website](http://xtext.github.io/xtext-gradle-plugin/).
76 changes: 50 additions & 26 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,20 @@ buildscript {
jcenter()
}
dependencies {
classpath 'org.xtend:xtend-gradle-plugin:0.4.5'
classpath 'com.github.oehme.sobula:sobula:0.5.0'
classpath 'org.xtend:xtend-gradle-plugin:0.4.14'
classpath 'com.github.oehme.sobula:sobula:0.6.6'
classpath "com.netflix.nebula:nebula-project-plugin:2.2.1"
}
}

/*
* TODO this weird order is a workaround for a bug in the nebula publishing plugin
* If they don't fix it soon, sobula should be rewritten to work without it.
*/
configure(subprojects.findAll{p-> p.name.contains('plugin')}){
apply plugin: 'org.xtend.xtend'
apply plugin: 'java-gradle-plugin'

dependencies {
compile 'org.eclipse.xtend:org.eclipse.xtend.lib:2.8.0'
}
}

subprojects {
apply plugin: 'eclipse'
apply plugin: 'java'

sourceCompatibility = 1.6
}

allprojects {
apply plugin: 'com.github.oehme.sobula.plugin-release'

group = "org.xtext"
bintray.pkg.name = "$rootProject.group:$rootProject.name"

contacts {
"xtext@itemis.com" {
"xtext.team@gmail.com" {
moniker "The Xtext team"
roles "owner"
github "xtext"
Expand All @@ -45,9 +26,52 @@ allprojects {
//TODO create bintray and central users
bintray.user = "oehme"
bintray.pkg.version.mavenCentralSync.user = "oehme"

repositories {
jcenter()
}
}

bintray.publications = [] // don't publish a POM for the root project
subprojects {
apply plugin: 'eclipse'
apply plugin: 'java'

sourceCompatibility = 1.6

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

dependencies {
compile gradleApi()
compile 'com.google.guava:guava:18.0'
}
}

configure(subprojects.findAll{p-> !p.name.contains('protocol')}) {
apply plugin: 'org.xtend.xtend'

dependencies {
compile 'org.eclipse.xtend:org.eclipse.xtend.lib:2.9.0'
}
}

configure(subprojects.findAll{p-> p.name.contains('plugin')}){
apply plugin: 'java-gradle-plugin'
apply plugin: "nebula.nebula-integtest"

jar {
manifest {
attributes("Implementation-Version": project.version)
}
}

dependencies {
integTestCompile gradleTestKit()
}

integrationTest {
dependsOn("install")
systemProperty 'gradle.project.version', version
}
}
12 changes: 6 additions & 6 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Jun 03 18:49:02 CEST 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-bin.zip
#Tue Jun 03 18:49:02 CEST 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-2.7-all.zip
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include 'xtext-gradle-lib', 'xtext-gradle-plugin', 'xtext-idea-gradle-plugin'
include 'xtext-gradle-protocol', 'xtext-gradle-builder', 'xtext-gradle-plugin', 'xtext-idea-gradle-plugin', 'xtext-android-gradle-plugin'
11 changes: 11 additions & 0 deletions xtext-android-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
description 'A plugin for integrating Xtext based Code generators with the Android build tools'

dependencies {
compile project(':xtext-gradle-plugin')
compile 'com.android.tools.build:gradle:1.5.0'
integTestCompile project(path : ':xtext-gradle-plugin', configuration: 'integTestCompile')
}

integrationTest {
dependsOn(':xtext-gradle-builder:install', ':xtext-gradle-protocol:install', ':xtext-gradle-plugin:install')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.xtext.gradle.android

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.xtext.gradle.XtendLanguageBasePlugin
import org.xtext.gradle.protocol.GradleInstallDebugInfoRequest.SourceInstaller
import org.xtext.gradle.tasks.XtextExtension

class XtendAndroidBuilderPlugin implements Plugin<Project> {

override apply(Project project) {
project.apply[
plugin(XtextAndroidBuilderPlugin)
plugin(XtendLanguageBasePlugin)
]

val xtext = project.extensions.getByType(XtextExtension)
xtext.languages.getAt("xtend") => [
debugger => [
sourceInstaller = SourceInstaller.PRIMARY
hideSyntheticVariables = false
]
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package org.xtext.gradle.android

import com.android.build.gradle.AppExtension
import com.android.build.gradle.AppPlugin
import com.android.build.gradle.BaseExtension
import com.android.build.gradle.LibraryExtension
import com.android.build.gradle.LibraryPlugin
import com.android.build.gradle.api.BaseVariant
import com.android.build.gradle.internal.api.TestedVariant
import java.io.File
import org.gradle.api.DomainObjectSet
import org.gradle.api.GradleException
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.xtext.gradle.XtextBuilderPlugin
import org.xtext.gradle.XtextJavaLanguagePlugin
import org.xtext.gradle.tasks.XtextExtension
import org.xtext.gradle.tasks.XtextGenerate

class XtextAndroidBuilderPlugin implements Plugin<Project> {

Project project
XtextExtension xtext
BaseExtension android
DomainObjectSet<? extends BaseVariant> variants

override apply(Project project) {
this.project = project
project.apply[
plugin(XtextBuilderPlugin)
plugin(XtextJavaLanguagePlugin)
]
xtext = project.extensions.getByType(XtextExtension)
project.plugins.withType(AppPlugin)[configureAndroid]
project.plugins.withType(LibraryPlugin)[configureAndroid]
}

private def configureAndroid() {
project.afterEvaluate[
android = project.extensions.getByName("android") as BaseExtension
variants = switch android {
AppExtension: android.applicationVariants as DomainObjectSet<? extends BaseVariant>
LibraryExtension: android.libraryVariants
default: throw new GradleException('''Unknown packaging type «android.class.simpleName»''')
}
configureOutletDefaults
configureGeneratorDefaults
configureSourceSetDefaults
]
}

private def configureSourceSetDefaults() {
variants.all [ variant |
configureSourceSetForVariant(variant)
if (variant instanceof TestedVariant) {
if (variant.testVariant != null)
configureSourceSetForVariant(variant.testVariant)
}
]
}

private def configureSourceSetForVariant(BaseVariant variant) {
xtext.sourceSets.maybeCreate(variant.name) => [ sourceSet |
val generatorTask = project.tasks.getByName(sourceSet.generatorTaskName) as XtextGenerate
generatorTask.dependsOn(
variant.aidlCompile,
variant.renderscriptCompile,
variant.generateBuildConfig
)
generatorTask.dependsOn(variant.outputs.map[processResources])
variant.javaCompiler.doLast[generatorTask.installDebugInfo]
val sourceDirs = newArrayList
val javaDirs = variant.sourceSets.map[javaDirectories].flatten.filter[directory]
sourceDirs += javaDirs
sourceDirs += #[
variant.aidlCompile.sourceOutputDir,
variant.generateBuildConfig.sourceOutputDir,
variant.renderscriptCompile.sourceOutputDir
]
sourceDirs += variant.outputs.map[processResources.sourceOutputDir]
sourceSet.srcDirs(sourceDirs)
generatorTask.bootClasspath = android.bootClasspath.join(File.pathSeparator)
generatorTask.classpath = variant.javaCompiler.classpath.plus(project.files(android.bootClasspath))
generatorTask.classesDir = variant.javaCompiler.destinationDir
generatorTask.options.encoding = android.compileOptions.encoding
variant.registerJavaGeneratingTask(generatorTask, generatorTask.outputDirectories)
]
}

private def configureGeneratorDefaults() {
xtext.languages.all [
generator.javaSourceLevel = android.compileOptions.sourceCompatibility.toString
]
}

private def configureOutletDefaults() {
xtext.languages.all [ language |
language.generator.outlets.all [ outlet |
xtext.sourceSets.all [ sourceSet |
val output = sourceSet.output
output.dir(outlet, '''«project.buildDir»/generated/source/«language.name»«outlet.folderFragment»/«sourceSet.name»''')
]
]
]
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
implementation-class=org.xtext.gradle.android.XtextAndroidBuilderPlugin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
implementation-class=org.xtext.gradle.android.XtendAndroidBuilderPlugin
8 changes: 8 additions & 0 deletions xtext-gradle-builder/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
description 'A small wrapper for Xtext to make it easier to use from Gradle'

dependencies {
compile "org.eclipse.xtext:org.eclipse.xtext:2.9.0"
compile "org.eclipse.xtext:org.eclipse.xtext.java:2.9.0"
compile "org.eclipse.xtext:org.eclipse.xtext.xbase:2.9.0"
compile project(':xtext-gradle-protocol')
}
Loading

0 comments on commit fb169ee

Please sign in to comment.