|
Re: Launching JET2 from code [message #57770 is a reply to message #57721] |
Thu, 26 February 2009 13:07 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
J F![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=jfrancis%40his.co.uk) Messages: 256 Registered: July 2009 |
Senior Member |
|
|
I seem to able to do this quite happily, as long as I take care of the
context variables;
import java.io.IOException;
import jet2testproject.Activator;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.jet.CoreJETException;
import org.eclipse.jet.JET2Context;
import org.eclipse.jet.JET2Platform;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.workspace.WorkspaceContextExtender;
import org.eclipse.jet.transform.IJETBundleDescriptor;
public class Jet2Utils2
{
public static final class WorkspaceResourceSpecification
{
public final String projectName;
public WorkspaceResourceSpecification(String projectName)
{
this.projectName = projectName;
}
}
String transformId;
Resource emfResource;
final IProgressMonitor monitor;
JET2Context context;
WorkspaceResourceSpecification resourceSpecification;
public Jet2Utils2(String transformId, Resource emfResource,
WorkspaceResourceSpecification resourceSpec, IProgressMonitor monitor)
{
this.transformId = transformId;
this.emfResource = emfResource;
this.monitor = monitor;
this.resourceSpecification = resourceSpec;
this.context = new JET2Context(null);
}
public void run()
{
IStatus status;
try
{
final IJETBundleDescriptor descriptor =
JET2Platform.getJETBundleManager()
.getDescriptor(transformId);
if(descriptor != null)
{
String fileType = descriptor.getModelExtension();
loadResourceAsSource(context, emfResource, fileType);
status = JET2Platform.runTransform(transformId, context, monitor);
LoggingSupport.handleStatus(Activator.getDefault(), status);
}
else
{
LoggingSupport.error(Activator.getDefault(), "Transform " +
transformId + " not found");
}
}
catch (IOException e)
{
// didn't work.
status = new Status(IStatus.ERROR, transformId, IStatus.OK,
e.getLocalizedMessage(), e);
LoggingSupport.handleStatus(Activator.getDefault(), status);
}
catch (CoreJETException e)
{
status = new Status(IStatus.ERROR, transformId, IStatus.OK,
e.getLocalizedMessage(), e);
LoggingSupport.handleStatus(Activator.getDefault(), status);
}
}
public void loadResourceAsSource(JET2Context context,
Resource emfResource,
String resourceType) throws CoreJETException,
IOException
{
context.setSource(emfResource);
try
{
//The only context variable I use at the momment
context.setVariable(WorkspaceContextExtender.VAR_RESOURCE_PR OJECT_NAME,
resourceSpecification.projectName);
}
catch (JET2TagException e)
{
LoggingSupport.error(Activator.getDefault(), "Invalid variable name",
e); // $NON-NLS
}
}
}
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04276 seconds