use of org.eclipse.xtext.util.StringInputStream 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);
}
}
Aggregations