Skip to content

Commit 289eebf

Browse files
authored
Merge pull request #102 from xtext/cd_issue101
[#101] Made Version Detection more robust regaring usage in java 9
2 parents 8165e6f + 789f312 commit 289eebf

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

xtext-gradle-plugin/src/main/java/org/xtext/gradle/XtextBuilderPlugin.xtend

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import org.gradle.api.GradleException
88
import org.gradle.api.Plugin
99
import org.gradle.api.Project
1010
import org.gradle.api.artifacts.Configuration
11+
import org.gradle.api.file.FileCollection
1112
import org.gradle.api.plugins.BasePlugin
1213
import org.gradle.api.plugins.JavaBasePlugin
1314
import org.gradle.api.plugins.JavaPluginConvention
@@ -16,13 +17,13 @@ import org.gradle.api.tasks.compile.JavaCompile
1617
import org.gradle.plugins.ide.eclipse.EclipsePlugin
1718
import org.gradle.plugins.ide.eclipse.model.EclipseModel
1819
import org.xtext.gradle.tasks.Outlet
20+
import org.xtext.gradle.tasks.XtextClasspathInferrer
1921
import org.xtext.gradle.tasks.XtextEclipseSettings
2022
import org.xtext.gradle.tasks.XtextExtension
2123
import org.xtext.gradle.tasks.XtextGenerate
2224

2325
import static extension org.xtext.gradle.GradleExtensions.*
24-
import org.gradle.api.file.FileCollection
25-
import org.xtext.gradle.tasks.XtextClasspathInferrer
26+
import static org.xtext.gradle.XtextBuilderPluginVersion.*
2627

2728
class XtextBuilderPlugin implements Plugin<Project> {
2829

@@ -54,7 +55,7 @@ class XtextBuilderPlugin implements Plugin<Project> {
5455
xtextClasspath = project.files(new Callable<FileCollection>() {
5556
FileCollection inferredClasspath
5657
override call() throws Exception {
57-
if (inferredClasspath == null) {
58+
if (inferredClasspath === null) {
5859
inferredClasspath = inferXtextClasspath(classpath)
5960
}
6061
inferredClasspath
@@ -81,14 +82,14 @@ class XtextBuilderPlugin implements Plugin<Project> {
8182
private def automaticallyInferXtextCoreClasspath() {
8283
xtext.classpathInferrers += new XtextClasspathInferrer() {
8384
override inferXtextClasspath(FileCollection xtextClasspath, FileCollection classpath) {
84-
val xtextBuilder = project.dependencies.externalModule('''org.xtext:xtext-gradle-builder:«pluginVersion»''')
85+
val xtextBuilder = project.dependencies.externalModule('''org.xtext:xtext-gradle-builder:«PLUGIN_VERSION»''')
8586
val xtextTooling = project.configurations.detachedConfiguration(xtextBuilder)
8687
xtext.makeXtextCompatible(xtextTooling)
8788
xtext.forceXtextVersion(xtextTooling, new Function0<String>() {
8889
String version = null
8990

9091
override apply() {
91-
if (version == null) {
92+
if (version === null) {
9293
version = xtext.getXtextVersion(classpath) ?: xtext.getXtextVersion(xtextClasspath)
9394
if (version === null) {
9495
throw new GradleException('''Could not infer Xtext classpath, because xtext.version was not set and no xtext libraries were found on the «classpath» classpath''')
@@ -102,10 +103,6 @@ class XtextBuilderPlugin implements Plugin<Project> {
102103
}
103104
}
104105

105-
private def String getPluginVersion() {
106-
XtextBuilderPlugin.package.implementationVersion
107-
}
108-
109106
private def configureOutletDefaults() {
110107
xtext.languages.all [ language |
111108
language.generator.outlets.create(Outlet.DEFAULT_OUTLET)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.xtext.gradle;
2+
3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
import java.util.jar.Manifest;
6+
7+
public class XtextBuilderPluginVersion {
8+
9+
public static final String PLUGIN_VERSION;
10+
11+
static {
12+
String implementationVersion = XtextBuilderPluginVersion.class.getPackage().getImplementationVersion();
13+
if (implementationVersion != null) {
14+
PLUGIN_VERSION = implementationVersion;
15+
} else {
16+
String version = null;
17+
try (InputStream stream = XtextBuilderPluginVersion.class.getResourceAsStream("/META-INF/MANIFEST.MF")) {
18+
if (stream != null) {
19+
Manifest mf = new Manifest(stream);
20+
version = mf.getMainAttributes().getValue("Implementation-Version");
21+
}
22+
} catch (IOException e) {
23+
}
24+
PLUGIN_VERSION = version;
25+
26+
}
27+
}
28+
29+
}

0 commit comments

Comments
 (0)