summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-04-13 10:34:27 (EDT)
committer pelder2006-04-13 10:34:27 (EDT)
commit1bdce577716470bdfd117964e4781a0d536d73b4 (patch)
treee5a75a7c9c51a0b9d57e3025c367a618b71567a2
parent203876711deb9f70d340fc617d2b9142ee58b5a6 (diff)
downloadorg.eclipse.jet-1bdce577716470bdfd117964e4781a0d536d73b4.zip
org.eclipse.jet-1bdce577716470bdfd117964e4781a0d536d73b4.tar.gz
org.eclipse.jet-1bdce577716470bdfd117964e4781a0d536d73b4.tar.bz2
[136649] Ant tasks to compile and execute JET transforms.
-rw-r--r--plugins/org.eclipse.jet/.classpath1
-rw-r--r--plugins/org.eclipse.jet/.settings/org.eclipse.pde.core.prefs3
-rw-r--r--plugins/org.eclipse.jet/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.jet/antsrc/org/eclipse/jet/ant/tasks/JETCompileTask.java95
-rw-r--r--plugins/org.eclipse.jet/antsrc/org/eclipse/jet/ant/tasks/JETTransformTask.java94
-rw-r--r--plugins/org.eclipse.jet/build.properties10
-rw-r--r--plugins/org.eclipse.jet/plugin.xml15
7 files changed, 218 insertions, 3 deletions
diff --git a/plugins/org.eclipse.jet/.classpath b/plugins/org.eclipse.jet/.classpath
index 751c8f2..f5a1d79 100644
--- a/plugins/org.eclipse.jet/.classpath
+++ b/plugins/org.eclipse.jet/.classpath
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
+ <classpathentry output="antbin" kind="src" path="antsrc"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
diff --git a/plugins/org.eclipse.jet/.settings/org.eclipse.pde.core.prefs b/plugins/org.eclipse.jet/.settings/org.eclipse.pde.core.prefs
new file mode 100644
index 0000000..610b17f
--- /dev/null
+++ b/plugins/org.eclipse.jet/.settings/org.eclipse.pde.core.prefs
@@ -0,0 +1,3 @@
+#Thu Apr 13 09:55:43 EDT 2006
+eclipse.preferences.version=1
+selfhosting.binExcludes=/org.eclipse.jet/antbin
diff --git a/plugins/org.eclipse.jet/META-INF/MANIFEST.MF b/plugins/org.eclipse.jet/META-INF/MANIFEST.MF
index 73a0c8b..3024585 100644
--- a/plugins/org.eclipse.jet/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.jet/META-INF/MANIFEST.MF
@@ -16,7 +16,8 @@ Require-Bundle: org.eclipse.ant.core,
org.eclipse.text;visibility:=reexport,
org.eclipse.core.expressions,
org.eclipse.core.filebuffers,
- org.eclipse.jdt.core
+ org.eclipse.jdt.core,
+ org.apache.ant
Eclipse-AutoStart: true
Export-Package: org.eclipse.jet,
org.eclipse.jet.compiler,
diff --git a/plugins/org.eclipse.jet/antsrc/org/eclipse/jet/ant/tasks/JETCompileTask.java b/plugins/org.eclipse.jet/antsrc/org/eclipse/jet/ant/tasks/JETCompileTask.java
new file mode 100644
index 0000000..ecca6e8
--- /dev/null
+++ b/plugins/org.eclipse.jet/antsrc/org/eclipse/jet/ant/tasks/JETCompileTask.java
@@ -0,0 +1,95 @@
+/**
+ * <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 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.ant.tasks;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.types.FileSet;
+import org.eclipse.ant.core.AntCorePlugin;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jet.compiler.JET2Compiler;
+
+/**
+ * Implement the jet.compile tag.
+ *
+ */
+public class JETCompileTask extends Task {
+
+ private List srcFilesets = new ArrayList();
+ private String destdir;
+ private IProject eclipseProject;
+ private Map jetBuildProperties = new HashMap();
+
+ /**
+ *
+ */
+ public JETCompileTask() {
+ super();
+ }
+
+ public void addSrcdir(FileSet srcdir) {
+ srcFilesets.add(srcdir);
+
+ }
+
+ public void setDestdir(String destdir) {
+ this.destdir = destdir;
+
+ }
+
+ public void setProject(String eclipseProject) {
+ this.eclipseProject = ResourcesPlugin.getWorkspace().getRoot().getProject(eclipseProject);
+ }
+
+ private void validate() {
+ if(destdir == null) throw new BuildException("destdir not set");
+ if(srcFilesets.size() == 0) throw new BuildException("srcdir not set");
+ if(!eclipseProject.exists()) throw new BuildException("project does not exist");
+ if(!eclipseProject.isOpen()) throw new BuildException("project is not open");
+ }
+
+ public void execute() throws BuildException {
+ validate();
+ IProgressMonitor monitor =
+ (IProgressMonitor) getProject().getReferences().get(AntCorePlugin.ECLIPSE_PROGRESS_MONITOR);
+ jetBuildProperties.put(JET2Compiler.OPTION_COMPILED_TEMPLATE_SRC_DIR, destdir);
+ log("destdir: " + destdir);
+ JET2Compiler compiler = new JET2Compiler(eclipseProject, monitor, jetBuildProperties);
+ for (Iterator i = srcFilesets.iterator(); i.hasNext();) {
+ FileSet fileset = (FileSet) i.next();
+ final DirectoryScanner ds = fileset.getDirectoryScanner(getProject());
+ final String[] includedFiles = ds.getIncludedFiles();
+ for (int j = 0; j < includedFiles.length; j++) {
+ log("Compiling: " + includedFiles[j], Project.MSG_INFO);
+ compiler.compile(eclipseProject.getFile(includedFiles[j]));
+ }
+ }
+ compiler.createTransformFiles();
+ }
+}
+
diff --git a/plugins/org.eclipse.jet/antsrc/org/eclipse/jet/ant/tasks/JETTransformTask.java b/plugins/org.eclipse.jet/antsrc/org/eclipse/jet/ant/tasks/JETTransformTask.java
new file mode 100644
index 0000000..3253ce5
--- /dev/null
+++ b/plugins/org.eclipse.jet/antsrc/org/eclipse/jet/ant/tasks/JETTransformTask.java
@@ -0,0 +1,94 @@
+/**
+ * <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 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.ant.tasks;
+
+import java.text.MessageFormat;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.eclipse.ant.core.AntCorePlugin;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jet.JET2Platform;
+
+/**
+ * Implement an ANT Task to run a JET transform.
+ *
+ */
+public class JETTransformTask extends Task {
+
+ private String transformId = null;
+
+ private String source = null;
+ /**
+ *
+ */
+ public JETTransformTask() {
+ super();
+ // TODO Auto-generated constructor stub
+ }
+
+ public final String getTransformId() {
+ return transformId;
+ }
+
+ public final void setTransformId(String transformId) {
+ this.transformId = transformId;
+ }
+
+ public final String getSource() {
+ return source;
+ }
+
+ public final void setSource(String source) {
+ this.source = source;
+ }
+
+ public void execute() throws BuildException {
+ final String missingAttrMsg = "Missing required attribute ''{0}''";
+ if(transformId == null) {
+ throw new BuildException(MessageFormat.format(missingAttrMsg, new Object[] {"transformId"})); //$NON-NLS-1$
+ }
+ if(source == null) {
+ throw new BuildException(MessageFormat.format(missingAttrMsg, new Object[] {"source"})); //$NON-NLS-1$
+ }
+
+ final IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(source);
+
+ if(resource == null) {
+ throw new BuildException("Could not find resource \"" + source + "\".");
+ }
+
+ IProgressMonitor monitor =
+ (IProgressMonitor) getProject().getReferences().get(AntCorePlugin.ECLIPSE_PROGRESS_MONITOR);
+ if(monitor == null) {
+ monitor = new NullProgressMonitor();
+ }
+
+ log("Running \"" + transformId + "\" on resource \"" + resource.toString() + "\".");
+
+ final IStatus result = JET2Platform.runTransformOnResource(transformId, resource, monitor);
+ if(!result.isOK()) {
+ throw new BuildException(result.getMessage());
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/build.properties b/plugins/org.eclipse.jet/build.properties
index abc0397..b36a4f6 100644
--- a/plugins/org.eclipse.jet/build.properties
+++ b/plugins/org.eclipse.jet/build.properties
@@ -17,7 +17,8 @@ bin.includes = META-INF/,\
about.html,\
.options,\
.deprecations/,\
- .jetproperties
+ .jetproperties,\
+ jetant.jar
src.includes = templates/,\
about.html,\
.options,\
@@ -36,4 +37,9 @@ src.includes = templates/,\
.jetproperties,\
build.properties,\
.project,\
- .settings/
+ .settings/,\
+ antsrc/
+jars.compile.order = .,\
+ jetant.jar
+source.jetant.jar = antsrc/
+output.jetant.jar = antbin/
diff --git a/plugins/org.eclipse.jet/plugin.xml b/plugins/org.eclipse.jet/plugin.xml
index 4880d33..3e82dc8 100644
--- a/plugins/org.eclipse.jet/plugin.xml
+++ b/plugins/org.eclipse.jet/plugin.xml
@@ -1379,6 +1379,21 @@ if 'length' is specified, convert only the specified number of characters, other
minArgs="1"
name="uppercaseFirst"/>
</extension>
+ <extension
+ point="org.eclipse.ant.core.antTasks">
+ <antTask
+ class="org.eclipse.jet.ant.tasks.JETCompileTask"
+ eclipseRuntime="true"
+ headless="true"
+ library="jetant.jar"
+ name="jet.compile"/>
+ <antTask
+ class="org.eclipse.jet.ant.tasks.JETTransformTask"
+ eclipseRuntime="true"
+ headless="true"
+ library="jetant.jar"
+ name="jet.transform"/>
+ </extension>
</plugin>