summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-04-06 04:09:26 (EDT)
committerpelder2006-04-06 04:09:26 (EDT)
commitd0b9babba1bde4cf2ae11f3728ba970516dd569d (patch)
tree4759411a264bd52e60284c1621a2f20626e42e8c
parent5859f0d3fa0037f1aa103e92a962ef839b9ce043 (diff)
downloadorg.eclipse.jet-d0b9babba1bde4cf2ae11f3728ba970516dd569d.zip
org.eclipse.jet-d0b9babba1bde4cf2ae11f3728ba970516dd569d.tar.gz
org.eclipse.jet-d0b9babba1bde4cf2ae11f3728ba970516dd569d.tar.bz2
[131192] Add parsing and use of information in plugin.xml
-rw-r--r--plugins/org.eclipse.jet/schema/transform.exsd14
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/CoreJETException.java (renamed from plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/CoreJETException.java)2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/ASTCompilerParseListener.java19
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2CompilationUnit.java34
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Compiler.java86
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/TagLibraryUsageManager.java86
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/InternalJET2Platform.java107
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/TransformData.java126
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/TransformDataFactory.java271
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/DeployedJETBundleProvider.java (renamed from plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/PluginDeployedTemplateBundleSupplier.java)179
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/DynamicJETBundleDescriptor.java45
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/IJET2Runnable.java35
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/IJET2TemplateBundleDescriptor.java42
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/IJET2TemplateBundleSupplier.java41
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/IJETBundleProvider.java50
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/InstalledJETBundleProvider.java194
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JET2Bundle.java182
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleDescriptor.java171
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleInstaller.java (renamed from plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/TemplateBundleManager.java)56
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleManager.java505
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleManifest.java67
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/PluginReferencedTemplateBundleDescriptor.java72
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/ProjectJETBundleDescriptor.java45
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/ProjectJETBundleProvider.java302
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/ProjectTemplateBundleDescriptor.java130
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/ProjectTemplateBundleSupplier.java256
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/TabLibraryReferenceImpl.java71
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/CoreExceptionWrapper.java1
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/LoaderManager.java1
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/runtime/model/ILoaderManager.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/WorkspaceContextExtender.java61
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/transform/IJETBundle.java52
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/transform/IJETBundleDescriptor.java8
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/transform/IJETBundleManager.java52
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/transform/IJETRunnable.java29
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/transform/TransformContextExtender.java130
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/runtime/TestBundleDescriptions.java18
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/runtime/TestBundleLoading.java75
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/control/LoadTagTests.java15
39 files changed, 2490 insertions, 1142 deletions
diff --git a/plugins/org.eclipse.jet/schema/transform.exsd b/plugins/org.eclipse.jet/schema/transform.exsd
index 5d8053e..111e1a4 100644
--- a/plugins/org.eclipse.jet/schema/transform.exsd
+++ b/plugins/org.eclipse.jet/schema/transform.exsd
@@ -61,7 +61,7 @@
<attribute name="startTemplate" type="string" use="required">
<annotation>
<documentation>
- The project relative path to the start template. Typically: template/control.jet
+ The project relative path to the main template in the transform. The main template serves as an entry point for the transform. Typical values: template/control.jet or template/main.jet
</documentation>
<appInfo>
<meta.attribute kind="resource"/>
@@ -81,7 +81,7 @@
<attribute name="modelLoader" type="string">
<annotation>
<documentation>
- A reference to the id of the model loader to use when loading Eclipse resources. If not specified, &apos;emf&apos; is used.
+ A reference to the id of the model loader to use when loading Eclipse resources. If not specified, a model loader is selected based on the file extension of the input model, or by the value of the &apos;modelExtension&apos; attribute.
</documentation>
</annotation>
</attribute>
@@ -92,6 +92,16 @@
</documentation>
</annotation>
</attribute>
+ <attribute name="modelExtension" type="string">
+ <annotation>
+ <documentation>
+ When specified, model loading ignores the file extension on the input model, and uses the value specified here instead. This can affect both the selection of a model loader (if the modelLoader attribute is not set), and the behavior of the selected model loader.
+&lt;p&gt;
+A typical use would be to force model loading to treat inputs as a specific type. For example, an Eclipse XML Schema file (exsd file extension) is an XML document that is not recognized by the XML model loaders. Setting the &apos;modelExtension&apos; attribute to &apos;xml&apos; would cause the model loading mechanism to treat an any input as if it had an &apos;xml&apos; extension.
+&lt;/p&gt;
+ </documentation>
+ </annotation>
+ </attribute>
</complexType>
</element>
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/CoreJETException.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/CoreJETException.java
index 3a1bdd9..003cdce 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/CoreJETException.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/CoreJETException.java
@@ -14,7 +14,7 @@
*
* $Id$
*/
-package org.eclipse.jet.internal.runtime.model;
+package org.eclipse.jet;
import org.eclipse.emf.common.util.Diagnostic;
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/ASTCompilerParseListener.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/ASTCompilerParseListener.java
index 209abd9..67fd129 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/ASTCompilerParseListener.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/ASTCompilerParseListener.java
@@ -19,6 +19,7 @@ package org.eclipse.jet.compiler;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -29,6 +30,7 @@ import org.eclipse.jet.internal.parser.JETReader;
import org.eclipse.jet.internal.parser.ParseProblemSeverity;
import org.eclipse.jet.taglib.TagDefinition;
import org.eclipse.jet.taglib.TagLibraryManager;
+import org.eclipse.jet.taglib.TagLibraryReference;
/**
@@ -170,10 +172,15 @@ class ASTCompilerParseListener implements JETParseEventListener2
public ASTCompilerParseListener(JET2CompilationUnit unit, JETReader reader)
{
+ this(unit, reader, Collections.EMPTY_MAP);
+ }
+
+ public ASTCompilerParseListener(JET2CompilationUnit unit, JETReader reader, Map predefinedLibraryMap)
+ {
compilationUnit = unit;
ast = compilationUnit.getAst();
this.reader = reader;
- tagLibManager = new TagLibraryUsageManager();
+ tagLibManager = new TagLibraryUsageManager(predefinedLibraryMap);
}
/**
@@ -222,13 +229,13 @@ class ASTCompilerParseListener implements JETParseEventListener2
stop.getCursor(),
start.getLine(), start.getCol());
}
- else if (tagLibManager.isPrefixDefined(prefix))
+ else if (!tagLibManager.canDefinePrefix(prefix, id))
{
compilationUnit.createProblem(
ParseProblemSeverity.ERROR,
Problem.DuplicateXMLNamespacePrefix,
JET2Messages.JET2Compiler_PrefixAlreadyAssigned,
- new Object []{ prefix, tagLibManager.getLibaryIdFromPrefix(prefix) },
+ new Object []{ prefix, tagLibManager.getLibraryIdFromPrefix(prefix) },
start.getCursor(),
stop.getCursor(),
start.getLine(), start.getCol());
@@ -518,4 +525,10 @@ class ASTCompilerParseListener implements JETParseEventListener2
compilationUnit.createProblem(severity, problemId, message, msgArgs, start, end, line, colOffset);
}
+ public TagLibraryReference[] getTagLibraryReferences()
+ {
+ TagLibraryReference[] result = tagLibManager.getTagLibraryReferences();
+
+ return result;
+ }
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2CompilationUnit.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2CompilationUnit.java
index 3534a31..b2bd65d 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2CompilationUnit.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2CompilationUnit.java
@@ -26,6 +26,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
@@ -37,7 +38,6 @@ import org.eclipse.jet.internal.parser.JETCoreElement;
import org.eclipse.jet.internal.parser.JETParser;
import org.eclipse.jet.internal.parser.JETReader;
import org.eclipse.jet.internal.parser.ParseProblemSeverity;
-import org.eclipse.jet.internal.taglib.TagLibraryReferenceImpl;
import org.eclipse.jet.taglib.TagLibraryReference;
@@ -64,6 +64,10 @@ public final class JET2CompilationUnit extends JET2ASTElement
private final IFile file;
+ private Map predefinedLibraryMap = Collections.EMPTY_MAP;
+
+ private TagLibraryReference[] tagLibraryReferences;
+
public JET2CompilationUnit()
{
super(new JET2AST(), -1, -1, -1, -1);
@@ -78,6 +82,16 @@ public final class JET2CompilationUnit extends JET2ASTElement
this.fileName = file.getFullPath().toString();
}
+ /**
+ * Define tag library prefixes (and associated tag library ids) that are
+ * automatically available to the transform.
+ * @param predefinedLibraryMap a map from prefix to tag library id.
+ */
+ public void setPredefinedTagLibraries(Map predefinedLibraryMap)
+ {
+ this.predefinedLibraryMap = predefinedLibraryMap;
+ }
+
public void parse(String document)
{
final String ENCODING = "UTF-8"; //$NON-NLS-1$
@@ -129,7 +143,9 @@ public final class JET2CompilationUnit extends JET2ASTElement
try
{
JETReader reader = new JETReader(fileName, contents, charset);
- ASTCompilerParseListener listener = new ASTCompilerParseListener(this, reader);
+
+ ASTCompilerParseListener listener = new ASTCompilerParseListener(this, reader,
+ predefinedLibraryMap != null ? predefinedLibraryMap : Collections.EMPTY_MAP);
JETParser.Directive directive = new JETParser.Directive();
directive.getDirectives().add("jet"); //$NON-NLS-1$
directive.getDirectives().add("taglib"); //$NON-NLS-1$
@@ -146,6 +162,7 @@ public final class JET2CompilationUnit extends JET2ASTElement
parser.parse();
listener.endPageProcessing();
+ tagLibraryReferences = listener.getTagLibraryReferences();
return;
}
catch (JETException e)
@@ -309,17 +326,6 @@ public final class JET2CompilationUnit extends JET2ASTElement
*/
public TagLibraryReference[] getTagLibraryReferences()
{
- final List result = new ArrayList();
- this.accept(new DefaultJET2ASTVisitor() {
- public void visit(JET2Directive directive)
- {
- if("taglib".equals(directive.getName())){ //$NON-NLS-1$
- String id = (String)directive.getAttributes().get("id"); //$NON-NLS-1$
- String prefix = (String)directive.getAttributes().get("prefix"); //$NON-NLS-1$
- result.add(new TagLibraryReferenceImpl(prefix, id, false));
- }
- }
- });
- return (TagLibraryReference[])result.toArray(new TagLibraryReference[result.size()]);
+ return tagLibraryReferences;
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Compiler.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Compiler.java
index 98429be..df842a7 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Compiler.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Compiler.java
@@ -20,7 +20,9 @@ package org.eclipse.jet.compiler;
import java.io.ByteArrayInputStream;
import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
import java.util.Properties;
import org.eclipse.core.resources.IContainer;
@@ -37,10 +39,14 @@ import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jet.JET2Platform;
import org.eclipse.jet.internal.InternalJET2Platform;
import org.eclipse.jet.internal.compiler.JET2CompilerState;
+import org.eclipse.jet.internal.compiler.LoaderGenerationParameters;
import org.eclipse.jet.internal.compiler.templates.JET2JavaGenerator;
import org.eclipse.jet.internal.compiler.templates.JET2TransformGenerator;
import org.eclipse.jet.internal.l10n.JET2Messages;
import org.eclipse.jet.internal.parser.ParseProblemSeverity;
+import org.eclipse.jet.taglib.TagLibraryReference;
+import org.eclipse.jet.transform.IJETBundleDescriptor;
+import org.eclipse.jet.transform.IJETBundleManager;
/**
@@ -63,16 +69,6 @@ public class JET2Compiler
public static final String OPTION_COMPILED_TEMPLATE_PACKAGE = "compiledTemplatePackage"; //$NON-NLS-1$
/**
- * Compiler option specifying the name of the generated template loader class; value: "templateLoaderClass".
- */
- public static final String OPTION_TEMPLATE_LOADER_CLASS = "templateLoaderClass"; //$NON-NLS-1$
-
- /**
- * Compiler option specifying the package to which the generated template laoder class is written; value: "templateLoaderPackage".
- */
- public static final String OPTION_TEMPLATE_LOADER_PACKAGE = "templateLoaderPackage"; //$NON-NLS-1$
-
- /**
* Compiler option specifying the Java project source directory to which compiled templates are written; value: "compiledTemplateSrcDir".
*/
public static final String OPTION_COMPILED_TEMPLATE_SRC_DIR = "compiledTemplateSrcDir"; //$NON-NLS-1$
@@ -88,16 +84,6 @@ public class JET2Compiler
public static final String DEFAULT_TEMPLATE_EXT = "jet"; //$NON-NLS-1$
/**
- * The default value of the {@link #OPTION_TEMPLATE_LOADER_CLASS} option; value: "_jet_transformation".
- */
- public static final String DEFAULT_TEMPLATE_LOADER_CLASS = "_jet_transformation"; //$NON-NLS-1$
-
- /**
- * The default value of the {@link #OPTION_TEMPLATE_LOADER_PACKAGE} option; value: "org.eclipse.jet.compiled".
- */
- public static final String DEFAULT_TEMPLATE_LOADER_PACKAGE = "org.eclipse.jet.compiled"; //$NON-NLS-1$
-
- /**
* The default value of the {@link #OPTION_COMPILED_TEMPLATE_SRC_DIR} option; value: "jet2java".
*/
public static final String DEFAULT_COMPILED_TEMPLATE_SRC_DIR = "jet2java"; //$NON-NLS-1$
@@ -117,6 +103,12 @@ public class JET2Compiler
private final Properties options;
+ private final Map predefinedLibraryMap;
+
+ private final String templateLoaderPackage;
+
+ private final String templateLoaderClassName;
+
/**
* Create an instance
* @param project the project upon which the compiler will act
@@ -134,6 +126,36 @@ public class JET2Compiler
this.noCompiles = 0;
+ final IJETBundleManager bundleManager = JET2Platform.getJETBundleManager();
+
+ final IJETBundleDescriptor descriptor = bundleManager.getDescriptorForProject(project.getName());
+ predefinedLibraryMap = getPredefinedPrefixMap(descriptor);
+
+ final String templateLoaderClass = descriptor.getTemplateLoaderClass();
+ if (templateLoaderClass != null)
+ {
+ int index = templateLoaderClass.lastIndexOf('.');
+ templateLoaderPackage = index >= 0 ? templateLoaderClass.substring(0, index) : ""; //$NON-NLS-1$
+ templateLoaderClassName = index >= 0 ? templateLoaderClass.substring(index + 1) : templateLoaderClass;
+ }
+ else
+ {
+ templateLoaderPackage = templateLoaderClassName = null;
+ }
+ }
+
+ private Map getPredefinedPrefixMap(IJETBundleDescriptor descriptor)
+ {
+ final TagLibraryReference[] tlRefs = descriptor.getTagLibraryReferences();
+ final Map result = new HashMap(tlRefs.length);
+ for (int i = 0; i < tlRefs.length; i++)
+ {
+ if (tlRefs[i].isAutoImport())
+ {
+ result.put(tlRefs[i].getPrefix(), tlRefs[i].getTagLibraryId());
+ }
+ }
+ return result;
}
/**
@@ -149,11 +171,13 @@ public class JET2Compiler
*/
private void createTemplateLoaderClass()
{
- String src = new JET2TransformGenerator().generate(compilerState.getTemplateMap());
+ if(templateLoaderClassName == null) return;
+
+ final LoaderGenerationParameters args = new LoaderGenerationParameters(templateLoaderPackage, templateLoaderClassName, compilerState.getTemplateMap());
+ String src = new JET2TransformGenerator().generate(args);
IPath targetPath = new Path(options.getProperty(OPTION_COMPILED_TEMPLATE_SRC_DIR, DEFAULT_COMPILED_TEMPLATE_SRC_DIR)).append(
- options.getProperty(OPTION_TEMPLATE_LOADER_PACKAGE, DEFAULT_TEMPLATE_LOADER_PACKAGE).replace('.', '/')).append(
- options.getProperty(OPTION_TEMPLATE_LOADER_CLASS, DEFAULT_TEMPLATE_LOADER_CLASS)).addFileExtension("java"); //$NON-NLS-1$
+ templateLoaderPackage.replace('.', '/')).append(templateLoaderClassName).addFileExtension("java"); //$NON-NLS-1$
try
{
@@ -211,6 +235,7 @@ public class JET2Compiler
}
JET2CompilationUnit cu = new JET2CompilationUnit(file);
+ cu.setPredefinedTagLibraries(predefinedLibraryMap);
try
{
cu.parse();
@@ -310,7 +335,7 @@ public class JET2Compiler
new Object []{ qualifiedClassName, compilerState.getTemplateFromClass(qualifiedClassName), },
-1,
-1,
- -1,
+ -1,
-1);
}
@@ -417,18 +442,17 @@ public class JET2Compiler
{
ensureDirsExist(targetFile.getParent());
- if(!targetFile.exists())
+ if (!targetFile.exists())
{
- targetFile.create(new ByteArrayInputStream(new byte[]{}), true, new SubProgressMonitor(monitor, 1));
+ targetFile.create(new ByteArrayInputStream(new byte []{}), true, new SubProgressMonitor(monitor, 1));
}
-
- if(!targetFile.getCharset().equals(charset))
+
+ if (!targetFile.getCharset().equals(charset))
{
targetFile.setCharset(charset, new SubProgressMonitor(monitor, 1));
}
-
- targetFile.setContents(new ByteArrayInputStream(javaSrc.getBytes(charset)),
- true, false, new SubProgressMonitor(monitor, 1));
+
+ targetFile.setContents(new ByteArrayInputStream(javaSrc.getBytes(charset)), true, false, new SubProgressMonitor(monitor, 1));
}
private void ensureDirsExist(IContainer container) throws CoreException
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/TagLibraryUsageManager.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/TagLibraryUsageManager.java
index 8b6694a..14c2718 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/TagLibraryUsageManager.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/TagLibraryUsageManager.java
@@ -4,12 +4,17 @@
package org.eclipse.jet.compiler;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
import java.util.Map;
+import org.eclipse.jet.internal.taglib.TagLibraryReferenceImpl;
import org.eclipse.jet.taglib.TagDefinition;
import org.eclipse.jet.taglib.TagLibrary;
import org.eclipse.jet.taglib.TagLibraryManager;
+import org.eclipse.jet.taglib.TagLibraryReference;
/**
@@ -20,18 +25,47 @@ public class TagLibraryUsageManager
{
private final Map tagLibraries = new HashMap();
+ private final Map predefinedLibraryMap;
/**
+ * @param predefinedLibraryMap a map of predefined prefixes and their tag libary ids.
*
*/
- public TagLibraryUsageManager()
+ public TagLibraryUsageManager(Map predefinedLibraryMap)
{
- super();
+ // make a defensive copy, we may change it...
+ this.predefinedLibraryMap = new HashMap(predefinedLibraryMap);
}
- public boolean isPrefixDefined(String prefix)
+ /**
+ * Test whether a prefix can be created.
+ * <p>
+ * Conditions where this can succeed:
+ * <bl>
+ * <li>prefix is not defined in either the predefined library map or the library map.</li>
+ * </bl>
+ * </p>
+ * @param prefix a prefix
+ * @param id the tag libary id.
+ * @return <code>true</code> if the prefix can be created.
+ */
+ public boolean canDefinePrefix(String prefix, String id)
{
- return tagLibraries.containsKey(prefix);
+
+ if( !tagLibraries.containsKey(prefix) && !predefinedLibraryMap.containsKey(prefix) )
+ {
+ return true;
+ }
+
+ // check for duplicate definitions of predefined libraries, this is ok, too.
+ if(id.equals(predefinedLibraryMap.get(prefix)))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
}
public boolean isLibraryDefined(String libaryId)
@@ -39,14 +73,34 @@ public class TagLibraryUsageManager
return tagLibraries.containsValue(libaryId);
}
- public String getLibaryIdFromPrefix(String prefix)
+ public String getLibraryIdFromPrefix(String prefix)
{
- return (String)tagLibraries.get(prefix);
+ String id = (String)tagLibraries.get(prefix);
+ if(id == null)
+ {
+ id = (String)predefinedLibraryMap.get(prefix);
+ }
+ return id;
}
+ /**
+ * Defined a prefix for a tag library id. If a prefix for the tag library id
+ * is already defined in the predefined librarys map, then that prefix is removed.
+ * @param prefix a prefix
+ * @param libraryId a library id
+ */
public void add(String prefix, String libraryId)
{
tagLibraries.put(prefix, libraryId);
+
+ for (Iterator i = predefinedLibraryMap.entrySet().iterator(); i.hasNext();)
+ {
+ Map.Entry entry = (Map.Entry)i.next();
+ if(libraryId.equals(entry.getValue()))
+ {
+ i.remove();
+ }
+ }
}
/**
@@ -59,7 +113,7 @@ public class TagLibraryUsageManager
int sepIndex = tagName.indexOf(':');
String prefix = sepIndex == -1 ? "" : tagName.substring(0, sepIndex); //$NON-NLS-1$
String tagNCName = sepIndex == -1 ? tagName : tagName.substring(sepIndex + 1);
- String id = (String)tagLibraries.get(prefix.toLowerCase());
+ String id = getLibraryIdFromPrefix(prefix.toLowerCase());
TagLibrary tagLibrary = TagLibraryManager.getInstance().getTagLibrary(id);
return tagLibrary.getTagDefinition(tagNCName);
}
@@ -75,7 +129,7 @@ public class TagLibraryUsageManager
int sepIndex = tagName.indexOf(':');
String prefix = sepIndex == -1 ? "" : tagName.substring(0, sepIndex); //$NON-NLS-1$
String tagNCName = sepIndex == -1 ? tagName : tagName.substring(sepIndex + 1);
- String id = (String)tagLibraries.get(prefix.toLowerCase());
+ String id = getLibraryIdFromPrefix(prefix.toLowerCase());
if (id != null)
{
TagLibrary tagLibrary = TagLibraryManager.getInstance().getTagLibrary(id);
@@ -84,4 +138,20 @@ public class TagLibraryUsageManager
return knownTag;
}
+ public TagLibraryReference[] getTagLibraryReferences()
+ {
+ List result = new ArrayList(predefinedLibraryMap.size() + tagLibraries.size());
+ for (Iterator i = predefinedLibraryMap.entrySet().iterator(); i.hasNext();)
+ {
+ Map.Entry entry = (Map.Entry)i.next();
+ result.add(new TagLibraryReferenceImpl((String)entry.getKey(), (String)entry.getValue(), true));
+ }
+ for (Iterator i = tagLibraries.entrySet().iterator(); i.hasNext();)
+ {
+ Map.Entry entry = (Map.Entry)i.next();
+ result.add(new TagLibraryReferenceImpl((String)entry.getKey(), (String)entry.getValue(), false));
+ }
+ return (TagLibraryReference[])result.toArray(new TagLibraryReference[result.size()]);
+ }
+
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/InternalJET2Platform.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/InternalJET2Platform.java
index d6dd649..1558315 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/InternalJET2Platform.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/InternalJET2Platform.java
@@ -17,16 +17,9 @@
package org.eclipse.jet.internal;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.common.EMFPlugin;
import org.eclipse.jet.JET2Platform;
@@ -35,14 +28,11 @@ import org.eclipse.jet.internal.compiler.JET2CompilerState;
import org.eclipse.jet.internal.extensionpoints.ModelInspectorsManager;
import org.eclipse.jet.internal.extensionpoints.ModelLoaderExtManager;
import org.eclipse.jet.internal.extensionpoints.XPathFunctionsManager;
-import org.eclipse.jet.internal.runtime.IJET2TemplateBundleDescriptor;
-import org.eclipse.jet.internal.runtime.IJET2TemplateBundleSupplier;
-import org.eclipse.jet.internal.runtime.PluginDeployedTemplateBundleSupplier;
-import org.eclipse.jet.internal.runtime.ProjectTemplateBundleSupplier;
-import org.eclipse.jet.internal.runtime.TemplateBundleManager;
+import org.eclipse.jet.internal.runtime.JETBundleInstaller;
+import org.eclipse.jet.internal.runtime.JETBundleManager;
import org.eclipse.jet.internal.taglib.InternalTagLibManager;
import org.eclipse.jet.taglib.TagLibrary;
-import org.eclipse.jet.transform.IJETBundle;
+import org.eclipse.jet.transform.IJETBundleManager;
import org.osgi.framework.BundleContext;
@@ -59,23 +49,15 @@ public class InternalJET2Platform extends EMFPlugin.EclipsePlugin
private InternalTagLibManager tagLibManager = null;
- private TemplateBundleManager transformBundleManager = null;
-
- private ProjectTemplateBundleSupplier projectTemplateBundleSupplier = null;
+ private JETBundleInstaller jetBundleInstaller = null;
- private PluginDeployedTemplateBundleSupplier pluginTemplateBundleSupplier = null;
-
private XPathFunctionsManager xpathFunctionsManager = null;
private ModelLoaderExtManager modelLoaderExtManager = null;
private ModelInspectorsManager modelInspectorExtManager = null;
-
- /**
- * A List of {@link org.eclipse.jet.internal.runtime.IJET2TemplateBundleSupplier} objects. The list order
- * is the order in transform search order.
- */
- private List templateBundleSuppliers = new ArrayList();
+
+ private JETBundleManager bundleManager = null;
/**
* Return the compiler state for the given project
@@ -231,35 +213,13 @@ public class InternalJET2Platform extends EMFPlugin.EclipsePlugin
return tagLibManager.getTagLibrary(id);
}
- public IJETBundle getTemplateBundle(String id, IProgressMonitor monitor) throws CoreException
- {
- if (monitor == null)
- {
- monitor = new NullProgressMonitor();
- }
- IJETBundle bundle = null;
- IJET2TemplateBundleDescriptor descriptor = null;
-
- for (Iterator i = templateBundleSuppliers.iterator(); i.hasNext() && descriptor == null;)
- {
- IJET2TemplateBundleSupplier supplier = (IJET2TemplateBundleSupplier)i.next();
- descriptor = supplier.findTemplateBundle(id);
- }
-
- if (descriptor != null)
- {
- bundle = descriptor.getTemplateBundle(monitor);
- }
- return bundle;
- }
-
/**
* Return the manager of transform bundles (compiled JET2 tranformations).
* @return the transform bundle manager
*/
- public TemplateBundleManager getTransformBundleManager()
+ public JETBundleInstaller getJETBundleInstaller()
{
- return transformBundleManager;
+ return jetBundleInstaller;
}
/**
@@ -276,18 +236,9 @@ public class InternalJET2Platform extends EMFPlugin.EclipsePlugin
tagLibManager = new InternalTagLibManager();
tagLibManager.startup();
- transformBundleManager = new TemplateBundleManager();
- transformBundleManager.startup(context);
-
- projectTemplateBundleSupplier = new ProjectTemplateBundleSupplier();
- projectTemplateBundleSupplier.startup();
+ jetBundleInstaller = new JETBundleInstaller();
+ jetBundleInstaller.startup(context);
- pluginTemplateBundleSupplier = new PluginDeployedTemplateBundleSupplier();
- pluginTemplateBundleSupplier.startup();
-
- templateBundleSuppliers.add(projectTemplateBundleSupplier);
- templateBundleSuppliers.add(pluginTemplateBundleSupplier);
-
xpathFunctionsManager = new XPathFunctionsManager();
xpathFunctionsManager.startup();
@@ -296,6 +247,9 @@ public class InternalJET2Platform extends EMFPlugin.EclipsePlugin
modelInspectorExtManager = new ModelInspectorsManager();
modelInspectorExtManager.startup();
+
+ bundleManager = new JETBundleManager();
+ bundleManager.startup();
}
/**
@@ -313,16 +267,8 @@ public class InternalJET2Platform extends EMFPlugin.EclipsePlugin
tagLibManager.shutdown();
tagLibManager = null;
- templateBundleSuppliers.clear();
-
- projectTemplateBundleSupplier.shutdown();
- projectTemplateBundleSupplier = null;
-
- pluginTemplateBundleSupplier.shutdown();
- pluginTemplateBundleSupplier = null;
-
- transformBundleManager.shutdown();
- transformBundleManager = null;
+ jetBundleInstaller.shutdown();
+ jetBundleInstaller = null;
xpathFunctionsManager.shutdown();
xpathFunctionsManager = null;
@@ -332,18 +278,9 @@ public class InternalJET2Platform extends EMFPlugin.EclipsePlugin
modelInspectorExtManager.shutdown();
modelInspectorExtManager = null;
- }
-
- public IJET2TemplateBundleDescriptor getTemplateBundleDescriptor(String id)
- {
- IJET2TemplateBundleDescriptor descriptor = null;
-
- for (Iterator i = templateBundleSuppliers.iterator(); i.hasNext() && descriptor == null;)
- {
- IJET2TemplateBundleSupplier supplier = (IJET2TemplateBundleSupplier)i.next();
- descriptor = supplier.findTemplateBundle(id);
- }
- return descriptor;
+
+ bundleManager.shutdown();
+ bundleManager = null;
}
/**
@@ -387,4 +324,12 @@ public class InternalJET2Platform extends EMFPlugin.EclipsePlugin
{
return tagLibManager;
}
+
+ /**
+ * @return Returns the bundleManager.
+ */
+ public final IJETBundleManager getBundleManager()
+ {
+ return bundleManager;
+ }
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/TransformData.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/TransformData.java
new file mode 100644
index 0000000..d668a5a
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/TransformData.java
@@ -0,0 +1,126 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.internal.extensionpoints;
+
+import org.eclipse.jet.taglib.TagLibraryReference;
+
+/**
+ * A invariant class that contains information from the Eclipse extension registry for the
+ * extension point 'org.eclipse.jet.transform'.
+ */
+public class TransformData
+{
+
+ private final String transformId;
+ private final String overridesId;
+ private final String modelLoaderId;
+ private final String modelExtension;
+ private final String templateLoaderClassName;
+ private final String mainTemplate;
+ private final TagLibraryReference[] tlRefs;
+ private final String description;
+
+ /**
+ * Construct a TransformData object.
+ * @param transformId
+ * @param overridesId
+ * @param modelLoaderId
+ * @param modelExtension
+ * @param templateLoaderClassName
+ * @param mainTemplate
+ * @param tlRefs
+ * @param description
+ */
+ public TransformData(String transformId, String overridesId,
+ String modelLoaderId, String modelExtension, String templateLoaderClassName,
+ String mainTemplate, TagLibraryReference[] tlRefs, String description)
+ {
+ this.transformId = transformId;
+ this.overridesId = overridesId == null || overridesId.length() == 0 ? null : overridesId;
+ this.modelLoaderId = modelLoaderId == null || modelLoaderId.length() == 0 ? null : modelLoaderId;
+ this.modelExtension = modelExtension == null || modelExtension.length() == 0 ? null : modelExtension;
+ this.templateLoaderClassName = templateLoaderClassName;
+ this.mainTemplate = mainTemplate;
+ this.tlRefs = tlRefs;
+ this.description = description;
+ }
+
+ /**
+ * @return Returns the mainTemplate.
+ */
+ public final String getMainTemplate()
+ {
+ return mainTemplate;
+ }
+
+ /**
+ * @return Returns the modelExtension.
+ */
+ public final String getModelExtension()
+ {
+ return modelExtension;
+ }
+
+ /**
+ * @return Returns the modelLoaderId.
+ */
+ public final String getModelLoaderId()
+ {
+ return modelLoaderId;
+ }
+
+ /**
+ * @return Returns the overridesId.
+ */
+ public final String getOverridesId()
+ {
+ return overridesId;
+ }
+
+ /**
+ * @return Returns the templateLoaderClassName.
+ */
+ public final String getTemplateLoaderClassName()
+ {
+ return templateLoaderClassName;
+ }
+
+ /**
+ * @return Returns the tlRefs.
+ */
+ public final TagLibraryReference[] getTagLibraryReferences()
+ {
+ return tlRefs;
+ }
+
+ /**
+ * @return Returns the transformId.
+ */
+ public final String getTransformId()
+ {
+ return transformId;
+ }
+
+ /**
+ * @return Returns the description.
+ */
+ public final String getDescription()
+ {
+ return description;
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/TransformDataFactory.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/TransformDataFactory.java
new file mode 100644
index 0000000..096f202
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/TransformDataFactory.java
@@ -0,0 +1,271 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.internal.extensionpoints;
+
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.InvalidRegistryObjectException;
+import org.eclipse.jet.CoreJETException;
+import org.eclipse.jet.internal.InternalJET2Platform;
+import org.eclipse.jet.internal.JETActivatorWrapper;
+import org.eclipse.jet.internal.taglib.TagLibraryReferenceImpl;
+import org.eclipse.jet.taglib.TagLibraryReference;
+import org.eclipse.jet.xpath.NodeSet;
+import org.eclipse.jet.xpath.XPath;
+import org.eclipse.jet.xpath.XPathException;
+import org.eclipse.jet.xpath.XPathExpression;
+import org.eclipse.jet.xpath.XPathFactory;
+
+
+/**
+ * A class than translates Extension Registry data into TransformData instances
+ */
+public class TransformDataFactory
+{
+ public static final String E_TRANSFORM = "transform"; //$NON-NLS-1$
+
+ public static final String A_TRANSFORM_STARTTEMPLATE = "startTemplate"; //$NON-NLS-1$
+
+ public static final String A_TRANSFORM_TEMPLATELOADERCLASS = "templateLoaderClass"; //$NON-NLS-1$
+
+ public static final String A_TRANSFORM_MODELLOADER = "modelLoader"; //$NON-NLS-1$
+
+ public static final String A_TRANSFORM_MODELEXTENSION = "modelExtension"; //$NON-NLS-1$
+
+ public static final String A_TRANSFORM_OVERRIDES = "overrides"; //$NON-NLS-1$
+
+ public static final String E_TAGLIBRARIES = "tagLibraries"; //$NON-NLS-1$
+
+ public static final String E_IMPORTLIBRARY = "importLibrary"; //$NON-NLS-1$
+
+ public static final String A_IMPORTLIBRARY_ID = "id"; //$NON-NLS-1$
+
+ public static final String A_IMPORTLIBRARY_USEPREFIX = "usePrefix"; //$NON-NLS-1$
+
+ public static final String A_IMPORTLIBRARY_AUTOIMPORT = "autoImport"; //$NON-NLS-1$
+
+ public static final String E_DESCRIPTION = "description"; //$NON-NLS-1$
+
+ public static final TransformDataFactory INSTANCE = new TransformDataFactory();
+
+ private boolean expresionsInitialized = false;
+
+ private XPathExpression xTransform;
+
+ private XPathExpression xTransformModelLoader;
+
+ private XPathExpression xTransformModelExtension;
+
+ private XPathExpression xTransformOverrides;
+
+ private XPathExpression xTransformStartTemplate;
+
+ private XPathExpression xTransformTemplateLoaderClass;
+
+ private XPathExpression xDescription;
+
+ private XPathExpression xTagLibrariesImportLibrary;
+
+ private XPathExpression xImportLibraryId;
+
+ private XPathExpression xImportLibraryUsePrefix;
+
+ private XPathExpression xImportLibraryAutoImport;
+
+ private TransformDataFactory()
+ {
+ // prevent instantiation by others
+ }
+
+ private void initXPathExpressions() throws XPathException
+ {
+ if (!expresionsInitialized)
+ {
+ final XPath xpath = XPathFactory.newInstance().newXPath(null);
+
+ xTransform = xpath.compile("/plugin/extension[@point = 'org.eclipse.jet.transform']/transform"); //$NON-NLS-1$
+ xTransformModelLoader = xpath.compile("@" + A_TRANSFORM_MODELLOADER); //$NON-NLS-1$
+ xTransformModelExtension = xpath.compile("@" + A_TRANSFORM_MODELEXTENSION); //$NON-NLS-1$
+ xTransformOverrides = xpath.compile("@" + A_TRANSFORM_OVERRIDES); //$NON-NLS-1$
+ xTransformStartTemplate = xpath.compile("@" + A_TRANSFORM_STARTTEMPLATE); //$NON-NLS-1$
+ xTransformTemplateLoaderClass = xpath.compile("@" + A_TRANSFORM_TEMPLATELOADERCLASS); //$NON-NLS-1$
+ xDescription = xpath.compile(E_DESCRIPTION);
+ xTagLibrariesImportLibrary = xpath.compile("tagLibraries/importLibrary"); //$NON-NLS-1$
+
+ xImportLibraryId = xpath.compile("@" + A_IMPORTLIBRARY_ID); //$NON-NLS-1$
+ xImportLibraryUsePrefix = xpath.compile("@" + A_IMPORTLIBRARY_USEPREFIX); //$NON-NLS-1$
+ xImportLibraryAutoImport = xpath.compile("@" + A_IMPORTLIBRARY_AUTOIMPORT); //$NON-NLS-1$
+
+ expresionsInitialized = true;
+ }
+ }
+
+ public TransformData createTransformData(String transformId, URL pluginURL)
+ {
+ TransformData transformData = null;
+
+ try
+ {
+ URL extensionsURL = new URL(pluginURL, "plugin.xml"); //$NON-NLS-1$
+ Object resource = JETActivatorWrapper.INSTANCE.getLoaderManager().getLoader(extensionsURL.toExternalForm(), null, null).load(extensionsURL);
+
+ initXPathExpressions();
+
+ final NodeSet transformSet = xTransform.evaluateAsNodeSet(resource);
+
+ if (transformSet.size() > 0)
+ {
+ transformData = createTransformData(transformId, transformSet.iterator().next());
+ }
+ }
+ catch (IOException e)
+ {
+ // ignore, plugin.xml doesn't exist.
+ }
+ catch (CoreJETException e)
+ {
+ InternalJET2Platform.logError("", e); //$NON-NLS-1$
+ }
+ catch (XPathException e)
+ {
+ InternalJET2Platform.logError("", e); //$NON-NLS-1$
+ }
+
+ return transformData;
+ }
+
+ /**
+ * @param transformId
+ * @param transform
+ * @return
+ */
+ public TransformData createTransformData(String transformId, final Object transform)
+ {
+ String modelLoaderId = xTransformModelLoader.evaluateAsString(transform);
+ String modelExtension = xTransformModelExtension.evaluateAsString(transform);
+ String overridesId = xTransformOverrides.evaluateAsString(transform);
+ String mainTemplate = xTransformStartTemplate.evaluateAsString(transform);
+ String templateLoaderClassName = xTransformTemplateLoaderClass.evaluateAsString(transform);
+ String description = xDescription.evaluateAsString(transform);
+
+ final NodeSet importNodes = xTagLibrariesImportLibrary.evaluateAsNodeSet(transform);
+
+ List tlRefs = new ArrayList();
+ for (Iterator i = importNodes.iterator(); i.hasNext();)
+ {
+ Object importCtx = i.next();
+
+ final String tlId = xImportLibraryId.evaluateAsString(importCtx);
+ final String tlPrefix = xImportLibraryUsePrefix.evaluateAsString(importCtx);
+ boolean autoImport = Boolean.valueOf(xImportLibraryAutoImport.evaluateAsString(importCtx)).booleanValue();
+
+ TagLibraryReference tlRef = new TagLibraryReferenceImpl(tlPrefix, tlId, autoImport);
+ tlRefs.add(tlRef);
+ }
+
+ TransformData transformData = new TransformData(
+ transformId,
+ overridesId,
+ modelLoaderId,
+ modelExtension,
+ templateLoaderClassName,
+ mainTemplate,
+ (TagLibraryReference[])tlRefs.toArray(new TagLibraryReference [tlRefs.size()]),
+ description);
+ return transformData;
+ }
+
+ /**
+ * Create transformData from the passed configuration element
+ * @param element an 'transform' configuration element
+ * @return a TransformData object, or <code>null</code> if the element is not a 'transform' element.
+ * @throws InvalidRegistryObjectException if the configuration element is invalid
+ */
+ public TransformData createTransformData(final IConfigurationElement element) throws InvalidRegistryObjectException
+ {
+ TransformData transformData = null;
+ if (element != null && E_TRANSFORM.equals(element.getName()))
+ {
+ String transformId = element.getDeclaringExtension().getNamespace();
+ String modelLoaderId = element.getAttribute(A_TRANSFORM_MODELLOADER);
+ String modelExtension = element.getAttribute(A_TRANSFORM_MODELEXTENSION);
+ String overridesId = element.getAttribute(A_TRANSFORM_OVERRIDES);
+ String mainTemplate = element.getAttribute(A_TRANSFORM_STARTTEMPLATE);
+ String templateLoaderClassName = element.getAttribute(A_TRANSFORM_TEMPLATELOADERCLASS);
+
+ TagLibraryReference[] tlRefs = getTagLibraryReferences(element);
+
+ String description = getDescription(element);
+
+ transformData = new TransformData(
+ transformId,
+ overridesId,
+ modelLoaderId,
+ modelExtension,
+ templateLoaderClassName,
+ mainTemplate,
+ tlRefs,
+ description);
+ }
+ return transformData;
+ }
+
+ private String getDescription(IConfigurationElement element)
+ {
+ String description = ""; //$NON-NLS-1$
+ final IConfigurationElement[] descElements = element.getChildren(E_DESCRIPTION);
+ if (descElements.length > 0)
+ {
+ description = descElements[0].getValue();
+ }
+ return description;
+ }
+
+ /**
+ * @param element
+ * @return
+ * @throws InvalidRegistryObjectException
+ */
+ private TagLibraryReference[] getTagLibraryReferences(final IConfigurationElement element) throws InvalidRegistryObjectException
+ {
+ List tlRefs = new ArrayList();
+ final IConfigurationElement[] tlElements = element.getChildren(E_TAGLIBRARIES);
+ for (int j = 0; j < tlElements.length; j++)
+ {
+ IConfigurationElement tlElement = tlElements[j];
+
+ final IConfigurationElement[] tlImports = tlElement.getChildren(E_IMPORTLIBRARY);
+ for (int k = 0; k < tlImports.length; k++)
+ {
+ final String tlId = tlImports[k].getAttribute(A_IMPORTLIBRARY_ID);
+ final String tlPrefix = tlImports[k].getAttribute(A_IMPORTLIBRARY_USEPREFIX);
+ boolean autoImport = Boolean.valueOf(tlImports[k].getAttribute(A_IMPORTLIBRARY_AUTOIMPORT)).booleanValue();
+
+ TagLibraryReference tlRef = new TagLibraryReferenceImpl(tlPrefix, tlId, autoImport);
+ tlRefs.add(tlRef);
+ }
+ }
+ return (TagLibraryReference[])tlRefs.toArray(new TagLibraryReference [tlRefs.size()]);
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/PluginDeployedTemplateBundleSupplier.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/DeployedJETBundleProvider.java
index 88bd662..a1168c2 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/PluginDeployedTemplateBundleSupplier.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/DeployedJETBundleProvider.java
@@ -1,11 +1,11 @@
/**
* <copyright>
*
- * Copyright (c) 2005 IBM Corporation and others.
+ * Copyright (c) 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
+ * are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
+ * http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
@@ -14,19 +14,22 @@
*
* $Id$
*/
-
package org.eclipse.jet.internal.runtime;
-
+import java.io.IOException;
+import java.net.MalformedURLException;
import java.net.URL;
import java.text.MessageFormat;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionDelta;
import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IRegistryChangeEvent;
import org.eclipse.core.runtime.IRegistryChangeListener;
import org.eclipse.core.runtime.IStatus;
@@ -34,20 +37,20 @@ import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.jet.JET2Platform;
import org.eclipse.jet.internal.InternalJET2Platform;
+import org.eclipse.jet.internal.extensionpoints.TransformData;
+import org.eclipse.jet.internal.extensionpoints.TransformDataFactory;
import org.eclipse.jet.internal.l10n.JET2Messages;
+import org.eclipse.jet.transform.IJETBundleDescriptor;
import org.osgi.framework.Bundle;
-
+import org.osgi.framework.BundleException;
/**
- * A supplier of template bundles deployed in eclipse plugins and referenced by the
- * "org.eclipse.jet.deployedTransforms" extension point.
- *
+ * Provider for JET Bundles deployed by the org.eclipse.jet.deployedTransforms extension point.
*/
-public class PluginDeployedTemplateBundleSupplier implements IJET2TemplateBundleSupplier, IRegistryChangeListener
+public class DeployedJETBundleProvider implements IJETBundleProvider, IRegistryChangeListener
{
-
private static boolean DEBUG = InternalJET2Platform.getDefault().isDebugging()
- && Boolean.valueOf(Platform.getDebugOption("org.eclipse.jet/debug/pluginBundleLoading")).booleanValue(); //$NON-NLS-1$
+ && Boolean.valueOf(Platform.getDebugOption("org.eclipse.jet/debug/pluginBundleLoading")).booleanValue(); //$NON-NLS-1$
private static final String PLUGIN_ID = JET2Platform.PLUGIN_ID;
@@ -61,32 +64,38 @@ public class PluginDeployedTemplateBundleSupplier implements IJET2TemplateBundle
private static final String BUNDLE_ATTRIBUTE = "bundle"; //$NON-NLS-1$
- private final Map idToBundleURLMap = new HashMap();
+ private final Map descriptorsById = Collections.synchronizedMap(new HashMap());
/**
*
*/
- public PluginDeployedTemplateBundleSupplier()
+ public DeployedJETBundleProvider()
{
super();
}
/* (non-Javadoc)
- * @see org.eclipse.jet.internal.runtime.IJET2TransformSupplier#findTransformation(java.lang.String)
+ * @see org.eclipse.jet.internal.runtime.IJETBundleProvider#getAllJETBundleIds()
*/
- public IJET2TemplateBundleDescriptor findTemplateBundle(String id)
+ public Set getAllJETBundleIds()
{
- IJET2TemplateBundleDescriptor result = null;
- URL bundle = (URL)idToBundleURLMap.get(id);
- if (bundle != null)
- {
- if (DEBUG)
- {
- InternalJET2Platform.debugMessage(this, "findTempalteBundle(" + id + ") found match"); //$NON-NLS-1$//$NON-NLS-2$
- }
- result = new PluginReferencedTemplateBundleDescriptor(bundle);
- }
- return result;
+ return descriptorsById.keySet();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.internal.runtime.IJETBundleProvider#getDescriptor(java.lang.String)
+ */
+ public IJETBundleDescriptor getDescriptor(String id)
+ {
+ return (IJETBundleDescriptor)descriptorsById.get(id);
+ }
+
+ public void shutdown()
+ {
+ IExtensionRegistry reg = Platform.getExtensionRegistry();
+ reg.removeRegistryChangeListener(this);
+
+ descriptorsById.clear();
}
public void startup()
@@ -98,23 +107,76 @@ public class PluginDeployedTemplateBundleSupplier implements IJET2TemplateBundle
reg.addRegistryChangeListener(this, EXTENSION_POINT_ID);
}
- private void addTransforms(IConfigurationElement[] configElements)
+ public void registryChanged(IRegistryChangeEvent event)
+ {
+ IExtensionDelta[] deltas = event.getExtensionDeltas(EXTENSION_POINT_ID);
+
+ for (int i = 0; i < deltas.length; i++)
+ {
+ IExtension ext = deltas[i].getExtension();
+ if (deltas[i].getKind() == IExtensionDelta.ADDED)
+ {
+ addTransforms(ext.getConfigurationElements());
+ }
+ else
+ {
+ removeTransforms(ext.getConfigurationElements());
+ }
+ }
+ }
+
+ private void removeTransforms(IConfigurationElement[] configElements)
{
for (int i = 0; i < configElements.length; i++)
{
if (DEPLOYEDTRANSFORM_ELEMENT.equals(configElements[i].getName()))
{
- // TODO: Would it not be better to get the id out of the bundle?
String id = configElements[i].getAttribute(ID_ATTRIBUTE);
+ if (id != null)
+ {
+ if (DEBUG)
+ {
+ InternalJET2Platform.debugMessage(this, "removeTransforms(" + id + ")"); //$NON-NLS-1$//$NON-NLS-2$
+ }
+ descriptorsById.remove(id);
+ }
+ }
+ }
+ }
+
+ private void addTransforms(IConfigurationElement[] configElements)
+ {
+ for (int i = 0; i < configElements.length; i++)
+ {
+ if (DEPLOYEDTRANSFORM_ELEMENT.equals(configElements[i].getName()))
+ {
+ // Ignore the 'id' attribute, and get the bundle id from the bundle itself.
+// String id = configElements[i].getAttribute(ID_ATTRIBUTE);
String jet2Bundle = configElements[i].getAttribute(BUNDLE_ATTRIBUTE);
- if (id != null && jet2Bundle != null)
+ if (jet2Bundle != null)
{
Bundle declaringBundle = Platform.getBundle(configElements[i].getDeclaringExtension().getNamespace());
- URL jet2BundleURL = declaringBundle.getEntry(jet2Bundle);
- idToBundleURLMap.put(id, jet2BundleURL);
- if (DEBUG)
+ try
+ {
+ URL bundleURL = declaringBundle.getEntry(jet2Bundle);
+ URL jarURL = new URL("jar", "", bundleURL.toExternalForm() + "!/"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ JETBundleManifest manifest = JETBundleManager.loadManifest(jarURL);
+ TransformData transformData = TransformDataFactory.INSTANCE.createTransformData(manifest.getTransformId(), jarURL);
+
+ final DynamicJETBundleDescriptor descriptor = new DynamicJETBundleDescriptor(manifest, transformData, jarURL, bundleURL);
+ descriptorsById.put(descriptor.getId(), descriptor);
+ if (DEBUG)
+ {
+ InternalJET2Platform.debugMessage(this, "addTransforms(" + descriptor.getId() + ", " + jarURL + ")"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ }
+ }
+ catch (MalformedURLException e)
+ {
+ InternalJET2Platform.logError("Unexpected failure getting deployed transform information.", e); //$NON-NLS-1$
+ }
+ catch (IOException e)
{
- InternalJET2Platform.debugMessage(this, "addTransform(" + id + ", " + jet2BundleURL + ")"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ InternalJET2Platform.logError("Unexpected failure reading deployed transform manifest.", e); //$NON-NLS-1$
}
}
else
@@ -132,48 +194,33 @@ public class PluginDeployedTemplateBundleSupplier implements IJET2TemplateBundle
}
}
- public void shutdown()
+ public Bundle load(String id, IProgressMonitor monitor) throws BundleException
{
- IExtensionRegistry reg = Platform.getExtensionRegistry();
- reg.removeRegistryChangeListener(this);
-
- idToBundleURLMap.clear();
+ Bundle bundle = null;
+ final DynamicJETBundleDescriptor descriptor = (DynamicJETBundleDescriptor)getDescriptor(id);
+ if(descriptor != null)
+ {
+ bundle = InternalJET2Platform.getDefault().getJETBundleInstaller().installBundle(descriptor.getBundleURL());
+ if(DEBUG) System.out.println("[deployedBundle] Loaded " + bundle.getSymbolicName()); //$NON-NLS-1$
+ }
+ return bundle;
}
- public void registryChanged(IRegistryChangeEvent event)
+ public void unload(String id) throws BundleException
{
- IExtensionDelta[] deltas = event.getExtensionDeltas(EXTENSION_POINT_ID);
-
- for (int i = 0; i < deltas.length; i++)
+ if(descriptorsById.containsKey(id))
{
- IExtension ext = deltas[i].getExtension();
- if (deltas[i].getKind() == IExtensionDelta.ADDED)
- {
- addTransforms(ext.getConfigurationElements());
- }
- else
- {
- removeTransforms(ext.getConfigurationElements());
- }
+ Bundle bundle = Platform.getBundle(id);
+ unload(bundle);
}
}
- private void removeTransforms(IConfigurationElement[] configElements)
+ public void unload(Bundle bundle) throws BundleException
{
- for (int i = 0; i < configElements.length; i++)
+ if(bundle != null)
{
- if (DEPLOYEDTRANSFORM_ELEMENT.equals(configElements[i].getName()))
- {
- String id = configElements[i].getAttribute(ID_ATTRIBUTE);
- if (id != null)
- {
- if (DEBUG)
- {
- InternalJET2Platform.debugMessage(this, "removeTransforms(" + id + ")"); //$NON-NLS-1$//$NON-NLS-2$
- }
- idToBundleURLMap.remove(id);
- }
- }
+ if(DEBUG) System.out.println("[deployedBundle] Unloading " + bundle.getSymbolicName()); //$NON-NLS-1$
+ bundle.uninstall();
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/DynamicJETBundleDescriptor.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/DynamicJETBundleDescriptor.java
new file mode 100644
index 0000000..71a2e85
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/DynamicJETBundleDescriptor.java
@@ -0,0 +1,45 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.internal.runtime;
+
+import java.net.URL;
+
+import org.eclipse.jet.internal.extensionpoints.TransformData;
+
+/**
+ * Bundle descriptor for a dynmically loadable JET Bundle.
+ */
+public class DynamicJETBundleDescriptor extends JETBundleDescriptor
+{
+
+ private final URL bundleURL;
+
+ public DynamicJETBundleDescriptor(JETBundleManifest manifest, TransformData transformData, URL jarURL, URL bundleURL)
+ {
+ super(manifest, transformData, jarURL);
+ this.bundleURL = bundleURL;
+ }
+
+ /**
+ * @return Returns the bundleURL.
+ */
+ public final URL getBundleURL()
+ {
+ return bundleURL;
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/IJET2Runnable.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/IJET2Runnable.java
deleted file mode 100644
index 0822c9e..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/IJET2Runnable.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-
-package org.eclipse.jet.internal.runtime;
-
-
-import org.eclipse.emf.common.util.Diagnostic;
-import org.eclipse.jet.JET2TemplateLoader;
-import org.eclipse.jet.taglib.JET2TagException;
-
-
-/**
- * Encapsulate of actions that may be run against the dynamically loaded JET2 transform.
- *
- */
-public interface IJET2Runnable
-{
-
- public abstract Diagnostic run(JET2TemplateLoader loader) throws JET2TagException;
-
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/IJET2TemplateBundleDescriptor.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/IJET2TemplateBundleDescriptor.java
deleted file mode 100644
index 8668709..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/IJET2TemplateBundleDescriptor.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-
-package org.eclipse.jet.internal.runtime;
-
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jet.transform.IJETBundle;
-
-
-/**
- * A description of a JET2 template bundle. The intent of the descriptor is to represent
- * template bundle information that can be obtained without loading the template bundle itself.
- *
- */
-public interface IJET2TemplateBundleDescriptor
-{
-
- /**
- * Load the template bundle represented by the descriptor
- * @param monitor a progress monitor
- * @return the transformation loader
- * @throws CoreException if transformation cannot be loaded, or of the load has been cancelled.
- */
- public abstract IJETBundle getTemplateBundle(IProgressMonitor monitor) throws CoreException;
-
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/IJET2TemplateBundleSupplier.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/IJET2TemplateBundleSupplier.java
deleted file mode 100644
index 8487d6f..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/IJET2TemplateBundleSupplier.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-
-package org.eclipse.jet.internal.runtime;
-
-
-/**
- * Represent a supplier of JET2 Transformations. Anticipated suppliers are:
- * <bl>
- * <li>the Eclipse Workspace</li>
- * <li>a shared respository specificed by a preference</li>
- * <li>a workspace local repository</li>
- * <li>installed plugins, via an extension point</li>
- * </bl>
- */
-public interface IJET2TemplateBundleSupplier
-{
-
- /**
- * Find the transformation descriptor for the given ID.
- * @param id a transformation id. Cannot be <code>null</code>.
- * @return the transformation descriptor or <code>null</code> if not found.
- * @throws NullPointerException if <code>id</code> is <code>null</code>.
- */
- public abstract IJET2TemplateBundleDescriptor findTemplateBundle(String id);
-
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/IJETBundleProvider.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/IJETBundleProvider.java
new file mode 100644
index 0000000..1a31d7a
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/IJETBundleProvider.java
@@ -0,0 +1,50 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.internal.runtime;
+
+import java.util.Set;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jet.transform.IJETBundleDescriptor;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+
+/**
+ * Interface for JETBundle providers managed by {@link JETBundleManager}.
+ */
+public interface IJETBundleProvider
+{
+
+ public abstract IJETBundleDescriptor getDescriptor(String id);
+
+ public abstract Set getAllJETBundleIds();
+
+ public abstract void startup();
+
+ public abstract void shutdown();
+
+ public abstract Bundle load(String id, IProgressMonitor monitor) throws BundleException;
+
+ /**
+ * @deprecated
+ * @param id
+ * @throws BundleException
+ */
+ public abstract void unload(String id) throws BundleException;
+
+ public abstract void unload(Bundle bundle) throws BundleException;
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/InstalledJETBundleProvider.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/InstalledJETBundleProvider.java
new file mode 100644
index 0000000..2d012d0
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/InstalledJETBundleProvider.java
@@ -0,0 +1,194 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+
+package org.eclipse.jet.internal.runtime;
+
+
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionDelta;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IRegistryChangeEvent;
+import org.eclipse.core.runtime.IRegistryChangeListener;
+import org.eclipse.core.runtime.InvalidRegistryObjectException;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jet.internal.extensionpoints.TransformDataFactory;
+import org.eclipse.jet.transform.IJETBundleDescriptor;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+
+
+/**
+ * Eclpise extension registry listener for the 'org.eclipse.jet.transform' extension point.
+ *
+ */
+public final class InstalledJETBundleProvider implements IRegistryChangeListener, IJETBundleProvider
+{
+
+ private static final String PLUGIN_ID = "org.eclipse.jet"; //$NON-NLS-1$
+
+ private static final String EXTENSION_NAME = "transform"; //$NON-NLS-1$
+
+ private static final String EXTENSION_POINT_ID = PLUGIN_ID + "." + EXTENSION_NAME; //$NON-NLS-1$
+
+ /**
+ * Map&lt;String, IJETBundleDescription&gt; where String is a transformId.
+ */
+ private final Map pluginBundleDescriptorsById = Collections.synchronizedMap(new HashMap());
+
+ /**
+ *
+ */
+ public InstalledJETBundleProvider()
+ {
+ }
+
+ /**
+ * Initialize the list of tabLibrary extensions currently loaded.
+ * @param bundleManager
+ *
+ */
+ public void startup()
+ {
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+
+ addConfigElements(registry.getConfigurationElementsFor(EXTENSION_POINT_ID));
+
+ registry.addRegistryChangeListener(this, PLUGIN_ID);
+ }
+
+ /**
+ * Update the cache of extensions currently loaded
+ */
+ public void registryChanged(IRegistryChangeEvent event)
+ {
+ IExtensionDelta[] deltas = event.getExtensionDeltas(EXTENSION_POINT_ID);
+
+ for (int i = 0; i < deltas.length; i++)
+ {
+ IExtension ext = deltas[i].getExtension();
+ if (deltas[i].getKind() == IExtensionDelta.ADDED)
+ {
+ addConfigElements(ext.getConfigurationElements());
+ }
+ else
+ {
+ removeConfigElements(ext.getConfigurationElements());
+ }
+ }
+ }
+
+ /**
+ * Release all held resources in preparation for shutting down.
+ *
+ */
+ public void shutdown()
+ {
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ registry.removeRegistryChangeListener(this);
+ registry = null;
+ }
+
+ /**
+ * @param configElements
+ */
+ private void addConfigElements(IConfigurationElement[] configElements)
+ {
+ for (int i = 0; i < configElements.length; i++)
+ {
+ final IConfigurationElement element = configElements[i];
+ if (TransformDataFactory.E_TRANSFORM.equals(element.getName()))
+ {
+ String transformId = element.getDeclaringExtension().getNamespace();
+ addJETPlugin(transformId, element);
+ }
+ }
+ }
+
+ private void removeConfigElements(IConfigurationElement[] configElements)
+ {
+ for (int i = 0; i < configElements.length; i++)
+ {
+ final IConfigurationElement element = configElements[i];
+ if (TransformDataFactory.E_TRANSFORM.equals(element.getName()))
+ {
+ String transformId = element.getDeclaringExtension().getNamespace();
+ removeJETPlugin(transformId);
+
+ }
+ }
+ }
+
+ public Set getAllJETBundleIds()
+ {
+ return pluginBundleDescriptorsById.keySet();
+ }
+
+ public IJETBundleDescriptor getDescriptor(String id)
+ {
+ return (IJETBundleDescriptor)pluginBundleDescriptorsById.get(id);
+ }
+
+ public void addJETPlugin(String id, IConfigurationElement transformElement)
+ {
+ try
+ {
+ final Bundle bundle = Platform.getBundle(id);
+ final JETBundleManifest manifest = new JETBundleManifest(bundle.getHeaders(Platform.getNL()));
+ pluginBundleDescriptorsById.put(id,
+ new JETBundleDescriptor(manifest, TransformDataFactory.INSTANCE.createTransformData(transformElement),
+ bundle.getEntry("/"))); //$NON-NLS-1$
+ }
+ catch (InvalidRegistryObjectException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void removeJETPlugin(String id)
+ {
+ pluginBundleDescriptorsById.remove(id);
+ }
+
+ public Bundle load(String id, IProgressMonitor monitor)
+ {
+ Bundle bundle = null;
+ if(pluginBundleDescriptorsById.containsKey(id))
+ {
+ bundle = Platform.getBundle(id);
+ }
+ return bundle;
+ }
+
+ public void unload(String id)
+ {
+ // nothing to do...
+ }
+
+ public void unload(Bundle bundle) throws BundleException
+ {
+ // nothing to do...
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JET2Bundle.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JET2Bundle.java
deleted file mode 100644
index 48b3322..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JET2Bundle.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-
-package org.eclipse.jet.internal.runtime;
-
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.jar.JarFile;
-import java.util.jar.Manifest;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.emf.common.util.Diagnostic;
-import org.eclipse.jet.JET2TemplateLoader;
-import org.eclipse.jet.internal.InternalJET2Platform;
-import org.eclipse.jet.internal.l10n.JET2Messages;
-import org.eclipse.jet.taglib.JET2TagException;
-import org.eclipse.jet.transform.IJETBundle;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.Constants;
-
-
-/**
- * Implementation of a JET2 bundle.
- *
- */
-public class JET2Bundle implements IJETBundle
-{
-
- public static final String JET2_TRANSFORM_LOADER_ATTRIBUTE = "JET2-TransformClass"; //$NON-NLS-1$
-
- private final URL bundleURL;
-
- private final String name;
-
- private final String id;
-
- private final String loaderClassName;
-
- public JET2Bundle(URL bundleURL) throws IOException
- {
- this.bundleURL = bundleURL;
-
- // Read the bundle manifest. Don't use JarInputStream#getManifest()
- // because Eclipse doesn't (as of 3.2M4 and earlier) correctly build plugin jars
- // as proper jars (it uses <zip> instead.
- // To work around this, we use 'jar' URL protocols to extract the manifest file...
- InputStream manifestInput = null;
-
- try
- {
- URL manifestURL;
- if (bundleURL.getFile().endsWith(".jar")) { //$NON-NLS-1$
- URL jarContentsBaseURL = new URL("jar", "", bundleURL + "!/"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- manifestURL = new URL(jarContentsBaseURL, JarFile.MANIFEST_NAME);
- }
- else
- {
- manifestURL = new URL(bundleURL, JarFile.MANIFEST_NAME);
- }
- manifestInput = manifestURL.openStream();
- Manifest manifest = new Manifest(manifestInput);
- name = manifest.getMainAttributes().getValue(Constants.BUNDLE_NAME);
- id = manifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
- loaderClassName = manifest.getMainAttributes().getValue(JET2_TRANSFORM_LOADER_ATTRIBUTE);
- }
- finally
- {
- if (manifestInput != null)
- {
- try
- {
- manifestInput.close();
- }
- catch (IOException e)
- {
- // there is nothing we can do on a failed close, and throwing from a finally is bad form
- // silently fail.
- }
-
- }
- }
-
- }
-
- /**
- * @return Returns the bundleURL.
- */
- public final URL getBundleURL()
- {
- return bundleURL;
- }
-
- /**
- * @return Returns the id.
- */
- public final String getId()
- {
- return id;
- }
-
- /**
- * @return Returns the name.
- */
- public final String getName()
- {
- return name;
- }
-
- /**
- * @return Returns the transformClass.
- */
- public final String getLoaderClassName()
- {
- return loaderClassName;
- }
-
- public Diagnostic execute(IJET2Runnable runnable) throws CoreException
- {
- TemplateBundleManager bundleManager = InternalJET2Platform.getDefault().getTransformBundleManager();
- Diagnostic result;
-
- Bundle bundle = null;
- try
- {
- bundle = bundleManager.installBundle(bundleURL);
- Class txClass = bundle.loadClass(loaderClassName);
- final Object loaderObject = txClass.newInstance();
- JET2TemplateLoader loader = (JET2TemplateLoader)loaderObject;
- result = runnable.run(loader);
- }
- catch (ClassNotFoundException e)
- {
- throw new CoreException(InternalJET2Platform.newStatus(IStatus.ERROR, JET2Messages.JET2Bundle_CouldNotLoadLoader, e));
- }
- catch (InstantiationException e)
- {
- throw new CoreException(InternalJET2Platform.newStatus(IStatus.ERROR, JET2Messages.JET2Bundle_CouldNotInstantiateLoader, e));
- }
- catch (IllegalAccessException e)
- {
- throw new CoreException(InternalJET2Platform.newStatus(IStatus.ERROR, JET2Messages.JET2Bundle_NoRightsToLoadLoader, e));
- }
- catch (JET2TagException e)
- {
- throw new CoreException(InternalJET2Platform.newStatus(IStatus.ERROR, JET2Messages.JET2Bundle_CouldNotLoadTemplate, e));
- }
- finally
- {
- if (bundle != null)
- {
- try
- {
- bundleManager.uninstallBundle(bundle);
- }
- catch (CoreException e)
- {
- InternalJET2Platform.logError(JET2Messages.JET2Bundle_CouldNotLoadJetBundle, e);
- }
- }
- }
-
- return result;
- }
-
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleDescriptor.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleDescriptor.java
new file mode 100644
index 0000000..cbd55f5
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleDescriptor.java
@@ -0,0 +1,171 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.internal.runtime;
+
+import java.net.URL;
+
+import org.eclipse.jet.internal.extensionpoints.TransformData;
+import org.eclipse.jet.taglib.TagLibraryReference;
+import org.eclipse.jet.transform.IJETBundleDescriptor;
+
+/**
+ * Implementation of {@link IJETBundleDescriptor}.
+ */
+public class JETBundleDescriptor implements IJETBundleDescriptor
+{
+
+ public static final String MAIN_TEMPLATE_DEFAULT = "templates/control.jet"; //$NON-NLS-1$
+
+ private final String id;
+ private final String name;
+ private final String description;
+ private final String modelLoaderId;
+ private final String modelExtension;
+ private final String overridesId;
+ private final String version;
+ private final String provider;
+ private final String templateLoaderClass;
+ private final String mainTemplate;
+ private final TagLibraryReference[] tagLibraryReferences;
+
+ private final URL baseURL;
+
+ public JETBundleDescriptor(JETBundleManifest jetManifest, TransformData transformData, URL baseURL)
+ {
+ this.id = jetManifest.getTransformId();
+ this.name = jetManifest.getName();
+ this.version = jetManifest.getVersion();
+ this.provider = jetManifest.getProvider();
+ this.baseURL = baseURL;
+
+ if(transformData == null)
+ {
+ this.templateLoaderClass = jetManifest.getTemplateLoaderClassName();
+ this.mainTemplate = MAIN_TEMPLATE_DEFAULT;
+ this.description = ""; //$NON-NLS-1$
+ this.overridesId = null;
+ this.modelLoaderId = null;
+ this.modelExtension = null;
+ this.tagLibraryReferences = new TagLibraryReference[0];
+ }
+ else
+ {
+ this.templateLoaderClass = transformData.getTemplateLoaderClassName();
+ this.mainTemplate = transformData.getMainTemplate();
+ this.description = transformData.getDescription();
+ this.overridesId = transformData.getOverridesId();
+ this.modelLoaderId = transformData.getModelLoaderId();
+ this.modelExtension = transformData.getModelExtension();
+ this.tagLibraryReferences = transformData.getTagLibraryReferences();
+
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.transform.IJETBundleDescriptor#getId()
+ */
+ public String getId()
+ {
+ return id;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.transform.IJETBundleDescriptor#getName()
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.transform.IJETBundleDescriptor#getDescription()
+ */
+ public String getDescription()
+ {
+ return description;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.transform.IJETBundleDescriptor#getModelLoaderId()
+ */
+ public String getModelLoaderId()
+ {
+ return modelLoaderId;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.transform.IJETBundleDescriptor#getModelExtension()
+ */
+ public String getModelExtension()
+ {
+ return modelExtension;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.transform.IJETBundleDescriptor#getOverridesId()
+ */
+ public String getOverridesId()
+ {
+ return overridesId;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.transform.IJETBundleDescriptor#getVersion()
+ */
+ public String getVersion()
+ {
+ return version;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.transform.IJETBundleDescriptor#getProvider()
+ */
+ public String getProvider()
+ {
+ return provider;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.transform.IJETBundleDescriptor#getTagLibraryReferences()
+ */
+ public TagLibraryReference[] getTagLibraryReferences()
+ {
+ return tagLibraryReferences;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.transform.IJETBundleDescriptor#getTemplateLoaderClass()
+ */
+ public String getTemplateLoaderClass()
+ {
+ return templateLoaderClass;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.transform.IJETBundleDescriptor#getMainTemplate()
+ */
+ public String getMainTemplate()
+ {
+ return mainTemplate;
+ }
+
+ public URL getBaseURL()
+ {
+ return baseURL;
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/TemplateBundleManager.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleInstaller.java
index 57b827e..550f876 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/TemplateBundleManager.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleInstaller.java
@@ -20,11 +20,7 @@ package org.eclipse.jet.internal.runtime;
import java.net.URL;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jet.JET2Platform;
-import org.eclipse.jet.internal.l10n.JET2Messages;
+import org.eclipse.jet.internal.InternalJET2Platform;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
@@ -35,7 +31,7 @@ import org.osgi.framework.BundleException;
* into the workbench..
*
*/
-public class TemplateBundleManager
+public class JETBundleInstaller
{
private BundleContext bundleContext = null;
@@ -43,7 +39,7 @@ public class TemplateBundleManager
/**
*
*/
- public TemplateBundleManager()
+ public JETBundleInstaller()
{
super();
}
@@ -70,45 +66,29 @@ public class TemplateBundleManager
* Install an OSGi bundle.
* @param bundleURL the external form of the URL of a bundle to install.
* @return the OSGi bundle the loaded OSGi bundle
- * @throws CoreException if the bundle cannot be loaded.
+ * @throws BundleException if the bundle cannot be loaded.
*/
- public Bundle installBundle(URL bundleURL) throws CoreException
+ public Bundle installBundle(URL bundleURL) throws BundleException
{
- try
- {
- return bundleContext.installBundle(bundleURL.toExternalForm());
- }
- catch (BundleException e)
- {
- throw new CoreException(new Status(
- IStatus.ERROR,
- JET2Platform.PLUGIN_ID,
- IStatus.OK,
- JET2Messages.TemplateBundleManager_CannotLoad,
- e));
- }
+ final Bundle bundle = bundleContext.installBundle(bundleURL.toExternalForm());
+
+ // 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(bundle.getSymbolicName());
+ InternalJET2Platform.getDefault().getTagLibManager().forceRefresh(bundle.getSymbolicName());
+
+ return bundle;
}
/**
* Uninstall a JET2 bundle
- * @param bundle
- * @throws CoreException
+ * @param bundle the bundle to unload
+ * @throws BundleException if the bundle cannot be unloaded
*/
- public void uninstallBundle(Bundle bundle) throws CoreException
+ public void uninstallBundle(Bundle bundle) throws BundleException
{
- try
- {
bundle.uninstall();
- }
- catch (BundleException e)
- {
- throw new CoreException(new Status(
- IStatus.ERROR,
- JET2Platform.PLUGIN_ID,
- IStatus.OK,
- JET2Messages.TemplateBundleManager_CannotUnload,
- e));
- }
-
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleManager.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleManager.java
new file mode 100644
index 0000000..454b712
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleManager.java
@@ -0,0 +1,505 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.internal.runtime;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.jar.Attributes;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.emf.common.util.BasicDiagnostic;
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.jet.CoreJETException;
+import org.eclipse.jet.JET2Platform;
+import org.eclipse.jet.JET2TemplateLoader;
+import org.eclipse.jet.internal.InternalJET2Platform;
+import org.eclipse.jet.internal.l10n.JET2Messages;
+import org.eclipse.jet.transform.IJETBundleDescriptor;
+import org.eclipse.jet.transform.IJETBundleManager;
+import org.eclipse.jet.transform.IJETRunnable;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+
+/**
+ * A Manager for JET bundles
+ */
+public class JETBundleManager implements IJETBundleManager
+{
+
+ private static class BundleWrapper {
+ private final Bundle bundle;
+ private int refCount;
+ private final IJETBundleProvider provider;
+
+ public BundleWrapper(IJETBundleProvider provider, Bundle bundle)
+ {
+ this.provider = provider;
+ this.bundle = bundle;
+ refCount = 0;
+ }
+
+ public void connect()
+ {
+ ++refCount;
+ }
+
+ public void disconnect()
+ {
+ --refCount;
+ }
+
+ public Bundle getBundle()
+ {
+ return bundle;
+ }
+
+ public boolean isDisconnected()
+ {
+ return refCount <= 0;
+ }
+
+ /**
+ * @return Returns the provider.
+ */
+ public final IJETBundleProvider getProvider()
+ {
+ return provider;
+ }
+ }
+ /**
+ * @param is
+ */
+ private static void ensureStreamClosed(InputStream is)
+ {
+ if(is != null)
+ {
+ try
+ {
+ is.close();
+ }
+ catch(IOException e)
+ {
+ // do nothing
+ }
+ }
+ }
+
+ public static JETBundleManifest loadManifest(URL pluginURL) throws IOException
+ {
+ URL manifestURL = new URL(pluginURL, JarFile.MANIFEST_NAME);
+
+ InputStream manifestStream = null;
+ try
+ {
+ manifestStream = manifestURL.openStream();
+ Manifest m = new Manifest(manifestStream);
+ return new JETBundleManifest(manifestToProperties(m.getMainAttributes()));
+ }
+ finally
+ {
+ ensureStreamClosed(manifestStream);
+ }
+ }
+
+ private static Properties manifestToProperties(Attributes d) {
+ Iterator iter = d.keySet().iterator();
+ Properties result = new Properties();
+ while (iter.hasNext()) {
+ Attributes.Name key = (Attributes.Name) iter.next();
+ result.put(key.toString(), d.get(key));
+ }
+ return result;
+}
+
+ private InstalledJETBundleProvider installedBundleProvider;
+
+ private ProjectJETBundleProvider projectBundleProvider;
+
+ private DeployedJETBundleProvider deployedBundleProvider;
+
+ private IJETBundleProvider[] providerSearchOrder;
+
+ private Map bundlesById = new HashMap();
+
+ public JETBundleManager()
+ {
+ // do nothing
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.internal.runtime.IJETBundleManager#getAllJETBundleDescriptors()
+ */
+ public IJETBundleDescriptor[] getAllJETBundleDescriptors()
+ {
+
+ final String[] allIds = getAllTransformIds();
+ IJETBundleDescriptor[] result = new IJETBundleDescriptor[allIds.length];
+ for (int i = 0; i < allIds.length; i++)
+ {
+ result[i] = getDescriptor(allIds[i]);
+
+ }
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.internal.runtime.IJETBundleManager#getDescriptor(java.lang.String)
+ */
+ public IJETBundleDescriptor getDescriptor(String id)
+ {
+ IJETBundleDescriptor descriptor = null;
+ for (int i = 0; i < providerSearchOrder.length && descriptor == null; i++)
+ {
+ IJETBundleProvider provider = providerSearchOrder[i];
+ descriptor = provider.getDescriptor(id);
+ }
+ return descriptor;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.internal.runtime.IJETBundleManager#getDescriptorForProject(java.lang.String)
+ */
+ public IJETBundleDescriptor getDescriptorForProject(String name)
+ {
+ return projectBundleProvider.getDescriptorForProject(name);
+ }
+
+// /**
+// * @param bundleURL
+// * @return
+// * @throws MalformedURLException
+// * @throws IOException
+// */
+// private ResourceBundle getResourceBundle(URL bundleURL)
+// {
+// InputStream isPluginProperties = null;
+// ResourceBundle translationBundle = null;
+// try
+// {
+// URL urlPluginProperties = new URL(bundleURL, "plugin.properties"); //$NON-NLS-1$
+// isPluginProperties = urlPluginProperties.openStream();
+// translationBundle = new PropertyResourceBundle(isPluginProperties);
+// }
+// catch (IOException e)
+// {
+// // didn't work, do nothing;
+// }
+// finally
+// {
+// ensureStreamClosed(isPluginProperties);
+// }
+// return translationBundle;
+// }
+
+ public void shutdown()
+ {
+ for (Iterator i = bundlesById.values().iterator(); i.hasNext();)
+ {
+ BundleWrapper wrappedBundle = (BundleWrapper)i.next();
+ try
+ {
+ wrappedBundle.getProvider().unload(wrappedBundle.getBundle());
+ }
+ catch (BundleException e)
+ {
+ InternalJET2Platform.logError(JET2Messages.JET2Bundle_CouldNotLoadJetBundle, e);
+ }
+ }
+ bundlesById.clear();
+
+ installedBundleProvider.shutdown();
+ installedBundleProvider = null;
+
+ projectBundleProvider.shutdown();
+ projectBundleProvider = null;
+
+ deployedBundleProvider.shutdown();
+ deployedBundleProvider = null;
+
+ providerSearchOrder = null;
+ }
+
+
+ public void startup()
+ {
+ // setup the extension 'org.eclipse.jet.transform' listener on loaded Eclipse plug-ins
+ installedBundleProvider = new InstalledJETBundleProvider();
+ installedBundleProvider.startup();
+
+ projectBundleProvider = new ProjectJETBundleProvider();
+ projectBundleProvider.startup();
+
+ deployedBundleProvider = new DeployedJETBundleProvider();
+ deployedBundleProvider.startup();
+
+ // Note: The order here is significant. Changing it will have impacts on
+ // which transform is found.
+ providerSearchOrder = new IJETBundleProvider[] {
+ installedBundleProvider,
+ projectBundleProvider,
+ deployedBundleProvider,
+ };
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.internal.runtime.IJETBundleManager#getProjectForId(java.lang.String)
+ */
+ public String getProjectForId(String id)
+ {
+ return projectBundleProvider.getProjectForId(id);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.internal.runtime.IJETBundleManager#run(java.lang.String, org.eclipse.jet.transform.IJETRunnable, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public void run(String id, IJETRunnable runnable, IProgressMonitor monitor) throws CoreJETException
+ {
+ monitor.beginTask(JET2Messages.JET2Platform_Executing, 100);
+ try
+ {
+ connect(id, new SubProgressMonitor(monitor, 10));
+ try
+ {
+ final IJETBundleDescriptor descriptor = getDescriptor(id);
+ JET2TemplateLoader loader = getTemplateLoader(id);
+ runnable.run(descriptor, loader, new SubProgressMonitor(monitor, 90));
+ }
+ finally
+ {
+ disconnect(id);
+ }
+ }
+ finally
+ {
+ monitor.done();
+ }
+
+ }
+ public void runOld(String id, IJETRunnable runnable, IProgressMonitor monitor) throws CoreJETException
+ {
+ IJETBundleProvider provider = null;
+ Bundle bundle = null;
+ monitor.beginTask(JET2Messages.JET2Platform_Executing, 100);
+ try
+ {
+ final IJETBundleDescriptor descriptor = getDescriptor(id);
+ provider = getProvider(id);
+ if(provider != null)
+ {
+ bundle = provider.load(id, new SubProgressMonitor(monitor, 10));
+ }
+ if(bundle != null)
+ {
+ final Class loader = bundle.loadClass(descriptor.getTemplateLoaderClass());
+ final Object newInstance = loader.newInstance();
+ if(newInstance instanceof JET2TemplateLoader)
+ {
+ runnable.run(descriptor, (JET2TemplateLoader)newInstance, new SubProgressMonitor(monitor, 90));
+ }
+ }
+ }
+ catch (BundleException e)
+ {
+ throw new CoreJETException(
+ new BasicDiagnostic(Diagnostic.ERROR, JET2Platform.PLUGIN_ID, IStatus.OK,
+ JET2Messages.TemplateBundleManager_CannotLoad, new Object[] {e}));
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new CoreJETException(
+ new BasicDiagnostic(Diagnostic.ERROR, JET2Platform.PLUGIN_ID, IStatus.OK,
+ JET2Messages.JET2Bundle_CouldNotLoadLoader, new Object[] {e}));
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new CoreJETException(
+ new BasicDiagnostic(Diagnostic.ERROR, JET2Platform.PLUGIN_ID, IStatus.OK,
+ JET2Messages.JET2Bundle_CouldNotInstantiateLoader, new Object[] {e}));
+ }
+ catch (InstantiationException e)
+ {
+ throw new CoreJETException(
+ new BasicDiagnostic(Diagnostic.ERROR, JET2Platform.PLUGIN_ID, IStatus.OK,
+ JET2Messages.JET2Bundle_CouldNotInstantiateLoader, new Object[] {e}));
+ }
+ finally
+ {
+ if(bundle != null)
+ {
+ try
+ {
+ provider.unload(bundle);
+ }
+ catch (BundleException e)
+ {
+ InternalJET2Platform.logError(JET2Messages.JET2Bundle_CouldNotLoadJetBundle, e);
+ }
+ }
+ monitor.done();
+ }
+
+ }
+
+
+ private IJETBundleProvider getProvider(String id)
+ {
+ for (int i = 0; i < providerSearchOrder.length; i++)
+ {
+ IJETBundleProvider provider = providerSearchOrder[i];
+ if(providerSearchOrder[i].getDescriptor(id) != null)
+ {
+ return provider;
+ }
+ }
+ return null;
+ }
+
+ public void connect(final String id, final IProgressMonitor monitor) throws CoreJETException
+ {
+ BundleWrapper wrappedBundle = null;
+ synchronized(bundlesById)
+ {
+ wrappedBundle = (BundleWrapper)bundlesById.get(id);
+
+ if(wrappedBundle == null)
+ {
+ IJETBundleProvider provider = getProvider(id);
+ if(provider != null)
+ {
+ Bundle bundle;
+ try
+ {
+ bundle = provider.load(id, monitor);
+ }
+ catch (BundleException e)
+ {
+ throw new CoreJETException(
+ new BasicDiagnostic(Diagnostic.ERROR, JET2Platform.PLUGIN_ID, IStatus.OK,
+ JET2Messages.TemplateBundleManager_CannotLoad, new Object[] {e}));
+ }
+ wrappedBundle = new BundleWrapper(provider, bundle);
+
+ bundlesById.put(id, wrappedBundle);
+ }
+ }
+ if(wrappedBundle != null)
+ {
+ wrappedBundle.connect();
+ }
+ else
+ {
+ throw new CoreJETException(
+ new BasicDiagnostic(Diagnostic.ERROR, JET2Platform.PLUGIN_ID, IStatus.OK,
+ JET2Messages.TemplateBundleManager_CannotLoad, null));
+ }
+ }
+ }
+
+ public void disconnect(String id)
+ {
+ synchronized(bundlesById)
+ {
+ BundleWrapper wrappedBundle = (BundleWrapper)bundlesById.get(id);
+ if(wrappedBundle == null)
+ {
+ return;
+ }
+
+ wrappedBundle.disconnect();
+ if(wrappedBundle.isDisconnected())
+ {
+ bundlesById.remove(id);
+ try
+ {
+ wrappedBundle.getProvider().unload(wrappedBundle.getBundle());
+ }
+ catch (BundleException e)
+ {
+ InternalJET2Platform.logError(JET2Messages.JET2Bundle_CouldNotLoadJetBundle, e);
+ }
+ }
+ }
+ }
+
+ public JET2TemplateLoader getTemplateLoader(String id) throws CoreJETException
+ {
+ synchronized(bundlesById)
+ {
+ final BundleWrapper wrappedBundle = (BundleWrapper)bundlesById.get(id);
+ if(wrappedBundle != null)
+ {
+ try
+ {
+ final Class loaderClass = wrappedBundle.getBundle().loadClass(wrappedBundle.getProvider().getDescriptor(id).getTemplateLoaderClass());
+ final Object newInstance = loaderClass.newInstance();
+ if(newInstance instanceof JET2TemplateLoader)
+ {
+ return (JET2TemplateLoader)newInstance;
+ }
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new CoreJETException(
+ new BasicDiagnostic(Diagnostic.ERROR, JET2Platform.PLUGIN_ID, IStatus.OK,
+ JET2Messages.JET2Bundle_CouldNotLoadLoader, new Object[] {e}));
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new CoreJETException(
+ new BasicDiagnostic(Diagnostic.ERROR, JET2Platform.PLUGIN_ID, IStatus.OK,
+ JET2Messages.JET2Bundle_CouldNotInstantiateLoader, new Object[] {e}));
+ }
+ catch (InstantiationException e)
+ {
+ throw new CoreJETException(
+ new BasicDiagnostic(Diagnostic.ERROR, JET2Platform.PLUGIN_ID, IStatus.OK,
+ JET2Messages.JET2Bundle_CouldNotInstantiateLoader, new Object[] {e}));
+ }
+ }
+ }
+ throw new CoreJETException(new BasicDiagnostic(Diagnostic.ERROR, JET2Platform.PLUGIN_ID, IStatus.OK,
+ JET2Messages.JET2Bundle_CouldNotLoadLoader, null));
+ }
+
+ public String[] getAllTransformIds()
+ {
+ SortedSet allIds = new TreeSet();
+ for (int i = 0; i < providerSearchOrder.length; i++)
+ {
+ IJETBundleProvider provider = providerSearchOrder[i];
+
+ allIds.addAll(provider.getAllJETBundleIds());
+ }
+ return (String[])allIds.toArray(new String[allIds.size()]);
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleManifest.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleManifest.java
new file mode 100644
index 0000000..396674b
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleManifest.java
@@ -0,0 +1,67 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.internal.runtime;
+
+import java.util.Dictionary;
+
+import org.osgi.framework.Constants;
+
+/**
+ * Wraps a Dictionary representing the MANIFEST.MF file for a JET bundle.
+ */
+public class JETBundleManifest
+{
+
+ private final Dictionary manifest;
+ public static final String JET2_TRANSFORM_LOADER_ATTRIBUTE = "JET2-TransformClass"; //$NON-NLS-1$
+
+ /**
+ *
+ */
+ public JETBundleManifest(Dictionary manifest)
+ {
+ this.manifest = manifest;
+ }
+
+ public String getTransformId()
+ {
+ final String rawId = (String)manifest.get(Constants.BUNDLE_SYMBOLICNAME);
+ int index = rawId.indexOf(';');
+
+ return index >= 0 ? rawId.substring(0, index) : rawId;
+ }
+
+ public String getName()
+ {
+ return (String)manifest.get(Constants.BUNDLE_NAME);
+ }
+
+ public String getVersion()
+ {
+ return (String)manifest.get(Constants.BUNDLE_VERSION);
+ }
+
+ public String getProvider()
+ {
+ return (String)manifest.get(Constants.BUNDLE_VENDOR);
+ }
+
+ public String getTemplateLoaderClassName()
+ {
+ return (String)manifest.get(JETBundleManifest.JET2_TRANSFORM_LOADER_ATTRIBUTE);
+ }
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/PluginReferencedTemplateBundleDescriptor.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/PluginReferencedTemplateBundleDescriptor.java
deleted file mode 100644
index ebc8a87..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/PluginReferencedTemplateBundleDescriptor.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-
-package org.eclipse.jet.internal.runtime;
-
-
-import java.io.IOException;
-import java.net.URL;
-import java.text.MessageFormat;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jet.internal.InternalJET2Platform;
-import org.eclipse.jet.internal.l10n.JET2Messages;
-import org.eclipse.jet.transform.IJETBundle;
-
-
-/**
- * Descriptor for JET bundle desclared in a Eclipse plugin.
- *
- */
-public class PluginReferencedTemplateBundleDescriptor implements IJET2TemplateBundleDescriptor
-{
-
- private final URL bundleURL;
-
- /**
- * @param bundle
- *
- */
- public PluginReferencedTemplateBundleDescriptor(URL bundle)
- {
- super();
- this.bundleURL = bundle;
- }
-
- public IJETBundle getTemplateBundle(IProgressMonitor monitor) throws CoreException
- {
- monitor.beginTask(MessageFormat.format(JET2Messages.PluginReferencedTemplateBundleDescriptor_Retrieving, new Object []{ bundleURL }), 1);
- try
- {
- return new JET2Bundle(bundleURL);
-
- }
- catch (IOException e)
- {
- throw new CoreException(InternalJET2Platform.newStatus(IStatus.ERROR, MessageFormat.format(
- JET2Messages.JET2Bundle_ErrorOpeningJar,
- new Object []{ bundleURL.toExternalForm() }), null));
- }
- finally
- {
- monitor.done();
- }
- }
-
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/ProjectJETBundleDescriptor.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/ProjectJETBundleDescriptor.java
new file mode 100644
index 0000000..aaf4091
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/ProjectJETBundleDescriptor.java
@@ -0,0 +1,45 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.internal.runtime;
+
+import java.net.URL;
+
+import org.eclipse.jet.internal.extensionpoints.TransformData;
+
+/**
+ * Define a specialization of JETBundleDescriptor for project-based transforms.
+ */
+public class ProjectJETBundleDescriptor extends JETBundleDescriptor
+{
+
+ private final String projectName;
+
+ public ProjectJETBundleDescriptor(JETBundleManifest manifest, TransformData transformData, URL projectURL, String projectName)
+ {
+ super(manifest, transformData, projectURL);
+ this.projectName = projectName;
+ }
+
+ /**
+ * @return Returns the projectName.
+ */
+ public final String getProjectName()
+ {
+ return projectName;
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/ProjectJETBundleProvider.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/ProjectJETBundleProvider.java
new file mode 100644
index 0000000..085a123
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/ProjectJETBundleProvider.java
@@ -0,0 +1,302 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.internal.runtime;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.jar.JarFile;
+
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IResourceDeltaVisitor;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.jobs.IJobManager;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jet.JET2Platform;
+import org.eclipse.jet.internal.InternalJET2Platform;
+import org.eclipse.jet.internal.extensionpoints.TransformData;
+import org.eclipse.jet.internal.extensionpoints.TransformDataFactory;
+import org.eclipse.jet.internal.l10n.JET2Messages;
+import org.eclipse.jet.transform.IJETBundleDescriptor;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+
+/**
+ * Monitor workspace changes in JET project manifests
+ */
+public class ProjectJETBundleProvider implements IResourceChangeListener, IJETBundleProvider
+{
+
+ /**
+ * Map&lt;String, IJETBundleDescription&gt; where String is a transformId.
+ */
+ private final Map descriptorsById = Collections.synchronizedMap(new HashMap());
+
+ private final Map projectNameToIdMap = Collections.synchronizedMap(new HashMap());
+
+ /**
+ */
+ public ProjectJETBundleProvider()
+ {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
+ */
+ public void resourceChanged(IResourceChangeEvent event)
+ {
+ switch (event.getType())
+ {
+ case IResourceChangeEvent.PRE_CLOSE:
+ case IResourceChangeEvent.PRE_DELETE:
+ handleProjectChange((IProject)event.getResource());
+ break;
+ case IResourceChangeEvent.POST_CHANGE:
+ handleWorkspaceChange(event.getDelta());
+ break;
+ }
+ }
+
+ public void startup()
+ {
+ IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+
+ for (int i = 0; i < projects.length; i++)
+ {
+ try
+ {
+ if (projects[i].exists() && projects[i].isOpen() && projects[i].hasNature(JET2Platform.JET2_NATURE_ID))
+ {
+ updateJETProject(projects[i]);
+ }
+ }
+ catch (CoreException e)
+ {
+ // this should not happen as exists() and isOpen() tests
+ // account for all possible causes if this exception
+ InternalJET2Platform.logError("Exception caught in \"should never happen\" catch clause", e); //$NON-NLS-1$
+ }
+ }
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
+ }
+
+ public void shutdown()
+ {
+ }
+
+ /**
+ * @param project
+ */
+ private void handleProjectChange(IProject project)
+ {
+ try
+ {
+ if (project.isOpen() && project.exists() && project.hasNature(JET2Platform.JET2_NATURE_ID))
+ {
+ removeJETProject(project.getName());
+ }
+ }
+ catch (CoreException e)
+ {
+ // this should not happen as exists() and isOpen() tests
+ // account for all possible causes if this exception
+ InternalJET2Platform.logError("Exception caught in \"should never happen\" catch clause", e); //$NON-NLS-1$
+ }
+ }
+
+ private void handleWorkspaceChange(IResourceDelta delta)
+ {
+
+ try
+ {
+ delta.accept(new IResourceDeltaVisitor()
+ {
+
+ public boolean visit(IResourceDelta childDelta) throws CoreException
+ {
+ switch (childDelta.getResource().getType())
+ {
+ case IResource.ROOT:
+ return true;
+ case IResource.PROJECT:
+ IProject project = (IProject)childDelta.getResource();
+ if (project.exists() && project.isOpen() && project.hasNature(JET2Platform.JET2_NATURE_ID))
+ {
+ IResourceDelta manifestDelta = childDelta.findMember(new Path(JarFile.MANIFEST_NAME));
+ IResourceDelta pluginXML = childDelta.findMember(new Path("plugin.xml")); //$NON-NLS-1$
+ if (manifestDelta != null || pluginXML != null)
+ {
+ updateJETProject(project);
+ }
+ return true;
+ }
+ return false;
+ case IResource.FOLDER:
+ IFolder folder = (IFolder)childDelta.getResource();
+ return folder.getProjectRelativePath().equals(new Path(JarFile.MANIFEST_NAME).removeLastSegments(1));
+ default:
+ return false;
+ }
+ }
+
+ });
+ }
+ catch (CoreException e)
+ {
+ // this should not happen as exists() and isOpen() tests
+ // account for all possible causes if this exception
+ InternalJET2Platform.logError("Exception caught in \"should never happen\" catch clause", e); //$NON-NLS-1$
+ }
+ }
+
+ public Set getAllJETBundleIds()
+ {
+ return descriptorsById.keySet();
+ }
+
+ public IJETBundleDescriptor getDescriptor(String id)
+ {
+ return (IJETBundleDescriptor)descriptorsById.get(id);
+ }
+
+ private void removeJETProject(final String projectName)
+ {
+ final String id = (String)projectNameToIdMap.get(projectName);
+ if(id != null)
+ {
+ projectNameToIdMap.remove(projectName);
+ descriptorsById.remove(id);
+ }
+ }
+
+ private void updateJETProject(final IProject project)
+ {
+ String projectName = project.getName();
+ try
+ {
+ final URL projectURL = new URL("file:/" + project.getLocation() + "/"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ final JETBundleManifest manifest = JETBundleManager.loadManifest(projectURL);
+
+ final String transformId = manifest.getTransformId();
+ final TransformData transformData = TransformDataFactory.INSTANCE.createTransformData(transformId, projectURL);
+
+ descriptorsById.put(transformId, new ProjectJETBundleDescriptor(manifest, transformData, projectURL, projectName));
+ projectNameToIdMap.put(projectName, transformId);
+ }
+ catch (MalformedURLException e)
+ {
+ e.printStackTrace();
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public IJETBundleDescriptor getDescriptorForProject(String name)
+ {
+ IJETBundleDescriptor result = null;
+ String id = (String)projectNameToIdMap.get(name);
+ if(id != null)
+ {
+ result = (IJETBundleDescriptor)descriptorsById.get(id);
+ }
+ return result;
+ }
+
+ public String getProjectForId(String id)
+ {
+ ProjectJETBundleDescriptor descriptor = (ProjectJETBundleDescriptor)getDescriptor(id);
+ return descriptor == null ? null : descriptor.getProjectName();
+ }
+
+ public Bundle load(String id, IProgressMonitor monitor) throws BundleException
+ {
+ Bundle bundle = null;
+ ProjectJETBundleDescriptor descriptor = (ProjectJETBundleDescriptor)getDescriptor(id);
+ if (descriptor != null)
+ {
+ if (ensureProjectIsBuilt(monitor))
+ {
+ bundle = InternalJET2Platform.getDefault().getJETBundleInstaller().installBundle(descriptor.getBaseURL());
+ }
+
+ }
+ return bundle;
+ }
+
+ public void unload(String id) throws BundleException
+ {
+ if(descriptorsById.containsKey(id))
+ {
+ Bundle bundle = Platform.getBundle(id);
+ unload(bundle);
+ }
+ }
+
+ /**
+ * @param monitor
+ */
+ private boolean ensureProjectIsBuilt(IProgressMonitor monitor)
+ {
+ boolean built = true;
+ // wait for in-progress auto-build to complete
+ IJobManager jobManager = Platform.getJobManager();
+ Job[] build = jobManager.find(ResourcesPlugin.FAMILY_AUTO_BUILD);
+ if (build.length == 1)
+ {
+ monitor.beginTask(JET2Messages.ProjectTemplateBundleDescriptor_WaitingForBuild, 1);
+ try
+ {
+ build[0].join();
+ }
+ catch (InterruptedException e)
+ {
+ built = false;
+ }
+ finally
+ {
+ monitor.done();
+ }
+ }
+ return built;
+ }
+
+ public void unload(Bundle bundle) throws BundleException
+ {
+ if(bundle != null)
+ {
+ bundle.uninstall();
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/ProjectTemplateBundleDescriptor.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/ProjectTemplateBundleDescriptor.java
deleted file mode 100644
index e054134..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/ProjectTemplateBundleDescriptor.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-
-package org.eclipse.jet.internal.runtime;
-
-
-import java.io.IOException;
-import java.net.URL;
-import java.text.MessageFormat;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.SubProgressMonitor;
-import org.eclipse.core.runtime.jobs.IJobManager;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.jet.internal.InternalJET2Platform;
-import org.eclipse.jet.internal.l10n.JET2Messages;
-import org.eclipse.jet.transform.IJETBundle;
-import org.eclipse.osgi.util.NLS;
-
-
-/**
- * A description of a transform in an Eclipse workspace Project.
- *
- */
-public class ProjectTemplateBundleDescriptor implements IJET2TemplateBundleDescriptor
-{
-
- private final IProject project;
-
- public ProjectTemplateBundleDescriptor(IProject project, String txId, String txName, String transformClass)
- {
- this.project = project;
- }
-
- /**
- * @param monitor
- */
- private void ensureProjectIsBuilt(IProgressMonitor monitor)
- {
- // wait for in-progress auto-build to complete
- IJobManager jobManager = Platform.getJobManager();
- Job[] build = jobManager.find(ResourcesPlugin.FAMILY_AUTO_BUILD);
- if (build.length == 1)
- {
- monitor.beginTask(JET2Messages.ProjectTemplateBundleDescriptor_WaitingForBuild, 1);
- try
- {
- // System.err.println("DEBUG: waiting for AUTO_BUILD to complete");
- build[0].join();
- // System.err.println("DEBUG: AUTO_BUILD to completed normally");
- }
- catch (InterruptedException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- // System.err.println("DEBUG: AUTO_BUILD was interrupted");
- }
- finally
- {
- // System.err.println("DEBUG: Exiting join on AUTO_BUILD");
- monitor.done();
- }
- }
- }
-
- public IJETBundle getTemplateBundle(IProgressMonitor monitor) throws CoreException
- {
- monitor.beginTask(NLS.bind(JET2Messages.ProjectTemplateBundleDescriptor_Retreiving, project.getName()), 100);
- try
- {
- ensureProjectIsBuilt(new SubProgressMonitor(monitor, 90));
-
- // We do not have to build a JAR if we adhere to the comment below.
-// URL bundleURL = JET2BundleBuildTool.bundleProject(project, new SubProgressMonitor(monitor, 10));
-// final String externalForm = bundleURL.toExternalForm();
-
- /*
- * Note: We can load directly from the plug-in project, but the Manifest.MF
- * must have an entry like:
- * Bundle-ClassPath: .,bin/
- * The New project transform must create this. This entry has no negative effect on deployed
- * transforms because bin is not found.
- * This is essentially the hack the PDE applies to the Eclipse run-time in "development mode",
- * except that development mode is statically initialized, so JET cannot take advantage
- * of it.
- */
- final String externalForm = "file:/" + project.getLocation().toString() + "/"; //$NON-NLS-1$ //$NON-NLS-2$
- try
- {
- URL bundleURL = new URL(externalForm);
- return new JET2Bundle(bundleURL);
- }
- catch (IOException e)
- {
- throw new CoreException(InternalJET2Platform.newStatus(IStatus.ERROR, MessageFormat.format(
- JET2Messages.JET2Bundle_ErrorOpeningJar,
- new Object []{ externalForm }), null));
- }
- }
- finally
- {
- monitor.done();
- }
- }
-
- public IProject getProject()
- {
- return project;
- }
-
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/ProjectTemplateBundleSupplier.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/ProjectTemplateBundleSupplier.java
deleted file mode 100644
index f1c7e9b..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/ProjectTemplateBundleSupplier.java
+++ /dev/null
@@ -1,256 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-
-package org.eclipse.jet.internal.runtime;
-
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.jar.Manifest;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IResourceChangeEvent;
-import org.eclipse.core.resources.IResourceChangeListener;
-import org.eclipse.core.resources.IResourceDelta;
-import org.eclipse.core.resources.IResourceDeltaVisitor;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.jet.JET2Platform;
-import org.eclipse.jet.internal.InternalJET2Platform;
-import org.eclipse.jet.internal.l10n.JET2Messages;
-import org.eclipse.osgi.util.NLS;
-import org.osgi.framework.Constants;
-
-
-/**
- * A template bundle supplier for JET2 projects (residing in Eclipse workspace projects).
- *
- */
-public class ProjectTemplateBundleSupplier implements IJET2TemplateBundleSupplier, IResourceChangeListener
-{
-
- private static final String META_INF_PATH = "META-INF"; //$NON-NLS-1$
-
- private static final String MANIFEST_MF_PATH = META_INF_PATH + "/MANIFEST.MF"; //$NON-NLS-1$
-
- private final Map idToTransformationMap = new HashMap();
-
- private final Map projectToIdMap = new HashMap();
-
- private static boolean DEBUG = InternalJET2Platform.getDefault().isDebugging()
- && Boolean.valueOf(Platform.getDebugOption("org.eclipse.jet/debug/projectBundleLoading")).booleanValue(); //$NON-NLS-1$
-
- /**
- *
- */
- public ProjectTemplateBundleSupplier()
- {
- super();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jet.internal.runtime.IJET2TransformSupplier#findTransformation(java.lang.String)
- */
- public IJET2TemplateBundleDescriptor findTemplateBundle(String id)
- {
- if (DEBUG && idToTransformationMap.get(id) != null)
- {
- InternalJET2Platform.debugMessage(this, "findTempalteBundle(" + id + ") found match"); //$NON-NLS-1$//$NON-NLS-2$
- }
- return (IJET2TemplateBundleDescriptor)idToTransformationMap.get(id);
- }
-
- public void startup()
- {
- IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
-
- for (int i = 0; i < projects.length; i++)
- {
- try
- {
- if (projects[i].exists() && projects[i].isOpen() && projects[i].hasNature(JET2Platform.JET2_NATURE_ID))
- {
- addProject(projects[i]);
- }
- }
- catch (CoreException e)
- {
- // this should not happen as exists() and isOpen() tests
- // account for all possible causes if this exception
- InternalJET2Platform.logError("Exception caught in \"should never happen\" catch clause", e); //$NON-NLS-1$
- }
- }
-
- ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
- }
-
- private void addProject(IProject project)
- {
- if (DEBUG)
- {
- InternalJET2Platform.debugMessage(this, "addProject(" + project.getName() + ")"); //$NON-NLS-1$//$NON-NLS-2$
- }
- IFile manifestFile = project.getFile(MANIFEST_MF_PATH);
- try
- {
- InputStream is = manifestFile.getContents();
- Manifest manifest = new Manifest(is);
- is.close();
- String name = manifest.getMainAttributes().getValue(Constants.BUNDLE_NAME);
- String txId = getTransformId(manifest);
- String transformClass = manifest.getMainAttributes().getValue(JET2Bundle.JET2_TRANSFORM_LOADER_ATTRIBUTE);
- IJET2TemplateBundleDescriptor descriptor = new ProjectTemplateBundleDescriptor(project, txId, name, transformClass);
- idToTransformationMap.put(txId, descriptor);
- projectToIdMap.put(project.getName(), txId);
- }
- catch (IOException e)
- {
- InternalJET2Platform.logWarning(NLS.bind(
- JET2Messages.ProjectTemplateBundleSupplier_CouldNotRead,
- manifestFile.getFullPath().toOSString()), e);
- }
- catch (CoreException e)
- {
- InternalJET2Platform.logWarning(NLS.bind(
- JET2Messages.ProjectTemplateBundleSupplier_CouldNotRead,
- manifestFile.getFullPath().toOSString()), e);
- }
-
- }
-
- public void shutdown()
- {
- ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
- idToTransformationMap.clear();
- projectToIdMap.clear();
- }
-
- public void resourceChanged(IResourceChangeEvent event)
- {
- switch (event.getType())
- {
- case IResourceChangeEvent.PRE_CLOSE:
- case IResourceChangeEvent.PRE_DELETE:
- handleProjectChange((IProject)event.getResource());
- break;
- case IResourceChangeEvent.POST_CHANGE:
- handleWorkspaceChange(event.getDelta());
- break;
- }
-
- }
-
- /**
- * @param delta
- */
- private void handleWorkspaceChange(IResourceDelta delta)
- {
-
- try
- {
- delta.accept(new IResourceDeltaVisitor()
- {
-
- public boolean visit(IResourceDelta childDelta) throws CoreException
- {
- switch (childDelta.getResource().getType())
- {
- case IResource.ROOT:
- return true;
- case IResource.PROJECT:
- IProject project = (IProject)childDelta.getResource();
- if (project.exists() && project.isOpen() && project.hasNature(JET2Platform.JET2_NATURE_ID))
- {
- IResourceDelta manifestDelta = childDelta.findMember(new Path(MANIFEST_MF_PATH));
- if (manifestDelta != null)
- {
- updateProject(project);
- }
- }
- return false;
- default:
- return false;
- }
- }
-
- });
- }
- catch (CoreException e)
- {
- // this should not happen as exists() and isOpen() tests
- // account for all possible causes if this exception
- InternalJET2Platform.logError("Exception caught in \"should never happen\" catch clause", e); //$NON-NLS-1$
- }
- }
-
- private void updateProject(IProject project)
- {
- removeProject(project);
- addProject(project);
- }
-
- /**
- * @param project
- */
- private void handleProjectChange(IProject project)
- {
- try
- {
- if (project.isOpen() && project.exists() && project.hasNature(JET2Platform.JET2_NATURE_ID))
- {
- removeProject(project);
- }
- }
- catch (CoreException e)
- {
- // this should not happen as exists() and isOpen() tests
- // account for all possible causes if this exception
- InternalJET2Platform.logError("Exception caught in \"should never happen\" catch clause", e); //$NON-NLS-1$
- }
- }
-
- private void removeProject(IProject project)
- {
- if (DEBUG)
- {
- InternalJET2Platform.debugMessage(this, "removeProject(" + project.getName() + ")"); //$NON-NLS-1$//$NON-NLS-2$
- }
- String txId = (String)projectToIdMap.remove(project.getName());
- if (txId != null)
- {
- idToTransformationMap.remove(txId);
- }
- }
-
- /**
- * @param manifest
- * @return
- */
- private String getTransformId(Manifest manifest)
- {
- String value = manifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
- int semiIndex = value.indexOf(';');
- String txId = value.substring(0, semiIndex >= 0 ? semiIndex : value.length());
- return txId;
- }
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/TabLibraryReferenceImpl.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/TabLibraryReferenceImpl.java
new file mode 100644
index 0000000..f18ee7b
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/TabLibraryReferenceImpl.java
@@ -0,0 +1,71 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.internal.runtime;
+
+import org.eclipse.jet.taglib.TagLibrary;
+import org.eclipse.jet.taglib.TagLibraryReference;
+
+/**
+ * Standard implementation of a {@link TagLibraryReference}.
+ */
+public class TabLibraryReferenceImpl implements TagLibraryReference
+{
+
+ private final String tagLibraryId;
+ private final String prefix;
+ private final boolean autoImport;
+
+ public TabLibraryReferenceImpl(String tagLibraryId, String prefix, boolean autoImport)
+ {
+ this.tagLibraryId = tagLibraryId;
+ this.prefix = prefix;
+ this.autoImport = autoImport;
+
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.taglib.TagLibraryReference#getPrefix()
+ */
+ public String getPrefix()
+ {
+ return prefix;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.taglib.TagLibraryReference#getTagLibrary()
+ */
+ public TagLibrary getTagLibrary()
+ {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.taglib.TagLibraryReference#getTagLibraryId()
+ */
+ public String getTagLibraryId()
+ {
+ return tagLibraryId;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.taglib.TagLibraryReference#isAutoImport()
+ */
+ public boolean isAutoImport()
+ {
+ return autoImport;
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/CoreExceptionWrapper.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/CoreExceptionWrapper.java
index 7aea3be..4d8eca2 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/CoreExceptionWrapper.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/CoreExceptionWrapper.java
@@ -25,6 +25,7 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.jet.CoreJETException;
/**
* A wrapper that makes a CoreException seem like a DiagnosticException.
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/LoaderManager.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/LoaderManager.java
index e3ba8fa..e5c6718 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/LoaderManager.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/LoaderManager.java
@@ -28,6 +28,7 @@ import java.util.Set;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.jet.CoreJETException;
import org.eclipse.jet.JET2Platform;
import org.eclipse.jet.internal.l10n.JET2Messages;
import org.eclipse.jet.runtime.model.ILoaderFactory;
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/runtime/model/ILoaderManager.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/runtime/model/ILoaderManager.java
index 508c840..90994cf 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/runtime/model/ILoaderManager.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/runtime/model/ILoaderManager.java
@@ -16,7 +16,7 @@
*/
package org.eclipse.jet.runtime.model;
-import org.eclipse.jet.internal.runtime.model.CoreJETException;
+import org.eclipse.jet.CoreJETException;
/**
* Interface to the manager for model loaders.
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/WorkspaceContextExtender.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/WorkspaceContextExtender.java
index 48c7c90..b0050a3 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/WorkspaceContextExtender.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/WorkspaceContextExtender.java
@@ -37,9 +37,10 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jet.AbstractContextExtender;
+import org.eclipse.jet.CoreJETException;
import org.eclipse.jet.JET2Context;
+import org.eclipse.jet.internal.InternalJET2Platform;
import org.eclipse.jet.internal.l10n.JET2Messages;
-import org.eclipse.jet.internal.runtime.model.CoreJETException;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.transform.TransformContextExtender;
import org.eclipse.jet.transform.TransformContextListener;
@@ -214,7 +215,6 @@ public class WorkspaceContextExtender extends AbstractContextExtender
{
final IWorkspaceAction action = (IWorkspaceAction)i.next();
- submon.subTask(JET2Messages.WorkspaceContextExtender_Writing);
Platform.run(new ISafeRunnable() {
public void handleException(Throwable exception)
@@ -410,32 +410,39 @@ public class WorkspaceContextExtender extends AbstractContextExtender
// setup context variables describing the loaded resource.
final String name = resource.getName();
- context.setVariable(VAR_RESOURCE_NAME, name);
- context.setVariable(VAR_RESOURCE_TYPE, getResourceTypeString(resource.getType()));
- context.setVariable(VAR_RESOURCE_LOCATION, resource.getLocation().toString());
- context.setVariable(VAR_RAW_LOCATION, resource.getRawLocation().toString());
- context.setVariable(VAR_RESOURCE_PROJECT_NAME, resource.getProject().getName());
- context.setVariable(VAR_RESOURCE_FULL_PATH, resource.getFullPath().toString());
- context.setVariable(VAR_RESOURCE_PROJECT_RELATIVE_PATH, resource.getProjectRelativePath().toString());
- final String fileExtension = resource.getFileExtension();
- context.setVariable(VAR_RESOURCE_FILE_EXTENSION, fileExtension);
- context.setVariable(VAR_RESOURCE_FILE_NAME,
- fileExtension == null ? name : name.substring(0, name.length() - fileExtension.length() - 1));
- switch (resource.getType())
+ try
{
- case IResource.FILE:
- case IResource.FOLDER:
- context.setVariable(VAR_RESOURCE_PARENT_NAME, resource.getParent().getName());
- context.setVariable(VAR_RESOURCE_PARENT_LOCATION, resource.getParent().getLocation().toString());
- context.setVariable(VAR_RESOURCE_PARENT_RAW_LOCATION,
- resource.getParent().getRawLocation() == null
- ? resource.getParent().getLocation().toString()
- : resource.getParent().getRawLocation().toString());
- context.setVariable(VAR_RESOURCE_PARENT_FULL_PATH, resource.getParent().getFullPath().toString());
- context.setVariable(VAR_RESOURCE_PARENT_PROJECT_RELATIVE_PATH, resource.getParent().getProjectRelativePath().toString());
- break;
- case IResource.PROJECT:
- break;
+ context.setVariable(VAR_RESOURCE_NAME, name);
+ context.setVariable(VAR_RESOURCE_TYPE, getResourceTypeString(resource.getType()));
+ context.setVariable(VAR_RESOURCE_LOCATION, resource.getLocation().toString());
+ context.setVariable(VAR_RAW_LOCATION, resource.getRawLocation().toString());
+ context.setVariable(VAR_RESOURCE_PROJECT_NAME, resource.getProject().getName());
+ context.setVariable(VAR_RESOURCE_FULL_PATH, resource.getFullPath().toString());
+ context.setVariable(VAR_RESOURCE_PROJECT_RELATIVE_PATH, resource.getProjectRelativePath().toString());
+ final String fileExtension = resource.getFileExtension();
+ context.setVariable(VAR_RESOURCE_FILE_EXTENSION, fileExtension);
+ context.setVariable(VAR_RESOURCE_FILE_NAME,
+ fileExtension == null ? name : name.substring(0, name.length() - fileExtension.length() - 1));
+ switch (resource.getType())
+ {
+ case IResource.FILE:
+ case IResource.FOLDER:
+ context.setVariable(VAR_RESOURCE_PARENT_NAME, resource.getParent().getName());
+ context.setVariable(VAR_RESOURCE_PARENT_LOCATION, resource.getParent().getLocation().toString());
+ context.setVariable(VAR_RESOURCE_PARENT_RAW_LOCATION,
+ resource.getParent().getRawLocation() == null
+ ? resource.getParent().getLocation().toString()
+ : resource.getParent().getRawLocation().toString());
+ context.setVariable(VAR_RESOURCE_PARENT_FULL_PATH, resource.getParent().getFullPath().toString());
+ context.setVariable(VAR_RESOURCE_PARENT_PROJECT_RELATIVE_PATH, resource.getParent().getProjectRelativePath().toString());
+ break;
+ case IResource.PROJECT:
+ break;
+ }
+ }
+ catch (JET2TagException e)
+ {
+ InternalJET2Platform.logError("Invalid variable name", e); //$NON-NLS-1$
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/IJETBundle.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/IJETBundle.java
deleted file mode 100644
index c9feb52..0000000
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/IJETBundle.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * <copyright>
- *
- * Copyright (c) 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *
- * </copyright>
- *
- * $Id$
- */
-
-package org.eclipse.jet.transform;
-
-
-import java.net.URL;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.emf.common.util.Diagnostic;
-import org.eclipse.jet.internal.runtime.IJET2Runnable;
-
-
-/**
- * Interface to a JET2 Bundle
- *
- */
-public interface IJETBundle
-{
-
- public abstract String getId();
-
- public abstract String getName();
-
- public abstract URL getBundleURL();
-
- public abstract String getLoaderClassName();
-
- /**
- * Load the template bundle and execute the passed code (runnable), passing it
- * a reference to the template bundle's template loader.
- * @param runnable the code to execute while having access to the loaded templates.
- * @return the status of the execution
- * @throws CoreException if an execution error occurs.
- */
- public abstract Diagnostic execute(IJET2Runnable runnable) throws CoreException;
-
-}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/IJETBundleDescriptor.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/IJETBundleDescriptor.java
index ba85e17..2838d9c 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/IJETBundleDescriptor.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/IJETBundleDescriptor.java
@@ -16,6 +16,8 @@
*/
package org.eclipse.jet.transform;
+import java.net.URL;
+
import org.eclipse.jet.taglib.TagLibraryReference;
/**
@@ -89,4 +91,10 @@ public interface IJETBundleDescriptor
* @return a bundle relative path to a template, or <code>null</code> if not specified.
*/
public abstract String getMainTemplate();
+
+ /**
+ * Return the base URL of from which all bundle content may be accessed.
+ * @return a URL
+ */
+ public abstract URL getBaseURL();
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/IJETBundleManager.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/IJETBundleManager.java
new file mode 100644
index 0000000..665c301
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/IJETBundleManager.java
@@ -0,0 +1,52 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.transform;
+
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jet.CoreJETException;
+import org.eclipse.jet.JET2TemplateLoader;
+
+
+public interface IJETBundleManager
+{
+
+ public abstract IJETBundleDescriptor[] getAllJETBundleDescriptors();
+
+ public abstract IJETBundleDescriptor getDescriptor(String id);
+
+ public abstract IJETBundleDescriptor getDescriptorForProject(String name);
+
+ /**
+ * Return the Workspace project name for the given JET transform id. If the transform does
+ * not reside in a Workspace project, then null is returned.
+ * @param id the transform id
+ * @return the project name or <code>null</code>.
+ */
+ public abstract String getProjectForId(String id);
+
+ public abstract void run(String id, IJETRunnable runnable, IProgressMonitor monitor) throws CoreJETException;
+
+ public abstract void connect(String id, IProgressMonitor monitor) throws CoreJETException;
+
+ public abstract void disconnect(String id);
+
+ public abstract JET2TemplateLoader getTemplateLoader(String id) throws CoreJETException;
+
+ public abstract String[] getAllTransformIds();
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/IJETRunnable.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/IJETRunnable.java
new file mode 100644
index 0000000..3e330cb
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/IJETRunnable.java
@@ -0,0 +1,29 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.transform;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jet.JET2TemplateLoader;
+
+/**
+ * Interface defining a series of actions to perform against a JET bundle.
+ */
+public interface IJETRunnable
+{
+
+ public abstract void run(IJETBundleDescriptor descriptor, JET2TemplateLoader templateLoader, IProgressMonitor monitor);
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/TransformContextExtender.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/TransformContextExtender.java
index ff21365..3b425ea 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/TransformContextExtender.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/TransformContextExtender.java
@@ -28,15 +28,20 @@ import java.util.List;
import java.util.Stack;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jet.AbstractContextExtender;
+import org.eclipse.jet.BodyContentWriter;
+import org.eclipse.jet.CoreJETException;
import org.eclipse.jet.JET2Context;
+import org.eclipse.jet.JET2Platform;
import org.eclipse.jet.JET2Template;
import org.eclipse.jet.JET2TemplateLoader;
+import org.eclipse.jet.JET2TemplateLoaderExtension;
import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.internal.JETActivatorWrapper;
import org.eclipse.jet.internal.l10n.JET2Messages;
import org.eclipse.jet.internal.runtime.TagFactoryImpl;
-import org.eclipse.jet.internal.runtime.model.CoreJETException;
import org.eclipse.jet.internal.runtime.model.TransformLoadContext;
import org.eclipse.jet.internal.runtime.model.WorkspaceLoadContext;
import org.eclipse.jet.runtime.model.ILoadContext;
@@ -54,8 +59,6 @@ public class TransformContextExtender extends AbstractContextExtender
private static final class ContextData
{
- private String id;
-
private final Stack templateStack = new Stack();
private JET2TemplateLoader loader;
@@ -64,8 +67,9 @@ public class TransformContextExtender extends AbstractContextExtender
private Object shellContext = null;
- private IJETBundle transform = null;
-
+ private IJETBundleDescriptor descriptor = null;
+
+ private final List connectedTransforms = new ArrayList();
}
/**
@@ -92,16 +96,7 @@ public class TransformContextExtender extends AbstractContextExtender
public String getId()
{
- return getData().id;
- }
-
- public void setId(String id)
- {
- if (getData().id != null)
- {
- throw new IllegalStateException("id already set"); //$NON-NLS-1$
- }
- getData().id = id;
+ return getData().descriptor.getId();
}
/**
@@ -122,6 +117,7 @@ public class TransformContextExtender extends AbstractContextExtender
public void execute(String templatePath, JET2Writer writer) throws JET2TagException
{
getData().templateStack.push(templatePath);
+ getContext().setTemplatePath(getTemplatePath());
try
{
JET2Template template = getData().loader.getTemplate(templatePath);
@@ -136,6 +132,7 @@ public class TransformContextExtender extends AbstractContextExtender
finally
{
getData().templateStack.pop();
+ getContext().setTemplatePath(getTemplatePath());
}
}
@@ -198,7 +195,7 @@ public class TransformContextExtender extends AbstractContextExtender
try
{
- listener.commit(getContext(), monitor);
+ listener.commit(getContext(), new SubProgressMonitor(monitor, 1));
}
catch (JET2TagException e)
{
@@ -248,29 +245,29 @@ public class TransformContextExtender extends AbstractContextExtender
}
/**
- * Set the transform bundle associated with this context.
- * @param transform
- * @throws IllegalStateException if the transform bundle has already been set.
+ * Set the description of the transform bundle.
+ * @param descriptor the bundle descriptor.
+ * @throws IllegalStateException if the bundle descriptor has already been set.
*/
- public void setTransform(IJETBundle transform)
+ public void setBundleDescriptor(IJETBundleDescriptor descriptor)
{
- if (getData().transform != null)
+ if (getData().descriptor != null)
{
throw new IllegalStateException();
}
- getData().transform = transform;
-
+ getData().descriptor = descriptor;
+ getContext().setJETBundleId(descriptor.getId());
}
-
+
/**
- * Return the transform bundle associated with this context.
- * @return the bundle
+ * Return the bundle descriptor of the JET transform bundle.
+ * @return a bundle descriptor
*/
- public IJETBundle getTransform()
+ public IJETBundleDescriptor getBundleDescriptor()
{
- return getData().transform;
+ return getData().descriptor;
}
-
+
/**
* Return the base URL to use given an urlContext constant. The supported URL contexts
* are:
@@ -289,7 +286,7 @@ public class TransformContextExtender extends AbstractContextExtender
if (urlContext == null || "transform".equalsIgnoreCase(urlContext)) { //$NON-NLS-1$
try
{
- definedContext = new TransformLoadContext(getTransform().getBundleURL());
+ definedContext = new TransformLoadContext(getBundleDescriptor().getBaseURL());
}
catch (MalformedURLException e)
{
@@ -357,4 +354,77 @@ public class TransformContextExtender extends AbstractContextExtender
return source;
}
+
+ public void setOverride(String id, IProgressMonitor monitor) throws JET2TagException
+ {
+ final IJETBundleManager bundleManager = JET2Platform.getJETBundleManager();
+ try
+ {
+ bundleManager.connect(id, monitor != null ? monitor : new NullProgressMonitor());
+ getData().connectedTransforms.add(id);
+ final JET2TemplateLoader delegateLoader = bundleManager.getTemplateLoader(id);
+
+ final JET2TemplateLoader loader = getLoader();
+ if(loader instanceof JET2TemplateLoaderExtension)
+ {
+ JET2TemplateLoaderExtension ext = (JET2TemplateLoaderExtension)loader;
+ ext.setDelegateLoader(delegateLoader);
+ }
+ else
+ {
+ final String msg = JET2Messages.TransformContextExtender_NeedsRebuildForOverride;
+ throw new JET2TagException(MessageFormat.format(msg, new Object[] {getId()}));
+ }
+ }
+ catch (CoreJETException e)
+ {
+ throw new JET2TagException(e);
+ }
+ }
+
+ public void cleanup()
+ {
+ // clean-up load transforms...
+ final IJETBundleManager bundleManager = JET2Platform.getJETBundleManager();
+ for (Iterator i = getData().connectedTransforms.iterator(); i.hasNext();)
+ {
+ String id = (String)i.next();
+ bundleManager.disconnect(id);
+ }
+ }
+
+ public void runSubTransform(String id) throws JET2TagException
+ {
+ final IJETBundleManager bundleManager = JET2Platform.getJETBundleManager();
+ final IJETBundleDescriptor savedDescriptor = getData().descriptor;
+ final JET2TemplateLoader savedLoader = getData().loader;
+ try
+ {
+ bundleManager.connect(id, new NullProgressMonitor());
+ getData().connectedTransforms.add(id);
+ final JET2TemplateLoader loader = bundleManager.getTemplateLoader(id);
+ final IJETBundleDescriptor descriptor = bundleManager.getDescriptor(id);
+
+ getData().loader = loader;
+ getData().descriptor = descriptor;
+
+ if(descriptor.getOverridesId() != null)
+ {
+ setOverride(descriptor.getOverridesId(), new NullProgressMonitor());
+ }
+
+ execute(descriptor.getMainTemplate(), new BodyContentWriter());
+
+ }
+ catch (CoreJETException e)
+ {
+ throw new JET2TagException(e);
+ }
+ finally
+ {
+ getData().descriptor = savedDescriptor;
+ getData().loader = savedLoader;
+ }
+ }
+
}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/runtime/TestBundleDescriptions.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/runtime/TestBundleDescriptions.java
index 25b77d1..67d2751 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/runtime/TestBundleDescriptions.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/runtime/TestBundleDescriptions.java
@@ -12,7 +12,7 @@ public class TestBundleDescriptions extends TestCase {
public void testGetProjectDescription()
{
- final IStatus result = JET2Platform.execute("org.eclipse.jet.transforms.newproject",
+ final IStatus result = JET2Platform.runTransformOnString("org.eclipse.jet.transforms.newproject",
"<newProjectModel><project name=\"foo.bar\"/></newProjectModel>",
new NullProgressMonitor());
@@ -26,13 +26,17 @@ public class TestBundleDescriptions extends TestCase {
assertNotNull(tlRefs);
assertEquals(4, tlRefs.length);
assertEquals("c", tlRefs[0].getPrefix());
- assertEquals("f", tlRefs[1].getPrefix());
- assertEquals("ws", tlRefs[2].getPrefix());
- assertEquals("java", tlRefs[3].getPrefix());
+ assertEquals("java", tlRefs[1].getPrefix());
+ assertEquals("f", tlRefs[2].getPrefix());
+ assertEquals("ws", tlRefs[3].getPrefix());
assertEquals("org.eclipse.jet.controlTags", tlRefs[0].getTagLibraryId());
- assertEquals("org.eclipse.jet.formatTags", tlRefs[1].getTagLibraryId());
- assertEquals("org.eclipse.jet.workspaceTags", tlRefs[2].getTagLibraryId());
- assertEquals("org.eclipse.jet.javaTags", tlRefs[3].getTagLibraryId());
+ assertEquals("org.eclipse.jet.javaTags", tlRefs[1].getTagLibraryId());
+ assertEquals("org.eclipse.jet.formatTags", tlRefs[2].getTagLibraryId());
+ assertEquals("org.eclipse.jet.workspaceTags", tlRefs[3].getTagLibraryId());
+ assertTrue(tlRefs[0].isAutoImport());
+ assertTrue(tlRefs[1].isAutoImport());
+ assertTrue(tlRefs[2].isAutoImport());
+ assertFalse(tlRefs[3].isAutoImport());
}
}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/runtime/TestBundleLoading.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/runtime/TestBundleLoading.java
index fa37fc9..c333464 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/runtime/TestBundleLoading.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/runtime/TestBundleLoading.java
@@ -2,30 +2,75 @@ package org.eclipse.jet.tests.runtime;
import junit.framework.TestCase;
-import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jet.JET2Platform;
import org.eclipse.jet.JET2Template;
import org.eclipse.jet.JET2TemplateLoader;
-import org.eclipse.jet.internal.InternalJET2Platform;
-import org.eclipse.jet.internal.runtime.IJET2Runnable;
-import org.eclipse.jet.transform.IJETBundle;
+import org.eclipse.jet.taglib.TagLibraryReference;
+import org.eclipse.jet.transform.IJETBundleDescriptor;
+import org.eclipse.jet.transform.IJETBundleManager;
+import org.eclipse.jet.transform.IJETRunnable;
public class TestBundleLoading extends TestCase {
-
+
public void testLoadSimpleBundle() throws Exception {
- IJETBundle tx = InternalJET2Platform.getDefault().getTemplateBundle("org.eclipse.jet.transforms.newproject", null);
-
- assertNotNull(tx);
-
- tx.execute(new IJET2Runnable() {
+ final IJETBundleManager bundleManager = JET2Platform.getJETBundleManager();
+ final boolean[] executed = new boolean[1];
+ executed[0] = false;
+ bundleManager.run("org.eclipse.jet.transforms.newproject", new IJETRunnable() {
- public Diagnostic run(JET2TemplateLoader loader) {
- JET2Template template = loader.getTemplate("templates/control.jet");
-
+ public void run(IJETBundleDescriptor descriptor, JET2TemplateLoader templateLoader, IProgressMonitor monitor) {
+ executed[0] = true;
+ final JET2Template template = templateLoader.getTemplate(descriptor.getMainTemplate());
assertNotNull(template);
- return Diagnostic.OK_INSTANCE;
- }});
+ }}, new NullProgressMonitor());
+
+ assertTrue("executed", executed[0]);
+ }
+
+ public void testGetBundles() throws Exception {
+ String projectName = getClass().getName() + ".testGetBundles";
+ String source = "<newProjectModel><project name=\"" + projectName
+ + "\"/></newProjectModel>";
+ JET2Platform.runTransformOnString("org.eclipse.jet.transforms.newproject", source,
+ new NullProgressMonitor());
+
+ IJETBundleManager mgr = JET2Platform.getJETBundleManager();
+
+ final IJETBundleDescriptor[] all = mgr.getAllJETBundleDescriptors();
+ assertNotNull(all);
+ assertTrue(all.length > 0);
+ IJETBundleDescriptor myDescriptor = null;
+ for (int i = 0; i < all.length; i++) {
+ if (all[i].getId().equals(projectName)) {
+ myDescriptor = all[i];
+ break;
+ }
+ }
+ assertNotNull(myDescriptor);
+ assertEquals(projectName, myDescriptor.getId());
}
+ public void testGetDescriptionForProject() {
+ String projectName = getClass().getName() + ".getDescriptionForProject";
+ String source = "<newProjectModel><project name=\"" + projectName
+ + "\"/></newProjectModel>";
+ JET2Platform.runTransformOnString(
+ "org.eclipse.jet.transforms.newproject", source,
+ new NullProgressMonitor());
+ IJETBundleManager mgr = JET2Platform.getJETBundleManager();
+ final IJETBundleDescriptor descriptor = mgr
+ .getDescriptorForProject(projectName);
+ assertNotNull(descriptor);
+ final TagLibraryReference[] tlrefs = descriptor
+ .getTagLibraryReferences();
+ assertEquals(4, tlrefs.length);
+ assertEquals("c", tlrefs[0].getPrefix());
+ assertEquals("java", tlrefs[1].getPrefix());
+ assertEquals("f", tlrefs[2].getPrefix());
+ assertEquals("ws", tlrefs[3].getPrefix());
+ }
}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/control/LoadTagTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/control/LoadTagTests.java
index 7186820..b38c31e 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/control/LoadTagTests.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/control/LoadTagTests.java
@@ -1,19 +1,19 @@
package org.eclipse.jet.tests.taglib.control;
+import junit.framework.TestCase;
+
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jet.BodyContentWriter;
import org.eclipse.jet.JET2Context;
+import org.eclipse.jet.JET2Platform;
import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.XPathContextExtender;
-import org.eclipse.jet.internal.InternalJET2Platform;
import org.eclipse.jet.internal.taglib.control.LoadTag;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.TagInfo;
-import org.eclipse.jet.transform.IJETBundle;
+import org.eclipse.jet.transform.IJETBundleDescriptor;
import org.eclipse.jet.transform.TransformContextExtender;
-import junit.framework.TestCase;
-
public class LoadTagTests extends TestCase {
/*
@@ -25,12 +25,11 @@ public class LoadTagTests extends TestCase {
JET2Context context = new JET2Context((Object)null);
TransformContextExtender tce = new TransformContextExtender(context);
- final IJETBundle templateBundle = InternalJET2Platform.getDefault().getTemplateBundle(id, null);
- tce.setId(id);
- tce.setTransform(templateBundle);
+ final IJETBundleDescriptor descriptor = JET2Platform.getJETBundleManager().getDescriptor(id);
+ tce.setBundleDescriptor(descriptor);
LoadTag tag = new LoadTag();
- TagInfo td = new TagInfo("", 0, 0, 0,
+ TagInfo td = new TagInfo("", 1, 1,
new String[] { "url", "var", "type" },
new String[] { "templates/project/sample.xml.jet", "root", "xml" });
tag.setTagInfo(td);