mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-17 01:08:56 +00:00
[xbase test] Made CompilationTestHelper work on real file system (temp folder). Added test for active annotation that reads and writes through the FileSystemSupport.
Change-Id: I62ebdf449ce193b036545d1ee87c86d3ae65582b
This commit is contained in:
parent
aa006f1d58
commit
36b636af9c
3 changed files with 84 additions and 3 deletions
|
@ -5,10 +5,11 @@
|
|||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.junit4.internal;
|
||||
package org.eclipse.xtext.junit4;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.junit.rules.ExternalResource;
|
||||
|
||||
|
@ -39,6 +40,10 @@ import com.google.inject.Singleton;
|
|||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @noextend This class is not intended to be subclassed by clients.
|
||||
*
|
||||
* @since 2.7
|
||||
*/
|
||||
@Singleton
|
||||
public class TemporaryFolder extends ExternalResource {
|
||||
|
@ -113,12 +118,29 @@ public class TemporaryFolder extends ExternalResource {
|
|||
*/
|
||||
public File newFolder() throws IOException {
|
||||
try {
|
||||
return createTempDir(getRoot());
|
||||
File tempDir = createTempDir(getRoot());
|
||||
addSourceInfo(tempDir);
|
||||
return tempDir;
|
||||
} catch (IllegalStateException e) {
|
||||
throw new IOException(e.getMessage()); // IOException(e) not available prior to 1.6
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* generate '.createdBy' file with a stack trace so tests that leak temp folders can be identified later.
|
||||
*/
|
||||
protected void addSourceInfo(File tempDir) throws IOException {
|
||||
PrintStream printStream = new PrintStream(new File(tempDir, ".createdBy"));
|
||||
try {
|
||||
printStream.append("This temp dir has been created from the stack below. If you want to make sure the temp folders are cleaned up after a test executed, you should add the following to your test class: \n\n");
|
||||
printStream.append(" @Rule @Inject public TemporaryFolder temporaryFolder \n\n");
|
||||
new Exception().printStackTrace(printStream);
|
||||
} finally {
|
||||
printStream.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Copied from Guava 10.x but added a base dir argument
|
||||
*/
|
|
@ -0,0 +1,59 @@
|
|||
/*******************************************************************************
|
||||
* 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.generator
|
||||
|
||||
import java.io.InputStream
|
||||
import org.eclipse.xtext.util.RuntimeIOException
|
||||
import org.eclipse.xtend.lib.macro.file.MutableFileSystemSupport
|
||||
import org.eclipse.xtend.lib.annotations.Accessors
|
||||
import org.eclipse.xtend.lib.macro.file.Path
|
||||
import com.google.inject.Inject
|
||||
import org.eclipse.emf.common.util.URI
|
||||
|
||||
/**
|
||||
*
|
||||
* An adapter between {org.eclipse.xtend.lib.macro.file.MutableFileSystemSupport} and {org.eclipse.xtext.generator.IFileSystemAccess}
|
||||
*
|
||||
* @author Sven Efftinge - Initial contribution and API
|
||||
* @since 2.7
|
||||
*/
|
||||
class FileSystemSupportBasedFileSystemAccess extends AbstractFileSystemAccess2 implements IFileSystemAccess, IFileSystemAccessExtension, IFileSystemAccessExtension2, IFileSystemAccessExtension3 {
|
||||
|
||||
@Inject @Accessors(PUBLIC_SETTER) extension MutableFileSystemSupport fileSystemSupport
|
||||
@Accessors(PUBLIC_SETTER) String projectName;
|
||||
|
||||
protected def getPath(String fileName, String outputConfigurationName) {
|
||||
val path = pathes.get(outputConfigurationName)
|
||||
return new Path("/"+projectName+"/"+path+"/"+fileName)
|
||||
}
|
||||
|
||||
override generateFile(String fileName, String outputConfigurationName, CharSequence contents) {
|
||||
val path = getPath(fileName, outputConfigurationName)
|
||||
path.contents = contents
|
||||
}
|
||||
|
||||
override getURI(String fileName, String outputConfiguration) {
|
||||
return URI.createFileURI(getPath(fileName, outputConfiguration).toURI.toURL.file)
|
||||
}
|
||||
|
||||
override generateFile(String fileName, String outputConfigurationName, InputStream content) throws RuntimeIOException {
|
||||
val path = getPath(fileName, outputConfigurationName)
|
||||
path.contentsAsStream = content
|
||||
}
|
||||
|
||||
override readBinaryFile(String fileName, String outputConfigurationName) throws RuntimeIOException {
|
||||
val path = getPath(fileName, outputConfigurationName)
|
||||
return path.contentsAsStream
|
||||
}
|
||||
|
||||
override readTextFile(String fileName, String outputConfigurationName) throws RuntimeIOException {
|
||||
val path = getPath(fileName, outputConfigurationName)
|
||||
return path.contents
|
||||
}
|
||||
|
||||
}
|
|
@ -23,7 +23,7 @@ import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
|
|||
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
|
||||
import org.eclipse.emf.ecore.util.EcoreUtil;
|
||||
import org.eclipse.emf.mwe.utils.StandaloneSetup;
|
||||
import org.eclipse.xtext.junit4.internal.TemporaryFolder;
|
||||
import org.eclipse.xtext.junit4.TemporaryFolder;
|
||||
import org.eclipse.xtext.util.concurrent.AbstractReadWriteAcces;
|
||||
import org.eclipse.xtext.util.concurrent.IReadAccess;
|
||||
import org.eclipse.xtext.util.concurrent.IUnitOfWork;
|
||||
|
|
Loading…
Reference in a new issue