Search in sources :

Example 1 with RuntimeIOException

use of org.eclipse.xtext.util.RuntimeIOException in project applause by applause.

the class ApplauseEclipseResourceFileSystemAccess2 method deleteFile.

@Override
public void deleteFile(String fileName, String outputName) {
    try {
        IFile file = getFile(fileName, outputName);
        deleteFile(file, monitor);
    } catch (CoreException e) {
        throw new RuntimeIOException(e);
    }
}
Also used : RuntimeIOException(org.eclipse.xtext.util.RuntimeIOException) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException)

Example 2 with RuntimeIOException

use of org.eclipse.xtext.util.RuntimeIOException in project applause by applause.

the class ApplauseEclipseResourceFileSystemAccess2 method readTextFile.

/**
	 * @since 2.4
	 */
public CharSequence readTextFile(String fileName, String outputCfgName) throws RuntimeIOException {
    try {
        IFile file = getFile(fileName, outputCfgName);
        String encoding = getEncoding(file);
        InputStream inputStream = file.getContents();
        try {
            byte[] bytes = ByteStreams.toByteArray(inputStream);
            return new String(bytes, encoding);
        } finally {
            inputStream.close();
        }
    } catch (IOException e) {
        throw new RuntimeIOException(e);
    } catch (CoreException e) {
        throw new RuntimeIOException(e);
    }
}
Also used : RuntimeIOException(org.eclipse.xtext.util.RuntimeIOException) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) StringInputStream(org.eclipse.xtext.util.StringInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) RuntimeIOException(org.eclipse.xtext.util.RuntimeIOException) IOException(java.io.IOException)

Example 3 with RuntimeIOException

use of org.eclipse.xtext.util.RuntimeIOException in project applause by applause.

the class ApplauseEclipseResourceFileSystemAccess2 method generateFile.

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);
    IFile traceFile = getTraceFile(file);
    try {
        String encoding = getEncoding(file);
        CharSequence postProcessedContent = postProcess(fileName, outputName, contents, encoding);
        String contentsAsString = postProcessedContent.toString();
        if (file.exists()) {
            if (outputConfig.isOverrideExistingResources()) {
                StringInputStream newContent = getInputStream(contentsAsString, encoding);
                if (hasContentsChanged(file, newContent)) {
                    // reset to offset zero allows to reuse internal byte[]
                    // no need to convert the string twice
                    newContent.reset();
                    file.setContents(newContent, true, true, monitor);
                } else {
                    file.touch(getMonitor());
                }
                if (file.isDerived() != outputConfig.isSetDerivedProperty()) {
                    setDerived(file, outputConfig.isSetDerivedProperty());
                }
                if (traceFile != null)
                    updateTraceInformation(traceFile, postProcessedContent, outputConfig.isSetDerivedProperty());
                if (callBack != null)
                    callBack.afterFileUpdate(file);
            }
        } else {
            ensureParentExists(file);
            file.create(getInputStream(contentsAsString, encoding), true, monitor);
            if (outputConfig.isSetDerivedProperty()) {
                setDerived(file, true);
            }
            if (traceFile != null)
                updateTraceInformation(traceFile, postProcessedContent, outputConfig.isSetDerivedProperty());
            if (callBack != null)
                callBack.afterFileCreation(file);
        }
    } catch (CoreException e) {
        throw new RuntimeIOException(e);
    } catch (IOException e) {
        throw new RuntimeIOException(e);
    }
}
Also used : RuntimeIOException(org.eclipse.xtext.util.RuntimeIOException) StringInputStream(org.eclipse.xtext.util.StringInputStream) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) OutputConfiguration(org.eclipse.xtext.generator.OutputConfiguration) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) RuntimeIOException(org.eclipse.xtext.util.RuntimeIOException) IOException(java.io.IOException)

Example 4 with RuntimeIOException

use of org.eclipse.xtext.util.RuntimeIOException in project applause by applause.

the class ApplauseEclipseResourceFileSystemAccess2 method generateFile.

/**
	 * @since 2.4
	 */
public void generateFile(String fileName, String outputName, InputStream content) {
    if (monitor.isCanceled())
        throw new OperationCanceledException();
    OutputConfiguration outputConfig = getOutputConfig(outputName);
    if (!ensureOutputConfigurationDirectoryExists(outputConfig))
        return;
    try {
        IFile file = getFile(fileName, outputName);
        if (file.exists()) {
            if (outputConfig.isOverrideExistingResources()) {
                if (hasContentsChanged(file, content)) {
                    // reset to offset zero allows to reuse internal byte[]
                    // no need to convert the string twice
                    content.reset();
                    file.setContents(content, true, true, monitor);
                } else {
                    file.touch(getMonitor());
                }
                if (file.isDerived() != outputConfig.isSetDerivedProperty())
                    setDerived(file, outputConfig.isSetDerivedProperty());
                if (callBack != null)
                    callBack.afterFileUpdate(file);
            }
        } else {
            ensureParentExists(file);
            file.create(content, true, monitor);
            if (outputConfig.isSetDerivedProperty()) {
                setDerived(file, true);
            }
            if (callBack != null)
                callBack.afterFileCreation(file);
        }
    } catch (CoreException e) {
        throw new RuntimeIOException(e);
    } catch (IOException e) {
        throw new RuntimeIOException(e);
    }
}
Also used : RuntimeIOException(org.eclipse.xtext.util.RuntimeIOException) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) OutputConfiguration(org.eclipse.xtext.generator.OutputConfiguration) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) RuntimeIOException(org.eclipse.xtext.util.RuntimeIOException) IOException(java.io.IOException)

Aggregations

IFile (org.eclipse.core.resources.IFile)4 CoreException (org.eclipse.core.runtime.CoreException)4 RuntimeIOException (org.eclipse.xtext.util.RuntimeIOException)4 IOException (java.io.IOException)3 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)2 OutputConfiguration (org.eclipse.xtext.generator.OutputConfiguration)2 StringInputStream (org.eclipse.xtext.util.StringInputStream)2 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1