Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2007-12-21 15:33:16 -0500
committerpelder2007-12-21 15:33:16 -0500
commitd7a02dc07ef527ea7b743e15d24271395022d35a (patch)
tree97426d4482372323784b80fa52d260344d052f4d
parent36e54e0479983b001954befbba3772f2f7a14de1 (diff)
downloadorg.eclipse.jet-d7a02dc07ef527ea7b743e15d24271395022d35a.tar.gz
org.eclipse.jet-d7a02dc07ef527ea7b743e15d24271395022d35a.tar.xz
org.eclipse.jet-d7a02dc07ef527ea7b743e15d24271395022d35a.zip
[212575] Provide better compile error recovery for the java:merge tag
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.java4
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.properties2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/MergeTag.java9
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/ActionsUtil.java67
4 files changed, 76 insertions, 6 deletions
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.java
index a4e8cb1..6453d83 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.java
@@ -88,6 +88,10 @@ public class JET2Messages extends NLS
public static String MergeTag_CouldNotRead;
+ public static String MergeTag_FailedOnCompilerError;
+
+ public static String MergeTag_UnknownJMergeFacadeHelper;
+
public static String ModelLoaderExtManager_TypeAlreadyDefined;
public static String ReplaceStringsTag_BadList;
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.properties b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.properties
index 7b35e99..3e0f5b5 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.properties
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.properties
@@ -161,9 +161,11 @@ LoaderManager_MultipleLoaders=Multiple loaders found for ''{0}'': {1}
LoaderManager_CouldNotFindLoader=Could not find a loader for ''{0}''
MergeTag_CouldNotRead=Unable to read file {0}
MergeTag_CouldNotCreateURL=Could not create URL({0}, {1})
+MergeTag_FailedOnCompilerError=Merge of generated content into {0} failed because of a compilation error. Re-run the transformation after you fix the any errors in the file, or rename or delete the file.
MarkerHelper_CouldNotCreateMarker=Unable to create marker on file {0}
TransformContextExtender_NeedsRebuildForOverride=Transformation {0} needs to be rebuild in order to support override
ReplaceStringsTag_BadList=Error parsing comma-separated list of strings:
ReplaceStringsTag_ListsNotSameLength='Replace' list and 'With' list have different lengths.
ReplaceStringsTag_EmptyList='Replace' list contains empty strings.
ASTCompilerParseListener_UnsupportedDirective=Unsupported directive ''{0}''
+MergeTag_UnknownJMergeFacadeHelper=Unknown JMerge facade helper: {0}
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 6da8613..27b52c1 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
@@ -28,6 +28,7 @@ import org.eclipse.emf.codegen.merge.java.facade.FacadeHelper;
import org.eclipse.emf.codegen.merge.java.facade.JCompilationUnit;
import org.eclipse.emf.codegen.merge.properties.PropertyMerger;
import org.eclipse.emf.codegen.util.CodeGenUtil;
+import org.eclipse.emf.common.util.WrappedException;
import org.eclipse.jet.BufferedJET2Writer;
import org.eclipse.jet.IWriterListener;
import org.eclipse.jet.JET2Context;
@@ -186,6 +187,12 @@ public class MergeTag extends AbstractEmptyTag
// This should not happen. Wrap in a runtime exception
throw new RuntimeException(e);
}
+ catch (WrappedException e)
+ {
+ final String baseMsg = JET2Messages.MergeTag_FailedOnCompilerError;
+ final String msg = MessageFormat.format(baseMsg, new Object[] {iFile.getFullPath().makeRelative()});
+ throw new JET2TagException(msg, e.exception());
+ }
}
/* (non-Javadoc)
@@ -248,7 +255,7 @@ private static final String JMERGE_POSITION_CATEGORY = MergeTag.class.getName();
{
FacadeHelper facadeHelper = CodeGenUtil.instantiateFacadeHelper(facade);
if(facadeHelper == null) {
- throw new JET2TagException(MessageFormat.format("Unknown JMerge facade helper: {0}",
+ throw new JET2TagException(MessageFormat.format(JET2Messages.MergeTag_UnknownJMergeFacadeHelper,
new Object []{ facade }));
}
URL rulesURL = new URL(baseURL, rules);
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/ActionsUtil.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/ActionsUtil.java
index 65b8234..969f8b4 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/ActionsUtil.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/ActionsUtil.java
@@ -17,6 +17,7 @@ package org.eclipse.jet.taglib.workspace;
import java.io.BufferedInputStream;
+import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -212,14 +213,19 @@ public final class ActionsUtil
}
monitor.worked(1);
+ // Step 4: check if contents have changed...
+ boolean contentsChanged = checkForContentChange(file, source);
+
// Step 5: write the contents - we created the file in step 1, so we only need to set its proper contents
- file.setContents(source, false, true, new SubProgressMonitor(monitor, 2));
+ if(contentsChanged) {
+ file.setContents(source, false, true, new SubProgressMonitor(monitor, 2));
+ }
// RuntimeLoggerContextExtender.log(context, fileMessage, tagInfo, templatePath);
// Step 6: Apply generated file properties...
file.setDerived(derived);
- return true;
+ return contentsChanged;
}
catch (UnsupportedEncodingException e)
{
@@ -235,6 +241,55 @@ public final class ActionsUtil
}
}
+ private static boolean checkForContentChange(IFile file, InputStream source) throws CoreException
+ {
+ boolean changed = false;
+ if(!file.exists())
+ {
+ return changed;
+ }
+ InputStream existing = null;
+ try {
+ existing = new BufferedInputStream(file.getContents());
+
+ final int bufferSize = 8196;
+ byte[] srcBuffer = new byte[bufferSize];
+ byte[] tgtBuffer = new byte[bufferSize];
+
+ while(true) {
+ int srcRead = source.read(srcBuffer);
+ int tgtRead = existing.read(tgtBuffer);
+ if(tgtRead != srcRead) {
+ changed = true;
+ break;
+ } else if(srcRead == -1) {
+ changed = srcRead != -1;
+ break;
+ } else if(!Arrays.equals(srcBuffer, tgtBuffer)) {
+ changed = true;
+ break;
+ }
+ }
+ if(changed) {
+ // rewind to the beginning, so we can write it
+ source.reset();
+ }
+ }
+ catch (IOException e)
+ {
+ changed = true; // couldn't read -- assume we must write
+ } finally {
+ if(existing != null) {
+ try {
+ existing.close();
+ } catch(IOException e) {
+ // ignore
+ }
+ }
+ }
+ return changed;
+ }
+
/**
* Ensure that a folder exists by creating it and any of its parents if necessary.
* @param folder the folder to ensure exists.
@@ -354,13 +409,15 @@ public final class ActionsUtil
reader = new InputStreamReader(input);
}
+ final int buffer_size = 8192;
+ final BufferedReader bufferedReader = new BufferedReader(reader, buffer_size);
StringBuffer inputContents = new StringBuffer();
- char readChars[] = new char [1024];
- for (int read = reader.read(readChars); read != -1; read = reader.read(readChars))
+ char readChars[] = new char [buffer_size];
+ for (int read = bufferedReader.read(readChars); read != -1; read = bufferedReader.read(readChars))
{
inputContents.append(readChars, 0, read);
}
- reader.close();
+ bufferedReader.close();
input.close();
return inputContents.toString();
}

Back to the top