mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-15 16:28:56 +00:00
Merge branch 'master' of git@github.com:eclipse/xtext-core
This commit is contained in:
commit
13ba597bc4
16 changed files with 192 additions and 81 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,3 +3,4 @@ bin/
|
|||
build/
|
||||
*._trace
|
||||
*.xtendbin
|
||||
org.eclipse.buildship.core.prefs
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
|
||||
connection.project.dir=
|
||||
derived.resources=.gradle,build
|
||||
eclipse.preferences.version=1
|
||||
project.path=\:
|
|
@ -1,7 +0,0 @@
|
|||
build.commands=org.eclipse.jdt.core.javabuilder,org.eclipse.xtext.ui.shared.xtextBuilder
|
||||
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
|
||||
connection.project.dir=..
|
||||
derived.resources=.gradle,build
|
||||
eclipse.preferences.version=1
|
||||
natures=org.eclipse.jdt.core.javanature,org.eclipse.xtext.ui.shared.xtextNature
|
||||
project.path=\:org.eclipse.xtext.ide.tests
|
|
@ -1,7 +0,0 @@
|
|||
build.commands=org.eclipse.jdt.core.javabuilder,org.eclipse.xtext.ui.shared.xtextBuilder
|
||||
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
|
||||
connection.project.dir=..
|
||||
derived.resources=.gradle,build
|
||||
eclipse.preferences.version=1
|
||||
natures=org.eclipse.jdt.core.javanature,org.eclipse.xtext.ui.shared.xtextNature
|
||||
project.path=\:org.eclipse.xtext.ide
|
|
@ -1,7 +0,0 @@
|
|||
build.commands=org.eclipse.jdt.core.javabuilder,org.eclipse.xtext.ui.shared.xtextBuilder
|
||||
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
|
||||
connection.project.dir=..
|
||||
derived.resources=.gradle,build
|
||||
eclipse.preferences.version=1
|
||||
natures=org.eclipse.jdt.core.javanature,org.eclipse.xtext.ui.shared.xtextNature
|
||||
project.path=\:org.eclipse.xtext.testing
|
|
@ -1,7 +0,0 @@
|
|||
build.commands=org.eclipse.jdt.core.javabuilder,org.eclipse.xtext.ui.shared.xtextBuilder
|
||||
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
|
||||
connection.project.dir=..
|
||||
derived.resources=.gradle,build
|
||||
eclipse.preferences.version=1
|
||||
natures=org.eclipse.jdt.core.javanature,org.eclipse.xtext.ui.shared.xtextNature
|
||||
project.path=\:org.eclipse.xtext.testlanguages.ide
|
|
@ -1,7 +0,0 @@
|
|||
build.commands=org.eclipse.jdt.core.javabuilder,org.eclipse.xtext.ui.shared.xtextBuilder
|
||||
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
|
||||
connection.project.dir=..
|
||||
derived.resources=.gradle,build
|
||||
eclipse.preferences.version=1
|
||||
natures=org.eclipse.jdt.core.javanature,org.eclipse.xtext.ui.shared.xtextNature
|
||||
project.path=\:org.eclipse.xtext.testlanguages
|
|
@ -1,7 +0,0 @@
|
|||
build.commands=org.eclipse.jdt.core.javabuilder,org.eclipse.xtext.ui.shared.xtextBuilder
|
||||
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
|
||||
connection.project.dir=..
|
||||
derived.resources=.gradle,build
|
||||
eclipse.preferences.version=1
|
||||
natures=org.eclipse.jdt.core.javanature,org.eclipse.xtext.ui.shared.xtextNature
|
||||
project.path=\:org.eclipse.xtext.tests
|
|
@ -0,0 +1,73 @@
|
|||
/*******************************************************************************
|
||||
* 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.filesystem
|
||||
|
||||
import com.google.common.base.StandardSystemProperty
|
||||
import com.google.inject.Inject
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
import java.util.UUID
|
||||
import org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl
|
||||
import org.eclipse.xtext.generator.IFileSystemAccess
|
||||
import org.eclipse.xtext.generator.IOutputConfigurationProvider
|
||||
import org.eclipse.xtext.generator.URIBasedFileSystemAccess
|
||||
import org.eclipse.xtext.testing.InjectWith
|
||||
import org.eclipse.xtext.testing.XtextRunner
|
||||
import org.eclipse.xtext.tests.XtextInjectorProvider
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import static org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* @author akos.kitta - Initial contribution and API
|
||||
*
|
||||
* @see https://github.com/eclipse/xtext-core/issues/180
|
||||
*/
|
||||
@RunWith(XtextRunner)
|
||||
@InjectWith(XtextInjectorProvider)
|
||||
class URIBasedFileSystemAccessTest {
|
||||
|
||||
static val MISSING_RESOURCE_NAME = 'someMissingResource';
|
||||
static val EXISTING_RESOURCE_NAME = 'someExistingResource';
|
||||
|
||||
@Inject
|
||||
URIBasedFileSystemAccess fsa;
|
||||
|
||||
@Inject
|
||||
IOutputConfigurationProvider configProvider;
|
||||
|
||||
ExtensibleURIConverterImpl uriConverter = new ExtensibleURIConverterImpl();
|
||||
|
||||
@Before
|
||||
def void before() {
|
||||
val tmpPath = Paths.get(StandardSystemProperty.JAVA_IO_TMPDIR.value);
|
||||
val output = Files.createTempDirectory(tmpPath, '''tempFolder_«UUID.randomUUID»''');
|
||||
val resource = Files.createFile(output.resolve(EXISTING_RESOURCE_NAME));
|
||||
|
||||
resource.toFile.deleteOnExit;
|
||||
output.toFile.deleteOnExit;
|
||||
|
||||
val config = configProvider.outputConfigurations.head;
|
||||
config.outputDirectory = output.toString;
|
||||
fsa.outputConfigurations = #{IFileSystemAccess.DEFAULT_OUTPUT -> config};
|
||||
fsa.converter = uriConverter;
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testFalseOnAbsent() {
|
||||
assertFalse(fsa.isFile(MISSING_RESOURCE_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testTrueOnPresent() {
|
||||
assertTrue(fsa.isFile(EXISTING_RESOURCE_NAME));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
/**
|
||||
* 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.filesystem;
|
||||
|
||||
import com.google.common.base.StandardSystemProperty;
|
||||
import com.google.inject.Inject;
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl;
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.generator.IFileSystemAccess;
|
||||
import org.eclipse.xtext.generator.IOutputConfigurationProvider;
|
||||
import org.eclipse.xtext.generator.OutputConfiguration;
|
||||
import org.eclipse.xtext.generator.URIBasedFileSystemAccess;
|
||||
import org.eclipse.xtext.testing.InjectWith;
|
||||
import org.eclipse.xtext.testing.XtextRunner;
|
||||
import org.eclipse.xtext.tests.XtextInjectorProvider;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.Exceptions;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.Pair;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
/**
|
||||
* @author akos.kitta - Initial contribution and API
|
||||
*
|
||||
* @see https://github.com/eclipse/xtext-core/issues/180
|
||||
*/
|
||||
@RunWith(XtextRunner.class)
|
||||
@InjectWith(XtextInjectorProvider.class)
|
||||
@SuppressWarnings("all")
|
||||
public class URIBasedFileSystemAccessTest {
|
||||
private final static String MISSING_RESOURCE_NAME = "someMissingResource";
|
||||
|
||||
private final static String EXISTING_RESOURCE_NAME = "someExistingResource";
|
||||
|
||||
@Inject
|
||||
private URIBasedFileSystemAccess fsa;
|
||||
|
||||
@Inject
|
||||
private IOutputConfigurationProvider configProvider;
|
||||
|
||||
private ExtensibleURIConverterImpl uriConverter = new ExtensibleURIConverterImpl();
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
try {
|
||||
String _value = StandardSystemProperty.JAVA_IO_TMPDIR.value();
|
||||
final Path tmpPath = Paths.get(_value);
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("tempFolder_");
|
||||
UUID _randomUUID = UUID.randomUUID();
|
||||
_builder.append(_randomUUID, "");
|
||||
final Path output = Files.createTempDirectory(tmpPath, _builder.toString());
|
||||
Path _resolve = output.resolve(URIBasedFileSystemAccessTest.EXISTING_RESOURCE_NAME);
|
||||
final Path resource = Files.createFile(_resolve);
|
||||
File _file = resource.toFile();
|
||||
_file.deleteOnExit();
|
||||
File _file_1 = output.toFile();
|
||||
_file_1.deleteOnExit();
|
||||
Set<OutputConfiguration> _outputConfigurations = this.configProvider.getOutputConfigurations();
|
||||
final OutputConfiguration config = IterableExtensions.<OutputConfiguration>head(_outputConfigurations);
|
||||
String _string = output.toString();
|
||||
config.setOutputDirectory(_string);
|
||||
Pair<String, OutputConfiguration> _mappedTo = Pair.<String, OutputConfiguration>of(IFileSystemAccess.DEFAULT_OUTPUT, config);
|
||||
this.fsa.setOutputConfigurations(Collections.<String, OutputConfiguration>unmodifiableMap(CollectionLiterals.<String, OutputConfiguration>newHashMap(_mappedTo)));
|
||||
this.fsa.setConverter(this.uriConverter);
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFalseOnAbsent() {
|
||||
boolean _isFile = this.fsa.isFile(URIBasedFileSystemAccessTest.MISSING_RESOURCE_NAME);
|
||||
Assert.assertFalse(_isFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTrueOnPresent() {
|
||||
boolean _isFile = this.fsa.isFile(URIBasedFileSystemAccessTest.EXISTING_RESOURCE_NAME);
|
||||
Assert.assertTrue(_isFile);
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
build.commands=org.eclipse.jdt.core.javabuilder,org.eclipse.xtext.ui.shared.xtextBuilder
|
||||
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
|
||||
connection.project.dir=..
|
||||
derived.resources=.gradle,build
|
||||
eclipse.preferences.version=1
|
||||
natures=org.eclipse.jdt.core.javanature,org.eclipse.xtext.ui.shared.xtextNature
|
||||
project.path=\:org.eclipse.xtext.util
|
|
@ -1,7 +0,0 @@
|
|||
build.commands=org.eclipse.jdt.core.javabuilder,org.eclipse.xtext.ui.shared.xtextBuilder
|
||||
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
|
||||
connection.project.dir=..
|
||||
derived.resources=.gradle,build
|
||||
eclipse.preferences.version=1
|
||||
natures=org.eclipse.jdt.core.javanature,org.eclipse.xtext.ui.shared.xtextNature
|
||||
project.path=\:org.eclipse.xtext.xtext.generator
|
|
@ -1,7 +0,0 @@
|
|||
build.commands=org.eclipse.jdt.core.javabuilder,org.eclipse.xtext.ui.shared.xtextBuilder
|
||||
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
|
||||
connection.project.dir=..
|
||||
derived.resources=.gradle,build
|
||||
eclipse.preferences.version=1
|
||||
natures=org.eclipse.jdt.core.javanature,org.eclipse.xtext.ui.shared.xtextNature
|
||||
project.path=\:org.eclipse.xtext.xtext.wizard
|
|
@ -1,7 +0,0 @@
|
|||
build.commands=org.eclipse.jdt.core.javabuilder,org.eclipse.xtext.ui.shared.xtextBuilder
|
||||
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
|
||||
connection.project.dir=..
|
||||
derived.resources=.gradle,build
|
||||
eclipse.preferences.version=1
|
||||
natures=org.eclipse.jdt.core.javanature,org.eclipse.xtext.ui.shared.xtextNature
|
||||
project.path=\:org.eclipse.xtext
|
|
@ -23,6 +23,7 @@ import org.eclipse.xtext.parser.IEncodingProvider
|
|||
import org.eclipse.xtext.util.RuntimeIOException
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
import java.io.FileNotFoundException
|
||||
|
||||
/**
|
||||
* A file system access implementation that is based on EMF URIs and URIConverter
|
||||
|
@ -110,9 +111,13 @@ class URIBasedFileSystemAccess extends AbstractFileSystemAccess2 {
|
|||
}
|
||||
|
||||
override readBinaryFile(String fileName, String outputCfgName) throws RuntimeIOException {
|
||||
val uri = getURI(fileName, outputCfgName)
|
||||
val input = converter.createInputStream(uri)
|
||||
return beforeRead.beforeRead(uri, input)
|
||||
try {
|
||||
val uri = getURI(fileName, outputCfgName)
|
||||
val input = converter.createInputStream(uri)
|
||||
return beforeRead.beforeRead(uri, input)
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
override readTextFile(String fileName, String outputCfgName) throws RuntimeIOException {
|
||||
|
|
|
@ -12,6 +12,7 @@ import com.google.common.io.CharStreams;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
|
@ -164,9 +165,18 @@ public class URIBasedFileSystemAccess extends AbstractFileSystemAccess2 {
|
|||
@Override
|
||||
public InputStream readBinaryFile(final String fileName, final String outputCfgName) throws RuntimeIOException {
|
||||
try {
|
||||
final URI uri = this.getURI(fileName, outputCfgName);
|
||||
final InputStream input = this.converter.createInputStream(uri);
|
||||
return this.beforeRead.beforeRead(uri, input);
|
||||
try {
|
||||
final URI uri = this.getURI(fileName, outputCfgName);
|
||||
final InputStream input = this.converter.createInputStream(uri);
|
||||
return this.beforeRead.beforeRead(uri, input);
|
||||
} catch (final Throwable _t) {
|
||||
if (_t instanceof FileNotFoundException) {
|
||||
final FileNotFoundException e = (FileNotFoundException)_t;
|
||||
throw new RuntimeIOException(e);
|
||||
} else {
|
||||
throw Exceptions.sneakyThrow(_t);
|
||||
}
|
||||
}
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue