org.eclipse.xtext.util.RuntimeIOException Java Examples

The following examples show how to use org.eclipse.xtext.util.RuntimeIOException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EclipseResourceFileSystemAccess2Test.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testMarkNotSupported() throws Exception {
	fsa.generateFile("tmp/bar", new StringInputStream("you should never see this"));
	InputStream input = new StringInputStream("foo") {
		@Override
		public boolean markSupported() {
			return false;
		}
		@Override
		public synchronized void reset() {
			throw new RuntimeIOException("mark/reset not supported");
		}
	};
	fsa.generateFile("tmp/bar", input);
	IFolder dir = project.getFolder("src-gen/tmp");
	assertTrue(dir.exists());
	IFile file = dir.getFile("bar");
	assertTrue(file.exists());
	assertEquals("foo", fsa.readTextFile("tmp/bar"));
}
 
Example #2
Source File: ResourceStorageFacade.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public ResourceStorageLoadable getOrCreateResourceStorageLoadable(StorageAwareResource resource) {
	try {
		ResourceSet resourceSet = resource.getResourceSet();
		ResourceStorageProviderAdapter stateProvider = getResourceStorageProviderAdapter(resourceSet);
		if (stateProvider != null) {
			ResourceStorageLoadable loadable = stateProvider.getResourceStorageLoadable(resource);
			if (loadable != null)
				return loadable;
		}
		if (resourceSet.getURIConverter().exists(getBinaryStorageURI(resource.getURI()),
				Collections.emptyMap())) {
			return createResourceStorageLoadable(resourceSet.getURIConverter()
					.createInputStream(getBinaryStorageURI(resource.getURI())));
		}
		return createResourceStorageLoadable(
				getFileSystemAccess(resource).readBinaryFile(computeOutputPath(resource)));
	} catch (IOException e) {
		throw new RuntimeIOException(e);
	}
}
 
Example #3
Source File: FileSystemScanner.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void scan(URI root, IAcceptor<URI> acceptor) {
	File rootFile = URIUtils.toFile(root);
	if (rootFile.isDirectory()) {
		try {
			Path rootPath = rootFile.toPath();
			if (acceptor instanceof FileVisitingAcceptor) {
				Files.walkFileTree(rootPath, (FileVisitingAcceptor) acceptor);
			} else {
				Files.walk(rootPath).forEach(p -> {
					File file = p.toFile();
					if (!file.isDirectory()) {
						acceptor.accept(new FileURI(p.toFile()).toURI());
					}
				});
			}
		} catch (IOException e) {
			throw new RuntimeIOException(e);
		}
	}
}
 
Example #4
Source File: EclipseResourceFileSystemAccess2.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void generateFile(String fileName, String outputName, CharSequence contents) {
	if (monitor.isCanceled())
		throw new OperationCanceledException();
	OutputConfiguration outputConfig = getOutputConfig(outputName);

	if (!ensureOutputConfigurationDirectoryExists(outputConfig))
		return;

	IFile file = getFile(fileName, outputName);
	if (file == null)
		return;
	IFile traceFile = getTraceFile(file);
	try {
		String encoding = getEncoding(file);
		CharSequence postProcessedContent = postProcess(fileName, outputName, contents, encoding);
		String contentsAsString = postProcessedContent.toString();
		StringInputStream newContent = getInputStream(contentsAsString, encoding);
		generateFile(file, newContent, traceFile, postProcessedContent, outputConfig);
	} catch (CoreException e) {
		throw new RuntimeIOException(e);
	}
}
 
Example #5
Source File: EclipseResourceFileSystemAccess2.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.4
 */
protected boolean ensureOutputConfigurationDirectoryExists(OutputConfiguration outputConfig) {
	IContainer container = getContainer(outputConfig);
	if (container == null) {
		return false;
	}
	if (!container.exists()) {
		if (outputConfig.isCreateOutputDirectory()) {
			try {
				createContainer(container);
				return true;
			} catch (CoreException e) {
				throw new RuntimeIOException(e);
			}
		} else {
			return false;
		}
	}
	return true;
}
 
Example #6
Source File: JavaIoFileSystemAccess.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void generateFile(String fileName, String outputConfigName, CharSequence contents) throws RuntimeIOException {
	File file = getFile(fileName, outputConfigName);
	if (!getOutputConfig(outputConfigName).isOverrideExistingResources() && file.exists()) {
		return;
	}
	try {
		createFolder(file.getParentFile());
		String encoding = getEncoding(getURI(fileName, outputConfigName));
		OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), encoding);
		try {
			writer.append(postProcess(fileName, outputConfigName, contents, encoding));
			if(callBack != null) 
				callBack.fileAdded(file);
			if (writeTrace)
				generateTrace(fileName, outputConfigName, contents);
		} finally {
			writer.close();
		}
	} catch (IOException e) {
		throw new RuntimeIOException(e);
	}
}
 
Example #7
Source File: JavaIoFileSystemAccess.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.4
 */
@Override
public void generateFile(String fileName, String outputCfgName, InputStream content) throws RuntimeIOException {
	File file = getFile(fileName, outputCfgName);
	if (!getOutputConfig(outputCfgName).isOverrideExistingResources() && file.exists()) {
      return;
	}
	try {
		createFolder(file.getParentFile());
		OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
		try {
			ByteStreams.copy(content, out);
		} finally {
			try {
				out.close();
				if(callBack != null) 
					callBack.fileAdded(file);
			} finally {
				content.close();
			}
		}
	} catch (IOException e) {
		throw new RuntimeIOException(e);
	}
}
 
Example #8
Source File: JavaIoFileSystemAccess.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.4
 */
@Override
public InputStream readBinaryFile(String fileName, String outputCfgName) throws RuntimeIOException {
	File file = getFile(fileName, outputCfgName);
	try {
		return new BufferedInputStream(new FileInputStream(file));
	} catch (FileNotFoundException e) {
		throw new RuntimeIOException(e);
	}
}
 
Example #9
Source File: EclipseResourceFileSystemAccess2.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.7
 */
public InputStream readBinaryFile(String fileName, String outputCfgName, IProgressMonitor progressMonitor) throws RuntimeIOException {
	try {
		IFile file = getFile(fileName, outputCfgName, progressMonitor);
		return new BufferedInputStream(file.getContents());
	} catch (CoreException e) {
		throw new RuntimeIOException(e);
	}
}
 
Example #10
Source File: JavaProjectSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public static IFolder createSubFolder(IProject project, String folderName) throws CoreException {
	IFolder folder = project.getFolder(folderName);
	if (folder.exists()) {
		folder.delete(true, null);
	}
	try {
		return createFolder(folder.getFullPath());
	} catch (Exception e) {
		throw new RuntimeIOException(e);
	}
}
 
Example #11
Source File: SourceRelativeFileSystemAccess.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected boolean ensureOutputConfigurationDirectoryExists(OutputConfiguration outputConfig) {
	try {
		if (super.ensureOutputConfigurationDirectoryExists(outputConfig)) {
			IContainer container = getContainer(outputConfig);
			addToSourceFolders(container);
			return true;
		}
		return false;
	} catch (CoreException e) {
		throw new RuntimeIOException(e);
	}
}
 
Example #12
Source File: XtendProjectConfigurator.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
private void writePreferences(OutputConfiguration configuration,
		IProject project) {
	ProjectScope projectPreferences = new ProjectScope(project);
	IEclipsePreferences languagePreferences = projectPreferences
			.getNode("org.eclipse.xtend.core.Xtend");
	languagePreferences.putBoolean(
			OptionsConfigurationBlock.isProjectSpecificPropertyKey(BuilderConfigurationBlock.PROPERTY_PREFIX), true);
	languagePreferences.putBoolean(
			getKey(configuration, INSTALL_DSL_AS_PRIMARY_SOURCE),
			configuration.isInstallDslAsPrimarySource());
	languagePreferences.putBoolean(
			getKey(configuration, HIDE_LOCAL_SYNTHETIC_VARIABLES),
			configuration.isHideSyntheticLocalVariables());
	languagePreferences.putBoolean(
			getKey(configuration, USE_OUTPUT_PER_SOURCE_FOLDER),
			true);
	for (SourceMapping sourceMapping : configuration.getSourceMappings()) {
		languagePreferences.put(
				getOutputForSourceFolderKey(configuration,
						sourceMapping.getSourceFolder()),
				Strings.nullToEmpty(sourceMapping.getOutputDirectory()));
	}

	try {
		languagePreferences.flush();
	} catch (BackingStoreException e) {
		throw new RuntimeIOException(e);
	}
}
 
