-
Notifications
You must be signed in to change notification settings - Fork 317
/
XtextVersion.java
157 lines (136 loc) · 3.52 KB
/
XtextVersion.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/**
* Copyright (c) 2015, 2023 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtext.util;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.jar.Manifest;
import org.eclipse.emf.common.EMFPlugin;
import org.eclipse.emf.common.util.ResourceLocator;
/**
* @since 2.9
*/
public class XtextVersion {
private static class Plugin extends EMFPlugin {
public static final XtextVersion.Plugin INSTANCE = new XtextVersion.Plugin();
private Plugin() {
super(new ResourceLocator[] {});
}
@Override
public ResourceLocator getPluginResourceLocator() {
return null;
}
}
private final String version;
public XtextVersion(String version) {
this.version = version;
}
public static XtextVersion getCurrent() {
String versionFromManifest = XtextVersion.readVersionFromManifest();
return new XtextVersion(versionFromManifest != null ? versionFromManifest : "unknown");
}
public String getXtextGradlePluginVersion() {
return "4.0.0";
}
/**
* @noreference
*/
public String getMweVersion() {
return "2.17.0.M3";
}
/**
* @noreference
*/
public String getMweBuildNumber() {
return "S202402180822";
}
public String getAntlrGeneratorVersion() {
return "2.1.1";
}
public String getXtendGradlePluginVersion() {
return getXtextGradlePluginVersion();
}
/**
* @noreference
*/
public String getXtendAndroidGradlePluginVersion() {
return getXtendGradlePluginVersion();
}
/**
* @return <code>true</code> if the current version ends with '-SNAPSHOT'
*/
public boolean isSnapshot() {
return version.endsWith("-SNAPSHOT");
}
/**
* @return <code>true</code> if the current version is not a snapshot and
* not a release<br>
* Release builds must match a following pattern: N.N(.N)+<br>
* (N is a digit)<br>
* For example 2.9.2 is a release, 2.9.2.beta3 is stable.
*/
public boolean isStable() {
return !isSnapshot() && !version.matches("\\d+\\.\\d+(\\.\\d+)+");
}
@Override
public String toString() {
return version;
}
private static String readVersionFromManifest() {
URL baseURL = null;
try {
baseURL = XtextVersion.Plugin.INSTANCE.getBaseURL();
} catch (Exception e) {
return null;
}
try (InputStream is = new URL (baseURL + "META-INF/MANIFEST.MF").openStream()) {
Manifest manifest = new Manifest(is);
String version = manifest.getMainAttributes().getValue("Maven-Version");
if (version == null) {
version = manifest.getMainAttributes().getValue("Bundle-Version");
if (version.endsWith(".qualifier")) {
return version.replace(".qualifier", "-SNAPSHOT");
} else {
return version.substring(0, version.lastIndexOf("."));
}
}
return version;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public int hashCode() {
return 31 * 1 + ((this.version== null) ? 0 : this.version.hashCode());
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
XtextVersion other = (XtextVersion) obj;
if (version == null) {
if (other.version != null) {
return false;
}
} else if (!version.equals(other.version)) {
return false;
}
return true;
}
public String getVersion() {
return version;
}
}