Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoratikhomirov2008-10-31 15:38:50 +0000
committeratikhomirov2008-10-31 15:38:50 +0000
commiteadfbad914bae520f451bbb7b66a57ca26d03cbd (patch)
tree508d069bb642aa91ef66d274104656eb992be2fd
parenteb6cce8e47fe5d52bd317afb1cf7cf5ae89e4739 (diff)
downloadorg.eclipse.gmf-tooling-eadfbad914bae520f451bbb7b66a57ca26d03cbd.tar.gz
org.eclipse.gmf-tooling-eadfbad914bae520f451bbb7b66a57ca26d03cbd.tar.xz
org.eclipse.gmf-tooling-eadfbad914bae520f451bbb7b66a57ca26d03cbd.zip
[251588] Ant integration for GMF-Xpand - extracted and reused inputURI
-rw-r--r--plugins/org.eclipse.gmf.xpand.ant/src-ant/org/eclipse/gmf/internal/xpand/ant/CodegenFlowTask.java5
-rw-r--r--plugins/org.eclipse.gmf.xpand.ant/src-ant/org/eclipse/gmf/internal/xpand/ant/InputSupport.java58
-rw-r--r--plugins/org.eclipse.gmf.xpand.ant/src-ant/org/eclipse/gmf/internal/xpand/ant/InvokeFewTemplatesTask.java6
-rw-r--r--plugins/org.eclipse.gmf.xpand.ant/src-ant/org/eclipse/gmf/internal/xpand/ant/InvokeTemplateTask.java35
4 files changed, 75 insertions, 29 deletions
diff --git a/plugins/org.eclipse.gmf.xpand.ant/src-ant/org/eclipse/gmf/internal/xpand/ant/CodegenFlowTask.java b/plugins/org.eclipse.gmf.xpand.ant/src-ant/org/eclipse/gmf/internal/xpand/ant/CodegenFlowTask.java
index 44e6cb1d0..bd3d58c80 100644
--- a/plugins/org.eclipse.gmf.xpand.ant/src-ant/org/eclipse/gmf/internal/xpand/ant/CodegenFlowTask.java
+++ b/plugins/org.eclipse.gmf.xpand.ant/src-ant/org/eclipse/gmf/internal/xpand/ant/CodegenFlowTask.java
@@ -24,6 +24,7 @@ import org.apache.tools.ant.UnknownElement;
public class CodegenFlowTask extends Task implements TaskContainer {
private final LinkedList<Task> myTasks = new LinkedList<Task>();
+ private final InputSupport myInput = new InputSupport();
private String[] myTemplateRoots;
public CodegenFlowTask() {
@@ -44,7 +45,8 @@ public class CodegenFlowTask extends Task implements TaskContainer {
public void setOutputRoot(String outputRoot) {
}
- public void setInputModel(String input) {
+ public void setInputURI(String uri) {
+ myInput.setURI(uri);
}
@Override
@@ -64,6 +66,7 @@ public class CodegenFlowTask extends Task implements TaskContainer {
}
if (t instanceof InvokeTemplateTask) {
((InvokeTemplateTask) t).setFacade(xf);
+ ((InvokeTemplateTask) t).setTemplateTarget(myInput);
}
}
ps.worked(2);
diff --git a/plugins/org.eclipse.gmf.xpand.ant/src-ant/org/eclipse/gmf/internal/xpand/ant/InputSupport.java b/plugins/org.eclipse.gmf.xpand.ant/src-ant/org/eclipse/gmf/internal/xpand/ant/InputSupport.java
new file mode 100644
index 000000000..02407386c
--- /dev/null
+++ b/plugins/org.eclipse.gmf.xpand.ant/src-ant/org/eclipse/gmf/internal/xpand/ant/InputSupport.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2008 Borland Software Corporation
+ *
+ * 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:
+ * Artem Tikhomirov (Borland) - initial API and implementation
+ */
+package org.eclipse.gmf.internal.xpand.ant;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.plugin.EcorePlugin;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+
+class InputSupport {
+ private String myInputURI;
+ private Object myInputObject;
+ private ResourceSetImpl myResourceSet;
+ private InputSupport myChain;
+
+ public void setBareInput(String input) {
+ myInputObject = input;
+ }
+
+ public void setURI(String uri) {
+ myInputURI = uri;
+ }
+
+ protected ResourceSet getResourceSet() {
+ if (myResourceSet == null) {
+ myResourceSet = new ResourceSetImpl();
+ myResourceSet.getURIConverter().getURIMap().putAll(EcorePlugin.computePlatformURIMap());
+ }
+ return myResourceSet;
+ }
+
+ public Object getTarget() {
+ if (myInputURI != null) {
+ return getResourceSet().getEObject(URI.createURI(myInputURI), true);
+ }
+ if (myInputObject != null) {
+ return myInputObject;
+ }
+ if (myChain != null) {
+ return myChain.getTarget();
+ }
+ return null;
+ }
+
+ public void chain(InputSupport input) {
+ myChain = input;
+ }
+
+}
diff --git a/plugins/org.eclipse.gmf.xpand.ant/src-ant/org/eclipse/gmf/internal/xpand/ant/InvokeFewTemplatesTask.java b/plugins/org.eclipse.gmf.xpand.ant/src-ant/org/eclipse/gmf/internal/xpand/ant/InvokeFewTemplatesTask.java
index ff39b9a33..47aa4e6a9 100644
--- a/plugins/org.eclipse.gmf.xpand.ant/src-ant/org/eclipse/gmf/internal/xpand/ant/InvokeFewTemplatesTask.java
+++ b/plugins/org.eclipse.gmf.xpand.ant/src-ant/org/eclipse/gmf/internal/xpand/ant/InvokeFewTemplatesTask.java
@@ -22,6 +22,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
public class InvokeFewTemplatesTask extends Task {
private final LinkedList<InvokeTemplateTask> myTemplates = new LinkedList<InvokeTemplateTask>();
+ private final InputSupport myInput = new InputSupport();
private String[] myTemplateRoots;
public void setTemplateRoot(String root) {
@@ -39,6 +40,10 @@ public class InvokeFewTemplatesTask extends Task {
}
+ public void setInputURI(String uri) {
+ myInput.setURI(uri);
+ }
+
@Override
public void execute() throws BuildException {
IProgressMonitor pm = new ProgressSupport(this);
@@ -46,6 +51,7 @@ public class InvokeFewTemplatesTask extends Task {
XpandFacade xf = createFacade();
for (InvokeTemplateTask tt : myTemplates) {
tt.setFacade(xf);
+ tt.setTemplateTarget(myInput);
tt.validate();
pm.worked(1);
}
diff --git a/plugins/org.eclipse.gmf.xpand.ant/src-ant/org/eclipse/gmf/internal/xpand/ant/InvokeTemplateTask.java b/plugins/org.eclipse.gmf.xpand.ant/src-ant/org/eclipse/gmf/internal/xpand/ant/InvokeTemplateTask.java
index 2c2339f78..fc6ebfa7b 100644
--- a/plugins/org.eclipse.gmf.xpand.ant/src-ant/org/eclipse/gmf/internal/xpand/ant/InvokeTemplateTask.java
+++ b/plugins/org.eclipse.gmf.xpand.ant/src-ant/org/eclipse/gmf/internal/xpand/ant/InvokeTemplateTask.java
@@ -21,10 +21,6 @@ import java.util.StringTokenizer;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.plugin.EcorePlugin;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
/**
* <p>... xmlns:xpt=<em>&quot;eclipse.org/gmf/2008/xpand&quot;</em>...
@@ -36,23 +32,21 @@ import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
public class InvokeTemplateTask extends Task {
private String myTemplateName;
- private String myInputURI;
private String[] myTemplateRoots;
private String myOutFile;
private XpandFacade myFacade;
- private Object myInputObject;
- private ResourceSetImpl myResourceSet;
+ private final InputSupport myInput = new InputSupport();
public void setName(String name) {
myTemplateName = name;
}
public void setBareInput(String input) {
- myInputObject = input;
+ myInput.setBareInput(input);
}
public void setInputURI(String uri) {
- myInputURI = uri;
+ myInput.setURI(uri);
}
public void setOutFile(String uri) {
@@ -81,7 +75,7 @@ public class InvokeTemplateTask extends Task {
protected void doExecute() throws BuildException {
XpandFacade xf = createExecFacade();
- String result = xf.xpand(myTemplateName, getTemplateTarget(), getTemplateArguments());
+ String result = xf.xpand(myTemplateName, myInput.getTarget(), getTemplateArguments());
if (myOutFile == null) {
System.err.println(result);
} else {
@@ -100,7 +94,7 @@ public class InvokeTemplateTask extends Task {
if (myTemplateName == null) {
throw new BuildException("Template name is missing", getLocation());
}
- if (myInputURI == null && myInputObject == null) {
+ if (myInput.getTarget() == null) {
throw new BuildException("Target object is missing", getLocation());
}
if (myFacade == null && (myTemplateRoots == null || myTemplateRoots.length == 0)) {
@@ -108,19 +102,12 @@ public class InvokeTemplateTask extends Task {
}
}
- protected Object getTemplateTarget() {
- if (myInputURI != null) {
- return getResourceSet().getEObject(URI.createURI(myInputURI), true);
- }
- return myInputObject;
- }
-
protected Object[] getTemplateArguments() {
return null;
}
- protected void setInputObject(Object input) {
- myInputObject = input;
+ protected void setTemplateTarget(InputSupport input) {
+ myInput.chain(input);
}
protected void setFacade(XpandFacade xf) {
@@ -147,12 +134,4 @@ public class InvokeTemplateTask extends Task {
throw new BuildException(ex, getLocation());
}
}
-
- protected ResourceSet getResourceSet() {
- if (myResourceSet == null) {
- myResourceSet = new ResourceSetImpl();
- myResourceSet.getURIConverter().getURIMap().putAll(EcorePlugin.computePlatformURIMap());
- }
- return myResourceSet;
- }
}

Back to the top