summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-04-06 04:12:24 (EDT)
committerpelder2006-04-06 04:12:24 (EDT)
commit21e1523df8efba59071796b82b309ac47cded80f (patch)
tree59f8fe474244d54e8f69dfd864e8948c88e113e2
parentd0b9babba1bde4cf2ae11f3728ba970516dd569d (diff)
downloadorg.eclipse.jet-21e1523df8efba59071796b82b309ac47cded80f.zip
org.eclipse.jet-21e1523df8efba59071796b82b309ac47cded80f.tar.gz
org.eclipse.jet-21e1523df8efba59071796b82b309ac47cded80f.tar.bz2
[131190] Implement execute functions using public APIs only. Also rename this to runTransformXXX to make usage clearer.
-rw-r--r--plugins/org.eclipse.jet/.deprecations/DEPRECATE_org.eclipse.jet.JET2Platform.execute(java.lang.String_java.lang.Object_org.eclipse.core.runtime.IProgressMonitor).xml4
-rw-r--r--plugins/org.eclipse.jet/.deprecations/DEPRECATE_org.eclipse.jet.JET2Platform.execute(java.lang.String_java.lang.String_java.lang.String_org.eclipse.core.runtime.IProgressMonitor).xml4
-rw-r--r--plugins/org.eclipse.jet/.deprecations/DEPRECATE_org.eclipse.jet.JET2Platform.execute(java.lang.String_java.lang.String_org.eclipse.core.runtime.IProgressMonitor).xml4
-rw-r--r--plugins/org.eclipse.jet/.deprecations/DEPRECATE_org.eclipse.jet.JET2Platform.execute(java.lang.String_org.eclipse.core.resources.IResource_org.eclipse.core.runtime.IProgressMonitor).xml4
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Context.java148
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java593
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/launch/JET2TransformationDelegate.java2
7 files changed, 450 insertions, 309 deletions
diff --git a/plugins/org.eclipse.jet/.deprecations/DEPRECATE_org.eclipse.jet.JET2Platform.execute(java.lang.String_java.lang.Object_org.eclipse.core.runtime.IProgressMonitor).xml b/plugins/org.eclipse.jet/.deprecations/DEPRECATE_org.eclipse.jet.JET2Platform.execute(java.lang.String_java.lang.Object_org.eclipse.core.runtime.IProgressMonitor).xml
new file mode 100644
index 0000000..3a72915
--- /dev/null
+++ b/plugins/org.eclipse.jet/.deprecations/DEPRECATE_org.eclipse.jet.JET2Platform.execute(java.lang.String_java.lang.Object_org.eclipse.core.runtime.IProgressMonitor).xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<session comment="Inline deprecated method" version="1.0">
+<refactoring comment="Inline deprecated method" delete="false" description="Inline method 'org.eclipse.jet.JET2Platform.execute(...)'" flags="393222" id="org.eclipse.jdt.ui.inline.method" input="unit://src/org/eclipse/jet/JET2Platform.java" mode="0" project="org.eclipse.jet" selection="-1 -1" version="1.0"/>
+</session>
diff --git a/plugins/org.eclipse.jet/.deprecations/DEPRECATE_org.eclipse.jet.JET2Platform.execute(java.lang.String_java.lang.String_java.lang.String_org.eclipse.core.runtime.IProgressMonitor).xml b/plugins/org.eclipse.jet/.deprecations/DEPRECATE_org.eclipse.jet.JET2Platform.execute(java.lang.String_java.lang.String_java.lang.String_org.eclipse.core.runtime.IProgressMonitor).xml
new file mode 100644
index 0000000..3a72915
--- /dev/null
+++ b/plugins/org.eclipse.jet/.deprecations/DEPRECATE_org.eclipse.jet.JET2Platform.execute(java.lang.String_java.lang.String_java.lang.String_org.eclipse.core.runtime.IProgressMonitor).xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<session comment="Inline deprecated method" version="1.0">
+<refactoring comment="Inline deprecated method" delete="false" description="Inline method 'org.eclipse.jet.JET2Platform.execute(...)'" flags="393222" id="org.eclipse.jdt.ui.inline.method" input="unit://src/org/eclipse/jet/JET2Platform.java" mode="0" project="org.eclipse.jet" selection="-1 -1" version="1.0"/>
+</session>
diff --git a/plugins/org.eclipse.jet/.deprecations/DEPRECATE_org.eclipse.jet.JET2Platform.execute(java.lang.String_java.lang.String_org.eclipse.core.runtime.IProgressMonitor).xml b/plugins/org.eclipse.jet/.deprecations/DEPRECATE_org.eclipse.jet.JET2Platform.execute(java.lang.String_java.lang.String_org.eclipse.core.runtime.IProgressMonitor).xml
new file mode 100644
index 0000000..3a72915
--- /dev/null
+++ b/plugins/org.eclipse.jet/.deprecations/DEPRECATE_org.eclipse.jet.JET2Platform.execute(java.lang.String_java.lang.String_org.eclipse.core.runtime.IProgressMonitor).xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<session comment="Inline deprecated method" version="1.0">
+<refactoring comment="Inline deprecated method" delete="false" description="Inline method 'org.eclipse.jet.JET2Platform.execute(...)'" flags="393222" id="org.eclipse.jdt.ui.inline.method" input="unit://src/org/eclipse/jet/JET2Platform.java" mode="0" project="org.eclipse.jet" selection="-1 -1" version="1.0"/>
+</session>
diff --git a/plugins/org.eclipse.jet/.deprecations/DEPRECATE_org.eclipse.jet.JET2Platform.execute(java.lang.String_org.eclipse.core.resources.IResource_org.eclipse.core.runtime.IProgressMonitor).xml b/plugins/org.eclipse.jet/.deprecations/DEPRECATE_org.eclipse.jet.JET2Platform.execute(java.lang.String_org.eclipse.core.resources.IResource_org.eclipse.core.runtime.IProgressMonitor).xml
new file mode 100644
index 0000000..3a72915
--- /dev/null
+++ b/plugins/org.eclipse.jet/.deprecations/DEPRECATE_org.eclipse.jet.JET2Platform.execute(java.lang.String_org.eclipse.core.resources.IResource_org.eclipse.core.runtime.IProgressMonitor).xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<session comment="Inline deprecated method" version="1.0">
+<refactoring comment="Inline deprecated method" delete="false" description="Inline method 'org.eclipse.jet.JET2Platform.execute(...)'" flags="393222" id="org.eclipse.jdt.ui.inline.method" input="unit://src/org/eclipse/jet/JET2Platform.java" mode="0" project="org.eclipse.jet" selection="-1 -1" version="1.0"/>
+</session>
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Context.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Context.java
index 35aae86..5f2b596 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Context.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Context.java
@@ -21,7 +21,10 @@ package org.eclipse.jet;
import java.text.MessageFormat;
import java.util.Collections;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
+import java.util.StringTokenizer;
+import java.util.regex.Pattern;
import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.Diagnostic;
@@ -30,7 +33,6 @@ import org.eclipse.jet.internal.runtime.JET2TemplateStatus;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.TagFactory;
import org.eclipse.jet.taglib.TagInfo;
-import org.eclipse.jet.transform.TransformContextExtender;
/**
@@ -48,13 +50,12 @@ public final class JET2Context
private TagFactory tagFactory = null;
- /**
- * Transitional item while refactoring JET2Context into TransformContextExtender.
- */
- private TransformContextExtender tce = null;
-
private final Map globalVariables = new HashMap();
+ private String templatePath = ""; //$NON-NLS-1$
+
+ private String jetBundleId;
+
/**
* Create a JET2 context with the specified source argument and the specified variables.
* @param source the source object
@@ -80,15 +81,6 @@ public final class JET2Context
this(source, Collections.EMPTY_MAP);
}
- private TransformContextExtender getTCE()
- {
- if (tce == null)
- {
- tce = new TransformContextExtender(this);
- }
- return tce;
- }
-
/**
* Set the source object for the transformation
*
@@ -125,7 +117,8 @@ public final class JET2Context
message = throwable.toString();
}
}
- JET2TemplateStatus status = new JET2TemplateStatus(severity, getTCE().getId(),
+ JET2TemplateStatus status = new JET2TemplateStatus(severity,
+ getJETBundleId() != null ? getJETBundleId() : JET2Platform.PLUGIN_ID,
message == null ? "" : message, //$NON-NLS-1$
templatePath,
tagInfo,
@@ -133,6 +126,28 @@ public final class JET2Context
stati.add(status);
}
+ /**
+ * Return the id of the JET Bundle defining the current template. Used in generating
+ * error messages.
+ * @return the JET Bundle id, or <code>null</code> if not defined.
+ * @see #setJETBundleId(String)
+ */
+ public String getJETBundleId()
+ {
+ return jetBundleId;
+ }
+
+ /**
+ * Set the id of the JET Bundle defining the current template. Used in generating
+ * error messages. If not set, then the ID of the JET plugin is used.
+ * @param jetBundleId the JET Bundle ide.
+ */
+ public void setJETBundleId(String jetBundleId)
+ {
+ this.jetBundleId = jetBundleId;
+
+ }
+
// private void log(ExecutionLogEntry entry) {
// executionLog.add(entry);
// }
@@ -145,10 +160,28 @@ public final class JET2Context
// Used once: LogTag.doFunction()
public void logInfo(String message)
{
- log(Diagnostic.INFO, getTCE().getTemplatePath(), null, message, (Throwable)null);
+ log(Diagnostic.INFO, getTemplatePath(), null, message, (Throwable)null);
+ }
+
+ /**
+ * Return the path for the executing template. This is used in creating error messages.
+ * @return the template path or <code>null</code> if no templatePath is defined.
+ * @see #setTemplatePath(String)
+ */
+ public String getTemplatePath()
+ {
+ return templatePath;
}
/**
+ * Set the templatePath. The templatePath is used in generating error messages.
+ * @param templatePath the template path or <code>null</code> to indicate no executing template.
+ */
+ public void setTemplatePath(String templatePath)
+ {
+ this.templatePath = templatePath;
+ }
+ /**
* Log a warning message
*
* @param message
@@ -156,7 +189,7 @@ public final class JET2Context
// Used once: LogTag.doFunction()
public void logWarning(String message)
{
- log(Diagnostic.WARNING, getTCE().getTemplatePath(), null, message, (Throwable)null);
+ log(Diagnostic.WARNING, getTemplatePath(), null, message, (Throwable)null);
}
/**
@@ -167,7 +200,7 @@ public final class JET2Context
// Used once: LogTag.doFunction()
public void logError(String message)
{
- log(Diagnostic.ERROR, getTCE().getTemplatePath(), null, message, null);
+ log(Diagnostic.ERROR, getTemplatePath(), null, message, null);
}
/**
@@ -178,7 +211,7 @@ public final class JET2Context
// Used once: TransformContextExtender.commit()
public void logError(Throwable e)
{
- log(Diagnostic.ERROR, getTCE().getTemplatePath(), null, null, e);
+ log(Diagnostic.ERROR, getTemplatePath(), null, null, e);
}
/**
@@ -191,7 +224,7 @@ public final class JET2Context
// Never used!
public void logError(String message, Throwable e)
{
- log(Diagnostic.ERROR, getTCE().getTemplatePath(), null, message, e);
+ log(Diagnostic.ERROR, getTemplatePath(), null, message, e);
}
/**
@@ -238,7 +271,7 @@ public final class JET2Context
// Used 3 times: TagSafeRunnable.handleException() x 2, tagFactoryImpl.createTagElement(),
public void logError(TagInfo tagInfo, String message, Throwable exception)
{
- log(Diagnostic.ERROR, getTCE().getTemplatePath(), tagInfo, message, exception);
+ log(Diagnostic.ERROR, getTemplatePath(), tagInfo, message, exception);
}
private String getContextExtenderId(Class clazz)
@@ -305,13 +338,18 @@ public final class JET2Context
}
+ private static final Pattern validVariableNamePattern = Pattern.compile("(?:_|\\p{L})(?:_|-|\\.|\\p{L}|\\d)*"); //$NON-NLS-1$
/**
* Assigne or create a variable, and set its value.
* @param var the variable name. Cannot be <code>null</code>.
* @param value the variable value.
*/
- public void setVariable(String var, Object value)
+ public void setVariable(String var, Object value) throws JET2TagException
{
+ if(!validVariableNamePattern.matcher(var).matches())
+ {
+ throw new JET2TagException(MessageFormat.format(JET2Messages.JET2Context_InvalidVariableName, new Object[] {var}));
+ }
globalVariables.put(var, value);
}
@@ -332,6 +370,16 @@ public final class JET2Context
}
/**
+ * Return a map of all variables currently defined in the context. The map is a copy
+ * of the variables maintained by the context; changes to the map have no affect on
+ * the context.
+ * @return a Map of variables, where the key is a variable name, and the value is the variable value.
+ */
+ public Map getVariables()
+ {
+ return new HashMap(globalVariables);
+ }
+ /**
* Remove a variable
* @param var the variable name
*/
@@ -365,4 +413,58 @@ public final class JET2Context
{
this.tagFactory = tagFactory;
}
+
+ /**
+ * Extract a list of variables from the context
+ * @param variableNames a comma separated list of variables. May be <code>null</code>.
+ * @return a Map keyed by variable name. Will be <code>null</code> if <code>variableNames</code> is <code>null</code>.
+ * @throws JET2TagException if <code>variableNames</code> contains an invalid variable name.
+ */
+ public Map extractVariables(String variableNames) throws JET2TagException
+ {
+ Map savedVariableValues = null;
+ if (variableNames != null)
+ {
+ savedVariableValues = new HashMap();
+ for (StringTokenizer tokenizer = new StringTokenizer(variableNames, ","); tokenizer.hasMoreTokens();) { //$NON-NLS-1$
+ String varName = tokenizer.nextToken();
+ varName = varName.trim();
+ savedVariableValues.put(varName, getVariable(varName));
+ }
+ }
+ return savedVariableValues;
+ }
+
+ /**
+ * Restore variables in the passed map to the context.
+ * @param savedVariableValues a Map keyed by variable name. If <code>null</code> the method does nothing.
+ * @throws JET2TagException if a variable name is invalid
+ */
+ public void restoreVariables(Map savedVariableValues) throws JET2TagException
+ {
+ if (savedVariableValues != null)
+ {
+ for (Iterator i = savedVariableValues.entrySet().iterator(); i.hasNext();)
+ {
+ Map.Entry entry = (Map.Entry)i.next();
+ setVariable((String)entry.getKey(), entry.getValue());
+ }
+ }
+ }
+
+ /**
+ * Set the context variables to only the variables in variablesToPass
+ * @param variablesToPass a non-null map keyed by variable name.
+ * @throws JET2TagException if a variable name is invalid
+ */
+ public void setVariables(Map variablesToPass) throws JET2TagException
+ {
+ globalVariables.clear();
+ for (Iterator i = variablesToPass.entrySet().iterator(); i.hasNext();)
+ {
+ Map.Entry entry = (Map.Entry)i.next();
+ String varName = (String)entry.getKey();
+ setVariable(varName, entry.getValue());
+ }
+ }
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java
index 3cb6932..df3c29f 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java
@@ -1,7 +1,7 @@
/**
* <copyright>
*
- * Copyright (c) 2005 IBM Corporation and others.
+ * Copyright (c) 2005, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -46,21 +46,17 @@ import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.jet.compiler.JET2Compiler;
import org.eclipse.jet.internal.InternalJET2Platform;
import org.eclipse.jet.internal.l10n.JET2Messages;
-import org.eclipse.jet.internal.runtime.IJET2Runnable;
-import org.eclipse.jet.internal.runtime.IJET2TemplateBundleDescriptor;
import org.eclipse.jet.internal.runtime.JET2TemplateStatus;
-import org.eclipse.jet.internal.runtime.ProjectTemplateBundleDescriptor;
import org.eclipse.jet.internal.runtime.RuntimeLoggerContextExtender;
import org.eclipse.jet.internal.runtime.RuntimeTagLogger;
-import org.eclipse.jet.internal.runtime.model.CoreJETException;
-import org.eclipse.jet.internal.taglib.TagLibraryReferenceImpl;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.TagInfo;
-import org.eclipse.jet.taglib.TagLibraryReference;
import org.eclipse.jet.taglib.workspace.WorkspaceContextExtender;
-import org.eclipse.jet.transform.IJETBundle;
import org.eclipse.jet.transform.IJETBundleDescriptor;
+import org.eclipse.jet.transform.IJETBundleManager;
+import org.eclipse.jet.transform.IJETRunnable;
import org.eclipse.jet.transform.TransformContextExtender;
+import org.eclipse.jet.xpath.XPathFunctionMetaData;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.FindReplaceDocumentAdapter;
import org.eclipse.jface.text.IRegion;
@@ -88,223 +84,6 @@ public class JET2Platform
public static final String JET2_NATURE_ID = JET2Platform.PLUGIN_ID + "." + "jet2Nature"; //$NON-NLS-1$ //$NON-NLS-2$
/**
- *
- */
- private JET2Platform()
- {
- super();
- }
-
- public static IStatus execute(final String id, final String source, final String kind, final IProgressMonitor monitor)
- {
- IStatus result = Status.OK_STATUS;
-
- JET2Context context = new JET2Context(null);
-
- // TODO Get this value from the transform descriptor
- String modelLoaderID = null;
-
- try
- {
- final Object sourceObject = TransformContextExtender.loadModelFromString(source, modelLoaderID, kind);
- context.setSource(sourceObject);
- result = internalExecute(context, id, monitor);
- }
- catch (CoreJETException e)
- {
- result = BasicDiagnostic.toIStatus(e.getDiagnostic());
- }
- catch (IOException e)
- {
- result = InternalJET2Platform.newStatus(IStatus.ERROR, JET2Messages.JET2Platform_CouldNotParseString, e);
- }
-
- return result;
- }
-
- public static IStatus execute(final String id, final String source, final IProgressMonitor monitor)
- {
- return execute(id, source, "xml", monitor); //$NON-NLS-1$
- }
-
- public static IStatus execute(final String id, final IResource resource, final IProgressMonitor monitor)
- {
- try
- {
- final JET2Context context = new JET2Context(null);
- // TODO get this value the transform descriptor
- String loaderId = null;
- // TODO Get this value from the transform descriptor
- String fileType = null;
- WorkspaceContextExtender.loadResourceAsSource(context, resource, loaderId, fileType);
-
- return internalExecute(context, id, monitor);
- }
- catch (IOException e)
- {
- // didn't work.
- return new Status(IStatus.ERROR, id, IStatus.OK, e.getLocalizedMessage(), e);
- }
- catch (CoreJETException e)
- {
- return BasicDiagnostic.toIStatus(e.getDiagnostic());
- }
- }
-
- /**
- * Execute a JET2 transformation
- * @param id
- * @param source
- * @param monitor
- * @return the execution status
- */
- public static IStatus execute(final String id, final Object source, final IProgressMonitor monitor)
- {
- final JET2Context context = new JET2Context(source);
- return internalExecute(context, id, monitor);
- }
-
- /**
- * @param context
- * @param id
- * @param monitor
- * @return
- */
- private static IStatus internalExecute(final JET2Context context, final String id, final IProgressMonitor monitor)
- {
- IStatus result;
- monitor.beginTask(JET2Messages.JET2Platform_Executing + id, 100);
- try
- {
- IJET2TemplateBundleDescriptor descriptor = InternalJET2Platform.getDefault().getTemplateBundleDescriptor(id);
- if (descriptor instanceof ProjectTemplateBundleDescriptor)
- {
- ((ProjectTemplateBundleDescriptor)descriptor).getProject().deleteMarkers(
- JET2Compiler.RUNTIME_PROBLEM_MARKER,
- true,
- IResource.DEPTH_INFINITE);
- }
- if (descriptor == null)
- {
- final String msg = MessageFormat.format(JET2Messages.JET2Platform_TransformNotFound, new Object []{ id });
- result = InternalJET2Platform.newStatus(IStatus.ERROR, msg, null);
- InternalJET2Platform.log(result);
- return result;
- }
- monitor.subTask(JET2Messages.JET2Platform_RetrievingBundle);
- final IJETBundle templateBundle = InternalJET2Platform.getDefault().getTemplateBundle(id, new SubProgressMonitor(monitor, 10));
-
- final TransformContextExtender tce = new TransformContextExtender(context);
- tce.setId(id);
- tce.setTransform(templateBundle);
-
- if (DEBUG)
- {
- RuntimeLoggerContextExtender rl = new RuntimeLoggerContextExtender(context);
- rl.addListener(new RuntimeTagLogger()
- {
-
- public void log(String message, TagInfo td, String templatePath)
- {
- int nlPos = message.indexOf(System.getProperty("line.separator")); //$NON-NLS-1$
- if(nlPos >= 0) {
- message = message.substring(0, nlPos);
- }
- System.out.println((templatePath == null ? "" : templatePath + " ") + td.toString() + ": " + message); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- });
- }
-
- Diagnostic diagnostic = templateBundle.execute(new IJET2Runnable()
- {
-
- public Diagnostic run(JET2TemplateLoader loader) throws JET2TagException
- {
- XPathContextExtender xpe = XPathContextExtender.getInstance(context);
- // once the bundle is dynamically loaded, force the extension point managers
- // to refresh extensions in the loaded bundle.
- // OSGi asynchronously broadcasts registry updates, but this is not prompt enough,
- // and there is no mechanism for waiting for these
- InternalJET2Platform.getDefault().getXPathFunctionsManager().forceRefresh(id);
- InternalJET2Platform.getDefault().getTagLibManager().forceRefresh(id);
-
- xpe.addCustomFunctions(InternalJET2Platform.getDefault().getXPathFunctionsManager().getCustomFunctions());
-
- tce.setLoader(loader);
-
- BodyContentWriter bodyContentWriter = new BodyContentWriter();
- monitor.subTask(JET2Messages.JET2Platform_ExecutingTemplates);
-
- // FIXME Hard coded value for control template - fix this
- tce.execute("templates/control.jet", bodyContentWriter); //$NON-NLS-1$
- // template.generate(context, bodyContentWriter);
- monitor.worked(30);
-
- monitor.subTask(JET2Messages.JET2Platform_CommittingResults);
- tce.commit(new SubProgressMonitor(monitor, 60));
-
- return context.getLogAsMultiStatus();
- }
- });
- if (diagnostic.getSeverity() != Diagnostic.OK)
- {
- processResults(id, diagnostic);
- }
- result = BasicDiagnostic.toIStatus(diagnostic);
- }
- catch (CoreException e)
- {
- result = e.getStatus();
- }
- finally
- {
- monitor.done();
- if(DEBUG) {
- System.out.flush();
- }
- }
-
- return result;
- }
-
- /**
- * @param id
- * @param result
- * @throws CoreException
- */
- private static void processResults(final String id, final Diagnostic result)
- {
- IJET2TemplateBundleDescriptor descriptor = InternalJET2Platform.getDefault().getTemplateBundleDescriptor(id);
- if (descriptor instanceof ProjectTemplateBundleDescriptor)
- {
- ProjectTemplateBundleDescriptor projectDescriptor = (ProjectTemplateBundleDescriptor)descriptor;
- final IProject project = projectDescriptor.getProject();
-
- // we use this runnable to allow markers to be completely created
- // prior to becoming visible to the platform. See Eclipse FAQ 304
- try
- {
- project.getWorkspace().run(new IWorkspaceRunnable()
- {
- public void run(IProgressMonitor monitor1) throws CoreException
- {
- addRuntimeProblemMarkersToProject(project, result);
- }
- }, null, IWorkspace.AVOID_UPDATE, null);
- }
- catch (CoreException e)
- {
- InternalJET2Platform.logError(JET2Messages.JET2Platform_ErrorMarkingProject, e);
- InternalJET2Platform.log(BasicDiagnostic.toIStatus(result));
- }
- }
- else
- {
- InternalJET2Platform.log(BasicDiagnostic.toIStatus(result));
- }
- }
-
- /**
* @param project
* @param result
* @throws CoreException
@@ -391,6 +170,64 @@ public class JET2Platform
}
/**
+ * @deprecated Use {@link #runTransformOnResource(String,IResource,IProgressMonitor)} instead
+ */
+ public static IStatus execute(final String id, final IResource resource, final IProgressMonitor monitor)
+ {
+ return runTransformOnResource(id, resource, monitor);
+ }
+
+ /**
+ * Execute a JET2 transformation
+ * @param id
+ * @param source
+ * @param monitor
+ * @return the execution status
+ * @deprecated Use {@link #runTransformOnObject(String,Object,IProgressMonitor)} instead
+ */
+ public static IStatus execute(final String id, final Object source, final IProgressMonitor monitor)
+ {
+ return runTransformOnObject(id, source, monitor);
+ }
+
+ /**
+ * Invoke a JET transform on the passed String representation of the input model.
+ * @deprecated Use {@link #runTransformOnString(String,String,IProgressMonitor)} instead
+ */
+ public static IStatus execute(final String id, final String source, final IProgressMonitor monitor)
+ {
+ return runTransformOnString(id, source, monitor);
+ }
+
+ /**
+ * Invoke a JET transform on the passed String representation of an input model.
+ * @param id the transform id
+ * @param source the string respresentation of the input model.
+ * @param kind the kind of model (file extension) the string represents.
+ * @param monitor a progress monitor
+ * @return the transform's execution status.
+ * @deprecated Use {@link #runTransformOnString(String,String,String,IProgressMonitor)} instead
+ */
+ public static IStatus execute(final String id, final String source, final String kind, final IProgressMonitor monitor)
+ {
+ return runTransformOnString(id, source, kind, monitor);
+ }
+
+ /**
+ * Return the XPath functions installed by the 'org.eclipse.jet.xpathFunctions' extension point.
+ * @return an array of functions.
+ */
+ public static XPathFunctionMetaData[] getInstalledXPathFunctions()
+ {
+ return InternalJET2Platform.getDefault().getXPathFunctionsManager().getCustomFunctions();
+ }
+
+ public static IJETBundleManager getJETBundleManager()
+ {
+ return InternalJET2Platform.getDefault().getBundleManager();
+ }
+
+ /**
* Return the bundle description for the named JET project
* @param name an Eclipse project name
* @return a bundle description, or <code>null</code> if the project does not exist or
@@ -402,88 +239,274 @@ public class JET2Platform
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
if(isOpenJETProject(project))
{
- // XXX HACK, fake a descriptor
- result = new IJETBundleDescriptor() {
+ final IJETBundleManager bundleManager = getJETBundleManager();
+ result = bundleManager.getDescriptorForProject(name);
+ }
+ return result;
+ }
- public String getId()
- {
- return name;
- }
+ /**
+ * Test whether a project is an open JET project
+ * @param project
+ * @return
+ */
+ private static boolean isOpenJETProject(IProject project)
+ {
+ try
+ {
+ return project != null && project.exists() && project.isOpen() && project.hasNature(JET2_NATURE_ID);
+ }
+ catch (CoreException e)
+ {
+ return false;
+ }
+ }
- public String getName()
- {
- return name;
- }
+ /**
+ * @param id
+ * @param result
+ * @throws CoreException
+ */
+ private static void processResults(final String id, final Diagnostic result)
+ {
+ final IJETBundleManager bundleManager = getJETBundleManager();
+ String projectName = bundleManager.getProjectForId(id);
+ if(projectName != null)
+ {
+ final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ // we use this runnable to allow markers to be completely created
+ // prior to becoming visible to the platform. See Eclipse FAQ 304
+ try
+ {
+ project.getWorkspace().run(new IWorkspaceRunnable()
+ {
+ public void run(IProgressMonitor monitor1) throws CoreException
+ {
+ project.deleteMarkers(
+ JET2Compiler.RUNTIME_PROBLEM_MARKER,
+ true,
+ IResource.DEPTH_INFINITE);
+ addRuntimeProblemMarkersToProject(project, result);
+ }
+ }, null, IWorkspace.AVOID_UPDATE, null);
+ }
+ catch (CoreException e)
+ {
+ InternalJET2Platform.logError(JET2Messages.JET2Platform_ErrorMarkingProject, e);
+ InternalJET2Platform.log(BasicDiagnostic.toIStatus(result));
+ }
+ }
+ else
+ {
+ InternalJET2Platform.log(BasicDiagnostic.toIStatus(result));
+ }
+ }
- public String getDescription()
- {
- return ""; //$NON-NLS-1$
- }
+ /**
+ * Invoke a JET transform against the passed context
+ * @param id the JET Transform id
+ * @param context the JET2Context
+ * @param monitor a progress monitor
+ * @return the transform's execution status
+ */
+ public static IStatus runTransform(final String id, final JET2Context context, final IProgressMonitor monitor)
+ {
+ IStatus result;
+ monitor.beginTask(JET2Messages.JET2Platform_Executing + id, 100);
+ try
+ {
+ final IJETBundleManager bundleManager = getJETBundleManager();
+
+ if (bundleManager.getDescriptor(id) == null)
+ {
+ final String msg = MessageFormat.format(JET2Messages.JET2Platform_TransformNotFound, new Object []{ id });
+ result = InternalJET2Platform.newStatus(IStatus.ERROR, msg, null);
+ InternalJET2Platform.log(result);
+ return result;
+ }
+ monitor.subTask(JET2Messages.JET2Platform_RetrievingBundle);
+
+
+ if (DEBUG)
+ {
+ RuntimeLoggerContextExtender rl = new RuntimeLoggerContextExtender(context);
+ rl.addListener(new RuntimeTagLogger()
+ {
- public String getModelLoaderId()
- {
- return null;
- }
+ public void log(String message, TagInfo td, String templatePath)
+ {
+ int nlPos = message.indexOf(System.getProperty("line.separator")); //$NON-NLS-1$
+ if(nlPos >= 0) {
+ message = message.substring(0, nlPos);
+ }
+ System.out.println((templatePath == null ? "" : templatePath + " ") + td.toString() + ": " + message); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ });
+ }
- public String getModelExtension()
- {
- return null;
- }
+ bundleManager.run(id, new IJETRunnable() {
- public String getOverridesId()
+ public void run(IJETBundleDescriptor descriptor, JET2TemplateLoader templateLoader, IProgressMonitor monitor)
{
- return null;
- }
+ monitor.beginTask(JET2Messages.JET2Platform_Executing, 100);
+ final TransformContextExtender tce = TransformContextExtender.getInstance(context);
+ try
+ {
+ XPathContextExtender xpe = XPathContextExtender.getInstance(context);
+ xpe.addCustomFunctions(getInstalledXPathFunctions());
+
+ tce.setLoader(templateLoader);
+ tce.setBundleDescriptor(descriptor);
+ if(descriptor.getOverridesId() != null)
+ {
+ tce.setOverride(descriptor.getOverridesId(), new SubProgressMonitor(monitor, 10));
+ }
- public String getVersion()
- {
- return "1.0.0"; //$NON-NLS-1$
- }
+ BodyContentWriter bodyContentWriter = new BodyContentWriter();
- public String getProvider()
- {
- return ""; //$NON-NLS-1$
- }
+ final SubProgressMonitor templateMonitor = new SubProgressMonitor(monitor, 50);
+ templateMonitor.beginTask(JET2Messages.JET2Platform_ExecutingTemplates, IProgressMonitor.UNKNOWN);
+ try
+ {
+ tce.execute(descriptor.getMainTemplate(), bodyContentWriter);
+ }
+ finally
+ {
+ templateMonitor.done();
+ }
+ monitor.subTask(JET2Messages.JET2Platform_CommittingResults);
+ tce.commit(new SubProgressMonitor(monitor, 50));
+ }
+ catch (JET2TagException e)
+ {
+ context.logError(e);
+ }
+ finally
+ {
+ tce.cleanup();
+ monitor.done();
+ }
+ }}, new SubProgressMonitor(monitor, 90));
+
+ Diagnostic diagnostic = context.getLogAsMultiStatus();
+ if (diagnostic.getSeverity() != Diagnostic.OK)
+ {
+ processResults(id, diagnostic);
+ }
+ result = BasicDiagnostic.toIStatus(diagnostic);
+ }
+ catch (CoreJETException e)
+ {
+ result = BasicDiagnostic.toIStatus(e.getDiagnostic());
+ }
+ finally
+ {
+ monitor.done();
+ if(DEBUG) {
+ System.out.flush();
+ }
+ }
- public TagLibraryReference[] getTagLibraryReferences()
- {
- return new TagLibraryReference[] {
- new TagLibraryReferenceImpl("c", "org.eclipse.jet.controlTags", true), //$NON-NLS-1$ //$NON-NLS-2$
- new TagLibraryReferenceImpl("f", "org.eclipse.jet.formatTags", true), //$NON-NLS-1$ //$NON-NLS-2$
- new TagLibraryReferenceImpl("ws", "org.eclipse.jet.workspaceTags", false), //$NON-NLS-1$ //$NON-NLS-2$
- new TagLibraryReferenceImpl("java", "org.eclipse.jet.javaTags", true), //$NON-NLS-1$ //$NON-NLS-2$
- };
- }
+ return result;
+ }
- public String getTemplateLoaderClass()
- {
- return "org.eclipse.jet.compiled._jet_transformation"; //$NON-NLS-1$
- }
+ /**
+ * Execute a JET transform with the passed object as the root of the source model.
+ * @param id the JET Transform id
+ * @param source the source model root object.
+ * @param monitor a progress monitor
+ * @return the transform's execution status
+ */
+ public static IStatus runTransformOnObject(final String id, final Object source, final IProgressMonitor monitor)
+ {
+ final JET2Context context = new JET2Context(source);
+ return runTransform(id, context, monitor);
+ }
- public String getMainTemplate()
- {
- return "templates/control.jet"; //$NON-NLS-1$
- }
-
- };
+ /**
+ * Invoke a JET Transform on the pass resource, loading the resource using the transform's model loader.
+ * @param id the JET Transform id
+ * @param resource the Eclipse Resource to load
+ * @param monitor a progress monitor
+ * @return the transform's execution status
+ */
+ public static IStatus runTransformOnResource(final String id, final IResource resource, final IProgressMonitor monitor)
+ {
+ try
+ {
+ final IJETBundleDescriptor descriptor = getJETBundleManager().getDescriptor(id);
+ final JET2Context context = new JET2Context(null);
+
+ String loaderId = descriptor.getModelLoaderId();
+ String fileType = descriptor.getModelExtension();
+
+ WorkspaceContextExtender.loadResourceAsSource(context, resource, loaderId, fileType);
+
+ return runTransform(id, context, monitor);
+ }
+ catch (IOException e)
+ {
+ // didn't work.
+ return new Status(IStatus.ERROR, id, IStatus.OK, e.getLocalizedMessage(), e);
+ }
+ catch (CoreJETException e)
+ {
+ return BasicDiagnostic.toIStatus(e.getDiagnostic());
}
- return result;
}
/**
- * Test whether a project is an open JET project
- * @param project
- * @return
+ * Invoke a JET transform on the passed String representation of an XML model.
+ * @param id the transform id
+ * @param source the XML source, as a string
+ * @param monitor a progress monitor
+ * @return the transform execution status.
*/
- private static boolean isOpenJETProject(IProject project)
+ public static IStatus runTransformOnString(final String id, final String source, final IProgressMonitor monitor)
+ {
+ return runTransformOnString(id, source, "xml", monitor); //$NON-NLS-1$
+ }
+
+ /**
+ * Invoke a JET transform on the passed String representation of an input model.
+ * @param id the transform id
+ * @param source the string respresentation of the input model.
+ * @param kind the kind of model (file extension) the string represents.
+ * @param monitor a progress monitor
+ * @return the transform's execution status.
+ */
+ public static IStatus runTransformOnString(final String id, final String source, final String kind, final IProgressMonitor monitor)
{
+ IStatus result = Status.OK_STATUS;
+
+ JET2Context context = new JET2Context(null);
+
+ final IJETBundleDescriptor descriptor = getJETBundleManager().getDescriptor(id);
+ String modelLoaderID = descriptor.getModelLoaderId();
+
try
{
- return project != null && project.exists() && project.isOpen() && project.hasNature(JET2_NATURE_ID);
+ final Object sourceObject = TransformContextExtender.loadModelFromString(source, modelLoaderID, kind);
+ context.setSource(sourceObject);
+ result = runTransform(id, context, monitor);
}
- catch (CoreException e)
+ catch (CoreJETException e)
{
- return false;
+ result = BasicDiagnostic.toIStatus(e.getDiagnostic());
+ }
+ catch (IOException e)
+ {
+ result = InternalJET2Platform.newStatus(IStatus.ERROR, JET2Messages.JET2Platform_CouldNotParseString, e);
}
+
+ return result;
+ }
+
+ /**
+ *
+ */
+ private JET2Platform()
+ {
+ super();
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/launch/JET2TransformationDelegate.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/launch/JET2TransformationDelegate.java
index b678b2b..94abfe2 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/launch/JET2TransformationDelegate.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/launch/JET2TransformationDelegate.java
@@ -62,7 +62,7 @@ public class JET2TransformationDelegate implements ILaunchConfigurationDelegate
// TODO convert source to an appropriate object
- final IStatus status = JET2Platform.execute(id, source, monitor);
+ final IStatus status = JET2Platform.runTransformOnResource(id, source, monitor);
if(!status.isOK())
{