Example #13
Source File: OnTheFlyJavaCompiler.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected File createTempDir() {
	if (temporaryFolder != null && temporaryFolder.isInitialized()) {
		try {
			return temporaryFolder.newFolder();
		} catch (IOException e) {
			throw new RuntimeIOException(e);
		}
	}
	return com.google.common.io.Files.createTempDir();
}
 
Example #14
Source File: URIBasedFileSystemAccess.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void generateFile(String fileName, String outputCfgName, InputStream content) throws RuntimeIOException {
	try {
		URI uri = getURI(fileName, outputCfgName);
		try (OutputStream out = converter.createOutputStream(uri)) {
			ByteStreams.copy(beforeWrite.beforeWrite(uri, outputCfgName, content), out);
		}
	} catch (IOException t) {
		throw new RuntimeIOException(t);
	}
}
 
Example #15
Source File: URIBasedFileSystemAccess.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public InputStream readBinaryFile(String fileName, String outputCfgName) throws RuntimeIOException {
	try {
		URI uri = getURI(fileName, outputCfgName);
		return beforeRead.beforeRead(uri, converter.createInputStream(uri));
	} catch (IOException t) {
		throw new RuntimeIOException(t);
	}
}
 
Example #16
Source File: InMemoryFileSystemAccess.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.4
 */
@Override
public void generateFile(String fileName, String outputCfgName, InputStream content) {
	try {
		try {
			byte[] byteArray = ByteStreams.toByteArray(content);
			files.put(getFileName(fileName, outputCfgName), byteArray);
		} finally {
			content.close();
		}
	} catch (IOException e) {
		throw new RuntimeIOException(e);
	}
}
 
Example #17
Source File: InMemoryFileSystemAccess.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.4
 */
@Override
public InputStream readBinaryFile(String fileName, String outputCfgName) throws RuntimeIOException {
	String name = getFileName(fileName, outputCfgName);
	Object contents = files.get(name);
	if (contents == null)
		throw new RuntimeIOException("File not found: " + name);
	if (contents instanceof byte[])
		return new ByteArrayInputStream((byte[]) contents);
	if (contents instanceof CharSequence)
		return new StringInputStream(contents.toString());
	throw new RuntimeIOException("Unknown File Data Type: " + contents.getClass() + " File: " + name);
}
 
Example #18
Source File: InMemoryFileSystemAccess.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.4
 */
@Override
public CharSequence readTextFile(String fileName, String outputCfgName) throws RuntimeIOException {
	String name = getFileName(fileName, outputCfgName);
	Object contents = files.get(name);
	if (contents == null)
		throw new RuntimeIOException("File not found: " + name);
	if (contents instanceof CharSequence)
		return (CharSequence) contents;
	if (contents instanceof byte[])
		throw new RuntimeIOException("Can not read a binary file using readTextFile(). File: " + name);
	throw new RuntimeIOException("Unknown File Data Type: " + contents.getClass() + " File: " + name);
}
 
Example #19
Source File: DerivedStateAwareResourceDescriptionManager.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected IResourceDescription internalGetResourceDescription(final Resource resource,
		IDefaultResourceDescriptionStrategy strategy) {
	if (resource instanceof DerivedStateAwareResource) {
		DerivedStateAwareResource res = (DerivedStateAwareResource) resource;
		if (!res.isLoaded()) {
			try {
				res.load(res.getResourceSet().getLoadOptions());
			} catch (IOException e) {
				throw new RuntimeIOException(e);
			}
		}
		boolean isInitialized = res.fullyInitialized || res.isInitializing;
		try {
			if (!isInitialized) {
				res.eSetDeliver(false);
				res.installDerivedState(true);
			}
			IResourceDescription description = createResourceDescription(resource, strategy);
			if (!isInitialized) {
				// eager initialize
				for (IEObjectDescription desc : description.getExportedObjects()) {
					desc.getEObjectURI();
				}
			}
			return description;
		} finally {
			if (!isInitialized) {
				if (log.isDebugEnabled())
					log.debug("Discarding inferred state for "+resource.getURI());
				res.discardDerivedState();
				res.eSetDeliver(true);
			}
		}
	} else {
		if (log.isDebugEnabled())
			log.debug("Invalid configuration. DerivedStateAwareResourceDescriptionManager was registered, but resource was a " + resource.getClass().getName());
		return super.internalGetResourceDescription(resource, strategy);
	}
}
 
Example #20
Source File: ProjectRelativeFileSystemAccess.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean ensureOutputConfigurationDirectoryExists(OutputConfiguration outputConfig) {
	try {
		if (super.ensureOutputConfigurationDirectoryExists(outputConfig)) {
			final IContainer container = getContainer(outputConfig);
			addToSourceFolders(container);
			return true;
		}
		return false;
	} catch (CoreException e) {
		throw new RuntimeIOException(e);
	}
}
 
Example #21
Source File: OnTheFlyJavaCompiler.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected File createTempDir() {
	if (temporaryFolder != null && temporaryFolder.isInitialized()) {
		try {
			return temporaryFolder.newFolder();
		} catch (IOException e) {
			throw new RuntimeIOException(e);
		}
	}
	return com.google.common.io.Files.createTempDir();
}
 
Example #22
Source File: JavaProjectSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public static IFolder createSubFolder(IProject project, String folderName) throws CoreException {
	IFolder folder = project.getFolder(folderName);
	if (folder.exists()) {
		folder.delete(true, null);
	}
	try {
		return IResourcesSetupUtil.createFolder(folder.getFullPath());
	} catch (Exception e) {
		throw new RuntimeIOException(e);
	}
}
 
Example #23
Source File: EclipseResourceFileSystemAccess2.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void deleteFile(String fileName, String outputName) {
	try {
		IFile file = getFile(fileName, outputName);
		deleteFile(file, outputName, monitor);
	} catch (CoreException e) {
		throw new RuntimeIOException(e);
	}
}
 
Example #24
Source File: EclipseResourceFileSystemAccess2.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected StringInputStream getInputStream(String contentsAsString, String encoding) {
	try {
		return new StringInputStream(contentsAsString, encoding);
	} catch (UnsupportedEncodingException e) {
		throw new RuntimeIOException(e);
	}
}
 
Example #25
Source File: ParallelFileSystemAccess.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.9
 */
@Override
public boolean isFile(String path) throws RuntimeIOException {
	if (delegate instanceof EclipseResourceFileSystemAccess2) {
		return ((EclipseResourceFileSystemAccess2) delegate).isFile(path, new NullProgressMonitor());
	}
	return delegate.isFile(path);
}
 
Example #26
Source File: ParallelFileSystemAccess.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.9
 */
@Override
public boolean isFile(String path, String outputConfigurationName) throws RuntimeIOException {
	if (delegate instanceof EclipseResourceFileSystemAccess2) {
		return ((EclipseResourceFileSystemAccess2) delegate).isFile(path, outputConfigurationName, new NullProgressMonitor());
	}
	return delegate.isFile(path, outputConfigurationName);
}
 
Example #27
Source File: ParallelFileSystemAccess.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public CharSequence readTextFile(String fileName) throws RuntimeIOException {
	if (delegate instanceof EclipseResourceFileSystemAccess2) {
		return ((EclipseResourceFileSystemAccess2) delegate).readTextFile(fileName, new NullProgressMonitor());
	}
	return delegate.readTextFile(fileName);
}
 
Example #28
Source File: ParallelFileSystemAccess.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public CharSequence readTextFile(String fileName, String outputCfgName) throws RuntimeIOException {
	if (delegate instanceof EclipseResourceFileSystemAccess2) {
		return ((EclipseResourceFileSystemAccess2) delegate).readTextFile(fileName, outputCfgName, new NullProgressMonitor());
	}
	return delegate.readTextFile(fileName, outputCfgName);
}
 
Example #29
Source File: ParallelFileSystemAccess.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public InputStream readBinaryFile(String fileName) throws RuntimeIOException {
	if (delegate instanceof EclipseResourceFileSystemAccess2) {
		return ((EclipseResourceFileSystemAccess2) delegate).readBinaryFile(fileName, new NullProgressMonitor());
	}
	return delegate.readBinaryFile(fileName);
}
 
Example #30
Source File: ParallelFileSystemAccess.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public InputStream readBinaryFile(String fileName, String outputCfgName) throws RuntimeIOException {
	if (delegate instanceof EclipseResourceFileSystemAccess2) {
		return ((EclipseResourceFileSystemAccess2) delegate).readBinaryFile(fileName, outputCfgName, new NullProgressMonitor());
	}
	return delegate.readBinaryFile(fileName, outputCfgName);
}