summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-03-22 21:48:22 (EST)
committer pelder2006-03-22 21:48:22 (EST)
commit3e7e12643751f1c62d814eb4a3017e0c9dc16212 (patch)
tree08b542a685b773eea10f9732046103705532da2d
parenteda319e7e116d647fa944d5d4de14917dcf9ccec (diff)
downloadorg.eclipse.jet-3e7e12643751f1c62d814eb4a3017e0c9dc16212.zip
org.eclipse.jet-3e7e12643751f1c62d814eb4a3017e0c9dc16212.tar.gz
org.eclipse.jet-3e7e12643751f1c62d814eb4a3017e0c9dc16212.tar.bz2
Implement a subset of the APIs needed for 131192.
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java102
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2CompilationUnit.java22
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/TagLibraryReferenceImpl.java82
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagLibraryReference.java48
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/transform/IJETBundleDescriptor.java92
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJET2Parser.java16
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/runtime/AllTests.java1
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/runtime/TestBundleDescriptions.java38
8 files changed, 400 insertions, 1 deletions
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java
index fce33a4..3cb6932 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java
@@ -32,6 +32,7 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -52,10 +53,13 @@ import org.eclipse.jet.internal.runtime.ProjectTemplateBundleDescriptor;
import org.eclipse.jet.internal.runtime.RuntimeLoggerContextExtender;
import org.eclipse.jet.internal.runtime.RuntimeTagLogger;
import org.eclipse.jet.internal.runtime.model.CoreJETException;
+import org.eclipse.jet.internal.taglib.TagLibraryReferenceImpl;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.TagInfo;
+import org.eclipse.jet.taglib.TagLibraryReference;
import org.eclipse.jet.taglib.workspace.WorkspaceContextExtender;
import org.eclipse.jet.transform.IJETBundle;
+import org.eclipse.jet.transform.IJETBundleDescriptor;
import org.eclipse.jet.transform.TransformContextExtender;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.FindReplaceDocumentAdapter;
@@ -120,7 +124,7 @@ public class JET2Platform
public static IStatus execute(final String id, final String source, final IProgressMonitor monitor)
{
- return execute(id, source, null, monitor);
+ return execute(id, source, "xml", monitor); //$NON-NLS-1$
}
public static IStatus execute(final String id, final IResource resource, final IProgressMonitor monitor)
@@ -386,4 +390,100 @@ public class JET2Platform
}
}
+ /**
+ * Return the bundle description for the named JET project
+ * @param name an Eclipse project name
+ * @return a bundle description, or <code>null</code> if the project does not exist or
+ * is not a JET project.
+ */
+ public static IJETBundleDescriptor getProjectDescription(final String name)
+ {
+ IJETBundleDescriptor result = null;
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
+ if(isOpenJETProject(project))
+ {
+ // XXX HACK, fake a descriptor
+ result = new IJETBundleDescriptor() {
+
+ public String getId()
+ {
+ return name;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public String getDescription()
+ {
+ return ""; //$NON-NLS-1$
+ }
+
+ public String getModelLoaderId()
+ {
+ return null;
+ }
+
+ public String getModelExtension()
+ {
+ return null;
+ }
+
+ public String getOverridesId()
+ {
+ return null;
+ }
+
+ public String getVersion()
+ {
+ return "1.0.0"; //$NON-NLS-1$
+ }
+
+ public String getProvider()
+ {
+ return ""; //$NON-NLS-1$
+ }
+
+ public TagLibraryReference[] getTagLibraryReferences()
+ {
+ return new TagLibraryReference[] {
+ new TagLibraryReferenceImpl("c", "org.eclipse.jet.controlTags", true), //$NON-NLS-1$ //$NON-NLS-2$
+ new TagLibraryReferenceImpl("f", "org.eclipse.jet.formatTags", true), //$NON-NLS-1$ //$NON-NLS-2$
+ new TagLibraryReferenceImpl("ws", "org.eclipse.jet.workspaceTags", false), //$NON-NLS-1$ //$NON-NLS-2$
+ new TagLibraryReferenceImpl("java", "org.eclipse.jet.javaTags", true), //$NON-NLS-1$ //$NON-NLS-2$
+ };
+ }
+
+ public String getTemplateLoaderClass()
+ {
+ return "org.eclipse.jet.compiled._jet_transformation"; //$NON-NLS-1$
+ }
+
+ public String getMainTemplate()
+ {
+ return "templates/control.jet"; //$NON-NLS-1$
+ }
+
+ };
+ }
+ return result;
+ }
+
+ /**
+ * Test whether a project is an open JET project
+ * @param project
+ * @return
+ */
+ private static boolean isOpenJETProject(IProject project)
+ {
+ try
+ {
+ return project != null && project.exists() && project.isOpen() && project.hasNature(JET2_NATURE_ID);
+ }
+ catch (CoreException e)
+ {
+ return false;
+ }
+ }
}
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 1233ac7..3534a31 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
@@ -37,6 +37,8 @@ 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;
/**
@@ -300,4 +302,24 @@ public final class JET2CompilationUnit extends JET2ASTElement
{
return false;
}
+
+ /**
+ * Return an array of tag libraries referenced by this template.
+ * @return a possibly empty array of tag library references.
+ */
+ 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()]);
+ }
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/TagLibraryReferenceImpl.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/TagLibraryReferenceImpl.java
new file mode 100644
index 0000000..bf2f715
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/TagLibraryReferenceImpl.java
@@ -0,0 +1,82 @@
+/**
+ * <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.taglib;
+
+import org.eclipse.jet.taglib.TagLibrary;
+import org.eclipse.jet.taglib.TagLibraryManager;
+import org.eclipse.jet.taglib.TagLibraryReference;
+
+/**
+ * Standard implementation of TagLibraryReference.
+ */
+public class TagLibraryReferenceImpl implements TagLibraryReference
+{
+
+ private final String prefix;
+ private final String id;
+ private final TagLibrary tagLibrary;
+ private final boolean autoImport;
+
+ /**
+ *
+ */
+ public TagLibraryReferenceImpl(String prefix, String id, boolean autoImport, TagLibrary tagLibrary)
+ {
+ this.prefix = prefix;
+ this.id = id;
+ this.autoImport = autoImport;
+ this.tagLibrary = tagLibrary;
+ }
+
+ public TagLibraryReferenceImpl(String prefix, String id, boolean autoImport)
+ {
+ this(prefix, id, autoImport, TagLibraryManager.getInstance().getTagLibrary(id));
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.taglib.TagLibraryReference#getPrefix()
+ */
+ public String getPrefix()
+ {
+ return prefix;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.taglib.TagLibraryReference#getTagLibraryId()
+ */
+ public String getTagLibraryId()
+ {
+ return id;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.taglib.TagLibraryReference#getTagLibrary()
+ */
+ public TagLibrary getTagLibrary()
+ {
+ return tagLibrary;
+ }
+
+ /* (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/taglib/TagLibraryReference.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagLibraryReference.java
new file mode 100644
index 0000000..33a8fe5
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagLibraryReference.java
@@ -0,0 +1,48 @@
+/**
+ * <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.taglib;
+
+/**
+ * Represent a reference to a tag library by a template or a transform.
+ */
+public interface TagLibraryReference
+{
+
+ /**
+ * Return the prefix that is mapped to the tag library.
+ * @return a string
+ */
+ public abstract String getPrefix();
+
+ /**
+ * Return the tag library id.
+ * @return a string
+ */
+ public abstract String getTagLibraryId();
+
+ /**
+ * Return the TagLibrary description object.
+ * @return an TagLibrary instance
+ */
+ public abstract TagLibrary getTagLibrary();
+
+ /**
+ * Test whether the tag library is automatically imported bundle templates.
+ * @return <code>true</code> if the library is an auto imported library.
+ */
+ public abstract boolean isAutoImport();
+}
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
new file mode 100644
index 0000000..ba85e17
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/IJETBundleDescriptor.java
@@ -0,0 +1,92 @@
+/**
+ * <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.jet.taglib.TagLibraryReference;
+
+/**
+ * Provide descriptive information about a JET Project/transform/bundle.
+ */
+public interface IJETBundleDescriptor
+{
+
+ /**
+ * Return the unique identifier of the bundle.
+ * @return the bundle's unique identifier
+ */
+ public abstract String getId();
+
+ /**
+ * Return the bundle's descriptive name.
+ * @return the bundle's descriptive name
+ */
+ public abstract String getName();
+
+ /**
+ * Return a description of the bundle.
+ * @return a string
+ */
+ public abstract String getDescription();
+
+ /**
+ * Return the id of the model loader the bundle expects to use.
+ * @return a string or <code>null</code> if the bundle does not specify a model loader.
+ */
+ public abstract String getModelLoaderId();
+
+ /**
+ * Return the model extension that the bundle expects its input to conform to.
+ * @return a string or <code>null</code> if the bundle does not specific a model extension.
+ */
+ public abstract String getModelExtension();
+
+ /**
+ * Return the id of a JET bundle that this bundle overrides.
+ * @return a string or <code>null</code> if the bundle does not override another bundle.
+ */
+ public abstract String getOverridesId();
+
+ /**
+ * Return the bundle version string.
+ * @return a string, typically of the form n.n.n.string.
+ */
+ public abstract String getVersion();
+
+ /**
+ * Return the name of the entity that created the bundle.
+ * @return a string
+ */
+ public abstract String getProvider();
+
+ /**
+ * Return an array containing the tag libraries imported by the bundle.
+ * @return
+ */
+ public abstract TagLibraryReference[] getTagLibraryReferences();
+
+ /**
+ * Return the template loader class for the bundle.
+ * @return a fully qualified Java class name, or <code>null</code> if not specified.
+ */
+ public abstract String getTemplateLoaderClass();
+
+ /**
+ * Return a bundle relative path to the main template for the bundle.
+ * @return a bundle relative path to a template, or <code>null</code> if not specified.
+ */
+ public abstract String getMainTemplate();
+}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJET2Parser.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJET2Parser.java
index 6f60af4..79f3ad8 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJET2Parser.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJET2Parser.java
@@ -24,6 +24,7 @@ import org.eclipse.jet.compiler.XMLBodyElement;
import org.eclipse.jet.compiler.XMLBodyElementEnd;
import org.eclipse.jet.compiler.XMLEmptyElement;
import org.eclipse.jet.internal.compiler.templates.JET2JavaGenerator;
+import org.eclipse.jet.taglib.TagLibraryReference;
import org.eclipse.jet.tests.FileUtils;
public class TestJET2Parser extends TestCase {
@@ -213,6 +214,21 @@ public class TestJET2Parser extends TestCase {
}
+ public void testCompilationUnit_getTagLibraryReferences() throws Exception {
+ String urlString = "platform:/plugin/org.eclipse.jet.tests/data/taglibs.jet";
+
+ InputStream is = getFileContentsAsStream(urlString);
+
+ JET2CompilationUnit cu = new JET2CompilationUnit();
+ cu.parse(is, "UTF-8");
+
+ final TagLibraryReference[] tlRefs = cu.getTagLibraryReferences();
+ assertNotNull(tlRefs);
+ assertEquals(1, tlRefs.length);
+ assertEquals("test", tlRefs[0].getPrefix());
+ assertEquals("org.eclipse.jet.tests.TestLibrary", tlRefs[0].getTagLibraryId());
+ }
+
public void testCodeGen() throws Exception {
// HACK: Disabling this test on Unix/Linux/Mac until uniform treatment of
// line separators in generated code is handled.
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/runtime/AllTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/runtime/AllTests.java
index 0debdf6..d2e7fe9 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/runtime/AllTests.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/runtime/AllTests.java
@@ -9,6 +9,7 @@ public class AllTests {
TestSuite suite = new TestSuite(
"Test for org.eclipse.jet.tests.runtime");
//$JUnit-BEGIN$
+ suite.addTestSuite(TestBundleDescriptions.class);
suite.addTestSuite(TestBundleLoading.class);
//$JUnit-END$
return suite;
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
new file mode 100644
index 0000000..25b77d1
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/runtime/TestBundleDescriptions.java
@@ -0,0 +1,38 @@
+package org.eclipse.jet.tests.runtime;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jet.JET2Platform;
+import org.eclipse.jet.taglib.TagLibraryReference;
+import org.eclipse.jet.transform.IJETBundleDescriptor;
+
+public class TestBundleDescriptions extends TestCase {
+
+ public void testGetProjectDescription()
+ {
+ final IStatus result = JET2Platform.execute("org.eclipse.jet.transforms.newproject",
+ "<newProjectModel><project name=\"foo.bar\"/></newProjectModel>",
+ new NullProgressMonitor());
+
+ assertTrue(result.isOK());
+
+ final IJETBundleDescriptor desc = JET2Platform.getProjectDescription("foo.bar");
+ assertNotNull(desc);
+ assertEquals("foo.bar", desc.getId());
+ assertEquals("foo.bar", desc.getName());
+ final TagLibraryReference[] tlRefs = desc.getTagLibraryReferences();
+ 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("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());
+ }
+
+}