use of org.eclipse.emf.codegen.jet.JETException in project mdw-designer by CenturyLinkCloud.
the class JetAccess method append.
/**
* Appends jet-generated content to the end of the JetAccess save file.
*
* @param monitor
* @param contents
* @return
* @throws IOException
* @throws CoreException
*/
public IFile append(IProgressMonitor monitor, byte[] contents) throws IOException, CoreException, JETException {
monitor = createIfNull(monitor);
JetConfig config = getConfig();
IContainer container = findOrCreateContainer(monitor, config.getTargetFolder(), config.getPackageName());
if (container == null) {
throw new JETException("Cound not find or create container for package " + config.getPackageName() + " in " + config.getTargetFolder());
}
IFile targetFile = container.getFile(new Path(config.getTargetFile()));
IFile result = getWritableTargetFile(targetFile, container, config.getTargetFile());
InputStream newContents = new ByteArrayInputStream(contents);
if (result.exists()) {
newContents = appendFile(result, new String(contents));
result.setContents(newContents, true, true, new SubProgressMonitor(monitor, 2));
} else {
result.create(newContents, true, new SubProgressMonitor(monitor, 1));
}
return result;
}
use of org.eclipse.emf.codegen.jet.JETException in project mdw-designer by CenturyLinkCloud.
the class JetAccess method merge.
/**
* Merges the specified emitterResult with the contents of an existing file
* (existing file is not modified). The location of the file to merge with
* is determined by finding or creating the container (folder) for the
* Config's package in the Config's target folder. The name of the file to
* merge with is the Config's target file.
*
* @param monitor
* the progress monitor to use (may be null)
* @param emitterResult
* generated content to merge with the existing content
* @return result of merging the generated contents with the existing file
* @throws CoreException
* if an error occurs accessing the contents of the file
*/
public String merge(IProgressMonitor monitor, String emitterResult) throws CoreException, JETException {
monitor = createIfNull(monitor);
JetConfig config = getConfig();
IContainer container = findOrCreateContainer(monitor, config.getTargetFolder(), config.getPackageName());
if (container == null) {
throw new JETException("Cound not find or create container for package " + config.getPackageName() + " in " + config.getTargetFolder());
}
IFile targetFile = container.getFile(new Path(config.getTargetFile()));
if (!targetFile.exists()) {
monitor.worked(1);
return emitterResult;
}
JMerger jMerger = new JMerger();
jMerger.setControlModel(new JControlModel(config.getMergeXmlFullUri()));
jMerger.setSourceCompilationUnit(jMerger.createCompilationUnitForContents(emitterResult));
jMerger.setTargetCompilationUnit(jMerger.createCompilationUnitForInputStream(targetFile.getContents(true)));
String oldContents = jMerger.getTargetCompilationUnit().getContents();
jMerger.merge();
monitor.worked(1);
String result = jMerger.getTargetCompilationUnit().getContents();
if (oldContents.equals(result)) {
return result;
}
if (!targetFile.isReadOnly()) {
return result;
}
// by a VCM component (here we ask permission to change the file)
if (targetFile.getWorkspace().validateEdit(new IFile[] { targetFile }, new SubProgressMonitor(monitor, 1)).isOK()) {
jMerger.setTargetCompilationUnit(jMerger.createCompilationUnitForInputStream(targetFile.getContents(true)));
jMerger.remerge();
return jMerger.getTargetCompilationUnit().getContents();
}
return result;
}
use of org.eclipse.emf.codegen.jet.JETException in project mdw-designer by CenturyLinkCloud.
the class JavaSource method getDefaultContent.
@Override
public String getDefaultContent() {
try {
// initialize from template
String templateUri = Platform.getBundle(MdwPlugin.getPluginId()).getEntry("/").toString() + "/templates/source/JavaSource.javajet";
JETEmitter emitter = new JETEmitter(templateUri, getClass().getClassLoader());
emitter.addVariable(null, MdwPlugin.getPluginId());
Map<String, Object> map = new HashMap<String, Object>();
JavaCode javaCode = new JavaCode(getJavaPackageName(), getJavaClassName());
map.put("model", javaCode);
map.put("settings", MdwPlugin.getSettings());
return emitter.generate(new NullProgressMonitor(), new Object[] { map });
} catch (JETException ex) {
PluginMessages.uiError(ex, "Generate Java", getProject());
return null;
}
}
Aggregations