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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations