Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilos Kleint2011-07-21 03:28:27 -0400
committerMilos Kleint2011-07-21 03:28:27 -0400
commit593ab33c38324bef158c2d7320dd5e0e945378e8 (patch)
tree9031127fcacc8ca8e9b55cfc193dd03ce3b92279
parente043662934bb501c6e6190a74be224bbd8b01034 (diff)
downloadm2e-core-593ab33c38324bef158c2d7320dd5e0e945378e8.tar.gz
m2e-core-593ab33c38324bef158c2d7320dd5e0e945378e8.tar.xz
m2e-core-593ab33c38324bef158c2d7320dd5e0e945378e8.zip
minor api addition to allow creating TextChange instances for refactoring that save all the pom files encountered. Fixes problems with partial reload of a project when changes are distributed to multiple pom files.
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/PomHelper.java54
1 files changed, 32 insertions, 22 deletions
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/PomHelper.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/PomHelper.java
index 00dae4b4..97c765f6 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/PomHelper.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/PomHelper.java
@@ -8,25 +8,7 @@
package org.eclipse.m2e.core.ui.internal.editing;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.ARTIFACT_ID;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.CLASSIFIER;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.DEPENDENCIES;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.DEPENDENCY;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.GROUP_ID;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.PLUGIN;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.SCOPE;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.TYPE;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.VERSION;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.childEquals;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.createElement;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.createElementWithText;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.findChild;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.findChilds;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.format;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.getChild;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.performOnDOMDocument;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.removeChild;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.setText;
+import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.*;
import java.util.List;
@@ -37,6 +19,8 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.text.IDocument;
import org.eclipse.ltk.core.refactoring.TextChange;
+import org.eclipse.ltk.core.refactoring.TextFileChange;
+
import org.eclipse.m2e.core.ui.internal.M2EUIPluginActivator;
import org.eclipse.m2e.core.ui.internal.Messages;
import org.eclipse.m2e.core.ui.internal.editing.PomEdits.Operation;
@@ -90,9 +74,17 @@ public final class PomHelper {
}
return false;
}
-
+ /**
+ *
+ * @param file
+ * @param operation
+ * @param label
+ * @param forceSave if true will save all files, no matter if associated document is opened in editor area or not.
+ * @return
+ * @throws CoreException
+ */
@SuppressWarnings("restriction")
- public static TextChange createChange(IFile file, Operation operation, String label) throws CoreException {
+ public static TextChange createChange(IFile file, Operation operation, String label, boolean forceSave) throws CoreException {
IStructuredModel model = null;
try {
model = StructuredModelManager.getModelManager().getModelForRead(file);
@@ -104,7 +96,13 @@ public final class PomHelper {
IDocument tempDocument = tempModel.getStructuredDocument();
performOnDOMDocument(new OperationTuple((IDOMModel) tempModel, operation));
- return new ChangeCreator(existing ? null : file, document, tempDocument, label).createChange();
+ TextChange change = new ChangeCreator(!forceSave && existing ? null : file, document, tempDocument, label).createChange();
+ if (forceSave) assert change instanceof TextFileChange; //if assert not fullfilled, we will not get the file saved..
+
+ if (forceSave && change instanceof TextFileChange) {
+ ((TextFileChange)change).setSaveMode(TextFileChange.FORCE_SAVE);
+ }
+ return change;
} catch(Exception exc) {
LOG.error(Messages.PomHelper_errorCreatingChange, exc);
throw new CoreException(new Status(IStatus.ERROR, M2EUIPluginActivator.PLUGIN_ID,
@@ -117,6 +115,18 @@ public final class PomHelper {
}
/**
+ * by default will create a change that won't save files with opened documents
+ * @param file
+ * @param operation
+ * @param label
+ * @return
+ * @throws CoreException
+ */
+ public static TextChange createChange(IFile file, Operation operation, String label) throws CoreException {
+ return createChange(file, operation, label, false);
+ }
+
+ /**
* creates and adds new plugin to the parent. Formats the result.
* @param parentList
* @param groupId null or value

Back to the top