diff --git a/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/UriExtensionsTest.xtend b/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/UriExtensionsTest.xtend index bce7955b7..b82d028cd 100644 --- a/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/UriExtensionsTest.xtend +++ b/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/UriExtensionsTest.xtend @@ -276,6 +276,20 @@ class UriExtensionsTest { var uri = createFileURI(directory.absolutePath + "/").toUriString.toUri assertTrue(uri.isPrefix) } + + @Test + def void test_withEmptyAuthority () { + val uriWithoutAuthority = org.eclipse.emf.common.util.URI.createURI("file:/path/to/resource/") + assertNull(uriWithoutAuthority.authority) + val uriWithEmptyAuthority = uriWithoutAuthority.withEmptyAuthority + assertNotSame(uriWithoutAuthority, uriWithEmptyAuthority) + assertEquals("Returned URI is expected to have an empty instead of null authority", "", uriWithEmptyAuthority.authority) + + val uriWithAuthority = org.eclipse.emf.common.util.URI.createURI("https://xtext.org/path/to/resource/") + assertNotNull(uriWithAuthority.authority) + assertEquals("xtext.org", uriWithAuthority.authority) + assertSame(uriWithAuthority, uriWithAuthority.withEmptyAuthority) + } private def createTempDir(String prefix) { return Files.createTempDirectory(tempDirPath, prefix); diff --git a/org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/server/UriExtensionsTest.java b/org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/server/UriExtensionsTest.java index 89fbb4435..59ccd083e 100644 --- a/org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/server/UriExtensionsTest.java +++ b/org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/server/UriExtensionsTest.java @@ -260,6 +260,19 @@ public class UriExtensionsTest { Assert.assertTrue(uri.isPrefix()); } + @Test + public void test_withEmptyAuthority() { + final URI uriWithoutAuthority = URI.createURI("file:/path/to/resource/"); + Assert.assertNull(uriWithoutAuthority.authority()); + final URI uriWithEmptyAuthority = this._uriExtensions.withEmptyAuthority(uriWithoutAuthority); + Assert.assertNotSame(uriWithoutAuthority, uriWithEmptyAuthority); + Assert.assertEquals("Returned URI is expected to have an empty instead of null authority", "", uriWithEmptyAuthority.authority()); + final URI uriWithAuthority = URI.createURI("https://xtext.org/path/to/resource/"); + Assert.assertNotNull(uriWithAuthority.authority()); + Assert.assertEquals("xtext.org", uriWithAuthority.authority()); + Assert.assertSame(uriWithAuthority, this._uriExtensions.withEmptyAuthority(uriWithAuthority)); + } + private Path createTempDir(final String prefix) { try { return Files.createTempDirectory(this.getTempDirPath(), prefix); diff --git a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/DisposableRegistry.java b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/DisposableRegistry.java new file mode 100644 index 000000000..18dbf5f40 --- /dev/null +++ b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/DisposableRegistry.java @@ -0,0 +1,33 @@ +/** + * Copyright (c) 2016, 2019 TypeFox GmbH (http://www.typefox.io) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.xtext.util; + +import java.util.ArrayList; +import java.util.List; + +import com.google.inject.Singleton; + +/** + * A compound disposable that serves as a registry. Call this one at the end of + * the lifecycle of your injector. + */ +@Singleton +public class DisposableRegistry implements IDisposable { + private final List disposables = new ArrayList<>(); + + public void register(IDisposable disposable) { + disposables.add(disposable); + } + + @Override + public void dispose() { + for (IDisposable d : disposables) { + d.dispose(); + } + } +} diff --git a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/DisposableRegistry.xtend b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/DisposableRegistry.xtend deleted file mode 100644 index bb1beeca8..000000000 --- a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/DisposableRegistry.xtend +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ -package org.eclipse.xtext.util - -import com.google.inject.Singleton -import java.util.List - -/** - * A compound disposable that serves as a registry. Call this one at the end of the lifecycle of your injector. - */ -@Singleton -class DisposableRegistry implements IDisposable { - - val List disposables = newArrayList - - def void register(IDisposable disposable) { - disposables += disposable - } - - override dispose() { - for (d : disposables) { - d.dispose() - } - } - -} \ No newline at end of file diff --git a/org.eclipse.xtext.util/xtend-gen/org/eclipse/xtext/util/IDisposable.java b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/IDisposable.java similarity index 74% rename from org.eclipse.xtext.util/xtend-gen/org/eclipse/xtext/util/IDisposable.java rename to org.eclipse.xtext.util/src/org/eclipse/xtext/util/IDisposable.java index 40d470e62..d0689d08b 100644 --- a/org.eclipse.xtext.util/xtend-gen/org/eclipse/xtext/util/IDisposable.java +++ b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/IDisposable.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others. + * Copyright (c) 2016, 2019 TypeFox GmbH (http://www.typefox.io) and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,7 +10,6 @@ package org.eclipse.xtext.util; /** * Interface for things that can be disposed. */ -@SuppressWarnings("all") public interface IDisposable { - public abstract void dispose(); + void dispose(); } diff --git a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/IDisposable.xtend b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/IDisposable.xtend deleted file mode 100644 index 806a9e904..000000000 --- a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/IDisposable.xtend +++ /dev/null @@ -1,17 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ -package org.eclipse.xtext.util - -/** - * Interface for things that can be disposed. - */ -interface IDisposable { - - def void dispose() - -} \ No newline at end of file diff --git a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/IFileSystemScanner.java b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/IFileSystemScanner.java new file mode 100644 index 000000000..5d58204cf --- /dev/null +++ b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/IFileSystemScanner.java @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2016, 2019 TypeFox GmbH (http://www.typefox.io) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.xtext.util; + +import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; + +import org.eclipse.emf.common.util.URI; + +import com.google.inject.ImplementedBy; +import com.google.inject.Inject; + +/** + * @author Sven Efftinge - Initial contribution and API + * @since 2.11 + */ +@ImplementedBy(IFileSystemScanner.JavaIoFileSystemScanner.class) +public interface IFileSystemScanner { + public static class JavaIoFileSystemScanner implements IFileSystemScanner { + @Inject + private UriExtensions uriExtensions; + + @Override + public void scan(URI root, IAcceptor acceptor) { + File file = new File(root.toFileString()); + scanRec(file, acceptor); + } + + public void scanRec(File file, IAcceptor acceptor) { + // we need to convert the given file to a decoded emf file uri + // e.g. file:///Users/x/y/z + // or file:///C:/x/y/z + Path path = Paths.get(file.getAbsoluteFile().toURI()); + URI uri = uriExtensions.toEmfUri(path.toUri()); + acceptor.accept(uri); + if (file.isDirectory()) { + File[] files = file.listFiles(); + if (files != null) { + for (File f : files) { + scanRec(f, acceptor); + } + } + } + } + } + + void scan(URI root, IAcceptor acceptor); +} diff --git a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/IFileSystemScanner.xtend b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/IFileSystemScanner.xtend deleted file mode 100644 index 01cae2a0a..000000000 --- a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/IFileSystemScanner.xtend +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2017 TypeFox GmbH (http://www.typefox.io) and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ -package org.eclipse.xtext.util - -import com.google.inject.ImplementedBy -import com.google.inject.Inject -import java.io.File -import java.nio.file.Paths -import org.eclipse.emf.common.util.URI - -/** - * @author Sven Efftinge - Initial contribution and API - * @since 2.11 - */ -@ImplementedBy(JavaIoFileSystemScanner) -interface IFileSystemScanner { - - def void scan(URI root, IAcceptor acceptor) - - static class JavaIoFileSystemScanner implements IFileSystemScanner { - - @Inject extension UriExtensions - - override scan(URI root, IAcceptor acceptor) { - val file = new File(root.toFileString) - scanRec(file, acceptor) - } - - def void scanRec(File file, IAcceptor acceptor) { - // we need to convert the given file to a decoded emf file uri - // e.g. file:///Users/x/y/z - // or file:///C:/x/y/z - val path = Paths.get(file.absoluteFile.toURI) - val uri = path.toUri.toEmfUri - acceptor.accept(uri) - if (file.isDirectory) { - val files = file.listFiles - if (files !== null) { - for (f : files) { - scanRec(f, acceptor) - } - } - } - } - - } - -} diff --git a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/LineAndColumn.java b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/LineAndColumn.java new file mode 100644 index 000000000..0259cbf0f --- /dev/null +++ b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/LineAndColumn.java @@ -0,0 +1,87 @@ +/** + * Copyright (c) 2015, 2019 itemis AG (http://www.itemis.eu) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.xtext.util; + +import org.eclipse.xtext.xbase.lib.util.ToStringBuilder; + +/** + * A simple record with line and column information. The line number is + * one-based, e.g. the first line in the document has the line number 1. The + * column number is one based, too, e.g the first column in a line has the index + * 1. + * + * Line breaks are part of the line itself, e.g. the first line break in the + * document still has line number one. + * + * @author Sebastian Zarnekow - Initial contribution and API + * @since 2.9 + */ +public class LineAndColumn { + private final int line; + + private final int column; + + public static LineAndColumn from(int line, int column) { + LineAndColumn result = new LineAndColumn(line, column); + if (line <= 0 || column <= 0) { + throw new IllegalArgumentException(result.toString()); + } + return result; + } + + private LineAndColumn(int line, int column) { + this.line = line; + this.column = column; + } + + public int getLine() { + return line; + } + + public int getColumn() { + return column; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + this.line; + return prime * result + this.column; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + LineAndColumn other = (LineAndColumn) obj; + if (other.line != line) { + return false; + } + if (other.column != column) { + return false; + } + return true; + } + + @Override + public String toString() { + ToStringBuilder b = new ToStringBuilder(this); + b.add("line", line); + b.add("column", column); + return b.toString(); + } + +} diff --git a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/LineAndColumn.xtend b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/LineAndColumn.xtend deleted file mode 100644 index fba5e11be..000000000 --- a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/LineAndColumn.xtend +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ -package org.eclipse.xtext.util - -import org.eclipse.xtend.lib.annotations.Data - -/** - * A simple record with line and column information. - * The line number is one-based, e.g. the first line in the document - * has the line number 1. - * The column number is one based, too, e.g the first column in a line - * has the index 1. - * - * Line breaks are part of the line itself, e.g. the first line break - * in the document still has line number one. - * - * @author Sebastian Zarnekow - Initial contribution and API - * @since 2.9 - */ -@Data -class LineAndColumn { - int line - int column - - static def from(int line, int column) { - val result = new LineAndColumn(line, column) - if (line <= 0 || column <= 0) { - throw new IllegalArgumentException(result.toString) - } - return result - } - - private new(int line, int column) { - this.line = line - this.column = column - } -} \ No newline at end of file diff --git a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/UriExtensions.java b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/UriExtensions.java new file mode 100644 index 000000000..b5a52797d --- /dev/null +++ b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/UriExtensions.java @@ -0,0 +1,63 @@ +/** + * Copyright (c) 2017, 2019 itemis AG (http://www.itemis.eu) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.xtext.util; + +import java.net.URISyntaxException; + +import org.eclipse.emf.common.util.URI; + +/** + * @author Christian Dietrich - Initial contribution and API + * @since 2.14 + */ +public class UriExtensions { + /** + * Returns an URI with empty authority, if authority is absent (null) and has file scheme. + */ + public URI toUri(String stringUri) { + try { + java.net.URI netUri = new java.net.URI(stringUri); + return toEmfUri(netUri); + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } + } + + /** + * Returns an URI with empty authority, if authority is absent (null) and has file scheme. + */ + public URI toEmfUri(java.net.URI netUri) { + String decoded = toDecodedString(netUri); + URI uri = URI.createURI(decoded, false); + URI result = withEmptyAuthority(uri); + return result; + } + + /** + * Converts a java.net.URI to a decoded string + */ + public String toDecodedString(java.net.URI uri) { + String scheme = uri.getScheme(); + String part = uri.getSchemeSpecificPart(); + if (scheme == null) { + return part; + } + return scheme + ":" + part; + } + + /** + * Converts the file URIs with an absent (null) authority to one with an empty ("") authority + */ + public URI withEmptyAuthority(URI uri) { + if (uri.isFile() && uri.authority() == null) { + return URI.createHierarchicalURI(uri.scheme(), "", uri.device(), uri.segments(), uri.query(), + uri.fragment()); + } + return uri; + } +} diff --git a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/UriExtensions.xtend b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/UriExtensions.xtend deleted file mode 100644 index 567f53e37..000000000 --- a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/UriExtensions.xtend +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 itemis AG (http://www.itemis.eu) and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ -package org.eclipse.xtext.util - -import org.eclipse.emf.common.util.URI - -/** - * @author Christian Dietrich - Initial contribution and API - * @since 2.14 - */ -class UriExtensions { - - /** - * returns a URI with empty authority, if absent and has file scheme. - */ - def URI toUri(String stringUri) { - val netUri = new java.net.URI(stringUri) - return netUri.toEmfUri - } - - /** - * returns a URI with empty authority, if absent and has file scheme. - */ - def URI toEmfUri(java.net.URI netUri) { - val decoded = netUri.toDecodedString - val uri = URI.createURI(decoded, false); - val result = uri.withEmptyAuthority - result - } - - /** - * converts a java.net.URI to a decoded string - */ - def String toDecodedString(java.net.URI uri) { - val scheme = uri.getScheme(); - val part = uri.getSchemeSpecificPart(); - if (scheme === null) { - return part - } - return scheme + ':' + part; - } - - /** - * converts the file URIs with an absent authority to one with an empty - */ - def URI withEmptyAuthority(URI uri) { - if (uri.isFile && uri.authority === null) { - URI.createHierarchicalURI(uri.scheme, "", uri.device, uri.segments, uri.query, uri.fragment) - } else { - uri - } - } - -} \ No newline at end of file diff --git a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/XtextVersion.java b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/XtextVersion.java new file mode 100644 index 000000000..79741db02 --- /dev/null +++ b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/XtextVersion.java @@ -0,0 +1,144 @@ +/** + * Copyright (c) 2015, 2019 itemis AG (http://www.itemis.eu) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +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 "2.0.8"; + } + + /** + * @noreference + */ + public String getMweVersion() { + return "2.11.1"; + } + + public String getAntlrGeneratorVersion() { + return "2.1.1"; + } + + public String getXtendGradlePluginVersion() { + return getXtextGradlePluginVersion(); + } + + /** + * @noreference + */ + public String getXtendAndroidGradlePluginVersion() { + return getXtendGradlePluginVersion(); + } + + /** + * @return true if the current version ends with '-SNAPSHOT' + */ + public boolean isSnapshot() { + return version.endsWith("-SNAPSHOT"); + } + + /** + * @return true if the current version is not a snapshot and + * not a release
+ * Release builds must match a following pattern: N.N(.N)+
+ * (N is a digit)
+ * 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 = XtextVersion.Plugin.INSTANCE.getBaseURL(); + try (InputStream is = new URL (baseURL + "META-INF/MANIFEST.MF").openStream()) { + Manifest manifest = new Manifest(is); + String version = manifest.getMainAttributes().getValue("Maven-Version"); + if ("unspecified".equals(version)) { + 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; + } +} diff --git a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/XtextVersion.xtend b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/XtextVersion.xtend deleted file mode 100644 index a7ea48a7a..000000000 --- a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/XtextVersion.xtend +++ /dev/null @@ -1,118 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015, 2019 itemis AG (http://www.itemis.eu) and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ -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.xtend.lib.annotations.Data - -/** - * @since 2.9 - */ -@Data -class XtextVersion { - - String version - - static def getCurrent() { - new XtextVersion(readVersionFromManifest ?: 'unknown') - } - - def getXtextGradlePluginVersion() { - '2.0.8' - } - - /** - * @noreference - */ - def getMweVersion() { - '2.11.1' - } - - def getAntlrGeneratorVersion() { - '2.1.1' - } - - def getXtendGradlePluginVersion() { - xtextGradlePluginVersion - } - - /** - * @noreference - */ - def getXtendAndroidGradlePluginVersion() { - xtendGradlePluginVersion - } - - /** - * @return true if the current version ends with '-SNAPSHOT' - */ - def isSnapshot() { - version.endsWith("-SNAPSHOT") - } - - /** - * @return true if the current version is not a snapshot and not a release
- * Release builds must match a following pattern: N.N(.N)+
- * (N is a digit)
- * For example 2.9.2 is a release, 2.9.2.beta3 is stable. - */ - def isStable() { - return !isSnapshot && !version.matches("\\d+\\.\\d+(\\.\\d+)+") - } - - override toString() { - version - } - - private static def readVersionFromManifest() { - var InputStream is - try { - val url = new URL(Plugin.INSTANCE.baseURL + 'META-INF/MANIFEST.MF') - is = url.openStream() - val manifest = new Manifest(is) - var version = manifest.getMainAttributes().getValue('Maven-Version') - // in dev mode, Maven-Version has the static value 'unspecified' - // during a Gradle build that version gets replaced - if ('unspecified' == version) { - version = manifest.getMainAttributes().getValue('Bundle-Version') - if (version.endsWith(".qualifier")) { - return version.replace(".qualifier","-SNAPSHOT") - } else { - // strip off build qualifier - return version.substring(0, version.lastIndexOf('.')) - } - } - return version - } catch (Exception e) { - return null; - } finally { - if (is !== null) { - try { - is.close() - } catch (IOException e) { - } - } - } - } - - private static class Plugin extends EMFPlugin { - public static final Plugin INSTANCE = new Plugin - - private new() { - super(#[]); - } - - override getPluginResourceLocator() { - } - } - -} diff --git a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/internal/AlternateJdkLoader.java b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/internal/AlternateJdkLoader.java new file mode 100644 index 000000000..71f9c88ae --- /dev/null +++ b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/internal/AlternateJdkLoader.java @@ -0,0 +1,71 @@ +/** + * Copyright (c) 2014, 2019 itemis AG (http://www.itemis.eu) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.xtext.util.internal; + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +import com.google.common.collect.Lists; + +public class AlternateJdkLoader extends URLClassLoader { + private final ConcurrentMap locks = new ConcurrentHashMap<>(); + + public AlternateJdkLoader(Iterable files) { + super(mapToURLs(files)); + } + + private static URL[] mapToURLs (Iterable files) { + ArrayList fileList = Lists.newArrayList(files); + URL[] result = new URL[fileList.size()]; + for (int i = 0; i < fileList.size(); i++) { + try { + result[i] = fileList.get(i).toURI().toURL(); + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } + } + return result; + } + + @Override + protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { + synchronized (getClassLoadingLockJdk5(name)) { + Class c = findLoadedClass(name); + if (c == null) { + c = findClass(name); + } + if (resolve) { + resolveClass(c); + } + return c; + } + } + + @Override + public URL getResource(String name) { + return findResource(name); + } + + @Override + public Enumeration getResources(String name) throws IOException { + return findResources(name); + } + + private Object getClassLoadingLockJdk5(String className) { + Object newLock = new Object(); + Object existingLock = locks.putIfAbsent(className, newLock); + return existingLock != null ? existingLock : newLock; + } +} diff --git a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/internal/AlternateJdkLoader.xtend b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/internal/AlternateJdkLoader.xtend deleted file mode 100644 index b75e2e03a..000000000 --- a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/internal/AlternateJdkLoader.xtend +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 itemis AG (http://www.itemis.eu) and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ -package org.eclipse.xtext.util.internal - -import com.google.common.collect.Maps -import java.io.File -import java.io.IOException -import java.net.URLClassLoader -import java.util.concurrent.ConcurrentMap - -class AlternateJdkLoader extends URLClassLoader { - final ConcurrentMap locks = Maps.newConcurrentMap; - - new(Iterable files) { - super(files.map[toURI.toURL]) - } - - override protected loadClass(String name, boolean resolve) throws ClassNotFoundException { - synchronized (getClassLoadingLockJdk5(name)) { - val c = findLoadedClass(name) ?: findClass(name) - if (resolve) { - resolveClass(c) - } - c - } - } - - override getResource(String name) { - findResource(name) - } - - override getResources(String name) throws IOException { - findResources(name) - } - - private def Object getClassLoadingLockJdk5(String className) { - val newLock = new Object - val existingLock = locks.putIfAbsent(className, newLock) - return existingLock ?: newLock - } -} diff --git a/org.eclipse.xtext.util/xtend-gen/org/eclipse/xtext/util/DisposableRegistry.java b/org.eclipse.xtext.util/xtend-gen/org/eclipse/xtext/util/DisposableRegistry.java deleted file mode 100644 index fc8d4f4c1..000000000 --- a/org.eclipse.xtext.util/xtend-gen/org/eclipse/xtext/util/DisposableRegistry.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.xtext.util; - -import com.google.inject.Singleton; -import java.util.List; -import org.eclipse.xtext.util.IDisposable; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; - -/** - * A compound disposable that serves as a registry. Call this one at the end of the lifecycle of your injector. - */ -@Singleton -@SuppressWarnings("all") -public class DisposableRegistry implements IDisposable { - private final List disposables = CollectionLiterals.newArrayList(); - - public void register(final IDisposable disposable) { - this.disposables.add(disposable); - } - - @Override - public void dispose() { - for (final IDisposable d : this.disposables) { - d.dispose(); - } - } -} diff --git a/org.eclipse.xtext.util/xtend-gen/org/eclipse/xtext/util/IFileSystemScanner.java b/org.eclipse.xtext.util/xtend-gen/org/eclipse/xtext/util/IFileSystemScanner.java deleted file mode 100644 index 7e5730132..000000000 --- a/org.eclipse.xtext.util/xtend-gen/org/eclipse/xtext/util/IFileSystemScanner.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright (c) 2016, 2017 TypeFox GmbH (http://www.typefox.io) and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.xtext.util; - -import com.google.inject.ImplementedBy; -import com.google.inject.Inject; -import java.io.File; -import java.nio.file.Path; -import java.nio.file.Paths; -import org.eclipse.emf.common.util.URI; -import org.eclipse.xtext.util.IAcceptor; -import org.eclipse.xtext.util.UriExtensions; -import org.eclipse.xtext.xbase.lib.Extension; - -/** - * @author Sven Efftinge - Initial contribution and API - * @since 2.11 - */ -@ImplementedBy(IFileSystemScanner.JavaIoFileSystemScanner.class) -@SuppressWarnings("all") -public interface IFileSystemScanner { - public static class JavaIoFileSystemScanner implements IFileSystemScanner { - @Inject - @Extension - private UriExtensions _uriExtensions; - - @Override - public void scan(final URI root, final IAcceptor acceptor) { - String _fileString = root.toFileString(); - final File file = new File(_fileString); - this.scanRec(file, acceptor); - } - - public void scanRec(final File file, final IAcceptor acceptor) { - final Path path = Paths.get(file.getAbsoluteFile().toURI()); - final URI uri = this._uriExtensions.toEmfUri(path.toUri()); - acceptor.accept(uri); - boolean _isDirectory = file.isDirectory(); - if (_isDirectory) { - final File[] files = file.listFiles(); - if ((files != null)) { - for (final File f : files) { - this.scanRec(f, acceptor); - } - } - } - } - } - - public abstract void scan(final URI root, final IAcceptor acceptor); -} diff --git a/org.eclipse.xtext.util/xtend-gen/org/eclipse/xtext/util/LineAndColumn.java b/org.eclipse.xtext.util/xtend-gen/org/eclipse/xtext/util/LineAndColumn.java deleted file mode 100644 index b48082ce2..000000000 --- a/org.eclipse.xtext.util/xtend-gen/org/eclipse/xtext/util/LineAndColumn.java +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.xtext.util; - -import org.eclipse.xtend.lib.annotations.Data; -import org.eclipse.xtext.xbase.lib.Pure; -import org.eclipse.xtext.xbase.lib.util.ToStringBuilder; - -/** - * A simple record with line and column information. - * The line number is one-based, e.g. the first line in the document - * has the line number 1. - * The column number is one based, too, e.g the first column in a line - * has the index 1. - * - * Line breaks are part of the line itself, e.g. the first line break - * in the document still has line number one. - * - * @author Sebastian Zarnekow - Initial contribution and API - * @since 2.9 - */ -@Data -@SuppressWarnings("all") -public class LineAndColumn { - private final int line; - - private final int column; - - public static LineAndColumn from(final int line, final int column) { - final LineAndColumn result = new LineAndColumn(line, column); - if (((line <= 0) || (column <= 0))) { - String _string = result.toString(); - throw new IllegalArgumentException(_string); - } - return result; - } - - private LineAndColumn(final int line, final int column) { - this.line = line; - this.column = column; - } - - @Override - @Pure - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + this.line; - return prime * result + this.column; - } - - @Override - @Pure - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - LineAndColumn other = (LineAndColumn) obj; - if (other.line != this.line) - return false; - if (other.column != this.column) - return false; - return true; - } - - @Override - @Pure - public String toString() { - ToStringBuilder b = new ToStringBuilder(this); - b.add("line", this.line); - b.add("column", this.column); - return b.toString(); - } - - @Pure - public int getLine() { - return this.line; - } - - @Pure - public int getColumn() { - return this.column; - } -} diff --git a/org.eclipse.xtext.util/xtend-gen/org/eclipse/xtext/util/UriExtensions.java b/org.eclipse.xtext.util/xtend-gen/org/eclipse/xtext/util/UriExtensions.java deleted file mode 100644 index 966694913..000000000 --- a/org.eclipse.xtext.util/xtend-gen/org/eclipse/xtext/util/UriExtensions.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Copyright (c) 2017 itemis AG (http://www.itemis.eu) and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.xtext.util; - -import org.eclipse.emf.common.util.URI; -import org.eclipse.xtext.xbase.lib.Exceptions; - -/** - * @author Christian Dietrich - Initial contribution and API - * @since 2.14 - */ -@SuppressWarnings("all") -public class UriExtensions { - /** - * returns a URI with empty authority, if absent and has file scheme. - */ - public URI toUri(final String stringUri) { - try { - final java.net.URI netUri = new java.net.URI(stringUri); - return this.toEmfUri(netUri); - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } - } - - /** - * returns a URI with empty authority, if absent and has file scheme. - */ - public URI toEmfUri(final java.net.URI netUri) { - URI _xblockexpression = null; - { - final String decoded = this.toDecodedString(netUri); - final URI uri = URI.createURI(decoded, false); - final URI result = this.withEmptyAuthority(uri); - _xblockexpression = result; - } - return _xblockexpression; - } - - /** - * converts a java.net.URI to a decoded string - */ - public String toDecodedString(final java.net.URI uri) { - final String scheme = uri.getScheme(); - final String part = uri.getSchemeSpecificPart(); - if ((scheme == null)) { - return part; - } - return ((scheme + ":") + part); - } - - /** - * converts the file URIs with an absent authority to one with an empty - */ - public URI withEmptyAuthority(final URI uri) { - URI _xifexpression = null; - if ((uri.isFile() && (uri.authority() == null))) { - _xifexpression = URI.createHierarchicalURI(uri.scheme(), "", uri.device(), uri.segments(), uri.query(), uri.fragment()); - } else { - _xifexpression = uri; - } - return _xifexpression; - } -} diff --git a/org.eclipse.xtext.util/xtend-gen/org/eclipse/xtext/util/XtextVersion.java b/org.eclipse.xtext.util/xtend-gen/org/eclipse/xtext/util/XtextVersion.java deleted file mode 100644 index 4009fe689..000000000 --- a/org.eclipse.xtext.util/xtend-gen/org/eclipse/xtext/util/XtextVersion.java +++ /dev/null @@ -1,174 +0,0 @@ -/** - * Copyright (c) 2015, 2019 itemis AG (http://www.itemis.eu) and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.xtext.util; - -import com.google.common.base.Objects; -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; -import org.eclipse.xtend.lib.annotations.Data; -import org.eclipse.xtext.xbase.lib.Exceptions; -import org.eclipse.xtext.xbase.lib.Pure; - -/** - * @since 2.9 - */ -@Data -@SuppressWarnings("all") -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 static XtextVersion getCurrent() { - String _elvis = null; - String _readVersionFromManifest = XtextVersion.readVersionFromManifest(); - if (_readVersionFromManifest != null) { - _elvis = _readVersionFromManifest; - } else { - _elvis = "unknown"; - } - return new XtextVersion(_elvis); - } - - public String getXtextGradlePluginVersion() { - return "2.0.8"; - } - - /** - * @noreference - */ - public String getMweVersion() { - return "2.11.1"; - } - - public String getAntlrGeneratorVersion() { - return "2.1.1"; - } - - public String getXtendGradlePluginVersion() { - return this.getXtextGradlePluginVersion(); - } - - /** - * @noreference - */ - public String getXtendAndroidGradlePluginVersion() { - return this.getXtendGradlePluginVersion(); - } - - /** - * @return true if the current version ends with '-SNAPSHOT' - */ - public boolean isSnapshot() { - return this.version.endsWith("-SNAPSHOT"); - } - - /** - * @return true if the current version is not a snapshot and not a release
- * Release builds must match a following pattern: N.N(.N)+
- * (N is a digit)
- * For example 2.9.2 is a release, 2.9.2.beta3 is stable. - */ - public boolean isStable() { - return ((!this.isSnapshot()) && (!this.version.matches("\\d+\\.\\d+(\\.\\d+)+"))); - } - - @Override - public String toString() { - return this.version; - } - - private static String readVersionFromManifest() { - InputStream is = null; - try { - URL _baseURL = XtextVersion.Plugin.INSTANCE.getBaseURL(); - String _plus = (_baseURL + "META-INF/MANIFEST.MF"); - final URL url = new URL(_plus); - is = url.openStream(); - final Manifest manifest = new Manifest(is); - String version = manifest.getMainAttributes().getValue("Maven-Version"); - boolean _equals = Objects.equal("unspecified", version); - if (_equals) { - version = manifest.getMainAttributes().getValue("Bundle-Version"); - boolean _endsWith = version.endsWith(".qualifier"); - if (_endsWith) { - return version.replace(".qualifier", "-SNAPSHOT"); - } else { - return version.substring(0, version.lastIndexOf(".")); - } - } - return version; - } catch (final Throwable _t) { - if (_t instanceof Exception) { - return null; - } else { - throw Exceptions.sneakyThrow(_t); - } - } finally { - if ((is != null)) { - try { - is.close(); - } catch (final Throwable _t_1) { - if (_t_1 instanceof IOException) { - } else { - throw Exceptions.sneakyThrow(_t_1); - } - } - } - } - } - - public XtextVersion(final String version) { - super(); - this.version = version; - } - - @Override - @Pure - public int hashCode() { - return 31 * 1 + ((this.version== null) ? 0 : this.version.hashCode()); - } - - @Override - @Pure - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - XtextVersion other = (XtextVersion) obj; - if (this.version == null) { - if (other.version != null) - return false; - } else if (!this.version.equals(other.version)) - return false; - return true; - } - - @Pure - public String getVersion() { - return this.version; - } -} diff --git a/org.eclipse.xtext.util/xtend-gen/org/eclipse/xtext/util/internal/AlternateJdkLoader.java b/org.eclipse.xtext.util/xtend-gen/org/eclipse/xtext/util/internal/AlternateJdkLoader.java deleted file mode 100644 index 85f7148e0..000000000 --- a/org.eclipse.xtext.util/xtend-gen/org/eclipse/xtext/util/internal/AlternateJdkLoader.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Copyright (c) 2014 itemis AG (http://www.itemis.eu) and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.xtext.util.internal; - -import com.google.common.collect.Maps; -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.Enumeration; -import java.util.concurrent.ConcurrentMap; -import org.eclipse.xtext.xbase.lib.Conversions; -import org.eclipse.xtext.xbase.lib.Exceptions; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.IterableExtensions; - -@SuppressWarnings("all") -public class AlternateJdkLoader extends URLClassLoader { - private final ConcurrentMap locks = Maps.newConcurrentMap(); - - public AlternateJdkLoader(final Iterable files) { - super(((URL[])Conversions.unwrapArray(IterableExtensions.map(files, ((Function1) (File it) -> { - try { - return it.toURI().toURL(); - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } - })), URL.class))); - } - - @Override - protected Class loadClass(final String name, final boolean resolve) throws ClassNotFoundException { - Class _xsynchronizedexpression = null; - synchronized (this.getClassLoadingLockJdk5(name)) { - Class _xblockexpression = null; - { - Class _elvis = null; - Class _findLoadedClass = this.findLoadedClass(name); - if (_findLoadedClass != null) { - _elvis = _findLoadedClass; - } else { - Class _findClass = this.findClass(name); - _elvis = _findClass; - } - final Class c = _elvis; - if (resolve) { - this.resolveClass(c); - } - _xblockexpression = c; - } - _xsynchronizedexpression = _xblockexpression; - } - return _xsynchronizedexpression; - } - - @Override - public URL getResource(final String name) { - return this.findResource(name); - } - - @Override - public Enumeration getResources(final String name) throws IOException { - return this.findResources(name); - } - - private Object getClassLoadingLockJdk5(final String className) { - final Object newLock = new Object(); - final Object existingLock = this.locks.putIfAbsent(className, newLock); - Object _elvis = null; - if (existingLock != null) { - _elvis = existingLock; - } else { - _elvis = newLock; - } - return _elvis; - } -}