Skip to content

Commit

Permalink
use new release infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
oehme committed Oct 20, 2014
1 parent ee8352f commit 996dcb7
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 140 deletions.
42 changes: 22 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
buildscript {
repositories {
mavenCentral()
}

jcenter()
maven { url 'http://dl.bintray.com/oehme/maven/' }
}
dependencies {
classpath 'org.xtend:xtend-gradle-plugin:0.1.+'
classpath 'org.xtend:xtend-gradle-plugin:0.3.1'
classpath 'de.oehme.sobula:sobula:0.0.+'
}
}

subprojects {
apply plugin: 'xtend'
apply from: '../mavenRelease.gradle'

group = "org.xtext"
version = "0.0.6"
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'de.oehme.sobula.maven-release'
apply plugin: 'de.oehme.sobula.bintray-release'

repositories {
mavenCentral()
}

dependencies {
compile localGroovy()
compile 'org.eclipse.xtend:org.eclipse.xtend.lib:2.6.+'
compile 'com.github.oehme.xtend:xtend-contrib:0.4.+'
}
group = "org.xtext"
version = "0.1.0"

repositories {
jcenter()
}

sourceCompatibility = 1.5
}

task createWrapper(type: Wrapper) {
gradleVersion = '1.12'
configure(subprojects.findAll{p-> p.name.contains('plugin')}){
apply plugin: 'org.xtend.xtend'

dependencies {
compile localGroovy()
compile 'org.eclipse.xtend:org.eclipse.xtend.lib:2.7.2'
}
}
2 changes: 0 additions & 2 deletions gradle.properties

This file was deleted.

2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-bin.zip
distributionUrl=http\://services.gradle.org/distributions/gradle-2.1-bin.zip
61 changes: 0 additions & 61 deletions mavenRelease.gradle

This file was deleted.

8 changes: 2 additions & 6 deletions xtext-gradle-lib/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
description 'A small wrapper for Xtext to make it easier to use from Gradle'

dependencies {
compile ("org.eclipse.xtext:org.eclipse.xtext.builder.standalone:[2.5.4,)") {
exclude group:'asm', module:'asm'
}
}

uploadArchives.repositories.mavenDeployer.pom.project {
name 'Xtext Gradle Lib'
description 'A small wrapper for Xtext to make it easier to use from Gradle'
}

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

public class Main {

public static void main(String[] args) throws Exception {
public static boolean generate(String[] args) throws Exception {
Injector injector = Guice.createInjector(new StandaloneBuilderModule());
StandaloneBuilder builder = injector.getInstance(StandaloneBuilder.class);
builder.setClassPathEntries(new ArrayList<String>());
Expand Down Expand Up @@ -53,10 +53,7 @@ public static void main(String[] args) throws Exception {
builder.setLanguages(languages);
builder.setSourceDirs(sourcePath);

boolean success = builder.launch();
if (!success) {
throw new IllegalStateException("Xtext failed");
}
return builder.launch();
}

private static void fixEncoding(Map<String, LanguageAccess> languages, StandaloneBuilder builder) {
Expand Down
11 changes: 3 additions & 8 deletions xtext-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
description 'A plugin for invoking Xtext base Code generators'

dependencies {
compile gradleApi()
compile 'org.eclipse.core:org.eclipse.core.runtime:3.7.0'
Expand All @@ -7,11 +9,4 @@ jar {
manifest {
attributes("Implementation-Version": version)
}
}

uploadArchives.repositories.mavenDeployer.pom.project {
name 'Xtext Gradle Plugin'
description 'A plugin for invoking Xtext base Code generators'
}

project.test.dependsOn project(":xtext-gradle-lib").install
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.xtext.gradle.tasks;

import de.oehme.xtend.contrib.Property
import groovy.lang.Closure
import org.eclipse.xtend.lib.annotations.Accessors
import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Project
import org.gradle.api.file.SourceDirectorySet
Expand All @@ -11,11 +11,10 @@ import org.gradle.api.tasks.SourceSet
import org.gradle.util.ConfigureUtil

class XtextExtension {
@Property String version = "2.6.0"
@Property String encoding = "UTF-8"
@Property SourceDirectorySet sources
@Property boolean fork
@Property NamedDomainObjectContainer<Language> languages;
@Accessors String version = "2.7.2"
@Accessors String encoding = "UTF-8"
@Accessors SourceDirectorySet sources
@Accessors NamedDomainObjectContainer<Language> languages;

private Project project

Expand All @@ -35,10 +34,10 @@ class XtextExtension {
}

class Language {
@Property String name;
@Property String setup
@Property boolean consumesJava
@Property NamedDomainObjectContainer<OutputConfiguration> outputs
@Accessors String name;
@Accessors String setup
@Accessors boolean consumesJava
@Accessors NamedDomainObjectContainer<OutputConfiguration> outputs

private Project project

Expand All @@ -62,9 +61,9 @@ class Language {
}

class OutputConfiguration {
@Property String name
@Property Object dir
@Property SourceSet javaSourceSet
@Accessors String name
@Accessors Object dir
@Accessors SourceSet javaSourceSet

new(String name) {
this.name = name
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
package org.xtext.gradle.tasks;

import de.oehme.xtend.contrib.Property
import java.io.File
import java.net.URLClassLoader
import java.util.ArrayList
import java.util.List
import org.eclipse.xtend.lib.annotations.Accessors
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.file.FileCollection
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.TaskAction

import static extension org.xtext.gradle.GradleExtensions.*
import org.gradle.internal.classloader.FilteringClassLoader

class XtextGenerate extends DefaultTask {

private XtextExtension xtext

@Property @InputFiles FileCollection xtextClasspath
@Accessors @InputFiles FileCollection xtextClasspath

@Property @InputFiles FileCollection classpath
@Accessors @InputFiles FileCollection classpath

def configure(XtextExtension xtext) {
this.xtext = xtext
Expand Down Expand Up @@ -56,36 +55,49 @@ class XtextGenerate extends DefaultTask {
]
]
args += xtext.sources.srcDirs.map[absolutePath]
if (xtext.fork) {
generateForked(args)
} else {
generateNonForked(args)
}
generate(args)
}

def generateNonForked(ArrayList<String> arguments) {
def generate(List<String> arguments) {
System.setProperty("org.eclipse.emf.common.util.ReferenceClearingQueue", "false")
val contextClassLoader = Thread.currentThread.contextClassLoader
val classLoader = new URLClassLoader(getXtextClasspath.map[absoluteFile.toURI.toURL],
ClassLoader.systemClassLoader.parent)
val classLoader = getCompilerClassLoader(getXtextClasspath)
try {
Thread.currentThread.contextClassLoader = classLoader
val main = classLoader.loadClass("org.xtext.builder.standalone.Main")
val mainMethod = main.getMethod("main",typeof(String[]))
mainMethod.invoke(null, #[arguments as String[]])
val method = main.getMethod("generate", typeof(String[]))
val success = method.invoke(null, #[arguments as String[]]) as Boolean
if (!success) {
throw new GradleException('''Xtext generation failed''');
}
} finally {
Thread.currentThread.contextClassLoader = contextClassLoader
}
}

def generateForked(ArrayList<String> args) {
val result = project.javaexec [
main = "org.xtext.builder.standalone.Main"
it.classpath = getXtextClasspath
setArgs(args)
]
if (result.exitValue != 0) {
throw new GradleException("Xtext failed");
static val currentCompilerClassLoader = new ThreadLocal<URLClassLoader>() {
override protected initialValue() {
null
}
}

private def getCompilerClassLoader(FileCollection classpath) {
val classPathWithoutLog4j = classpath.filter[!name.contains("log4j")]
val urls = classPathWithoutLog4j.map[absoluteFile.toURI.toURL].toList
val currentClassLoader = currentCompilerClassLoader.get
if (currentClassLoader !== null && currentClassLoader.URLs.toList == urls) {
return currentClassLoader
} else {
val newClassLoader = new URLClassLoader(urls, loggingBridgeClassLoader)
currentCompilerClassLoader.set(newClassLoader)
return newClassLoader
}
}

private def loggingBridgeClassLoader() {
new FilteringClassLoader(XtextGenerate.classLoader) => [
allowPackage("org.slf4j")
allowPackage("org.apache.log4j")
]
}
}

0 comments on commit 996dcb7

Please sign in to comment.