summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-03-29 09:32:35 (EST)
committer pelder2006-03-29 09:32:35 (EST)
commit81dc9f81dbd28b780503891ead8a0f72b21fead8 (patch)
tree84555f1fd506cbb3e027574672b6fe5c22a20a7b
parent9c0118baf54aabd4d269d61ecabcb12b763daea7 (diff)
downloadorg.eclipse.jet-81dc9f81dbd28b780503891ead8a0f72b21fead8.zip
org.eclipse.jet-81dc9f81dbd28b780503891ead8a0f72b21fead8.tar.gz
org.eclipse.jet-81dc9f81dbd28b780503891ead8a0f72b21fead8.tar.bz2
[133842] Add properties merge to the <java:merge> tag.
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/MergeTag.java99
1 files changed, 59 insertions, 40 deletions
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/MergeTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/MergeTag.java
index 96d869b..515af64 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/MergeTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/MergeTag.java
@@ -20,14 +20,11 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.text.MessageFormat;
-import org.eclipse.core.filebuffers.FileBuffers;
-import org.eclipse.core.filebuffers.ITextFileBuffer;
-import org.eclipse.core.filebuffers.ITextFileBufferManager;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.codegen.jmerge.JControlModel;
import org.eclipse.emf.codegen.jmerge.JMerger;
+import org.eclipse.emf.codegen.jmerge.PropertyMerger;
import org.eclipse.jdt.core.jdom.DOMFactory;
import org.eclipse.jdt.core.jdom.IDOMCompilationUnit;
import org.eclipse.jdt.core.jdom.IDOMFactory;
@@ -37,6 +34,7 @@ import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.taglib.AbstractEmptyTag;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.TagInfo;
+import org.eclipse.jet.taglib.TagUtil;
import org.eclipse.jet.transform.TransformContextExtender;
import org.eclipse.jface.text.Position;
@@ -95,53 +93,74 @@ public class MergeTag extends AbstractEmptyTag
if(file instanceof IFile)
{
IFile iFile = (IFile)file;
- if(!"java".equals(iFile.getFileExtension())) //$NON-NLS-1$
- {
- throw new JET2TagException("This tag is only applicable to Java files.");
- }
-
if(!iFile.exists())
{
return;
}
-
- final Position[] positions = writer.getPositions(JMERGE_POSITION_CATEGORY);
-
- final ITextFileBufferManager textFileBufferManager = FileBuffers.getTextFileBufferManager();
- try
+ if("java".equals(iFile.getFileExtension())) //$NON-NLS-1$
{
- textFileBufferManager.connect(iFile.getLocation(), new NullProgressMonitor());
- try
- {
-
- final ITextFileBuffer textFileBuffer = textFileBufferManager.getTextFileBuffer(iFile.getLocation());
- IDOMFactory domFactory = new DOMFactory();
-
- IDOMCompilationUnit sourceCU = domFactory.createCompilationUnit(
- writer.toString(), iFile.getName());
-
- IDOMCompilationUnit targetCU = domFactory.createCompilationUnit(
- textFileBuffer.getDocument().get(), iFile.getName());
- JControlModel controlModel = new JControlModel(((MergePosition)positions[0]).getRulesURL().toExternalForm());
- JMerger merger = new JMerger(controlModel , sourceCU, targetCU);
-
- merger.merge();
-
- writer.getDocument().set(targetCU.getContents());
- }
- finally
- {
- textFileBufferManager.disconnect(iFile.getLocation(), new NullProgressMonitor());
- }
+ jmerge(writer, iFile);
}
- catch (CoreException e)
+ else if("properties".equals(iFile.getFileExtension())) //$NON-NLS-1$
{
- final String msg = "Unable to read existing java file {0}";
- throw new JET2TagException(MessageFormat.format(msg, new Object[] {iFile.getFullPath()}));
+ propmerge(writer, iFile);
}
}
}
+ private void propmerge(JET2Writer writer, IFile file) throws JET2TagException
+ {
+ PropertyMerger merger = new PropertyMerger();
+
+ try
+ {
+ String targetPropertiesString = TagUtil.getContents(file.getLocation());
+
+ merger.setSourceProperties(writer.getDocument().get());
+ merger.setTargetProperties(targetPropertiesString);
+
+ merger.merge();
+
+ writer.getDocument().set(merger.getTargetProperties());
+ }
+ catch (CoreException e)
+ {
+ final String msg = "Unable to read file {0}";
+ throw new JET2TagException(MessageFormat.format(msg, new Object []{ file.getFullPath() }));
+ }
+ }
+
+ /**
+ * @param writer
+ * @param iFile
+ * @throws JET2TagException
+ */
+ private void jmerge(JET2Writer writer, IFile iFile) throws JET2TagException
+ {
+ final Position[] positions = writer.getPositions(JMERGE_POSITION_CATEGORY);
+
+ try
+ {
+ String targetCUSource = TagUtil.getContents(iFile.getLocation());
+ IDOMFactory domFactory = new DOMFactory();
+
+ IDOMCompilationUnit sourceCU = domFactory.createCompilationUnit(writer.toString(), iFile.getName());
+
+ IDOMCompilationUnit targetCU = domFactory.createCompilationUnit(targetCUSource, iFile.getName());
+ JControlModel controlModel = new JControlModel(((MergePosition)positions[0]).getRulesURL().toExternalForm());
+ JMerger merger = new JMerger(controlModel, sourceCU, targetCU);
+
+ merger.merge();
+
+ writer.getDocument().set(targetCU.getContents());
+ }
+ catch (CoreException e)
+ {
+ final String msg = "Unable to read file {0}";
+ throw new JET2TagException(MessageFormat.format(msg, new Object []{ iFile.getFullPath() }));
+ }
+ }
+
/* (non-Javadoc)
* @see org.eclipse.jet.IWriterListener#postCommitContent(org.eclipse.jet.JET2Writer, java.lang.Object)
*/